Asterisk - The Open Source Telephony Project GIT-master-80b953f
Loading...
Searching...
No Matches
Data Structures | Macros | Typedefs | Enumerations | Functions
cel.h File Reference

Call Event Logging API. More...

#include "asterisk/event.h"
#include "asterisk/strings.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...
 

Macros

#define AST_CEL_EVENT_RECORD_VERSION   3
 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 , AST_CEL_LOCAL_OPTIMIZE_BEGIN = 18 ,
  AST_CEL_STREAM_BEGIN = 19 , AST_CEL_STREAM_END = 20 , AST_CEL_DTMF = 21
}
 CEL event types. More...
 

Functions

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.
 
struct ast_eventast_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.
 
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.
 
int ast_cel_format_eventtime (struct timeval eventtime, char *timebuf, size_t len)
 Format an event timeval using dateformat from cel.conf.
 
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_publish_user_event (struct ast_channel *chan, const char *event, const char *extra)
 Publish a CEL user 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.

Macro Definition Documentation

◆ AST_CEL_EVENT_RECORD_VERSION

#define AST_CEL_EVENT_RECORD_VERSION   3

struct ABI version

Note
This must be incremented when the struct changes.

Definition at line 162 of file cel.h.

Typedef Documentation

◆ ast_cel_backend_cb

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

CEL backend callback.

Definition at line 330 of file cel.h.

Enumeration Type Documentation

◆ ast_cel_event_type

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, this marks the end.

AST_CEL_LOCAL_OPTIMIZE_BEGIN 

A local channel optimization has begun.

AST_CEL_STREAM_BEGIN 

A stream started.

AST_CEL_STREAM_END 

A stream ended.

AST_CEL_DTMF 

A DTMF digit was processed.

Definition at line 42 of file cel.h.

42 {
44 AST_CEL_ALL = 0,
45 /*! \brief channel birth */
47 /*! \brief channel end */
49 /*! \brief hangup terminates connection */
51 /*! \brief A ringing phone is answered */
53 /*! \brief an app starts */
55 /*! \brief an app ends */
57 /*! \brief channel enters a bridge */
59 /*! \brief channel exits a bridge */
61 /*! \brief a channel is parked */
63 /*! \brief channel out of the park */
65 /*! \brief a transfer occurs */
67 /*! \brief a transfer occurs */
69 /*! \brief a user-defined event, the event name field should be set */
71 /*! \brief the last channel with the given linkedid is retired */
73 /*! \brief a directed pickup was performed on this channel */
74 AST_CEL_PICKUP = 15,
75 /*! \brief this call was forwarded somewhere else */
76 AST_CEL_FORWARD = 16,
77 /*! \brief A local channel optimization occurred, this marks the end */
79 /*! \brief A local channel optimization has begun */
81 /*! \brief A stream started */
83 /*! \brief A stream ended */
85 /*! \brief A DTMF digit was processed */
86 AST_CEL_DTMF = 21,
87};
@ AST_CEL_CHANNEL_END
channel end
Definition cel.h:48
@ AST_CEL_APP_END
an app ends
Definition cel.h:56
@ AST_CEL_ANSWER
A ringing phone is answered.
Definition cel.h:52
@ AST_CEL_PARK_START
a channel is parked
Definition cel.h:62
@ AST_CEL_LINKEDID_END
the last channel with the given linkedid is retired
Definition cel.h:72
@ AST_CEL_INVALID_VALUE
Definition cel.h:43
@ AST_CEL_BRIDGE_EXIT
channel exits a bridge
Definition cel.h:60
@ AST_CEL_FORWARD
this call was forwarded somewhere else
Definition cel.h:76
@ AST_CEL_HANGUP
hangup terminates connection
Definition cel.h:50
@ AST_CEL_USER_DEFINED
a user-defined event, the event name field should be set
Definition cel.h:70
@ AST_CEL_PICKUP
a directed pickup was performed on this channel
Definition cel.h:74
@ AST_CEL_APP_START
an app starts
Definition cel.h:54
@ AST_CEL_LOCAL_OPTIMIZE_BEGIN
A local channel optimization has begun.
Definition cel.h:80
@ AST_CEL_ALL
Definition cel.h:44
@ AST_CEL_DTMF
A DTMF digit was processed.
Definition cel.h:86
@ AST_CEL_PARK_END
channel out of the park
Definition cel.h:64
@ AST_CEL_CHANNEL_START
channel birth
Definition cel.h:46
@ AST_CEL_STREAM_BEGIN
A stream started.
Definition cel.h:82
@ AST_CEL_ATTENDEDTRANSFER
a transfer occurs
Definition cel.h:68
@ AST_CEL_BRIDGE_ENTER
channel enters a bridge
Definition cel.h:58
@ AST_CEL_STREAM_END
A stream ended.
Definition cel.h:84
@ AST_CEL_BLINDTRANSFER
a transfer occurs
Definition cel.h:66
@ AST_CEL_LOCAL_OPTIMIZE
A local channel optimization occurred, this marks the end.
Definition cel.h:78

