Asterisk - The Open Source Telephony Project GIT-master-8f1982c
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Macros Modules Pages
Macros | Functions | Variables
cel_manager.c File Reference

Asterisk Channel Event records. More...

#include "asterisk.h"
#include "asterisk/channel.h"
#include "asterisk/cel.h"
#include "asterisk/module.h"
#include "asterisk/logger.h"
#include "asterisk/utils.h"
#include "asterisk/manager.h"
#include "asterisk/config.h"
Include dependency graph for cel_manager.c:

Go to the source code of this file.

Macros

#define CEL_AMI_ENABLED_DEFAULT   0
 AMI CEL is off by default. More...
 
#define CEL_SHOW_USERDEF_DEFAULT   0
 show_user_def is off by default More...
 
#define MANAGER_BACKEND_NAME   "Manager Event Logging"
 

Functions

static void __reg_module (void)
 
static void __unreg_module (void)
 
struct ast_moduleAST_MODULE_SELF_SYM (void)
 
static int load_config (int reload)
 
static int load_module (void)
 
static void manager_log (struct ast_event *event)
 
static int reload (void)
 
static int unload_module (void)
 

Variables

static struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_LOAD_ORDER , .description = "Asterisk Manager Interface CEL Backend" , .key = "This paragraph is copyright (c) 2006 by Digium, Inc. \In order for your module to load, it must return this \key via a function called \"key\". Any code which \includes this paragraph must be licensed under the GNU \General Public License version 2 or later (at your \option). In addition to Digium's general reservations \of rights, Digium expressly reserves the right to \allow other parties to license this paragraph under \different terms. Any use of Digium, Inc. trademarks or \logos (including \"Asterisk\" or \"Digium\") without \express written permission of Digium, Inc. is prohibited.\n" , .buildopt_sum = AST_BUILDOPT_SUM, .support_level = AST_MODULE_SUPPORT_CORE, .load = load_module, .unload = unload_module, .reload = reload, .load_pri = AST_MODPRI_CDR_DRIVER, .requires = "cel", }
 
static const struct ast_module_infoast_module_info = &__mod_info
 
static unsigned char cel_show_user_def
 
static const char CONF_FILE [] = "cel.conf"
 
static const char DATE_FORMAT [] = "%Y-%m-%d %T"
 
static int enablecel
 

Detailed Description

Asterisk Channel Event records.

See also

Definition in file cel_manager.c.

Macro Definition Documentation

◆ CEL_AMI_ENABLED_DEFAULT

#define CEL_AMI_ENABLED_DEFAULT   0

AMI CEL is off by default.

Definition at line 214 of file cel_manager.c.

◆ CEL_SHOW_USERDEF_DEFAULT

#define CEL_SHOW_USERDEF_DEFAULT   0

show_user_def is off by default

Definition at line 219 of file cel_manager.c.

◆ MANAGER_BACKEND_NAME

#define MANAGER_BACKEND_NAME   "Manager Event Logging"

Definition at line 221 of file cel_manager.c.

Function Documentation

◆ __reg_module()

static void __reg_module ( void  )
static

Definition at line 394 of file cel_manager.c.

◆ __unreg_module()

static void __unreg_module ( void  )
static

Definition at line 394 of file cel_manager.c.

◆ AST_MODULE_SELF_SYM()

struct ast_module * AST_MODULE_SELF_SYM ( void  )

Definition at line 394 of file cel_manager.c.

◆ load_config()

static int load_config ( int  reload)
static

Definition at line 310 of file cel_manager.c.

