[svn-commits] rmudgett: trunk r378081 - /trunk/channels/chan_local.c

SVN commits to the Digium repositories svn-commits at lists.digium.com
Mon Dec 17 15:22:24 CST 2012


Author: rmudgett
Date: Mon Dec 17 15:22:21 2012
New Revision: 378081

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=378081
Log:
chan_local: Parse dial string consistently.

* Fix local_alloc() unexpected limitation of exten and context length from
a combined length of 80 characters to a normal 80 characters each.

* Made local_alloc() and local_devicestate() parse the same way.

Modified:
    trunk/channels/chan_local.c

Modified: trunk/channels/chan_local.c
URL: http://svnview.digium.com/svn/asterisk/trunk/channels/chan_local.c?view=diff&rev=378081&r1=378080&r2=378081
==============================================================================
--- trunk/channels/chan_local.c (original)
+++ trunk/channels/chan_local.c Mon Dec 17 15:22:21 2012
@@ -282,27 +282,31 @@
 static int local_devicestate(const char *data)
 {
 	char *exten = ast_strdupa(data);
-	char *context = NULL, *opts = NULL;
+	char *context;
+	char *opts;
 	int res;
 	struct local_pvt *lp;
 	struct ao2_iterator it;
 
-	if (!(context = strchr(exten, '@'))) {
-		ast_log(LOG_WARNING, "Someone used Local/%s somewhere without a @context. This is bad.\n", exten);
+	/* Strip options if they exist */
+	opts = strchr(exten, '/');
+	if (opts) {
+		*opts = '\0';
+	}
+
+	context = strchr(exten, '@');
+	if (!context) {
+		ast_log(LOG_WARNING,
+			"Someone used Local/%s somewhere without a @context. This is bad.\n", data);
+		return AST_DEVICE_INVALID;	
+	}
+	*context++ = '\0';
+
+	ast_debug(3, "Checking if extension %s@%s exists (devicestate)\n", exten, context);
+	res = ast_exists_extension(NULL, context, exten, 1, NULL);
+	if (!res) {
 		return AST_DEVICE_INVALID;
 	}
-
-	*context++ = '\0';
-
-	/* Strip options if they exist */
-	if ((opts = strchr(context, '/')))
-		*opts = '\0';
-
-	ast_debug(3, "Checking if extension %s@%s exists (devicestate)\n", exten, context);
-
-	res = ast_exists_extension(NULL, context, exten, 1, NULL);
-	if (!res)
-		return AST_DEVICE_INVALID;
 
 	res = AST_DEVICE_NOT_INUSE;
 
@@ -1147,7 +1151,9 @@
 static struct local_pvt *local_alloc(const char *data, struct ast_format_cap *cap)
 {
 	struct local_pvt *tmp = NULL;
-	char *c = NULL, *opts = NULL;
+	char *parse;
+	char *c = NULL;
+	char *opts = NULL;
 
 	if (!(tmp = ao2_alloc(sizeof(*tmp), local_destroy))) {
 		return NULL;
@@ -1158,12 +1164,12 @@
 	}
 
 	/* Initialize private structure information */
-	ast_copy_string(tmp->exten, data, sizeof(tmp->exten));
+	parse = ast_strdupa(data);
 
 	memcpy(&tmp->jb_conf, &g_jb_conf, sizeof(tmp->jb_conf));
 
 	/* Look for options */
-	if ((opts = strchr(tmp->exten, '/'))) {
+	if ((opts = strchr(parse, '/'))) {
 		*opts++ = '\0';
 		if (strchr(opts, 'n'))
 			ast_set_flag(tmp, LOCAL_NO_OPTIMIZATION);
@@ -1184,24 +1190,16 @@
 	}
 
 	/* Look for a context */
-	if ((c = strchr(tmp->exten, '@')))
+	if ((c = strchr(parse, '@'))) {
 		*c++ = '\0';
+	}
 
 	ast_copy_string(tmp->context, c ? c : "default", sizeof(tmp->context));
-#if 0
-	/* We can't do this check here, because we don't know the CallerID yet, and
-	 * the CallerID could potentially affect what step is actually taken (or
-	 * even if that step exists). */
-	if (!ast_exists_extension(NULL, tmp->context, tmp->exten, 1, NULL)) {
-		ast_log(LOG_NOTICE, "No such extension/context %s@%s creating local channel\n", tmp->exten, tmp->context);
-		tmp = local_pvt_destroy(tmp);
-	} else {
-#endif
-		/* Add to list */
-		ao2_link(locals, tmp);
-#if 0
-	}
-#endif
+	ast_copy_string(tmp->exten, parse, sizeof(tmp->exten));
+
+	/* Add to list */
+	ao2_link(locals, tmp);
+
 	return tmp; /* this is returned with a ref */
 }
 




More information about the svn-commits mailing list