cel.h File Reference

Call Event Logging API. More...

#include "asterisk/event.h"

Include dependency graph for cel.h:

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  ast_cel_event_record
 Helper struct for getting the fields out of a CEL event. More...
struct  ast_cel_general_config
 A structure to hold CEL global configuration options. More...

Defines

#define AST_CEL_EVENT_RECORD_VERSION   2
 struct ABI version

Typedefs

typedef void(* ast_cel_backend_cb )(struct ast_event *event)
 CEL backend callback.

Enumerations

enum  ast_cel_event_type {
  AST_CEL_INVALID_VALUE = -1, AST_CEL_ALL = 0, AST_CEL_CHANNEL_START = 1, AST_CEL_CHANNEL_END = 2,
  AST_CEL_HANGUP = 3, AST_CEL_ANSWER = 4, AST_CEL_APP_START = 5, AST_CEL_APP_END = 6,
  AST_CEL_BRIDGE_ENTER = 7, AST_CEL_BRIDGE_EXIT = 8, AST_CEL_PARK_START = 9, AST_CEL_PARK_END = 10,
  AST_CEL_BLINDTRANSFER = 11, AST_CEL_ATTENDEDTRANSFER = 12, AST_CEL_USER_DEFINED = 13, AST_CEL_LINKEDID_END = 14,
  AST_CEL_PICKUP = 15, AST_CEL_FORWARD = 16, AST_CEL_LOCAL_OPTIMIZE = 17
}
 CEL event types. More...

Functions

struct ast_cel * ast_cel_alloc (void)
 Allocate a CEL record.
int ast_cel_backend_register (const char *name, ast_cel_backend_cb backend_callback)
 Register a CEL backend.
int ast_cel_backend_unregister (const char *name)
 Unregister a CEL backend.
unsigned int ast_cel_check_enabled (void)
 Check to see if CEL is enabled.
struct ast_eventast_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.
void ast_cel_destroy (struct ast_cel *cel)
 Destroy a CEL record.
struct ast_channelast_cel_fabricate_channel_from_event (const struct ast_event *event)
 Create a fake channel from data in a CEL event.
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.
void * ast_cel_general_config_alloc (void)
 Allocate a CEL configuration object.
struct ast_cel_general_configast_cel_get_config (void)
 Obtain the current CEL configuration.
const char * ast_cel_get_type_name (enum ast_cel_event_type type)
 Get the name of a CEL event type.
void ast_cel_publish_event (struct ast_channel *chan, enum ast_cel_event_type event_type, struct ast_json *blob)
 Publish a CEL event.
void ast_cel_set_config (struct ast_cel_general_config *config)
 Set the current CEL configuration.
enum ast_cel_event_type ast_cel_str_to_event_type (const char *name)
 Get the event type from a string.
struct stasis_topicast_cel_topic (void)
 Get the CEL topic.


Detailed Description

Call Event Logging API.

Todo:
TODO: There some event types that have been defined here, but are not yet used anywhere in the code. It would be really awesome if someone went through and had Asterisk generate these events where it is appropriate to do so. The defined, but unused events are: CONF_ENTER, CONF_EXIT, CONF_START, CONF_END, 3WAY_START, 3WAY_END, TRANSFER, and HOOKFLASH.

Definition in file cel.h.


Define Documentation

#define AST_CEL_EVENT_RECORD_VERSION   2

struct ABI version

Note:
This must be incremented when the struct changes.

Definition at line 164 of file cel.h.

Referenced by ast_cel_fabricate_channel_from_event(), ast_cel_fill_record(), manager_log(), odbc_log(), pgsql_log(), radius_log(), and tds_log().


Typedef Documentation

typedef void(* ast_cel_backend_cb)(struct ast_event *event)

CEL backend callback.

Definition at line 293 of file cel.h.


Enumeration Type Documentation

CEL event types.

Enumerator:
AST_CEL_INVALID_VALUE 
AST_CEL_ALL 
AST_CEL_CHANNEL_START  channel birth
AST_CEL_CHANNEL_END  channel end
AST_CEL_HANGUP  hangup terminates connection
AST_CEL_ANSWER  A ringing phone is answered.
AST_CEL_APP_START  an app starts
AST_CEL_APP_END  an app ends
AST_CEL_BRIDGE_ENTER  channel enters a bridge
AST_CEL_BRIDGE_EXIT  channel exits a bridge
AST_CEL_PARK_START  a channel is parked
AST_CEL_PARK_END  channel out of the park
AST_CEL_BLINDTRANSFER  a transfer occurs
AST_CEL_ATTENDEDTRANSFER  a transfer occurs
AST_CEL_USER_DEFINED  a user-defined event, the event name field should be set
AST_CEL_LINKEDID_END  the last channel with the given linkedid is retired
AST_CEL_PICKUP  a directed pickup was performed on this channel
AST_CEL_FORWARD  this call was forwarded somewhere else
AST_CEL_LOCAL_OPTIMIZE  A local channel optimization occurred.