311{
312 const char *cat = NULL;
313 struct ast_config *cfg;
314 struct ast_flags config_flags = { reload ? CONFIG_FLAG_FILEUNCHANGED : 0 };
315 struct ast_variable *v;
316 int newenablecel = CEL_AMI_ENABLED_DEFAULT;
317 int new_cel_show_user_def = CEL_SHOW_USERDEF_DEFAULT;
318
319 cfg = ast_config_load(CONF_FILE, config_flags);
320 if (cfg == CONFIG_STATUS_FILEUNCHANGED) {
321 return 0;
322 }
323
324 if (cfg == CONFIG_STATUS_FILEINVALID) {
325 ast_log(LOG_WARNING, "Configuration file '%s' is invalid. CEL manager Module not activated.\n",
326 CONF_FILE);
327 enablecel = 0;
328 return -1;
329 } else if (!cfg) {
330 ast_log(LOG_WARNING, "Failed to load configuration file. CEL manager Module not activated.\n");
331 enablecel = 0;
332 return -1;
333 }
334
335 while ((cat = ast_category_browse(cfg, cat))) {
336 if (strcasecmp(cat, "manager")) {
337 continue;
338 }
339
340 for (v = ast_variable_browse(cfg, cat); v; v = v->next) {
341 if (!strcasecmp(v->name, "enabled")) {
342 newenablecel = ast_true(v->value) ? 1 : 0;
343 } else if (!strcasecmp(v->name, "show_user_defined")) {
344 new_cel_show_user_def = ast_true(v->value) ? 1 : 0;
345 } else {
346 ast_log(LOG_NOTICE, "Unknown option '%s' specified "
347 "for cel_manager.\n", v->name);
348 }
349 }
350 }
351
353
354 cel_show_user_def = new_cel_show_user_def;
355 if (enablecel && !newenablecel) {
357 } else if (!enablecel && newenablecel) {
359 ast_log(LOG_ERROR, "Unable to register Asterisk Call Manager CEL handling\n");
360 }
361 }
362 enablecel = newenablecel;
363
364 return 0;
365}
#define ast_log
Definition: astobj2.c:42
int ast_cel_backend_unregister(const char *name)
Unregister a CEL backend.
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:1798
#define CEL_SHOW_USERDEF_DEFAULT
show_user_def is off by default
Definition: cel_manager.c:219
static void manager_log(struct ast_event *event)
Definition: cel_manager.c:226
#define CEL_AMI_ENABLED_DEFAULT
AMI CEL is off by default.
Definition: cel_manager.c:214
static unsigned char cel_show_user_def
Definition: cel_manager.c:224
static int enablecel
Definition: cel_manager.c:216
static int reload(void)
Definition: cel_manager.c:382
#define MANAGER_BACKEND_NAME
Definition: cel_manager.c:221
static const char CONF_FILE[]
Definition: cel_manager.c:211
#define ast_config_load(filename, flags)
Load a config file.
char * ast_category_browse(struct ast_config *config, const char *prev_name)
Browse categories.
Definition: extconf.c:3326
@ CONFIG_FLAG_FILEUNCHANGED
#define CONFIG_STATUS_FILEUNCHANGED
#define CONFIG_STATUS_FILEINVALID
void ast_config_destroy(struct ast_config *cfg)
Destroys a config.
Definition: extconf.c:1289
struct ast_variable * ast_variable_browse(const struct ast_config *config, const char *category_name)
Definition: extconf.c:1215
#define LOG_ERROR
#define LOG_NOTICE
#define LOG_WARNING
#define NULL
Definition: resample.c:96
int attribute_pure ast_true(const char *val)
Make sure something is true. Determine if a string containing a boolean value is "true"....
Definition: utils.c:2199
Structure used to handle boolean flags.
Definition: utils.h:199
Structure for variables, used for configurations and for channel variables.
struct ast_variable * next

References ast_category_browse(), ast_cel_backend_register(), ast_cel_backend_unregister(), ast_config_destroy(), ast_config_load, ast_log, ast_true(), ast_variable_browse(), CEL_AMI_ENABLED_DEFAULT, cel_show_user_def, CEL_SHOW_USERDEF_DEFAULT, CONF_FILE, CONFIG_FLAG_FILEUNCHANGED, CONFIG_STATUS_FILEINVALID, CONFIG_STATUS_FILEUNCHANGED, enablecel, LOG_ERROR, LOG_NOTICE, LOG_WARNING, MANAGER_BACKEND_NAME, manager_log(), ast_variable::name, ast_variable::next, NULL, reload(), and ast_variable::value.

Referenced by load_module(), and reload().

◆ load_module()

static int load_module ( void  )
static

Definition at line 373 of file cel_manager.c.

374{
375 if (load_config(0)) {
377 }
378
380}
static int load_config(int reload)
Definition: cel_manager.c:310
@ AST_MODULE_LOAD_SUCCESS
Definition: module.h:70
@ AST_MODULE_LOAD_DECLINE
Module has failed to load, may be in an inconsistent state.
Definition: module.h:78

References AST_MODULE_LOAD_DECLINE, AST_MODULE_LOAD_SUCCESS, and load_config().

◆ manager_log()

static void manager_log ( struct ast_event event)
static