Function Documentation

◆ ast_cel_backend_register()

int ast_cel_backend_register ( const char *  name,
ast_cel_backend_cb  backend_callback 
)

Register a CEL backend.

Parameters
nameName of backend to register
backend_callbackCallback to register
Return values
zeroon success
non-zeroon failure
Since
12

Definition at line 1836 of file cel.c.

1837{
1839 struct cel_backend *backend;
1840
1841 if (!backends || ast_strlen_zero(name) || !backend_callback) {
1842 return -1;
1843 }
1844
1845 /* The backend object is immutable so it doesn't need a lock of its own. */
1846 backend = ao2_alloc_options(sizeof(*backend) + 1 + strlen(name), NULL,
1848 if (!backend) {
1849 return -1;
1850 }
1851 strcpy(backend->name, name);/* Safe */
1852 backend->callback = backend_callback;
1853
1854 ao2_link(backends, backend);
1855 ao2_ref(backend, -1);
1856 return 0;
1857}
#define ao2_link(container, obj)
Add an object to a container.
Definition astobj2.h:1532
@ AO2_ALLOC_OPT_LOCK_NOLOCK
Definition astobj2.h:367
#define ao2_cleanup(obj)
Definition astobj2.h:1934
#define ao2_global_obj_ref(holder)
Get a reference to the object stored in the global holder.
Definition astobj2.h:918
#define ao2_ref(o, delta)
Reference/unreference an object and return the old refcount.
Definition astobj2.h:459
#define ao2_alloc_options(data_size, destructor_fn, options)
Definition astobj2.h:404
static const char name[]
Definition format_mp3.c:68
#define NULL
Definition resample.c:96
static force_inline int attribute_pure ast_strlen_zero(const char *s)
Definition strings.h:65
Generic container type.
the list of registered channel types
Definition channel.c:125
ast_cel_backend_cb callback
Definition cel.c:350
char name[0]
Definition cel.c:351
#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:981

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, name, NULL, and RAII_VAR.

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

◆ ast_cel_backend_unregister()

int ast_cel_backend_unregister ( const char *  name)

Unregister a CEL backend.

Parameters
nameName of backend to unregister
Return values
zeroon success
non-zeroon failure
Since
12

Definition at line 1824 of file cel.c.

1825{
1826 struct ao2_container *backends = ao2_global_obj_ref(cel_backends);
1827
1828 if (backends) {
1830 ao2_ref(backends, -1);
1831 }
1832
1833 return 0;
1834}
#define ao2_find(container, arg, flags)
Definition astobj2.h:1736
@ OBJ_NODATA
Definition astobj2.h:1044
@ OBJ_UNLINK
Definition astobj2.h:1039
@ OBJ_SEARCH_KEY
The arg parameter is a search key, but is not an object.
Definition astobj2.h:1101

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

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

◆ ast_cel_check_enabled()

unsigned int ast_cel_check_enabled ( void  )

Check to see if CEL is enabled.

Since
1.8
Return values
zeronot enabled
non-zeroenabled

Check to see if CEL is enabled.

Comparator function for cel_backend

Hashing function for dialstatus container

Comparator function for dialstatus container

Definition at line 366 of file cel.c.

367{
368 unsigned int enabled;
369 struct cel_config *cfg = ao2_global_obj_ref(cel_configs);
370
371 enabled = (!cfg || !cfg->general) ? 0 : cfg->general->enable;
372 ao2_cleanup(cfg);
373 return enabled;
374}
static int enabled
Definition dnsmgr.c:91
A container that holds all config-related information.
Definition cel.c:228
struct ast_cel_general_config * general
Definition cel.c:229

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

Referenced by ast_cel_set_config(), handle_cli_status(), load_module(), and reload_module().

◆ ast_cel_create_event()

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.

Parameters
snapshotAn ast_channel_snapshot of the primary channel associated with this channel event.
event_typeThe type of call event being reported.
userdefevnameCustom name for the call event. (optional)
extraAn event-specific opaque JSON blob to be rendered and placed in the "CEL_EXTRA" information element of the call event. (optional)
peer_strA list of comma-separated peer channel names. (optional)
Since
12
Return values
Thecreated ast_event structure
NULLon failure

Definition at line 540 of file cel.c.

543{
544 struct timeval eventtime = ast_tvnow();
545
546 return ast_cel_create_event_with_time(snapshot, event_type, &eventtime,
547 userdefevname, extra, peer);
548}
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)
Allocate and populate a CEL event structure.
Definition cel.c:550
struct timeval ast_tvnow(void)
Returns current timeval. Meant to replace calls to gettimeofday().
Definition time.h:159

