Mon Mar 19 11:30:23 2012

Asterisk developer's documentation


cel.c

Go to the documentation of this file.
00001 /*
00002  * Asterisk -- An open source telephony toolkit.
00003  *
00004  * Copyright (C) 2007 - 2009, Digium, Inc.
00005  *
00006  * See http://www.asterisk.org for more information about
00007  * the Asterisk project. Please do not directly contact
00008  * any of the maintainers of this project for assistance;
00009  * the project provides a web site, mailing lists and IRC
00010  * channels for your use.
00011  *
00012  * This program is free software, distributed under the terms of
00013  * the GNU General Public License Version 2. See the LICENSE file
00014  * at the top of the source tree.
00015  */
00016 
00017 /*!
00018  * \file
00019  *
00020  * \brief Channel Event Logging API
00021  *
00022  * \author Steve Murphy <murf@digium.com>
00023  * \author Russell Bryant <russell@digium.com>
00024  *
00025  * \todo Do thorough testing of all transfer methods to ensure that BLINDTRANSFER,
00026  *       ATTENDEDTRANSFER, BRIDGE_START, and BRIDGE_END events are all reported
00027  *       as expected.
00028  */
00029 
00030 #include "asterisk.h"
00031 
00032 ASTERISK_FILE_VERSION(__FILE__, "$Revision: 350555 $")
00033 
00034 #include "asterisk/_private.h"
00035 
00036 #include "asterisk/channel.h"
00037 #include "asterisk/pbx.h"
00038 #include "asterisk/cel.h"
00039 #include "asterisk/logger.h"
00040 #include "asterisk/linkedlists.h"
00041 #include "asterisk/utils.h"
00042 #include "asterisk/config.h"
00043 #include "asterisk/cli.h"
00044 #include "asterisk/astobj2.h"
00045 
00046 /*! Is the CEL subsystem enabled ? */
00047 static unsigned char cel_enabled;
00048 
00049 /*! \brief CEL is off by default */
00050 #define CEL_ENABLED_DEFAULT      0
00051 
00052 /*! 
00053  * \brief which events we want to track 
00054  *
00055  * \note bit field, up to 64 events
00056  */
00057 static int64_t eventset;
00058 
00059 /*!
00060  * \brief Maximum possible CEL event IDs
00061  * \note This limit is currently imposed by the eventset definition
00062  */
00063 #define CEL_MAX_EVENT_IDS 64
00064 
00065 /*! 
00066  * \brief Track no events by default.
00067  */
00068 #define CEL_DEFAULT_EVENTS 0
00069 
00070 /*!
00071  * \brief Number of buckets for the appset container
00072  */
00073 #define NUM_APP_BUCKETS    97
00074 
00075 /*!
00076  * \brief Container of Asterisk application names
00077  *
00078  * The apps in this container are the applications that were specified
00079  * in the configuration as applications that CEL events should be generated
00080  * for when they start and end on a channel.
00081  */
00082 static struct ao2_container *appset;
00083 
00084 /*!
00085  * \brief Configured date format for event timestamps
00086  */
00087 static char cel_dateformat[256];
00088 
00089 /*!
00090  * \brief Map of ast_cel_event_type to strings
00091  */
00092 static const char * const cel_event_types[CEL_MAX_EVENT_IDS] = {
00093    [0]                        = "ALL",
00094    [AST_CEL_CHANNEL_START]    = "CHAN_START",
00095    [AST_CEL_CHANNEL_END]      = "CHAN_END",
00096    [AST_CEL_ANSWER]           = "ANSWER",
00097    [AST_CEL_HANGUP]           = "HANGUP",
00098    [AST_CEL_APP_START]        = "APP_START",
00099    [AST_CEL_APP_END]          = "APP_END",
00100    [AST_CEL_BRIDGE_START]     = "BRIDGE_START",
00101    [AST_CEL_BRIDGE_END]       = "BRIDGE_END",
00102    [AST_CEL_BRIDGE_UPDATE]    = "BRIDGE_UPDATE",
00103    [AST_CEL_CONF_START]       = "CONF_START",
00104    [AST_CEL_CONF_END]         = "CONF_END",
00105    [AST_CEL_PARK_START]       = "PARK_START",
00106    [AST_CEL_PARK_END]         = "PARK_END",
00107    [AST_CEL_TRANSFER]         = "TRANSFER",
00108    [AST_CEL_USER_DEFINED]     = "USER_DEFINED",
00109    [AST_CEL_CONF_ENTER]       = "CONF_ENTER",
00110    [AST_CEL_CONF_EXIT]        = "CONF_EXIT",
00111    [AST_CEL_BLINDTRANSFER]    = "BLINDTRANSFER",
00112    [AST_CEL_ATTENDEDTRANSFER] = "ATTENDEDTRANSFER",
00113    [AST_CEL_PICKUP]           = "PICKUP",
00114    [AST_CEL_FORWARD]          = "FORWARD",
00115    [AST_CEL_3WAY_START]       = "3WAY_START",
00116    [AST_CEL_3WAY_END]         = "3WAY_END",
00117    [AST_CEL_HOOKFLASH]        = "HOOKFLASH",
00118    [AST_CEL_LINKEDID_END]     = "LINKEDID_END",
00119 };
00120 
00121 /*!
00122  * \brief Map of ast_cel_ama_flags to strings
00123  */
00124 static const char * const cel_ama_flags[AST_CEL_AMA_FLAG_TOTAL] = {
00125    [AST_CEL_AMA_FLAG_NONE]          = "NONE",
00126    [AST_CEL_AMA_FLAG_OMIT]          = "OMIT",
00127    [AST_CEL_AMA_FLAG_BILLING]       = "BILLING",
00128    [AST_CEL_AMA_FLAG_DOCUMENTATION] = "DOCUMENTATION",
00129 };
00130 
00131 unsigned int ast_cel_check_enabled(void)
00132 {
00133    return cel_enabled;
00134 }
00135 
00136 static int print_app(void *obj, void *arg, int flags)
00137 {
00138    struct ast_cli_args *a = arg;
00139 
00140    ast_cli(a->fd, "CEL Tracking Application: %s\n", (const char *) obj);
00141 
00142    return 0;
00143 }
00144 
00145 static void print_cel_sub(const struct ast_event *event, void *data)
00146 {
00147    struct ast_cli_args *a = data;
00148 
00149    ast_cli(a->fd, "CEL Event Subscriber: %s\n",
00150          ast_event_get_ie_str(event, AST_EVENT_IE_DESCRIPTION));
00151 }
00152 
00153 static char *handle_cli_status(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
00154 {
00155    unsigned int i;
00156    struct ast_event_sub *sub;
00157 
00158    switch (cmd) {
00159    case CLI_INIT:
00160       e->command = "cel show status";
00161       e->usage =
00162          "Usage: cel show status\n"
00163          "       Displays the Channel Event Logging system status.\n";
00164       return NULL;
00165    case CLI_GENERATE:
00166       return NULL;
00167    case CLI_HANDLER:
00168       break;
00169    }
00170 
00171    if (a->argc > 3) {
00172       return CLI_SHOWUSAGE;
00173    }
00174 
00175    ast_cli(a->fd, "CEL Logging: %s\n", cel_enabled ? "Enabled" : "Disabled");
00176 
00177    if (!cel_enabled) {
00178       return CLI_SUCCESS;
00179    }
00180 
00181    for (i = 0; i < (sizeof(eventset) * 8); i++) {
00182       const char *name;
00183 
00184       if (!(eventset & ((int64_t) 1 << i))) {
00185          continue;
00186       }
00187 
00188       name = ast_cel_get_type_name(i);
00189       if (strcasecmp(name, "Unknown")) {
00190          ast_cli(a->fd, "CEL Tracking Event: %s\n", name);
00191       }
00192    }
00193 
00194    ao2_callback(appset, OBJ_NODATA, print_app, a);
00195 
00196    if (!(sub = ast_event_subscribe_new(AST_EVENT_SUB, print_cel_sub, a))) {
00197       return CLI_FAILURE;
00198    }
00199    ast_event_sub_append_ie_uint(sub, AST_EVENT_IE_EVENTTYPE, AST_EVENT_CEL);
00200    ast_event_report_subs(sub);
00201    ast_event_sub_destroy(sub);
00202    sub = NULL;
00203 
00204    return CLI_SUCCESS;
00205 }
00206 
00207 static struct ast_cli_entry cli_status = AST_CLI_DEFINE(handle_cli_status, "Display the CEL status");
00208 
00209 enum ast_cel_event_type ast_cel_str_to_event_type(const char *name)
00210 {
00211    unsigned int i;
00212 
00213    for (i = 0; i < ARRAY_LEN(cel_event_types); i++) {
00214       if (!cel_event_types[i]) {
00215          continue;
00216       }
00217 
00218       if (!strcasecmp(name, cel_event_types[i])) {
00219          return i;
00220       }
00221    }
00222 
00223    return -1;
00224 }
00225 
00226 static int ast_cel_track_event(enum ast_cel_event_type et)
00227 {
00228    return (eventset & ((int64_t) 1 << et));
00229 }
00230 
00231 static void parse_events(const char *val)
00232 {
00233    char *events = ast_strdupa(val);
00234    char *cur_event;
00235 
00236    while ((cur_event = strsep(&events, ","))) {
00237       enum ast_cel_event_type event_type;
00238 
00239       cur_event = ast_strip(cur_event);
00240       if (ast_strlen_zero(cur_event)) {
00241          continue;
00242       }
00243 
00244       event_type = ast_cel_str_to_event_type(cur_event);
00245 
00246       if (event_type == 0) {
00247          /* All events */
00248          eventset = (int64_t) -1;
00249       } else if (event_type == -1) {
00250          ast_log(LOG_WARNING, "Unknown event name '%s'\n",
00251                cur_event);
00252       } else {
00253          eventset |= ((int64_t) 1 << event_type);
00254       }
00255    }
00256 }
00257 
00258 static void parse_apps(const char *val)
00259 {
00260    char *apps = ast_strdupa(val);
00261    char *cur_app;
00262 
00263    if (!ast_cel_track_event(AST_CEL_APP_START) && !ast_cel_track_event(AST_CEL_APP_END)) {
00264       ast_log(LOG_WARNING, "An apps= config line, but not tracking APP events\n");
00265       return;
00266    }
00267 
00268    while ((cur_app = strsep(&apps, ","))) {
00269       char *app;
00270 
00271       cur_app = ast_strip(cur_app);
00272       if (ast_strlen_zero(cur_app)) {
00273          continue;
00274       }
00275 
00276       if (!(app = ao2_alloc(strlen(cur_app) + 1, NULL))) {
00277          continue;
00278       }
00279       strcpy(app, cur_app);
00280 
00281       ao2_link(appset, app);
00282       ao2_ref(app, -1);
00283       app = NULL;
00284    }
00285 }
00286 
00287 AST_MUTEX_DEFINE_STATIC(reload_lock);
00288 
00289 static int do_reload(void)
00290 {
00291    struct ast_config *config;
00292    const char *enabled_value;
00293    const char *val;
00294    int res = 0;
00295    struct ast_flags config_flags = { 0, };
00296    const char *s;
00297 
00298    ast_mutex_lock(&reload_lock);
00299 
00300    /* Reset all settings before reloading configuration */
00301    cel_enabled = CEL_ENABLED_DEFAULT;
00302    eventset = CEL_DEFAULT_EVENTS;
00303    *cel_dateformat = '\0';
00304    ao2_callback(appset, OBJ_UNLINK | OBJ_NODATA | OBJ_MULTIPLE, NULL, NULL);
00305 
00306    config = ast_config_load2("cel.conf", "cel", config_flags);
00307 
00308    if (config == CONFIG_STATUS_FILEMISSING) {
00309       config = NULL;
00310       goto return_cleanup;
00311    }
00312 
00313    if ((enabled_value = ast_variable_retrieve(config, "general", "enable"))) {
00314       cel_enabled = ast_true(enabled_value);
00315    }
00316 
00317    if (!cel_enabled) {
00318       goto return_cleanup;
00319    }
00320 
00321    /* get the date format for logging */
00322    if ((s = ast_variable_retrieve(config, "general", "dateformat"))) {
00323       ast_copy_string(cel_dateformat, s, sizeof(cel_dateformat));
00324    }
00325 
00326    if ((val = ast_variable_retrieve(config, "general", "events"))) {
00327       parse_events(val);
00328    }
00329 
00330    if ((val = ast_variable_retrieve(config, "general", "apps"))) {
00331       parse_apps(val);
00332    }
00333 
00334 return_cleanup:
00335    ast_verb(3, "CEL logging %sabled.\n", cel_enabled ? "en" : "dis");
00336 
00337    ast_mutex_unlock(&reload_lock);
00338 
00339    if (config) {
00340       ast_config_destroy(config);
00341    }
00342 
00343    return res;
00344 }
00345 
00346 const char *ast_cel_get_type_name(enum ast_cel_event_type type)
00347 {
00348    return S_OR(cel_event_types[type], "Unknown");
00349 }
00350 
00351 const char *ast_cel_get_ama_flag_name(enum ast_cel_ama_flag flag)
00352 {
00353    if (flag < 0 || flag >= ARRAY_LEN(cel_ama_flags)) {
00354       ast_log(LOG_WARNING, "Invalid AMA flag: %d\n", flag);
00355       return "Unknown";
00356    }
00357 
00358    return S_OR(cel_ama_flags[flag], "Unknown");
00359 }
00360 
00361 /* called whenever a channel is destroyed or a linkedid is changed to
00362  * potentially emit a CEL_LINKEDID_END event */
00363 
00364 struct channel_find_data {
00365    const struct ast_channel *chan;
00366    const char *linkedid;
00367 };
00368 
00369 static int linkedid_match(void *obj, void *arg, void *data, int flags)
00370 {
00371    struct ast_channel *c = obj;
00372    struct channel_find_data *find_dat = data;
00373    int res;
00374 
00375    ast_channel_lock(c);
00376    res = (c != find_dat->chan && c->linkedid && !strcmp(find_dat->linkedid, c->linkedid));
00377    ast_channel_unlock(c);
00378 
00379    return res ? CMP_MATCH | CMP_STOP : 0;
00380 }
00381 
00382 void ast_cel_check_retire_linkedid(struct ast_channel *chan)
00383 {
00384    const char *linkedid = chan->linkedid;
00385    struct channel_find_data find_dat;
00386 
00387    /* make sure we need to do all this work */
00388 
00389    if (!ast_strlen_zero(linkedid) && ast_cel_track_event(AST_CEL_LINKEDID_END)) {
00390       struct ast_channel *tmp = NULL;
00391       find_dat.chan = chan;
00392       find_dat.linkedid = linkedid;
00393       if ((tmp = ast_channel_callback(linkedid_match, NULL, &find_dat, 0))) {
00394          tmp = ast_channel_unref(tmp);
00395       } else {
00396          ast_cel_report_event(chan, AST_CEL_LINKEDID_END, NULL, NULL, NULL);
00397       }
00398    }
00399 }
00400 
00401 struct ast_channel *ast_cel_fabricate_channel_from_event(const struct ast_event *event)
00402 {
00403    struct varshead *headp;
00404    struct ast_var_t *newvariable;
00405    char timebuf[30];
00406    struct ast_channel *tchan;
00407    struct ast_cel_event_record record = {
00408       .version = AST_CEL_EVENT_RECORD_VERSION,
00409    };
00410 
00411    /* do not call ast_channel_alloc because this is not really a real channel */
00412    if (!(tchan = ast_dummy_channel_alloc())) {
00413       return NULL;
00414    }
00415 
00416    headp = &tchan->varshead;
00417 
00418    /* first, get the variables from the event */
00419    if (ast_cel_fill_record(event, &record)) {
00420       ast_channel_unref(tchan);
00421       return NULL;
00422    }
00423 
00424    /* next, fill the channel with their data */
00425    if ((newvariable = ast_var_assign("eventtype", record.event_name))) {
00426       AST_LIST_INSERT_HEAD(headp, newvariable, entries);
00427    }
00428 
00429    if (ast_strlen_zero(cel_dateformat)) {
00430       snprintf(timebuf, sizeof(timebuf), "%ld.%06ld", (long) record.event_time.tv_sec,
00431             (long) record.event_time.tv_usec);
00432    } else {
00433       struct ast_tm tm;
00434       ast_localtime(&record.event_time, &tm, NULL);
00435       ast_strftime(timebuf, sizeof(timebuf), cel_dateformat, &tm);
00436    }
00437 
00438    if ((newvariable = ast_var_assign("eventtime", timebuf))) {
00439       AST_LIST_INSERT_HEAD(headp, newvariable, entries);
00440    }
00441 
00442    if ((newvariable = ast_var_assign("userdeftype", record.user_defined_name))) {
00443       AST_LIST_INSERT_HEAD(headp, newvariable, entries);
00444    }
00445    if ((newvariable = ast_var_assign("eventextra", record.extra))) {
00446       AST_LIST_INSERT_HEAD(headp, newvariable, entries);
00447    }
00448 
00449    tchan->caller.id.name.valid = 1;
00450    tchan->caller.id.name.str = ast_strdup(record.caller_id_name);
00451    tchan->caller.id.number.valid = 1;
00452    tchan->caller.id.number.str = ast_strdup(record.caller_id_num);
00453    tchan->caller.ani.number.valid = 1;
00454    tchan->caller.ani.number.str = ast_strdup(record.caller_id_ani);
00455    tchan->redirecting.from.number.valid = 1;
00456    tchan->redirecting.from.number.str = ast_strdup(record.caller_id_rdnis);
00457    tchan->dialed.number.str = ast_strdup(record.caller_id_dnid);
00458 
00459    ast_copy_string(tchan->exten, record.extension, sizeof(tchan->exten));
00460    ast_copy_string(tchan->context, record.context, sizeof(tchan->context));
00461    ast_string_field_set(tchan, name, record.channel_name);
00462    ast_string_field_set(tchan, uniqueid, record.unique_id);
00463    ast_string_field_set(tchan, linkedid, record.linked_id);
00464    ast_string_field_set(tchan, accountcode, record.account_code);
00465    ast_string_field_set(tchan, peeraccount, record.peer_account);
00466    ast_string_field_set(tchan, userfield, record.user_field);
00467 
00468    if ((newvariable = ast_var_assign("BRIDGEPEER", record.peer))) {
00469       AST_LIST_INSERT_HEAD(headp, newvariable, entries);
00470    }
00471 
00472    tchan->appl = ast_strdup(record.application_name);
00473    tchan->data = ast_strdup(record.application_data);
00474    tchan->amaflags = record.amaflag;
00475 
00476    return tchan;
00477 }
00478 
00479 int ast_cel_report_event(struct ast_channel *chan, enum ast_cel_event_type event_type,
00480       const char *userdefevname, const char *extra, struct ast_channel *peer2)
00481 {
00482    struct timeval eventtime;
00483    struct ast_event *ev;
00484    const char *peername = "";
00485    struct ast_channel *peer;
00486 
00487    ast_channel_lock(chan);
00488    peer = ast_bridged_channel(chan);
00489    if (peer) {
00490       ast_channel_ref(peer);
00491    }
00492    ast_channel_unlock(chan);
00493 
00494    /* Make sure a reload is not occurring while we're checking to see if this
00495     * is an event that we care about.  We could lose an important event in this
00496     * process otherwise. */
00497    ast_mutex_lock(&reload_lock);
00498 
00499    if (!cel_enabled || !ast_cel_track_event(event_type)) {
00500       ast_mutex_unlock(&reload_lock);
00501       if (peer) {
00502          ast_channel_unref(peer);
00503       }
00504       return 0;
00505    }
00506 
00507    if (event_type == AST_CEL_APP_START || event_type == AST_CEL_APP_END) {
00508       char *app;
00509       if (!(app = ao2_find(appset, (char *) chan->appl, OBJ_POINTER))) {
00510          ast_mutex_unlock(&reload_lock);
00511          if (peer) {
00512             ast_channel_unref(peer);
00513          }
00514          return 0;
00515       }
00516       ao2_ref(app, -1);
00517    }
00518 
00519    ast_mutex_unlock(&reload_lock);
00520 
00521    if (peer) {
00522       ast_channel_lock(peer);
00523       peername = ast_strdupa(peer->name);
00524       ast_channel_unlock(peer);
00525    } else if (peer2) {
00526       ast_channel_lock(peer2);
00527       peername = ast_strdupa(peer2->name);
00528       ast_channel_unlock(peer2);
00529    }
00530 
00531    if (!userdefevname) {
00532       userdefevname = "";
00533    }
00534 
00535    if (!extra) {
00536       extra = "";
00537    }
00538 
00539    eventtime = ast_tvnow();
00540 
00541    ast_channel_lock(chan);
00542 
00543    ev = ast_event_new(AST_EVENT_CEL,
00544       AST_EVENT_IE_CEL_EVENT_TYPE, AST_EVENT_IE_PLTYPE_UINT, event_type,
00545       AST_EVENT_IE_CEL_EVENT_TIME, AST_EVENT_IE_PLTYPE_UINT, eventtime.tv_sec,
00546       AST_EVENT_IE_CEL_EVENT_TIME_USEC, AST_EVENT_IE_PLTYPE_UINT, eventtime.tv_usec,
00547       AST_EVENT_IE_CEL_USEREVENT_NAME, AST_EVENT_IE_PLTYPE_STR, userdefevname,
00548       AST_EVENT_IE_CEL_CIDNAME, AST_EVENT_IE_PLTYPE_STR,
00549          S_COR(chan->caller.id.name.valid, chan->caller.id.name.str, ""),
00550       AST_EVENT_IE_CEL_CIDNUM, AST_EVENT_IE_PLTYPE_STR,
00551          S_COR(chan->caller.id.number.valid, chan->caller.id.number.str, ""),
00552       AST_EVENT_IE_CEL_CIDANI, AST_EVENT_IE_PLTYPE_STR,
00553          S_COR(chan->caller.ani.number.valid, chan->caller.ani.number.str, ""),
00554       AST_EVENT_IE_CEL_CIDRDNIS, AST_EVENT_IE_PLTYPE_STR,
00555          S_COR(chan->redirecting.from.number.valid, chan->redirecting.from.number.str, ""),
00556       AST_EVENT_IE_CEL_CIDDNID, AST_EVENT_IE_PLTYPE_STR,
00557          S_OR(chan->dialed.number.str, ""),
00558       AST_EVENT_IE_CEL_EXTEN, AST_EVENT_IE_PLTYPE_STR, chan->exten,
00559       AST_EVENT_IE_CEL_CONTEXT, AST_EVENT_IE_PLTYPE_STR, chan->context,
00560       AST_EVENT_IE_CEL_CHANNAME, AST_EVENT_IE_PLTYPE_STR, chan->name,
00561       AST_EVENT_IE_CEL_APPNAME, AST_EVENT_IE_PLTYPE_STR, S_OR(chan->appl, ""),
00562       AST_EVENT_IE_CEL_APPDATA, AST_EVENT_IE_PLTYPE_STR, S_OR(chan->data, ""),
00563       AST_EVENT_IE_CEL_AMAFLAGS, AST_EVENT_IE_PLTYPE_UINT, chan->amaflags,
00564       AST_EVENT_IE_CEL_ACCTCODE, AST_EVENT_IE_PLTYPE_STR, chan->accountcode,
00565       AST_EVENT_IE_CEL_PEERACCT, AST_EVENT_IE_PLTYPE_STR, chan->peeraccount,
00566       AST_EVENT_IE_CEL_UNIQUEID, AST_EVENT_IE_PLTYPE_STR, chan->uniqueid,
00567       AST_EVENT_IE_CEL_LINKEDID, AST_EVENT_IE_PLTYPE_STR, chan->linkedid,
00568       AST_EVENT_IE_CEL_USERFIELD, AST_EVENT_IE_PLTYPE_STR, chan->userfield,
00569       AST_EVENT_IE_CEL_EXTRA, AST_EVENT_IE_PLTYPE_STR, extra,
00570       AST_EVENT_IE_CEL_PEER, AST_EVENT_IE_PLTYPE_STR, peername,
00571       AST_EVENT_IE_END);
00572 
00573    ast_channel_unlock(chan);
00574 
00575    if (peer) {
00576       peer = ast_channel_unref(peer);
00577    }
00578 
00579    if (ev && ast_event_queue(ev)) {
00580       ast_event_destroy(ev);
00581       return -1;
00582    }
00583 
00584    return 0;
00585 }
00586 
00587 int ast_cel_fill_record(const struct ast_event *e, struct ast_cel_event_record *r)
00588 {
00589    if (r->version != AST_CEL_EVENT_RECORD_VERSION) {
00590       ast_log(LOG_ERROR, "Module ABI mismatch for ast_cel_event_record.  "
00591             "Please ensure all modules were compiled for "
00592             "this version of Asterisk.\n");
00593       return -1;
00594    }
00595 
00596    r->event_type = ast_event_get_ie_uint(e, AST_EVENT_IE_CEL_EVENT_TYPE);
00597 
00598    r->event_time.tv_sec = ast_event_get_ie_uint(e, AST_EVENT_IE_CEL_EVENT_TIME);
00599    r->event_time.tv_usec = ast_event_get_ie_uint(e, AST_EVENT_IE_CEL_EVENT_TIME_USEC);
00600 
00601    r->user_defined_name = "";
00602 
00603    if (r->event_type == AST_CEL_USER_DEFINED) {
00604       r->user_defined_name = ast_event_get_ie_str(e, AST_EVENT_IE_CEL_USEREVENT_NAME);
00605       r->event_name = r->user_defined_name;
00606    } else {
00607       r->event_name = ast_cel_get_type_name(r->event_type);
00608    }
00609 
00610    r->caller_id_name   = S_OR(ast_event_get_ie_str(e, AST_EVENT_IE_CEL_CIDNAME), "");
00611    r->caller_id_num    = S_OR(ast_event_get_ie_str(e, AST_EVENT_IE_CEL_CIDNUM), "");
00612    r->caller_id_ani    = S_OR(ast_event_get_ie_str(e, AST_EVENT_IE_CEL_CIDANI), "");
00613    r->caller_id_rdnis  = S_OR(ast_event_get_ie_str(e, AST_EVENT_IE_CEL_CIDRDNIS), "");
00614    r->caller_id_dnid   = S_OR(ast_event_get_ie_str(e, AST_EVENT_IE_CEL_CIDDNID), "");
00615    r->extension        = S_OR(ast_event_get_ie_str(e, AST_EVENT_IE_CEL_EXTEN), "");
00616    r->context          = S_OR(ast_event_get_ie_str(e, AST_EVENT_IE_CEL_CONTEXT), "");
00617    r->channel_name     = S_OR(ast_event_get_ie_str(e, AST_EVENT_IE_CEL_CHANNAME), "");
00618    r->application_name = S_OR(ast_event_get_ie_str(e, AST_EVENT_IE_CEL_APPNAME), "");
00619    r->application_data = S_OR(ast_event_get_ie_str(e, AST_EVENT_IE_CEL_APPDATA), "");
00620    r->account_code     = S_OR(ast_event_get_ie_str(e, AST_EVENT_IE_CEL_ACCTCODE), "");
00621    r->peer_account     = S_OR(ast_event_get_ie_str(e, AST_EVENT_IE_CEL_ACCTCODE), "");
00622    r->unique_id        = S_OR(ast_event_get_ie_str(e, AST_EVENT_IE_CEL_UNIQUEID), "");
00623    r->linked_id        = S_OR(ast_event_get_ie_str(e, AST_EVENT_IE_CEL_LINKEDID), "");
00624    r->amaflag          = ast_event_get_ie_uint(e, AST_EVENT_IE_CEL_AMAFLAGS);
00625    r->user_field       = S_OR(ast_event_get_ie_str(e, AST_EVENT_IE_CEL_USERFIELD), "");
00626    r->peer             = S_OR(ast_event_get_ie_str(e, AST_EVENT_IE_CEL_PEER), "");
00627    r->extra            = S_OR(ast_event_get_ie_str(e, AST_EVENT_IE_CEL_EXTRA), "");
00628 
00629    return 0;
00630 }
00631 
00632 static int app_hash(const void *obj, const int flags)
00633 {
00634    return ast_str_case_hash((const char *) obj);
00635 }
00636 
00637 static int app_cmp(void *obj, void *arg, int flags)
00638 {
00639    const char *app1 = obj, *app2 = arg;
00640 
00641    return !strcasecmp(app1, app2) ? CMP_MATCH | CMP_STOP : 0;
00642 }
00643 
00644 static void ast_cel_engine_term(void)
00645 {
00646    if (appset) {
00647       ao2_ref(appset, -1);
00648       appset = NULL;
00649    }
00650 }
00651 
00652 int ast_cel_engine_init(void)
00653 {
00654    if (!(appset = ao2_container_alloc(NUM_APP_BUCKETS, app_hash, app_cmp))) {
00655       return -1;
00656    }
00657 
00658    if (do_reload()) {
00659       ao2_ref(appset, -1);
00660       appset = NULL;
00661       return -1;
00662    }
00663 
00664    if (ast_cli_register(&cli_status)) {
00665       ao2_ref(appset, -1);
00666       appset = NULL;
00667       return -1;
00668    }
00669 
00670    ast_register_atexit(ast_cel_engine_term);
00671 
00672    return 0;
00673 }
00674 
00675 int ast_cel_engine_reload(void)
00676 {
00677    return do_reload();
00678 }
00679 

Generated on Mon Mar 19 11:30:23 2012 for Asterisk - The Open Source Telephony Project by  doxygen 1.4.7