Definition at line 226 of file cel_manager.c.

227{
228 struct ast_tm timeresult;
229 char start_time[80] = "";
230 char user_defined_header[160];
231 const char *event_name;
232 struct ast_cel_event_record record = {
234 };
235 RAII_VAR(char *, tenant_id, NULL, ast_free);
236
237 if (!enablecel) {
238 return;
239 }
240
241 if (ast_cel_fill_record(event, &record)) {
242 return;
243 }
244
245 ast_localtime(&record.event_time, &timeresult, NULL);
246 ast_strftime(start_time, sizeof(start_time), DATE_FORMAT, &timeresult);
247
248 event_name = record.event_name;
249 user_defined_header[0] = '\0';
250 if (record.event_type == AST_CEL_USER_DEFINED) {
251 if (cel_show_user_def) {
252 snprintf(user_defined_header, sizeof(user_defined_header),
253 "UserDefType: %s\r\n", record.user_defined_name);
254 } else {
256 }
257 }
258
259 if (!ast_strlen_zero(record.tenant_id)) {
260 ast_asprintf(&tenant_id, "TenantID: %s\r\n", record.tenant_id);
261 }
262
264 "EventName: %s\r\n"
265 "AccountCode: %s\r\n"
266 "CallerIDnum: %s\r\n"
267 "CallerIDname: %s\r\n"
268 "CallerIDani: %s\r\n"
269 "CallerIDrdnis: %s\r\n"
270 "CallerIDdnid: %s\r\n"
271 "Exten: %s\r\n"
272 "Context: %s\r\n"
273 "Channel: %s\r\n"
274 "Application: %s\r\n"
275 "AppData: %s\r\n"
276 "EventTime: %s\r\n"
277 "AMAFlags: %s\r\n"
278 "UniqueID: %s\r\n"
279 "LinkedID: %s\r\n"
280 "%s"
281 "Userfield: %s\r\n"
282 "Peer: %s\r\n"
283 "PeerAccount: %s\r\n"
284 "%s"
285 "Extra: %s\r\n",
287 record.account_code,
288 record.caller_id_num,
289 record.caller_id_name,
290 record.caller_id_ani,
291 record.caller_id_rdnis,
292 record.caller_id_dnid,
293 record.extension,
294 record.context,
295 record.channel_name,
296 record.application_name,
297 record.application_data,
298 start_time,
300 record.unique_id,
301 record.linked_id,
303 record.user_field,
304 record.peer,
305 record.peer_account,
306 user_defined_header,
307 record.extra);
308}
#define ast_free(a)
Definition: astmm.h:180
#define ast_asprintf(ret, fmt,...)
A wrapper for asprintf()
Definition: astmm.h:267
@ AST_CEL_USER_DEFINED
a user-defined event, the event name field should be set
Definition: cel.h:69
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:837
#define AST_CEL_EVENT_RECORD_VERSION
struct ABI version
Definition: cel.h:143
static const char DATE_FORMAT[]
Definition: cel_manager.c:209
const char * ast_channel_amaflags2string(enum ama_flags flags)
Convert the enum representation of an AMA flag to a string representation.
Definition: channel.c:4331
struct ast_tm * ast_localtime(const struct timeval *timep, struct ast_tm *p_tm, const char *zone)
Timezone-independent version of localtime_r(3).
Definition: localtime.c:1739
int ast_strftime(char *buf, size_t len, const char *format, const struct ast_tm *tm)
Special version of strftime(3) that handles fractions of a second. Takes the same arguments as strfti...
Definition: localtime.c:2524
#define manager_event(category, event, contents,...)
External routines may send asterisk manager events this way.
Definition: manager.h:254
#define EVENT_FLAG_CALL
Definition: manager.h:76
static force_inline int attribute_pure ast_strlen_zero(const char *s)
Definition: strings.h:65
Helper struct for getting the fields out of a CEL event.
Definition: cel.h:138
const char * caller_id_dnid
Definition: cel.h:157
const char * application_data
Definition: cel.h:162
const char * account_code
Definition: cel.h:163
const char * caller_id_rdnis
Definition: cel.h:156
const char * extra
Definition: cel.h:171
const char * extension
Definition: cel.h:158
const char * caller_id_num
Definition: cel.h:154
const char * channel_name
Definition: cel.h:160
const char * linked_id
Definition: cel.h:166
const char * peer_account
Definition: cel.h:164
const char * peer
Definition: cel.h:170
enum ast_cel_event_type event_type
Definition: cel.h:149
const char * unique_id
Definition: cel.h:165
const char * user_defined_name
Definition: cel.h:152
const char * context
Definition: cel.h:159
const char * application_name
Definition: cel.h:161
struct timeval event_time
Definition: cel.h:150
uint32_t version
struct ABI version
Definition: cel.h:148
const char * tenant_id
Definition: cel.h:167
const char * user_field
Definition: cel.h:169
const char * caller_id_ani
Definition: cel.h:155
const char * caller_id_name
Definition: cel.h:153
const char * event_name
Definition: cel.h:151
Definition: astman.c:222
#define RAII_VAR(vartype, varname, initval, dtor)
Declare a variable that will call a destructor function when it goes out of scope.
Definition: utils.h:941