References ast_cel_create_event_with_time(), and ast_tvnow().

Referenced by append_expected_event_snapshot().

◆ ast_cel_create_event_with_time()

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.

Parameters
snapshotAn ast_channel_snapshot of the primary channel associated with this channel event.
event_typeThe type of call event being reported.
event_timeThe time at which the event occurred.
userdefevnameCustom name for the call event. (optional)
extraAn event-specific opaque JSON blob to be rendered and placed in the "CEL_EXTRA" information element of the call event. (optional)
peer_strA list of comma-separated peer channel names. (optional)
Since
13.29.0
16.6.0
Return values
Thecreated ast_event structure
NULLon failure

Definition at line 550 of file cel.c.

553{
554 RAII_VAR(char *, extra_txt, NULL, ast_json_free);
555 if (extra) {
556 extra_txt = ast_json_dump_string(extra);
557 }
583}
struct ast_event * ast_event_new(enum ast_event_type event_type,...)
Create a new event.
Definition event.c:403
@ AST_EVENT_IE_CEL_ACCTCODE
Channel Event AccountCode Used by: AST_EVENT_CEL Payload type: STR.
Definition event_defs.h:205
@ AST_EVENT_IE_END
Definition event_defs.h:70
@ AST_EVENT_IE_CEL_EXTRA
Channel Event extra data Used by: AST_EVENT_CEL Payload type: STR.
Definition event_defs.h:259
@ AST_EVENT_IE_CEL_CONTEXT
Channel Event context name Used by: AST_EVENT_CEL Payload type: STR.
Definition event_defs.h:175
@ AST_EVENT_IE_CEL_PEERACCT
Channel Event peeraccount Used by: AST_EVENT_CEL Payload type: STR.
Definition event_defs.h:253
@ AST_EVENT_IE_CEL_CIDRDNIS
Channel Event CID RDNIS field Used by: AST_EVENT_CEL Payload type: STR.
Definition event_defs.h:229
@ AST_EVENT_IE_CEL_EVENT_TIME
Channel Event Time (seconds) Used by: AST_EVENT_CEL Payload type: UINT.
Definition event_defs.h:139
@ AST_EVENT_IE_CEL_CHANNAME
Channel Event channel name Used by: AST_EVENT_CEL Payload type: STR.
Definition event_defs.h:181
@ AST_EVENT_IE_CEL_CIDANI
Channel Event CID ANI field Used by: AST_EVENT_CEL Payload type: STR.
Definition event_defs.h:223
@ AST_EVENT_IE_CEL_CIDDNID
Channel Event CID dnid Used by: AST_EVENT_CEL Payload type: STR.
Definition event_defs.h:235
@ AST_EVENT_IE_CEL_EXTEN
Channel Event extension name Used by: AST_EVENT_CEL Payload type: STR.
Definition event_defs.h:169
@ AST_EVENT_IE_CEL_CIDNAME
Channel Event CID name Used by: AST_EVENT_CEL Payload type: STR.
Definition event_defs.h:157
@ AST_EVENT_IE_CEL_AMAFLAGS
Channel Event AMA flags Used by: AST_EVENT_CEL Payload type: UINT.
Definition event_defs.h:199
@ AST_EVENT_IE_CEL_USEREVENT_NAME
Channel Event User Event Name Used by: AST_EVENT_CEL Payload type: STR.
Definition event_defs.h:151
@ AST_EVENT_IE_CEL_TENANTID
Channel Event TenantID Used by: AST_EVENT_CEL Payload type: STR.
Definition event_defs.h:320
@ AST_EVENT_IE_CEL_LINKEDID
Channel Event LinkedID Used by: AST_EVENT_CEL Payload type: STR.
Definition event_defs.h:247
@ AST_EVENT_IE_CEL_EVENT_TIME_USEC
Channel Event Time (micro-seconds) Used by: AST_EVENT_CEL Payload type: UINT.
Definition event_defs.h:145
@ AST_EVENT_IE_CEL_EVENT_TYPE
Channel Event Type Used by: AST_EVENT_CEL Payload type: UINT.
Definition event_defs.h:133
@ AST_EVENT_IE_CEL_UNIQUEID
Channel Event UniqueID Used by: AST_EVENT_CEL Payload type: STR.
Definition event_defs.h:211
@ AST_EVENT_IE_CEL_APPNAME
Channel Event app name Used by: AST_EVENT_CEL Payload type: STR.
Definition event_defs.h:187
@ AST_EVENT_IE_CEL_APPDATA
Channel Event app args/data Used by: AST_EVENT_CEL Payload type: STR.
Definition event_defs.h:193
@ AST_EVENT_IE_CEL_PEER
Channel Event Peer – for Things involving multiple channels, like BRIDGE Used by: AST_EVENT_CEL Paylo...
Definition event_defs.h:241
@ AST_EVENT_IE_CEL_CIDNUM
Channel Event CID num Used by: AST_EVENT_CEL Payload type: STR.
Definition event_defs.h:163
@ AST_EVENT_IE_CEL_USERFIELD
Channel Event Userfield Used by: AST_EVENT_CEL Payload type: STR.
Definition event_defs.h:217
@ AST_EVENT_CEL
Definition event_defs.h:50
@ AST_EVENT_IE_PLTYPE_UINT
Definition event_defs.h:333
@ AST_EVENT_IE_PLTYPE_STR
Definition event_defs.h:335
void ast_json_free(void *p)
Asterisk's custom JSON allocator. Exposed for use by unit tests.
Definition json.c:52
#define ast_json_dump_string(root)
Encode a JSON value to a compact string.
Definition json.h:810
#define S_OR(a, b)
returns the equivalent of logic or for strings: first one if not empty, otherwise second one.
Definition strings.h:80
const ast_string_field tenantid
const ast_string_field accountcode
const ast_string_field userfield
const ast_string_field uniqueid
const ast_string_field name
const ast_string_field number
const ast_string_field rdnis
const ast_string_field ani
const ast_string_field name
const ast_string_field dnid
const ast_string_field data
const ast_string_field context
const ast_string_field exten
const ast_string_field appl
struct ast_channel_snapshot_dialplan * dialplan
struct ast_channel_snapshot_peer * peer
struct ast_channel_snapshot_base * base
struct ast_channel_snapshot_caller * caller

