No subject


Fri Sep 2 03:59:05 CDT 2011


Made predial routines on the callee channel without supplied context or
exten use the needed value from the caller channel.  The added support
will allow similar relative hangup handler references to get the missing
context or exten from the channel adding the handler at the time it is
added.

Modified:
    team/rmudgett/hangup_handlers/apps/app_dial.c
    team/rmudgett/hangup_handlers/apps/app_followme.c
    team/rmudgett/hangup_handlers/apps/app_stack.c
    team/rmudgett/hangup_handlers/include/asterisk/app.h
    team/rmudgett/hangup_handlers/main/app.c

Modified: team/rmudgett/hangup_handlers/apps/app_dial.c
URL: http://svnview.digium.com/svn/asterisk/team/rmudgett/hangup_handlers/apps/app_dial.c?view=diff&rev=368918&r1=368917&r2=368918
==============================================================================
--- team/rmudgett/hangup_handlers/apps/app_dial.c (original)
+++ team/rmudgett/hangup_handlers/apps/app_dial.c Wed Jun 13 16:35:01 2012
@@ -2550,12 +2550,18 @@
 	if (ast_test_flag64(&opts, OPT_PREDIAL_CALLEE)
 		&& !ast_strlen_zero(opt_args[OPT_ARG_PREDIAL_CALLEE])
 		&& !AST_LIST_EMPTY(&out_chans)) {
-		ast_autoservice_start(chan);
+		const char *predial_callee;
+
 		ast_replace_subargument_delimiter(opt_args[OPT_ARG_PREDIAL_CALLEE]);
-		AST_LIST_TRAVERSE(&out_chans, tmp, node) {
-			ast_pre_call(tmp->chan, opt_args[OPT_ARG_PREDIAL_CALLEE]);
-		}
-		ast_autoservice_stop(chan);
+		predial_callee = ast_app_expand_sub_args(chan, opt_args[OPT_ARG_PREDIAL_CALLEE]);
+		if (predial_callee) {
+			ast_autoservice_start(chan);
+			AST_LIST_TRAVERSE(&out_chans, tmp, node) {
+				ast_pre_call(tmp->chan, predial_callee);
+			}
+			ast_autoservice_stop(chan);
+			ast_free((char *) predial_callee);
+		}
 	}
 
 	/* Start all outgoing calls */

Modified: team/rmudgett/hangup_handlers/apps/app_followme.c
URL: http://svnview.digium.com/svn/asterisk/team/rmudgett/hangup_handlers/apps/app_followme.c?view=diff&rev=368918&r1=368917&r2=368918
==============================================================================
--- team/rmudgett/hangup_handlers/apps/app_followme.c (original)
+++ team/rmudgett/hangup_handlers/apps/app_followme.c Wed Jun 13 16:35:01 2012
@@ -1386,7 +1386,8 @@
 	if (ast_test_flag(&targs->followmeflags, FOLLOWMEFLAG_PREDIAL_CALLEE)
 		&& !ast_strlen_zero(opt_args[FOLLOWMEFLAG_ARG_PREDIAL_CALLEE])) {
 		ast_replace_subargument_delimiter(opt_args[FOLLOWMEFLAG_ARG_PREDIAL_CALLEE]);
-		targs->predial_callee = opt_args[FOLLOWMEFLAG_ARG_PREDIAL_CALLEE];
+		targs->predial_callee =
+			ast_app_expand_sub_args(chan, opt_args[FOLLOWMEFLAG_ARG_PREDIAL_CALLEE]);
 	}
 
 	/* PREDIAL: Run gosub on the caller's channel */
@@ -1522,6 +1523,7 @@
 	if (!ast_strlen_zero(targs->namerecloc)) {
 		unlink(targs->namerecloc);
 	}
+	ast_free((char *) targs->predial_callee);
 	ast_party_connected_line_free(&targs->connected_in);
 	ast_party_connected_line_free(&targs->connected_out);
 	ast_free(targs);

Modified: team/rmudgett/hangup_handlers/apps/app_stack.c
URL: http://svnview.digium.com/svn/asterisk/team/rmudgett/hangup_handlers/apps/app_stack.c?view=diff&rev=368918&r1=368917&r2=368918
==============================================================================
--- team/rmudgett/hangup_handlers/apps/app_stack.c (original)
+++ team/rmudgett/hangup_handlers/apps/app_stack.c Wed Jun 13 16:35:01 2012
@@ -379,6 +379,91 @@
 	return res;
 }
 
