[asterisk-commits] kmoore: branch kmoore/bridge_construction-cel_bridging r389329 - in /team/kmo...
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Mon May 20 16:08:52 CDT 2013
Author: kmoore
Date: Mon May 20 16:08:49 2013
New Revision: 389329
URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=389329
Log:
Multiple revisions 389315,389327
........
r389315 | root | 2013-05-20 15:18:48 -0500 (Mon, 20 May 2013) | 13 lines
Set the AST_CDR_FLAG_ORIGINATED flag on originated channel's CDRs
This may alleviate some of the CDR woes with originated channels, as CDRs
do like to know when a channel was originated. Eventually this will get
converted to be a channel flag, so its location is still good to know
post the great CDR shakeup of 2013.
........
Merged revisions 389306 from file:///srv/subversion/repos/asterisk/trunk
........
Merged revisions 389310 from file:///srv/subversion/repos/asterisk/team/group/bridge_construction
........
r389327 | kmoore | 2013-05-20 15:47:36 -0500 (Mon, 20 May 2013) | 5 lines
Refactor to avoid ast_bridged_channel
This also includes a function (ast_channel_snapshot_get_latest) swiped
from dlee.
........
Merged revisions 389315,389327 from http://svn.asterisk.org/svn/asterisk/team/kmoore/bridge_construction-cel_channels
Modified:
team/kmoore/bridge_construction-cel_bridging/ (props changed)
team/kmoore/bridge_construction-cel_bridging/include/asterisk/stasis_channels.h
team/kmoore/bridge_construction-cel_bridging/main/cel.c
team/kmoore/bridge_construction-cel_bridging/main/pbx.c
team/kmoore/bridge_construction-cel_bridging/main/stasis_channels.c
Propchange: team/kmoore/bridge_construction-cel_bridging/
------------------------------------------------------------------------------
--- bc-cel_bridging-integrated (original)
+++ bc-cel_bridging-integrated Mon May 20 16:08:49 2013
@@ -1,1 +1,1 @@
-/team/kmoore/bridge_construction-cel_channels:1-389306
+/team/kmoore/bridge_construction-cel_channels:1-389327
Propchange: team/kmoore/bridge_construction-cel_bridging/
------------------------------------------------------------------------------
--- bridge_construction-integrated (original)
+++ bridge_construction-integrated Mon May 20 16:08:49 2013
@@ -1,1 +1,1 @@
-/trunk:1-389280
+/trunk:1-389309
Modified: team/kmoore/bridge_construction-cel_bridging/include/asterisk/stasis_channels.h
URL: http://svnview.digium.com/svn/asterisk/team/kmoore/bridge_construction-cel_bridging/include/asterisk/stasis_channels.h?view=diff&rev=389329&r1=389328&r2=389329
==============================================================================
--- team/kmoore/bridge_construction-cel_bridging/include/asterisk/stasis_channels.h (original)
+++ team/kmoore/bridge_construction-cel_bridging/include/asterisk/stasis_channels.h Mon May 20 16:08:49 2013
@@ -50,8 +50,6 @@
AST_STRING_FIELD(data); /*!< Data passed to current application */
AST_STRING_FIELD(context); /*!< Dialplan: Current extension context */
AST_STRING_FIELD(exten); /*!< Dialplan: Current extension number */
- AST_STRING_FIELD(bridged_name); /*!< The name of the channel bridged to this one */
- AST_STRING_FIELD(bridged_id); /*!< The uniqueid of the channel bridged to this one */
AST_STRING_FIELD(caller_name); /*!< Caller ID Name */
AST_STRING_FIELD(caller_number); /*!< Caller ID Number */
AST_STRING_FIELD(caller_ani); /*!< Caller ID ANI Number */
@@ -129,6 +127,18 @@
/*!
* \since 12
+ * \since 12
+ * \brief Get the most recent snapshot for channel with the given \a uniqueid.
+ *
+ * \param uniqueid Uniqueid of the snapshot to fetch.
+ * \return Most recent channel snapshot
+ * \return \c NULL on error
+ */
+struct ast_channel_snapshot *ast_channel_snapshot_get_latest(
+ const char *uniqueid);
+
+/*!
+ * \since 12
* \brief Creates a \ref ast_channel_blob message.
*
* The given \a blob should be treated as immutable and not modified after it is
Modified: team/kmoore/bridge_construction-cel_bridging/main/cel.c
URL: http://svnview.digium.com/svn/asterisk/team/kmoore/bridge_construction-cel_bridging/main/cel.c?view=diff&rev=389329&r1=389328&r2=389329
==============================================================================
--- team/kmoore/bridge_construction-cel_bridging/main/cel.c (original)
+++ team/kmoore/bridge_construction-cel_bridging/main/cel.c Mon May 20 16:08:49 2013
@@ -72,7 +72,7 @@
/*! Subscription for forwarding the channel caching topic */
static struct stasis_subscription *cel_bridge_forwarder;
-/*! Container for primary channel listing for 2 party bridges */
+/*! 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 */
@@ -162,6 +162,75 @@
[AST_CEL_LINKEDID_END] = "LINKEDID_END",
};
+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);
+}
+
+/*! \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");
@@ -435,19 +504,29 @@
struct timeval eventtime;
struct ast_event *ev;
char *linkedid = ast_strdupa(snapshot->linkedid);
- const char *peer_name = snapshot->bridged_name;
+ char *peer_name = "";
+ RAII_VAR(struct bridge_assoc *, assoc, NULL, ao2_cleanup);
+
+ if (!cel_enabled) {
+ return 0;
+ }
+
+ 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);
+ }
+ }
if (ast_strlen_zero(peer_name) && peer2_id) {
- RAII_VAR(struct ast_channel_snapshot *, peer2_snapshot, NULL /* XXX ast_channel_snapshot_get_latest(peer2_id)*/, ao2_cleanup);
+ RAII_VAR(struct ast_channel_snapshot *, peer2_snapshot, ast_channel_snapshot_get_latest(peer2_id), ao2_cleanup);
if (!peer2_snapshot) {
return -1;
}
peer_name = ast_strdupa(peer2_snapshot->name);
- }
-
- if (!cel_enabled) {
- return 0;
}
/* Make sure a reload is not occurring while we're checking to see if this
@@ -519,7 +598,7 @@
enum ast_cel_event_type event_type, const char *userdefevname,
const char *extra, const char *peer2_id)
{
- RAII_VAR(struct ast_channel_snapshot *, snapshot, NULL /* XXX ast_channel_snapshot_get_latest(channel_id)*/, ao2_cleanup);
+ RAII_VAR(struct ast_channel_snapshot *, snapshot, ast_channel_snapshot_get_latest(channel_id), ao2_cleanup);
if (!snapshot) {
return -1;
}
@@ -1037,7 +1116,7 @@
}
ao2_iterator_destroy(&i);
- ast_str_container_add(bridge_primaries, channel_id);
+ add_bridge_primary(channel_id, snapshot->uniqueid, chan_snapshot->uniqueid);
report_event_id(channel_id, AST_CEL_BRIDGE_START, NULL, NULL, chan_snapshot->uniqueid);
}
} else if (snapshot->capabilities | AST_BRIDGE_CAPABILITY_MULTIMIX) {
@@ -1059,9 +1138,9 @@
if ((snapshot->capabilities | AST_BRIDGE_CAPABILITY_1TO1MIX)
|| (snapshot->capabilities | AST_BRIDGE_CAPABILITY_NATIVE)) {
if (ao2_container_count(snapshot->channels) == 1) {
- RAII_VAR(char *, ao2_primary, ao2_find(bridge_primaries, chan_snapshot->uniqueid, OBJ_KEY), ao2_cleanup);
+ 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);
- char *primary, *secondary;
+ const char *primary, *secondary;
struct ao2_iterator i;
/* get the only item in the container */
@@ -1072,15 +1151,14 @@
ao2_iterator_destroy(&i);
if (ao2_primary) {
- primary = ao2_primary;
+ primary = chan_snapshot->uniqueid;
secondary = channel_id_in_bridge;
} else {
primary = channel_id_in_bridge;
- secondary = ao2_primary;
+ secondary = chan_snapshot->uniqueid;
}
- ast_str_container_remove(bridge_primaries, primary);
-
+ remove_bridge_primary(primary);
report_event_id(primary, AST_CEL_BRIDGE_END, NULL, NULL, secondary);
}
/* AST_CEL_BRIDGE_END when all parties have left */
@@ -1193,7 +1271,7 @@
return -1;
}
- bridge_primaries = ast_str_container_alloc(BRIDGE_PRIMARY_BUCKETS);
+ bridge_primaries = ao2_container_alloc(BRIDGE_PRIMARY_BUCKETS, bridge_assoc_hash, bridge_assoc_cmp);
if (!bridge_primaries) {
return -1;
}
Modified: team/kmoore/bridge_construction-cel_bridging/main/pbx.c
URL: http://svnview.digium.com/svn/asterisk/team/kmoore/bridge_construction-cel_bridging/main/pbx.c?view=diff&rev=389329&r1=389328&r2=389329
==============================================================================
--- team/kmoore/bridge_construction-cel_bridging/main/pbx.c (original)
+++ team/kmoore/bridge_construction-cel_bridging/main/pbx.c Mon May 20 16:08:49 2013
@@ -10085,6 +10085,7 @@
if (account) {
ast_cdr_setaccount(dialed, account);
}
+ ast_set_flag(ast_channel_cdr(dialed), AST_CDR_FLAG_ORIGINATED);
if (!ast_strlen_zero(cid_num) && !ast_strlen_zero(cid_name)) {
struct ast_party_connected_line connected;
Modified: team/kmoore/bridge_construction-cel_bridging/main/stasis_channels.c
URL: http://svnview.digium.com/svn/asterisk/team/kmoore/bridge_construction-cel_bridging/main/stasis_channels.c?view=diff&rev=389329&r1=389328&r2=389329
==============================================================================
--- team/kmoore/bridge_construction-cel_bridging/main/stasis_channels.c (original)
+++ team/kmoore/bridge_construction-cel_bridging/main/stasis_channels.c Mon May 20 16:08:49 2013
@@ -103,7 +103,6 @@
struct ast_channel_snapshot *ast_channel_snapshot_create(struct ast_channel *chan)
{
RAII_VAR(struct ast_channel_snapshot *, snapshot, NULL, ao2_cleanup);
- struct ast_channel *bridged;
snapshot = ao2_alloc(sizeof(*snapshot), channel_snapshot_dtor);
if (!snapshot || ast_string_field_init(snapshot, 1024)) {
@@ -127,17 +126,6 @@
ast_string_field_set(snapshot, context, ast_channel_context(chan));
ast_string_field_set(snapshot, exten, ast_channel_exten(chan));
- bridged = ast_bridged_channel(chan);
- if (bridged) {
- ast_channel_ref(bridged);
- ast_channel_lock(bridged);
- ast_string_field_set(snapshot, bridged_name, ast_channel_name(bridged));
- ast_string_field_set(snapshot, bridged_id, ast_channel_uniqueid(bridged));
- ast_channel_unlock(bridged);
- ast_channel_unref(bridged);
- bridged = NULL;
- }
-
ast_string_field_set(snapshot, caller_name,
S_COR(ast_channel_caller(chan)->id.name.valid, ast_channel_caller(chan)->id.name.str, ""));
ast_string_field_set(snapshot, caller_number,
@@ -164,6 +152,28 @@
snapshot->caller_pres = ast_party_id_presentation(&ast_channel_caller(chan)->id);
snapshot->manager_vars = ast_channel_get_manager_vars(chan);
+
+ ao2_ref(snapshot, +1);
+ return snapshot;
+}
+
+struct ast_channel_snapshot *ast_channel_snapshot_get_latest(
+ const char *uniqueid)
+{
+ RAII_VAR(struct stasis_message *, msg, NULL, ao2_cleanup);
+ struct ast_channel_snapshot *snapshot;
+
+ msg = stasis_cache_get(ast_channel_topic_all_cached(),
+ ast_channel_snapshot_type(), uniqueid);
+
+ if (!msg) {
+ return NULL;
+ }
+
+ snapshot = stasis_message_data(msg);
+ if (!snapshot) {
+ return NULL;
+ }
ao2_ref(snapshot, +1);
return snapshot;
More information about the asterisk-commits
mailing list