Definition at line 41 of file cel.h.

00041                         {
00042    AST_CEL_INVALID_VALUE = -1,
00043    AST_CEL_ALL = 0,
00044    /*! \brief channel birth */
00045    AST_CEL_CHANNEL_START = 1,
00046    /*! \brief channel end */
00047    AST_CEL_CHANNEL_END = 2,
00048    /*! \brief hangup terminates connection */
00049    AST_CEL_HANGUP = 3,
00050    /*! \brief A ringing phone is answered */
00051    AST_CEL_ANSWER = 4,
00052    /*! \brief an app starts */
00053    AST_CEL_APP_START = 5,
00054    /*! \brief an app ends */
00055    AST_CEL_APP_END = 6,
00056    /*! \brief channel enters a bridge */
00057    AST_CEL_BRIDGE_ENTER = 7,
00058    /*! \brief channel exits a bridge */
00059    AST_CEL_BRIDGE_EXIT = 8,
00060    /*! \brief a channel is parked */
00061    AST_CEL_PARK_START = 9,
00062    /*! \brief channel out of the park */
00063    AST_CEL_PARK_END = 10,
00064    /*! \brief a transfer occurs */
00065    AST_CEL_BLINDTRANSFER = 11,
00066    /*! \brief a transfer occurs */
00067    AST_CEL_ATTENDEDTRANSFER = 12,
00068    /*! \brief a user-defined event, the event name field should be set  */
00069    AST_CEL_USER_DEFINED = 13,
00070    /*! \brief the last channel with the given linkedid is retired  */
00071    AST_CEL_LINKEDID_END = 14,
00072    /*! \brief a directed pickup was performed on this channel  */
00073    AST_CEL_PICKUP = 15,
00074    /*! \brief this call was forwarded somewhere else  */
00075    AST_CEL_FORWARD = 16,
00076    /*! \brief A local channel optimization occurred */
00077    AST_CEL_LOCAL_OPTIMIZE = 17,
00078 };


Function Documentation

struct ast_cel* ast_cel_alloc ( void   )  [read]

Allocate a CEL record.

Since:
1.8
Note:
The CEL record must be destroyed with ast_cel_destroy().
Return values:
non-NULL an allocated ast_cel structure
NULL error

int ast_cel_backend_register ( const char *  name,
ast_cel_backend_cb  backend_callback 
)

Register a CEL backend.

Parameters:
name Name of backend to register
backend_callback Callback to register
Return values:
zero on success
non-zero on failure
Since:
12

Definition at line 1873 of file cel.c.

References AO2_ALLOC_OPT_LOCK_NOLOCK, ao2_alloc_options, ao2_cleanup, ao2_global_obj_ref, ao2_link, ao2_ref, ast_strlen_zero, cel_backend::callback, cel_backend::name, NULL, and RAII_VAR.

Referenced by load_config(), load_module(), my_load_module(), and test_cel_init_cb().

01874 {
01875    RAII_VAR(struct ao2_container *, backends, ao2_global_obj_ref(cel_backends), ao2_cleanup);
01876    struct cel_backend *backend;
01877 
01878    if (!backends || ast_strlen_zero(name) || !backend_callback) {
01879       return -1;
01880    }
01881 
01882    /* The backend object is immutable so it doesn't need a lock of its own. */
01883    backend = ao2_alloc_options(sizeof(*backend) + 1 + strlen(name), NULL,
01884       AO2_ALLOC_OPT_LOCK_NOLOCK);
01885    if (!backend) {
01886       return -1;
01887    }
01888    strcpy(backend->name, name);/* Safe */
01889    backend->callback = backend_callback;
01890 
01891    ao2_link(backends, backend);
01892    ao2_ref(backend, -1);
01893    return 0;
01894 }

int ast_cel_backend_unregister ( const char *  name  ) 

Unregister a CEL backend.

Parameters:
name Name of backend to unregister
Return values:
zero on success
non-zero on failure
Since:
12

Definition at line 1861 of file cel.c.

