Skip to content

Commit b742514

Browse files
InterLinked1gtjoseph
authored andcommitted
app_originate: Allow setting Caller ID and variables
Caller ID can now be set on the called channel and Variables can now be set on the destination using the Originate application, just as they can be currently using call files or the Manager Action. ASTERISK-29450 Change-Id: Ia64cfe97d2792bcbf4775b3126cad662922a8b66
1 parent c0fc8ad commit b742514

File tree

2 files changed

+83
-8
lines changed

2 files changed

+83
-8
lines changed

apps/app_originate.c

Lines changed: 77 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,6 @@
2727
*
2828
* \ingroup applications
2929
*
30-
* \todo Make a way to be able to set variables (and functions) on the outbound
31-
* channel, similar to the Variable headers for the AMI Originate, and the
32-
* Set options for call files.
3330
*/
3431

3532
/*** MODULEINFO
@@ -98,12 +95,26 @@ static const char app_originate[] = "Originate";
9895
<argument name="argN" />
9996
</argument>
10097
</option>
98+
<option name="c">
99+
<para>The caller ID number to use for the called channel. Default is
100+
the current channel's Caller ID number.</para>
101+
</option>
102+
<option name="n">
103+
<para>The caller ID name to use for the called channel. Default is
104+
the current channel's Caller ID name.</para>
105+
</option>
106+
<option name="v" argsep="^">
107+
<para>A series of channel variables to set on the destination channel.</para>
108+
<argument name="var1" multiple="true" argsep="=">
109+
<argument name="name" required="true" />
110+
<argument name="value" required="true" />
111+
</argument>
112+
</option>
101113
</optionlist>
102114
</parameter>
103115
</syntax>
104116
<description>
105117
<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>
106-
107118
<para>This application sets the following channel variable before exiting:</para>
108119
<variablelist>
109120
<variable name="ORIGINATE_STATUS">
@@ -128,11 +139,17 @@ enum {
128139
OPT_PREDIAL_CALLEE = (1 << 0),
129140
OPT_PREDIAL_CALLER = (1 << 1),
130141
OPT_ASYNC = (1 << 2),
142+
OPT_CALLER_NUM = (1 << 3),
143+
OPT_CALLER_NAME = (1 << 4),
144+
OPT_VARIABLES = (1 << 5),
131145
};
132146

133147
enum {
134148
OPT_ARG_PREDIAL_CALLEE,
135149
OPT_ARG_PREDIAL_CALLER,
150+
OPT_ARG_CALLER_NUM,
151+
OPT_ARG_CALLER_NAME,
152+
OPT_ARG_VARIABLES,
136153
/* note: this entry _MUST_ be the last one in the enum */
137154
OPT_ARG_ARRAY_SIZE,
138155
};
@@ -141,9 +158,11 @@ AST_APP_OPTIONS(originate_exec_options, BEGIN_OPTIONS
141158
AST_APP_OPTION('a', OPT_ASYNC),
142159
AST_APP_OPTION_ARG('b', OPT_PREDIAL_CALLEE, OPT_ARG_PREDIAL_CALLEE),
143160
AST_APP_OPTION_ARG('B', OPT_PREDIAL_CALLER, OPT_ARG_PREDIAL_CALLER),
161+
AST_APP_OPTION_ARG('c', OPT_CALLER_NUM, OPT_ARG_CALLER_NUM),
162+
AST_APP_OPTION_ARG('n', OPT_CALLER_NAME, OPT_ARG_CALLER_NAME),
163+
AST_APP_OPTION_ARG('v', OPT_VARIABLES, OPT_ARG_VARIABLES),
144164
END_OPTIONS );
145165

