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.

Defines

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

Functions

static void __reg_module (void)
static void __unreg_module (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, }
static 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.


Define Documentation

#define CEL_AMI_ENABLED_DEFAULT   0

AMI CEL is off by default.

Definition at line 213 of file cel_manager.c.

Referenced by load_config().

#define CEL_SHOW_USERDEF_DEFAULT   0

show_user_def is off by default

Definition at line 218 of file cel_manager.c.

Referenced by load_config(), and process_my_load_module().

#define MANAGER_BACKEND_NAME   "Manager Event Logging"

Definition at line 220 of file cel_manager.c.

Referenced by load_config(), and unload_module().


Function Documentation

static void __reg_module ( void   )  [static]

Definition at line 385 of file cel_manager.c.

static void __unreg_module ( void   )  [static]

Definition at line 385 of file cel_manager.c.

static int load_config ( int  reload  )  [static]

Definition at line 302 of file cel_manager.c.

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_USERDEF_DEFAULT, CONFIG_FLAG_FILEUNCHANGED, CONFIG_STATUS_FILEINVALID, CONFIG_STATUS_FILEUNCHANGED, LOG_ERROR, LOG_NOTICE, LOG_WARNING, MANAGER_BACKEND_NAME, manager_log(), ast_variable::name, ast_variable::next, NULL, and ast_variable::value.

00303 {
00304    const char *cat = NULL;
00305    struct ast_config *cfg;
00306    struct ast_flags config_flags = { reload ? CONFIG_FLAG_FILEUNCHANGED : 0 };
00307    struct ast_variable *v;
00308    int newenablecel = CEL_AMI_ENABLED_DEFAULT;
00309    int new_cel_show_user_def = CEL_SHOW_USERDEF_DEFAULT;
00310 
00311    cfg = ast_config_load(CONF_FILE, config_flags);
00312    if (cfg == CONFIG_STATUS_FILEUNCHANGED) {
00313       return 0;
00314    }
00315 
00316    if (cfg == CONFIG_STATUS_FILEINVALID) {
00317       ast_log(LOG_WARNING, "Configuration file '%s' is invalid. CEL manager Module not activated.\n",
00318          CONF_FILE);
00319       enablecel = 0;
00320       return -1;
00321    } else if (!cfg) {
00322       ast_log(LOG_WARNING, "Failed to load configuration file. CEL manager Module not activated.\n");
00323       enablecel = 0;
00324       return -1;
00325    }
00326 
00327    while ((cat = ast_category_browse(cfg, cat))) {
00328       if (strcasecmp(cat, "manager")) {
00329          continue;
00330       }
00331 
00332       for (v = ast_variable_browse(cfg, cat); v; v = v->next) {
00333          if (!strcasecmp(v->name, "enabled")) {
00334             newenablecel = ast_true(v->value) ? 1 : 0;
00335          } else if (!strcasecmp(v->name, "show_user_defined")) {
00336             new_cel_show_user_def = ast_true(v->value) ? 1 : 0;
00337          } else {
00338             ast_log(LOG_NOTICE, "Unknown option '%s' specified "
00339                   "for cel_manager.\n", v->name);
00340          }
00341       }
00342    }
00343 
00344    ast_config_destroy(cfg);
00345 
00346    cel_show_user_def = new_cel_show_user_def;
00347    if (enablecel && !newenablecel) {
00348       ast_cel_backend_unregister(MANAGER_BACKEND_NAME);
00349    } else if (!enablecel && newenablecel) {
00350       if (ast_cel_backend_register(MANAGER_BACKEND_NAME, manager_log)) {
00351          ast_log(LOG_ERROR, "Unable to register Asterisk Call Manager CEL handling\n");
00352       }
00353    }
00354    enablecel = newenablecel;
00355 
00356    return 0;
00357 }

static int load_module ( void   )  [static]

Definition at line 365 of file cel_manager.c.

References AST_MODULE_LOAD_DECLINE, AST_MODULE_LOAD_SUCCESS, and load_config().

00366 {
00367    if (load_config(0)) {
00368       return AST_MODULE_LOAD_DECLINE;
00369    }
00370 
00371    return AST_MODULE_LOAD_SUCCESS;
00372 }

