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

Channel Event Logging API. More...

#include "asterisk.h"
#include "asterisk/module.h"
#include "asterisk/channel.h"
#include "asterisk/pbx.h"
#include "asterisk/cel.h"
#include "asterisk/logger.h"
#include "asterisk/linkedlists.h"
#include "asterisk/utils.h"
#include "asterisk/config.h"
#include "asterisk/config_options.h"
#include "asterisk/cli.h"
#include "asterisk/astobj2.h"
#include "asterisk/stasis_message_router.h"
#include "asterisk/stasis_channels.h"
#include "asterisk/stasis_bridges.h"
#include "asterisk/bridge.h"
#include "asterisk/parking.h"
#include "asterisk/pickup.h"
#include "asterisk/core_local.h"
#include "asterisk/taskprocessor.h"
Include dependency graph for cel.c:

Go to the source code of this file.

Data Structures

struct  cel_backend
 
struct  cel_config
 A container that holds all config-related information. More...
 
struct  cel_dialstatus
 
struct  cel_linkedid
 

Macros

#define BACKEND_BUCKETS   13
 
#define CEL_MAX_EVENT_IDS   64
 Maximum possible CEL event IDs.
 
#define NUM_APP_BUCKETS   97
 Number of buckets for the appset container.
 
#define NUM_DIALSTATUS_BUCKETS   251
 Number of buckets for the dialstatus container.
 

Typedefs

typedef void(* cel_channel_snapshot_monitor) (struct ast_channel_snapshot *old_snapshot, struct ast_channel_snapshot *new_snapshot, const struct timeval *event_time)
 Typedef for callbacks that get called on channel snapshot updates.
 

Functions

static void __reg_module (void)
 
static void __unreg_module (void)
 
static AO2_GLOBAL_OBJ_STATIC (cel_backends)
 
static AO2_GLOBAL_OBJ_STATIC (cel_configs)
 
static AO2_GLOBAL_OBJ_STATIC (cel_dialstatus_store)
 
static AO2_GLOBAL_OBJ_STATIC (cel_linkedids)
 
static int apps_handler (const struct aco_option *opt, struct ast_variable *var, void *obj)
 
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)
 Hashing function for cel_backend.
 
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)
 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)
 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 *e, 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.
 
static int ast_cel_track_event (enum ast_cel_event_type et)
 
struct ast_moduleAST_MODULE_SELF_SYM (void)
 
static void cel_attended_transfer_cb (void *data, struct stasis_subscription *sub, struct stasis_message *message)
 
static int cel_backend_send_cb (void *obj, void *arg, int flags)
 
static void cel_blind_transfer_cb (void *data, struct stasis_subscription *sub, struct stasis_message *message)
 
static void cel_bridge_enter_cb (void *data, struct stasis_subscription *sub, struct stasis_message *message)
 
static void cel_bridge_leave_cb (void *data, struct stasis_subscription *sub, struct stasis_message *message)
 
static void cel_channel_app_change (struct ast_channel_snapshot *old_snapshot, struct ast_channel_snapshot *new_snapshot, const struct timeval *event_time)
 
static void cel_channel_linkedid_change (struct ast_channel_snapshot *old_snapshot, struct ast_channel_snapshot *new_snapshot, const struct timeval *event_time)
 
static void cel_channel_state_change (struct ast_channel_snapshot *old_snapshot, struct ast_channel_snapshot *new_snapshot, const struct timeval *event_time)
 Handle channel state changes.
 
static void * cel_config_alloc (void)
 
static void cel_config_dtor (void *obj)
 Destructor for cel_config.
 
static void cel_dial_cb (void *data, struct stasis_subscription *sub, struct stasis_message *message)
 
static int cel_filter_channel_snapshot (struct ast_channel_snapshot *snapshot)
 
static int cel_format_eventtime (struct cel_config *cfg, struct timeval eventtime, char *timebuf, size_t len)
 
static void cel_general_config_dtor (void *obj)
 Destructor for cel_config.
 
static struct ast_strcel_generate_peer_str (struct ast_bridge_snapshot *bridge, struct ast_channel_snapshot *chan)
 
static void cel_generic_cb (void *data, struct stasis_subscription *sub, struct stasis_message *message)
 
struct stasis_message_typecel_generic_type (void)
 
static int cel_linkedid_ref (const char *linkedid)
 
static void cel_local_optimization_begin_cb (void *data, struct stasis_subscription *sub, struct stasis_message *message)
 
static void cel_local_optimization_cb_helper (void *data, struct stasis_subscription *sub, struct stasis_message *message, enum ast_cel_event_type event_type)
 
static void cel_local_optimization_end_cb (void *data, struct stasis_subscription *sub, struct stasis_message *message)
 
static void cel_parking_cb (void *data, struct stasis_subscription *sub, struct stasis_message *message)
 
static void cel_pickup_cb (void *data, struct stasis_subscription *sub, struct stasis_message *message)
 
static int cel_pre_apply_config (void)
 
static int cel_report_event (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)
 
static void cel_snapshot_update_cb (void *data, struct stasis_subscription *sub, struct stasis_message *message)
 
static int cel_track_app (const char *const_app)
 
static void check_retire_linkedid (struct ast_channel_snapshot *snapshot, const struct timeval *event_time)
 
 CONFIG_INFO_CORE ("cel", cel_cfg_info, cel_configs, cel_config_alloc,.files=ACO_FILES(&cel_conf),.pre_apply_config=cel_pre_apply_config,)
 
static int create_routes (void)
 Create the Stasis message router and routes for CEL.
 
static int create_subscriptions (void)
 Create the Stasis subscriptions for CEL.
 
static void destroy_routes (void)
 
static void destroy_subscriptions (void)
 
static int events_handler (const struct aco_option *opt, struct ast_variable *var, void *obj)
 
static const char * get_blob_variable (struct ast_multi_channel_blob *blob, const char *varname)
 
static struct cel_dialstatusget_dialstatus (const char *uniqueid)
 
static char * handle_cli_status (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
 
static int is_valid_dialstatus (struct ast_multi_channel_blob *blob)
 
static int load_module (void)
 
static int reload_module (void)
 
static void save_dialstatus (struct ast_multi_channel_blob *blob, struct ast_channel_snapshot *snapshot)
 
 STASIS_MESSAGE_TYPE_DEFN (cel_generic_type)
 
static int unload_module (void)
 

Variables

static struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_GLOBAL_SYMBOLS | AST_MODFLAG_LOAD_ORDER , .description = "CEL Engine" , .key = ASTERISK_GPL_KEY , .buildopt_sum = AST_BUILDOPT_SUM, .support_level = AST_MODULE_SUPPORT_CORE, .load = load_module, .unload = unload_module, .reload = reload_module, .load_pri = AST_MODPRI_CORE, .requires = "extconfig", }
 
static const struct ast_module_infoast_module_info = &__mod_info
 
static struct stasis_topiccel_aggregation_topic
 
static struct stasis_forwardcel_bridge_forwarder
 
static struct stasis_forwardcel_cel_forwarder
 
static struct stasis_forwardcel_channel_forwarder
 
cel_channel_snapshot_monitor cel_channel_monitors []
 Handlers for channel snapshot changes.
 
static struct aco_file cel_conf
 The config file to be processed for the module.
 
static const char *const cel_event_types [CEL_MAX_EVENT_IDS]
 Map of ast_cel_event_type to strings.
 
static struct stasis_forwardcel_parking_forwarder
 
static struct stasis_message_routercel_state_router
 
static struct stasis_topiccel_topic
 
static struct ast_cli_entry cli_status = { .handler = handle_cli_status , .summary = "Display the CEL status" ,}
 
static const struct ast_datastore_info fabricated_channel_datastore
 
static struct aco_type general_option
 An aco_type structure to link the "general" category to the ast_cel_general_config type.
 
static struct aco_typegeneral_options [] = ACO_TYPES(&general_option)
 
static const char * ignore_categories []
 
static struct aco_type ignore_option
 

Detailed Description

Channel Event Logging API.

Author
Steve Murphy murf@.nosp@m.digi.nosp@m.um.co.nosp@m.m
Russell Bryant russe.nosp@m.ll@d.nosp@m.igium.nosp@m..com

Definition in file cel.c.

Macro Definition Documentation

◆ BACKEND_BUCKETS

#define BACKEND_BUCKETS   13

The number of buckets into which backend names will be hashed

Definition at line 160 of file cel.c.

◆ CEL_MAX_EVENT_IDS

#define CEL_MAX_EVENT_IDS   64

Maximum possible CEL event IDs.

Note
This limit is currently imposed by the eventset definition

Definition at line 169 of file cel.c.

◆ NUM_APP_BUCKETS

#define NUM_APP_BUCKETS   97

Number of buckets for the appset container.

Definition at line 174 of file cel.c.

◆ NUM_DIALSTATUS_BUCKETS

#define NUM_DIALSTATUS_BUCKETS   251

Number of buckets for the dialstatus container.

Definition at line 179 of file cel.c.

Typedef Documentation

◆ cel_channel_snapshot_monitor

typedef void(* cel_channel_snapshot_monitor) (struct ast_channel_snapshot *old_snapshot, struct ast_channel_snapshot *new_snapshot, const struct timeval *event_time)

Typedef for callbacks that get called on channel snapshot updates.

Definition at line 911 of file cel.c.

Function Documentation

◆ __reg_module()

static void __reg_module ( void  )
static

Definition at line 1866 of file cel.c.

◆ __unreg_module()

static void __unreg_module ( void  )
static

Definition at line 1866 of file cel.c.

◆ AO2_GLOBAL_OBJ_STATIC() [1/4]

static AO2_GLOBAL_OBJ_STATIC ( cel_backends  )
static

Container for CEL backend information

◆ AO2_GLOBAL_OBJ_STATIC() [2/4]

static AO2_GLOBAL_OBJ_STATIC ( cel_configs  )
static

◆ AO2_GLOBAL_OBJ_STATIC() [3/4]

static AO2_GLOBAL_OBJ_STATIC ( cel_dialstatus_store  )
static

Container for dial end multichannel blobs for holding on to dial statuses

◆ AO2_GLOBAL_OBJ_STATIC() [4/4]

static AO2_GLOBAL_OBJ_STATIC ( cel_linkedids  )
static

Container of channel references to a linkedid for CEL purposes.

◆ apps_handler()

static int apps_handler ( const struct aco_option opt,
struct ast_variable var,
void *  obj 
)
static

Definition at line 495 of file cel.c.

496{
497 struct ast_cel_general_config *cfg = obj;
498 char *apps = ast_strdupa(var->value);
499 char *cur_app;
500
501 while ((cur_app = strsep(&apps, ","))) {
502 cur_app = ast_strip(cur_app);
503 if (ast_strlen_zero(cur_app)) {
504 continue;
505 }
506
507 cur_app = ast_str_to_lower(cur_app);
508 ast_str_container_add(cfg->apps, cur_app);
509 }
510
511 return 0;
512}
#define var
Definition ast_expr2f.c:605
char * strsep(char **str, const char *delims)
#define ast_strdupa(s)
duplicate a string in memory from the stack
Definition astmm.h:298
static force_inline char * ast_str_to_lower(char *str)
Convert a string to all lower-case.
Definition strings.h:1321
static force_inline int attribute_pure ast_strlen_zero(const char *s)
Definition strings.h:65
char * ast_strip(char *s)
Strip leading/trailing whitespace from a string.
Definition strings.h:223
int ast_str_container_add(struct ao2_container *str_container, const char *add)
Adds a string to a string container allocated by ast_str_container_alloc.
Definition strings.c:205
Registered applications container.
Definition pbx_app.c:69
A structure to hold CEL global configuration options.
Definition cel.h:243
struct ao2_container * apps
Definition cel.h:252

