Asterisk - The Open Source Telephony Project GIT-master-0deac78
cel.h
Go to the documentation of this file.
1/*
2 * Asterisk -- An open source telephony toolkit.
3 *
4 * Copyright (C) 2008 - 2009, Digium, Inc.
5 *
6 * See http://www.asterisk.org for more information about
7 * the Asterisk project. Please do not directly contact
8 * any of the maintainers of this project for assistance;
9 * the project provides a web site, mailing lists and IRC
10 * channels for your use.
11 *
12 * This program is free software, distributed under the terms of
13 * the GNU General Public License Version 2. See the LICENSE file
14 * at the top of the source tree.
15 */
16
17/*!
18 * \file
19 * \brief Call Event Logging API
20 *
21 * \todo TODO: There some event types that have been defined here, but are not
22 * yet used anywhere in the code. It would be really awesome if someone
23 * went through and had Asterisk generate these events where it is
24 * appropriate to do so. The defined, but unused events are:
25 * CONF_ENTER, CONF_EXIT, CONF_START, CONF_END, 3WAY_START, 3WAY_END,
26 * TRANSFER, and HOOKFLASH.
27 */
28
29#ifndef __AST_CEL_H__
30#define __AST_CEL_H__
31
32#if defined(__cplusplus) || defined(c_plusplus)
33extern "C" {
34#endif
35
36#include "asterisk/event.h"
37
38/*!
39 * \brief CEL event types
40 */
44 /*! \brief channel birth */
46 /*! \brief channel end */
48 /*! \brief hangup terminates connection */
50 /*! \brief A ringing phone is answered */
52 /*! \brief an app starts */
54 /*! \brief an app ends */
56 /*! \brief channel enters a bridge */
58 /*! \brief channel exits a bridge */
60 /*! \brief a channel is parked */
62 /*! \brief channel out of the park */
64 /*! \brief a transfer occurs */
66 /*! \brief a transfer occurs */
68 /*! \brief a user-defined event, the event name field should be set */
70 /*! \brief the last channel with the given linkedid is retired */
72 /*! \brief a directed pickup was performed on this channel */
74 /*! \brief this call was forwarded somewhere else */
76 /*! \brief A local channel optimization occurred, this marks the end */
78 /*! \brief A local channel optimization has begun */
80 /*! \brief A stream started */
82 /*! \brief A stream ended */
84 /*! \brief A DTMF digit was processed */
86};
87
88/*!
89 * \brief Check to see if CEL is enabled
90 *
91 * \since 1.8
92 *
93 * \retval zero not enabled
94 * \retval non-zero enabled
95 */
96unsigned int ast_cel_check_enabled(void);
97
98/*!
99 * \brief Get the name of a CEL event type
100 *
101 * \param type the type to get the name of
102 *
103 * \since 1.8
104 *
105 * \return the string representation of the type
106 */
108
109/*!
110 * \brief Get the event type from a string
111 *
112 * \param name the event type name as a string
113 *
114 * \since 1.8
115 *
116 * \return the ast_cel_event_type given by the string
117 */
119
120/*!
121 * \brief Create a fake channel from data in a CEL event
122 *
123 * \note
124 * This function creates a fake channel containing the
125 * serialized channel data in the given cel event. It should be
126 * released with ast_channel_unref() but could be released with
127 * ast_channel_release().
128 *
129 * \param event the CEL event
130 *
131 * \since 1.8
132 *
133 * \return a channel with the data filled in, or NULL on error
134 *
135 * \todo This function is \b very expensive, especially given that some CEL backends
136 * use it on \b every CEL event. This function really needs to go away at
137 * some point.
138 */
140
141/*!
142 * \brief Helper struct for getting the fields out of a CEL event
143 */
145 /*!
146 * \brief struct ABI version
147 * \note This \b must be incremented when the struct changes.
148 */
149 #define AST_CEL_EVENT_RECORD_VERSION 3
150 /*!
151 * \brief struct ABI version
152 * \note This \b must stay as the first member.
153 */
154 uint32_t version;
156 struct timeval event_time;
157 const char *event_name;
158 const char *user_defined_name;
159 const char *caller_id_name;
160 const char *caller_id_num;
161 const char *caller_id_ani;
162 const char *caller_id_rdnis;
163 const char *caller_id_dnid;
164 const char *extension;
165 const char *context;
166 const char *channel_name;
167 const char *application_name;
168 const char *application_data;
169 const char *account_code;
170 const char *peer_account;
171 const char *unique_id;
172 const char *linked_id;
173 const char *tenant_id;
175 const char *user_field;
176 const char *peer;
177 const char *extra;
178};
179
180/*!
181 * \brief Fill in an ast_cel_event_record from a CEL event
182 *
183 * \param[in] event the CEL event
184 * \param[out] r the ast_cel_event_record to fill in
185 *
186 * \since 1.8
187 *
188 * \retval 0 success
189 * \retval non-zero failure
190 */
191int ast_cel_fill_record(const struct ast_event *event, struct ast_cel_event_record *r);
192
193/*!
194 * \brief Publish a CEL event
195 * \since 12
196 *
197 * \param chan This is the primary channel associated with this channel event.
198 * \param event_type This is the type of call event being reported.
199 * \param blob This contains any additional parameters that need to be conveyed for this event.
200 */
201void ast_cel_publish_event(struct ast_channel *chan,
202 enum ast_cel_event_type event_type,
203 struct ast_json *blob);
204
205/*!
206 * \brief Publish a CEL user event
207 * \since 18
208 *
209 * \note
210 * This serves as a wrapper function around ast_cel_publish_event() to help pack the
211 * extra details before publishing.
212 *
213 * \param chan This is the primary channel associated with this channel event.
214 * \param event This is the user event being reported.
215 * \param extra This contains any extra parameters that need to be conveyed for this event.
216 */
218 const char *event,
219 const char *extra);
220
221/*!
222 * \brief Get the CEL topic
223 *
224 * \retval The CEL topic
225 * \retval NULL if not allocated
226 */
227struct stasis_topic *ast_cel_topic(void);
228
229/*! \brief A structure to hold CEL global configuration options */
232 AST_STRING_FIELD(date_format); /*!< The desired date format for logging */
233 );
234 int enable; /*!< Whether CEL is enabled */
235 int64_t events; /*!< The events to be logged */
236 /*! The apps for which to log app start and end events. This is
237 * ast_str_container_alloc()ed and filled with ao2-allocated
238 * char* which are all-lowercase application names. */
240};
241
242/*!
243 * \brief Allocate a CEL configuration object
244 *
245 * \retval NULL on error
246 * \retval The new CEL configuration object
247 */
249
250/*!
251 * \since 12
252 * \brief Obtain the current CEL configuration
253 *
254 * The configuration is a ref counted object. The caller of this function must
255 * decrement the ref count when finished with the configuration.
256 *
257 * \retval NULL on error
258 * \retval The current CEL configuration
259 */
261
262/*!
263 * \since 12
264 * \brief Set the current CEL configuration
265 *
266 * \param config The new CEL configuration
267 */
269
271/*!
272 * \brief Allocate and populate a CEL event structure
273 *
274 * \param snapshot An ast_channel_snapshot of the primary channel associated
275 * with this channel event.
276 * \param event_type The type of call event being reported.
277 * \param userdefevname Custom name for the call event. (optional)
278 * \param extra An event-specific opaque JSON blob to be rendered and placed
279 * in the "CEL_EXTRA" information element of the call event. (optional)
280 * \param peer_str A list of comma-separated peer channel names. (optional)
281 *
282 * \since 12
283 *
284 * \retval The created ast_event structure
285 * \retval NULL on failure
286 */
288 enum ast_cel_event_type event_type, const char *userdefevname,
289 struct ast_json *extra, const char *peer_str);
290
291/*!
292 * \brief Allocate and populate a CEL event structure
293 *
294 * \param snapshot An ast_channel_snapshot of the primary channel associated
295 * with this channel event.
296 * \param event_type The type of call event being reported.
297 * \param event_time The time at which the event occurred.
298 * \param userdefevname Custom name for the call event. (optional)
299 * \param extra An event-specific opaque JSON blob to be rendered and placed
300 * in the "CEL_EXTRA" information element of the call event. (optional)
301 * \param peer_str A list of comma-separated peer channel names. (optional)
302 *
303 * \since 13.29.0
304 * \since 16.6.0
305 *
306 * \retval The created ast_event structure
307 * \retval NULL on failure
308 */
310 enum ast_cel_event_type event_type, const struct timeval *event_time,
311 const char *userdefevname, struct ast_json *extra, const char *peer_str);
312
313/*!
314 * \brief CEL backend callback
315 */
316/*typedef int (*ast_cel_backend_cb)(struct ast_cel_event_record *cel);*/
317typedef void (*ast_cel_backend_cb)(struct ast_event *event);
318
319/*!
320 * \brief Register a CEL backend
321 *
322 * \param name Name of backend to register
323 * \param backend_callback Callback to register
324 *
325 * \retval zero on success
326 * \retval non-zero on failure
327 * \since 12
328 */
329int ast_cel_backend_register(const char *name, ast_cel_backend_cb backend_callback);
330
331/*!
332 * \brief Unregister a CEL backend
333 *
334 * \param name Name of backend to unregister
335 *
336 * \retval zero on success
337 * \retval non-zero on failure
338 * \since 12
339 */
340int ast_cel_backend_unregister(const char *name);
341
342#if defined(__cplusplus) || defined(c_plusplus)
343}
344#endif
345
346#endif /* __AST_CEL_H__ */
struct ast_event * ast_cel_create_event_with_time(struct ast_channel_snapshot *snapshot, enum ast_cel_event_type event_type, const struct timeval *event_time, const char *userdefevname, struct ast_json *extra, const char *peer_str)
Allocate and populate a CEL event structure.
Definition: cel.c:550
void ast_cel_publish_user_event(struct ast_channel *chan, const char *event, const char *extra)
Publish a CEL user event.
Definition: cel.c:1720
void ast_cel_set_config(struct ast_cel_general_config *config)
Set the current CEL configuration.
Definition: cel.c:1771
struct ast_event * ast_cel_create_event(struct ast_channel_snapshot *snapshot, enum ast_cel_event_type event_type, const char *userdefevname, struct ast_json *extra, const char *peer_str)
Allocate and populate a CEL event structure.
Definition: cel.c:540
int ast_cel_backend_unregister(const char *name)
Unregister a CEL backend.
Definition: cel.c:1797
enum ast_cel_event_type ast_cel_str_to_event_type(const char *name)
Get the event type from a string.
Definition: cel.c:441
void ast_cel_publish_event(struct ast_channel *chan, enum ast_cel_event_type event_type, struct ast_json *blob)
Publish a CEL event.
Definition: cel.c:1735
ast_cel_event_type
CEL event types.
Definition: cel.h:41
@ AST_CEL_CHANNEL_END
channel end
Definition: cel.h:47
@ AST_CEL_APP_END
an app ends
Definition: cel.h:55
@ AST_CEL_ANSWER
A ringing phone is answered.
Definition: cel.h:51
@ AST_CEL_PARK_START
a channel is parked
Definition: cel.h:61
@ AST_CEL_LINKEDID_END
the last channel with the given linkedid is retired
Definition: cel.h:71
@ AST_CEL_INVALID_VALUE
Definition: cel.h:42
@ AST_CEL_BRIDGE_EXIT
channel exits a bridge
Definition: cel.h:59
@ AST_CEL_FORWARD
this call was forwarded somewhere else
Definition: cel.h:75
@ AST_CEL_HANGUP
hangup terminates connection
Definition: cel.h:49
@ AST_CEL_USER_DEFINED
a user-defined event, the event name field should be set
Definition: cel.h:69
@ AST_CEL_PICKUP
a directed pickup was performed on this channel
Definition: cel.h:73
@ AST_CEL_APP_START
an app starts
Definition: cel.h:53
@ AST_CEL_LOCAL_OPTIMIZE_BEGIN
A local channel optimization has begun.
Definition: cel.h:79
@ AST_CEL_ALL
Definition: cel.h:43
@ AST_CEL_DTMF
A DTMF digit was processed.
Definition: cel.h:85
@ AST_CEL_PARK_END
channel out of the park
Definition: cel.h:63
@ AST_CEL_CHANNEL_START
channel birth
Definition: cel.h:45
@ AST_CEL_STREAM_BEGIN
A stream started.
Definition: cel.h:81
@ AST_CEL_ATTENDEDTRANSFER
a transfer occurs
Definition: cel.h:67
@ AST_CEL_BRIDGE_ENTER
channel enters a bridge
Definition: cel.h:57
@ AST_CEL_STREAM_END
A stream ended.
Definition: cel.h:83
@ AST_CEL_BLINDTRANSFER
a transfer occurs
Definition: cel.h:65
@ AST_CEL_LOCAL_OPTIMIZE
A local channel optimization occurred, this marks the end.
Definition: cel.h:77
void * ast_cel_general_config_alloc(void)
Allocate a CEL configuration object.
Definition: cel.c:207
unsigned int ast_cel_check_enabled(void)
Check to see if CEL is enabled.
Definition: cel.c:366
void(* ast_cel_backend_cb)(struct ast_event *event)
CEL backend callback.
Definition: cel.h:317
struct stasis_topic * ast_cel_topic(void)
Get the CEL topic.
Definition: cel.c:1754
struct ast_channel * ast_cel_fabricate_channel_from_event(const struct ast_event *event)
Create a fake channel from data in a CEL event.
Definition: cel.c:684
int ast_cel_fill_record(const struct ast_event *event, struct ast_cel_event_record *r)
Fill in an ast_cel_event_record from a CEL event.
Definition: cel.c:843
struct ast_cel_general_config * ast_cel_get_config(void)
Obtain the current CEL configuration.
Definition: cel.c:1759
int ast_cel_backend_register(const char *name, ast_cel_backend_cb backend_callback)
Register a CEL backend.
Definition: cel.c:1809
const char * ast_cel_get_type_name(enum ast_cel_event_type type)
Get the name of a CEL event type.
Definition: cel.c:514
static const char type[]
Definition: chan_ooh323.c:109
static const char config[]
Definition: chan_ooh323.c:111
static const char name[]
Definition: format_mp3.c:68
#define AST_STRING_FIELD(name)
Declare a string field.
Definition: stringfields.h:303
Generic container type.
Helper struct for getting the fields out of a CEL event.
Definition: cel.h:144
const char * caller_id_dnid
Definition: cel.h:163
const char * application_data
Definition: cel.h:168
const char * account_code
Definition: cel.h:169
const char * caller_id_rdnis
Definition: cel.h:162
const char * extra
Definition: cel.h:177
const char * extension
Definition: cel.h:164
const char * caller_id_num
Definition: cel.h:160
const char * channel_name
Definition: cel.h:166
const char * linked_id
Definition: cel.h:172
const char * peer_account
Definition: cel.h:170
const char * peer
Definition: cel.h:176
enum ast_cel_event_type event_type
Definition: cel.h:155
const char * unique_id
Definition: cel.h:171
const char * user_defined_name
Definition: cel.h:158
const char * context
Definition: cel.h:165
const char * application_name
Definition: cel.h:167
struct timeval event_time
Definition: cel.h:156
uint32_t version
struct ABI version
Definition: cel.h:154
const char * tenant_id
Definition: cel.h:173
const char * user_field
Definition: cel.h:175
const char * caller_id_ani
Definition: cel.h:161
const char * caller_id_name
Definition: cel.h:159
const char * event_name
Definition: cel.h:157
A structure to hold CEL global configuration options.
Definition: cel.h:230
int64_t events
Definition: cel.h:235
AST_DECLARE_STRING_FIELDS(AST_STRING_FIELD(date_format);)
struct ao2_container * apps
Definition: cel.h:239
Structure representing a snapshot of channel state.
Main Channel structure associated with a channel.
An event.
Definition: event.c:81
Abstract JSON element (object, array, string, int, ...).
Definition: astman.c:222