References ao2_find, ao2_global_obj_ref, ao2_ref, OBJ_NODATA, OBJ_SEARCH_KEY, and OBJ_UNLINK.

Referenced by cel_verify_and_cleanup_cb(), load_config(), my_unload_module(), tds_unload_module(), and unload_module().

01862 {
01863    struct ao2_container *backends = ao2_global_obj_ref(cel_backends);
01864 
01865    if (backends) {
01866       ao2_find(backends, name, OBJ_SEARCH_KEY | OBJ_NODATA | OBJ_UNLINK);
01867       ao2_ref(backends, -1);
01868    }
01869 
01870    return 0;
01871 }

unsigned int ast_cel_check_enabled ( void   ) 

Check to see if CEL is enabled.

Since:
1.8
Return values:
zero not enabled
non-zero enabled

Definition at line 447 of file cel.c.

References ao2_cleanup, ao2_global_obj_ref, ast_cel_general_config::enable, enabled, and cel_config::general.

Referenced by ast_cel_engine_init(), ast_cel_engine_reload(), ast_cel_set_config(), and handle_cli_status().

00448 {
00449    unsigned int enabled;
00450    struct cel_config *cfg = ao2_global_obj_ref(cel_configs);
00451 
00452    enabled = (!cfg || !cfg->general) ? 0 : cfg->general->enable;
00453    ao2_cleanup(cfg);
00454    return enabled;
00455 }

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 
) [read]

Allocate and populate a CEL event structure.

Parameters:
snapshot An ast_channel_snapshot of the primary channel associated with this channel event.
event_type The type of call event being reported.
userdefevname Custom name for the call event. (optional)
extra An event-specific opaque JSON blob to be rendered and placed in the "CEL_EXTRA" information element of the call event. (optional)
peer_str A list of comma-separated peer channel names. (optional)
Since:
12
Return values:
The created ast_event structure
NULL on failure

Definition at line 621 of file cel.c.

References ast_channel_snapshot::accountcode, ast_channel_snapshot::amaflags, ast_channel_snapshot::appl, AST_EVENT_CEL, AST_EVENT_IE_CEL_ACCTCODE, AST_EVENT_IE_CEL_AMAFLAGS, AST_EVENT_IE_CEL_APPDATA, AST_EVENT_IE_CEL_APPNAME, AST_EVENT_IE_CEL_CHANNAME, AST_EVENT_IE_CEL_CIDANI, AST_EVENT_IE_CEL_CIDDNID, AST_EVENT_IE_CEL_CIDNAME, AST_EVENT_IE_CEL_CIDNUM, AST_EVENT_IE_CEL_CIDRDNIS, AST_EVENT_IE_CEL_CONTEXT, AST_EVENT_IE_CEL_EVENT_TIME, AST_EVENT_IE_CEL_EVENT_TIME_USEC, AST_EVENT_IE_CEL_EVENT_TYPE, AST_EVENT_IE_CEL_EXTEN, AST_EVENT_IE_CEL_EXTRA, AST_EVENT_IE_CEL_LINKEDID, AST_EVENT_IE_CEL_PEER, AST_EVENT_IE_CEL_PEERACCT, AST_EVENT_IE_CEL_UNIQUEID, AST_EVENT_IE_CEL_USEREVENT_NAME, AST_EVENT_IE_CEL_USERFIELD, AST_EVENT_IE_END, AST_EVENT_IE_PLTYPE_STR, AST_EVENT_IE_PLTYPE_UINT, ast_event_new(), ast_json_dump_string, ast_json_free(), ast_tvnow(), ast_channel_snapshot::caller_ani, ast_channel_snapshot::caller_dnid, ast_channel_snapshot::caller_name, ast_channel_snapshot::caller_number, ast_channel_snapshot::caller_rdnis, ast_channel_snapshot::context, ast_channel_snapshot::data, ast_channel_snapshot::exten, ast_channel_snapshot::linkedid, ast_channel_snapshot::name, NULL, ast_channel_snapshot::peeraccount, RAII_VAR, S_OR, ast_channel_snapshot::uniqueid, and ast_channel_snapshot::userfield.

Referenced by append_expected_event_snapshot(), and cel_report_event().