References ast_cel_general_config::apps, ast_str_container_add(), ast_str_to_lower(), ast_strdupa, ast_strip(), ast_strlen_zero(), strsep(), and var.

Referenced by load_module().

◆ 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
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  )

Hashing function for cel_backend.

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
@ AST_CEL_USER_DEFINED
a user-defined event, the event name field should be set
Definition cel.h:70
#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

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}
@ AST_CEL_INVALID_VALUE
Definition cel.h:43
#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().

◆ ast_cel_track_event()

static int ast_cel_track_event ( enum ast_cel_event_type  et)
static

Definition at line 455 of file cel.c.

456{
457 RAII_VAR(struct cel_config *, cfg, ao2_global_obj_ref(cel_configs), ao2_cleanup);
458
459 if (!cfg || !cfg->general) {
460 return 0;
461 }
462
463 return (cfg->general->events & ((int64_t) 1 << et)) ? 1 : 0;
464}

References ao2_cleanup, ao2_global_obj_ref, and RAII_VAR.

Referenced by cel_channel_linkedid_change(), cel_channel_state_change(), and cel_report_event().

◆ AST_MODULE_SELF_SYM()

struct ast_module * AST_MODULE_SELF_SYM ( void  )

Definition at line 1866 of file cel.c.

◆ cel_attended_transfer_cb()

static void cel_attended_transfer_cb ( void *  data,
struct stasis_subscription sub,
struct stasis_message message 
)
static

Definition at line 1362 of file cel.c.

1365{
1367 struct ast_json *extra = NULL;
1368 struct ast_bridge_snapshot *bridge1, *bridge2;
1369 struct ast_channel_snapshot *channel1, *channel2;
1370
1371 /* Make sure bridge1 is always non-NULL */
1372 if (!xfer->to_transferee.bridge_snapshot) {
1373 bridge1 = xfer->to_transfer_target.bridge_snapshot;
1374 bridge2 = xfer->to_transferee.bridge_snapshot;
1375 channel1 = xfer->to_transfer_target.channel_snapshot;
1376 channel2 = xfer->to_transferee.channel_snapshot;
1377 } else {
1378 bridge1 = xfer->to_transferee.bridge_snapshot;
1379 bridge2 = xfer->to_transfer_target.bridge_snapshot;
1380 channel1 = xfer->to_transferee.channel_snapshot;
1381 channel2 = xfer->to_transfer_target.channel_snapshot;
1382 }
1383
1384 switch (xfer->dest_type) {
1386 return;
1387 /* handle these three the same */
1391 extra = ast_json_pack("{s: s, s: s, s: s, s: s, s: s, s: s, s: s, s: s}",
1392 "bridge1_id", bridge1->uniqueid,
1393 "channel2_name", channel2->base->name,
1394 "channel2_uniqueid", channel2->base->uniqueid,
1395 "bridge2_id", bridge2->uniqueid,
1396 "transferee_channel_name", xfer->transferee ? xfer->transferee->base->name : "N/A",
1397 "transferee_channel_uniqueid", xfer->transferee ? xfer->transferee->base->uniqueid : "N/A",
1398 "transfer_target_channel_name", xfer->target ? xfer->target->base->name : "N/A",
1399 "transfer_target_channel_uniqueid", xfer->target ? xfer->target->base->uniqueid : "N/A");
1400 if (!extra) {
1401 return;
1402 }
1403 break;
1406 extra = ast_json_pack("{s: s, s: s, s: s, s: s, s: s, s: s, s: s, s: s}",
1407 "bridge1_id", bridge1->uniqueid,
1408 "channel2_name", channel2->base->name,
1409 "channel2_uniqueid", channel2->base->uniqueid,
1410 "app", xfer->dest.app,
1411 "transferee_channel_name", xfer->transferee ? xfer->transferee->base->name : "N/A",
1412 "transferee_channel_uniqueid", xfer->transferee ? xfer->transferee->base->uniqueid : "N/A",
1413 "transfer_target_channel_name", xfer->target ? xfer->target->base->name : "N/A",
1414 "transfer_target_channel_uniqueid", xfer->target ? xfer->target->base->uniqueid : "N/A");
1415 if (!extra) {
1416 return;
1417 }
1418 break;
1419 }
1421 NULL, extra, NULL);
1422 ast_json_unref(extra);
1423}
static int cel_report_event(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)
Definition cel.c:593
@ AST_CEL_ATTENDEDTRANSFER
a transfer occurs
Definition cel.h:68
void * stasis_message_data(const struct stasis_message *msg)
Get the data contained in a message.
const struct timeval * stasis_message_timestamp(const struct stasis_message *msg)
Get the time when a message was created.
@ AST_ATTENDED_TRANSFER_DEST_FAIL
@ AST_ATTENDED_TRANSFER_DEST_BRIDGE_MERGE
@ AST_ATTENDED_TRANSFER_DEST_LOCAL_APP
@ AST_ATTENDED_TRANSFER_DEST_LINK
@ AST_ATTENDED_TRANSFER_DEST_APP
@ AST_ATTENDED_TRANSFER_DEST_THREEWAY
Message representing attended transfer.
enum ast_attended_transfer_dest_type dest_type
union ast_attended_transfer_message::@301 dest
struct ast_bridge_channel_snapshot_pair to_transfer_target
struct ast_channel_snapshot * transferee
struct ast_bridge_channel_snapshot_pair to_transferee
struct ast_bridge_snapshot * bridge_snapshot
struct ast_channel_snapshot * channel_snapshot
Structure that contains a snapshot of information about a bridge.
Definition bridge.h:318
const ast_string_field uniqueid
Definition bridge.h:332
Structure representing a snapshot of channel state.

References ast_attended_transfer_message::app, AST_ATTENDED_TRANSFER_DEST_APP, AST_ATTENDED_TRANSFER_DEST_BRIDGE_MERGE, AST_ATTENDED_TRANSFER_DEST_FAIL, AST_ATTENDED_TRANSFER_DEST_LINK, AST_ATTENDED_TRANSFER_DEST_LOCAL_APP, AST_ATTENDED_TRANSFER_DEST_THREEWAY, AST_CEL_ATTENDEDTRANSFER, ast_json_pack(), ast_json_unref(), ast_channel_snapshot::base, ast_bridge_channel_snapshot_pair::bridge_snapshot, cel_report_event(), ast_bridge_channel_snapshot_pair::channel_snapshot, ast_attended_transfer_message::dest, ast_attended_transfer_message::dest_type, ast_channel_snapshot_base::name, NULL, stasis_message_data(), stasis_message_timestamp(), ast_attended_transfer_message::target, ast_attended_transfer_message::to_transfer_target, ast_attended_transfer_message::to_transferee, ast_attended_transfer_message::transferee, ast_bridge_snapshot::uniqueid, and ast_channel_snapshot_base::uniqueid.

Referenced by create_routes().

◆ cel_backend_send_cb()

static int cel_backend_send_cb ( void *  obj,
void *  arg,
int  flags 
)
static

Definition at line 585 of file cel.c.

586{
587 struct cel_backend *backend = obj;
588
589 backend->callback(arg);
590 return 0;
591}

References cel_backend::callback.

Referenced by cel_report_event().

◆ cel_blind_transfer_cb()

static void cel_blind_transfer_cb ( void *  data,
struct stasis_subscription sub,
struct stasis_message message 
)
static

Definition at line 1336 of file cel.c.

1339{
1341 struct ast_channel_snapshot *chan_snapshot = transfer_msg->transferer;
1342 struct ast_bridge_snapshot *bridge_snapshot = transfer_msg->bridge;
1343 struct ast_json *extra;
1344
1345 if (transfer_msg->result != AST_BRIDGE_TRANSFER_SUCCESS) {
1346 return;
1347 }
1348
1349 extra = ast_json_pack("{s: s, s: s, s: s, s: s, s: s}",
1350 "extension", transfer_msg->exten,
1351 "context", transfer_msg->context,
1352 "bridge_id", bridge_snapshot->uniqueid,
1353 "transferee_channel_name", transfer_msg->transferee ? transfer_msg->transferee->base->name : "N/A",
1354 "transferee_channel_uniqueid", transfer_msg->transferee ? transfer_msg->transferee->base->uniqueid : "N/A");
1355 if (extra) {
1357 NULL, extra, NULL);
1358 ast_json_unref(extra);
1359 }
1360}
@ AST_BRIDGE_TRANSFER_SUCCESS
Definition bridge.h:1104
@ AST_CEL_BLINDTRANSFER
a transfer occurs
Definition cel.h:66
Message published during a blind transfer.
char exten[AST_MAX_EXTENSION]
struct ast_bridge_snapshot * bridge
struct ast_channel_snapshot * transferer
struct ast_channel_snapshot * transferee
enum ast_transfer_result result
char context[AST_MAX_CONTEXT]

References AST_BRIDGE_TRANSFER_SUCCESS, AST_CEL_BLINDTRANSFER, ast_json_pack(), ast_json_unref(), ast_channel_snapshot::base, ast_blind_transfer_message::bridge, cel_report_event(), ast_blind_transfer_message::context, ast_blind_transfer_message::exten, ast_channel_snapshot_base::name, NULL, ast_blind_transfer_message::result, stasis_message_data(), stasis_message_timestamp(), ast_blind_transfer_message::transferee, ast_blind_transfer_message::transferer, ast_bridge_snapshot::uniqueid, and ast_channel_snapshot_base::uniqueid.

Referenced by create_routes().

◆ cel_bridge_enter_cb()

static void cel_bridge_enter_cb ( void *  data,
struct stasis_subscription sub,
struct stasis_message message 
)
static

Definition at line 1095 of file cel.c.

1098{
1100 struct ast_bridge_snapshot *snapshot = blob->bridge;
1101 struct ast_channel_snapshot *chan_snapshot = blob->channel;
1102 RAII_VAR(struct ast_json *, extra, NULL, ast_json_unref);
1103 RAII_VAR(struct ast_str *, peer_str, NULL, ast_free);
1104
1105 if (cel_filter_channel_snapshot(chan_snapshot)) {
1106 return;
1107 }
1108
1109 extra = ast_json_pack("{s: s, s: s}",
1110 "bridge_id", snapshot->uniqueid,
1111 "bridge_technology", snapshot->technology);
1112 if (!extra) {
1113 return;
1114 }
1115
1116 peer_str = cel_generate_peer_str(snapshot, chan_snapshot);
1117 if (!peer_str) {
1118 return;
1119 }
1120
1122 NULL, extra, ast_str_buffer(peer_str));
1123}
#define ast_free(a)
Definition astmm.h:180
static int cel_filter_channel_snapshot(struct ast_channel_snapshot *snapshot)
Definition cel.c:1034
static struct ast_str * cel_generate_peer_str(struct ast_bridge_snapshot *bridge, struct ast_channel_snapshot *chan)
Definition cel.c:1057
@ AST_CEL_BRIDGE_ENTER
channel enters a bridge
Definition cel.h:58
char *attribute_pure ast_str_buffer(const struct ast_str *buf)
Returns the string buffer within the ast_str buf.
Definition strings.h:761
Blob of data associated with a bridge.
struct ast_bridge_snapshot * bridge
struct ast_channel_snapshot * channel
struct ast_json * blob
const ast_string_field technology
Definition bridge.h:332
Support for dynamic strings.
Definition strings.h:623

References AST_CEL_BRIDGE_ENTER, ast_free, ast_json_pack(), ast_json_unref(), ast_str_buffer(), ast_bridge_blob::blob, ast_bridge_blob::bridge, cel_filter_channel_snapshot(), cel_generate_peer_str(), cel_report_event(), ast_bridge_blob::channel, NULL, RAII_VAR, stasis_message_data(), stasis_message_timestamp(), ast_bridge_snapshot::technology, and ast_bridge_snapshot::uniqueid.

