Skip to content

Commit 1521c77

Browse files
authored
app_callerid: Add status variable.
The SendCWCID application now sets the CWCIDSTATUS variable before it returns so that the dialplan / other modules can use the result.
1 parent d70d65f commit 1521c77

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

apps/app_callerid.c

+33
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,22 @@
109109
This application functions using the same idea as an "orange box".</para>
110110
<para>On DAHDI channels, the native channel driver hooks for Call Waiting Caller ID
111111
can be used. On all other channels, it will be generated as linear audio.</para>
112+
<variablelist>
113+
<variable name="CWCIDSTATUS">
114+
<value name="SUCCESS">
115+
Call Waiting Caller ID successfully sent to CPE.
116+
</value>
117+
<value name="UNSUPPORTED">
118+
CPE does not support off-hook Caller ID. This is not set if the d option is used.
119+
</value>
120+
<value name="FAILURE">
121+
General failure occured.
122+
</value>
123+
<value name="HANGUP">
124+
Channel hung up before spill could complete.
125+
</value>
126+
</variable>
127+
</variablelist>
112128
</description>
113129
</application>
114130
***/
@@ -130,6 +146,7 @@ AST_APP_OPTIONS(cwcid_option_flags, {
130146
});
131147

132148
static const char *app = "SendCWCID";
149+
static const char *var = "CWCIDSTATUS";
133150

