mirror of
https://github.com/asterisk/asterisk.git
synced 2025-09-03 03:20:57 +00:00
app_originate: Add option to execute gosub prior to dial
Issue/patch ASTERISK-26587 was inspired by issue ASTERISK-22992 that requested ability to add callerid into app_originate. Comments in that issue suggested that it was better solved by adding an option to gosub prior to originating the call. The attached patch implements this much like app_dial with two options one to gosub on the originating channel and one to gosub on the newly created channel and behaves just like app_dial. I have tested this patch by adding callerid info to the new channel and also SIPAddHeader (to e.g. add header to force auto answer) and confirmed it works. Have also tested both 'exten' and 'app' versions of app_originate. Opened by: dkerr Patch by: dkerr Change-Id: I36abc39b58567ffcab4a636ea196ef48be234c57
This commit is contained in:
@@ -72,6 +72,30 @@ static const char app_originate[] = "Originate";
|
||||
<parameter name="timeout" required="false">
|
||||
<para>Timeout in seconds. Default is 30 seconds.</para>
|
||||
</parameter>
|
||||
<parameter name="options" required="false">
|
||||
<optionlist>
|
||||
<option name="b" argsep="^">
|
||||
<para>Before originating the outgoing call, Gosub to the specified
|
||||
location using the newly created channel.</para>
|
||||
<argument name="context" required="false" />
|
||||
<argument name="exten" required="false" />
|
||||
<argument name="priority" required="true" hasparams="optional" argsep="^">
|
||||
<argument name="arg1" multiple="true" required="true" />
|
||||
<argument name="argN" />
|
||||
</argument>
|
||||
</option>
|
||||
<option name="B" argsep="^">
|
||||
<para>Before originating the outgoing call, Gosub to the specified
|
||||
location using the current channel.</para>
|
||||
<argument name="context" required="false" />
|
||||
<argument name="exten" required="false" />
|
||||
<argument name="priority" required="true" hasparams="optional" argsep="^">
|
||||
<argument name="arg1" multiple="true" required="true" />
|
||||
<argument name="argN" />
|
||||
</argument>
|
||||
</option>
|
||||
</optionlist>
|
||||
</parameter>
|
||||
</syntax>
|
||||
<description>
|
||||
<para>This application originates an outbound call and connects it to a specified extension or application. This application will block until the outgoing call fails or gets answered. At that point, this application will exit with the status variable set and dialplan processing will continue.</para>
|
||||
@@ -95,6 +119,25 @@ static const char app_originate[] = "Originate";
|
||||
</application>
|
||||
***/
|
||||
|
||||
|
||||
enum {
|
||||
OPT_PREDIAL_CALLEE = (1 << 0),
|
||||
OPT_PREDIAL_CALLER = (1 << 1),
|
||||
};
|
||||
|
||||
enum {
|
||||
OPT_ARG_PREDIAL_CALLEE,
|
||||
OPT_ARG_PREDIAL_CALLER,
|
||||
/* note: this entry _MUST_ be the last one in the enum */
|
||||
OPT_ARG_ARRAY_SIZE,
|
||||
};
|
||||
|
||||
AST_APP_OPTIONS(originate_exec_options, BEGIN_OPTIONS
|
||||
AST_APP_OPTION_ARG('b', OPT_PREDIAL_CALLEE, OPT_ARG_PREDIAL_CALLEE),
|
||||
AST_APP_OPTION_ARG('B', OPT_PREDIAL_CALLER, OPT_ARG_PREDIAL_CALLER),
|
||||
END_OPTIONS );
|
||||
|
||||
|
||||
static int originate_exec(struct ast_channel *chan, const char *data)
|
||||
{
|
||||
AST_DECLARE_APP_ARGS(args,
|
||||
@@ -104,7 +147,11 @@ static int originate_exec(struct ast_channel *chan, const char *data)
|
||||
AST_APP_ARG(arg2);
|
||||
AST_APP_ARG(arg3);
|
||||
AST_APP_ARG(timeout);
|
||||
AST_APP_ARG(options);
|
||||
);
|
||||
struct ast_flags64 opts = { 0, };
|
||||
char *opt_args[OPT_ARG_ARRAY_SIZE];
|
||||
char *predial_callee = NULL;
|
||||
char *parse;
|
||||
char *chantech, *chandata;
|
||||
int res = -1;
|
||||
@@ -157,6 +204,25 @@ static int originate_exec(struct ast_channel *chan, const char *data)
|
||||
goto return_cleanup;
|
||||
}
|
||||
|
||||
if (!ast_strlen_zero(args.options) &&
|
||||
ast_app_parse_options64(originate_exec_options, &opts, opt_args, args.options)) {
|
||||
ast_log(LOG_ERROR, "Invalid options: '%s'\n", args.options);
|
||||
goto return_cleanup;
|
||||
}
|
||||
|
||||
/* PREDIAL: Run gosub on the caller's channel */
|
||||
if (ast_test_flag64(&opts, OPT_PREDIAL_CALLER)
|
||||
&& !ast_strlen_zero(opt_args[OPT_ARG_PREDIAL_CALLER])) {
|
||||
ast_replace_subargument_delimiter(opt_args[OPT_ARG_PREDIAL_CALLER]);
|
||||
ast_app_exec_sub(NULL, chan, opt_args[OPT_ARG_PREDIAL_CALLER], 0);
|
||||
}
|
||||
|
||||
if (ast_test_flag64(&opts, OPT_PREDIAL_CALLEE)
|
||||
&& !ast_strlen_zero(opt_args[OPT_ARG_PREDIAL_CALLEE])) {
|
||||
ast_replace_subargument_delimiter(opt_args[OPT_ARG_PREDIAL_CALLEE]);
|
||||
predial_callee = opt_args[OPT_ARG_PREDIAL_CALLEE];
|
||||
}
|
||||
|
||||
if (!strcasecmp(args.type, "exten")) {
|
||||
int priority = 1; /* Initialized in case priority not specified */
|
||||
const char *exten = args.arg2;
|
||||
@@ -175,16 +241,16 @@ static int originate_exec(struct ast_channel *chan, const char *data)
|
||||
ast_debug(1, "Originating call to '%s/%s' and connecting them to extension %s,%s,%d\n",
|
||||
chantech, chandata, args.arg1, exten, priority);
|
||||
|
||||
ast_pbx_outgoing_exten(chantech, cap_slin, chandata,
|
||||
ast_pbx_outgoing_exten_predial(chantech, cap_slin, chandata,
|
||||
timeout * 1000, args.arg1, exten, priority, &outgoing_status, 1, NULL,
|
||||
NULL, NULL, NULL, NULL, 0, NULL);
|
||||
NULL, NULL, NULL, NULL, 0, NULL, predial_callee);
|
||||
} else if (!strcasecmp(args.type, "app")) {
|
||||
ast_debug(1, "Originating call to '%s/%s' and connecting them to %s(%s)\n",
|
||||
chantech, chandata, args.arg1, S_OR(args.arg2, ""));
|
||||
|
||||
ast_pbx_outgoing_app(chantech, cap_slin, chandata,
|
||||
ast_pbx_outgoing_app_predial(chantech, cap_slin, chandata,
|
||||
timeout * 1000, args.arg1, args.arg2, &outgoing_status, 1, NULL,
|
||||
NULL, NULL, NULL, NULL, NULL);
|
||||
NULL, NULL, NULL, NULL, NULL, predial_callee);
|
||||
} else {
|
||||
ast_log(LOG_ERROR, "Incorrect type, it should be 'exten' or 'app': %s\n",
|
||||
args.type);
|
||||
|
Reference in New Issue
Block a user