00624 {
00625    struct timeval eventtime = ast_tvnow();
00626    RAII_VAR(char *, extra_txt, NULL, ast_json_free);
00627    if (extra) {
00628       extra_txt = ast_json_dump_string(extra);
00629    }
00630    return ast_event_new(AST_EVENT_CEL,
00631       AST_EVENT_IE_CEL_EVENT_TYPE, AST_EVENT_IE_PLTYPE_UINT, event_type,
00632       AST_EVENT_IE_CEL_EVENT_TIME, AST_EVENT_IE_PLTYPE_UINT, eventtime.tv_sec,
00633       AST_EVENT_IE_CEL_EVENT_TIME_USEC, AST_EVENT_IE_PLTYPE_UINT, eventtime.tv_usec,
00634       AST_EVENT_IE_CEL_USEREVENT_NAME, AST_EVENT_IE_PLTYPE_STR, S_OR(userdefevname, ""),
00635       AST_EVENT_IE_CEL_CIDNAME, AST_EVENT_IE_PLTYPE_STR, snapshot->caller_name,
00636       AST_EVENT_IE_CEL_CIDNUM, AST_EVENT_IE_PLTYPE_STR, snapshot->caller_number,
00637       AST_EVENT_IE_CEL_CIDANI, AST_EVENT_IE_PLTYPE_STR, snapshot->caller_ani,
00638       AST_EVENT_IE_CEL_CIDRDNIS, AST_EVENT_IE_PLTYPE_STR, snapshot->caller_rdnis,
00639       AST_EVENT_IE_CEL_CIDDNID, AST_EVENT_IE_PLTYPE_STR, snapshot->caller_dnid,
00640       AST_EVENT_IE_CEL_EXTEN, AST_EVENT_IE_PLTYPE_STR, snapshot->exten,
00641       AST_EVENT_IE_CEL_CONTEXT, AST_EVENT_IE_PLTYPE_STR, snapshot->context,
00642       AST_EVENT_IE_CEL_CHANNAME, AST_EVENT_IE_PLTYPE_STR, snapshot->name,
00643       AST_EVENT_IE_CEL_APPNAME, AST_EVENT_IE_PLTYPE_STR, snapshot->appl,
00644       AST_EVENT_IE_CEL_APPDATA, AST_EVENT_IE_PLTYPE_STR, snapshot->data,
00645       AST_EVENT_IE_CEL_AMAFLAGS, AST_EVENT_IE_PLTYPE_UINT, snapshot->amaflags,
00646       AST_EVENT_IE_CEL_ACCTCODE, AST_EVENT_IE_PLTYPE_STR, snapshot->accountcode,
00647       AST_EVENT_IE_CEL_PEERACCT, AST_EVENT_IE_PLTYPE_STR, snapshot->peeraccount,
00648       AST_EVENT_IE_CEL_UNIQUEID, AST_EVENT_IE_PLTYPE_STR, snapshot->uniqueid,
00649       AST_EVENT_IE_CEL_LINKEDID, AST_EVENT_IE_PLTYPE_STR, snapshot->linkedid,
00650       AST_EVENT_IE_CEL_USERFIELD, AST_EVENT_IE_PLTYPE_STR, snapshot->userfield,
00651       AST_EVENT_IE_CEL_EXTRA, AST_EVENT_IE_PLTYPE_STR, S_OR(extra_txt, ""),
00652       AST_EVENT_IE_CEL_PEER, AST_EVENT_IE_PLTYPE_STR, S_OR(peer, ""),
00653       AST_EVENT_IE_END);
00654 }

void ast_cel_destroy ( struct ast_cel *  cel  ) 

Destroy a CEL record.

Parameters:
cel the record to destroy
Since:
1.8
Returns:
nothing.

struct ast_channel* ast_cel_fabricate_channel_from_event ( const struct ast_event event  )  [read]

Create a fake channel from data in a CEL event.

Note:
This function creates a fake channel containing the serialized channel data in the given cel event. It should be released with ast_channel_unref() but could be released with ast_channel_release().
Parameters:
event the CEL event
Since:
1.8
Returns:
a channel with the data filled in, or NULL on error
Todo:
This function is very expensive, especially given that some CEL backends use it on every CEL event. This function really needs to go away at some point.

Definition at line 754 of file cel.c.

