[asterisk-commits] kmoore: branch kmoore/stasis-bridge_events r385302 - in /team/kmoore/stasis-b...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Thu Apr 11 08:51:35 CDT 2013


Author: kmoore
Date: Thu Apr 11 08:51:34 2013
New Revision: 385302

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=385302
Log:
Introduce helper function for string containers and simplify existing code
........

Merged revisions 385301 from http://svn.asterisk.org/svn/asterisk/team/kmoore/stasis-bridging-channel_events

Modified:
    team/kmoore/stasis-bridge_events/   (props changed)
    team/kmoore/stasis-bridge_events/apps/app_stasis.c
    team/kmoore/stasis-bridge_events/include/asterisk/strings.h
    team/kmoore/stasis-bridge_events/main/stasis_bridging.c
    team/kmoore/stasis-bridge_events/main/strings.c
    team/kmoore/stasis-bridge_events/res/res_stasis_websocket.c

Propchange: team/kmoore/stasis-bridge_events/
------------------------------------------------------------------------------
--- svnmerge-integrated (original)
+++ svnmerge-integrated Thu Apr 11 08:51:34 2013
@@ -1,1 +1,1 @@
-/team/kmoore/stasis-bridging-channel_events:1-385265
+/team/kmoore/stasis-bridging-channel_events:1-385301

Modified: team/kmoore/stasis-bridge_events/apps/app_stasis.c
URL: http://svnview.digium.com/svn/asterisk/team/kmoore/stasis-bridge_events/apps/app_stasis.c?view=diff&rev=385302&r1=385301&r2=385302
==============================================================================
--- team/kmoore/stasis-bridge_events/apps/app_stasis.c (original)
+++ team/kmoore/stasis-bridge_events/apps/app_stasis.c Thu Apr 11 08:51:34 2013
@@ -283,22 +283,15 @@
 
 static int app_add_channel(struct app* app, const struct ast_channel *chan)
 {
-	RAII_VAR(char *, ao2_channel_id, NULL, ao2_cleanup);
 	RAII_VAR(char *, ao2_bridge_id, NULL, ao2_cleanup);
 	char *uniqueid;
 	ast_assert(chan != NULL);
 	ast_assert(app != NULL);
 
 	uniqueid = ast_strdupa(ast_channel_uniqueid(chan));
-
-	ao2_channel_id = ao2_alloc(strlen(uniqueid) + 1, NULL);
-	if (!ao2_channel_id) {
+	if (!ast_str_container_add(app->channels, uniqueid)) {
 		return -1;
 	}
-
-	/* safe strcpy */
-	strcpy(ao2_channel_id, uniqueid);
-	ao2_link(app->channels, ao2_channel_id);
 
 	add_bridge_for_chan(uniqueid);
 	return 0;

Modified: team/kmoore/stasis-bridge_events/include/asterisk/strings.h
URL: http://svnview.digium.com/svn/asterisk/team/kmoore/stasis-bridge_events/include/asterisk/strings.h?view=diff&rev=385302&r1=385301&r2=385302
==============================================================================
--- team/kmoore/stasis-bridge_events/include/asterisk/strings.h (original)
+++ team/kmoore/stasis-bridge_events/include/asterisk/strings.h Thu Apr 11 08:51:34 2013
@@ -1016,9 +1016,23 @@
 /*!
  * \since 12
  * \brief Allocates a hash container for bare strings
+ *
+ * \param buckets The number of buckets to use for the hash container
+ *
  * \retval AO2 container for strings
  * \retval NULL if allocation failed
  */
 struct ao2_container *ast_str_container_alloc(int buckets);
 
+/*!
+ * \since 12
+ * \brief Adds a string to a string container allocated by ast_str_container_alloc
+ *
+ * \param str_container The container to which to add a string
+ * \param add The string to add to the container
+ *
+ * \retval zero on success
+ * \retval non-zero if the operation failed
+ */
+int ast_str_container_add(struct ao2_container *str_container, const char *add);
 #endif /* _ASTERISK_STRINGS_H */

Modified: team/kmoore/stasis-bridge_events/main/stasis_bridging.c
URL: http://svnview.digium.com/svn/asterisk/team/kmoore/stasis-bridge_events/main/stasis_bridging.c?view=diff&rev=385302&r1=385301&r2=385302
==============================================================================
--- team/kmoore/stasis-bridge_events/main/stasis_bridging.c (original)
+++ team/kmoore/stasis-bridge_events/main/stasis_bridging.c Thu Apr 11 08:51:34 2013
@@ -75,17 +75,10 @@
 	}
 
 	AST_LIST_TRAVERSE(&bridge->channels, bridge_channel, entry) {
-		RAII_VAR(char *, ao2_uniqueid, NULL, ao2_cleanup);
-		const char *chan_uniqueid = ast_channel_uniqueid(bridge_channel->chan);
-
-		ao2_uniqueid = ao2_alloc(strlen(chan_uniqueid) + 1, NULL);
-		if (!ao2_uniqueid) {
+		if (ast_str_container_add(snapshot->channels,
+				ast_channel_uniqueid(bridge_channel->chan))) {
 			return NULL;
 		}
-
-		/* safe strcpy */
-		strcpy(ao2_uniqueid, chan_uniqueid);
-		ao2_link(snapshot->channels, ao2_uniqueid);
 	}
 
 	ast_string_field_set(snapshot, uniqueid, bridge->uniqueid);

Modified: team/kmoore/stasis-bridge_events/main/strings.c
URL: http://svnview.digium.com/svn/asterisk/team/kmoore/stasis-bridge_events/main/strings.c?view=diff&rev=385302&r1=385301&r2=385302
==============================================================================
--- team/kmoore/stasis-bridge_events/main/strings.c (original)
+++ team/kmoore/stasis-bridge_events/main/strings.c Thu Apr 11 08:51:34 2013
@@ -174,3 +174,16 @@
 {
 	return ao2_container_alloc(buckets, str_hash, str_cmp);
 }
+
+int ast_str_container_add(struct ao2_container *str_container, const char *add)
+{
+	RAII_VAR(char *, ao2_add, ao2_alloc(strlen(add) + 1, NULL), ao2_cleanup);
+
+	if (!ao2_add) {
+		return -1;
+	}
+
+	/* safe strcpy */
+	strcpy(ao2_add, add);
+	return ao2_link(str_container, ao2_add);
+}

Modified: team/kmoore/stasis-bridge_events/res/res_stasis_websocket.c
URL: http://svnview.digium.com/svn/asterisk/team/kmoore/stasis-bridge_events/res/res_stasis_websocket.c?view=diff&rev=385302&r1=385301&r2=385302
==============================================================================
--- team/kmoore/stasis-bridge_events/res/res_stasis_websocket.c (original)
+++ team/kmoore/stasis-bridge_events/res/res_stasis_websocket.c Thu Apr 11 08:51:34 2013
@@ -177,17 +177,10 @@
 		return -1;
 	}
 	while ((app_name = strsep(&apps, ","))) {
-		RAII_VAR(char *, app, NULL, ao2_cleanup);
-
-		app = ao2_alloc(strlen(app_name) + 1, NULL);
-		if (!app) {
+		if (ast_str_container_add(session->websocket_apps, app_name)) {
 			websocket_write_json(session->ws_session, oom_json);
 			return -1;
 		}
-
-		/* safe strcpy */
-		strcpy(app, app_name);
-		ao2_link(session->websocket_apps, app);
 
 		stasis_app_register(app_name, app_handler, session);
 	}




More information about the asterisk-commits mailing list