Referenced by create_routes().

◆ cel_bridge_leave_cb()

static void cel_bridge_leave_cb ( void *  data,
struct stasis_subscription sub,
struct stasis_message message 
)
static

Definition at line 1125 of file cel.c.

1128{
1130 struct ast_bridge_snapshot *snapshot = blob->bridge;
1131 struct ast_channel_snapshot *chan_snapshot = blob->channel;
1132 RAII_VAR(struct ast_json *, extra, NULL, ast_json_unref);
1133 RAII_VAR(struct ast_str *, peer_str, NULL, ast_free);
1134
1135 if (cel_filter_channel_snapshot(chan_snapshot)) {
1136 return;
1137 }
1138
1139 extra = ast_json_pack("{s: s, s: s}",
1140 "bridge_id", snapshot->uniqueid,
1141 "bridge_technology", snapshot->technology);
1142 if (!extra) {
1143 return;
1144 }
1145
1146 peer_str = cel_generate_peer_str(snapshot, chan_snapshot);
1147 if (!peer_str) {
1148 return;
1149 }
1150
1152 NULL, extra, ast_str_buffer(peer_str));
1153}
@ AST_CEL_BRIDGE_EXIT
channel exits a bridge
Definition cel.h:60

References AST_CEL_BRIDGE_EXIT, ast_free, ast_json_pack(), ast_json_unref(), ast_str_buffer(), ast_bridge_blob::blob, ast_bridge_blob::bridge, cel_filter_channel_snapshot(), cel_generate_peer_str(), cel_report_event(), ast_bridge_blob::channel, NULL, RAII_VAR, stasis_message_data(), stasis_message_timestamp(), ast_bridge_snapshot::technology, and ast_bridge_snapshot::uniqueid.

Referenced by create_routes().

◆ cel_channel_app_change()

static void cel_channel_app_change ( struct ast_channel_snapshot old_snapshot,
struct ast_channel_snapshot new_snapshot,
const struct timeval *  event_time 
)
static

Definition at line 1003 of file cel.c.

1007{
1008 if (old_snapshot && !strcmp(old_snapshot->dialplan->appl, new_snapshot->dialplan->appl)) {
1009 return;
1010 }
1011
1012 /* old snapshot has an application, end it */
1013 if (old_snapshot && !ast_strlen_zero(old_snapshot->dialplan->appl)) {
1014 cel_report_event(old_snapshot, AST_CEL_APP_END, event_time, NULL, NULL, NULL);
1015 }
1016
1017 /* new snapshot has an application, start it */
1018 if (!ast_strlen_zero(new_snapshot->dialplan->appl)) {
1019 cel_report_event(new_snapshot, AST_CEL_APP_START, event_time, NULL, NULL, NULL);
1020 }
1021}
@ AST_CEL_APP_END
an app ends
Definition cel.h:56
@ AST_CEL_APP_START
an app starts
Definition cel.h:54

References ast_channel_snapshot_dialplan::appl, AST_CEL_APP_END, AST_CEL_APP_START, ast_strlen_zero(), cel_report_event(), ast_channel_snapshot::dialplan, and NULL.

◆ cel_channel_linkedid_change()

static void cel_channel_linkedid_change ( struct ast_channel_snapshot old_snapshot,
struct ast_channel_snapshot new_snapshot,
const struct timeval *  event_time 
)
static

Definition at line 984 of file cel.c.

988{
989 if (!old_snapshot) {
990 return;
991 }
992
993 ast_assert(!ast_strlen_zero(new_snapshot->peer->linkedid));
994 ast_assert(!ast_strlen_zero(old_snapshot->peer->linkedid));
995
997 && strcmp(old_snapshot->peer->linkedid, new_snapshot->peer->linkedid)) {
998 cel_linkedid_ref(new_snapshot->peer->linkedid);
999 check_retire_linkedid(old_snapshot, event_time);
1000 }
1001}
static int cel_linkedid_ref(const char *linkedid)
Definition cel.c:832
static int ast_cel_track_event(enum ast_cel_event_type et)
Definition cel.c:455
static void check_retire_linkedid(struct ast_channel_snapshot *snapshot, const struct timeval *event_time)
Definition cel.c:638
@ AST_CEL_LINKEDID_END
the last channel with the given linkedid is retired
Definition cel.h:72
#define ast_assert(a)
Definition utils.h:779

References ast_assert, AST_CEL_LINKEDID_END, ast_cel_track_event(), ast_strlen_zero(), cel_linkedid_ref(), check_retire_linkedid(), ast_channel_snapshot_peer::linkedid, and ast_channel_snapshot::peer.

◆ cel_channel_state_change()

static void cel_channel_state_change ( struct ast_channel_snapshot old_snapshot,
struct ast_channel_snapshot new_snapshot,
const struct timeval *  event_time 
)
static

Handle channel state changes.

Definition at line 944 of file cel.c.

948{
949 int is_hungup, was_hungup;
950
951 if (!old_snapshot) {
952 cel_report_event(new_snapshot, AST_CEL_CHANNEL_START, event_time, NULL, NULL, NULL);
953 return;
954 }
955
956 was_hungup = ast_test_flag(&old_snapshot->flags, AST_FLAG_DEAD) ? 1 : 0;
957 is_hungup = ast_test_flag(&new_snapshot->flags, AST_FLAG_DEAD) ? 1 : 0;
958
959 if (!was_hungup && is_hungup) {
960 struct ast_json *extra;
961 struct cel_dialstatus *dialstatus = get_dialstatus(new_snapshot->base->uniqueid);
962
963 extra = ast_json_pack("{s: i, s: s, s: s}",
964 "hangupcause", new_snapshot->hangup->cause,
965 "hangupsource", new_snapshot->hangup->source,
966 "dialstatus", dialstatus ? dialstatus->dialstatus : "");
967 cel_report_event(new_snapshot, AST_CEL_HANGUP, event_time, NULL, extra, NULL);
968 ast_json_unref(extra);
970
971 cel_report_event(new_snapshot, AST_CEL_CHANNEL_END, event_time, NULL, NULL, NULL);
973 check_retire_linkedid(new_snapshot, event_time);
974 }
975 return;
976 }
977
978 if (old_snapshot->state != new_snapshot->state && new_snapshot->state == AST_STATE_UP) {
979 cel_report_event(new_snapshot, AST_CEL_ANSWER, event_time, NULL, NULL, NULL);
980 return;
981 }
982}
static struct cel_dialstatus * get_dialstatus(const char *uniqueid)
Definition cel.c:916
@ AST_CEL_CHANNEL_END
channel end
Definition cel.h:48
@ AST_CEL_ANSWER
A ringing phone is answered.
Definition cel.h:52
@ AST_CEL_HANGUP
hangup terminates connection
Definition cel.h:50
@ AST_CEL_CHANNEL_START
channel birth
Definition cel.h:46
@ AST_FLAG_DEAD
Definition channel.h:1065
@ AST_STATE_UP
enum ast_channel_state state
struct ast_flags flags
struct ast_channel_snapshot_hangup * hangup
char dialstatus[0]
Definition cel.c:195
#define ast_test_flag(p, flag)
Definition utils.h:64

References ao2_cleanup, AST_CEL_ANSWER, AST_CEL_CHANNEL_END, AST_CEL_CHANNEL_START, AST_CEL_HANGUP, AST_CEL_LINKEDID_END, ast_cel_track_event(), AST_FLAG_DEAD, ast_json_pack(), ast_json_unref(), AST_STATE_UP, ast_test_flag, ast_channel_snapshot::base, ast_channel_snapshot_hangup::cause, cel_report_event(), check_retire_linkedid(), cel_dialstatus::dialstatus, ast_channel_snapshot::flags, get_dialstatus(), ast_channel_snapshot::hangup, NULL, ast_channel_snapshot_hangup::source, ast_channel_snapshot::state, and ast_channel_snapshot_base::uniqueid.

◆ cel_config_alloc()

static void * cel_config_alloc ( void  )
static

Definition at line 243 of file cel.c.

244{
245 RAII_VAR(struct cel_config *, cfg, NULL, ao2_cleanup);
246
247 if (!(cfg = ao2_alloc(sizeof(*cfg), cel_config_dtor))) {
248 return NULL;
249 }
250
251 if (!(cfg->general = ast_cel_general_config_alloc())) {
252 return NULL;
253 }
254
255 ao2_ref(cfg, +1);
256 return cfg;
257}
void * ast_cel_general_config_alloc(void)
Allocate a CEL configuration object.
Definition cel.c:207
static void cel_config_dtor(void *obj)
Destructor for cel_config.
Definition cel.c:236

References ao2_alloc, ao2_cleanup, ao2_ref, ast_cel_general_config_alloc(), cel_config_dtor(), NULL, and RAII_VAR.

Referenced by load_module().

◆ cel_config_dtor()

static void cel_config_dtor ( void *  obj)
static

Destructor for cel_config.

Definition at line 236 of file cel.c.

237{
238 struct cel_config *cfg = obj;
239 ao2_cleanup(cfg->general);
240 cfg->general = NULL;
241}

References ao2_cleanup, cel_config::general, and NULL.

Referenced by cel_config_alloc().

◆ cel_dial_cb()

static void cel_dial_cb ( void *  data,
struct stasis_subscription sub,
struct stasis_message message 
)
static

Definition at line 1277 of file cel.c.

1279{
1281 struct ast_channel_snapshot *snapshot;
1282
1283 snapshot = ast_multi_channel_blob_get_channel(blob, "caller");
1284 if (!snapshot || cel_filter_channel_snapshot(snapshot)) {
1285 return;
1286 }
1287
1288 if (!ast_strlen_zero(get_blob_variable(blob, "forward"))) {
1289 struct ast_json *extra;
1290
1291 extra = ast_json_pack("{s: s}", "forward", get_blob_variable(blob, "forward"));
1292 if (extra) {
1294 NULL, extra, NULL);
1295 ast_json_unref(extra);
1296 }
1297 }
1298
1299 if (is_valid_dialstatus(blob)) {
1300 save_dialstatus(blob, snapshot);
1301 }
1302}
static int is_valid_dialstatus(struct ast_multi_channel_blob *blob)
Definition cel.c:1248
static void save_dialstatus(struct ast_multi_channel_blob *blob, struct ast_channel_snapshot *snapshot)
Definition cel.c:1204
static const char * get_blob_variable(struct ast_multi_channel_blob *blob, const char *varname)
Definition cel.c:928
@ AST_CEL_FORWARD
this call was forwarded somewhere else
Definition cel.h:76
struct ast_channel_snapshot * ast_multi_channel_blob_get_channel(struct ast_multi_channel_blob *obj, const char *role)
Retrieve a channel snapshot associated with a specific role from a ast_multi_channel_blob.
A multi channel blob data structure for multi_channel_blob stasis messages.
struct ast_json * blob

References AST_CEL_FORWARD, ast_json_pack(), ast_json_unref(), ast_multi_channel_blob_get_channel(), ast_strlen_zero(), ast_multi_channel_blob::blob, cel_filter_channel_snapshot(), cel_report_event(), get_blob_variable(), is_valid_dialstatus(), NULL, save_dialstatus(), stasis_message_data(), and stasis_message_timestamp().

Referenced by create_routes().

◆ cel_filter_channel_snapshot()

static int cel_filter_channel_snapshot ( struct ast_channel_snapshot snapshot)
static

Definition at line 1034 of file cel.c.

1035{
1036 if (!snapshot) {
1037 return 0;
1038 }
1039 return snapshot->base->tech_properties & AST_CHAN_TP_INTERNAL;
1040}
@ AST_CHAN_TP_INTERNAL
Channels with this particular technology are an implementation detail of Asterisk and should generall...
Definition channel.h:991