References ast_cel_event_record::account_code, ast_cel_event_record::amaflag, ast_party_caller::ani, ao2_cleanup, ao2_global_obj_ref, 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_amaflags_set(), ast_channel_appl_set(), ast_channel_caller(), ast_channel_context_set(), ast_channel_data_set(), ast_channel_datastore_add(), ast_channel_dialed(), ast_channel_exten_set(), ast_channel_internal_set_fake_ids(), ast_channel_name_set(), ast_channel_redirecting(), ast_channel_unref, ast_channel_varshead(), ast_datastore_alloc, ast_datastore_free(), ast_dummy_channel_alloc(), AST_LIST_INSERT_HEAD, ast_localtime(), ast_malloc, ast_strdup, ast_strftime(), ast_strlen_zero, ast_var_assign(), 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, ast_datastore::data, 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_party_redirecting::from, ast_party_caller::id, ast_cel_event_record::linked_id, ast_party_id::name, NULL, ast_party_dialed::number, ast_party_id::number, ast_cel_event_record::peer, ast_cel_event_record::peer_account, RAII_VAR, ast_party_dialed::str, ast_party_number::str, ast_party_name::str, ast_cel_event_record::unique_id, ast_cel_event_record::user_defined_name, ast_cel_event_record::user_field, ast_party_number::valid, ast_party_name::valid, and ast_cel_event_record::version.

Referenced by custom_log(), and write_cel().

00755 {
00756    struct varshead *headp;
00757    struct ast_var_t *newvariable;
00758    const char *mixed_name;
00759    char timebuf[30];
00760    struct ast_channel *tchan;
00761    struct ast_cel_event_record record = {
00762       .version = AST_CEL_EVENT_RECORD_VERSION,
00763    };
00764    struct ast_datastore *datastore;
00765    char *app_data;
00766    RAII_VAR(struct cel_config *, cfg, ao2_global_obj_ref(cel_configs), ao2_cleanup);
00767 
00768    if (!cfg || !cfg->general) {
00769       return NULL;
00770    }
00771 
00772    /* do not call ast_channel_alloc because this is not really a real channel */
00773    if (!(tchan = ast_dummy_channel_alloc())) {
00774       return NULL;
00775    }
00776 
00777    headp = ast_channel_varshead(tchan);
00778 
00779    /* first, get the variables from the event */
00780    if (ast_cel_fill_record(event, &record)) {
00781       ast_channel_unref(tchan);
00782       return NULL;
00783    }
00784 
00785    /* next, fill the channel with their data */
00786    mixed_name = (record.event_type == AST_CEL_USER_DEFINED)
00787       ? record.user_defined_name : record.event_name;
00788    if ((newvariable = ast_var_assign("eventtype", mixed_name))) {
00789       AST_LIST_INSERT_HEAD(headp, newvariable, entries);
00790    }
00791 
00792    if (ast_strlen_zero(cfg->general->date_format)) {
00793       snprintf(timebuf, sizeof(timebuf), "%ld.%06ld", (long) record.event_time.tv_sec,
00794             (long) record.event_time.tv_usec);
00795    } else {
00796       struct ast_tm tm;
00797       ast_localtime(&record.event_time, &tm, NULL);
00798       ast_strftime(timebuf, sizeof(timebuf), cfg->general->date_format, &tm);
00799    }
00800 
00801    if ((newvariable = ast_var_assign("eventtime", timebuf))) {
00802       AST_LIST_INSERT_HEAD(headp, newvariable, entries);
00803    }
00804 
00805    if ((newvariable = ast_var_assign("eventenum", record.event_name))) {
00806       AST_LIST_INSERT_HEAD(headp, newvariable, entries);
00807    }
00808    if ((newvariable = ast_var_assign("userdeftype", record.user_defined_name))) {
00809       AST_LIST_INSERT_HEAD(headp, newvariable, entries);
00810    }
00811    if ((newvariable = ast_var_assign("eventextra", record.extra))) {
00812       AST_LIST_INSERT_HEAD(headp, newvariable, entries);
00813    }
00814 
00815    ast_channel_caller(tchan)->id.name.valid = 1;
00816    ast_channel_caller(tchan)->id.name.str = ast_strdup(record.caller_id_name);
00817    ast_channel_caller(tchan)->id.number.valid = 1;
00818    ast_channel_caller(tchan)->id.number.str = ast_strdup(record.caller_id_num);
00819    ast_channel_caller(tchan)->ani.number.valid = 1;
00820    ast_channel_caller(tchan)->ani.number.str = ast_strdup(record.caller_id_ani);
00821    ast_channel_redirecting(tchan)->from.number.valid = 1;
00822    ast_channel_redirecting(tchan)->from.number.str = ast_strdup(record.caller_id_rdnis);
00823    ast_channel_dialed(tchan)->number.str = ast_strdup(record.caller_id_dnid);
00824 
00825    ast_channel_exten_set(tchan, record.extension);
00826    ast_channel_context_set(tchan, record.context);
00827    ast_channel_name_set(tchan, record.channel_name);
00828    ast_channel_internal_set_fake_ids(tchan, record.unique_id, record.linked_id);
00829    ast_channel_accountcode_set(tchan, record.account_code);
00830    ast_channel_peeraccount_set(tchan, record.peer_account);
00831    ast_channel_userfield_set(tchan, record.user_field);
00832 
00833    if ((newvariable = ast_var_assign("BRIDGEPEER", record.peer))) {
00834       AST_LIST_INSERT_HEAD(headp, newvariable, entries);
00835    }
00836 
00837    ast_channel_amaflags_set(tchan, record.amaflag);
00838 
00839    /* We need to store an 'application name' and 'application
00840     * data' on the channel for logging purposes, but the channel
00841     * structure only provides a place to store pointers, and it
00842     * expects these pointers to be pointing to data that does not
00843     * need to be freed. This means that the channel's destructor
00844     * does not attempt to free any storage that these pointers
00845     * point to. However, we can't provide data in that form directly for
00846     * these structure members. In order to ensure that these data
00847     * elements have a lifetime that matches the channel's
00848     * lifetime, we'll put them in a datastore attached to the
00849     * channel, and set's the channel's pointers to point into the
00850     * datastore.  The datastore will then be automatically destroyed
00851     * when the channel is destroyed.
00852     */
00853 
00854    if (!(datastore = ast_datastore_alloc(&fabricated_channel_datastore, NULL))) {
00855       ast_channel_unref(tchan);
00856       return NULL;
00857    }
00858 
00859    if (!(app_data = ast_malloc(strlen(record.application_name) + strlen(record.application_data) + 2))) {
00860       ast_datastore_free(datastore);
00861       ast_channel_unref(tchan);
00862       return NULL;
00863    }
00864 
00865    ast_channel_appl_set(tchan, strcpy(app_data, record.application_name));
00866    ast_channel_data_set(tchan, strcpy(app_data + strlen(record.application_name) + 1,
00867       record.application_data));
00868 
00869    datastore->data = app_data;
00870    ast_channel_datastore_add(tchan, datastore);
00871 
00872    return tchan;
00873 }

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.