References ast_channel_snapshot_peer::account, ast_channel_snapshot_base::accountcode, ast_channel_snapshot::amaflags, ast_channel_snapshot_caller::ani, ast_channel_snapshot_dialplan::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_TENANTID, 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_channel_snapshot::base, ast_channel_snapshot::caller, ast_channel_snapshot_dialplan::context, ast_channel_snapshot_dialplan::data, ast_channel_snapshot::dialplan, ast_channel_snapshot_caller::dnid, ast_channel_snapshot_dialplan::exten, ast_channel_snapshot_peer::linkedid, ast_channel_snapshot_caller::name, ast_channel_snapshot_base::name, NULL, ast_channel_snapshot_caller::number, ast_channel_snapshot::peer, RAII_VAR, ast_channel_snapshot_caller::rdnis, S_OR, ast_channel_snapshot_base::tenantid, ast_channel_snapshot_base::uniqueid, and ast_channel_snapshot_base::userfield.

Referenced by ast_cel_create_event(), and cel_report_event().

◆ ast_cel_fabricate_channel_from_event()

struct ast_channel * ast_cel_fabricate_channel_from_event ( const struct ast_event event)

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
eventthe 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 717 of file cel.c.

718{
719 struct varshead *headp;
720 struct ast_var_t *newvariable;
721 const char *mixed_name;
722 char timebuf[30];
723 struct ast_channel *tchan;
724 struct ast_cel_event_record record = {
726 };
727 struct ast_datastore *datastore;
728 char *app_data;
729 RAII_VAR(struct cel_config *, cfg, ao2_global_obj_ref(cel_configs), ao2_cleanup);
730
731 if (!cfg || !cfg->general) {
732 return NULL;
733 }
734
735 /* do not call ast_channel_alloc because this is not really a real channel */
736 if (!(tchan = ast_dummy_channel_alloc())) {
737 return NULL;
738 }
739
740 headp = ast_channel_varshead(tchan);
741
742 /* first, get the variables from the event */
743 if (ast_cel_fill_record(event, &record)) {
744 ast_channel_unref(tchan);
745 return NULL;
746 }
747
748 /* next, fill the channel with their data */
749 mixed_name = (record.event_type == AST_CEL_USER_DEFINED)
750 ? record.user_defined_name : record.event_name;
751 if ((newvariable = ast_var_assign("eventtype", mixed_name))) {
752 AST_LIST_INSERT_HEAD(headp, newvariable, entries);
753 }
754
755 cel_format_eventtime(cfg, record.event_time, timebuf, sizeof(timebuf));
756
757 if ((newvariable = ast_var_assign("eventtime", timebuf))) {
758 AST_LIST_INSERT_HEAD(headp, newvariable, entries);
759 }
760
761 if ((newvariable = ast_var_assign("eventenum", record.event_name))) {
762 AST_LIST_INSERT_HEAD(headp, newvariable, entries);
763 }
764 if ((newvariable = ast_var_assign("userdeftype", record.user_defined_name))) {
765 AST_LIST_INSERT_HEAD(headp, newvariable, entries);
766 }
767 if ((newvariable = ast_var_assign("eventextra", record.extra))) {
768 AST_LIST_INSERT_HEAD(headp, newvariable, entries);
769 }
770
771 ast_channel_caller(tchan)->id.name.valid = 1;
773 ast_channel_caller(tchan)->id.number.valid = 1;
780
781 ast_channel_exten_set(tchan, record.extension);
782 ast_channel_context_set(tchan, record.context);
783 ast_channel_name_set(tchan, record.channel_name);
785 ast_channel_accountcode_set(tchan, record.account_code);
786 ast_channel_peeraccount_set(tchan, record.peer_account);
787 ast_channel_userfield_set(tchan, record.user_field);
788 ast_channel_tenantid_set(tchan, record.tenant_id);
789
790 if ((newvariable = ast_var_assign("BRIDGEPEER", record.peer))) {
791 AST_LIST_INSERT_HEAD(headp, newvariable, entries);
792 }
793
794 ast_channel_amaflags_set(tchan, record.amaflag);
795
796 /* We need to store an 'application name' and 'application
797 * data' on the channel for logging purposes, but the channel
798 * structure only provides a place to store pointers, and it
799 * expects these pointers to be pointing to data that does not
800 * need to be freed. This means that the channel's destructor
801 * does not attempt to free any storage that these pointers
802 * point to. However, we can't provide data in that form directly for
803 * these structure members. In order to ensure that these data
804 * elements have a lifetime that matches the channel's
805 * lifetime, we'll put them in a datastore attached to the
806 * channel, and set's the channel's pointers to point into the
807 * datastore. The datastore will then be automatically destroyed
808 * when the channel is destroyed.
809 */
810
812 ast_channel_unref(tchan);
813 return NULL;
814 }
815
816 if (!(app_data = ast_malloc(strlen(record.application_name) + strlen(record.application_data) + 2))) {
817 ast_datastore_free(datastore);
818 ast_channel_unref(tchan);
819 return NULL;
820 }
821
822 ast_channel_appl_set(tchan, strcpy(app_data, record.application_name));
823 ast_channel_data_set(tchan, strcpy(app_data + strlen(record.application_name) + 1,
824 record.application_data));
825
826 datastore->data = app_data;
827 ast_channel_datastore_add(tchan, datastore);
828
829 return tchan;
830}
#define ast_strdup(str)
A wrapper for strdup()
Definition astmm.h:241
#define ast_malloc(len)
A wrapper for malloc()
Definition astmm.h:191
static int cel_format_eventtime(struct cel_config *cfg, struct timeval eventtime, char *timebuf, size_t len)
Definition cel.c:676
int ast_cel_fill_record(const struct ast_event *e, struct ast_cel_event_record *r)
Fill in an ast_cel_event_record from a CEL event.
Definition cel.c:870
static const struct ast_datastore_info fabricated_channel_datastore
Definition cel.c:712
#define AST_CEL_EVENT_RECORD_VERSION
struct ABI version
Definition cel.h:162
void ast_channel_exten_set(struct ast_channel *chan, const char *value)
void ast_channel_appl_set(struct ast_channel *chan, const char *value)
void ast_channel_internal_set_fake_ids(struct ast_channel *chan, const char *uniqueid, const char *linkedid)
Set uniqueid and linkedid string value only (not time)
int ast_channel_datastore_add(struct ast_channel *chan, struct ast_datastore *datastore)
Add a datastore to a channel.
Definition channel.c:2376
struct varshead * ast_channel_varshead(struct ast_channel *chan)
void ast_channel_tenantid_set(struct ast_channel *chan, const char *value)
void ast_channel_data_set(struct ast_channel *chan, const char *value)
struct ast_party_redirecting * ast_channel_redirecting(struct ast_channel *chan)
struct ast_party_dialed * ast_channel_dialed(struct ast_channel *chan)
#define ast_channel_unref(c)
Decrease channel reference count.
Definition channel.h:3018
void ast_channel_amaflags_set(struct ast_channel *chan, enum ama_flags value)
void ast_channel_context_set(struct ast_channel *chan, const char *value)
#define ast_dummy_channel_alloc()
Create a fake channel structure.
Definition channel.h:1328
struct ast_party_caller * ast_channel_caller(struct ast_channel *chan)
void ast_channel_name_set(struct ast_channel *chan, const char *value)
#define ast_var_assign(name, value)
Definition chanvars.h:40
#define ast_datastore_alloc(info, uid)
Definition datastore.h:85
int ast_datastore_free(struct ast_datastore *datastore)
Free a data store object.
Definition datastore.c:68
#define AST_LIST_INSERT_HEAD(head, elm, field)
Inserts a list entry at the head of a list.
Helper struct for getting the fields out of a CEL event.
Definition cel.h:157
const char * caller_id_dnid
Definition cel.h:176
const char * application_data
Definition cel.h:181
const char * account_code
Definition cel.h:182
const char * caller_id_rdnis
Definition cel.h:175
const char * extra
Definition cel.h:190
const char * extension
Definition cel.h:177
const char * caller_id_num
Definition cel.h:173
const char * channel_name
Definition cel.h:179
const char * linked_id
Definition cel.h:185
const char * peer_account
Definition cel.h:183
const char * peer
Definition cel.h:189
enum ast_cel_event_type event_type
Definition cel.h:168
const char * unique_id
Definition cel.h:184
const char * user_defined_name
Definition cel.h:171
const char * context
Definition cel.h:178
const char * application_name
Definition cel.h:180
struct timeval event_time
Definition cel.h:169
uint32_t version
struct ABI version
Definition cel.h:167
const char * tenant_id
Definition cel.h:186
const char * user_field
Definition cel.h:188
const char * caller_id_ani
Definition cel.h:174
const char * caller_id_name
Definition cel.h:172
const char * event_name
Definition cel.h:170
Main Channel structure associated with a channel.
Structure for a data store object.
Definition datastore.h:64
void * data
Definition datastore.h:66
struct ast_party_id id
Caller party ID.
Definition channel.h:422
struct ast_party_id ani
Automatic Number Identification (ANI)
Definition channel.h:429
char * str
Subscriber phone number (Malloced)
Definition channel.h:388
struct ast_party_dialed::@217 number
Dialed/Called number.
struct ast_party_name name
Subscriber name.
Definition channel.h:342
struct ast_party_number number
Subscriber phone number.
Definition channel.h:344
unsigned char valid
TRUE if the name information is valid/present.
Definition channel.h:281
char * str
Subscriber name (Malloced)
Definition channel.h:266
unsigned char valid
TRUE if the number information is valid/present.
Definition channel.h:299
char * str
Subscriber phone number (Malloced)
Definition channel.h:293
struct ast_party_id from
Who is redirecting the call (Sent to the party the call is redirected toward)
Definition channel.h:529

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_tenantid_set(), ast_channel_unref, ast_channel_varshead(), ast_datastore_alloc, ast_datastore_free(), ast_dummy_channel_alloc, AST_LIST_INSERT_HEAD, ast_malloc, ast_strdup, 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, cel_format_eventtime(), 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, fabricated_channel_datastore, ast_party_redirecting::from, ast_party_caller::id, ast_cel_event_record::linked_id, ast_party_id::name, NULL, ast_party_id::number, ast_party_dialed::number, ast_cel_event_record::peer, ast_cel_event_record::peer_account, RAII_VAR, ast_party_name::str, ast_party_number::str, ast_party_dialed::str, 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, ast_party_name::valid, ast_party_number::valid, and ast_cel_event_record::version.