References AST_CHAN_TP_INTERNAL, ast_channel_snapshot::base, and ast_channel_snapshot_base::tech_properties.

Referenced by cel_bridge_enter_cb(), cel_bridge_leave_cb(), cel_dial_cb(), and cel_snapshot_update_cb().

◆ cel_format_eventtime()

static int cel_format_eventtime ( struct cel_config cfg,
struct timeval  eventtime,
char *  timebuf,
size_t  len 
)
static

Definition at line 676 of file cel.c.

677{
678 if (!timebuf || len < 30) {
679 return -1;
680 }
681
683 snprintf(timebuf, len, "%ld.%06ld", (long) eventtime.tv_sec,
684 (long) eventtime.tv_usec);
685 } else {
686 struct ast_tm tm;
687 ast_localtime(&eventtime, &tm, NULL);
688 ast_strftime(timebuf, len, cfg->general->date_format, &tm);
689 }
690
691 return 0;
692}
struct ast_tm * ast_localtime(const struct timeval *timep, struct ast_tm *p_tm, const char *zone)
Timezone-independent version of localtime_r(3).
Definition localtime.c:1739
int ast_strftime(char *buf, size_t len, const char *format, const struct ast_tm *tm)
Special version of strftime(3) that handles fractions of a second. Takes the same arguments as strfti...
Definition localtime.c:2524
const ast_string_field date_format
Definition cel.h:246

References ast_localtime(), ast_strftime(), ast_strlen_zero(), ast_cel_general_config::date_format, cel_config::general, len(), and NULL.

Referenced by ast_cel_fabricate_channel_from_event(), and ast_cel_format_eventtime().

◆ cel_general_config_dtor()

static void cel_general_config_dtor ( void *  obj)
static

Destructor for cel_config.

Definition at line 199 of file cel.c.

200{
201 struct ast_cel_general_config *cfg = obj;
203 ao2_cleanup(cfg->apps);
204 cfg->apps = NULL;
205}
#define ast_string_field_free_memory(x)
free all memory - to be called before destroying the object

References ao2_cleanup, ast_cel_general_config::apps, ast_string_field_free_memory, and NULL.

Referenced by ast_cel_general_config_alloc().

◆ cel_generate_peer_str()

static struct ast_str * cel_generate_peer_str ( struct ast_bridge_snapshot bridge,
struct ast_channel_snapshot chan 
)
static

Definition at line 1057 of file cel.c.

1060{
1061 struct ast_str *peer_str = ast_str_create(32);
1062 struct ao2_iterator i;
1063 char *current_chan = NULL;
1064
1065 if (!peer_str) {
1066 return NULL;
1067 }
1068
1069 for (i = ao2_iterator_init(bridge->channels, 0);
1070 (current_chan = ao2_iterator_next(&i));
1071 ao2_cleanup(current_chan)) {
1072 struct ast_channel_snapshot *current_snapshot;
1073
1074 /* Don't add the channel for which this message is being generated */
1075 if (!strcmp(current_chan, chan->base->uniqueid)) {
1076 continue;
1077 }
1078
1079 current_snapshot = ast_channel_snapshot_get_latest(current_chan);
1080 if (!current_snapshot) {
1081 continue;
1082 }
1083
1084 ast_str_append(&peer_str, 0, "%s,", current_snapshot->base->name);
1085 ao2_cleanup(current_snapshot);
1086 }
1088
1089 /* Rip off the trailing comma */
1090 ast_str_truncate(peer_str, -1);
1091
1092 return peer_str;
1093}
#define ao2_iterator_next(iter)
Definition astobj2.h:1911
struct ao2_iterator ao2_iterator_init(struct ao2_container *c, int flags) attribute_warn_unused_result
Create an iterator for a container.
void ao2_iterator_destroy(struct ao2_iterator *iter)
Destroy a container iterator.
struct ast_channel_snapshot * ast_channel_snapshot_get_latest(const char *uniqueid)
Obtain the latest ast_channel_snapshot from the Stasis Message Bus API cache. This is an ao2 object,...
char * ast_str_truncate(struct ast_str *buf, ssize_t len)
Truncates the enclosed string to the given length.
Definition strings.h:786
int ast_str_append(struct ast_str **buf, ssize_t max_len, const char *fmt,...)
Append to a thread local dynamic string.
Definition strings.h:1139
#define ast_str_create(init_len)
Create a malloc'ed dynamic length string.
Definition strings.h:659
When we need to walk through a container, we use an ao2_iterator to keep track of the current positio...
Definition astobj2.h:1821
struct ao2_container * channels
Definition bridge.h:335

References ao2_cleanup, ao2_iterator_destroy(), ao2_iterator_init(), ao2_iterator_next, ast_channel_snapshot_get_latest(), ast_str_append(), ast_str_create, ast_str_truncate(), ast_channel_snapshot::base, ast_bridge_snapshot::channels, ast_channel_snapshot_base::name, NULL, and ast_channel_snapshot_base::uniqueid.

Referenced by cel_bridge_enter_cb(), and cel_bridge_leave_cb().

◆ cel_generic_cb()

static void cel_generic_cb ( void *  data,
struct stasis_subscription sub,
struct stasis_message message 
)
static

Definition at line 1304 of file cel.c.

1307{
1309 int event_type = ast_json_integer_get(ast_json_object_get(obj->blob, "event_type"));
1310 struct ast_json *event_details = ast_json_object_get(obj->blob, "event_details");
1311
1312 switch (event_type) {
1314 case AST_CEL_DTMF:
1316 {
1317 const char *event = ast_json_string_get(ast_json_object_get(event_details, "event"));
1318 struct ast_json *extra = ast_json_object_get(event_details, "extra");
1320 event, extra, NULL);
1321 break;
1322 }
1323 case AST_CEL_STREAM_END:
1324 {
1325 const char *event = ast_json_string_get(ast_json_object_get(event_details, "event"));
1327 event, NULL, NULL);
1328 break;
1329 }
1330 default:
1331 ast_log(LOG_ERROR, "Unhandled %s event blob\n", ast_cel_get_type_name(event_type));
1332 break;
1333 }
1334}
@ AST_CEL_DTMF
A DTMF digit was processed.
Definition cel.h:86
@ AST_CEL_STREAM_BEGIN
A stream started.
Definition cel.h:82
@ AST_CEL_STREAM_END
A stream ended.
Definition cel.h:84
const char * ast_json_string_get(const struct ast_json *string)
Get the value of a JSON string.
Definition json.c:283
struct ast_json * ast_json_object_get(struct ast_json *object, const char *key)
Get a field from a JSON object.
Definition json.c:407
intmax_t ast_json_integer_get(const struct ast_json *integer)
Get the value from a JSON integer.
Definition json.c:332
Blob of data associated with a channel.
struct ast_channel_snapshot * snapshot
struct ast_json * blob

References AST_CEL_DTMF, ast_cel_get_type_name(), AST_CEL_STREAM_BEGIN, AST_CEL_STREAM_END, AST_CEL_USER_DEFINED, ast_json_integer_get(), ast_json_object_get(), ast_json_string_get(), ast_log, ast_channel_blob::blob, cel_report_event(), LOG_ERROR, NULL, ast_channel_blob::snapshot, stasis_message_data(), and stasis_message_timestamp().

Referenced by create_routes().

◆ cel_generic_type()

struct stasis_message_type * cel_generic_type ( void  )

◆ cel_linkedid_ref()

static int cel_linkedid_ref ( const char *  linkedid)
static

Definition at line 832 of file cel.c.

833{
834 RAII_VAR(struct ao2_container *, linkedids, ao2_global_obj_ref(cel_linkedids), ao2_cleanup);
835 struct cel_linkedid *lid;
836
837 if (ast_strlen_zero(linkedid)) {
838 ast_log(LOG_ERROR, "The linkedid should never be empty\n");
839 return -1;
840 }
841 if (!linkedids) {
842 /* The CEL module is shutdown. Abort. */
843 return -1;
844 }
845
846 ao2_lock(linkedids);
847 lid = ao2_find(linkedids, (void *) linkedid, OBJ_SEARCH_KEY);
848 if (!lid) {
849 /*
850 * Changes to the lid->count member are protected by the
851 * container lock so the lid object does not need its own lock.
852 */
853 lid = ao2_alloc_options(sizeof(*lid) + strlen(linkedid) + 1, NULL,
855 if (!lid) {
856 ao2_unlock(linkedids);
857 return -1;
858 }
859 strcpy(lid->id, linkedid);/* Safe */
860
861 ao2_link(linkedids, lid);
862 }
863 ++lid->count;
864 ao2_unlock(linkedids);
865 ao2_ref(lid, -1);
866
867 return 0;
868}
#define ao2_unlock(a)
Definition astobj2.h:729
#define ao2_lock(a)
Definition astobj2.h:717
unsigned int count
Definition cel.c:183
char id[0]
Definition cel.c:185

References AO2_ALLOC_OPT_LOCK_NOLOCK, ao2_alloc_options, ao2_cleanup, ao2_find, ao2_global_obj_ref, ao2_link, ao2_lock, ao2_ref, ao2_unlock, ast_log, ast_strlen_zero(), cel_linkedid::count, cel_linkedid::id, LOG_ERROR, NULL, OBJ_SEARCH_KEY, and RAII_VAR.

Referenced by cel_channel_linkedid_change(), and cel_report_event().

◆ cel_local_optimization_begin_cb()

static void cel_local_optimization_begin_cb ( void *  data,
struct stasis_subscription sub,
struct stasis_message message 
)
static

Definition at line 1485 of file cel.c.

1488{
1490}
static void cel_local_optimization_cb_helper(void *data, struct stasis_subscription *sub, struct stasis_message *message, enum ast_cel_event_type event_type)
Definition cel.c:1450
@ AST_CEL_LOCAL_OPTIMIZE_BEGIN
A local channel optimization has begun.
Definition cel.h:80
static struct stasis_subscription * sub
Statsd channel stats. Exmaple of how to subscribe to Stasis events.

References AST_CEL_LOCAL_OPTIMIZE_BEGIN, cel_local_optimization_cb_helper(), and sub.

Referenced by create_routes().

◆ cel_local_optimization_cb_helper()

static void cel_local_optimization_cb_helper ( void *  data,
struct stasis_subscription sub,
struct stasis_message message,
enum ast_cel_event_type  event_type 
)
static

Definition at line 1450 of file cel.c.

1454{
1456 struct ast_channel_snapshot *localone = ast_multi_channel_blob_get_channel(obj, "1");
1457 struct ast_channel_snapshot *localtwo = ast_multi_channel_blob_get_channel(obj, "2");
1458 struct ast_json *extra;
1459
1460 if (!localone || !localtwo) {
1461 return;
1462 }
1463
1464 extra = ast_json_pack("{s: s, s: s}",
1465 "local_two", localtwo->base->name,
1466 "local_two_uniqueid", localtwo->base->uniqueid);
1467 if (!extra) {
1468 return;
1469 }
1470
1471 cel_report_event(localone, event_type, stasis_message_timestamp(message), NULL, extra, NULL);
1472 ast_json_unref(extra);
1473}

References ast_json_pack(), ast_json_unref(), ast_multi_channel_blob_get_channel(), ast_channel_snapshot::base, cel_report_event(), ast_channel_snapshot_base::name, NULL, stasis_message_data(), stasis_message_timestamp(), and ast_channel_snapshot_base::uniqueid.

Referenced by cel_local_optimization_begin_cb(), and cel_local_optimization_end_cb().

◆ cel_local_optimization_end_cb()

static void cel_local_optimization_end_cb ( void *  data,
struct stasis_subscription sub,
struct stasis_message message 
)
static

Definition at line 1475 of file cel.c.

1478{
1479 /* The AST_CEL_LOCAL_OPTIMIZE event has always been triggered by the end of optimization.
1480 This can either be used as an indication that the call was locally optimized, or as
1481 the END event in combination with the subsequently added BEGIN event. */
1483}
@ AST_CEL_LOCAL_OPTIMIZE
A local channel optimization occurred, this marks the end.
Definition cel.h:78

References AST_CEL_LOCAL_OPTIMIZE, cel_local_optimization_cb_helper(), and sub.

Referenced by create_routes().

◆ cel_parking_cb()

static void cel_parking_cb ( void *  data,
struct stasis_subscription sub,
struct stasis_message message 
)
static

Definition at line 1155 of file cel.c.

1158{
1159 struct ast_parked_call_payload *parked_payload = stasis_message_data(message);
1160 RAII_VAR(struct ast_json *, extra, NULL, ast_json_unref);
1161 const char *reason = NULL;
1162
1163 switch (parked_payload->event_type) {
1164 case PARKED_CALL:
1165 extra = ast_json_pack("{s: s, s: s}",
1166 "parker_dial_string", parked_payload->parker_dial_string,
1167 "parking_lot", parked_payload->parkinglot);
1168 if (extra) {
1170 NULL, extra, NULL);
1171 }
1172 return;
1174 reason = "ParkedCallTimeOut";
1175 break;
1176 case PARKED_CALL_GIVEUP:
1177 reason = "ParkedCallGiveUp";
1178 break;
1180 reason = "ParkedCallUnparked";
1181 break;
1182 case PARKED_CALL_FAILED:
1183 reason = "ParkedCallFailed";
1184 break;
1185 case PARKED_CALL_SWAP:
1186 reason = "ParkedCallSwap";
1187 break;
1188 }
1189
1190 if (parked_payload->retriever) {
1191 extra = ast_json_pack("{s: s, s: s}",
1192 "reason", reason ?: "",
1193 "retriever", parked_payload->retriever->base->name);
1194 } else {
1195 extra = ast_json_pack("{s: s}", "reason", reason ?: "");
1196 }
1197
1198 if (extra) {
1200 NULL, extra, NULL);
1201 }
1202}
@ AST_CEL_PARK_START
a channel is parked
Definition cel.h:62
@ AST_CEL_PARK_END
channel out of the park
Definition cel.h:64
@ PARKED_CALL
Definition parking.h:47
@ PARKED_CALL_TIMEOUT
Definition parking.h:48
@ PARKED_CALL_UNPARKED
Definition parking.h:50
@ PARKED_CALL_FAILED
Definition parking.h:51
@ PARKED_CALL_GIVEUP
Definition parking.h:49
@ PARKED_CALL_SWAP
Definition parking.h:52
A parked call message payload.
Definition parking.h:59
const ast_string_field parkinglot
Definition parking.h:69
struct ast_channel_snapshot * retriever
Definition parking.h:61
struct ast_channel_snapshot * parkee
Definition parking.h:60
enum ast_parked_call_event_type event_type
Definition parking.h:62
const ast_string_field parker_dial_string
Definition parking.h:69

