Asterisk - The Open Source Telephony Project GIT-master-80b953f
Loading...
Searching...
No Matches
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#include "asterisk/strings.h"
38
39/*!
40 * \brief CEL event types
41 */
45 /*! \brief channel birth */
47 /*! \brief channel end */
49 /*! \brief hangup terminates connection */
51 /*! \brief A ringing phone is answered */
53 /*! \brief an app starts */
55 /*! \brief an app ends */
57 /*! \brief channel enters a bridge */
59 /*! \brief channel exits a bridge */
61 /*! \brief a channel is parked */
63 /*! \brief channel out of the park */
65 /*! \brief a transfer occurs */
67 /*! \brief a transfer occurs */
69 /*! \brief a user-defined event, the event name field should be set */
71 /*! \brief the last channel with the given linkedid is retired */
73 /*! \brief a directed pickup was performed on this channel */
75 /*! \brief this call was forwarded somewhere else */
77 /*! \brief A local channel optimization occurred, this marks the end */
79 /*! \brief A local channel optimization has begun */
81 /*! \brief A stream started */
83 /*! \brief A stream ended */
85 /*! \brief A DTMF digit was processed */
87};
88
89/*!
90 * \brief Check to see if CEL is enabled
91 *
92 * \since 1.8
93 *
94 * \retval zero not enabled
95 * \retval non-zero enabled
96 */
97unsigned int ast_cel_check_enabled(void);
98
99/*!
100 * \brief Get the name of a CEL event type
101 *
102 * \param type the type to get the name of
103 *
104 * \since 1.8
105 *
106 * \return the string representation of the type
107 */
109
110/*!
111 * \brief Get the event type from a string
112 *
113 * \param name the event type name as a string
114 *
115 * \since 1.8
116 *
117 * \return the ast_cel_event_type given by the string
118 */
120
121/*!
122 * \brief Format an event timeval using dateformat from cel.conf
123 *
124 * \param eventtime The timeval to format
125 * \param timebuf A buffer of at least 30 characters to place the result in
126 * \param len Length of buffer
127
128 * \retval zero Success
129 * \retval non-zero Failure
130 */
131int ast_cel_format_eventtime(struct timeval eventtime, char *timebuf, size_t len);
132
133/*!
134 * \brief Create a fake channel from data in a CEL event
135 *
136 * \note
137 * This function creates a fake channel containing the
138 * serialized channel data in the given cel event. It should be
139 * released with ast_channel_unref() but could be released with
140 * ast_channel_release().
141 *
142 * \param event the CEL event
143 *
144 * \since 1.8
145 *
146 * \return a channel with the data filled in, or NULL on error
147 *
148 * \todo This function is \b very expensive, especially given that some CEL backends
149 * use it on \b every CEL event. This function really needs to go away at
150 * some point.
151 */
153
154/*!
155 * \brief Helper struct for getting the fields out of a CEL event
156 */
158 /*!
159 * \brief struct ABI version
160 * \note This \b must be incremented when the struct changes.
161 */
162 #define AST_CEL_EVENT_RECORD_VERSION 3
163 /*!
164 * \brief struct ABI version
165 * \note This \b must stay as the first member.
166 */
167 uint32_t version;
169 struct timeval event_time;
170 const char *event_name;
171 const char *user_defined_name;
172 const char *caller_id_name;
173 const char *caller_id_num;
174 const char *caller_id_ani;
175 const char *caller_id_rdnis;
176 const char *caller_id_dnid;
177 const char *extension;
178 const char *context;
179 const char *channel_name;
180 const char *application_name;
181 const char *application_data;
182 const char *account_code;
183 const char *peer_account;
184 const char *unique_id;
185 const char *linked_id;
186 const char *tenant_id;
188 const char *user_field;
189 const char *peer;
190 const char *extra;
191};
192
193/*!
194 * \brief Fill in an ast_cel_event_record from a CEL event
195 *
196 * \param[in] event the CEL event
197 * \param[out] r the ast_cel_event_record to fill in
198 *
199 * \since 1.8
200 *
201 * \retval 0 success
202 * \retval non-zero failure
203 */
204int ast_cel_fill_record(const struct ast_event *event, struct ast_cel_event_record *r);
205
206/*!
207 * \brief Publish a CEL event
208 * \since 12
209 *
210 * \param chan This is the primary channel associated with this channel event.
211 * \param event_type This is the type of call event being reported.
212 * \param blob This contains any additional parameters that need to be conveyed for this event.
213 */
214void ast_cel_publish_event(struct ast_channel *chan,
215 enum ast_cel_event_type event_type,
216 struct ast_json *blob);
217
218/*!
219 * \brief Publish a CEL user event
220 * \since 18
221 *
222 * \note
223 * This serves as a wrapper function around ast_cel_publish_event() to help pack the
224 * extra details before publishing.
225 *
226 * \param chan This is the primary channel associated with this channel event.
227 * \param event This is the user event being reported.
228 * \param extra This contains any extra parameters that need to be conveyed for this event.
229 */
231 const char *event,
232 const char *extra);
233
234/*!
235 * \brief Get the CEL topic
236 *
237 * \retval The CEL topic
238 * \retval NULL if not allocated
239 */
240struct stasis_topic *ast_cel_topic(void);
241
242/*! \brief A structure to hold CEL global configuration options */
245 AST_STRING_FIELD(date_format); /*!< The desired date format for logging */
246 );
247 int enable; /*!< Whether CEL is enabled */
248 int64_t events; /*!< The events to be logged */
249 /*! The apps for which to log app start and end events. This is
250 * ast_str_container_alloc()ed and filled with ao2-allocated
251 * char* which are all-lowercase application names. */
253};
254
255/*!
256 * \brief Allocate a CEL configuration object
257 *
258 * \retval NULL on error
259 * \retval The new CEL configuration object
260 */
262
263/*!
264 * \since 12
265 * \brief Obtain the current CEL configuration
266 *
267 * The configuration is a ref counted object. The caller of this function must
268 * decrement the ref count when finished with the configuration.
269 *
270 * \retval NULL on error
271 * \retval The current CEL configuration
272 */
274
275/*!
276 * \since 12
277 * \brief Set the current CEL configuration
278 *
279 * \param config The new CEL configuration
280 */
282
284/*!
285 * \brief Allocate and populate a CEL event structure
286 *
287 * \param snapshot An ast_channel_snapshot of the primary channel associated
288 * with this channel event.
289 * \param event_type The type of call event being reported.
290 * \param userdefevname Custom name for the call event. (optional)
291 * \param extra An event-specific opaque JSON blob to be rendered and placed
292 * in the "CEL_EXTRA" information element of the call event. (optional)
293 * \param peer_str A list of comma-separated peer channel names. (optional)
294 *
295 * \since 12
296 *
297 * \retval The created ast_event structure
298 * \retval NULL on failure
299 */
301 enum ast_cel_event_type event_type, const char *userdefevname,
302 struct ast_json *extra, const char *peer_str);
303
304/*!
305 * \brief Allocate and populate a CEL event structure
306 *
307 * \param snapshot An ast_channel_snapshot of the primary channel associated
308 * with this channel event.
309 * \param event_type The type of call event being reported.
310 * \param event_time The time at which the event occurred.
311 * \param userdefevname Custom name for the call event. (optional)
312 * \param extra An event-specific opaque JSON blob to be rendered and placed
313 * in the "CEL_EXTRA" information element of the call event. (optional)
314 * \param peer_str A list of comma-separated peer channel names. (optional)
315 *
316 * \since 13.29.0
317 * \since 16.6.0
318 *
319 * \retval The created ast_event structure
320 * \retval NULL on failure
321 */
323 enum ast_cel_event_type event_type, const struct timeval *event_time,
324 const char *userdefevname, struct ast_json *extra, const char *peer_str);
325
326/*!
327 * \brief CEL backend callback
328 */
329/*typedef int (*ast_cel_backend_cb)(struct ast_cel_event_record *cel);*/
330typedef void (*ast_cel_backend_cb)(struct ast_event *event);
331
332/*!
333 * \brief Register a CEL backend
334 *
335 * \param name Name of backend to register
336 * \param backend_callback Callback to register
337 *
338 * \retval zero on success
339 * \retval non-zero on failure
340 * \since 12
341 */
342int ast_cel_backend_register(const char *name, ast_cel_backend_cb backend_callback);
343
344/*!
345 * \brief Unregister a CEL backend
346 *
347 * \param name Name of backend to unregister
348 *
349 * \retval zero on success
350 * \retval non-zero on failure
351 * \since 12
352 */
353int ast_cel_backend_unregister(const char *name);
354
355#if defined(__cplusplus) || defined(c_plusplus)
356}
357#endif
358
359#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:1747
void ast_cel_set_config(struct ast_cel_general_config *config)
Set the current CEL configuration.
Definition cel.c:1798
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:1824
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:1762
ast_cel_event_type
CEL event types.
Definition cel.h:42
@ AST_CEL_CHANNEL_END
channel end
Definition cel.h:48
@ AST_CEL_APP_END
an app ends
Definition cel.h:56
@ AST_CEL_ANSWER
A ringing phone is answered.
Definition cel.h:52
@ AST_CEL_PARK_START
a channel is parked
Definition cel.h:62
@ AST_CEL_LINKEDID_END
the last channel with the given linkedid is retired
Definition cel.h:72
@ AST_CEL_INVALID_VALUE
Definition cel.h:43
@ AST_CEL_BRIDGE_EXIT
channel exits a bridge
Definition cel.h:60
@ AST_CEL_FORWARD
this call was forwarded somewhere else
Definition cel.h:76
@ AST_CEL_HANGUP
hangup terminates connection
Definition cel.h:50
@ AST_CEL_USER_DEFINED
a user-defined event, the event name field should be set
Definition cel.h:70
@ AST_CEL_PICKUP
a directed pickup was performed on this channel
Definition cel.h:74
@ AST_CEL_APP_START
an app starts
Definition cel.h:54
@ AST_CEL_LOCAL_OPTIMIZE_BEGIN
A local channel optimization has begun.
Definition cel.h:80
@ AST_CEL_ALL
Definition cel.h:44
@ AST_CEL_DTMF
A DTMF digit was processed.
Definition cel.h:86
@ AST_CEL_PARK_END
channel out of the park
Definition cel.h:64
@ AST_CEL_CHANNEL_START
channel birth
Definition cel.h:46
@ AST_CEL_STREAM_BEGIN
A stream started.
Definition cel.h:82
@ AST_CEL_ATTENDEDTRANSFER
a transfer occurs
Definition cel.h:68
@ AST_CEL_BRIDGE_ENTER
channel enters a bridge
Definition cel.h:58
@ AST_CEL_STREAM_END
A stream ended.
Definition cel.h:84
@ AST_CEL_BLINDTRANSFER
a transfer occurs
Definition cel.h:66
@ AST_CEL_LOCAL_OPTIMIZE
A local channel optimization occurred, this marks the end.
Definition cel.h:78
void * ast_cel_general_config_alloc(void)
Allocate a CEL configuration object.
Definition cel.c:207
int ast_cel_format_eventtime(struct timeval eventtime, char *timebuf, size_t len)
Format an event timeval using dateformat from cel.conf.
Definition cel.c:694
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:330
struct stasis_topic * ast_cel_topic(void)
Get the CEL topic.
Definition cel.c:1781
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:717
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:870
struct ast_cel_general_config * ast_cel_get_config(void)
Obtain the current CEL configuration.
Definition cel.c:1786
int ast_cel_backend_register(const char *name, ast_cel_backend_cb backend_callback)
Register a CEL backend.
Definition cel.c:1836
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[]
static const char config[]
static const char name[]
Definition format_mp3.c:68
static int len(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t buflen)
#define AST_DECLARE_STRING_FIELDS(field_list)
Declare the fields needed in a structure.
#define AST_STRING_FIELD(name)
Declare a string field.
String manipulation functions.
Generic container type.
Helper struct for getting the fields out of a CEL event.
Definition cel.h:157
const char * caller_id_dnid
Definition cel.h:176
const char * application_data
Definition cel.h:181
const char * account_code
Definition cel.h:182
const char * caller_id_rdnis
Definition cel.h:175
const char * extra
Definition cel.h:190
const char * extension
Definition cel.h:177
const char * caller_id_num
Definition cel.h:173
const char * channel_name
Definition cel.h:179
const char * linked_id
Definition cel.h:185
const char * peer_account
Definition cel.h:183
const char * peer
Definition cel.h:189
enum ast_cel_event_type event_type
Definition cel.h:168
const char * unique_id
Definition cel.h:184
const char * user_defined_name
Definition cel.h:171
const char * context
Definition cel.h:178
const char * application_name
Definition cel.h:180
struct timeval event_time
Definition cel.h:169
uint32_t version
struct ABI version
Definition cel.h:167
const char * tenant_id
Definition cel.h:186
const char * user_field
Definition cel.h:188
const char * caller_id_ani
Definition cel.h:174
const char * caller_id_name
Definition cel.h:172
const char * event_name
Definition cel.h:170
A structure to hold CEL global configuration options.
Definition cel.h:243
const ast_string_field date_format
Definition cel.h:246
struct ao2_container * apps
Definition cel.h:252
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, ...).