Parameters:
[in] event the CEL event
[out] r the ast_cel_event_record to fill in
Since:
1.8
Return values:
0 success
non-zero failure

Definition at line 913 of file cel.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_get_type_name(), AST_CEL_USER_DEFINED, ast_event_get_ie_str(), ast_event_get_ie_uint(), AST_EVENT_IE_CEL_ACCTCODE, AST_EVENT_IE_CEL_AMAFLAGS, AST_EVENT_IE_CEL_APPDATA, AST_EVENT_IE_CEL_APPNAME, AST_EVENT_IE_CEL_CHANNAME, AST_EVENT_IE_CEL_CIDANI, AST_EVENT_IE_CEL_CIDDNID, AST_EVENT_IE_CEL_CIDNAME, AST_EVENT_IE_CEL_CIDNUM, AST_EVENT_IE_CEL_CIDRDNIS, AST_EVENT_IE_CEL_CONTEXT, AST_EVENT_IE_CEL_EVENT_TIME, AST_EVENT_IE_CEL_EVENT_TIME_USEC, AST_EVENT_IE_CEL_EVENT_TYPE, AST_EVENT_IE_CEL_EXTEN, AST_EVENT_IE_CEL_EXTRA, AST_EVENT_IE_CEL_LINKEDID, AST_EVENT_IE_CEL_PEER, AST_EVENT_IE_CEL_PEERACCT, AST_EVENT_IE_CEL_UNIQUEID, AST_EVENT_IE_CEL_USEREVENT_NAME, AST_EVENT_IE_CEL_USERFIELD, ast_log, 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, 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, LOG_ERROR, ast_cel_event_record::peer, ast_cel_event_record::peer_account, S_OR, 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 ast_cel_fabricate_channel_from_event(), manager_log(), odbc_log(), pgsql_log(), radius_log(), and tds_log().