+/*!
+ * \internal
+ * \brief Add missing context and/or exten to Gosub application argument string.
+ * \since 11.0
+ *
+ * \param chan Channel to obtain context/exten.
+ * \param args Gosub application argument string.
+ *
+ * \details
+ * Fills in the optional context and exten from the given channel.
+ * Convert: [[context,]exten,]priority[(arg1[,...][,argN])]
+ * To: context,exten,priority[(arg1[,...][,argN])]
+ *
+ * \retval expanded Gosub argument string on success.  Must be freed.
+ * \retval NULL on error.
+ *
+ * \note The parsing needs to be kept in sync with the
+ * gosub_exec() argument format.
+ */
+static const char *expand_gosub_args(struct ast_channel *chan, const char *args)
+{
+	int len;
+	char *parse;
+	char *label;
+	char *new_args;
+	const char *context;
+	const char *exten;
+	const char *pri;
+
+	/* Separate the context,exten,pri from the optional routine arguments. */
+	parse = ast_strdupa(args);
+	label = strsep(&parse, "(");
+	if (parse) {
+		char *endparen;
+
+		endparen = strrchr(parse, ')');
+		if (endparen) {
+			*endparen = '\0';
+		} else {
+			ast_log(LOG_WARNING, "Ouch.  No closing paren: '%s'?\n", args);
+		}
+	}
+
+	/* Split context,exten,pri */
+	context = strsep(&label, ",");
+	exten = strsep(&label, ",");
+	pri = strsep(&label, ",");
+	if (!exten) {
+		/* Only a priority in this one */
+		pri = context;
+		exten = NULL;
+		context = NULL;
+	} else if (!pri) {
+		/* Only an extension and priority in this one */
+		pri = exten;
+		exten = context;
+		context = NULL;
+	}
+
+	ast_channel_lock(chan);
+	if (ast_strlen_zero(exten)) {
+		exten = ast_channel_exten(chan);
+	}
+	if (ast_strlen_zero(context)) {
+		context = ast_channel_context(chan);
+	}
+	len = strlen(context) + strlen(exten) + strlen(pri) + 3;
+	if (!ast_strlen_zero(parse)) {
+		len += 2 + strlen(parse);
+	}
+	new_args = ast_malloc(len);
+	if (new_args) {
+		if (ast_strlen_zero(parse)) {
+			snprintf(new_args, len, "%s,%s,%s", context, exten, pri);
+		} else {
+			snprintf(new_args, len, "%s,%s,%s(%s)", context, exten, pri, parse);
+		}
+	}
+	ast_channel_unlock(chan);
+
+	ast_debug(4, "Gosub args:%s new_args:%s\n", args, new_args ? new_args : "");
+
+	return new_args;
+}
+
 static int gosub_exec(struct ast_channel *chan, const char *data)
 {
 	struct ast_datastore *stack_store;
@@ -1128,6 +1213,7 @@
 	/* Setup the stack application callback functions. */
 	static struct ast_app_stack_funcs funcs = {
 		.run_sub = gosub_run,
+		.expand_sub_args = expand_gosub_args,
 	};
 
 	ast_agi_register(ast_module_info->self, &gosub_agi_command);

Modified: team/rmudgett/hangup_handlers/include/asterisk/app.h
URL: http://svnview.digium.com/svn/asterisk/team/rmudgett/hangup_handlers/include/asterisk/app.h?view=diff&rev=368918&r1=368917&r2=368918
==============================================================================
--- team/rmudgett/hangup_handlers/include/asterisk/app.h (original)
+++ team/rmudgett/hangup_handlers/include/asterisk/app.h Wed Jun 13 16:35:01 2012
@@ -205,6 +205,20 @@
 	 */
 	int (*run_sub)(struct ast_channel *chan, const char *args, int ignore_hangup);
 
+	/*!
+	 * \brief Add missing context/exten to Gosub application argument string.
+	 *
+	 * \param chan Channel to obtain context/exten.
+	 * \param args Gosub application argument string.
+	 *
+	 * \details
+	 * Fills in the optional context and exten from the given channel.
+	 *
+	 * \retval New-args Gosub argument string on success.  Must be freed.
+	 * \retval NULL on error.
+	 */
+	const char *(*expand_sub_args)(struct ast_channel *chan, const char *args);
+
 	/* Add new API calls to the end here. */
 };
 
@@ -214,6 +228,20 @@
  * \param funcs Stack applications callback functions.
  */
 void ast_install_stack_functions(const struct ast_app_stack_funcs *funcs);
+
+/*!
+ * \brief Add missing context/exten to subroutine argument string.
+ *
+ * \param chan Channel to obtain context/exten.
+ * \param args Gosub application argument string.
+ *
+ * \details
+ * Fills in the optional context and exten from the given channel.
+ *
+ * \retval New-args Gosub argument string on success.  Must be freed.
+ * \retval NULL on error.
+ */
+const char *ast_app_expand_sub_args(struct ast_channel *chan, const char *args);
 
 /*!
  * \since 11

Modified: team/rmudgett/hangup_handlers/main/app.c
URL: http://svnview.digium.com/svn/asterisk/team/rmudgett/hangup_handlers/main/app.c?view=diff&rev=368918&r1=368917&r2=368918
==============================================================================
--- team/rmudgett/hangup_handlers/main/app.c (original)
+++ team/rmudgett/hangup_handlers/main/app.c Wed Jun 13 16:35:01 2012
@@ -318,6 +318,25 @@
 void ast_install_stack_functions(const struct ast_app_stack_funcs *funcs)
 {
 	app_stack_callbacks = funcs;
+}
+
+const char *ast_app_expand_sub_args(struct ast_channel *chan, const char *args)
+{
+	const struct ast_app_stack_funcs *funcs;
+	const char *new_args;
+
+	funcs = app_stack_callbacks;
+	if (!funcs || !funcs->expand_sub_args) {
+		ast_log(LOG_WARNING,
+			"Cannot expand 'Gosub(%s)' arguments.  The app_stack module is not available.\n",
+			args);
+		return NULL;
+	}
+	ast_module_ref(funcs->module);
+
+	new_args = funcs->expand_sub_args(chan, args);
+	ast_module_unref(funcs->module);
+	return new_args;
 }
 
 int ast_app_exec_sub(struct ast_channel *autoservice_chan, struct ast_channel *sub_chan, const char *sub_args, int ignore_hangup)




More information about the asterisk-commits mailing list