134151
static int await_ack(struct ast_channel *chan, int ms)
135152
{
@@ -354,11 +371,13 @@ static int cwcid_exec(struct ast_channel *chan, const char *data)
354371
if (pvt->cidspill) {
355372
ast_channel_unlock(chan);
356373
ast_log(LOG_WARNING, "cidspill already exists??\n"); /* We're probably getting a legitimate call waiting at the same time we're trying to execute this. */
374+
pbx_builtin_setvar_helper(chan, var, "FAILURE");
357375
return 0;
358376
}
359377
if (!(pvt->cidspill = ast_malloc((sas ? 2400 + 680 : 680) + READ_SIZE * 4))) {
360378
ast_channel_unlock(chan);
361379
ast_log(LOG_WARNING, "Failed to malloc cidspill\n");
380+
pbx_builtin_setvar_helper(chan, var, "FAILURE");
362381
return -1;
363382
}
364383
ast_gen_cas(pvt->cidspill, sas, sas ? 2400 + 680 : 680, AST_LAW(pvt));
@@ -370,6 +389,7 @@ static int cwcid_exec(struct ast_channel *chan, const char *data)
370389
/* wait for CID spill in dahdi_read (as opposed to calling send_caller directly */
371390
if (ast_safe_sleep(chan, sas ? 300 + 85 : 85)) {
372391
ast_debug(1, "ast_safe_sleep returned -1\n");
392+
pbx_builtin_setvar_helper(chan, var, "HANGUP");
373393
return -1;
374394
}
375395
/* chan_dahdi will free pvt->cidspill */
@@ -379,22 +399,26 @@ static int cwcid_exec(struct ast_channel *chan, const char *data)
379399

380400
if (ast_set_write_format(chan, ast_format_ulaw)) {
381401
ast_log(LOG_WARNING, "Unable to set '%s' to signed linear format (write)\n", ast_channel_name(chan));
402+
pbx_builtin_setvar_helper(chan, var, "FAILURE");
382403
return -1;
383404
}
384405
if (ast_set_read_format(chan, ast_format_ulaw)) {
385406
ast_log(LOG_WARNING, "Unable to set read format to ULAW\n");
407+
pbx_builtin_setvar_helper(chan, var, "FAILURE");
386408
return -1;
387409
}
388410

389411
if (!(cidspill = ast_malloc((sas ? 2400 + 680 : 680) + READ_SIZE * 4))) {
390412
ast_log(LOG_WARNING, "Failed to malloc cidspill\n");
413+
pbx_builtin_setvar_helper(chan, var, "FAILURE");
391414
return -1;
392415
}
393416
ast_gen_cas(cidspill, sas, sas ? 2400 + 680 : 680, ast_format_ulaw);
394417

395418
if (cwcid_careful_send(chan, cidspill, sas ? 2400 + 680 : 680, NULL)) {
396419
ast_free(cidspill);
397420
ast_log(LOG_WARNING, "Failed to write cidspill\n");
421+
pbx_builtin_setvar_helper(chan, var, "FAILURE");
398422
return -1;
399423
}
400424
ast_free(cidspill);
@@ -404,10 +428,12 @@ static int cwcid_exec(struct ast_channel *chan, const char *data)
404428
res = await_ack(chan, 500); /* wait up to 500ms for ACK */
405429
if (res == -1) {
406430
ast_debug(1, "await_ack returned -1\n");
431+
pbx_builtin_setvar_helper(chan, var, "HANGUP");
407432
return -1;
408433
}
409434
if (ack) { /* make sure we got the ACK, if we're supposed to check */
410435
if (res != 'A' && res != 'D') {
436+
pbx_builtin_setvar_helper(chan, var, "UNSUPPORTED");
411437
return 0; /* Didn't get ACK, abort. */
412438
}
413439
}
@@ -418,6 +444,7 @@ static int cwcid_exec(struct ast_channel *chan, const char *data)
418444
while (pvt->cidspill) { /* shouldn't happen */
419445
ast_debug(1, "Waiting for cidspill to finish\n");
420446
if (ast_safe_sleep(chan, 10)) { /* try not to busy wait */
447+
pbx_builtin_setvar_helper(chan, var, "HANGUP");
421448
return -1;
422449
}
423450
}
@@ -426,6 +453,7 @@ static int cwcid_exec(struct ast_channel *chan, const char *data)
426453
if (!(pvt->cidspill = ast_malloc(MAX_CALLERID_SIZE))) {
427454
ast_channel_unlock(chan);
428455
ast_log(LOG_WARNING, "Failed to malloc cidspill\n");
456+
pbx_builtin_setvar_helper(chan, var, "FAILURE");
429457
return -1;
430458
}
431459
/* similar to my_send_callerid in chan_dahdi.c: */
@@ -447,11 +475,13 @@ static int cwcid_exec(struct ast_channel *chan, const char *data)
447475

448476
/* wait for CID spill in dahdi_read (as opposed to calling send_caller directly */
449477
if (ast_safe_sleep(chan, pvt->cidlen / 8)) {
478+
pbx_builtin_setvar_helper(chan, var, "HANGUP");
450479
return -1;
451480
}
452481
while (pvt->cidspill) { /* shouldn't happen */
453482
ast_debug(1, "Waiting for cidspill to finish\n");
454483
if (ast_safe_sleep(chan, 10)) { /* try not to busy wait */
484+
pbx_builtin_setvar_helper(chan, var, "HANGUP");
455485
return -1;
456486
}
457487
}
@@ -463,6 +493,7 @@ static int cwcid_exec(struct ast_channel *chan, const char *data)
463493

464494
if (!(cidspill = ast_malloc(MAX_CALLERID_SIZE))) {
465495
ast_log(LOG_WARNING, "Failed to malloc cidspill\n");
496+
pbx_builtin_setvar_helper(chan, var, "FAILURE");
466497
return -1;
467498
}
468499
cidlen = ast_callerid_callwaiting_full_tz_generate(cidspill,
@@ -476,12 +507,14 @@ static int cwcid_exec(struct ast_channel *chan, const char *data)
476507
tz);
477508
if (cwcid_careful_send(chan, cidspill, cidlen, NULL)) {
478509
ast_log(LOG_WARNING, "Failed to write cidspill\n");
510+
pbx_builtin_setvar_helper(chan, var, "FAILURE");
479511
res = -1;
480512
}
481513
ast_free(cidspill);
482514
}
483515

484516
ast_debug(1, "res is %d\n", res);
517+
pbx_builtin_setvar_helper(chan, var, res ? "FAILURE" : "SUCCESS");
485518

486519
return res;
487520
}

0 commit comments

Comments
 (0)