Referenced by dummy_chan_alloc_cel().

◆ ast_cel_fill_record()

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]eventthe CEL event
[out]rthe ast_cel_event_record to fill in
Since
1.8
Return values
0success
non-zerofailure

Definition at line 870 of file cel.c.

871{
873 ast_log(LOG_ERROR, "Module ABI mismatch for ast_cel_event_record. "
874 "Please ensure all modules were compiled for "
875 "this version of Asterisk.\n");
876 return -1;
877 }
878
880
883
885
906
907 return 0;
908}
#define ast_log
Definition astobj2.c:42
const char * ast_cel_get_type_name(enum ast_cel_event_type type)
Get the name of a CEL event type.
Definition cel.c:514
uint32_t ast_event_get_ie_uint(const struct ast_event *event, enum ast_event_ie_type ie_type)
Get the value of an information element that has an integer payload.
Definition event.c:294
const char * ast_event_get_ie_str(const struct ast_event *event, enum ast_event_ie_type ie_type)
Get the value of an information element that has a string payload.
Definition event.c:303
#define LOG_ERROR

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_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_TENANTID, 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::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 ast_cel_fabricate_channel_from_event(), cel_bs_put(), manager_log(), odbc_log(), pgsql_log(), radius_log(), and tds_log().

◆ ast_cel_format_eventtime()