References AST_CEL_PARK_END, AST_CEL_PARK_START, ast_json_pack(), ast_json_unref(), ast_channel_snapshot::base, cel_report_event(), ast_parked_call_payload::event_type, ast_channel_snapshot_base::name, NULL, PARKED_CALL, PARKED_CALL_FAILED, PARKED_CALL_GIVEUP, PARKED_CALL_SWAP, PARKED_CALL_TIMEOUT, PARKED_CALL_UNPARKED, ast_parked_call_payload::parkee, ast_parked_call_payload::parker_dial_string, ast_parked_call_payload::parkinglot, RAII_VAR, ast_parked_call_payload::retriever, stasis_message_data(), and stasis_message_timestamp().

Referenced by create_routes().

◆ cel_pickup_cb()

static void cel_pickup_cb ( void *  data,
struct stasis_subscription sub,
struct stasis_message message 
)
static

Definition at line 1425 of file cel.c.

1428{
1430 struct ast_channel_snapshot *channel = ast_multi_channel_blob_get_channel(obj, "channel");
1431 struct ast_channel_snapshot *target = ast_multi_channel_blob_get_channel(obj, "target");
1432 struct ast_json *extra;
1433
1434 if (!channel || !target) {
1435 return;
1436 }
1437
1438 extra = ast_json_pack("{s: s, s: s}",
1439 "pickup_channel", channel->base->name,
1440 "pickup_channel_uniqueid", channel->base->uniqueid);
1441 if (!extra) {
1442 return;
1443 }
1444
1446 ast_json_unref(extra);
1447}
@ AST_CEL_PICKUP
a directed pickup was performed on this channel
Definition cel.h:74

References AST_CEL_PICKUP, ast_json_pack(), ast_json_unref(), ast_multi_channel_blob_get_channel(), ast_channel_snapshot::base, cel_report_event(), ast_channel_snapshot_base::name, NULL, stasis_message_data(), stasis_message_timestamp(), and ast_channel_snapshot_base::uniqueid.

Referenced by create_routes().

◆ cel_pre_apply_config()

static int cel_pre_apply_config ( void  )
static

Definition at line 295 of file cel.c.

296{
297 struct cel_config *cfg = aco_pending_config(&cel_cfg_info);
298
299 if (!cfg->general) {
300 return -1;
301 }
302
303 if (!ao2_container_count(cfg->general->apps)) {
304 return 0;
305 }
306
307 if (cfg->general->events & ((int64_t) 1 << AST_CEL_APP_START)) {
308 return 0;
309 }
310
311 if (cfg->general->events & ((int64_t) 1 << AST_CEL_APP_END)) {
312 return 0;
313 }
314
315 ast_log(LOG_ERROR, "Applications are listed to be tracked, but APP events are not tracked\n");
316 return -1;
317}
int ao2_container_count(struct ao2_container *c)
Returns the number of elements in a container.
void * aco_pending_config(struct aco_info *info)
Get pending config changes.

References aco_pending_config(), ao2_container_count(), ast_cel_general_config::apps, AST_CEL_APP_END, AST_CEL_APP_START, ast_log, ast_cel_general_config::events, cel_config::general, and LOG_ERROR.

◆ cel_report_event()

static int cel_report_event ( 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 
)
static

Definition at line 593 of file cel.c.

597{
598 struct ast_event *ev;
599 RAII_VAR(struct cel_config *, cfg, ao2_global_obj_ref(cel_configs), ao2_cleanup);
601
602 if (!cfg || !cfg->general || !cfg->general->enable || !backends) {
603 return 0;
604 }
605
606 /* Record the linkedid of new channels if we are tracking LINKEDID_END even if we aren't
607 * reporting on CHANNEL_START so we can track when to send LINKEDID_END */
608 if (event_type == AST_CEL_CHANNEL_START
610 if (cel_linkedid_ref(snapshot->peer->linkedid)) {
611 return -1;
612 }
613 }
614
615 if (!ast_cel_track_event(event_type)) {
616 return 0;
617 }
618
619 if ((event_type == AST_CEL_APP_START || event_type == AST_CEL_APP_END)
620 && !cel_track_app(snapshot->dialplan->appl)) {
621 return 0;
622 }
623
624 ev = ast_cel_create_event_with_time(snapshot, event_type, event_time, userdefevname, extra, peer_str);
625 if (!ev) {
626 return -1;
627 }
628
629 /* Distribute event to backends */
632
633 return 0;
634}
#define ao2_callback(c, flags, cb_fn, arg)
ao2_callback() is a generic function that applies cb_fn() to all objects in a container,...
Definition astobj2.h:1693
@ OBJ_MULTIPLE
Definition astobj2.h:1049
static int cel_track_app(const char *const_app)
Definition cel.c:519
static int cel_backend_send_cb(void *obj, void *arg, int flags)
Definition cel.c:585
void ast_event_destroy(struct ast_event *event)
Destroy an event.
Definition event.c:525
An event.
Definition event.c:81

References ao2_callback, ao2_cleanup, ao2_global_obj_ref, ast_channel_snapshot_dialplan::appl, AST_CEL_APP_END, AST_CEL_APP_START, AST_CEL_CHANNEL_START, ast_cel_create_event_with_time(), AST_CEL_LINKEDID_END, ast_cel_track_event(), ast_event_destroy(), cel_backend_send_cb(), cel_linkedid_ref(), cel_track_app(), ast_channel_snapshot::dialplan, ast_channel_snapshot_peer::linkedid, OBJ_MULTIPLE, OBJ_NODATA, ast_channel_snapshot::peer, and RAII_VAR.

Referenced by cel_attended_transfer_cb(), cel_blind_transfer_cb(), cel_bridge_enter_cb(), cel_bridge_leave_cb(), cel_channel_app_change(), cel_channel_state_change(), cel_dial_cb(), cel_generic_cb(), cel_local_optimization_cb_helper(), cel_parking_cb(), cel_pickup_cb(), and check_retire_linkedid().

◆ cel_snapshot_update_cb()

static void cel_snapshot_update_cb ( void *  data,
struct stasis_subscription sub,
struct stasis_message message 
)
static

Definition at line 1042 of file cel.c.

1044{
1046 size_t i;
1047
1048 if (cel_filter_channel_snapshot(update->old_snapshot) || cel_filter_channel_snapshot(update->new_snapshot)) {
1049 return;
1050 }
1051
1052 for (i = 0; i < ARRAY_LEN(cel_channel_monitors); ++i) {
1053 cel_channel_monitors[i](update->old_snapshot, update->new_snapshot, stasis_message_timestamp(message));
1054 }
1055}
cel_channel_snapshot_monitor cel_channel_monitors[]
Handlers for channel snapshot changes.
Definition cel.c:1028
static void update(int code_size, int y, int wi, int fi, int dq, int sr, int dqsez, struct g726_state *state_ptr)
Definition codec_g726.c:367
Structure representing a change of snapshot of channel state.

References ARRAY_LEN, cel_channel_monitors, cel_filter_channel_snapshot(), stasis_message_data(), stasis_message_timestamp(), and update().

Referenced by create_routes().

◆ cel_track_app()

static int cel_track_app ( const char *  const_app)
static

Definition at line 519 of file cel.c.

520{
521 RAII_VAR(struct cel_config *, cfg, ao2_global_obj_ref(cel_configs), ao2_cleanup);
522 RAII_VAR(char *, app, NULL, ao2_cleanup);
523 char *app_lower;
524
525 if (!cfg || !cfg->general) {
526 return 0;
527 }
528
529 app_lower = ast_str_to_lower(ast_strdupa(const_app));
530 app = ao2_find(cfg->general->apps, app_lower, OBJ_SEARCH_KEY);
531 if (!app) {
532 return 0;
533 }
534
535 return 1;
536}
static const char app[]

References ao2_cleanup, ao2_find, ao2_global_obj_ref, app, ast_str_to_lower(), ast_strdupa, NULL, OBJ_SEARCH_KEY, and RAII_VAR.

Referenced by cel_report_event().

◆ check_retire_linkedid()

static void check_retire_linkedid ( struct ast_channel_snapshot snapshot,
const struct timeval *  event_time 
)
static

Definition at line 638 of file cel.c.