static void manager_log ( struct ast_event event  )  [static]

Definition at line 225 of file cel_manager.c.

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_CEL_EVENT_RECORD_VERSION, ast_cel_fill_record(), AST_CEL_USER_DEFINED, ast_channel_amaflags2string(), ast_localtime(), ast_strftime(), 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, ast_cel_event_record::channel_name, ast_cel_event_record::context, 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, 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.

00226 {
00227    struct ast_tm timeresult;
00228    char start_time[80] = "";
00229    char user_defined_header[160];
00230    const char *event_name;
00231    struct ast_cel_event_record record = {
00232       .version = AST_CEL_EVENT_RECORD_VERSION,
00233    };
00234 
00235    if (!enablecel) {
00236       return;
00237    }
00238 
00239    if (ast_cel_fill_record(event, &record)) {
00240       return;
00241    }
00242 
00243    ast_localtime(&record.event_time, &timeresult, NULL);
00244    ast_strftime(start_time, sizeof(start_time), DATE_FORMAT, &timeresult);
00245 
00246    event_name = record.event_name;
00247    user_defined_header[0] = '\0';
00248    if (record.event_type == AST_CEL_USER_DEFINED) {
00249       if (cel_show_user_def) {
00250          snprintf(user_defined_header, sizeof(user_defined_header),
00251             "UserDefType: %s\r\n", record.user_defined_name);
00252       } else {
00253          event_name = record.user_defined_name;
00254       }
00255    }
00256 
00257    manager_event(EVENT_FLAG_CALL, "CEL",
00258       "EventName: %s\r\n"
00259       "AccountCode: %s\r\n"
00260       "CallerIDnum: %s\r\n"
00261       "CallerIDname: %s\r\n"
00262       "CallerIDani: %s\r\n"
00263       "CallerIDrdnis: %s\r\n"
00264       "CallerIDdnid: %s\r\n"
00265       "Exten: %s\r\n"
00266       "Context: %s\r\n"
00267       "Channel: %s\r\n"
00268       "Application: %s\r\n"
00269       "AppData: %s\r\n"
00270       "EventTime: %s\r\n"
00271       "AMAFlags: %s\r\n"
00272       "UniqueID: %s\r\n"
00273       "LinkedID: %s\r\n"
00274       "Userfield: %s\r\n"
00275       "Peer: %s\r\n"
00276       "PeerAccount: %s\r\n"
00277       "%s"
00278       "Extra: %s\r\n",
00279       event_name,
00280       record.account_code,
00281       record.caller_id_num,
00282       record.caller_id_name,
00283       record.caller_id_ani,
00284       record.caller_id_rdnis,
00285       record.caller_id_dnid,
00286       record.extension,
00287       record.context,
00288       record.channel_name,
00289       record.application_name,
00290       record.application_data,
00291       start_time,
00292       ast_channel_amaflags2string(record.amaflag),
00293       record.unique_id,
00294       record.linked_id,
00295       record.user_field,
00296       record.peer,
00297       record.peer_account,
00298       user_defined_header,
00299       record.extra);
00300 }

static int reload ( void   )  [static]

Definition at line 374 of file cel_manager.c.

References load_config().

00375 {
00376    return load_config(1);
00377 }

static int unload_module ( void   )  [static]

Definition at line 359 of file cel_manager.c.

References ast_cel_backend_unregister(), and MANAGER_BACKEND_NAME.

00360 {
00361    ast_cel_backend_unregister(MANAGER_BACKEND_NAME);
00362    return 0;
00363 }


Variable Documentation

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, } [static]

Definition at line 385 of file cel_manager.c.

Definition at line 385 of file cel_manager.c.

unsigned char cel_show_user_def [static]

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

Definition at line 223 of file cel_manager.c.

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

Definition at line 210 of file cel_manager.c.

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

Definition at line 208 of file cel_manager.c.

int enablecel [static]

Definition at line 215 of file cel_manager.c.


Generated on Thu Apr 16 06:29:28 2015 for Asterisk - The Open Source Telephony Project by  doxygen 1.5.6