109
109
This application functions using the same idea as an "orange box".</para>
110
110
<para>On DAHDI channels, the native channel driver hooks for Call Waiting Caller ID
111
111
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>
112
128
</description>
113
129
</application>
114
130
***/
@@ -130,6 +146,7 @@ AST_APP_OPTIONS(cwcid_option_flags, {
130
146
});
131
147
132
148
static const char * app = "SendCWCID" ;
149
+ static const char * var = "CWCIDSTATUS" ;
133
150
134
151
static int await_ack (struct ast_channel * chan , int ms )
135
152
{
@@ -354,11 +371,13 @@ static int cwcid_exec(struct ast_channel *chan, const char *data)
354
371
if (pvt -> cidspill ) {
355
372
ast_channel_unlock (chan );
356
373
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" );
357
375
return 0 ;
358
376
}
359
377
if (!(pvt -> cidspill = ast_malloc ((sas ? 2400 + 680 : 680 ) + READ_SIZE * 4 ))) {
360
378
ast_channel_unlock (chan );
361
379
ast_log (LOG_WARNING , "Failed to malloc cidspill\n" );
380
+ pbx_builtin_setvar_helper (chan , var , "FAILURE" );
362
381
return -1 ;
363
382
}
364
383
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)
370
389
/* wait for CID spill in dahdi_read (as opposed to calling send_caller directly */
371
390
if (ast_safe_sleep (chan , sas ? 300 + 85 : 85 )) {
372
391
ast_debug (1 , "ast_safe_sleep returned -1\n" );
392
+ pbx_builtin_setvar_helper (chan , var , "HANGUP" );
373
393
return -1 ;
374
394
}
375
395
/* chan_dahdi will free pvt->cidspill */
@@ -379,22 +399,26 @@ static int cwcid_exec(struct ast_channel *chan, const char *data)
379
399
380
400
if (ast_set_write_format (chan , ast_format_ulaw )) {
381
401
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" );
382
403
return -1 ;
383
404
}
384
405
if (ast_set_read_format (chan , ast_format_ulaw )) {
385
406
ast_log (LOG_WARNING , "Unable to set read format to ULAW\n" );
407
+ pbx_builtin_setvar_helper (chan , var , "FAILURE" );
386
408
return -1 ;
387
409
}
388
410
389
411
if (!(cidspill = ast_malloc ((sas ? 2400 + 680 : 680 ) + READ_SIZE * 4 ))) {
390
412
ast_log (LOG_WARNING , "Failed to malloc cidspill\n" );
413
+ pbx_builtin_setvar_helper (chan , var , "FAILURE" );
391
414
return -1 ;
392
415
}
393
416
ast_gen_cas (cidspill , sas , sas ? 2400 + 680 : 680 , ast_format_ulaw );
394
417
395
418
if (cwcid_careful_send (chan , cidspill , sas ? 2400 + 680 : 680 , NULL )) {
396
419
ast_free (cidspill );
397
420
ast_log (LOG_WARNING , "Failed to write cidspill\n" );
421
+ pbx_builtin_setvar_helper (chan , var , "FAILURE" );
398
422
return -1 ;
399
423
}
400
424
ast_free (cidspill );
@@ -404,10 +428,12 @@ static int cwcid_exec(struct ast_channel *chan, const char *data)
404
428
res = await_ack (chan , 500 ); /* wait up to 500ms for ACK */
405
429
if (res == -1 ) {
406
430
ast_debug (1 , "await_ack returned -1\n" );
431
+ pbx_builtin_setvar_helper (chan , var , "HANGUP" );
407
432
return -1 ;
408
433
}
409
434
if (ack ) { /* make sure we got the ACK, if we're supposed to check */
410
435
if (res != 'A' && res != 'D' ) {
436
+ pbx_builtin_setvar_helper (chan , var , "UNSUPPORTED" );
411
437
return 0 ; /* Didn't get ACK, abort. */
412
438
}
413
439
}
@@ -418,6 +444,7 @@ static int cwcid_exec(struct ast_channel *chan, const char *data)
418
444
while (pvt -> cidspill ) { /* shouldn't happen */
419
445
ast_debug (1 , "Waiting for cidspill to finish\n" );
420
446
if (ast_safe_sleep (chan , 10 )) { /* try not to busy wait */
447
+ pbx_builtin_setvar_helper (chan , var , "HANGUP" );
421
448
return -1 ;
422
449
}
423
450
}
@@ -426,6 +453,7 @@ static int cwcid_exec(struct ast_channel *chan, const char *data)
426
453
if (!(pvt -> cidspill = ast_malloc (MAX_CALLERID_SIZE ))) {
427
454
ast_channel_unlock (chan );
428
455
ast_log (LOG_WARNING , "Failed to malloc cidspill\n" );
456
+ pbx_builtin_setvar_helper (chan , var , "FAILURE" );
429
457
return -1 ;
430
458
}
431
459
/* similar to my_send_callerid in chan_dahdi.c: */
@@ -447,11 +475,13 @@ static int cwcid_exec(struct ast_channel *chan, const char *data)
447
475
448
476
/* wait for CID spill in dahdi_read (as opposed to calling send_caller directly */
449
477
if (ast_safe_sleep (chan , pvt -> cidlen / 8 )) {
478
+ pbx_builtin_setvar_helper (chan , var , "HANGUP" );
450
479
return -1 ;
451
480
}
452
481
while (pvt -> cidspill ) { /* shouldn't happen */
453
482
ast_debug (1 , "Waiting for cidspill to finish\n" );
454
483
if (ast_safe_sleep (chan , 10 )) { /* try not to busy wait */
484
+ pbx_builtin_setvar_helper (chan , var , "HANGUP" );
455
485
return -1 ;
456
486
}
457
487
}
@@ -463,6 +493,7 @@ static int cwcid_exec(struct ast_channel *chan, const char *data)
463
493
464
494
if (!(cidspill = ast_malloc (MAX_CALLERID_SIZE ))) {
465
495
ast_log (LOG_WARNING , "Failed to malloc cidspill\n" );
496
+ pbx_builtin_setvar_helper (chan , var , "FAILURE" );
466
497
return -1 ;
467
498
}
468
499
cidlen = ast_callerid_callwaiting_full_tz_generate (cidspill ,
@@ -476,12 +507,14 @@ static int cwcid_exec(struct ast_channel *chan, const char *data)
476
507
tz );
477
508
if (cwcid_careful_send (chan , cidspill , cidlen , NULL )) {
478
509
ast_log (LOG_WARNING , "Failed to write cidspill\n" );
510
+ pbx_builtin_setvar_helper (chan , var , "FAILURE" );
479
511
res = -1 ;
480
512
}
481
513
ast_free (cidspill );
482
514
}
483
515
484
516
ast_debug (1 , "res is %d\n" , res );
517
+ pbx_builtin_setvar_helper (chan , var , res ? "FAILURE" : "SUCCESS" );
485
518
486
519
return res ;
487
520
}
0 commit comments