[asterisk-commits] dlee: branch dlee/stasis-res r385123 - in /team/dlee/stasis-res: ./ res/

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Tue Apr 9 14:06:34 CDT 2013


Author: dlee
Date: Tue Apr  9 14:06:31 2013
New Revision: 385123

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=385123
Log:
Backported app_stasis fix from stasis-http branch.

The hash and compare functions for the control container was reusing
the wrong ones, causing some problems. I fixed it, but in the wrong
branch. Oh well, it happens.
........

Merged revisions 385116 from http://svn.asterisk.org/svn/asterisk/trunk

Modified:
    team/dlee/stasis-res/   (props changed)
    team/dlee/stasis-res/res/res_stasis.c

Propchange: team/dlee/stasis-res/
------------------------------------------------------------------------------
--- svnmerge-integrated (original)
+++ svnmerge-integrated Tue Apr  9 14:06:31 2013
@@ -1,1 +1,1 @@
-/trunk:1-385115
+/trunk:1-385121

Modified: team/dlee/stasis-res/res/res_stasis.c
URL: http://svnview.digium.com/svn/asterisk/team/dlee/stasis-res/res/res_stasis.c?view=diff&rev=385123&r1=385122&r2=385123
==============================================================================
--- team/dlee/stasis-res/res/res_stasis.c (original)
+++ team/dlee/stasis-res/res/res_stasis.c Tue Apr  9 14:06:31 2013
@@ -33,6 +33,7 @@
 
 #include "asterisk/astobj2.h"
 #include "asterisk/channel.h"
+#include "asterisk/lock.h"
 #include "asterisk/module.h"
 #include "asterisk/stasis.h"
 #include "asterisk/stasis_app.h"
@@ -152,7 +153,7 @@
 	 */
 	int continue_to_dialplan:1;
 	/*! Uniqueid of the associated channel */
-	char channel_uniqueid[];
+	char channel_id[];
 };
 
 static struct stasis_app_control *control_create(const char *uniqueid)
@@ -166,9 +167,33 @@
 		return NULL;
 	}
 
-	strncpy(control->channel_uniqueid, uniqueid, size - sizeof(*control));
+	strncpy(control->channel_id, uniqueid, size - sizeof(*control));
 
 	return control;
+}
+
+/*! AO2 hash function for \ref stasis_app_control */
+static int control_hash(const void *obj, const int flags)
+{
+	const struct stasis_app_control *control = obj;
+	const char *id = flags & OBJ_KEY ? obj : control->channel_id;
+
+	return ast_str_hash(id);
+}
+
+/*! AO2 comparison function for \ref stasis_app_control */
+static int control_compare(void *lhs, void *rhs, int flags)
+{
+	const struct stasis_app_control *lhs_control = lhs;
+	const struct stasis_app_control *rhs_control = rhs;
+	const char *rhs_name =
+		flags & OBJ_KEY ? rhs : rhs_control->channel_id;
+
+	if (strcmp(lhs_control->channel_id, rhs_name) == 0) {
+		return CMP_MATCH | CMP_STOP;
+	} else {
+		return 0;
+	}
 }
 
 struct stasis_app_control *stasis_app_control_find_by_channel(
@@ -340,7 +365,8 @@
 	}
 
 	controls = app_controls();
-	ao2_unlink_flags(controls, control, OBJ_POINTER | OBJ_UNLINK | OBJ_NODATA);
+	ao2_unlink_flags(controls, control,
+			 OBJ_POINTER | OBJ_UNLINK | OBJ_NODATA);
 	ao2_cleanup(control);
 }
 
@@ -351,7 +377,8 @@
 	RAII_VAR(struct ao2_container *, apps, apps_registry(), ao2_cleanup);
 	RAII_VAR(struct app *, app, NULL, ao2_cleanup);
 	RAII_VAR(struct stasis_app_control *, control, NULL, control_unlink);
-	RAII_VAR(struct stasis_subscription *, subscription, NULL, stasis_unsubscribe);
+	RAII_VAR(struct stasis_subscription *, subscription, NULL,
+		 stasis_unsubscribe);
 	int res = 0;
 	int hungup = 0;
 
@@ -359,7 +386,8 @@
 
 	app = ao2_find(apps, app_name, OBJ_KEY);
 	if (!app) {
-		ast_log(LOG_ERROR, "Stasis app '%s' not registered\n", app_name);
+		ast_log(LOG_ERROR,
+			"Stasis app '%s' not registered\n", app_name);
 		return -1;
 	}
 
@@ -375,9 +403,11 @@
 		ao2_link(controls, control);
 	}
 
-	subscription = stasis_subscribe(ast_channel_topic(chan), sub_handler, app);
+	subscription =
+		stasis_subscribe(ast_channel_topic(chan), sub_handler, app);
 	if (subscription == NULL) {
-		ast_log(LOG_ERROR, "Error subscribing app %s to channel %s\n", app_name, ast_channel_name(chan));
+		ast_log(LOG_ERROR, "Error subscribing app %s to channel %s\n",
+			app_name, ast_channel_name(chan));
 		return -1;
 	}
 	ao2_ref(app, +1); /* subscription now has a reference */
@@ -398,7 +428,8 @@
 		switch (f->frametype) {
 		case AST_FRAME_CONTROL:
 			if (f->subclass.integer == AST_CONTROL_HANGUP) {
-				ast_debug(3, "%s: Received hangup\n", ast_channel_uniqueid(chan));
+				ast_debug(3, "%s: Received hangup\n",
+					  ast_channel_uniqueid(chan));
 				hungup = 1;
 			}
 			break;
@@ -410,7 +441,8 @@
 
 	res = send_end_msg(app, chan);
 	if (res != 0) {
-		ast_log(LOG_ERROR, "Error sending end message to %s\n", app_name);
+		ast_log(LOG_ERROR,
+			"Error sending end message to %s\n", app_name);
 		return res;
 	}
 
@@ -425,10 +457,11 @@
 	app = ao2_find(apps, app_name, OBJ_KEY);
 
 	if (!app) {
-		/* XXX We can do a better job handling late binding, queueing up the call for a few seconds
-		 * to wait for the app to register.
+		/* XXX We can do a better job handling late binding, queueing up
+		 * the call for a few seconds to wait for the app to register.
 		 */
-		ast_log(LOG_WARNING, "Stasis app '%s' not registered\n", app_name);
+		ast_log(LOG_WARNING,
+			"Stasis app '%s' not registered\n", app_name);
 		return -1;
 	}
 
@@ -482,12 +515,14 @@
 {
 	int r = 0;
 
-	__apps_registry = ao2_container_alloc(APPS_NUM_BUCKETS, app_hash, app_compare);
+	__apps_registry =
+		ao2_container_alloc(APPS_NUM_BUCKETS, app_hash, app_compare);
 	if (__apps_registry == NULL) {
 		return AST_MODULE_LOAD_FAILURE;
 	}
 
-	__app_controls = ao2_container_alloc(CONTROLS_NUM_BUCKETS, app_hash, app_compare);
+	__app_controls = ao2_container_alloc(CONTROLS_NUM_BUCKETS,
+					     control_hash, control_compare);
 	if (__app_controls == NULL) {
 		return AST_MODULE_LOAD_FAILURE;
 	}




More information about the asterisk-commits mailing list