[asterisk-commits] kmoore: branch kmoore/stasis-bridging-channel_events r385301 - in /team/kmoor...

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


Author: kmoore
Date: Thu Apr 11 08:42:16 2013
New Revision: 385301

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

Modified:
    team/kmoore/stasis-bridging-channel_events/apps/app_stasis.c
    team/kmoore/stasis-bridging-channel_events/include/asterisk/strings.h
    team/kmoore/stasis-bridging-channel_events/main/strings.c
    team/kmoore/stasis-bridging-channel_events/res/res_stasis_websocket.c

Modified: team/kmoore/stasis-bridging-channel_events/apps/app_stasis.c
URL: http://svnview.digium.com/svn/asterisk/team/kmoore/stasis-bridging-channel_events/apps/app_stasis.c?view=diff&rev=385301&r1=385300&r2=385301
==============================================================================
--- team/kmoore/stasis-bridging-channel_events/apps/app_stasis.c (original)
+++ team/kmoore/stasis-bridging-channel_events/apps/app_stasis.c Thu Apr 11 08:42:16 2013
@@ -183,21 +183,14 @@
 
 static int app_add_channel(struct app* app, const struct ast_channel *chan)
 {
-	RAII_VAR(char *, ao2_channel_id, NULL, ao2_cleanup);
 	const char *uniqueid;
 	ast_assert(chan != NULL);
 	ast_assert(app != NULL);
 
 	uniqueid = 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);
 	return 0;
 }
 

Modified: team/kmoore/stasis-bridging-channel_events/include/asterisk/strings.h
URL: http://svnview.digium.com/svn/asterisk/team/kmoore/stasis-bridging-channel_events/include/asterisk/strings.h?view=diff&rev=385301&r1=385300&r2=385301
==============================================================================
--- team/kmoore/stasis-bridging-channel_events/include/asterisk/strings.h (original)
+++ team/kmoore/stasis-bridging-channel_events/include/asterisk/strings.h Thu Apr 11 08:42:16 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-bridging-channel_events/main/strings.c
URL: http://svnview.digium.com/svn/asterisk/team/kmoore/stasis-bridging-channel_events/main/strings.c?view=diff&rev=385301&r1=385300&r2=385301
==============================================================================
--- team/kmoore/stasis-bridging-channel_events/main/strings.c (original)
+++ team/kmoore/stasis-bridging-channel_events/main/strings.c Thu Apr 11 08:42:16 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-bridging-channel_events/res/res_stasis_websocket.c
URL: http://svnview.digium.com/svn/asterisk/team/kmoore/stasis-bridging-channel_events/res/res_stasis_websocket.c?view=diff&rev=385301&r1=385300&r2=385301
==============================================================================
--- team/kmoore/stasis-bridging-channel_events/res/res_stasis_websocket.c (original)
+++ team/kmoore/stasis-bridging-channel_events/res/res_stasis_websocket.c Thu Apr 11 08:42:16 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