2009-06-26 15:28:53 +00:00
|
|
|
/*
|
|
|
|
* Asterisk -- An open source telephony toolkit.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2007 - 2009, Digium, Inc.
|
|
|
|
*
|
|
|
|
* See http://www.asterisk.org for more information about
|
|
|
|
* the Asterisk project. Please do not directly contact
|
|
|
|
* any of the maintainers of this project for assistance;
|
|
|
|
* the project provides a web site, mailing lists and IRC
|
|
|
|
* channels for your use.
|
|
|
|
*
|
|
|
|
* This program is free software, distributed under the terms of
|
|
|
|
* the GNU General Public License Version 2. See the LICENSE file
|
|
|
|
* at the top of the source tree.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* \file
|
|
|
|
*
|
|
|
|
* \brief Channel Event Logging API
|
|
|
|
*
|
|
|
|
* \author Steve Murphy <murf@digium.com>
|
|
|
|
* \author Russell Bryant <russell@digium.com>
|
|
|
|
*
|
|
|
|
* \todo Do thorough testing of all transfer methods to ensure that BLINDTRANSFER,
|
|
|
|
* ATTENDEDTRANSFER, BRIDGE_START, and BRIDGE_END events are all reported
|
|
|
|
* as expected.
|
|
|
|
*/
|
|
|
|
|
2012-10-18 14:17:40 +00:00
|
|
|
/*! \li \ref cel.c uses the configuration file \ref cel.conf
|
|
|
|
* \addtogroup configuration_file Configuration Files
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* \page cel.conf cel.conf
|
|
|
|
* \verbinclude cel.conf.sample
|
|
|
|
*/
|
|
|
|
|
2012-06-15 16:20:16 +00:00
|
|
|
/*** MODULEINFO
|
|
|
|
<support_level>core</support_level>
|
|
|
|
***/
|
|
|
|
|
2009-06-26 15:28:53 +00:00
|
|
|
#include "asterisk.h"
|
|
|
|
|
|
|
|
ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
|
|
|
|
|
|
|
|
#include "asterisk/_private.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"
|
2013-06-13 13:15:56 +00:00
|
|
|
#include "asterisk/config_options.h"
|
2009-06-26 15:28:53 +00:00
|
|
|
#include "asterisk/cli.h"
|
|
|
|
#include "asterisk/astobj2.h"
|
2013-06-13 13:15:56 +00:00
|
|
|
#include "asterisk/stasis_message_router.h"
|
|
|
|
#include "asterisk/stasis_channels.h"
|
|
|
|
#include "asterisk/stasis_bridging.h"
|
|
|
|
#include "asterisk/bridging.h"
|
|
|
|
|
|
|
|
/*** DOCUMENTATION
|
|
|
|
<configInfo name="cel" language="en_US">
|
|
|
|
<configFile name="cel.conf">
|
|
|
|
<configObject name="general">
|
|
|
|
<synopsis>Options that apply globally to Channel Event Logging (CEL)</synopsis>
|
|
|
|
<configOption name="enable">
|
|
|
|
<synopsis>Determines whether CEL is enabled</synopsis>
|
|
|
|
</configOption>
|
|
|
|
<configOption name="dateformat">
|
|
|
|
<synopsis>The format to be used for dates when logging</synopsis>
|
|
|
|
</configOption>
|
|
|
|
<configOption name="apps">
|
|
|
|
<synopsis>List of apps for CEL to track</synopsis>
|
|
|
|
<description><para>A case-insensitive, comma-separated list of applications
|
|
|
|
to track when one or both of APP_START and APP_END events are flagged for
|
|
|
|
tracking</para></description>
|
|
|
|
</configOption>
|
|
|
|
<configOption name="events">
|
|
|
|
<synopsis>List of events for CEL to track</synopsis>
|
|
|
|
<description><para>A case-sensitive, comma-separated list of event names
|
|
|
|
to track. These event names do not include the leading <literal>AST_CEL</literal>.
|
|
|
|
</para>
|
|
|
|
<enumlist>
|
|
|
|
<enum name="ALL">
|
|
|
|
<para>Special value which tracks all events.</para>
|
|
|
|
</enum>
|
|
|
|
<enum name="CHAN_START"/>
|
|
|
|
<enum name="CHAN_END"/>
|
|
|
|
<enum name="ANSWER"/>
|
|
|
|
<enum name="HANGUP"/>
|
|
|
|
<enum name="APP_START"/>
|
|
|
|
<enum name="APP_END"/>
|
|
|
|
<enum name="BRIDGE_START"/>
|
|
|
|
<enum name="BRIDGE_END"/>
|
|
|
|
<enum name="BRIDGE_UPDATE"/>
|
|
|
|
<enum name="CONF_START"/>
|
|
|
|
<enum name="CONF_END"/>
|
|
|
|
<enum name="PARK_START"/>
|
|
|
|
<enum name="PARK_END"/>
|
|
|
|
<enum name="TRANSFER"/>
|
|
|
|
<enum name="USER_DEFINED"/>
|
|
|
|
<enum name="CONF_ENTER"/>
|
|
|
|
<enum name="CONF_EXIT"/>
|
|
|
|
<enum name="BLINDTRANSFER"/>
|
|
|
|
<enum name="ATTENDEDTRANSFER"/>
|
|
|
|
<enum name="PICKUP"/>
|
|
|
|
<enum name="FORWARD"/>
|
|
|
|
<enum name="3WAY_START"/>
|
|
|
|
<enum name="3WAY_END"/>
|
|
|
|
<enum name="HOOKFLASH"/>
|
|
|
|
<enum name="LINKEDID_END"/>
|
|
|
|
|
|
|
|
</enumlist>
|
|
|
|
</description>
|
|
|
|
</configOption>
|
|
|
|
</configObject>
|
|
|
|
</configFile>
|
|
|
|
</configInfo>
|
|
|
|
***/
|
2009-06-26 15:28:53 +00:00
|
|
|
|
2013-06-13 13:15:56 +00:00
|
|
|
/*! Message router for state that CEL needs to know about */
|
|
|
|
static struct stasis_message_router *cel_state_router;
|
2009-06-26 15:28:53 +00:00
|
|
|
|
2013-06-13 13:15:56 +00:00
|
|
|
/*! Aggregation topic for all topics CEL needs to know about */
|
|
|
|
static struct stasis_topic *cel_state_topic;
|
2009-06-26 15:28:53 +00:00
|
|
|
|
2013-06-13 13:15:56 +00:00
|
|
|
/*! Subscription for forwarding the channel caching topic */
|
|
|
|
static struct stasis_subscription *cel_channel_forwarder;
|
|
|
|
|
|
|
|
/*! Subscription for forwarding the channel caching topic */
|
|
|
|
static struct stasis_subscription *cel_bridge_forwarder;
|
|
|
|
|
|
|
|
/*! Container for primary channel/bridge ID listing for 2 party bridges */
|
|
|
|
static struct ao2_container *bridge_primaries;
|
|
|
|
|
|
|
|
/*! The number of buckets into which primary channel uniqueids will be hashed */
|
|
|
|
#define BRIDGE_PRIMARY_BUCKETS 251
|
|
|
|
|
|
|
|
/*! Container for dial end multichannel blobs for holding on to dial statuses */
|
|
|
|
static struct ao2_container *cel_dialstatus_store;
|
2009-06-26 15:28:53 +00:00
|
|
|
|
|
|
|
/*!
|
|
|
|
* \brief Maximum possible CEL event IDs
|
|
|
|
* \note This limit is currently imposed by the eventset definition
|
|
|
|
*/
|
|
|
|
#define CEL_MAX_EVENT_IDS 64
|
|
|
|
|
2012-03-22 19:51:16 +00:00
|
|
|
/*!
|
2013-06-13 13:15:56 +00:00
|
|
|
* \brief Number of buckets for the appset container
|
2009-06-26 15:28:53 +00:00
|
|
|
*/
|
2013-06-13 13:15:56 +00:00
|
|
|
#define NUM_APP_BUCKETS 97
|
2009-06-26 15:28:53 +00:00
|
|
|
|
|
|
|
/*!
|
2013-06-13 13:15:56 +00:00
|
|
|
* \brief Number of buckets for the dialstatus container
|
2009-06-26 15:28:53 +00:00
|
|
|
*/
|
2013-06-13 13:15:56 +00:00
|
|
|
#define NUM_DIALSTATUS_BUCKETS 251
|
2009-06-26 15:28:53 +00:00
|
|
|
|
|
|
|
/*!
|
|
|
|
* \brief Container of Asterisk application names
|
|
|
|
*
|
|
|
|
* The apps in this container are the applications that were specified
|
|
|
|
* in the configuration as applications that CEL events should be generated
|
|
|
|
* for when they start and end on a channel.
|
|
|
|
*/
|
2012-05-02 17:43:16 +00:00
|
|
|
static struct ao2_container *linkedids;
|
2009-06-26 15:28:53 +00:00
|
|
|
|
2013-06-13 13:15:56 +00:00
|
|
|
/*! \brief A structure to hold global configuration-related options */
|
|
|
|
struct cel_general_config {
|
|
|
|
AST_DECLARE_STRING_FIELDS(
|
|
|
|
AST_STRING_FIELD(date_format); /*!< The desired date format for logging */
|
|
|
|
);
|
|
|
|
int enable; /*!< Whether CEL is enabled */
|
|
|
|
int64_t events; /*!< The events to be logged */
|
|
|
|
struct ao2_container *apps; /*!< The apps for which to log app start and end events */
|
|
|
|
};
|
|
|
|
|
|
|
|
/*! \brief Destructor for cel_config */
|
|
|
|
static void cel_general_config_dtor(void *obj)
|
|
|
|
{
|
|
|
|
struct cel_general_config *cfg = obj;
|
|
|
|
ast_string_field_free_memory(cfg);
|
|
|
|
ao2_cleanup(cfg->apps);
|
|
|
|
cfg->apps = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void *cel_general_config_alloc(void)
|
|
|
|
{
|
|
|
|
RAII_VAR(struct cel_general_config *, cfg, NULL, ao2_cleanup);
|
|
|
|
|
|
|
|
if (!(cfg = ao2_alloc(sizeof(*cfg), cel_general_config_dtor))) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ast_string_field_init(cfg, 64)) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!(cfg->apps = ast_str_container_alloc(NUM_APP_BUCKETS))) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
ao2_ref(cfg, +1);
|
|
|
|
return cfg;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*! \brief A container that holds all config-related information */
|
|
|
|
struct cel_config {
|
|
|
|
struct cel_general_config *general;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
static AO2_GLOBAL_OBJ_STATIC(cel_configs);
|
|
|
|
|
|
|
|
/*! \brief Destructor for cel_config */
|
|
|
|
static void cel_config_dtor(void *obj)
|
|
|
|
{
|
|
|
|
struct cel_config *cfg = obj;
|
|
|
|
ao2_cleanup(cfg->general);
|
|
|
|
cfg->general = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void *cel_config_alloc(void)
|
|
|
|
{
|
|
|
|
RAII_VAR(struct cel_config *, cfg, NULL, ao2_cleanup);
|
|
|
|
|
|
|
|
if (!(cfg = ao2_alloc(sizeof(*cfg), cel_config_dtor))) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!(cfg->general = cel_general_config_alloc())) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
ao2_ref(cfg, +1);
|
|
|
|
return cfg;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*! \brief An aco_type structure to link the "general" category to the cel_general_config type */
|
|
|
|
static struct aco_type general_option = {
|
|
|
|
.type = ACO_GLOBAL,
|
|
|
|
.name = "general",
|
|
|
|
.item_offset = offsetof(struct cel_config, general),
|
|
|
|
.category_match = ACO_WHITELIST,
|
|
|
|
.category = "^general$",
|
|
|
|
};
|
|
|
|
|
|
|
|
/*! \brief The config file to be processed for the module. */
|
|
|
|
static struct aco_file cel_conf = {
|
|
|
|
.filename = "cel.conf", /*!< The name of the config file */
|
|
|
|
.types = ACO_TYPES(&general_option), /*!< The mapping object types to be processed */
|
|
|
|
.skip_category = "(^manager$|^radius$)", /*!< Config sections used by existing modules. Do not add to this list. */
|
|
|
|
};
|
|
|
|
|
|
|
|
static int cel_pre_apply_config(void);
|
|
|
|
|
|
|
|
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 cel_pre_apply_config(void)
|
|
|
|
{
|
|
|
|
struct cel_config *cfg = aco_pending_config(&cel_cfg_info);
|
|
|
|
|
|
|
|
if (!cfg->general) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!ao2_container_count(cfg->general->apps)) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (cfg->general->events & ((int64_t) 1 << AST_CEL_APP_START)) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (cfg->general->events & ((int64_t) 1 << AST_CEL_APP_END)) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
ast_log(LOG_ERROR, "Applications are listed to be tracked, but APP events are not tracked\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct aco_type *general_options[] = ACO_TYPES(&general_option);
|
2009-06-26 15:28:53 +00:00
|
|
|
|
|
|
|
/*!
|
|
|
|
* \brief Map of ast_cel_event_type to strings
|
|
|
|
*/
|
2009-07-09 14:10:01 +00:00
|
|
|
static const char * const cel_event_types[CEL_MAX_EVENT_IDS] = {
|
2009-06-26 15:28:53 +00:00
|
|
|
[0] = "ALL",
|
|
|
|
[AST_CEL_CHANNEL_START] = "CHAN_START",
|
|
|
|
[AST_CEL_CHANNEL_END] = "CHAN_END",
|
|
|
|
[AST_CEL_ANSWER] = "ANSWER",
|
|
|
|
[AST_CEL_HANGUP] = "HANGUP",
|
|
|
|
[AST_CEL_APP_START] = "APP_START",
|
|
|
|
[AST_CEL_APP_END] = "APP_END",
|
|
|
|
[AST_CEL_BRIDGE_START] = "BRIDGE_START",
|
|
|
|
[AST_CEL_BRIDGE_END] = "BRIDGE_END",
|
|
|
|
[AST_CEL_BRIDGE_UPDATE] = "BRIDGE_UPDATE",
|
|
|
|
[AST_CEL_CONF_START] = "CONF_START",
|
|
|
|
[AST_CEL_CONF_END] = "CONF_END",
|
|
|
|
[AST_CEL_PARK_START] = "PARK_START",
|
|
|
|
[AST_CEL_PARK_END] = "PARK_END",
|
|
|
|
[AST_CEL_TRANSFER] = "TRANSFER",
|
|
|
|
[AST_CEL_USER_DEFINED] = "USER_DEFINED",
|
|
|
|
[AST_CEL_CONF_ENTER] = "CONF_ENTER",
|
|
|
|
[AST_CEL_CONF_EXIT] = "CONF_EXIT",
|
|
|
|
[AST_CEL_BLINDTRANSFER] = "BLINDTRANSFER",
|
|
|
|
[AST_CEL_ATTENDEDTRANSFER] = "ATTENDEDTRANSFER",
|
|
|
|
[AST_CEL_PICKUP] = "PICKUP",
|
|
|
|
[AST_CEL_FORWARD] = "FORWARD",
|
|
|
|
[AST_CEL_3WAY_START] = "3WAY_START",
|
|
|
|
[AST_CEL_3WAY_END] = "3WAY_END",
|
|
|
|
[AST_CEL_HOOKFLASH] = "HOOKFLASH",
|
|
|
|
[AST_CEL_LINKEDID_END] = "LINKEDID_END",
|
|
|
|
};
|
|
|
|
|
2013-06-13 13:15:56 +00:00
|
|
|
struct bridge_assoc {
|
|
|
|
AST_DECLARE_STRING_FIELDS(
|
|
|
|
AST_STRING_FIELD(channel_id); /*!< UniqueID of the primary/dialing channel */
|
|
|
|
AST_STRING_FIELD(bridge_id); /*!< UniqueID of the bridge */
|
|
|
|
AST_STRING_FIELD(secondary_id); /*!< UniqueID of the secondary/dialed channel */
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
static void bridge_assoc_dtor(void *obj)
|
|
|
|
{
|
|
|
|
struct bridge_assoc *assoc = obj;
|
|
|
|
ast_string_field_free_memory(assoc);
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct bridge_assoc *bridge_assoc_alloc(const char *channel_id, const char *bridge_id, const char *secondary_id)
|
|
|
|
{
|
|
|
|
RAII_VAR(struct bridge_assoc *, assoc, ao2_alloc(sizeof(*assoc), bridge_assoc_dtor), ao2_cleanup);
|
|
|
|
if (!assoc || ast_string_field_init(assoc, 64)) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
ast_string_field_set(assoc, channel_id, channel_id);
|
|
|
|
ast_string_field_set(assoc, bridge_id, bridge_id);
|
|
|
|
ast_string_field_set(assoc, secondary_id, secondary_id);
|
|
|
|
|
|
|
|
ao2_ref(assoc, +1);
|
|
|
|
return assoc;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int add_bridge_primary(const char *channel_id, const char *bridge_id, const char *secondary_id)
|
|
|
|
{
|
|
|
|
RAII_VAR(struct bridge_assoc *, assoc, bridge_assoc_alloc(channel_id, bridge_id, secondary_id), ao2_cleanup);
|
|
|
|
if (!assoc) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
ao2_link(bridge_primaries, assoc);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void remove_bridge_primary(const char *channel_id)
|
|
|
|
{
|
|
|
|
ao2_find(bridge_primaries, channel_id, OBJ_NODATA | OBJ_MULTIPLE | OBJ_UNLINK | OBJ_KEY);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*! \brief Hashing function for bridge_assoc */
|
|
|
|
static int bridge_assoc_hash(const void *obj, int flags)
|
|
|
|
{
|
|
|
|
const struct bridge_assoc *assoc = obj;
|
|
|
|
const char *uniqueid = obj;
|
|
|
|
if (!(flags & OBJ_KEY)) {
|
|
|
|
uniqueid = assoc->channel_id;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ast_str_hash(uniqueid);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*! \brief Comparator function for bridge_assoc */
|
|
|
|
static int bridge_assoc_cmp(void *obj, void *arg, int flags)
|
|
|
|
{
|
|
|
|
struct bridge_assoc *assoc1 = obj, *assoc2 = arg;
|
|
|
|
const char *assoc2_id = arg, *assoc1_id = assoc1->channel_id;
|
|
|
|
if (!(flags & OBJ_KEY)) {
|
|
|
|
assoc2_id = assoc2->channel_id;
|
|
|
|
}
|
|
|
|
|
|
|
|
return !strcmp(assoc1_id, assoc2_id) ? CMP_MATCH | CMP_STOP : 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const char *get_caller_uniqueid(struct ast_multi_channel_blob *blob)
|
|
|
|
{
|
|
|
|
struct ast_channel_snapshot *caller = ast_multi_channel_blob_get_channel(blob, "caller");
|
|
|
|
if (!caller) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return caller->uniqueid;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*! \brief Hashing function for dialstatus container */
|
|
|
|
static int dialstatus_hash(const void *obj, int flags)
|
|
|
|
{
|
|
|
|
struct ast_multi_channel_blob *blob = (void *) obj;
|
|
|
|
const char *uniqueid = obj;
|
|
|
|
if (!(flags & OBJ_KEY)) {
|
|
|
|
uniqueid = get_caller_uniqueid(blob);
|
|
|
|
}
|
|
|
|
|
|
|
|
return ast_str_hash(uniqueid);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*! \brief Comparator function for dialstatus container */
|
|
|
|
static int dialstatus_cmp(void *obj, void *arg, int flags)
|
|
|
|
{
|
|
|
|
struct ast_multi_channel_blob *blob1 = obj, *blob2 = arg;
|
|
|
|
const char *blob2_id = arg, *blob1_id = get_caller_uniqueid(blob1);
|
|
|
|
if (!(flags & OBJ_KEY)) {
|
|
|
|
blob2_id = get_caller_uniqueid(blob2);
|
|
|
|
}
|
|
|
|
|
|
|
|
return !strcmp(blob1_id, blob2_id) ? CMP_MATCH | CMP_STOP : 0;
|
|
|
|
}
|
|
|
|
|
2009-06-26 15:28:53 +00:00
|
|
|
/*!
|
|
|
|
* \brief Map of ast_cel_ama_flags to strings
|
|
|
|
*/
|
2009-07-09 14:10:01 +00:00
|
|
|
static const char * const cel_ama_flags[AST_CEL_AMA_FLAG_TOTAL] = {
|
2010-08-23 13:23:37 +00:00
|
|
|
[AST_CEL_AMA_FLAG_NONE] = "NONE",
|
2009-06-26 15:28:53 +00:00
|
|
|
[AST_CEL_AMA_FLAG_OMIT] = "OMIT",
|
|
|
|
[AST_CEL_AMA_FLAG_BILLING] = "BILLING",
|
|
|
|
[AST_CEL_AMA_FLAG_DOCUMENTATION] = "DOCUMENTATION",
|
|
|
|
};
|
|
|
|
|
|
|
|
unsigned int ast_cel_check_enabled(void)
|
|
|
|
{
|
2013-06-13 13:15:56 +00:00
|
|
|
RAII_VAR(struct cel_config *, cfg, ao2_global_obj_ref(cel_configs), ao2_cleanup);
|
|
|
|
|
|
|
|
if (!cfg || !cfg->general) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return cfg->general->enable;
|
2009-06-26 15:28:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int print_app(void *obj, void *arg, int flags)
|
|
|
|
{
|
|
|
|
struct ast_cli_args *a = arg;
|
|
|
|
|
|
|
|
ast_cli(a->fd, "CEL Tracking Application: %s\n", (const char *) obj);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void print_cel_sub(const struct ast_event *event, void *data)
|
|
|
|
{
|
|
|
|
struct ast_cli_args *a = data;
|
|
|
|
|
|
|
|
ast_cli(a->fd, "CEL Event Subscriber: %s\n",
|
|
|
|
ast_event_get_ie_str(event, AST_EVENT_IE_DESCRIPTION));
|
|
|
|
}
|
|
|
|
|
|
|
|
static char *handle_cli_status(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
|
|
|
|
{
|
|
|
|
unsigned int i;
|
|
|
|
struct ast_event_sub *sub;
|
2013-06-13 13:15:56 +00:00
|
|
|
RAII_VAR(struct cel_config *, cfg, ao2_global_obj_ref(cel_configs), ao2_cleanup);
|
|
|
|
|
|
|
|
if (!cfg || !cfg->general) {
|
|
|
|
return CLI_FAILURE;
|
|
|
|
}
|
2009-06-26 15:28:53 +00:00
|
|
|
|
|
|
|
switch (cmd) {
|
|
|
|
case CLI_INIT:
|
|
|
|
e->command = "cel show status";
|
|
|
|
e->usage =
|
|
|
|
"Usage: cel show status\n"
|
|
|
|
" Displays the Channel Event Logging system status.\n";
|
|
|
|
return NULL;
|
|
|
|
case CLI_GENERATE:
|
|
|
|
return NULL;
|
|
|
|
case CLI_HANDLER:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (a->argc > 3) {
|
|
|
|
return CLI_SHOWUSAGE;
|
|
|
|
}
|
|
|
|
|
2013-06-13 13:15:56 +00:00
|
|
|
ast_cli(a->fd, "CEL Logging: %s\n", ast_cel_check_enabled() ? "Enabled" : "Disabled");
|
2009-06-26 15:28:53 +00:00
|
|
|
|
2013-06-13 13:15:56 +00:00
|
|
|
if (!cfg->general->enable) {
|
2009-06-26 15:28:53 +00:00
|
|
|
return CLI_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2013-06-13 13:15:56 +00:00
|
|
|
for (i = 0; i < (sizeof(cfg->general->events) * 8); i++) {
|
2009-06-26 15:28:53 +00:00
|
|
|
const char *name;
|
|
|
|
|
2013-06-13 13:15:56 +00:00
|
|
|
if (!(cfg->general->events & ((int64_t) 1 << i))) {
|
2009-06-26 15:28:53 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
name = ast_cel_get_type_name(i);
|
|
|
|
if (strcasecmp(name, "Unknown")) {
|
|
|
|
ast_cli(a->fd, "CEL Tracking Event: %s\n", name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-06-13 13:15:56 +00:00
|
|
|
ao2_callback(cfg->general->apps, OBJ_NODATA, print_app, a);
|
2009-06-26 15:28:53 +00:00
|
|
|
|
|
|
|
if (!(sub = ast_event_subscribe_new(AST_EVENT_SUB, print_cel_sub, a))) {
|
|
|
|
return CLI_FAILURE;
|
|
|
|
}
|
|
|
|
ast_event_sub_append_ie_uint(sub, AST_EVENT_IE_EVENTTYPE, AST_EVENT_CEL);
|
|
|
|
ast_event_report_subs(sub);
|
|
|
|
ast_event_sub_destroy(sub);
|
|
|
|
sub = NULL;
|
|
|
|
|
|
|
|
return CLI_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct ast_cli_entry cli_status = AST_CLI_DEFINE(handle_cli_status, "Display the CEL status");
|
|
|
|
|
|
|
|
enum ast_cel_event_type ast_cel_str_to_event_type(const char *name)
|
|
|
|
{
|
|
|
|
unsigned int i;
|
|
|
|
|
|
|
|
for (i = 0; i < ARRAY_LEN(cel_event_types); i++) {
|
|
|
|
if (!cel_event_types[i]) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!strcasecmp(name, cel_event_types[i])) {
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int ast_cel_track_event(enum ast_cel_event_type et)
|
|
|
|
{
|
2013-06-13 13:15:56 +00:00
|
|
|
RAII_VAR(struct cel_config *, cfg, ao2_global_obj_ref(cel_configs), ao2_cleanup);
|
|
|
|
|
|
|
|
if (!cfg || !cfg->general) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (cfg->general->events & ((int64_t) 1 << et));
|
2009-06-26 15:28:53 +00:00
|
|
|
}
|
|
|
|
|
2013-06-13 13:15:56 +00:00
|
|
|
static int events_handler(const struct aco_option *opt, struct ast_variable *var, void *obj)
|
2009-06-26 15:28:53 +00:00
|
|
|
{
|
2013-06-13 13:15:56 +00:00
|
|
|
struct cel_general_config *cfg = obj;
|
|
|
|
char *events = ast_strdupa(var->value);
|
2009-06-26 15:28:53 +00:00
|
|
|
char *cur_event;
|
|
|
|
|
|
|
|
while ((cur_event = strsep(&events, ","))) {
|
|
|
|
enum ast_cel_event_type event_type;
|
|
|
|
|
|
|
|
cur_event = ast_strip(cur_event);
|
|
|
|
if (ast_strlen_zero(cur_event)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
event_type = ast_cel_str_to_event_type(cur_event);
|
|
|
|
|
|
|
|
if (event_type == 0) {
|
|
|
|
/* All events */
|
2013-06-13 13:15:56 +00:00
|
|
|
cfg->events = (int64_t) -1;
|
2009-06-26 15:28:53 +00:00
|
|
|
} else if (event_type == -1) {
|
2013-06-13 13:15:56 +00:00
|
|
|
ast_log(LOG_ERROR, "Unknown event name '%s'\n", cur_event);
|
|
|
|
return -1;
|
2009-06-26 15:28:53 +00:00
|
|
|
} else {
|
2013-06-13 13:15:56 +00:00
|
|
|
cfg->events |= ((int64_t) 1 << event_type);
|
2009-06-26 15:28:53 +00:00
|
|
|
}
|
|
|
|
}
|
2013-06-13 13:15:56 +00:00
|
|
|
|
|
|
|
return 0;
|
2009-06-26 15:28:53 +00:00
|
|
|
}
|
|
|
|
|
2013-06-13 13:15:56 +00:00
|
|
|
static int apps_handler(const struct aco_option *opt, struct ast_variable *var, void *obj)
|
2009-06-26 15:28:53 +00:00
|
|
|
{
|
2013-06-13 13:15:56 +00:00
|
|
|
struct cel_general_config *cfg = obj;
|
|
|
|
char *apps = ast_strdupa(var->value);
|
2009-06-26 15:28:53 +00:00
|
|
|
char *cur_app;
|
|
|
|
|
|
|
|
while ((cur_app = strsep(&apps, ","))) {
|
|
|
|
cur_app = ast_strip(cur_app);
|
|
|
|
if (ast_strlen_zero(cur_app)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2013-06-13 13:15:56 +00:00
|
|
|
cur_app = ast_str_to_lower(cur_app);
|
|
|
|
ast_str_container_add(cfg->apps, cur_app);
|
2009-06-26 15:28:53 +00:00
|
|
|
}
|
|
|
|
|
2013-06-13 13:15:56 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2009-06-26 15:28:53 +00:00
|
|
|
|
|
|
|
static int do_reload(void)
|
|
|
|
{
|
2013-06-13 13:15:56 +00:00
|
|
|
if (aco_process_config(&cel_cfg_info, 1)) {
|
|
|
|
return -1;
|
|
|
|
}
|
2009-06-26 15:28:53 +00:00
|
|
|
|
2013-06-13 13:15:56 +00:00
|
|
|
ast_verb(3, "CEL logging %sabled.\n", ast_cel_check_enabled() ? "en" : "dis");
|
2009-06-26 15:28:53 +00:00
|
|
|
|
2013-06-13 13:15:56 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2009-06-26 15:28:53 +00:00
|
|
|
|
2013-06-13 13:15:56 +00:00
|
|
|
const char *ast_cel_get_type_name(enum ast_cel_event_type type)
|
|
|
|
{
|
|
|
|
return S_OR(cel_event_types[type], "Unknown");
|
|
|
|
}
|
2009-06-26 15:28:53 +00:00
|
|
|
|
2013-06-13 13:15:56 +00:00
|
|
|
const char *ast_cel_get_ama_flag_name(enum ast_cel_ama_flag flag)
|
|
|
|
{
|
|
|
|
if (flag < 0 || flag >= ARRAY_LEN(cel_ama_flags)) {
|
|
|
|
ast_log(LOG_WARNING, "Invalid AMA flag: %d\n", flag);
|
|
|
|
return "Unknown";
|
2009-06-26 15:28:53 +00:00
|
|
|
}
|
|
|
|
|
2013-06-13 13:15:56 +00:00
|
|
|
return S_OR(cel_ama_flags[flag], "Unknown");
|
|
|
|
}
|
|
|
|
|
|
|
|
static int cel_track_app(const char *const_app)
|
|
|
|
{
|
|
|
|
RAII_VAR(struct cel_config *, cfg, ao2_global_obj_ref(cel_configs), ao2_cleanup);
|
|
|
|
RAII_VAR(char *, app, NULL, ao2_cleanup);
|
|
|
|
char *app_lower;
|
|
|
|
|
|
|
|
if (!cfg || !cfg->general) {
|
|
|
|
return 0;
|
2009-06-26 15:28:53 +00:00
|
|
|
}
|
|
|
|
|
2013-06-13 13:15:56 +00:00
|
|
|
app_lower = ast_str_to_lower(ast_strdupa(const_app));
|
|
|
|
app = ao2_find(cfg->general->apps, app_lower, OBJ_KEY);
|
|
|
|
if (!app) {
|
|
|
|
return 0;
|
2009-06-26 15:28:53 +00:00
|
|
|
}
|
|
|
|
|
2013-06-13 13:15:56 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int report_event_snapshot(struct ast_channel_snapshot *snapshot,
|
|
|
|
enum ast_cel_event_type event_type, const char *userdefevname,
|
|
|
|
const char *extra)
|
|
|
|
{
|
|
|
|
struct timeval eventtime;
|
|
|
|
struct ast_event *ev;
|
|
|
|
char *linkedid = ast_strdupa(snapshot->linkedid);
|
|
|
|
char *peer_name = "";
|
|
|
|
RAII_VAR(struct bridge_assoc *, assoc, NULL, ao2_cleanup);
|
|
|
|
RAII_VAR(struct cel_config *, cfg, ao2_global_obj_ref(cel_configs), ao2_cleanup);
|
|
|
|
|
|
|
|
if (!cfg || !cfg->general) {
|
|
|
|
return 0;
|
2009-06-26 15:28:53 +00:00
|
|
|
}
|
|
|
|
|
2013-06-13 13:15:56 +00:00
|
|
|
if (!cfg->general->enable) {
|
|
|
|
return 0;
|
2009-06-26 15:28:53 +00:00
|
|
|
}
|
|
|
|
|
2013-06-13 13:15:56 +00:00
|
|
|
assoc = ao2_find(bridge_primaries, snapshot->uniqueid, OBJ_KEY);
|
|
|
|
if (assoc) {
|
|
|
|
RAII_VAR(struct ast_channel_snapshot *, bridged_snapshot, NULL, ao2_cleanup);
|
|
|
|
bridged_snapshot = ast_channel_snapshot_get_latest(assoc->secondary_id);
|
|
|
|
if (bridged_snapshot) {
|
|
|
|
peer_name = ast_strdupa(bridged_snapshot->name);
|
|
|
|
}
|
2009-06-26 15:28:53 +00:00
|
|
|
}
|
|
|
|
|
2013-06-13 13:15:56 +00:00
|
|
|
/* Record the linkedid of new channels if we are tracking LINKEDID_END even if we aren't
|
|
|
|
* reporting on CHANNEL_START so we can track when to send LINKEDID_END */
|
|
|
|
if (ast_cel_track_event(AST_CEL_LINKEDID_END) && event_type == AST_CEL_CHANNEL_START && linkedid) {
|
|
|
|
if (ast_cel_linkedid_ref(linkedid)) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
2009-06-26 15:28:53 +00:00
|
|
|
|
2013-06-13 13:15:56 +00:00
|
|
|
if (!ast_cel_track_event(event_type)) {
|
|
|
|
return 0;
|
|
|
|
}
|
2009-06-26 15:28:53 +00:00
|
|
|
|
2013-06-13 13:15:56 +00:00
|
|
|
if ((event_type == AST_CEL_APP_START || event_type == AST_CEL_APP_END)
|
|
|
|
&& !cel_track_app(snapshot->appl)) {
|
|
|
|
return 0;
|
2009-06-26 15:28:53 +00:00
|
|
|
}
|
|
|
|
|
2013-06-13 13:15:56 +00:00
|
|
|
eventtime = ast_tvnow();
|
2009-06-26 15:28:53 +00:00
|
|
|
|
2013-06-13 13:15:56 +00:00
|
|
|
ev = ast_event_new(AST_EVENT_CEL,
|
|
|
|
AST_EVENT_IE_CEL_EVENT_TYPE, AST_EVENT_IE_PLTYPE_UINT, event_type,
|
|
|
|
AST_EVENT_IE_CEL_EVENT_TIME, AST_EVENT_IE_PLTYPE_UINT, eventtime.tv_sec,
|
|
|
|
AST_EVENT_IE_CEL_EVENT_TIME_USEC, AST_EVENT_IE_PLTYPE_UINT, eventtime.tv_usec,
|
|
|
|
AST_EVENT_IE_CEL_USEREVENT_NAME, AST_EVENT_IE_PLTYPE_STR, S_OR(userdefevname, ""),
|
|
|
|
AST_EVENT_IE_CEL_CIDNAME, AST_EVENT_IE_PLTYPE_STR, snapshot->caller_name,
|
|
|
|
AST_EVENT_IE_CEL_CIDNUM, AST_EVENT_IE_PLTYPE_STR, snapshot->caller_number,
|
|
|
|
AST_EVENT_IE_CEL_CIDANI, AST_EVENT_IE_PLTYPE_STR, snapshot->caller_ani,
|
|
|
|
AST_EVENT_IE_CEL_CIDRDNIS, AST_EVENT_IE_PLTYPE_STR, snapshot->caller_rdnis,
|
|
|
|
AST_EVENT_IE_CEL_CIDDNID, AST_EVENT_IE_PLTYPE_STR, snapshot->caller_dnid,
|
|
|
|
AST_EVENT_IE_CEL_EXTEN, AST_EVENT_IE_PLTYPE_STR, snapshot->exten,
|
|
|
|
AST_EVENT_IE_CEL_CONTEXT, AST_EVENT_IE_PLTYPE_STR, snapshot->context,
|
|
|
|
AST_EVENT_IE_CEL_CHANNAME, AST_EVENT_IE_PLTYPE_STR, snapshot->name,
|
|
|
|
AST_EVENT_IE_CEL_APPNAME, AST_EVENT_IE_PLTYPE_STR, snapshot->appl,
|
|
|
|
AST_EVENT_IE_CEL_APPDATA, AST_EVENT_IE_PLTYPE_STR, snapshot->data,
|
|
|
|
AST_EVENT_IE_CEL_AMAFLAGS, AST_EVENT_IE_PLTYPE_UINT, snapshot->amaflags,
|
|
|
|
AST_EVENT_IE_CEL_ACCTCODE, AST_EVENT_IE_PLTYPE_STR, snapshot->accountcode,
|
|
|
|
AST_EVENT_IE_CEL_PEERACCT, AST_EVENT_IE_PLTYPE_STR, snapshot->peeraccount,
|
|
|
|
AST_EVENT_IE_CEL_UNIQUEID, AST_EVENT_IE_PLTYPE_STR, snapshot->uniqueid,
|
|
|
|
AST_EVENT_IE_CEL_LINKEDID, AST_EVENT_IE_PLTYPE_STR, snapshot->linkedid,
|
|
|
|
AST_EVENT_IE_CEL_USERFIELD, AST_EVENT_IE_PLTYPE_STR, snapshot->userfield,
|
|
|
|
AST_EVENT_IE_CEL_EXTRA, AST_EVENT_IE_PLTYPE_STR, S_OR(extra, ""),
|
|
|
|
AST_EVENT_IE_CEL_PEER, AST_EVENT_IE_PLTYPE_STR, peer_name,
|
|
|
|
AST_EVENT_IE_END);
|
2009-06-26 15:28:53 +00:00
|
|
|
|
2013-06-13 13:15:56 +00:00
|
|
|
if (ev && ast_event_queue(ev)) {
|
|
|
|
ast_event_destroy(ev);
|
|
|
|
return -1;
|
2010-08-23 13:09:47 +00:00
|
|
|
}
|
|
|
|
|
2013-06-13 13:15:56 +00:00
|
|
|
return 0;
|
2009-06-26 15:28:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* called whenever a channel is destroyed or a linkedid is changed to
|
|
|
|
* potentially emit a CEL_LINKEDID_END event */
|
2013-06-13 13:15:56 +00:00
|
|
|
static void check_retire_linkedid(struct ast_channel_snapshot *snapshot)
|
2009-06-26 15:28:53 +00:00
|
|
|
{
|
2012-05-02 17:43:16 +00:00
|
|
|
char *lid;
|
2009-06-26 15:28:53 +00:00
|
|
|
|
|
|
|
/* make sure we need to do all this work */
|
|
|
|
|
2013-06-13 13:15:56 +00:00
|
|
|
if (ast_strlen_zero(snapshot->linkedid) || !ast_cel_track_event(AST_CEL_LINKEDID_END)) {
|
2012-05-02 17:43:16 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-06-13 13:15:56 +00:00
|
|
|
if (!(lid = ao2_find(linkedids, (void *) snapshot->linkedid, OBJ_POINTER))) {
|
|
|
|
ast_log(LOG_ERROR, "Something weird happened, couldn't find linkedid %s\n", snapshot->linkedid);
|
2012-05-02 17:43:16 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* We have a ref for each channel with this linkedid, the link and the above find, so if
|
|
|
|
* before unreffing the channel we have a refcount of 3, we're done. Unlink and report. */
|
|
|
|
if (ao2_ref(lid, -1) == 3) {
|
2013-06-13 13:15:56 +00:00
|
|
|
ast_str_container_remove(linkedids, lid);
|
|
|
|
report_event_snapshot(snapshot, AST_CEL_LINKEDID_END, NULL, NULL);
|
2009-06-26 15:28:53 +00:00
|
|
|
}
|
2012-05-02 17:43:16 +00:00
|
|
|
ao2_ref(lid, -1);
|
2009-06-26 15:28:53 +00:00
|
|
|
}
|
|
|
|
|
2012-07-18 19:18:40 +00:00
|
|
|
/* Note that no 'chan_fixup' function is provided for this datastore type,
|
|
|
|
* because the channels that will use it will never be involved in masquerades.
|
|
|
|
*/
|
|
|
|
static const struct ast_datastore_info fabricated_channel_datastore = {
|
|
|
|
.type = "CEL fabricated channel",
|
2012-07-19 22:08:20 +00:00
|
|
|
.destroy = ast_free_ptr,
|
2012-07-18 19:18:40 +00:00
|
|
|
};
|
|
|
|
|
2009-06-26 15:28:53 +00:00
|
|
|
struct ast_channel *ast_cel_fabricate_channel_from_event(const struct ast_event *event)
|
|
|
|
{
|
|
|
|
struct varshead *headp;
|
|
|
|
struct ast_var_t *newvariable;
|
2012-02-01 17:42:15 +00:00
|
|
|
const char *mixed_name;
|
2009-06-26 15:28:53 +00:00
|
|
|
char timebuf[30];
|
|
|
|
struct ast_channel *tchan;
|
|
|
|
struct ast_cel_event_record record = {
|
|
|
|
.version = AST_CEL_EVENT_RECORD_VERSION,
|
|
|
|
};
|
2012-07-18 19:18:40 +00:00
|
|
|
struct ast_datastore *datastore;
|
|
|
|
char *app_data;
|
2013-06-13 13:15:56 +00:00
|
|
|
RAII_VAR(struct cel_config *, cfg, ao2_global_obj_ref(cel_configs), ao2_cleanup);
|
|
|
|
|
|
|
|
if (!cfg || !cfg->general) {
|
|
|
|
return NULL;
|
|
|
|
}
|
2009-06-26 15:28:53 +00:00
|
|
|
|
|
|
|
/* do not call ast_channel_alloc because this is not really a real channel */
|
|
|
|
if (!(tchan = ast_dummy_channel_alloc())) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2012-02-29 16:52:47 +00:00
|
|
|
headp = ast_channel_varshead(tchan);
|
2009-06-26 15:28:53 +00:00
|
|
|
|
|
|
|
/* first, get the variables from the event */
|
|
|
|
if (ast_cel_fill_record(event, &record)) {
|
2011-09-26 19:40:12 +00:00
|
|
|
ast_channel_unref(tchan);
|
2009-06-26 15:28:53 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* next, fill the channel with their data */
|
2012-02-01 17:42:15 +00:00
|
|
|
mixed_name = (record.event_type == AST_CEL_USER_DEFINED)
|
|
|
|
? record.user_defined_name : record.event_name;
|
|
|
|
if ((newvariable = ast_var_assign("eventtype", mixed_name))) {
|
2009-06-26 15:28:53 +00:00
|
|
|
AST_LIST_INSERT_HEAD(headp, newvariable, entries);
|
|
|
|
}
|
|
|
|
|
2013-06-13 13:15:56 +00:00
|
|
|
if (ast_strlen_zero(cfg->general->date_format)) {
|
2010-03-20 12:03:07 +00:00
|
|
|
snprintf(timebuf, sizeof(timebuf), "%ld.%06ld", (long) record.event_time.tv_sec,
|
2009-07-23 01:31:18 +00:00
|
|
|
(long) record.event_time.tv_usec);
|
2009-06-26 15:28:53 +00:00
|
|
|
} else {
|
|
|
|
struct ast_tm tm;
|
|
|
|
ast_localtime(&record.event_time, &tm, NULL);
|
2013-06-13 13:15:56 +00:00
|
|
|
ast_strftime(timebuf, sizeof(timebuf), cfg->general->date_format, &tm);
|
2009-06-26 15:28:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if ((newvariable = ast_var_assign("eventtime", timebuf))) {
|
|
|
|
AST_LIST_INSERT_HEAD(headp, newvariable, entries);
|
|
|
|
}
|
|
|
|
|
2012-02-01 17:42:15 +00:00
|
|
|
if ((newvariable = ast_var_assign("eventenum", record.event_name))) {
|
|
|
|
AST_LIST_INSERT_HEAD(headp, newvariable, entries);
|
|
|
|
}
|
2012-01-13 17:36:44 +00:00
|
|
|
if ((newvariable = ast_var_assign("userdeftype", record.user_defined_name))) {
|
|
|
|
AST_LIST_INSERT_HEAD(headp, newvariable, entries);
|
|
|
|
}
|
2009-06-26 15:28:53 +00:00
|
|
|
if ((newvariable = ast_var_assign("eventextra", record.extra))) {
|
|
|
|
AST_LIST_INSERT_HEAD(headp, newvariable, entries);
|
|
|
|
}
|
|
|
|
|
2012-02-29 16:52:47 +00:00
|
|
|
ast_channel_caller(tchan)->id.name.valid = 1;
|
|
|
|
ast_channel_caller(tchan)->id.name.str = ast_strdup(record.caller_id_name);
|
|
|
|
ast_channel_caller(tchan)->id.number.valid = 1;
|
|
|
|
ast_channel_caller(tchan)->id.number.str = ast_strdup(record.caller_id_num);
|
|
|
|
ast_channel_caller(tchan)->ani.number.valid = 1;
|
|
|
|
ast_channel_caller(tchan)->ani.number.str = ast_strdup(record.caller_id_ani);
|
|
|
|
ast_channel_redirecting(tchan)->from.number.valid = 1;
|
|
|
|
ast_channel_redirecting(tchan)->from.number.str = ast_strdup(record.caller_id_rdnis);
|
|
|
|
ast_channel_dialed(tchan)->number.str = ast_strdup(record.caller_id_dnid);
|
2009-06-26 15:28:53 +00:00
|
|
|
|
2012-02-13 17:27:06 +00:00
|
|
|
ast_channel_exten_set(tchan, record.extension);
|
|
|
|
ast_channel_context_set(tchan, record.context);
|
2012-01-09 22:15:50 +00:00
|
|
|
ast_channel_name_set(tchan, record.channel_name);
|
2012-01-24 20:12:09 +00:00
|
|
|
ast_channel_uniqueid_set(tchan, record.unique_id);
|
|
|
|
ast_channel_linkedid_set(tchan, record.linked_id);
|
|
|
|
ast_channel_accountcode_set(tchan, record.account_code);
|
|
|
|
ast_channel_peeraccount_set(tchan, record.peer_account);
|
|
|
|
ast_channel_userfield_set(tchan, record.user_field);
|
2009-06-26 15:28:53 +00:00
|
|
|
|
2012-01-11 22:53:09 +00:00
|
|
|
if ((newvariable = ast_var_assign("BRIDGEPEER", record.peer))) {
|
|
|
|
AST_LIST_INSERT_HEAD(headp, newvariable, entries);
|
|
|
|
}
|
2009-06-26 15:28:53 +00:00
|
|
|
|
2012-02-20 23:43:27 +00:00
|
|
|
ast_channel_amaflags_set(tchan, record.amaflag);
|
2009-06-26 15:28:53 +00:00
|
|
|
|
2012-07-18 19:18:40 +00:00
|
|
|
/* We need to store an 'application name' and 'application
|
|
|
|
* data' on the channel for logging purposes, but the channel
|
|
|
|
* structure only provides a place to store pointers, and it
|
|
|
|
* expects these pointers to be pointing to data that does not
|
|
|
|
* need to be freed. This means that the channel's destructor
|
|
|
|
* does not attempt to free any storage that these pointers
|
|
|
|
* point to. However, we can't provide data in that form directly for
|
|
|
|
* these structure members. In order to ensure that these data
|
|
|
|
* elements have a lifetime that matches the channel's
|
|
|
|
* lifetime, we'll put them in a datastore attached to the
|
|
|
|
* channel, and set's the channel's pointers to point into the
|
|
|
|
* datastore. The datastore will then be automatically destroyed
|
|
|
|
* when the channel is destroyed.
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (!(datastore = ast_datastore_alloc(&fabricated_channel_datastore, NULL))) {
|
|
|
|
ast_channel_unref(tchan);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!(app_data = ast_malloc(strlen(record.application_name) + strlen(record.application_data) + 2))) {
|
|
|
|
ast_datastore_free(datastore);
|
|
|
|
ast_channel_unref(tchan);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2012-07-19 22:25:00 +00:00
|
|
|
ast_channel_appl_set(tchan, strcpy(app_data, record.application_name));
|
|
|
|
ast_channel_data_set(tchan, strcpy(app_data + strlen(record.application_name) + 1,
|
|
|
|
record.application_data));
|
2012-07-18 19:18:40 +00:00
|
|
|
|
|
|
|
datastore->data = app_data;
|
|
|
|
ast_channel_datastore_add(tchan, datastore);
|
|
|
|
|
2009-06-26 15:28:53 +00:00
|
|
|
return tchan;
|
|
|
|
}
|
|
|
|
|
2012-05-22 17:29:12 +00:00
|
|
|
int ast_cel_linkedid_ref(const char *linkedid)
|
|
|
|
{
|
|
|
|
char *lid;
|
|
|
|
|
|
|
|
if (ast_strlen_zero(linkedid)) {
|
|
|
|
ast_log(LOG_ERROR, "The linkedid should never be empty\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!(lid = ao2_find(linkedids, (void *) linkedid, OBJ_POINTER))) {
|
|
|
|
if (!(lid = ao2_alloc(strlen(linkedid) + 1, NULL))) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
strcpy(lid, linkedid);
|
|
|
|
if (!ao2_link(linkedids, lid)) {
|
|
|
|
ao2_ref(lid, -1);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
/* Leave both the link and the alloc refs to show a count of 1 + the link */
|
|
|
|
}
|
|
|
|
/* If we've found, go ahead and keep the ref to increment count of how many channels
|
|
|
|
* have this linkedid. We'll clean it up in check_retire */
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-06-26 15:28:53 +00:00
|
|
|
int ast_cel_report_event(struct ast_channel *chan, enum ast_cel_event_type event_type,
|
|
|
|
const char *userdefevname, const char *extra, struct ast_channel *peer2)
|
|
|
|
{
|
|
|
|
struct timeval eventtime;
|
|
|
|
struct ast_event *ev;
|
|
|
|
const char *peername = "";
|
|
|
|
struct ast_channel *peer;
|
2012-05-02 17:43:16 +00:00
|
|
|
char *linkedid = ast_strdupa(ast_channel_linkedid(chan));
|
2009-06-26 15:28:53 +00:00
|
|
|
|
2013-06-13 13:15:56 +00:00
|
|
|
if (!ast_cel_check_enabled()) {
|
|
|
|
return 0;
|
|
|
|
}
|
2009-06-26 15:28:53 +00:00
|
|
|
|
2012-05-02 17:43:16 +00:00
|
|
|
/* Record the linkedid of new channels if we are tracking LINKEDID_END even if we aren't
|
|
|
|
* reporting on CHANNEL_START so we can track when to send LINKEDID_END */
|
2013-06-13 13:15:56 +00:00
|
|
|
if (ast_cel_track_event(AST_CEL_LINKEDID_END) && event_type == AST_CEL_CHANNEL_START && linkedid) {
|
2012-05-22 17:29:12 +00:00
|
|
|
if (ast_cel_linkedid_ref(linkedid)) {
|
|
|
|
return -1;
|
2012-05-02 17:43:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-06-13 13:15:56 +00:00
|
|
|
if (!ast_cel_track_event(event_type)) {
|
2009-06-26 15:28:53 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-06-13 13:15:56 +00:00
|
|
|
if ((event_type == AST_CEL_APP_START || event_type == AST_CEL_APP_END)
|
|
|
|
&& !cel_track_app(ast_channel_appl(chan))) {
|
|
|
|
return 0;
|
2009-06-26 15:28:53 +00:00
|
|
|
}
|
|
|
|
|
2012-05-02 17:43:16 +00:00
|
|
|
ast_channel_lock(chan);
|
|
|
|
peer = ast_bridged_channel(chan);
|
|
|
|
if (peer) {
|
|
|
|
ast_channel_ref(peer);
|
|
|
|
}
|
|
|
|
ast_channel_unlock(chan);
|
|
|
|
|
2009-06-26 15:28:53 +00:00
|
|
|
if (peer) {
|
|
|
|
ast_channel_lock(peer);
|
2012-01-09 22:15:50 +00:00
|
|
|
peername = ast_strdupa(ast_channel_name(peer));
|
2009-06-26 15:28:53 +00:00
|
|
|
ast_channel_unlock(peer);
|
|
|
|
} else if (peer2) {
|
|
|
|
ast_channel_lock(peer2);
|
2012-01-09 22:15:50 +00:00
|
|
|
peername = ast_strdupa(ast_channel_name(peer2));
|
2009-06-26 15:28:53 +00:00
|
|
|
ast_channel_unlock(peer2);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!userdefevname) {
|
|
|
|
userdefevname = "";
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!extra) {
|
|
|
|
extra = "";
|
|
|
|
}
|
|
|
|
|
|
|
|
eventtime = ast_tvnow();
|
|
|
|
|
|
|
|
ast_channel_lock(chan);
|
|
|
|
|
|
|
|
ev = ast_event_new(AST_EVENT_CEL,
|
2010-07-14 15:48:36 +00:00
|
|
|
AST_EVENT_IE_CEL_EVENT_TYPE, AST_EVENT_IE_PLTYPE_UINT, event_type,
|
|
|
|
AST_EVENT_IE_CEL_EVENT_TIME, AST_EVENT_IE_PLTYPE_UINT, eventtime.tv_sec,
|
|
|
|
AST_EVENT_IE_CEL_EVENT_TIME_USEC, AST_EVENT_IE_PLTYPE_UINT, eventtime.tv_usec,
|
|
|
|
AST_EVENT_IE_CEL_USEREVENT_NAME, AST_EVENT_IE_PLTYPE_STR, userdefevname,
|
|
|
|
AST_EVENT_IE_CEL_CIDNAME, AST_EVENT_IE_PLTYPE_STR,
|
2012-02-29 16:52:47 +00:00
|
|
|
S_COR(ast_channel_caller(chan)->id.name.valid, ast_channel_caller(chan)->id.name.str, ""),
|
2010-07-14 15:48:36 +00:00
|
|
|
AST_EVENT_IE_CEL_CIDNUM, AST_EVENT_IE_PLTYPE_STR,
|
2012-02-29 16:52:47 +00:00
|
|
|
S_COR(ast_channel_caller(chan)->id.number.valid, ast_channel_caller(chan)->id.number.str, ""),
|
2010-07-14 15:48:36 +00:00
|
|
|
AST_EVENT_IE_CEL_CIDANI, AST_EVENT_IE_PLTYPE_STR,
|
2012-02-29 16:52:47 +00:00
|
|
|
S_COR(ast_channel_caller(chan)->ani.number.valid, ast_channel_caller(chan)->ani.number.str, ""),
|
2010-07-14 15:48:36 +00:00
|
|
|
AST_EVENT_IE_CEL_CIDRDNIS, AST_EVENT_IE_PLTYPE_STR,
|
2012-02-29 16:52:47 +00:00
|
|
|
S_COR(ast_channel_redirecting(chan)->from.number.valid, ast_channel_redirecting(chan)->from.number.str, ""),
|
2010-07-14 15:48:36 +00:00
|
|
|
AST_EVENT_IE_CEL_CIDDNID, AST_EVENT_IE_PLTYPE_STR,
|
2012-02-29 16:52:47 +00:00
|
|
|
S_OR(ast_channel_dialed(chan)->number.str, ""),
|
2012-02-13 17:27:06 +00:00
|
|
|
AST_EVENT_IE_CEL_EXTEN, AST_EVENT_IE_PLTYPE_STR, ast_channel_exten(chan),
|
|
|
|
AST_EVENT_IE_CEL_CONTEXT, AST_EVENT_IE_PLTYPE_STR, ast_channel_context(chan),
|
2012-01-09 22:15:50 +00:00
|
|
|
AST_EVENT_IE_CEL_CHANNAME, AST_EVENT_IE_PLTYPE_STR, ast_channel_name(chan),
|
2012-02-13 17:27:06 +00:00
|
|
|
AST_EVENT_IE_CEL_APPNAME, AST_EVENT_IE_PLTYPE_STR, S_OR(ast_channel_appl(chan), ""),
|
|
|
|
AST_EVENT_IE_CEL_APPDATA, AST_EVENT_IE_PLTYPE_STR, S_OR(ast_channel_data(chan), ""),
|
2012-02-20 23:43:27 +00:00
|
|
|
AST_EVENT_IE_CEL_AMAFLAGS, AST_EVENT_IE_PLTYPE_UINT, ast_channel_amaflags(chan),
|
2012-01-24 20:12:09 +00:00
|
|
|
AST_EVENT_IE_CEL_ACCTCODE, AST_EVENT_IE_PLTYPE_STR, ast_channel_accountcode(chan),
|
|
|
|
AST_EVENT_IE_CEL_PEERACCT, AST_EVENT_IE_PLTYPE_STR, ast_channel_peeraccount(chan),
|
|
|
|
AST_EVENT_IE_CEL_UNIQUEID, AST_EVENT_IE_PLTYPE_STR, ast_channel_uniqueid(chan),
|
|
|
|
AST_EVENT_IE_CEL_LINKEDID, AST_EVENT_IE_PLTYPE_STR, ast_channel_linkedid(chan),
|
|
|
|
AST_EVENT_IE_CEL_USERFIELD, AST_EVENT_IE_PLTYPE_STR, ast_channel_userfield(chan),
|
2010-07-14 15:48:36 +00:00
|
|
|
AST_EVENT_IE_CEL_EXTRA, AST_EVENT_IE_PLTYPE_STR, extra,
|
|
|
|
AST_EVENT_IE_CEL_PEER, AST_EVENT_IE_PLTYPE_STR, peername,
|
|
|
|
AST_EVENT_IE_END);
|
2009-06-26 15:28:53 +00:00
|
|
|
|
|
|
|
ast_channel_unlock(chan);
|
|
|
|
|
|
|
|
if (peer) {
|
|
|
|
peer = ast_channel_unref(peer);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ev && ast_event_queue(ev)) {
|
|
|
|
ast_event_destroy(ev);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int ast_cel_fill_record(const struct ast_event *e, struct ast_cel_event_record *r)
|
|
|
|
{
|
|
|
|
if (r->version != AST_CEL_EVENT_RECORD_VERSION) {
|
|
|
|
ast_log(LOG_ERROR, "Module ABI mismatch for ast_cel_event_record. "
|
|
|
|
"Please ensure all modules were compiled for "
|
|
|
|
"this version of Asterisk.\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
r->event_type = ast_event_get_ie_uint(e, AST_EVENT_IE_CEL_EVENT_TYPE);
|
|
|
|
|
|
|
|
r->event_time.tv_sec = ast_event_get_ie_uint(e, AST_EVENT_IE_CEL_EVENT_TIME);
|
|
|
|
r->event_time.tv_usec = ast_event_get_ie_uint(e, AST_EVENT_IE_CEL_EVENT_TIME_USEC);
|
|
|
|
|
2012-02-01 17:42:15 +00:00
|
|
|
r->event_name = ast_cel_get_type_name(r->event_type);
|
2009-06-26 15:28:53 +00:00
|
|
|
if (r->event_type == AST_CEL_USER_DEFINED) {
|
|
|
|
r->user_defined_name = ast_event_get_ie_str(e, AST_EVENT_IE_CEL_USEREVENT_NAME);
|
|
|
|
} else {
|
2012-02-01 17:42:15 +00:00
|
|
|
r->user_defined_name = "";
|
2009-06-26 15:28:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
r->caller_id_name = S_OR(ast_event_get_ie_str(e, AST_EVENT_IE_CEL_CIDNAME), "");
|
|
|
|
r->caller_id_num = S_OR(ast_event_get_ie_str(e, AST_EVENT_IE_CEL_CIDNUM), "");
|
|
|
|
r->caller_id_ani = S_OR(ast_event_get_ie_str(e, AST_EVENT_IE_CEL_CIDANI), "");
|
|
|
|
r->caller_id_rdnis = S_OR(ast_event_get_ie_str(e, AST_EVENT_IE_CEL_CIDRDNIS), "");
|
|
|
|
r->caller_id_dnid = S_OR(ast_event_get_ie_str(e, AST_EVENT_IE_CEL_CIDDNID), "");
|
|
|
|
r->extension = S_OR(ast_event_get_ie_str(e, AST_EVENT_IE_CEL_EXTEN), "");
|
|
|
|
r->context = S_OR(ast_event_get_ie_str(e, AST_EVENT_IE_CEL_CONTEXT), "");
|
|
|
|
r->channel_name = S_OR(ast_event_get_ie_str(e, AST_EVENT_IE_CEL_CHANNAME), "");
|
|
|
|
r->application_name = S_OR(ast_event_get_ie_str(e, AST_EVENT_IE_CEL_APPNAME), "");
|
|
|
|
r->application_data = S_OR(ast_event_get_ie_str(e, AST_EVENT_IE_CEL_APPDATA), "");
|
|
|
|
r->account_code = S_OR(ast_event_get_ie_str(e, AST_EVENT_IE_CEL_ACCTCODE), "");
|
|
|
|
r->peer_account = S_OR(ast_event_get_ie_str(e, AST_EVENT_IE_CEL_ACCTCODE), "");
|
|
|
|
r->unique_id = S_OR(ast_event_get_ie_str(e, AST_EVENT_IE_CEL_UNIQUEID), "");
|
|
|
|
r->linked_id = S_OR(ast_event_get_ie_str(e, AST_EVENT_IE_CEL_LINKEDID), "");
|
|
|
|
r->amaflag = ast_event_get_ie_uint(e, AST_EVENT_IE_CEL_AMAFLAGS);
|
|
|
|
r->user_field = S_OR(ast_event_get_ie_str(e, AST_EVENT_IE_CEL_USERFIELD), "");
|
|
|
|
r->peer = S_OR(ast_event_get_ie_str(e, AST_EVENT_IE_CEL_PEER), "");
|
|
|
|
r->extra = S_OR(ast_event_get_ie_str(e, AST_EVENT_IE_CEL_EXTRA), "");
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-06-13 13:15:56 +00:00
|
|
|
/*! \brief Typedef for callbacks that get called on channel snapshot updates */
|
|
|
|
typedef void (*cel_channel_snapshot_monitor)(
|
|
|
|
struct ast_channel_snapshot *old_snapshot,
|
|
|
|
struct ast_channel_snapshot *new_snapshot);
|
|
|
|
|
|
|
|
static struct ast_multi_channel_blob *get_dialstatus_blob(const char *uniqueid)
|
2009-06-26 15:28:53 +00:00
|
|
|
{
|
2013-06-13 13:15:56 +00:00
|
|
|
return ao2_find(cel_dialstatus_store, uniqueid, OBJ_KEY | OBJ_UNLINK);
|
2009-06-26 15:28:53 +00:00
|
|
|
}
|
|
|
|
|
2013-06-13 13:15:56 +00:00
|
|
|
static const char *get_caller_dialstatus(struct ast_multi_channel_blob *blob)
|
2009-06-26 15:28:53 +00:00
|
|
|
{
|
2013-06-13 13:15:56 +00:00
|
|
|
struct ast_json *json = ast_multi_channel_blob_get_json(blob);
|
|
|
|
if (!json) {
|
|
|
|
return NULL;
|
|
|
|
}
|
2009-06-26 15:28:53 +00:00
|
|
|
|
2013-06-13 13:15:56 +00:00
|
|
|
json = ast_json_object_get(json, "dialstatus");
|
|
|
|
if (!json) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ast_json_string_get(json);
|
2009-06-26 15:28:53 +00:00
|
|
|
}
|
|
|
|
|
2013-06-13 13:15:56 +00:00
|
|
|
/*! \brief Handle channel state changes */
|
|
|
|
static void cel_channel_state_change(
|
|
|
|
struct ast_channel_snapshot *old_snapshot,
|
|
|
|
struct ast_channel_snapshot *new_snapshot)
|
|
|
|
{
|
|
|
|
int is_hungup, was_hungup;
|
2012-05-02 17:43:16 +00:00
|
|
|
|
2013-06-13 13:15:56 +00:00
|
|
|
if (!new_snapshot) {
|
|
|
|
report_event_snapshot(old_snapshot, AST_CEL_CHANNEL_END, NULL, NULL);
|
|
|
|
check_retire_linkedid(old_snapshot);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!old_snapshot) {
|
|
|
|
report_event_snapshot(new_snapshot, AST_CEL_CHANNEL_START, NULL, NULL);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
was_hungup = ast_test_flag(&old_snapshot->flags, AST_FLAG_ZOMBIE) ? 1 : 0;
|
|
|
|
is_hungup = ast_test_flag(&new_snapshot->flags, AST_FLAG_ZOMBIE) ? 1 : 0;
|
|
|
|
|
|
|
|
if (!was_hungup && is_hungup) {
|
|
|
|
RAII_VAR(struct ast_str *, extra_str, ast_str_create(128), ast_free);
|
|
|
|
RAII_VAR(struct ast_multi_channel_blob *, blob, get_dialstatus_blob(new_snapshot->uniqueid), ao2_cleanup);
|
|
|
|
const char *dialstatus = "";
|
|
|
|
if (blob && !ast_strlen_zero(get_caller_dialstatus(blob))) {
|
|
|
|
dialstatus = get_caller_dialstatus(blob);
|
|
|
|
}
|
|
|
|
ast_str_set(&extra_str, 0, "%d,%s,%s",
|
|
|
|
new_snapshot->hangupcause,
|
|
|
|
new_snapshot->hangupsource,
|
|
|
|
dialstatus);
|
|
|
|
report_event_snapshot(new_snapshot, AST_CEL_HANGUP, NULL, ast_str_buffer(extra_str));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (old_snapshot->state != new_snapshot->state && new_snapshot->state == AST_STATE_UP) {
|
|
|
|
report_event_snapshot(new_snapshot, AST_CEL_ANSWER, NULL, NULL);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void cel_channel_linkedid_change(
|
|
|
|
struct ast_channel_snapshot *old_snapshot,
|
|
|
|
struct ast_channel_snapshot *new_snapshot)
|
|
|
|
{
|
|
|
|
if (!old_snapshot || !new_snapshot) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (strcmp(old_snapshot->linkedid, new_snapshot->linkedid)) {
|
|
|
|
check_retire_linkedid(old_snapshot);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void cel_channel_app_change(
|
|
|
|
struct ast_channel_snapshot *old_snapshot,
|
|
|
|
struct ast_channel_snapshot *new_snapshot)
|
|
|
|
{
|
|
|
|
if (new_snapshot && old_snapshot
|
|
|
|
&& !strcmp(old_snapshot->appl, new_snapshot->appl)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* old snapshot has an application, end it */
|
|
|
|
if (old_snapshot && !ast_strlen_zero(old_snapshot->appl)) {
|
|
|
|
report_event_snapshot(old_snapshot, AST_CEL_APP_END, NULL, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* new snapshot has an application, start it */
|
|
|
|
if (new_snapshot && !ast_strlen_zero(new_snapshot->appl)) {
|
|
|
|
report_event_snapshot(new_snapshot, AST_CEL_APP_START, NULL, NULL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
cel_channel_snapshot_monitor cel_channel_monitors[] = {
|
|
|
|
cel_channel_state_change,
|
|
|
|
cel_channel_app_change,
|
|
|
|
cel_channel_linkedid_change,
|
|
|
|
};
|
|
|
|
|
|
|
|
static void cel_snapshot_update_cb(void *data, struct stasis_subscription *sub,
|
|
|
|
struct stasis_topic *topic,
|
|
|
|
struct stasis_message *message)
|
|
|
|
{
|
|
|
|
struct stasis_cache_update *update = stasis_message_data(message);
|
|
|
|
if (ast_channel_snapshot_type() == update->type) {
|
|
|
|
struct ast_channel_snapshot *old_snapshot;
|
|
|
|
struct ast_channel_snapshot *new_snapshot;
|
|
|
|
size_t i;
|
|
|
|
|
|
|
|
old_snapshot = stasis_message_data(update->old_snapshot);
|
|
|
|
new_snapshot = stasis_message_data(update->new_snapshot);
|
|
|
|
|
|
|
|
for (i = 0; i < ARRAY_LEN(cel_channel_monitors); ++i) {
|
|
|
|
cel_channel_monitors[i](old_snapshot, new_snapshot);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void cel_bridge_enter_cb(
|
|
|
|
void *data, struct stasis_subscription *sub,
|
|
|
|
struct stasis_topic *topic,
|
|
|
|
struct stasis_message *message)
|
|
|
|
{
|
|
|
|
struct ast_bridge_blob *blob = stasis_message_data(message);
|
|
|
|
struct ast_bridge_snapshot *snapshot = blob->bridge;
|
|
|
|
struct ast_channel_snapshot *chan_snapshot = blob->channel;
|
|
|
|
|
|
|
|
if (snapshot->capabilities & (AST_BRIDGE_CAPABILITY_1TO1MIX | AST_BRIDGE_CAPABILITY_NATIVE)) {
|
|
|
|
if (ao2_container_count(snapshot->channels) == 2) {
|
|
|
|
struct ao2_iterator i;
|
|
|
|
RAII_VAR(char *, channel_id, NULL, ao2_cleanup);
|
|
|
|
|
|
|
|
/* get the name of the channel in the container we don't already know the name of */
|
|
|
|
i = ao2_iterator_init(snapshot->channels, 0);
|
|
|
|
while ((channel_id = ao2_iterator_next(&i))) {
|
|
|
|
if (strcmp(channel_id, chan_snapshot->uniqueid)) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
ao2_cleanup(channel_id);
|
|
|
|
channel_id = NULL;
|
|
|
|
}
|
|
|
|
ao2_iterator_destroy(&i);
|
|
|
|
|
|
|
|
add_bridge_primary(channel_id, snapshot->uniqueid, chan_snapshot->uniqueid);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void cel_bridge_leave_cb(
|
|
|
|
void *data, struct stasis_subscription *sub,
|
|
|
|
struct stasis_topic *topic,
|
|
|
|
struct stasis_message *message)
|
|
|
|
{
|
|
|
|
struct ast_bridge_blob *blob = stasis_message_data(message);
|
|
|
|
struct ast_bridge_snapshot *snapshot = blob->bridge;
|
|
|
|
struct ast_channel_snapshot *chan_snapshot = blob->channel;
|
|
|
|
|
|
|
|
if ((snapshot->capabilities | AST_BRIDGE_CAPABILITY_1TO1MIX)
|
|
|
|
|| (snapshot->capabilities | AST_BRIDGE_CAPABILITY_NATIVE)) {
|
|
|
|
if (ao2_container_count(snapshot->channels) == 1) {
|
|
|
|
RAII_VAR(struct bridge_assoc *, ao2_primary, ao2_find(bridge_primaries, chan_snapshot->uniqueid, OBJ_KEY), ao2_cleanup);
|
|
|
|
RAII_VAR(char *, channel_id_in_bridge, NULL, ao2_cleanup);
|
|
|
|
const char *primary;
|
|
|
|
struct ao2_iterator i;
|
|
|
|
|
|
|
|
/* get the only item in the container */
|
|
|
|
i = ao2_iterator_init(snapshot->channels, 0);
|
|
|
|
while ((channel_id_in_bridge = ao2_iterator_next(&i))) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
ao2_iterator_destroy(&i);
|
|
|
|
|
|
|
|
if (ao2_primary) {
|
|
|
|
primary = chan_snapshot->uniqueid;
|
|
|
|
} else {
|
|
|
|
primary = channel_id_in_bridge;
|
|
|
|
}
|
|
|
|
|
|
|
|
remove_bridge_primary(primary);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void save_dialstatus(struct ast_multi_channel_blob *blob)
|
|
|
|
{
|
|
|
|
ao2_link(cel_dialstatus_store, blob);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void cel_dial_cb(void *data, struct stasis_subscription *sub,
|
|
|
|
struct stasis_topic *topic,
|
|
|
|
struct stasis_message *message)
|
2009-06-26 15:28:53 +00:00
|
|
|
{
|
2013-06-13 13:15:56 +00:00
|
|
|
struct ast_multi_channel_blob *blob = stasis_message_data(message);
|
|
|
|
|
|
|
|
if (!get_caller_uniqueid(blob)) {
|
|
|
|
return;
|
2009-06-26 15:28:53 +00:00
|
|
|
}
|
2013-06-13 13:15:56 +00:00
|
|
|
|
|
|
|
if (ast_strlen_zero(get_caller_dialstatus(blob))) {
|
|
|
|
return;
|
2012-10-02 01:47:16 +00:00
|
|
|
}
|
2013-06-13 13:15:56 +00:00
|
|
|
|
|
|
|
save_dialstatus(blob);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void ast_cel_engine_term(void)
|
|
|
|
{
|
|
|
|
stasis_message_router_unsubscribe_and_join(cel_state_router);
|
|
|
|
cel_state_router = NULL;
|
|
|
|
ao2_cleanup(cel_state_topic);
|
|
|
|
cel_state_topic = NULL;
|
|
|
|
cel_channel_forwarder = stasis_unsubscribe_and_join(cel_channel_forwarder);
|
|
|
|
cel_bridge_forwarder = stasis_unsubscribe_and_join(cel_bridge_forwarder);
|
|
|
|
ao2_cleanup(linkedids);
|
|
|
|
linkedids = NULL;
|
2012-12-11 22:03:23 +00:00
|
|
|
ast_cli_unregister(&cli_status);
|
2013-06-13 13:15:56 +00:00
|
|
|
ao2_cleanup(bridge_primaries);
|
|
|
|
bridge_primaries = NULL;
|
2009-06-26 15:28:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int ast_cel_engine_init(void)
|
|
|
|
{
|
2013-06-13 13:15:56 +00:00
|
|
|
int ret = 0;
|
|
|
|
if (!(linkedids = ast_str_container_alloc(NUM_APP_BUCKETS))) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!(cel_dialstatus_store = ao2_container_alloc(NUM_DIALSTATUS_BUCKETS, dialstatus_hash, dialstatus_cmp))) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (aco_info_init(&cel_cfg_info)) {
|
2009-06-26 15:28:53 +00:00
|
|
|
return -1;
|
|
|
|
}
|
2013-06-13 13:15:56 +00:00
|
|
|
|
|
|
|
aco_option_register(&cel_cfg_info, "enable", ACO_EXACT, general_options, "no", OPT_BOOL_T, 1, FLDSET(struct cel_general_config, enable));
|
|
|
|
aco_option_register(&cel_cfg_info, "dateformat", ACO_EXACT, general_options, "", OPT_STRINGFIELD_T, 0, STRFLDSET(struct cel_general_config, date_format));
|
|
|
|
aco_option_register_custom(&cel_cfg_info, "apps", ACO_EXACT, general_options, "", apps_handler, 0);
|
|
|
|
aco_option_register_custom(&cel_cfg_info, "events", ACO_EXACT, general_options, "", events_handler, 0);
|
|
|
|
|
|
|
|
if (aco_process_config(&cel_cfg_info, 0)) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ast_cli_register(&cli_status)) {
|
2009-06-26 15:28:53 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2013-06-13 13:15:56 +00:00
|
|
|
cel_state_topic = stasis_topic_create("cel_state_topic");
|
|
|
|
if (!cel_state_topic) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
cel_channel_forwarder = stasis_forward_all(
|
|
|
|
stasis_caching_get_topic(ast_channel_topic_all_cached()),
|
|
|
|
cel_state_topic);
|
|
|
|
if (!cel_channel_forwarder) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
cel_bridge_forwarder = stasis_forward_all(
|
|
|
|
stasis_caching_get_topic(ast_bridge_topic_all_cached()),
|
|
|
|
cel_state_topic);
|
|
|
|
if (!cel_bridge_forwarder) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
cel_state_router = stasis_message_router_create(cel_state_topic);
|
|
|
|
if (!cel_state_router) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret |= stasis_message_router_add(cel_state_router,
|
|
|
|
stasis_cache_update_type(),
|
|
|
|
cel_snapshot_update_cb,
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
ret |= stasis_message_router_add(cel_state_router,
|
|
|
|
ast_channel_dial_type(),
|
|
|
|
cel_dial_cb,
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
/* If somehow we failed to add any routes, just shut down the whole
|
|
|
|
* thing and fail it.
|
|
|
|
*/
|
|
|
|
if (ret) {
|
|
|
|
ast_cel_engine_term();
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
bridge_primaries = ao2_container_alloc(BRIDGE_PRIMARY_BUCKETS, bridge_assoc_hash, bridge_assoc_cmp);
|
|
|
|
if (!bridge_primaries) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret |= stasis_message_router_add(cel_state_router,
|
|
|
|
ast_channel_entered_bridge_type(),
|
|
|
|
cel_bridge_enter_cb,
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
ret |= stasis_message_router_add(cel_state_router,
|
|
|
|
ast_channel_left_bridge_type(),
|
|
|
|
cel_bridge_leave_cb,
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
/* If somehow we failed to add any routes, just shut down the whole
|
|
|
|
* thing and fail it.
|
|
|
|
*/
|
|
|
|
if (ret) {
|
|
|
|
ast_cel_engine_term();
|
2009-06-26 15:28:53 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
ast_register_atexit(ast_cel_engine_term);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int ast_cel_engine_reload(void)
|
|
|
|
{
|
|
|
|
return do_reload();
|
|
|
|
}
|
|
|
|
|