639{
640 RAII_VAR(struct ao2_container *, linkedids, ao2_global_obj_ref(cel_linkedids), ao2_cleanup);
641 struct cel_linkedid *lid;
642
643 if (!linkedids || ast_strlen_zero(snapshot->peer->linkedid)) {
644 /* The CEL module is shutdown. Abort. */
645 return;
646 }
647
648 ao2_lock(linkedids);
649
650 lid = ao2_find(linkedids, (void *) snapshot->peer->linkedid, OBJ_SEARCH_KEY);
651 if (!lid) {
652 ao2_unlock(linkedids);
653
654 /*
655 * The user may have done a reload to start tracking linkedids
656 * when a call was already in progress. This is an unusual kind
657 * of change to make after starting Asterisk.
658 */
659 ast_log(LOG_ERROR, "Something weird happened, couldn't find linkedid %s\n",
660 snapshot->peer->linkedid);
661 return;
662 }
663
664 if (!--lid->count) {
665 /* No channels use this linkedid anymore. */
666 ao2_unlink(linkedids, lid);
667 ao2_unlock(linkedids);
668
669 cel_report_event(snapshot, AST_CEL_LINKEDID_END, event_time, NULL, NULL, NULL);
670 } else {
671 ao2_unlock(linkedids);
672 }
673 ao2_ref(lid, -1);
674}
#define ao2_unlink(container, obj)
Remove an object from a container.
Definition astobj2.h:1578

References ao2_cleanup, ao2_find, ao2_global_obj_ref, ao2_lock, ao2_ref, ao2_unlink, ao2_unlock, AST_CEL_LINKEDID_END, ast_log, ast_strlen_zero(), cel_report_event(), cel_linkedid::count, ast_channel_snapshot_peer::linkedid, LOG_ERROR, NULL, OBJ_SEARCH_KEY, ast_channel_snapshot::peer, and RAII_VAR.

Referenced by cel_channel_linkedid_change(), and cel_channel_state_change().

◆ CONFIG_INFO_CORE()

CONFIG_INFO_CORE ( "cel"  ,
cel_cfg_info  ,
cel_configs  ,
cel_config_alloc  ,
files = ACO_FILES(&cel_conf),
pre_apply_config = cel_pre_apply_config 
)

◆ create_routes()

static int create_routes ( void  )
static

Create the Stasis message router and routes for CEL.

Definition at line 1576 of file cel.c.

1577{
1578 int ret = 0;
1579
1581 if (!cel_state_router) {
1582 return -1;
1583 }
1586
1590 NULL);
1591
1595 NULL);
1596
1600 NULL);
1601
1605 NULL);
1606
1610 NULL);
1611
1615 NULL);
1616
1620 NULL);
1621
1625 NULL);
1626
1630 NULL);
1631
1635 NULL);
1636
1640 NULL);
1641
1642 if (ret) {
1643 ast_log(AST_LOG_ERROR, "Failed to register for Stasis messages\n");
1644 }
1645
1646 return ret;
1647}
static void cel_local_optimization_end_cb(void *data, struct stasis_subscription *sub, struct stasis_message *message)
Definition cel.c:1475
static void cel_bridge_leave_cb(void *data, struct stasis_subscription *sub, struct stasis_message *message)
Definition cel.c:1125
static void cel_dial_cb(void *data, struct stasis_subscription *sub, struct stasis_message *message)
Definition cel.c:1277
static void cel_snapshot_update_cb(void *data, struct stasis_subscription *sub, struct stasis_message *message)
Definition cel.c:1042
static void cel_pickup_cb(void *data, struct stasis_subscription *sub, struct stasis_message *message)
Definition cel.c:1425
static void cel_blind_transfer_cb(void *data, struct stasis_subscription *sub, struct stasis_message *message)
Definition cel.c:1336
static void cel_attended_transfer_cb(void *data, struct stasis_subscription *sub, struct stasis_message *message)
Definition cel.c:1362
static void cel_generic_cb(void *data, struct stasis_subscription *sub, struct stasis_message *message)
Definition cel.c:1304
static void cel_parking_cb(void *data, struct stasis_subscription *sub, struct stasis_message *message)
Definition cel.c:1155
static struct stasis_message_router * cel_state_router
Definition cel.c:133
static void cel_local_optimization_begin_cb(void *data, struct stasis_subscription *sub, struct stasis_message *message)
Definition cel.c:1485
static void cel_bridge_enter_cb(void *data, struct stasis_subscription *sub, struct stasis_message *message)
Definition cel.c:1095
static struct stasis_topic * cel_aggregation_topic
Definition cel.c:139
struct stasis_message_type * ast_local_optimization_end_type(void)
Message type for when a local channel optimization completes.
struct stasis_message_type * ast_local_optimization_begin_type(void)
Message type for when a local channel optimization begins.
struct stasis_message_type * ast_parked_call_type(void)
accessor for the parked call stasis message type
struct stasis_message_type * ast_channel_dial_type(void)
Message type for when a channel dials another channel.
struct stasis_message_type * ast_channel_snapshot_type(void)
Message type for ast_channel_snapshot_update.
#define AST_LOG_ERROR
struct stasis_message_type * ast_call_pickup_type(void)
accessor for call pickup message type
struct stasis_message_type * ast_channel_entered_bridge_type(void)
Message type for ast_channel enter bridge blob messages.
struct stasis_message_type * ast_blind_transfer_type(void)
Message type for ast_blind_transfer_message.
struct stasis_message_type * ast_attended_transfer_type(void)
Message type for ast_attended_transfer_message.
struct stasis_message_type * ast_channel_left_bridge_type(void)
Message type for ast_channel leave bridge blob messages.
int stasis_message_router_set_congestion_limits(struct stasis_message_router *router, long low_water, long high_water)
Set the high and low alert water marks of the stasis message router.
#define stasis_message_router_create(topic)
Create a new message router object.
int stasis_message_router_add(struct stasis_message_router *router, struct stasis_message_type *message_type, stasis_subscription_cb callback, void *data)
Add a route to a message router.
#define AST_TASKPROCESSOR_HIGH_WATER_LEVEL

References ast_attended_transfer_type(), ast_blind_transfer_type(), ast_call_pickup_type(), ast_channel_dial_type(), ast_channel_entered_bridge_type(), ast_channel_left_bridge_type(), ast_channel_snapshot_type(), ast_local_optimization_begin_type(), ast_local_optimization_end_type(), ast_log, AST_LOG_ERROR, ast_parked_call_type(), AST_TASKPROCESSOR_HIGH_WATER_LEVEL, cel_aggregation_topic, cel_attended_transfer_cb(), cel_blind_transfer_cb(), cel_bridge_enter_cb(), cel_bridge_leave_cb(), cel_dial_cb(), cel_generic_cb(), cel_generic_type(), cel_local_optimization_begin_cb(), cel_local_optimization_end_cb(), cel_parking_cb(), cel_pickup_cb(), cel_snapshot_update_cb(), cel_state_router, NULL, stasis_message_router_add(), stasis_message_router_create, and stasis_message_router_set_congestion_limits().

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

◆ create_subscriptions()

static int create_subscriptions ( void  )
static

Create the Stasis subscriptions for CEL.

Definition at line 1530 of file cel.c.

1531{
1532 cel_aggregation_topic = stasis_topic_create("cel:aggregator");
1533 if (!cel_aggregation_topic) {
1534 return -1;
1535 }
1536
1537 cel_topic = stasis_topic_create("cel:misc");
1538 if (!cel_topic) {
1539 return -1;
1540 }
1541
1545 if (!cel_channel_forwarder) {
1546 return -1;
1547 }
1548
1552 if (!cel_bridge_forwarder) {
1553 return -1;
1554 }
1555
1559 if (!cel_parking_forwarder) {
1560 return -1;
1561 }
1562
1564 ast_cel_topic(),
1566 if (!cel_cel_forwarder) {
1567 return -1;
1568 }
1569
1570 return 0;
1571}
static struct stasis_forward * cel_cel_forwarder
Definition cel.c:151
static struct stasis_forward * cel_channel_forwarder
Definition cel.c:142
static struct stasis_forward * cel_bridge_forwarder
Definition cel.c:145
static struct stasis_forward * cel_parking_forwarder
Definition cel.c:148
struct stasis_topic * ast_parking_topic(void)
accessor for the parking stasis topic
Definition parking.c:67
struct stasis_topic * ast_channel_topic_all(void)
A topic which publishes the events for all channels.
struct stasis_topic * stasis_topic_create(const char *name)
Create a new topic.
Definition stasis.c:684
struct stasis_forward * stasis_forward_all(struct stasis_topic *from_topic, struct stasis_topic *to_topic)
Create a subscription which forwards all messages from one topic to another.
Definition stasis.c:1645
struct stasis_topic * ast_bridge_topic_all(void)
A topic which publishes the events for all bridges.

References ast_bridge_topic_all(), ast_cel_topic(), ast_channel_topic_all(), ast_parking_topic(), cel_aggregation_topic, cel_bridge_forwarder, cel_cel_forwarder, cel_channel_forwarder, cel_parking_forwarder, cel_topic, stasis_forward_all(), and stasis_topic_create().

Referenced by load_module().

◆ destroy_routes()

static void destroy_routes ( void  )
static

Definition at line 1492 of file cel.c.

1493{
1496}
void stasis_message_router_unsubscribe_and_join(struct stasis_message_router *router)
Unsubscribe the router from the upstream topic, blocking until the final message has been processed.

References cel_state_router, NULL, and stasis_message_router_unsubscribe_and_join().

Referenced by ast_cel_set_config(), reload_module(), and unload_module().

◆ destroy_subscriptions()

static void destroy_subscriptions ( void  )
static

◆ events_handler()

static int events_handler ( const struct aco_option opt,
struct ast_variable var,
void *  obj 
)
static

Definition at line 466 of file cel.c.

467{
468 struct ast_cel_general_config *cfg = obj;
469 char *events = ast_strdupa(var->value);
470 char *cur_event;
471
472 while ((cur_event = strsep(&events, ","))) {
473 enum ast_cel_event_type event_type;
474
475 cur_event = ast_strip(cur_event);
476 if (ast_strlen_zero(cur_event)) {
477 continue;
478 }
479
480 event_type = ast_cel_str_to_event_type(cur_event);
481
482 if (event_type == AST_CEL_ALL) {
483 /* All events */
484 cfg->events = (int64_t) -1;
485 } else if (event_type == AST_CEL_INVALID_VALUE) {
486 return -1;
487 } else {
488 cfg->events |= ((int64_t) 1 << event_type);
489 }
490 }
491
492 return 0;
493}
static const struct adsi_event events[]
enum ast_cel_event_type ast_cel_str_to_event_type(const char *name)
Get the event type from a string.
Definition cel.c:441
ast_cel_event_type
CEL event types.
Definition cel.h:42
@ AST_CEL_ALL
Definition cel.h:44

References AST_CEL_ALL, AST_CEL_INVALID_VALUE, ast_cel_str_to_event_type(), ast_strdupa, ast_strip(), ast_strlen_zero(), events, ast_cel_general_config::events, strsep(), and var.

Referenced by load_module().

◆ get_blob_variable()

static const char * get_blob_variable ( struct ast_multi_channel_blob blob,
const char *  varname 
)
static

Definition at line 928 of file cel.c.

929{
930 struct ast_json *json = ast_multi_channel_blob_get_json(blob);
931 if (!json) {
932 return NULL;
933 }
934
935 json = ast_json_object_get(json, varname);
936 if (!json) {
937 return NULL;
938 }
939
940 return ast_json_string_get(json);
941}
struct ast_json * ast_multi_channel_blob_get_json(struct ast_multi_channel_blob *obj)
Retrieve the JSON blob from a ast_multi_channel_blob. Returned ast_json is still owned by obj.

References ast_json_object_get(), ast_json_string_get(), ast_multi_channel_blob_get_json(), and NULL.

Referenced by cel_dial_cb(), is_valid_dialstatus(), and save_dialstatus().

◆ get_dialstatus()

static struct cel_dialstatus * get_dialstatus ( const char *  uniqueid)
static

Definition at line 916 of file cel.c.