00914 {
00915    if (r->version != AST_CEL_EVENT_RECORD_VERSION) {
00916       ast_log(LOG_ERROR, "Module ABI mismatch for ast_cel_event_record.  "
00917             "Please ensure all modules were compiled for "
00918             "this version of Asterisk.\n");
00919       return -1;
00920    }
00921 
00922    r->event_type = ast_event_get_ie_uint(e, AST_EVENT_IE_CEL_EVENT_TYPE);
00923 
00924    r->event_time.tv_sec = ast_event_get_ie_uint(e, AST_EVENT_IE_CEL_EVENT_TIME);
00925    r->event_time.tv_usec = ast_event_get_ie_uint(e, AST_EVENT_IE_CEL_EVENT_TIME_USEC);
00926 
00927    r->event_name = ast_cel_get_type_name(r->event_type);
00928    if (r->event_type == AST_CEL_USER_DEFINED) {
00929       r->user_defined_name = ast_event_get_ie_str(e, AST_EVENT_IE_CEL_USEREVENT_NAME);
00930    } else {
00931       r->user_defined_name = "";
00932    }
00933 
00934    r->caller_id_name   = S_OR(ast_event_get_ie_str(e, AST_EVENT_IE_CEL_CIDNAME), "");
00935    r->caller_id_num    = S_OR(ast_event_get_ie_str(e, AST_EVENT_IE_CEL_CIDNUM), "");
00936    r->caller_id_ani    = S_OR(ast_event_get_ie_str(e, AST_EVENT_IE_CEL_CIDANI), "");
00937    r->caller_id_rdnis  = S_OR(ast_event_get_ie_str(e, AST_EVENT_IE_CEL_CIDRDNIS), "");
00938    r->caller_id_dnid   = S_OR(ast_event_get_ie_str(e, AST_EVENT_IE_CEL_CIDDNID), "");
00939    r->extension        = S_OR(ast_event_get_ie_str(e, AST_EVENT_IE_CEL_EXTEN), "");
00940    r->context          = S_OR(ast_event_get_ie_str(e, AST_EVENT_IE_CEL_CONTEXT), "");
00941    r->channel_name     = S_OR(ast_event_get_ie_str(e, AST_EVENT_IE_CEL_CHANNAME), "");
00942    r->application_name = S_OR(ast_event_get_ie_str(e, AST_EVENT_IE_CEL_APPNAME), "");
00943    r->application_data = S_OR(ast_event_get_ie_str(e, AST_EVENT_IE_CEL_APPDATA), "");
00944    r->account_code     = S_OR(ast_event_get_ie_str(e, AST_EVENT_IE_CEL_ACCTCODE), "");
00945    r->peer_account     = S_OR(ast_event_get_ie_str(e, AST_EVENT_IE_CEL_PEERACCT), "");
00946    r->unique_id        = S_OR(ast_event_get_ie_str(e, AST_EVENT_IE_CEL_UNIQUEID), "");
00947    r->linked_id        = S_OR(ast_event_get_ie_str(e, AST_EVENT_IE_CEL_LINKEDID), "");
00948    r->amaflag          = ast_event_get_ie_uint(e, AST_EVENT_IE_CEL_AMAFLAGS);
00949    r->user_field       = S_OR(ast_event_get_ie_str(e, AST_EVENT_IE_CEL_USERFIELD), "");
00950    r->peer             = S_OR(ast_event_get_ie_str(e, AST_EVENT_IE_CEL_PEER), "");
00951    r->extra            = S_OR(ast_event_get_ie_str(e, AST_EVENT_IE_CEL_EXTRA), "");
00952 
00953    return 0;
00954 }

void* ast_cel_general_config_alloc ( void   ) 

Allocate a CEL configuration object.

Return values:
NULL on error
The new CEL configuration object

Definition at line 182 of file cel.c.

References ao2_alloc, ao2_cleanup, ao2_ref, ast_str_container_alloc, ast_string_field_init, cel_general_config_dtor(), NULL, NUM_APP_BUCKETS, and RAII_VAR.

Referenced by cel_config_alloc(), and load_module().

00183 {
00184    RAII_VAR(struct ast_cel_general_config *, cfg, NULL, ao2_cleanup);
00185 
00186    if (!(cfg = ao2_alloc(sizeof(*cfg), cel_general_config_dtor))) {
00187       return NULL;
00188    }
00189 
00190    if (ast_string_field_init(cfg, 64)) {
00191       return NULL;
00192    }
00193 
00194    if (!(cfg->apps = ast_str_container_alloc(NUM_APP_BUCKETS))) {
00195       return NULL;
00196    }
00197 
00198    ao2_ref(cfg, +1);
00199    return cfg;
00200 }

struct ast_cel_general_config* ast_cel_get_config ( void   )  [read]

Obtain the current CEL configuration.

Since:
12 The configuration is a ref counted object. The caller of this function must decrement the ref count when finished with the configuration.
Return values:
NULL on error
The current CEL configuration

Definition at line 1823 of file cel.c.

References ao2_cleanup, ao2_global_obj_ref, ao2_ref, NULL, and RAII_VAR.