int ast_cel_format_eventtime ( struct timeval  eventtime,
char *  timebuf,
size_t  len 
)

Format an event timeval using dateformat from cel.conf.

Parameters
eventtimeThe timeval to format
timebufA buffer of at least 30 characters to place the result in
lenLength of buffer
Return values
zeroSuccess
non-zeroFailure

Definition at line 694 of file cel.c.

695{
696 struct cel_config *cfg = ao2_global_obj_ref(cel_configs);
697 int res = 0;
698
699 if (!cfg) {
700 return -1;
701 }
702
703 res = cel_format_eventtime(cfg, eventtime, timebuf, len);
704 ao2_cleanup(cfg);
705
706 return res;
707}
static int len(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t buflen)

References ao2_cleanup, ao2_global_obj_ref, cel_format_eventtime(), and len().

Referenced by format_timeval().

◆ ast_cel_general_config_alloc()

void * ast_cel_general_config_alloc ( void  )

Allocate a CEL configuration object.

Return values
NULLon error
Thenew CEL configuration object

Definition at line 207 of file cel.c.

208{
210
211 if (!(cfg = ao2_alloc(sizeof(*cfg), cel_general_config_dtor))) {
212 return NULL;
213 }
214
215 if (ast_string_field_init(cfg, 64)) {
216 return NULL;
217 }
218
219 if (!(cfg->apps = ast_str_container_alloc(NUM_APP_BUCKETS))) {
220 return NULL;
221 }
222
223 ao2_ref(cfg, +1);
224 return cfg;
225}
#define ao2_alloc(data_size, destructor_fn)
Definition astobj2.h:409
static void cel_general_config_dtor(void *obj)
Destructor for cel_config.
Definition cel.c:199
#define NUM_APP_BUCKETS
Number of buckets for the appset container.
Definition cel.c:174
#define ast_string_field_init(x, size)
Initialize a field pool and fields.
#define ast_str_container_alloc(buckets)
Allocates a hash container for bare strings.
Definition strings.h:1365
A structure to hold CEL global configuration options.
Definition cel.h:243

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().

