00001 /* 00002 * Asterisk -- An open source telephony toolkit. 00003 * 00004 * Copyright (C) 2008 - 2009, Digium, Inc. 00005 * 00006 * See http://www.asterisk.org for more information about 00007 * the Asterisk project. Please do not directly contact 00008 * any of the maintainers of this project for assistance; 00009 * the project provides a web site, mailing lists and IRC 00010 * channels for your use. 00011 * 00012 * This program is free software, distributed under the terms of 00013 * the GNU General Public License Version 2. See the LICENSE file 00014 * at the top of the source tree. 00015 */ 00016 00017 /*! 00018 * \file 00019 * \brief Call Event Logging API 00020 * 00021 * \todo TODO: There some event types that have been defined here, but are not 00022 * yet used anywhere in the code. It would be really awesome if someone 00023 * went through and had Asterisk generate these events where it is 00024 * appropriate to do so. The defined, but unused events are: 00025 * CONF_ENTER, CONF_EXIT, CONF_START, CONF_END, 3WAY_START, 3WAY_END, 00026 * TRANSFER, and HOOKFLASH. 00027 */ 00028 00029 #ifndef __AST_CEL_H__ 00030 #define __AST_CEL_H__ 00031 00032 #if defined(__cplusplus) || defined(c_plusplus) 00033 extern "C" { 00034 #endif 00035 00036 #include "asterisk/event.h" 00037 00038 /*! 00039 * \brief AMA Flags 00040 * 00041 * \note This must much up with the AST_CDR_* defines for AMA flags. 00042 */ 00043 enum ast_cel_ama_flag { 00044 AST_CEL_AMA_FLAG_NONE, 00045 AST_CEL_AMA_FLAG_OMIT, 00046 AST_CEL_AMA_FLAG_BILLING, 00047 AST_CEL_AMA_FLAG_DOCUMENTATION, 00048 /*! \brief Must be final entry */ 00049 AST_CEL_AMA_FLAG_TOTAL, 00050 }; 00051 00052 /*! 00053 * \brief CEL event types 00054 */ 00055 enum ast_cel_event_type { 00056 /*! \brief channel birth */ 00057 AST_CEL_CHANNEL_START = 1, 00058 /*! \brief channel end */ 00059 AST_CEL_CHANNEL_END = 2, 00060 /*! \brief hangup terminates connection */ 00061 AST_CEL_HANGUP = 3, 00062 /*! \brief A ringing phone is answered */ 00063 AST_CEL_ANSWER = 4, 00064 /*! \brief an app starts */ 00065 AST_CEL_APP_START = 5, 00066 /*! \brief an app ends */ 00067 AST_CEL_APP_END = 6, 00068 /*! \brief a bridge is established */ 00069 AST_CEL_BRIDGE_START = 7, 00070 /*! \brief a bridge is torn down */ 00071 AST_CEL_BRIDGE_END = 8, 00072 /*! \brief a conference is started */ 00073 AST_CEL_CONF_START = 9, 00074 /*! \brief a conference is ended */ 00075 AST_CEL_CONF_END = 10, 00076 /*! \brief a channel is parked */ 00077 AST_CEL_PARK_START = 11, 00078 /*! \brief channel out of the park */ 00079 AST_CEL_PARK_END = 12, 00080 /*! \brief a transfer occurs */ 00081 AST_CEL_BLINDTRANSFER = 13, 00082 /*! \brief a transfer occurs */ 00083 AST_CEL_ATTENDEDTRANSFER = 14, 00084 /*! \brief a transfer occurs */ 00085 AST_CEL_TRANSFER = 15, 00086 /*! \brief a 3-way conference, usually part of a transfer */ 00087 AST_CEL_HOOKFLASH = 16, 00088 /*! \brief a 3-way conference, usually part of a transfer */ 00089 AST_CEL_3WAY_START = 17, 00090 /*! \brief a 3-way conference, usually part of a transfer */ 00091 AST_CEL_3WAY_END = 18, 00092 /*! \brief channel enters a conference */ 00093 AST_CEL_CONF_ENTER = 19, 00094 /*! \brief channel exits a conference */ 00095 AST_CEL_CONF_EXIT = 20, 00096 /*! \brief a user-defined event, the event name field should be set */ 00097 AST_CEL_USER_DEFINED = 21, 00098 /*! \brief the last channel with the given linkedid is retired */ 00099 AST_CEL_LINKEDID_END = 22, 00100 /*! \brief a masquerade happened to alter the participants on a bridge */ 00101 AST_CEL_BRIDGE_UPDATE = 23, 00102 /*! \brief a directed pickup was performed on this channel */ 00103 AST_CEL_PICKUP = 24, 00104 /*! \brief this call was forwarded somewhere else */ 00105 AST_CEL_FORWARD = 25, 00106 }; 00107 00108 /*! 00109 * \brief Check to see if CEL is enabled 00110 * 00111 * \since 1.8 00112 * 00113 * \retval zero not enabled 00114 * \retval non-zero enabled 00115 */ 00116 unsigned int ast_cel_check_enabled(void); 00117 00118 /*! 00119 * \brief Allocate a CEL record 00120 * 00121 * \since 1.8 00122 * 00123 * \note The CEL record must be destroyed with ast_cel_destroy(). 00124 * 00125 * \retval non-NULL an allocated ast_cel structure 00126 * \retval NULL error 00127 */ 00128 struct ast_cel *ast_cel_alloc(void); 00129 00130 /*! 00131 * \brief Destroy a CEL record. 00132 * 00133 * \param cel the record to destroy 00134 * 00135 * \since 1.8 00136 * 00137 * \return nothing. 00138 */ 00139 void ast_cel_destroy(struct ast_cel *cel); 00140 00141 /*! 00142 * \brief Get the name of a CEL event type 00143 * 00144 * \param type the type to get the name of 00145 * 00146 * \since 1.8 00147 * 00148 * \return the string representation of the type 00149 */ 00150 const char *ast_cel_get_type_name(enum ast_cel_event_type type); 00151 00152 /*! 00153 * \brief Get the event type from a string 00154 * 00155 * \param name the event type name as a string 00156 * 00157 * \since 1.8 00158 * 00159 * \return the ast_cel_event_type given by the string 00160 */ 00161 enum ast_cel_event_type ast_cel_str_to_event_type(const char *name); 00162 00163 /*! 00164 * \brief Convert AMA flag to printable string 00165 * 00166 * \param[in] flag the flag to convert to a string 00167 * 00168 * \since 1.8 00169 * 00170 * \return the string representation of the flag 00171 */ 00172 const char *ast_cel_get_ama_flag_name(enum ast_cel_ama_flag flag); 00173 00174 /*! 00175 * \brief Check and potentially retire a Linked ID 00176 * 00177 * \param chan channel that is being destroyed or its linkedid is changing 00178 * 00179 * \since 1.8 00180 * 00181 * If at least one CEL backend is looking for CEL_LINKEDID_END 00182 * events, this function will check if the given channel is the last 00183 * active channel with that linkedid, and if it is, emit a 00184 * CEL_LINKEDID_END event. 00185 * 00186 * \return nothing 00187 */ 00188 void ast_cel_check_retire_linkedid(struct ast_channel *chan); 00189 00190 /*! 00191 * \brief Inform CEL that a new linkedid is being used 00192 * \since 11 00193 * 00194 * \retval -1 error 00195 * \retval 0 success 00196 */ 00197 int ast_cel_linkedid_ref(const char *linkedid); 00198 00199 /*! 00200 * \brief Create a fake channel from data in a CEL event 00201 * 00202 * \note 00203 * This function creates a fake channel containing the 00204 * serialized channel data in the given cel event. It should be 00205 * released with ast_channel_unref() but could be released with 00206 * ast_channel_release(). 00207 * 00208 * \param event the CEL event 00209 * 00210 * \since 1.8 00211 * 00212 * \return a channel with the data filled in, or NULL on error 00213 * 00214 * \todo This function is \b very expensive, especially given that some CEL backends 00215 * use it on \b every CEL event. This function really needs to go away at 00216 * some point. 00217 */ 00218 struct ast_channel *ast_cel_fabricate_channel_from_event(const struct ast_event *event); 00219 00220 /*! 00221 * \brief Report a channel event 00222 * 00223 * \param chan This argument is required. This is the primary channel associated with 00224 * this channel event. 00225 * \param event_type This is the type of call event being reported. 00226 * \param userdefevname This is an optional custom name for the call event. 00227 * \param extra This is an optional opaque field that will go into the "CEL_EXTRA" 00228 * information element of the call event. 00229 * \param peer2 All CEL events contain a "peer name" information element. The first 00230 * place the code will look to get a peer name is from the bridged channel to 00231 * chan. If chan has no bridged channel and peer2 is specified, then the name 00232 * of peer2 will go into the "peer name" field. If neither are available, the 00233 * peer name field will be blank. 00234 * 00235 * \since 1.8 00236 * 00237 * \pre chan and peer2 are both unlocked 00238 * 00239 * \retval 0 success 00240 * \retval non-zero failure 00241 */ 00242 int ast_cel_report_event(struct ast_channel *chan, enum ast_cel_event_type event_type, 00243 const char *userdefevname, const char *extra, struct ast_channel *peer2); 00244 00245 /*! 00246 * \brief Helper struct for getting the fields out of a CEL event 00247 */ 00248 struct ast_cel_event_record { 00249 /*! 00250 * \brief struct ABI version 00251 * \note This \b must be incremented when the struct changes. 00252 */ 00253 #define AST_CEL_EVENT_RECORD_VERSION 2 00254 /*! 00255 * \brief struct ABI version 00256 * \note This \b must stay as the first member. 00257 */ 00258 uint32_t version; 00259 enum ast_cel_event_type event_type; 00260 struct timeval event_time; 00261 const char *event_name; 00262 const char *user_defined_name; 00263 const char *caller_id_name; 00264 const char *caller_id_num; 00265 const char *caller_id_ani; 00266 const char *caller_id_rdnis; 00267 const char *caller_id_dnid; 00268 const char *extension; 00269 const char *context; 00270 const char *channel_name; 00271 const char *application_name; 00272 const char *application_data; 00273 const char *account_code; 00274 const char *peer_account; 00275 const char *unique_id; 00276 const char *linked_id; 00277 uint amaflag; 00278 const char *user_field; 00279 const char *peer; 00280 const char *extra; 00281 }; 00282 00283 /*! 00284 * \brief Fill in an ast_cel_event_record from a CEL event 00285 * 00286 * \param[in] event the CEL event 00287 * \param[out] r the ast_cel_event_record to fill in 00288 * 00289 * \since 1.8 00290 * 00291 * \retval 0 success 00292 * \retval non-zero failure 00293 */ 00294 int ast_cel_fill_record(const struct ast_event *event, struct ast_cel_event_record *r); 00295 00296 #if defined(__cplusplus) || defined(c_plusplus) 00297 } 00298 #endif 00299 00300 #endif /* __AST_CEL_H__ */