Referenced by test_cel_init_cb().

01824 {
01825    RAII_VAR(struct cel_config *, mod_cfg, ao2_global_obj_ref(cel_configs), ao2_cleanup);
01826 
01827    if (!mod_cfg || !mod_cfg->general) {
01828       return NULL;
01829    }
01830 
01831    ao2_ref(mod_cfg->general, +1);
01832    return mod_cfg->general;
01833 }

const char* ast_cel_get_type_name ( enum ast_cel_event_type  type  ) 

Get the name of a CEL event type.

Parameters:
type the type to get the name of
Since:
1.8
Returns:
the string representation of the type

Definition at line 595 of file cel.c.

References S_OR.

Referenced by ast_cel_fill_record(), cel_generic_cb(), dump_event(), and handle_cli_status().

00596 {
00597    return S_OR(cel_event_types[type], "Unknown");
00598 }

void ast_cel_publish_event ( struct ast_channel chan,
enum ast_cel_event_type  event_type,
struct ast_json blob 
)

Publish a CEL event.

Since:
12
Parameters:
chan This is the primary channel associated with this channel event.
event_type This is the type of call event being reported.
blob This contains any additional parameters that need to be conveyed for this event.

Definition at line 1799 of file cel.c.

References ao2_cleanup, ast_cel_topic(), ast_channel_blob_create_from_cache(), ast_channel_uniqueid(), ast_json_pack(), ast_json_unref(), cel_generic_type(), and stasis_publish().

Referenced by celgenuserevent_exec().

01802 {
01803    struct ast_json *cel_blob;
01804    struct stasis_message *message;
01805 
01806    cel_blob = ast_json_pack("{s: i, s: O}",
01807       "event_type", event_type,
01808       "event_details", blob);
01809 
01810    message = ast_channel_blob_create_from_cache(ast_channel_uniqueid(chan), cel_generic_type(), cel_blob);
01811    if (message) {
01812       stasis_publish(ast_cel_topic(), message);
01813    }
01814    ao2_cleanup(message);
01815    ast_json_unref(cel_blob);
01816 }

void ast_cel_set_config ( struct ast_cel_general_config config  ) 

Set the current CEL configuration.

Since:
12
Parameters:
config The new CEL configuration

Definition at line 1835 of file cel.c.

References ao2_bump, ao2_cleanup, ao2_global_obj_ref, ao2_ref, ast_cel_check_enabled(), create_routes(), destroy_routes(), cel_config::general, and is_enabled().

Referenced by cel_verify_and_cleanup_cb(), and test_cel_init_cb().

01836 {
01837    int was_enabled;
01838    int is_enabled;
01839    struct ast_cel_general_config *cleanup_config;
01840    struct cel_config *mod_cfg = ao2_global_obj_ref(cel_configs);
01841 
01842    if (mod_cfg) {
01843       was_enabled = ast_cel_check_enabled();
01844 
01845       cleanup_config = mod_cfg->general;
01846       ao2_bump(config);
01847       mod_cfg->general = config;
01848       ao2_cleanup(cleanup_config);
01849 
01850       is_enabled = ast_cel_check_enabled();
01851       if (!was_enabled && is_enabled) {
01852          create_routes();
01853       } else if (was_enabled && !is_enabled) {
01854          destroy_routes();
01855       }
01856 
01857       ao2_ref(mod_cfg, -1);
01858    }
01859 }

enum ast_cel_event_type ast_cel_str_to_event_type ( const char *  name  ) 

Get the event type from a string.

Parameters:
name the event type name as a string
Since:
1.8
Returns:
the ast_cel_event_type given by the string

Definition at line 522 of file cel.c.

References ARRAY_LEN, AST_CEL_INVALID_VALUE, ast_log, and LOG_ERROR.

Referenced by events_handler().

00523 {
00524    unsigned int i;
00525 
00526    for (i = 0; i < ARRAY_LEN(cel_event_types); i++) {
00527       if (cel_event_types[i] && !strcasecmp(name, cel_event_types[i])) {
00528          return i;
00529       }
00530    }
00531 
00532    ast_log(LOG_ERROR, "Unknown event name '%s'\n", name);
00533    return AST_CEL_INVALID_VALUE;
00534 }

struct stasis_topic* ast_cel_topic ( void   )  [read]

Get the CEL topic.

Return values:
The CEL topic
NULL if not allocated

Definition at line 1818 of file cel.c.

Referenced by ast_cel_publish_event(), and create_subscriptions().

01819 {
01820    return cel_topic;
01821 }


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