References ast_cel_event_record::account_code, ast_cel_event_record::amaflag, ast_cel_event_record::application_data, ast_cel_event_record::application_name, ast_asprintf, AST_CEL_EVENT_RECORD_VERSION, ast_cel_fill_record(), AST_CEL_USER_DEFINED, ast_channel_amaflags2string(), ast_free, ast_localtime(), ast_strftime(), ast_strlen_zero(), ast_cel_event_record::caller_id_ani, ast_cel_event_record::caller_id_dnid, ast_cel_event_record::caller_id_name, ast_cel_event_record::caller_id_num, ast_cel_event_record::caller_id_rdnis, cel_show_user_def, ast_cel_event_record::channel_name, ast_cel_event_record::context, DATE_FORMAT, enablecel, EVENT_FLAG_CALL, ast_cel_event_record::event_name, ast_cel_event_record::event_time, ast_cel_event_record::event_type, ast_cel_event_record::extension, ast_cel_event_record::extra, ast_cel_event_record::linked_id, manager_event, NULL, ast_cel_event_record::peer, ast_cel_event_record::peer_account, RAII_VAR, ast_cel_event_record::tenant_id, ast_cel_event_record::unique_id, ast_cel_event_record::user_defined_name, ast_cel_event_record::user_field, and ast_cel_event_record::version.

Referenced by load_config().

◆ reload()

static int reload ( void  )
static

Definition at line 382 of file cel_manager.c.

383{
384 return load_config(1);
385}

References load_config().

Referenced by load_config().

◆ unload_module()

static int unload_module ( void  )
static

Definition at line 367 of file cel_manager.c.

368{
370 return 0;
371}

References ast_cel_backend_unregister(), and MANAGER_BACKEND_NAME.

Variable Documentation

◆ __mod_info

struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_LOAD_ORDER , .description = "Asterisk Manager Interface CEL Backend" , .key = "This paragraph is copyright (c) 2006 by Digium, Inc. \In order for your module to load, it must return this \key via a function called \"key\". Any code which \includes this paragraph must be licensed under the GNU \General Public License version 2 or later (at your \option). In addition to Digium's general reservations \of rights, Digium expressly reserves the right to \allow other parties to license this paragraph under \different terms. Any use of Digium, Inc. trademarks or \logos (including \"Asterisk\" or \"Digium\") without \express written permission of Digium, Inc. is prohibited.\n" , .buildopt_sum = AST_BUILDOPT_SUM, .support_level = AST_MODULE_SUPPORT_CORE, .load = load_module, .unload = unload_module, .reload = reload, .load_pri = AST_MODPRI_CDR_DRIVER, .requires = "cel", }
static

Definition at line 394 of file cel_manager.c.

◆ ast_module_info

const struct ast_module_info* ast_module_info = &__mod_info
static

Definition at line 394 of file cel_manager.c.

◆ cel_show_user_def

unsigned char cel_show_user_def
static

TRUE if we should set the EventName header to USER_DEFINED on user events.

Definition at line 224 of file cel_manager.c.

Referenced by load_config(), and manager_log().

◆ CONF_FILE

const char CONF_FILE[] = "cel.conf"
static

Definition at line 211 of file cel_manager.c.

Referenced by load_config().

◆ DATE_FORMAT

const char DATE_FORMAT[] = "%Y-%m-%d %T"
static

Definition at line 209 of file cel_manager.c.

Referenced by manager_log().

◆ enablecel

int enablecel
static

Definition at line 216 of file cel_manager.c.

Referenced by load_config(), and manager_log().