Asterisk - The Open Source Telephony Project  18.5.0
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)
33 extern "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 */
78 };
79 
80 /*!
81  * \brief Check to see if CEL is enabled
82  *
83  * \since 1.8
84  *
85  * \retval zero not enabled
86  * \retval non-zero enabled
87  */
88 unsigned int ast_cel_check_enabled(void);
89 
90 /*!
91  * \brief Get the name of a CEL event type
92  *
93  * \param type the type to get the name of
94  *
95  * \since 1.8
96  *
97  * \return the string representation of the type
98  */
100 
101 /*!
102  * \brief Get the event type from a string
103  *
104  * \param name the event type name as a string
105  *
106  * \since 1.8
107  *
108  * \return the ast_cel_event_type given by the string
109  */
111 
112 /*!
113  * \brief Create a fake channel from data in a CEL event
114  *
115  * \note
116  * This function creates a fake channel containing the
117  * serialized channel data in the given cel event. It should be
118  * released with ast_channel_unref() but could be released with
119  * ast_channel_release().
120  *
121  * \param event the CEL event
122  *
123  * \since 1.8
124  *
125  * \return a channel with the data filled in, or NULL on error
126  *
127  * \todo This function is \b very expensive, especially given that some CEL backends
128  * use it on \b every CEL event. This function really needs to go away at
129  * some point.
130  */
132 
133 /*!
134  * \brief Helper struct for getting the fields out of a CEL event
135  */
137  /*!
138  * \brief struct ABI version
139  * \note This \b must be incremented when the struct changes.
140  */
141  #define AST_CEL_EVENT_RECORD_VERSION 2
142  /*!
143  * \brief struct ABI version
144  * \note This \b must stay as the first member.
145  */
146  uint32_t version;
148  struct timeval event_time;
149  const char *event_name;
150  const char *user_defined_name;
151  const char *caller_id_name;
152  const char *caller_id_num;
153  const char *caller_id_ani;
154  const char *caller_id_rdnis;
155  const char *caller_id_dnid;
156  const char *extension;
157  const char *context;
158  const char *channel_name;
159  const char *application_name;
160  const char *application_data;
161  const char *account_code;
162  const char *peer_account;
163  const char *unique_id;
164  const char *linked_id;
165  uint amaflag;
166  const char *user_field;
167  const char *peer;
168  const char *extra;
169 };
170 
171 /*!
172  * \brief Fill in an ast_cel_event_record from a CEL event
173  *
174  * \param[in] event the CEL event
175  * \param[out] r the ast_cel_event_record to fill in
176  *
177  * \since 1.8
178  *
179  * \retval 0 success
180  * \retval non-zero failure
181  */
182 int ast_cel_fill_record(const struct ast_event *event, struct ast_cel_event_record *r);
183 
184 /*!
185  * \brief Publish a CEL event
186  * \since 12
187  *
188  * \param chan This is the primary channel associated with this channel event.
189  * \param event_type This is the type of call event being reported.
190  * \param blob This contains any additional parameters that need to be conveyed for this event.
191  */
192 void ast_cel_publish_event(struct ast_channel *chan,
194  struct ast_json *blob);
195 
196 /*!
197  * \brief Get the CEL topic
198  *
199  * \retval The CEL topic
200  * \retval NULL if not allocated
201  */
202 struct stasis_topic *ast_cel_topic(void);
203 
204 /*! \brief A structure to hold CEL global configuration options */
207  AST_STRING_FIELD(date_format); /*!< The desired date format for logging */
208  );
209  int enable; /*!< Whether CEL is enabled */
210  int64_t events; /*!< The events to be logged */
211  /*! The apps for which to log app start and end events. This is
212  * ast_str_container_alloc()ed and filled with ao2-allocated
213  * char* which are all-lowercase application names. */
215 };
216 
217 /*!
218  * \brief Allocate a CEL configuration object
219  *
220  * \retval NULL on error
221  * \retval The new CEL configuration object
222  */
223 void *ast_cel_general_config_alloc(void);
224 
225 /*!
226  * \since 12
227  * \brief Obtain the current CEL configuration
228  *
229  * The configuration is a ref counted object. The caller of this function must
230  * decrement the ref count when finished with the configuration.
231  *
232  * \retval NULL on error
233  * \retval The current CEL configuration
234  */
236 
237 /*!
238  * \since 12
239  * \brief Set the current CEL configuration
240  *
241  * \param config The new CEL configuration
242  */
244 
245 struct ast_channel_snapshot;
246 /*!
247  * \brief Allocate and populate a CEL event structure
248  *
249  * \param snapshot An ast_channel_snapshot of the primary channel associated
250  * with this channel event.
251  * \param event_type The type of call event being reported.
252  * \param userdefevname Custom name for the call event. (optional)
253  * \param extra An event-specific opaque JSON blob to be rendered and placed
254  * in the "CEL_EXTRA" information element of the call event. (optional)
255  * \param peer_str A list of comma-separated peer channel names. (optional)
256  *
257  * \since 12
258  *
259  * \retval The created ast_event structure
260  * \retval NULL on failure
261  */
262 struct ast_event *ast_cel_create_event(struct ast_channel_snapshot *snapshot,
263  enum ast_cel_event_type event_type, const char *userdefevname,
264  struct ast_json *extra, const char *peer_str);
265 
266 /*!
267  * \brief Allocate and populate a CEL event structure
268  *
269  * \param snapshot An ast_channel_snapshot of the primary channel associated
270  * with this channel event.
271  * \param event_type The type of call event being reported.
272  * \param event_time The time at which the event occurred.
273  * \param userdefevname Custom name for the call event. (optional)
274  * \param extra An event-specific opaque JSON blob to be rendered and placed
275  * in the "CEL_EXTRA" information element of the call event. (optional)
276  * \param peer_str A list of comma-separated peer channel names. (optional)
277  *
278  * \since 13.29.0
279  * \since 16.6.0
280  *
281  * \retval The created ast_event structure
282  * \retval NULL on failure
283  */
285  enum ast_cel_event_type event_type, const struct timeval *event_time,
286  const char *userdefevname, struct ast_json *extra, const char *peer_str);
287 
288 /*!
289  * \brief CEL backend callback
290  */
291 /*typedef int (*ast_cel_backend_cb)(struct ast_cel_event_record *cel);*/
292 typedef void (*ast_cel_backend_cb)(struct ast_event *event);
293 
294 /*!
295  * \brief Register a CEL backend
296  *
297  * \param name Name of backend to register
298  * \param backend_callback Callback to register
299  *
300  * \retval zero on success
301  * \retval non-zero on failure
302  * \since 12
303  */
304 int ast_cel_backend_register(const char *name, ast_cel_backend_cb backend_callback);
305 
306 /*!
307  * \brief Unregister a CEL backend
308  *
309  * \param name Name of backend to unregister
310  *
311  * \retval zero on success
312  * \retval non-zero on failure
313  * \since 12
314  */
315 int ast_cel_backend_unregister(const char *name);
316 
317 #if defined(__cplusplus) || defined(c_plusplus)
318 }
319 #endif
320 
321 #endif /* __AST_CEL_H__ */
const char * account_code
Definition: cel.h:161
the last channel with the given linkedid is retired
Definition: cel.h:71
const char * caller_id_name
Definition: cel.h:151
static const char type[]
Definition: chan_ooh323.c:109
Helper struct for getting the fields out of a CEL event.
Definition: cel.h:136
const char * linked_id
Definition: cel.h:164
Main Channel structure associated with a channel.
An event.
Definition: event.c:81
char * config
Definition: conf2ael.c:66
const char * user_defined_name
Definition: cel.h:150
int ast_cel_backend_register(const char *name, ast_cel_backend_cb backend_callback)
Register a CEL backend.
Definition: cel.c:1740
const char * application_data
Definition: cel.h:160
const char * application_name
Definition: cel.h:159
A local channel optimization occurred.
Definition: cel.h:77
Structure representing a snapshot of channel state.
const char * extension
Definition: cel.h:156
static char date_format[6]
Definition: chan_skinny.c:209
channel birth
Definition: cel.h:45
unsigned int ast_cel_check_enabled(void)
Check to see if CEL is enabled.
Definition: cel.c:343
Definition: astman.c:222
#define AST_DECLARE_STRING_FIELDS(field_list)
Declare the fields needed in a structure.
Definition: stringfields.h:337
const char * caller_id_num
Definition: cel.h:152
const char * extra
Definition: cel.h:168
int64_t events
Definition: cel.h:210
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:527
const char * ast_cel_get_type_name(enum ast_cel_event_type type)
Get the name of a CEL event type.
Definition: cel.c:491
void ast_cel_set_config(struct ast_cel_general_config *config)
Set the current CEL configuration.
Definition: cel.c:1702
channel enters a bridge
Definition: cel.h:57
void(* ast_cel_backend_cb)(struct ast_event *event)
CEL backend callback.
Definition: cel.h:292
an app ends
Definition: cel.h:55
#define AST_STRING_FIELD(name)
Declare a string field.
Definition: stringfields.h:299
const char * context
Definition: cel.h:157
uint32_t version
struct ABI version
Definition: cel.h:146
hangup terminates connection
Definition: cel.h:49
a transfer occurs
Definition: cel.h:65
a channel is parked
Definition: cel.h:61
int ast_cel_backend_unregister(const char *name)
Unregister a CEL backend.
Definition: cel.c:1728
enum ast_cel_event_type event_type
Definition: cel.h:147
a transfer occurs
Definition: cel.h:67
const char * caller_id_rdnis
Definition: cel.h:154
const char * peer
Definition: cel.h:167
struct ao2_container * apps
Definition: cel.h:214
channel end
Definition: cel.h:47
static const char name[]
Definition: cdr_mysql.c:74
struct ast_cel_general_config * ast_cel_get_config(void)
Obtain the current CEL configuration.
Definition: cel.c:1690
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:660
const char * caller_id_ani
Definition: cel.h:153
const char * user_field
Definition: cel.h:166
const char * peer_account
Definition: cel.h:162
A structure to hold CEL global configuration options.
Definition: cel.h:205
struct stasis_topic * ast_cel_topic(void)
Get the CEL topic.
Definition: cel.c:1685
enum ast_cel_event_type ast_cel_str_to_event_type(const char *name)
Get the event type from a string.
Definition: cel.c:418
void * ast_cel_general_config_alloc(void)
Allocate a CEL configuration object.
Definition: cel.c:188
A ringing phone is answered.
Definition: cel.h:51
channel out of the park
Definition: cel.h:63
const char * unique_id
Definition: cel.h:163
Abstract JSON element (object, array, string, int, ...).
a user-defined event, the event name field should be set
Definition: cel.h:69
channel exits a bridge
Definition: cel.h:59
ast_cel_event_type
CEL event types.
Definition: cel.h:41
const char * caller_id_dnid
Definition: cel.h:155
const char * channel_name
Definition: cel.h:158
Generic container type.
const char * event_name
Definition: cel.h:149
an app starts
Definition: cel.h:53
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:517
struct timeval event_time
Definition: cel.h:148
a directed pickup was performed on this channel
Definition: cel.h:73
this call was forwarded somewhere else
Definition: cel.h:75
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:1666
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:819