917{
918 struct ao2_container *dial_statuses = ao2_global_obj_ref(cel_dialstatus_store);
920
921 if (dial_statuses) {
923 ao2_ref(dial_statuses, -1);
924 }
925 return dialstatus;
926}
char uniqueid[AST_MAX_UNIQUEID]
Definition cel.c:193

References ao2_find, ao2_global_obj_ref, ao2_ref, cel_dialstatus::dialstatus, NULL, OBJ_SEARCH_KEY, OBJ_UNLINK, and cel_dialstatus::uniqueid.

Referenced by cel_channel_state_change().

◆ handle_cli_status()

static char * handle_cli_status ( struct ast_cli_entry e,
int  cmd,
struct ast_cli_args a 
)
static

Definition at line 376 of file cel.c.

377{
378 unsigned int i;
379 RAII_VAR(struct cel_config *, cfg, ao2_global_obj_ref(cel_configs), ao2_cleanup);
381 struct ao2_iterator iter;
382 char *app;
383
384 switch (cmd) {
385 case CLI_INIT:
386 e->command = "cel show status";
387 e->usage =
388 "Usage: cel show status\n"
389 " Displays the Channel Event Logging system status.\n";
390 return NULL;
391 case CLI_GENERATE:
392 return NULL;
393 case CLI_HANDLER:
394 break;
395 }
396
397 if (a->argc > 3) {
398 return CLI_SHOWUSAGE;
399 }
400
401 ast_cli(a->fd, "CEL Logging: %s\n", ast_cel_check_enabled() ? "Enabled" : "Disabled");
402
403 if (!cfg || !cfg->general || !cfg->general->enable) {
404 return CLI_SUCCESS;
405 }
406
407 for (i = 0; i < (sizeof(cfg->general->events) * 8); i++) {
408 const char *name;
409
410 if (!(cfg->general->events & ((int64_t) 1 << i))) {
411 continue;
412 }
413
415 if (strcasecmp(name, "Unknown")) {
416 ast_cli(a->fd, "CEL Tracking Event: %s\n", name);
417 }
418 }
419
420 iter = ao2_iterator_init(cfg->general->apps, 0);
421 for (; (app = ao2_iterator_next(&iter)); ao2_ref(app, -1)) {
422 ast_cli(a->fd, "CEL Tracking Application: %s\n", app);
423 }
425
426 if (backends) {
427 struct cel_backend *backend;
428
429 iter = ao2_iterator_init(backends, 0);
430 for (; (backend = ao2_iterator_next(&iter)); ao2_ref(backend, -1)) {
431 ast_cli(a->fd, "CEL Event Subscriber: %s\n", backend->name);
432 }
434 }
435
436 return CLI_SUCCESS;
437}
#define CLI_SHOWUSAGE
Definition cli.h:45
#define CLI_SUCCESS
Definition cli.h:44
void ast_cli(int fd, const char *fmt,...)
Definition clicompat.c:6
@ CLI_HANDLER
Definition cli.h:154
@ CLI_INIT
Definition cli.h:152
@ CLI_GENERATE
Definition cli.h:153
char * command
Definition cli.h:186
const char * usage
Definition cli.h:177
static struct test_val a

References a, ao2_cleanup, ao2_global_obj_ref, ao2_iterator_destroy(), ao2_iterator_init(), ao2_iterator_next, ao2_ref, app, ast_cel_check_enabled(), ast_cel_get_type_name(), ast_cli(), CLI_GENERATE, CLI_HANDLER, CLI_INIT, CLI_SHOWUSAGE, CLI_SUCCESS, ast_cli_entry::command, cel_backend::name, name, NULL, RAII_VAR, and ast_cli_entry::usage.

◆ is_valid_dialstatus()

static int is_valid_dialstatus ( struct ast_multi_channel_blob blob)
static

Definition at line 1248 of file cel.c.

1249{
1250 const char *dialstatus = get_blob_variable(blob, "dialstatus");
1251 int res = 0;
1252
1253 if (ast_strlen_zero(dialstatus)) {
1254 res = 0;
1255 } else if (!strcasecmp(dialstatus, "CHANUNAVAIL")) {
1256 res = 1;
1257 } else if (!strcasecmp(dialstatus, "CONGESTION")) {
1258 res = 1;
1259 } else if (!strcasecmp(dialstatus, "NOANSWER")) {
1260 res = 1;
1261 } else if (!strcasecmp(dialstatus, "BUSY")) {
1262 res = 1;
1263 } else if (!strcasecmp(dialstatus, "ANSWER")) {
1264 res = 1;
1265 } else if (!strcasecmp(dialstatus, "CANCEL")) {
1266 res = 1;
1267 } else if (!strcasecmp(dialstatus, "DONTCALL")) {
1268 res = 1;
1269 } else if (!strcasecmp(dialstatus, "TORTURE")) {
1270 res = 1;
1271 } else if (!strcasecmp(dialstatus, "INVALIDARGS")) {
1272 res = 1;
1273 }
1274 return res;
1275}

References ast_strlen_zero(), cel_dialstatus::dialstatus, and get_blob_variable().

Referenced by cel_dial_cb().

◆ load_module()

static int load_module ( void  )
static

Definition at line 1652 of file cel.c.

1653{
1654 struct ao2_container *container;
1655
1657 NUM_APP_BUCKETS, cel_linkedid_hash_fn, NULL, cel_linkedid_cmp_fn);
1660 if (!container) {
1662 }
1663
1665 NUM_DIALSTATUS_BUCKETS, cel_dialstatus_hash_fn, NULL, cel_dialstatus_cmp_fn);
1666 ao2_global_obj_replace_unref(cel_dialstatus_store, container);
1668 if (!container) {
1670 }
1671
1674 }
1675
1678 }
1679
1681 cel_backend_hash_fn, NULL, cel_backend_cmp_fn);
1684 if (!container) {
1686 }
1687
1688 if (aco_info_init(&cel_cfg_info)) {
1690 }
1691
1692 aco_option_register(&cel_cfg_info, "enable", ACO_EXACT, general_options, "no", OPT_BOOL_T, 1, FLDSET(struct ast_cel_general_config, enable));
1693 aco_option_register(&cel_cfg_info, "dateformat", ACO_EXACT, general_options, "", OPT_STRINGFIELD_T, 0, STRFLDSET(struct ast_cel_general_config, date_format));
1694 aco_option_register_custom(&cel_cfg_info, "apps", ACO_EXACT, general_options, "", apps_handler, 0);
1695 aco_option_register_custom(&cel_cfg_info, "events", ACO_EXACT, general_options, "", events_handler, 0);
1696
1697 if (aco_process_config(&cel_cfg_info, 0)) {
1698 struct cel_config *cel_cfg = cel_config_alloc();
1699
1700 if (!cel_cfg) {
1702 }
1703
1704 /* We couldn't process the configuration so create a default config. */
1705 if (!aco_set_defaults(&general_option, "general", cel_cfg->general)) {
1706 ast_log(LOG_NOTICE, "Failed to process CEL configuration; using defaults\n");
1707 ao2_global_obj_replace_unref(cel_configs, cel_cfg);
1708 }
1709 ao2_ref(cel_cfg, -1);
1710 }
1711
1712 if (create_subscriptions()) {
1714 }
1715
1718 }
1719
1721}
@ AO2_ALLOC_OPT_LOCK_MUTEX
Definition astobj2.h:363
#define ao2_global_obj_replace_unref(holder, obj)
Replace an ao2 object in the global holder, throwing away any old object.
Definition astobj2.h:901
#define ao2_container_alloc_hash(ao2_options, container_options, n_buckets, hash_fn, sort_fn, cmp_fn)
Allocate and initialize a hash container with the desired number of buckets.
Definition astobj2.h:1303
#define BACKEND_BUCKETS
Definition cel.c:160
static struct ast_cli_entry cli_status
Definition cel.c:439
static int create_subscriptions(void)
Create the Stasis subscriptions for CEL.
Definition cel.c:1530
static struct aco_type general_option
An aco_type structure to link the "general" category to the ast_cel_general_config type.
Definition cel.c:260
static int events_handler(const struct aco_option *opt, struct ast_variable *var, void *obj)
Definition cel.c:466
#define NUM_DIALSTATUS_BUCKETS
Number of buckets for the dialstatus container.
Definition cel.c:179
static struct aco_type * general_options[]
Definition cel.c:319
static int apps_handler(const struct aco_option *opt, struct ast_variable *var, void *obj)
Definition cel.c:495
static void * cel_config_alloc(void)
Definition cel.c:243
#define ast_cli_register(e)
Registers a command or an array of commands.
Definition cli.h:256
@ ACO_EXACT
int aco_set_defaults(struct aco_type *type, const char *category, void *obj)
Set all default options of obj.
#define STRFLDSET(type,...)
Convert a struct and a list of stringfield fields to an argument list of field offsets.
int aco_info_init(struct aco_info *info)
Initialize an aco_info structure.
#define FLDSET(type,...)
Convert a struct and list of fields to an argument list of field offsets.
#define aco_option_register(info, name, matchtype, types, default_val, opt_type, flags,...)
Register a config option.
@ OPT_BOOL_T
Type for default option handler for bools (ast_true/ast_false)
@ OPT_STRINGFIELD_T
Type for default option handler for stringfields.
#define aco_option_register_custom(info, name, matchtype, types, default_val, handler, flags)
Register a config option.
enum aco_process_status aco_process_config(struct aco_info *info, int reload)
Process a config info via the options registered with an aco_info.
#define LOG_NOTICE
@ AST_MODULE_LOAD_FAILURE
Module could not be loaded properly.
Definition module.h:102
@ AST_MODULE_LOAD_SUCCESS
Definition module.h:70
struct ao2_container * container
Definition res_fax.c:603
#define STASIS_MESSAGE_TYPE_INIT(name)
Boiler-plate messaging macro for initializing message types.
Definition stasis.h:1493

References ACO_EXACT, aco_info_init(), aco_option_register, aco_option_register_custom, aco_process_config(), aco_set_defaults(), AO2_ALLOC_OPT_LOCK_MUTEX, ao2_cleanup, ao2_container_alloc_hash, ao2_global_obj_replace_unref, ao2_ref, apps_handler(), ast_cel_check_enabled(), ast_cli_register, ast_log, AST_MODULE_LOAD_FAILURE, AST_MODULE_LOAD_SUCCESS, BACKEND_BUCKETS, cel_config_alloc(), cel_generic_type(), cli_status, container, create_routes(), create_subscriptions(), events_handler(), FLDSET, cel_config::general, general_option, general_options, LOG_NOTICE, NULL, NUM_APP_BUCKETS, NUM_DIALSTATUS_BUCKETS, OPT_BOOL_T, OPT_STRINGFIELD_T, STASIS_MESSAGE_TYPE_INIT, and STRFLDSET.

◆ reload_module()

static int reload_module ( void  )
static

Definition at line 1723 of file cel.c.

1724{
1725 unsigned int was_enabled = ast_cel_check_enabled();
1726 unsigned int is_enabled;
1727
1728 if (aco_process_config(&cel_cfg_info, 1) == ACO_PROCESS_ERROR) {
1729 return -1;
1730 }
1731
1733
1734 if (!was_enabled && is_enabled) {
1735 if (create_routes()) {
1736 return -1;
1737 }
1738 } else if (was_enabled && !is_enabled) {
1740 }
1741
1742 ast_verb(3, "CEL logging %sabled.\n", is_enabled ? "en" : "dis");
1743
1744 return 0;
1745}
@ ACO_PROCESS_ERROR
Their was an error and no changes were applied.
#define ast_verb(level,...)

References aco_process_config(), ACO_PROCESS_ERROR, ast_cel_check_enabled(), ast_verb, create_routes(), destroy_routes(), and is_enabled().

◆ save_dialstatus()