◆ ast_cel_get_config()

struct ast_cel_general_config * ast_cel_get_config ( void  )

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
NULLon error
Thecurrent CEL configuration

Definition at line 1786 of file cel.c.

1787{
1788 RAII_VAR(struct cel_config *, mod_cfg, ao2_global_obj_ref(cel_configs), ao2_cleanup);
1789
1790 if (!mod_cfg || !mod_cfg->general) {
1791 return NULL;
1792 }
1793
1794 ao2_ref(mod_cfg->general, +1);
1795 return mod_cfg->general;
1796}

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

Referenced by test_cel_init_cb().

◆ ast_cel_get_type_name()

const char * ast_cel_get_type_name ( enum ast_cel_event_type  type)

Get the name of a CEL event type.

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

Definition at line 514 of file cel.c.

515{
516 return S_OR(cel_event_types[type], "Unknown");
517}
static const char *const cel_event_types[CEL_MAX_EVENT_IDS]
Map of ast_cel_event_type to strings.
Definition cel.c:324
static const char type[]

References cel_event_types, S_OR, and type.

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

◆ ast_cel_publish_event()

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
chanThis is the primary channel associated with this channel event.
event_typeThis is the type of call event being reported.
blobThis contains any additional parameters that need to be conveyed for this event.

Definition at line 1762 of file cel.c.

