[asterisk-commits] kmoore: branch kmoore/stasis-cel_bridging r389040 - in /team/kmoore/stasis-ce...
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Fri May 17 21:46:46 CDT 2013
Author: kmoore
Date: Fri May 17 21:46:42 2013
New Revision: 389040
URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=389040
Log:
Bring in CEL channel refactoring
Modified:
team/kmoore/stasis-cel_bridging/include/asterisk/stasis_channels.h
team/kmoore/stasis-cel_bridging/include/asterisk/strings.h
team/kmoore/stasis-cel_bridging/main/cel.c
team/kmoore/stasis-cel_bridging/main/stasis_channels.c
Modified: team/kmoore/stasis-cel_bridging/include/asterisk/stasis_channels.h
URL: http://svnview.digium.com/svn/asterisk/team/kmoore/stasis-cel_bridging/include/asterisk/stasis_channels.h?view=diff&rev=389040&r1=389039&r2=389040
==============================================================================
--- team/kmoore/stasis-cel_bridging/include/asterisk/stasis_channels.h (original)
+++ team/kmoore/stasis-cel_bridging/include/asterisk/stasis_channels.h Fri May 17 21:46:42 2013
@@ -59,11 +59,6 @@
AST_STRING_FIELD(caller_dnid); /*!< Caller ID DNID Number */
AST_STRING_FIELD(connected_name); /*!< Connected Line Name */
AST_STRING_FIELD(connected_number); /*!< Connected Line Number */
- /*!
- * The value of the DIALSTATUS channel variable.
- * This is necessary to keep separately from manager_vars for CEL purposes.
- */
- AST_STRING_FIELD(dialstatus);
);
struct timeval creationtime; /*!< The time of channel creation */
Modified: team/kmoore/stasis-cel_bridging/include/asterisk/strings.h
URL: http://svnview.digium.com/svn/asterisk/team/kmoore/stasis-cel_bridging/include/asterisk/strings.h?view=diff&rev=389040&r1=389039&r2=389040
==============================================================================
--- team/kmoore/stasis-cel_bridging/include/asterisk/strings.h (original)
+++ team/kmoore/stasis-cel_bridging/include/asterisk/strings.h Fri May 17 21:46:42 2013
@@ -1069,4 +1069,46 @@
}
+/*!
+ * \brief Convert a string to all lower-case
+ *
+ * \param str The string to be converted to lower case
+ *
+ * \retval str for convenience
+ */
+static force_inline char *attribute_pure ast_str_to_lower(char *str)
+{
+ char *str_orig = str;
+ if (!str) {
+ return str;
+ }
+
+ for (; *str; ++str) {
+ *str = tolower(*str);
+ }
+
+ return str_orig;
+}
+
+/*!
+ * \brief Convert a string to all upper-case
+ *
+ * \param str The string to be converted to upper case
+ *
+ * \retval str for convenience
+ */
+static force_inline char *attribute_pure ast_str_to_upper(char *str)
+{
+ char *str_orig = str;
+ if (!str) {
+ return str;
+ }
+
+ for (; *str; ++str) {
+ *str = toupper(*str);
+ }
+
+ return str_orig;
+}
+
#endif /* _ASTERISK_STRINGS_H */
Modified: team/kmoore/stasis-cel_bridging/main/cel.c
URL: http://svnview.digium.com/svn/asterisk/team/kmoore/stasis-cel_bridging/main/cel.c?view=diff&rev=389040&r1=389039&r2=389040
==============================================================================
--- team/kmoore/stasis-cel_bridging/main/cel.c (original)
+++ team/kmoore/stasis-cel_bridging/main/cel.c Fri May 17 21:46:42 2013
@@ -78,6 +78,9 @@
/*! 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;
+
/*! Is the CEL subsystem enabled ? */
static unsigned char cel_enabled;
@@ -106,6 +109,11 @@
* \brief Number of buckets for the appset container
*/
#define NUM_APP_BUCKETS 97
+
+/*!
+ * \brief Number of buckets for the dialstatus container
+ */
+#define NUM_DIALSTATUS_BUCKETS 251
/*!
* \brief Container of Asterisk application names
@@ -154,6 +162,40 @@
[AST_CEL_LINKEDID_END] = "LINKEDID_END",
};
+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;
+}
+
/*!
* \brief Map of ast_cel_ama_flags to strings
*/
@@ -302,21 +344,13 @@
}
while ((cur_app = strsep(&apps, ","))) {
- char *app;
-
cur_app = ast_strip(cur_app);
if (ast_strlen_zero(cur_app)) {
continue;
}
- if (!(app = ao2_alloc(strlen(cur_app) + 1, NULL))) {
- continue;
- }
- strcpy(app, cur_app);
-
- ao2_link(appset, app);
- ao2_ref(app, -1);
- app = NULL;
+ cur_app = ast_str_to_lower(cur_app);
+ ast_str_container_add(appset, cur_app);
}
}
@@ -436,12 +470,12 @@
}
if (event_type == AST_CEL_APP_START || event_type == AST_CEL_APP_END) {
- char *app;
- if (!(app = ao2_find(appset, (char *) snapshot->appl, OBJ_POINTER))) {
+ RAII_VAR(char *, app, NULL, ao2_cleanup);
+ char *app_lower = ast_str_to_lower(ast_strdupa(snapshot->appl));
+ if (!(app = ao2_find(appset, app_lower, OBJ_POINTER))) {
ast_mutex_unlock(&reload_lock);
return 0;
}
- ao2_ref(app, -1);
}
ast_mutex_unlock(&reload_lock);
@@ -512,7 +546,7 @@
/* 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) {
- ao2_unlink(linkedids, lid);
+ ast_str_container_remove(linkedids, lid);
report_event_snapshot(snapshot, AST_CEL_LINKEDID_END, NULL, NULL, NULL);
}
ao2_ref(lid, -1);
@@ -697,12 +731,12 @@
}
if (event_type == AST_CEL_APP_START || event_type == AST_CEL_APP_END) {
- char *app;
- if (!(app = ao2_find(appset, (char *) ast_channel_appl(chan), OBJ_POINTER))) {
+ RAII_VAR(char *, app, NULL, ao2_cleanup);
+ char *app_lower = ast_str_to_lower(ast_strdupa(ast_channel_appl(chan)));
+ if (!(app = ao2_find(appset, app_lower, OBJ_POINTER))) {
ast_mutex_unlock(&reload_lock);
return 0;
}
- ao2_ref(app, -1);
}
ast_mutex_unlock(&reload_lock);
@@ -823,26 +857,31 @@
return 0;
}
-static int app_hash(const void *obj, const int flags)
-{
- return ast_str_case_hash((const char *) obj);
-}
-
-static int app_cmp(void *obj, void *arg, int flags)
-{
- const char *app1 = obj, *app2 = arg;
-
- return !strcasecmp(app1, app2) ? CMP_MATCH | CMP_STOP : 0;
-}
-
-#define lid_hash app_hash
-#define lid_cmp app_cmp
-
/*! \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)
+{
+ return ao2_find(cel_dialstatus_store, uniqueid, OBJ_KEY | OBJ_UNLINK);
+}
+
+static const char *get_caller_dialstatus(struct ast_multi_channel_blob *blob)
+{
+ struct ast_json *json = ast_multi_channel_blob_get_json(blob);
+ if (!json) {
+ return NULL;
+ }
+
+ json = ast_json_object_get(json, "dialstatus");
+ if (!json) {
+ return NULL;
+ }
+
+ return ast_json_string_get(json);
+}
+
/*! \brief Handle channel state changes */
static void cel_channel_state_change(
struct ast_channel_snapshot *old_snapshot,
@@ -866,7 +905,15 @@
if (!was_hungup && is_hungup) {
RAII_VAR(struct ast_str *, extra_str, ast_str_create(128), ast_free);
- ast_str_set(&extra_str, 0, "%d,%s,%s", new_snapshot->hangupcause, new_snapshot->hangupsource, new_snapshot->dialstatus);
+ RAII_VAR(struct ast_multi_channel_blob *, blob, get_dialstatus_blob(new_snapshot->uniqueid), ao2_cleanup);
+ const char *dialstatus = "";
+ if (blob && 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), NULL);
return;
}
@@ -926,8 +973,8 @@
}
static void cel_snapshot_update_cb(void *data, struct stasis_subscription *sub,
- struct stasis_topic *topic,
- struct stasis_message *message)
+ struct stasis_topic *topic,
+ struct stasis_message *message)
{
struct stasis_cache_update *update = stasis_message_data(message);
if (update->type == ast_channel_snapshot_type()) {
@@ -1044,6 +1091,28 @@
}
}
+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)
+{
+ struct ast_multi_channel_blob *blob = stasis_message_data(message);
+
+ if (!get_caller_uniqueid(blob)) {
+ return;
+ }
+
+ if (!get_caller_dialstatus(blob)) {
+ return;
+ }
+
+ save_dialstatus(blob);
+}
+
static void ast_cel_engine_term(void)
{
stasis_message_router_unsubscribe(cel_state_router);
@@ -1052,14 +1121,10 @@
cel_state_topic = NULL;
cel_channel_forwarder = stasis_unsubscribe(cel_channel_forwarder);
cel_bridge_forwarder = stasis_unsubscribe(cel_bridge_forwarder);
- if (appset) {
- ao2_ref(appset, -1);
- appset = NULL;
- }
- if (linkedids) {
- ao2_ref(linkedids, -1);
- linkedids = NULL;
- }
+ ao2_cleanup(appset);
+ appset = NULL;
+ ao2_cleanup(linkedids);
+ linkedids = NULL;
ast_cli_unregister(&cli_status);
stasis_message_router_unsubscribe(cel_state_router);
cel_state_router = NULL;
@@ -1070,19 +1135,20 @@
int ast_cel_engine_init(void)
{
int ret = 0;
- if (!(appset = ao2_container_alloc(NUM_APP_BUCKETS, app_hash, app_cmp))) {
- return -1;
- }
- if (!(linkedids = ao2_container_alloc(NUM_APP_BUCKETS, lid_hash, lid_cmp))) {
- ao2_ref(appset, -1);
- return -1;
- }
+ if (!(appset = ast_str_container_alloc(NUM_APP_BUCKETS))) {
+ return -1;
+ }
+
+ 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 (do_reload() || ast_cli_register(&cli_status)) {
- ao2_ref(appset, -1);
- appset = NULL;
- ao2_ref(linkedids, -1);
- linkedids = NULL;
return -1;
}
@@ -1113,6 +1179,11 @@
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
Modified: team/kmoore/stasis-cel_bridging/main/stasis_channels.c
URL: http://svnview.digium.com/svn/asterisk/team/kmoore/stasis-cel_bridging/main/stasis_channels.c?view=diff&rev=389040&r1=389039&r2=389040
==============================================================================
--- team/kmoore/stasis-cel_bridging/main/stasis_channels.c (original)
+++ team/kmoore/stasis-cel_bridging/main/stasis_channels.c Fri May 17 21:46:42 2013
@@ -163,8 +163,6 @@
snapshot->flags = *ast_channel_flags(chan);
snapshot->caller_pres = ast_party_id_presentation(&ast_channel_caller(chan)->id);
- ast_string_field_set(snapshot, dialstatus,
- S_OR(pbx_builtin_getvar_helper(chan, "DIALSTATUS"), ""));
snapshot->manager_vars = ast_channel_get_manager_vars(chan);
ao2_ref(snapshot, +1);
More information about the asterisk-commits
mailing list