static void save_dialstatus ( struct ast_multi_channel_blob blob,
struct ast_channel_snapshot snapshot 
)
static

Definition at line 1204 of file cel.c.

1205{
1206 struct ao2_container *dial_statuses = ao2_global_obj_ref(cel_dialstatus_store);
1207 const char *dialstatus_string = get_blob_variable(blob, "dialstatus");
1208 struct cel_dialstatus *dialstatus;
1209 size_t dialstatus_string_len;
1210
1211 if (!dial_statuses || ast_strlen_zero(dialstatus_string)) {
1212 ao2_cleanup(dial_statuses);
1213 return;
1214 }
1215
1216 dialstatus = ao2_find(dial_statuses, snapshot->base->uniqueid, OBJ_SEARCH_KEY);
1217 if (dialstatus) {
1218 if (!strcasecmp(dialstatus_string, "ANSWER") && strcasecmp(dialstatus->dialstatus, "ANSWER")) {
1219 /* In the case of an answer after we already have a dial status we give
1220 * priority to the answer since the call was, well, answered. In the case of
1221 * failure dial status results we simply let the first failure be the status.
1222 */
1223 ao2_unlink(dial_statuses, dialstatus);
1224 ao2_ref(dialstatus, -1);
1225 } else {
1226 ao2_ref(dialstatus, -1);
1227 ao2_ref(dial_statuses, -1);
1228 return;
1229 }
1230 }
1231
1232 dialstatus_string_len = strlen(dialstatus_string) + 1;
1233 dialstatus = ao2_alloc_options(sizeof(*dialstatus) + dialstatus_string_len, NULL,
1235 if (!dialstatus) {
1236 ao2_ref(dial_statuses, -1);
1237 return;
1238 }
1239
1240 ast_copy_string(dialstatus->uniqueid, snapshot->base->uniqueid, sizeof(dialstatus->uniqueid));
1241 ast_copy_string(dialstatus->dialstatus, dialstatus_string, dialstatus_string_len);
1242
1243 ao2_link(dial_statuses, dialstatus);
1244 ao2_ref(dialstatus, -1);
1245 ao2_ref(dial_statuses, -1);
1246}
void ast_copy_string(char *dst, const char *src, size_t size)
Size-limited null-terminating string copy.
Definition strings.h:425

References AO2_ALLOC_OPT_LOCK_NOLOCK, ao2_alloc_options, ao2_cleanup, ao2_find, ao2_global_obj_ref, ao2_link, ao2_ref, ao2_unlink, ast_copy_string(), ast_strlen_zero(), ast_channel_snapshot::base, cel_dialstatus::dialstatus, get_blob_variable(), NULL, OBJ_SEARCH_KEY, and ast_channel_snapshot_base::uniqueid.

Referenced by cel_dial_cb().

◆ STASIS_MESSAGE_TYPE_DEFN()

STASIS_MESSAGE_TYPE_DEFN ( cel_generic_type  )

◆ unload_module()

static int unload_module ( void  )
static

Definition at line 1511 of file cel.c.

1512{
1516
1518 aco_info_destroy(&cel_cfg_info);
1519 ao2_global_obj_release(cel_configs);
1520 ao2_global_obj_release(cel_dialstatus_store);
1521 ao2_global_obj_release(cel_linkedids);
1522 ao2_global_obj_release(cel_backends);
1523
1524 return 0;
1525}
#define ao2_global_obj_release(holder)
Release the ao2 object held in the global holder.
Definition astobj2.h:859
static void destroy_subscriptions(void)
Definition cel.c:1498
int ast_cli_unregister(struct ast_cli_entry *e)
Unregisters a command or an array of commands.
Definition main/cli.c:2516
void aco_info_destroy(struct aco_info *info)
Destroy an initialized aco_info struct.
#define STASIS_MESSAGE_TYPE_CLEANUP(name)
Boiler-plate messaging macro for cleaning up message types.
Definition stasis.h:1515

References aco_info_destroy(), ao2_global_obj_release, ast_cli_unregister(), cel_generic_type(), cli_status, destroy_routes(), destroy_subscriptions(), and STASIS_MESSAGE_TYPE_CLEANUP.

Variable Documentation

◆ __mod_info

struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_GLOBAL_SYMBOLS | AST_MODFLAG_LOAD_ORDER , .description = "CEL Engine" , .key = ASTERISK_GPL_KEY , .buildopt_sum = AST_BUILDOPT_SUM, .support_level = AST_MODULE_SUPPORT_CORE, .load = load_module, .unload = unload_module, .reload = reload_module, .load_pri = AST_MODPRI_CORE, .requires = "extconfig", }
static

Definition at line 1866 of file cel.c.

◆ ast_module_info

const struct ast_module_info* ast_module_info = &__mod_info
static

Definition at line 1866 of file cel.c.

◆ cel_aggregation_topic

struct stasis_topic* cel_aggregation_topic
static

Aggregation topic for all topics CEL needs to know about

Definition at line 139 of file cel.c.

Referenced by create_routes(), create_subscriptions(), and destroy_subscriptions().

◆ cel_bridge_forwarder

struct stasis_forward* cel_bridge_forwarder
static

Subscription for forwarding the channel caching topic

Definition at line 145 of file cel.c.

Referenced by create_subscriptions(), and destroy_subscriptions().

◆ cel_cel_forwarder

struct stasis_forward* cel_cel_forwarder
static

Subscription for forwarding the CEL-specific topic

Definition at line 151 of file cel.c.

Referenced by create_subscriptions(), and destroy_subscriptions().

◆ cel_channel_forwarder

struct stasis_forward* cel_channel_forwarder
static

Subscription for forwarding the channel caching topic

Definition at line 142 of file cel.c.

Referenced by create_subscriptions(), and destroy_subscriptions().

◆ cel_channel_monitors

cel_channel_snapshot_monitor cel_channel_monitors[]
Initial value:
= {
}
static void cel_channel_linkedid_change(struct ast_channel_snapshot *old_snapshot, struct ast_channel_snapshot *new_snapshot, const struct timeval *event_time)
Definition cel.c:984
static void cel_channel_state_change(struct ast_channel_snapshot *old_snapshot, struct ast_channel_snapshot *new_snapshot, const struct timeval *event_time)
Handle channel state changes.
Definition cel.c:944
static void cel_channel_app_change(struct ast_channel_snapshot *old_snapshot, struct ast_channel_snapshot *new_snapshot, const struct timeval *event_time)
Definition cel.c:1003

Handlers for channel snapshot changes.

Note
Order of the handlers matters. Application changes must come before state changes to ensure that hangup notifications occur after application changes. Linkedid checking should always come last.

Definition at line 1028 of file cel.c.

Referenced by cel_snapshot_update_cb().

◆ cel_conf

struct aco_file cel_conf
static
Initial value:
= {
.filename = "cel.conf",
}
static struct aco_type ignore_option
Definition cel.c:275
#define ACO_TYPES(...)
A helper macro to ensure that aco_info types always have a sentinel.

The config file to be processed for the module.

Definition at line 283 of file cel.c.

283 {
284 .filename = "cel.conf", /*!< The name of the config file */
285 .types = ACO_TYPES(&general_option, &ignore_option), /*!< The mapping object types to be processed */
286};

◆ cel_event_types

const char* const cel_event_types[CEL_MAX_EVENT_IDS]
static

Map of ast_cel_event_type to strings.

Definition at line 324 of file cel.c.

324 {
325 [AST_CEL_ALL] = "ALL",
326 [AST_CEL_CHANNEL_START] = "CHAN_START",
327 [AST_CEL_CHANNEL_END] = "CHAN_END",
328 [AST_CEL_ANSWER] = "ANSWER",
329 [AST_CEL_HANGUP] = "HANGUP",
330 [AST_CEL_APP_START] = "APP_START",
331 [AST_CEL_APP_END] = "APP_END",
332 [AST_CEL_PARK_START] = "PARK_START",
333 [AST_CEL_PARK_END] = "PARK_END",
334 [AST_CEL_USER_DEFINED] = "USER_DEFINED",
335 [AST_CEL_BRIDGE_ENTER] = "BRIDGE_ENTER",
336 [AST_CEL_BRIDGE_EXIT] = "BRIDGE_EXIT",
337 [AST_CEL_BLINDTRANSFER] = "BLINDTRANSFER",
338 [AST_CEL_ATTENDEDTRANSFER] = "ATTENDEDTRANSFER",
339 [AST_CEL_PICKUP] = "PICKUP",
340 [AST_CEL_FORWARD] = "FORWARD",
341 [AST_CEL_LINKEDID_END] = "LINKEDID_END",
342 [AST_CEL_LOCAL_OPTIMIZE] = "LOCAL_OPTIMIZE",
343 [AST_CEL_LOCAL_OPTIMIZE_BEGIN] = "LOCAL_OPTIMIZE_BEGIN",
344 [AST_CEL_STREAM_BEGIN] = "STREAM_BEGIN",
345 [AST_CEL_STREAM_END] = "STREAM_END",
346 [AST_CEL_DTMF] = "DTMF",
347};

Referenced by ast_cel_get_type_name(), and ast_cel_str_to_event_type().

◆ cel_parking_forwarder

struct stasis_forward* cel_parking_forwarder
static

Subscription for forwarding the parking topic

Definition at line 148 of file cel.c.

Referenced by create_subscriptions(), and destroy_subscriptions().

◆ cel_state_router

struct stasis_message_router* cel_state_router
static

Message router for state that CEL needs to know about

Definition at line 133 of file cel.c.

Referenced by create_routes(), and destroy_routes().

◆ cel_topic

struct stasis_topic* cel_topic
static

Topic for CEL-specific messages

Definition at line 136 of file cel.c.

Referenced by ast_cel_topic(), create_subscriptions(), and destroy_subscriptions().

◆ cli_status

struct ast_cli_entry cli_status = { .handler = handle_cli_status , .summary = "Display the CEL status" ,}
static

Definition at line 439 of file cel.c.

Referenced by load_module(), and unload_module().

◆ fabricated_channel_datastore

const struct ast_datastore_info fabricated_channel_datastore
static
Initial value:
= {
.type = "CEL fabricated channel",
.destroy = ast_free_ptr,
}
void ast_free_ptr(void *ptr)
free() wrapper
Definition astmm.c:1739

Definition at line 712 of file cel.c.

712 {
713 .type = "CEL fabricated channel",
714 .destroy = ast_free_ptr,
715};

Referenced by ast_cel_fabricate_channel_from_event().

◆ general_option

struct aco_type general_option
static

An aco_type structure to link the "general" category to the ast_cel_general_config type.

Definition at line 260 of file cel.c.

260 {
261 .type = ACO_GLOBAL,
262 .name = "general",
263 .item_offset = offsetof(struct cel_config, general),
264 .category_match = ACO_WHITELIST_EXACT,
265 .category = "general",
266};
@ ACO_GLOBAL
@ ACO_WHITELIST_EXACT

Referenced by load_module().

◆ general_options

struct aco_type* general_options[] = ACO_TYPES(&general_option)
static

Definition at line 319 of file cel.c.

Referenced by load_module().

◆ ignore_categories

const char* ignore_categories[]
static
Initial value:
= {
"manager",
"radius",
}

Config sections used by existing modules. Do not add to this list.

Definition at line 269 of file cel.c.

269 {
270 "manager",
271 "radius",
272 NULL,
273};

◆ ignore_option

struct aco_type ignore_option
static

Definition at line 275 of file cel.c.

275 {
276 .type = ACO_IGNORE,
277 .name = "modules",
278 .category = (const char*)ignore_categories,
279 .category_match = ACO_WHITELIST_ARRAY,
280};
static const char * ignore_categories[]
Definition cel.c:269
@ ACO_IGNORE
@ ACO_WHITELIST_ARRAY