1765{
1766 struct ast_json *cel_blob;
1767 struct stasis_message *message;
1768
1769 cel_blob = ast_json_pack("{s: i, s: o}",
1770 "event_type", event_type,
1771 "event_details", ast_json_ref(blob));
1772
1774 if (message) {
1776 }
1778 ast_json_unref(cel_blob);
1779}
struct stasis_topic * ast_cel_topic(void)
Get the CEL topic.
Definition cel.c:1781
struct stasis_message_type * cel_generic_type(void)
const char * ast_channel_uniqueid(const struct ast_channel *chan)
struct stasis_message * ast_channel_blob_create_from_cache(const char *uniqueid, struct stasis_message_type *type, struct ast_json *blob)
Create a ast_channel_blob message, pulling channel state from the cache.
void ast_json_unref(struct ast_json *value)
Decrease refcount on value. If refcount reaches zero, value is freed.
Definition json.c:73
struct ast_json * ast_json_pack(char const *format,...)
Helper for creating complex JSON values.
Definition json.c:612
struct ast_json * ast_json_ref(struct ast_json *value)
Increase refcount on value.
Definition json.c:67
void stasis_publish(struct stasis_topic *topic, struct stasis_message *message)
Publish a message to a topic's subscribers.
Definition stasis.c:1578
Abstract JSON element (object, array, string, int, ...).

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

Referenced by ast_cel_publish_user_event(), ast_stopstream(), ast_streamfile(), celgenuserevent_exec(), moh_post_start(), moh_post_stop(), and send_dtmf_end_event().

◆ ast_cel_publish_user_event()

void ast_cel_publish_user_event ( struct ast_channel chan,
const char *  event,
const char *  extra 
)

Publish a CEL user event.

Since
18
Note
This serves as a wrapper function around ast_cel_publish_event() to help pack the extra details before publishing.
Parameters
chanThis is the primary channel associated with this channel event.
eventThis is the user event being reported.
extraThis contains any extra parameters that need to be conveyed for this event.

Definition at line 1747 of file cel.c.

1750{
1751 RAII_VAR(struct ast_json *, blob, NULL, ast_json_unref);
1752
1753 blob = ast_json_pack("{s: s, s: {s: s}}",
1754 "event", event,
1755 "extra", "extra", S_OR(extra, ""));
1756 if (!blob) {
1757 return;
1758 }
1760}
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:1762

References ast_cel_publish_event(), AST_CEL_USER_DEFINED, ast_json_pack(), ast_json_unref(), NULL, RAII_VAR, and S_OR.

◆ ast_cel_set_config()

void ast_cel_set_config ( struct ast_cel_general_config config)

Set the current CEL configuration.

Since
12
Parameters
configThe new CEL configuration

Definition at line 1798 of file cel.c.

1799{
1800 int was_enabled;
1801 int is_enabled;
1802 struct ast_cel_general_config *cleanup_config;
1803 struct cel_config *mod_cfg = ao2_global_obj_ref(cel_configs);
1804
1805 if (mod_cfg) {
1806 was_enabled = ast_cel_check_enabled();
1807
1808 cleanup_config = mod_cfg->general;
1810 mod_cfg->general = config;
1811 ao2_cleanup(cleanup_config);
1812
1814 if (!was_enabled && is_enabled) {
1815 create_routes();
1816 } else if (was_enabled && !is_enabled) {
1818 }
1819
1820 ao2_ref(mod_cfg, -1);
1821 }
1822}
#define ao2_bump(obj)
Bump refcount on an AO2 object by one, returning the object.
Definition astobj2.h:480
static void destroy_routes(void)
Definition cel.c:1492
static int create_routes(void)
Create the Stasis message router and routes for CEL.
Definition cel.c:1576
unsigned int ast_cel_check_enabled(void)
Hashing function for cel_backend.
Definition cel.c:366
static const char config[]
static int is_enabled(void)
Helper function to check if module is enabled.
Definition res_ari.c:96

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

Referenced by cel_verify_and_cleanup_cb(), and test_cel_init_cb().

◆ ast_cel_str_to_event_type()

enum ast_cel_event_type ast_cel_str_to_event_type ( const char *  name)

Get the event type from a string.

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

Definition at line 441 of file cel.c.

442{
443 unsigned int i;
444
445 for (i = 0; i < ARRAY_LEN(cel_event_types); i++) {
446 if (cel_event_types[i] && !strcasecmp(name, cel_event_types[i])) {
447 return i;
448 }
449 }
450
451 ast_log(LOG_ERROR, "Unknown event name '%s'\n", name);
453}
#define ARRAY_LEN(a)
Definition utils.h:706

References ARRAY_LEN, AST_CEL_INVALID_VALUE, ast_log, cel_event_types, LOG_ERROR, and name.

Referenced by events_handler().

◆ ast_cel_topic()

struct stasis_topic * ast_cel_topic ( void  )

Get the CEL topic.

Return values
TheCEL topic
NULLif not allocated

Definition at line 1781 of file cel.c.

1782{
1783 return cel_topic;
1784}
static struct stasis_topic * cel_topic
Definition cel.c:136

References cel_topic.

Referenced by ast_cel_publish_event(), and create_subscriptions().