146-
147166
static int originate_exec(struct ast_channel *chan, const char *data)
148167
{
149168
AST_DECLARE_APP_ARGS(args,
@@ -158,7 +177,9 @@ static int originate_exec(struct ast_channel *chan, const char *data)
158177
struct ast_flags64 opts = { 0, };
159178
char *opt_args[OPT_ARG_ARRAY_SIZE];
160179
char *predial_callee = NULL;
161-
char *parse;
180+
char *parse, *cnum = NULL, *cname = NULL;
181+
182+
struct ast_variable *vars = NULL;
162183
char *chantech, *chandata;
163184
int res = -1;
164185
int continue_in_dialplan = 0;
@@ -236,7 +257,50 @@ static int originate_exec(struct ast_channel *chan, const char *data)
236257
goto return_cleanup;
237258
}
238259

260+
if (ast_test_flag64(&opts, OPT_CALLER_NUM)) {
261+
if (!ast_strlen_zero(opt_args[OPT_ARG_CALLER_NUM])) {
262+
cnum = opt_args[OPT_ARG_CALLER_NUM];
263+
} else if (ast_channel_caller(chan)->id.number.str) {
264+
cnum = ast_channel_caller(chan)->id.number.str;
265+
}
266+
}
267+
268+
if (ast_test_flag64(&opts, OPT_CALLER_NAME)) {
269+
if (!ast_strlen_zero(opt_args[OPT_ARG_CALLER_NAME])) {
270+
cname = opt_args[OPT_ARG_CALLER_NAME];
271+
} else if (ast_channel_caller(chan)->id.name.str) {
272+
cname = ast_channel_caller(chan)->id.name.str;
273+
}
274+
}
275+
276+
/* Assign variables */
277+
if (ast_test_flag64(&opts, OPT_VARIABLES)
278+
&& !ast_strlen_zero(opt_args[OPT_ARG_VARIABLES])) {
279+
char *vartext;
280+
char *text = opt_args[OPT_ARG_VARIABLES];
281+
while ((vartext = ast_strsep(&text, '^', 0))) {
282+
struct ast_variable *var;
283+
char *varname, *varvalue;
284+
if (!(varname = ast_strsep(&vartext, '=', 0))) {
285+
ast_log(LOG_ERROR, "Variable syntax error: %s\n", vartext);
286+
goto return_cleanup;
287+
}
288+
if (!(varvalue = ast_strsep(&vartext, '=', 0))) {
289+
varvalue = ""; /* empty values are allowed */
290+
}
291+
var = ast_variable_new(varname, varvalue, "");
292+
if (!var) {
293+
ast_log(LOG_ERROR, "Failed to allocate variable: %s\n", varname);
294+
goto return_cleanup;
295+
}
296+
ast_debug(1, "Appending variable '%s' with value '%s'", varname, varvalue);
297+
ast_variable_list_append(&vars, var);
298+
}
299+
}
300+
239301
if (!strcasecmp(args.type, "exten")) {
302+
const char *cid_num = cnum;
303+
const char *cid_name = cname;
240304
int priority = 1; /* Initialized in case priority not specified */
241305
const char *exten = args.arg2;
242306

@@ -257,16 +321,18 @@ static int originate_exec(struct ast_channel *chan, const char *data)
257321
res = ast_pbx_outgoing_exten_predial(chantech, cap_slin, chandata,
258322
timeout * 1000, args.arg1, exten, priority, &outgoing_status,
259323
ast_test_flag64(&opts, OPT_ASYNC) ? AST_OUTGOING_NO_WAIT : AST_OUTGOING_WAIT,
260-
NULL, NULL, NULL, NULL, NULL, 0, NULL,
324+
cid_num, cid_name, vars, NULL, NULL, 0, NULL,
261325
predial_callee);
262326
} else {
327+
const char *cid_num = cnum;
328+
const char *cid_name = cname;
263329
ast_debug(1, "Originating call to '%s/%s' and connecting them to %s(%s)\n",
264330
chantech, chandata, args.arg1, S_OR(args.arg2, ""));
265331

266332
res = ast_pbx_outgoing_app_predial(chantech, cap_slin, chandata,
267333
timeout * 1000, args.arg1, args.arg2, &outgoing_status,
268334
ast_test_flag64(&opts, OPT_ASYNC) ? AST_OUTGOING_NO_WAIT : AST_OUTGOING_WAIT,
269-
NULL, NULL, NULL, NULL, NULL, NULL,
335+
cid_num, cid_name, vars, NULL, NULL, NULL,
270336
predial_callee);
271337
}
272338

@@ -311,6 +377,9 @@ static int originate_exec(struct ast_channel *chan, const char *data)
311377
break;
312378
}
313379
}
380+
if (vars) {
381+
ast_variables_destroy(vars);
382+
}
314383
ao2_cleanup(cap_slin);
315384
ast_autoservice_stop(chan);
316385

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
Subject: Add variable support to Originate
2+
3+
The Originate application now allows
4+
variables to be set on the new channel
5+
through a new option.
6+

0 commit comments

Comments
 (0)