00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033 #include "asterisk.h"
00034
00035 ASTERISK_FILE_VERSION(__FILE__, "$Revision: 290614 $")
00036
00037 #include <sys/time.h>
00038 #include <sys/signal.h>
00039 #include <sys/stat.h>
00040 #include <netinet/in.h>
00041
00042 #include "asterisk/paths.h"
00043 #include "asterisk/lock.h"
00044 #include "asterisk/file.h"
00045 #include "asterisk/channel.h"
00046 #include "asterisk/pbx.h"
00047 #include "asterisk/module.h"
00048 #include "asterisk/translate.h"
00049 #include "asterisk/say.h"
00050 #include "asterisk/config.h"
00051 #include "asterisk/features.h"
00052 #include "asterisk/musiconhold.h"
00053 #include "asterisk/callerid.h"
00054 #include "asterisk/utils.h"
00055 #include "asterisk/app.h"
00056 #include "asterisk/causes.h"
00057 #include "asterisk/rtp_engine.h"
00058 #include "asterisk/cdr.h"
00059 #include "asterisk/manager.h"
00060 #include "asterisk/privacy.h"
00061 #include "asterisk/stringfields.h"
00062 #include "asterisk/global_datastores.h"
00063 #include "asterisk/dsp.h"
00064 #include "asterisk/cel.h"
00065 #include "asterisk/aoc.h"
00066 #include "asterisk/ccss.h"
00067 #include "asterisk/indications.h"
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152
00153
00154
00155
00156
00157
00158
00159
00160
00161
00162
00163
00164
00165
00166
00167
00168
00169
00170
00171
00172
00173
00174
00175
00176
00177
00178
00179
00180
00181
00182
00183
00184
00185
00186
00187
00188
00189
00190
00191
00192
00193
00194
00195
00196
00197
00198
00199
00200
00201
00202
00203
00204
00205
00206
00207
00208
00209
00210
00211
00212
00213
00214
00215
00216
00217
00218
00219
00220
00221
00222
00223
00224
00225
00226
00227
00228
00229
00230
00231
00232
00233
00234
00235
00236
00237
00238
00239
00240
00241
00242
00243
00244
00245
00246
00247
00248
00249
00250
00251
00252
00253
00254
00255
00256
00257
00258
00259
00260
00261
00262
00263
00264
00265
00266
00267
00268
00269
00270
00271
00272
00273
00274
00275
00276
00277
00278
00279
00280
00281
00282
00283
00284
00285
00286
00287
00288
00289
00290
00291
00292
00293
00294
00295
00296
00297
00298
00299
00300
00301
00302
00303
00304
00305
00306
00307
00308
00309
00310
00311
00312
00313
00314
00315
00316
00317
00318
00319
00320
00321
00322
00323
00324
00325
00326
00327
00328
00329
00330
00331
00332
00333
00334
00335
00336
00337
00338
00339
00340
00341
00342
00343
00344
00345
00346
00347
00348
00349
00350
00351
00352
00353
00354
00355
00356
00357
00358
00359
00360
00361
00362
00363
00364
00365
00366
00367
00368
00369
00370
00371
00372
00373
00374
00375
00376
00377
00378
00379
00380
00381
00382
00383
00384
00385
00386
00387
00388
00389
00390
00391
00392
00393
00394
00395
00396
00397
00398
00399
00400
00401
00402
00403
00404
00405
00406
00407
00408
00409
00410
00411
00412
00413
00414
00415
00416
00417
00418
00419
00420
00421
00422
00423
00424
00425
00426
00427
00428
00429
00430
00431
00432
00433
00434
00435
00436
00437
00438
00439
00440
00441
00442
00443
00444
00445
00446
00447
00448
00449
00450
00451
00452
00453
00454
00455
00456
00457
00458
00459
00460
00461
00462
00463
00464
00465
00466
00467
00468
00469
00470
00471
00472
00473
00474
00475
00476
00477
00478
00479
00480
00481
00482
00483
00484
00485
00486
00487
00488
00489
00490
00491
00492
00493
00494
00495
00496
00497
00498
00499
00500
00501
00502
00503
00504
00505
00506
00507
00508
00509
00510
00511
00512
00513
00514
00515 static const char app[] = "Dial";
00516 static const char rapp[] = "RetryDial";
00517
00518 enum {
00519 OPT_ANNOUNCE = (1 << 0),
00520 OPT_RESETCDR = (1 << 1),
00521 OPT_DTMF_EXIT = (1 << 2),
00522 OPT_SENDDTMF = (1 << 3),
00523 OPT_FORCECLID = (1 << 4),
00524 OPT_GO_ON = (1 << 5),
00525 OPT_CALLEE_HANGUP = (1 << 6),
00526 OPT_CALLER_HANGUP = (1 << 7),
00527 OPT_ORIGINAL_CLID = (1 << 8),
00528 OPT_DURATION_LIMIT = (1 << 9),
00529 OPT_MUSICBACK = (1 << 10),
00530 OPT_CALLEE_MACRO = (1 << 11),
00531 OPT_SCREEN_NOINTRO = (1 << 12),
00532 OPT_SCREEN_NOCALLERID = (1 << 13),
00533 OPT_IGNORE_CONNECTEDLINE = (1 << 14),
00534 OPT_SCREENING = (1 << 15),
00535 OPT_PRIVACY = (1 << 16),
00536 OPT_RINGBACK = (1 << 17),
00537 OPT_DURATION_STOP = (1 << 18),
00538 OPT_CALLEE_TRANSFER = (1 << 19),
00539 OPT_CALLER_TRANSFER = (1 << 20),
00540 OPT_CALLEE_MONITOR = (1 << 21),
00541 OPT_CALLER_MONITOR = (1 << 22),
00542 OPT_GOTO = (1 << 23),
00543 OPT_OPERMODE = (1 << 24),
00544 OPT_CALLEE_PARK = (1 << 25),
00545 OPT_CALLER_PARK = (1 << 26),
00546 OPT_IGNORE_FORWARDING = (1 << 27),
00547 OPT_CALLEE_GOSUB = (1 << 28),
00548 OPT_CALLEE_MIXMONITOR = (1 << 29),
00549 OPT_CALLER_MIXMONITOR = (1 << 30),
00550 OPT_CALLER_ANSWER = (1 << 31),
00551 };
00552
00553 #define DIAL_STILLGOING (1 << 31)
00554 #define DIAL_NOFORWARDHTML ((uint64_t)1 << 32)
00555 #define DIAL_CALLERID_ABSENT ((uint64_t)1 << 33)
00556 #define OPT_CANCEL_ELSEWHERE ((uint64_t)1 << 34)
00557 #define OPT_PEER_H ((uint64_t)1 << 35)
00558 #define OPT_CALLEE_GO_ON ((uint64_t)1 << 36)
00559 #define OPT_CANCEL_TIMEOUT ((uint64_t)1 << 37)
00560 #define OPT_FORCE_CID_TAG ((uint64_t)1 << 38)
00561 #define OPT_FORCE_CID_PRES ((uint64_t)1 << 39)
00562
00563 enum {
00564 OPT_ARG_ANNOUNCE = 0,
00565 OPT_ARG_SENDDTMF,
00566 OPT_ARG_GOTO,
00567 OPT_ARG_DURATION_LIMIT,
00568 OPT_ARG_MUSICBACK,
00569 OPT_ARG_CALLEE_MACRO,
00570 OPT_ARG_RINGBACK,
00571 OPT_ARG_CALLEE_GOSUB,
00572 OPT_ARG_CALLEE_GO_ON,
00573 OPT_ARG_PRIVACY,
00574 OPT_ARG_DURATION_STOP,
00575 OPT_ARG_OPERMODE,
00576 OPT_ARG_SCREEN_NOINTRO,
00577 OPT_ARG_FORCECLID,
00578 OPT_ARG_FORCE_CID_TAG,
00579 OPT_ARG_FORCE_CID_PRES,
00580
00581 OPT_ARG_ARRAY_SIZE,
00582 };
00583
00584 AST_APP_OPTIONS(dial_exec_options, BEGIN_OPTIONS
00585 AST_APP_OPTION_ARG('A', OPT_ANNOUNCE, OPT_ARG_ANNOUNCE),
00586 AST_APP_OPTION('a', OPT_CALLER_ANSWER),
00587 AST_APP_OPTION('C', OPT_RESETCDR),
00588 AST_APP_OPTION('c', OPT_CANCEL_ELSEWHERE),
00589 AST_APP_OPTION('d', OPT_DTMF_EXIT),
00590 AST_APP_OPTION_ARG('D', OPT_SENDDTMF, OPT_ARG_SENDDTMF),
00591 AST_APP_OPTION('e', OPT_PEER_H),
00592 AST_APP_OPTION_ARG('f', OPT_FORCECLID, OPT_ARG_FORCECLID),
00593 AST_APP_OPTION_ARG('F', OPT_CALLEE_GO_ON, OPT_ARG_CALLEE_GO_ON),
00594 AST_APP_OPTION('g', OPT_GO_ON),
00595 AST_APP_OPTION_ARG('G', OPT_GOTO, OPT_ARG_GOTO),
00596 AST_APP_OPTION('h', OPT_CALLEE_HANGUP),
00597 AST_APP_OPTION('H', OPT_CALLER_HANGUP),
00598 AST_APP_OPTION('i', OPT_IGNORE_FORWARDING),
00599 AST_APP_OPTION('I', OPT_IGNORE_CONNECTEDLINE),
00600 AST_APP_OPTION('k', OPT_CALLEE_PARK),
00601 AST_APP_OPTION('K', OPT_CALLER_PARK),
00602 AST_APP_OPTION_ARG('L', OPT_DURATION_LIMIT, OPT_ARG_DURATION_LIMIT),
00603 AST_APP_OPTION_ARG('m', OPT_MUSICBACK, OPT_ARG_MUSICBACK),
00604 AST_APP_OPTION_ARG('M', OPT_CALLEE_MACRO, OPT_ARG_CALLEE_MACRO),
00605 AST_APP_OPTION_ARG('n', OPT_SCREEN_NOINTRO, OPT_ARG_SCREEN_NOINTRO),
00606 AST_APP_OPTION('N', OPT_SCREEN_NOCALLERID),
00607 AST_APP_OPTION('o', OPT_ORIGINAL_CLID),
00608 AST_APP_OPTION_ARG('O', OPT_OPERMODE, OPT_ARG_OPERMODE),
00609 AST_APP_OPTION('p', OPT_SCREENING),
00610 AST_APP_OPTION_ARG('P', OPT_PRIVACY, OPT_ARG_PRIVACY),
00611 AST_APP_OPTION_ARG('r', OPT_RINGBACK, OPT_ARG_RINGBACK),
00612 AST_APP_OPTION_ARG('S', OPT_DURATION_STOP, OPT_ARG_DURATION_STOP),
00613 AST_APP_OPTION_ARG('s', OPT_FORCE_CID_TAG, OPT_ARG_FORCE_CID_TAG),
00614 AST_APP_OPTION_ARG('u', OPT_FORCE_CID_PRES, OPT_ARG_FORCE_CID_PRES),
00615 AST_APP_OPTION('t', OPT_CALLEE_TRANSFER),
00616 AST_APP_OPTION('T', OPT_CALLER_TRANSFER),
00617 AST_APP_OPTION_ARG('U', OPT_CALLEE_GOSUB, OPT_ARG_CALLEE_GOSUB),
00618 AST_APP_OPTION('w', OPT_CALLEE_MONITOR),
00619 AST_APP_OPTION('W', OPT_CALLER_MONITOR),
00620 AST_APP_OPTION('x', OPT_CALLEE_MIXMONITOR),
00621 AST_APP_OPTION('X', OPT_CALLER_MIXMONITOR),
00622 AST_APP_OPTION('z', OPT_CANCEL_TIMEOUT),
00623 END_OPTIONS );
00624
00625 #define CAN_EARLY_BRIDGE(flags,chan,peer) (!ast_test_flag64(flags, OPT_CALLEE_HANGUP | \
00626 OPT_CALLER_HANGUP | OPT_CALLEE_TRANSFER | OPT_CALLER_TRANSFER | \
00627 OPT_CALLEE_MONITOR | OPT_CALLER_MONITOR | OPT_CALLEE_PARK | \
00628 OPT_CALLER_PARK | OPT_ANNOUNCE | OPT_CALLEE_MACRO | OPT_CALLEE_GOSUB) && \
00629 !chan->audiohooks && !peer->audiohooks)
00630
00631
00632
00633
00634 struct chanlist {
00635 struct chanlist *next;
00636 struct ast_channel *chan;
00637 uint64_t flags;
00638
00639 struct ast_party_connected_line connected;
00640
00641 unsigned int pending_connected_update:1;
00642 struct ast_aoc_decoded *aoc_s_rate_list;
00643 };
00644
00645 static int detect_disconnect(struct ast_channel *chan, char code, struct ast_str *featurecode);
00646
00647 static void chanlist_free(struct chanlist *outgoing)
00648 {
00649 ast_party_connected_line_free(&outgoing->connected);
00650 ast_aoc_destroy_decoded(outgoing->aoc_s_rate_list);
00651 ast_free(outgoing);
00652 }
00653
00654 static void hanguptree(struct chanlist *outgoing, struct ast_channel *exception, int answered_elsewhere)
00655 {
00656
00657 struct chanlist *oo;
00658 while (outgoing) {
00659
00660 if (outgoing->chan && (outgoing->chan != exception)) {
00661 if (answered_elsewhere) {
00662
00663 ast_set_flag(outgoing->chan, AST_FLAG_ANSWERED_ELSEWHERE);
00664
00665 outgoing->chan->hangupcause = AST_CAUSE_ANSWERED_ELSEWHERE;
00666 }
00667 ast_hangup(outgoing->chan);
00668 }
00669 oo = outgoing;
00670 outgoing = outgoing->next;
00671 chanlist_free(oo);
00672 }
00673 }
00674
00675 #define AST_MAX_WATCHERS 256
00676
00677
00678
00679
00680 struct cause_args {
00681 struct ast_channel *chan;
00682 int busy;
00683 int congestion;
00684 int nochan;
00685 };
00686
00687 static void handle_cause(int cause, struct cause_args *num)
00688 {
00689 struct ast_cdr *cdr = num->chan->cdr;
00690
00691 switch(cause) {
00692 case AST_CAUSE_BUSY:
00693 if (cdr)
00694 ast_cdr_busy(cdr);
00695 num->busy++;
00696 break;
00697
00698 case AST_CAUSE_CONGESTION:
00699 if (cdr)
00700 ast_cdr_failed(cdr);
00701 num->congestion++;
00702 break;
00703
00704 case AST_CAUSE_NO_ROUTE_DESTINATION:
00705 case AST_CAUSE_UNREGISTERED:
00706 if (cdr)
00707 ast_cdr_failed(cdr);
00708 num->nochan++;
00709 break;
00710
00711 case AST_CAUSE_NO_ANSWER:
00712 if (cdr) {
00713 ast_cdr_noanswer(cdr);
00714 }
00715 break;
00716 case AST_CAUSE_NORMAL_CLEARING:
00717 break;
00718
00719 default:
00720 num->nochan++;
00721 break;
00722 }
00723 }
00724
00725 static int onedigit_goto(struct ast_channel *chan, const char *context, char exten, int pri)
00726 {
00727 char rexten[2] = { exten, '\0' };
00728
00729 if (context) {
00730 if (!ast_goto_if_exists(chan, context, rexten, pri))
00731 return 1;
00732 } else {
00733 if (!ast_goto_if_exists(chan, chan->context, rexten, pri))
00734 return 1;
00735 else if (!ast_strlen_zero(chan->macrocontext)) {
00736 if (!ast_goto_if_exists(chan, chan->macrocontext, rexten, pri))
00737 return 1;
00738 }
00739 }
00740 return 0;
00741 }
00742
00743
00744 static const char *get_cid_name(char *name, int namelen, struct ast_channel *chan)
00745 {
00746 const char *context;
00747 const char *exten;
00748
00749 ast_channel_lock(chan);
00750 context = ast_strdupa(S_OR(chan->macrocontext, chan->context));
00751 exten = ast_strdupa(S_OR(chan->macroexten, chan->exten));
00752 ast_channel_unlock(chan);
00753
00754 return ast_get_hint(NULL, 0, name, namelen, chan, context, exten) ? name : "";
00755 }
00756
00757 static void senddialevent(struct ast_channel *src, struct ast_channel *dst, const char *dialstring)
00758 {
00759 struct ast_channel *chans[] = { src, dst };
00760 ast_manager_event_multichan(EVENT_FLAG_CALL, "Dial", 2, chans,
00761 "SubEvent: Begin\r\n"
00762 "Channel: %s\r\n"
00763 "Destination: %s\r\n"
00764 "CallerIDNum: %s\r\n"
00765 "CallerIDName: %s\r\n"
00766 "UniqueID: %s\r\n"
00767 "DestUniqueID: %s\r\n"
00768 "Dialstring: %s\r\n",
00769 src->name, dst->name,
00770 S_COR(src->caller.id.number.valid, src->caller.id.number.str, "<unknown>"),
00771 S_COR(src->caller.id.name.valid, src->caller.id.name.str, "<unknown>"),
00772 src->uniqueid, dst->uniqueid,
00773 dialstring ? dialstring : "");
00774 }
00775
00776 static void senddialendevent(struct ast_channel *src, const char *dialstatus)
00777 {
00778 ast_manager_event(src, EVENT_FLAG_CALL, "Dial",
00779 "SubEvent: End\r\n"
00780 "Channel: %s\r\n"
00781 "UniqueID: %s\r\n"
00782 "DialStatus: %s\r\n",
00783 src->name, src->uniqueid, dialstatus);
00784 }
00785
00786
00787
00788
00789
00790
00791
00792
00793
00794 static void do_forward(struct chanlist *o,
00795 struct cause_args *num, struct ast_flags64 *peerflags, int single, int *to)
00796 {
00797 char tmpchan[256];
00798 struct ast_channel *original = o->chan;
00799 struct ast_channel *c = o->chan;
00800 struct ast_channel *in = num->chan;
00801 char *stuff;
00802 char *tech;
00803 int cause;
00804
00805 ast_copy_string(tmpchan, c->call_forward, sizeof(tmpchan));
00806 if ((stuff = strchr(tmpchan, '/'))) {
00807 *stuff++ = '\0';
00808 tech = tmpchan;
00809 } else {
00810 const char *forward_context;
00811 ast_channel_lock(c);
00812 forward_context = pbx_builtin_getvar_helper(c, "FORWARD_CONTEXT");
00813 if (ast_strlen_zero(forward_context)) {
00814 forward_context = NULL;
00815 }
00816 snprintf(tmpchan, sizeof(tmpchan), "%s@%s", c->call_forward, forward_context ? forward_context : c->context);
00817 ast_channel_unlock(c);
00818 stuff = tmpchan;
00819 tech = "Local";
00820 }
00821
00822 ast_cel_report_event(in, AST_CEL_FORWARD, NULL, c->call_forward, NULL);
00823
00824
00825 ast_verb(3, "Now forwarding %s to '%s/%s' (thanks to %s)\n", in->name, tech, stuff, c->name);
00826
00827 if (ast_test_flag64(peerflags, OPT_IGNORE_FORWARDING)) {
00828 ast_verb(3, "Forwarding %s to '%s/%s' prevented.\n", in->name, tech, stuff);
00829 c = o->chan = NULL;
00830 cause = AST_CAUSE_BUSY;
00831 } else {
00832
00833 c = o->chan = ast_request(tech, in->nativeformats, in, stuff, &cause);
00834 if (c) {
00835 if (single)
00836 ast_channel_make_compatible(o->chan, in);
00837 ast_channel_inherit_variables(in, o->chan);
00838 ast_channel_datastore_inherit(in, o->chan);
00839
00840
00841
00842
00843 ast_ignore_cc(o->chan);
00844 ast_log(LOG_NOTICE, "Not accepting call completion offers from call-forward recipient %s\n", o->chan->name);
00845 } else
00846 ast_log(LOG_NOTICE,
00847 "Forwarding failed to create channel to dial '%s/%s' (cause = %d)\n",
00848 tech, stuff, cause);
00849 }
00850 if (!c) {
00851 ast_clear_flag64(o, DIAL_STILLGOING);
00852 handle_cause(cause, num);
00853 ast_hangup(original);
00854 } else {
00855 struct ast_party_redirecting redirecting;
00856
00857 if (single && CAN_EARLY_BRIDGE(peerflags, c, in)) {
00858 ast_rtp_instance_early_bridge_make_compatible(c, in);
00859 }
00860
00861 ast_channel_set_redirecting(c, &original->redirecting, NULL);
00862 ast_channel_lock(c);
00863 while (ast_channel_trylock(in)) {
00864 CHANNEL_DEADLOCK_AVOIDANCE(c);
00865 }
00866 if (!c->redirecting.from.number.valid
00867 || ast_strlen_zero(c->redirecting.from.number.str)) {
00868
00869
00870
00871
00872 ast_party_number_free(&c->redirecting.from.number);
00873 ast_party_number_init(&c->redirecting.from.number);
00874 c->redirecting.from.number.valid = 1;
00875 c->redirecting.from.number.str =
00876 ast_strdup(S_OR(in->macroexten, in->exten));
00877 }
00878
00879 c->dialed.transit_network_select = in->dialed.transit_network_select;
00880
00881 if (ast_test_flag64(o, OPT_FORCECLID)) {
00882 ast_party_id_free(&c->caller.id);
00883 ast_party_id_init(&c->caller.id);
00884 c->caller.id.number.valid = 1;
00885 c->caller.id.number.str = ast_strdup(S_OR(in->macroexten, in->exten));
00886 ast_string_field_set(c, accountcode, c->accountcode);
00887 } else {
00888 ast_party_caller_copy(&c->caller, &in->caller);
00889 ast_string_field_set(c, accountcode, in->accountcode);
00890 }
00891 ast_party_connected_line_copy(&c->connected, &original->connected);
00892 c->appl = "AppDial";
00893 c->data = "(Outgoing Line)";
00894
00895
00896
00897
00898
00899
00900 ast_party_redirecting_init(&redirecting);
00901 ast_party_redirecting_copy(&redirecting, &c->redirecting);
00902 ast_channel_unlock(c);
00903 if (ast_channel_redirecting_macro(c, in, &redirecting, 1, 0)) {
00904 ast_channel_update_redirecting(in, &redirecting, NULL);
00905 }
00906 ast_party_redirecting_free(&redirecting);
00907 ast_channel_unlock(in);
00908
00909 ast_clear_flag64(peerflags, OPT_IGNORE_CONNECTEDLINE);
00910 if (ast_test_flag64(peerflags, OPT_CANCEL_TIMEOUT)) {
00911 *to = -1;
00912 }
00913
00914 if (ast_call(c, stuff, 0)) {
00915 ast_log(LOG_NOTICE, "Forwarding failed to dial '%s/%s'\n",
00916 tech, stuff);
00917 ast_clear_flag64(o, DIAL_STILLGOING);
00918 ast_hangup(original);
00919 ast_hangup(c);
00920 c = o->chan = NULL;
00921 num->nochan++;
00922 } else {
00923 ast_channel_lock(c);
00924 while (ast_channel_trylock(in)) {
00925 CHANNEL_DEADLOCK_AVOIDANCE(c);
00926 }
00927 senddialevent(in, c, stuff);
00928 if (!ast_test_flag64(peerflags, OPT_ORIGINAL_CLID)) {
00929 char cidname[AST_MAX_EXTENSION] = "";
00930 const char *tmpexten;
00931 tmpexten = ast_strdupa(S_OR(in->macroexten, in->exten));
00932 ast_channel_unlock(in);
00933 ast_channel_unlock(c);
00934 ast_set_callerid(c, tmpexten, get_cid_name(cidname, sizeof(cidname), in), NULL);
00935 } else {
00936 ast_channel_unlock(in);
00937 ast_channel_unlock(c);
00938 }
00939
00940 ast_hangup(original);
00941 }
00942 if (single) {
00943 ast_indicate(in, -1);
00944 }
00945 }
00946 }
00947
00948
00949 struct privacy_args {
00950 int sentringing;
00951 int privdb_val;
00952 char privcid[256];
00953 char privintro[1024];
00954 char status[256];
00955 };
00956
00957 static struct ast_channel *wait_for_answer(struct ast_channel *in,
00958 struct chanlist *outgoing, int *to, struct ast_flags64 *peerflags,
00959 char *opt_args[],
00960 struct privacy_args *pa,
00961 const struct cause_args *num_in, int *result, char *dtmf_progress,
00962 const int ignore_cc)
00963 {
00964 struct cause_args num = *num_in;
00965 int prestart = num.busy + num.congestion + num.nochan;
00966 int orig = *to;
00967 struct ast_channel *peer = NULL;
00968
00969 int single = outgoing && !outgoing->next;
00970 #ifdef HAVE_EPOLL
00971 struct chanlist *epollo;
00972 #endif
00973 struct ast_party_connected_line connected_caller;
00974 struct ast_str *featurecode = ast_str_alloca(FEATURE_MAX_LEN + 1);
00975 int cc_recall_core_id;
00976 int is_cc_recall;
00977 int cc_frame_received = 0;
00978 int num_ringing = 0;
00979
00980 ast_party_connected_line_init(&connected_caller);
00981 if (single) {
00982
00983 if (!ast_test_flag64(outgoing, OPT_MUSICBACK | OPT_RINGBACK)) {
00984 ast_deactivate_generator(in);
00985
00986
00987 ast_channel_make_compatible(outgoing->chan, in);
00988 }
00989
00990 if (!ast_test_flag64(peerflags, OPT_IGNORE_CONNECTEDLINE) && !ast_test_flag64(outgoing, DIAL_CALLERID_ABSENT)) {
00991 ast_channel_lock(outgoing->chan);
00992 ast_connected_line_copy_from_caller(&connected_caller, &outgoing->chan->caller);
00993 ast_channel_unlock(outgoing->chan);
00994 connected_caller.source = AST_CONNECTED_LINE_UPDATE_SOURCE_ANSWER;
00995 ast_channel_update_connected_line(in, &connected_caller, NULL);
00996 ast_party_connected_line_free(&connected_caller);
00997 }
00998 }
00999
01000 is_cc_recall = ast_cc_is_recall(in, &cc_recall_core_id, NULL);
01001
01002 #ifdef HAVE_EPOLL
01003 for (epollo = outgoing; epollo; epollo = epollo->next)
01004 ast_poll_channel_add(in, epollo->chan);
01005 #endif
01006
01007 while (*to && !peer) {
01008 struct chanlist *o;
01009 int pos = 0;
01010 int numlines = prestart;
01011 struct ast_channel *winner;
01012 struct ast_channel *watchers[AST_MAX_WATCHERS];
01013
01014 watchers[pos++] = in;
01015 for (o = outgoing; o; o = o->next) {
01016
01017 if (ast_test_flag64(o, DIAL_STILLGOING) && o->chan)
01018 watchers[pos++] = o->chan;
01019 numlines++;
01020 }
01021 if (pos == 1) {
01022 if (numlines == (num.busy + num.congestion + num.nochan)) {
01023 ast_verb(2, "Everyone is busy/congested at this time (%d:%d/%d/%d)\n", numlines, num.busy, num.congestion, num.nochan);
01024 if (num.busy)
01025 strcpy(pa->status, "BUSY");
01026 else if (num.congestion)
01027 strcpy(pa->status, "CONGESTION");
01028 else if (num.nochan)
01029 strcpy(pa->status, "CHANUNAVAIL");
01030 } else {
01031 ast_verb(3, "No one is available to answer at this time (%d:%d/%d/%d)\n", numlines, num.busy, num.congestion, num.nochan);
01032 }
01033 *to = 0;
01034 if (is_cc_recall) {
01035 ast_cc_failed(cc_recall_core_id, "Everyone is busy/congested for the recall. How sad");
01036 }
01037 return NULL;
01038 }
01039 winner = ast_waitfor_n(watchers, pos, to);
01040 for (o = outgoing; o; o = o->next) {
01041 struct ast_frame *f;
01042 struct ast_channel *c = o->chan;
01043
01044 if (c == NULL)
01045 continue;
01046 if (ast_test_flag64(o, DIAL_STILLGOING) && c->_state == AST_STATE_UP) {
01047 if (!peer) {
01048 ast_verb(3, "%s answered %s\n", c->name, in->name);
01049 if (!single && !ast_test_flag64(peerflags, OPT_IGNORE_CONNECTEDLINE)) {
01050 if (o->pending_connected_update) {
01051 if (ast_channel_connected_line_macro(c, in, &o->connected, 1, 0)) {
01052 ast_channel_update_connected_line(in, &o->connected, NULL);
01053 }
01054 } else if (!ast_test_flag64(o, DIAL_CALLERID_ABSENT)) {
01055 ast_channel_lock(c);
01056 ast_connected_line_copy_from_caller(&connected_caller, &c->caller);
01057 ast_channel_unlock(c);
01058 connected_caller.source = AST_CONNECTED_LINE_UPDATE_SOURCE_ANSWER;
01059 ast_channel_update_connected_line(in, &connected_caller, NULL);
01060 ast_party_connected_line_free(&connected_caller);
01061 }
01062 }
01063 if (o->aoc_s_rate_list) {
01064 size_t encoded_size;
01065 struct ast_aoc_encoded *encoded;
01066 if ((encoded = ast_aoc_encode(o->aoc_s_rate_list, &encoded_size, o->chan))) {
01067 ast_indicate_data(in, AST_CONTROL_AOC, encoded, encoded_size);
01068 ast_aoc_destroy_encoded(encoded);
01069 }
01070 }
01071 peer = c;
01072 ast_copy_flags64(peerflags, o,
01073 OPT_CALLEE_TRANSFER | OPT_CALLER_TRANSFER |
01074 OPT_CALLEE_HANGUP | OPT_CALLER_HANGUP |
01075 OPT_CALLEE_MONITOR | OPT_CALLER_MONITOR |
01076 OPT_CALLEE_PARK | OPT_CALLER_PARK |
01077 OPT_CALLEE_MIXMONITOR | OPT_CALLER_MIXMONITOR |
01078 DIAL_NOFORWARDHTML);
01079 ast_string_field_set(c, dialcontext, "");
01080 ast_copy_string(c->exten, "", sizeof(c->exten));
01081 }
01082 continue;
01083 }
01084 if (c != winner)
01085 continue;
01086
01087 if (!ast_strlen_zero(c->call_forward)) {
01088 pa->sentringing = 0;
01089 if (!ignore_cc && (f = ast_read(c))) {
01090 if (f->frametype == AST_FRAME_CONTROL && f->subclass.integer == AST_CONTROL_CC) {
01091
01092
01093
01094 ast_handle_cc_control_frame(in, c, f->data.ptr);
01095 }
01096 ast_frfree(f);
01097 }
01098 do_forward(o, &num, peerflags, single, to);
01099 continue;
01100 }
01101 f = ast_read(winner);
01102 if (!f) {
01103 in->hangupcause = c->hangupcause;
01104 #ifdef HAVE_EPOLL
01105 ast_poll_channel_del(in, c);
01106 #endif
01107 ast_hangup(c);
01108 c = o->chan = NULL;
01109 ast_clear_flag64(o, DIAL_STILLGOING);
01110 handle_cause(in->hangupcause, &num);
01111 continue;
01112 }
01113 if (f->frametype == AST_FRAME_CONTROL) {
01114 switch (f->subclass.integer) {
01115 case AST_CONTROL_ANSWER:
01116
01117 if (!peer) {
01118 ast_verb(3, "%s answered %s\n", c->name, in->name);
01119 if (!single && !ast_test_flag64(peerflags, OPT_IGNORE_CONNECTEDLINE)) {
01120 if (o->pending_connected_update) {
01121 if (ast_channel_connected_line_macro(c, in, &o->connected, 1, 0)) {
01122 ast_channel_update_connected_line(in, &o->connected, NULL);
01123 }
01124 } else if (!ast_test_flag64(o, DIAL_CALLERID_ABSENT)) {
01125 ast_channel_lock(c);
01126 ast_connected_line_copy_from_caller(&connected_caller, &c->caller);
01127 ast_channel_unlock(c);
01128 connected_caller.source = AST_CONNECTED_LINE_UPDATE_SOURCE_ANSWER;
01129 ast_channel_update_connected_line(in, &connected_caller, NULL);
01130 ast_party_connected_line_free(&connected_caller);
01131 }
01132 }
01133 if (o->aoc_s_rate_list) {
01134 size_t encoded_size;
01135 struct ast_aoc_encoded *encoded;
01136 if ((encoded = ast_aoc_encode(o->aoc_s_rate_list, &encoded_size, o->chan))) {
01137 ast_indicate_data(in, AST_CONTROL_AOC, encoded, encoded_size);
01138 ast_aoc_destroy_encoded(encoded);
01139 }
01140 }
01141 peer = c;
01142 if (peer->cdr) {
01143 peer->cdr->answer = ast_tvnow();
01144 peer->cdr->disposition = AST_CDR_ANSWERED;
01145 }
01146 ast_copy_flags64(peerflags, o,
01147 OPT_CALLEE_TRANSFER | OPT_CALLER_TRANSFER |
01148 OPT_CALLEE_HANGUP | OPT_CALLER_HANGUP |
01149 OPT_CALLEE_MONITOR | OPT_CALLER_MONITOR |
01150 OPT_CALLEE_PARK | OPT_CALLER_PARK |
01151 OPT_CALLEE_MIXMONITOR | OPT_CALLER_MIXMONITOR |
01152 DIAL_NOFORWARDHTML);
01153 ast_string_field_set(c, dialcontext, "");
01154 ast_copy_string(c->exten, "", sizeof(c->exten));
01155 if (CAN_EARLY_BRIDGE(peerflags, in, peer))
01156
01157 ast_channel_early_bridge(in, peer);
01158 }
01159
01160 in->hangupcause = AST_CAUSE_NORMAL_CLEARING;
01161 c->hangupcause = AST_CAUSE_NORMAL_CLEARING;
01162 break;
01163 case AST_CONTROL_BUSY:
01164 ast_verb(3, "%s is busy\n", c->name);
01165 in->hangupcause = c->hangupcause;
01166 ast_hangup(c);
01167 c = o->chan = NULL;
01168 ast_clear_flag64(o, DIAL_STILLGOING);
01169 handle_cause(AST_CAUSE_BUSY, &num);
01170 break;
01171 case AST_CONTROL_CONGESTION:
01172 ast_verb(3, "%s is circuit-busy\n", c->name);
01173 in->hangupcause = c->hangupcause;
01174 ast_hangup(c);
01175 c = o->chan = NULL;
01176 ast_clear_flag64(o, DIAL_STILLGOING);
01177 handle_cause(AST_CAUSE_CONGESTION, &num);
01178 break;
01179 case AST_CONTROL_RINGING:
01180
01181
01182
01183
01184
01185
01186
01187
01188
01189
01190
01191
01192
01193
01194
01195
01196
01197
01198
01199
01200
01201
01202
01203
01204
01205 ++num_ringing;
01206 if (ignore_cc || cc_frame_received || num_ringing == numlines) {
01207 ast_verb(3, "%s is ringing\n", c->name);
01208
01209 if (single && CAN_EARLY_BRIDGE(peerflags, in, c))
01210 ast_channel_early_bridge(in, c);
01211 if (!(pa->sentringing) && !ast_test_flag64(outgoing, OPT_MUSICBACK) && ast_strlen_zero(opt_args[OPT_ARG_RINGBACK])) {
01212 ast_indicate(in, AST_CONTROL_RINGING);
01213 pa->sentringing++;
01214 }
01215 }
01216 break;
01217 case AST_CONTROL_PROGRESS:
01218 ast_verb(3, "%s is making progress passing it to %s\n", c->name, in->name);
01219
01220 if (single && CAN_EARLY_BRIDGE(peerflags, in, c))
01221 ast_channel_early_bridge(in, c);
01222 if (!ast_test_flag64(outgoing, OPT_RINGBACK))
01223 if (single || (!single && !pa->sentringing)) {
01224 ast_indicate(in, AST_CONTROL_PROGRESS);
01225 }
01226 if(!ast_strlen_zero(dtmf_progress)) {
01227 ast_verb(3, "Sending DTMF '%s' to the called party as result of receiving a PROGRESS message.\n", dtmf_progress);
01228 ast_dtmf_stream(c, in, dtmf_progress, 250, 0);
01229 }
01230 break;
01231 case AST_CONTROL_VIDUPDATE:
01232 ast_verb(3, "%s requested a video update, passing it to %s\n", c->name, in->name);
01233 ast_indicate(in, AST_CONTROL_VIDUPDATE);
01234 break;
01235 case AST_CONTROL_SRCUPDATE:
01236 ast_verb(3, "%s requested a source update, passing it to %s\n", c->name, in->name);
01237 ast_indicate(in, AST_CONTROL_SRCUPDATE);
01238 break;
01239 case AST_CONTROL_CONNECTED_LINE:
01240 if (ast_test_flag64(peerflags, OPT_IGNORE_CONNECTEDLINE)) {
01241 ast_verb(3, "Connected line update to %s prevented.\n", in->name);
01242 } else if (!single) {
01243 struct ast_party_connected_line connected;
01244 ast_verb(3, "%s connected line has changed. Saving it until answer for %s\n", c->name, in->name);
01245 ast_party_connected_line_set_init(&connected, &o->connected);
01246 ast_connected_line_parse_data(f->data.ptr, f->datalen, &connected);
01247 ast_party_connected_line_set(&o->connected, &connected, NULL);
01248 ast_party_connected_line_free(&connected);
01249 o->pending_connected_update = 1;
01250 } else {
01251 if (ast_channel_connected_line_macro(c, in, f, 1, 1)) {
01252 ast_indicate_data(in, AST_CONTROL_CONNECTED_LINE, f->data.ptr, f->datalen);
01253 }
01254 }
01255 break;
01256 case AST_CONTROL_AOC:
01257 {
01258 struct ast_aoc_decoded *decoded = ast_aoc_decode(f->data.ptr, f->datalen, o->chan);
01259 if (decoded && (ast_aoc_get_msg_type(decoded) == AST_AOC_S)) {
01260 ast_aoc_destroy_decoded(o->aoc_s_rate_list);
01261 o->aoc_s_rate_list = decoded;
01262 } else {
01263 ast_aoc_destroy_decoded(decoded);
01264 }
01265 }
01266 break;
01267 case AST_CONTROL_REDIRECTING:
01268 if (ast_test_flag64(peerflags, OPT_IGNORE_CONNECTEDLINE)) {
01269 ast_verb(3, "Redirecting update to %s prevented.\n", in->name);
01270 } else {
01271 ast_verb(3, "%s redirecting info has changed, passing it to %s\n", c->name, in->name);
01272 if (ast_channel_redirecting_macro(c, in, f, 1, 1)) {
01273 ast_indicate_data(in, AST_CONTROL_REDIRECTING, f->data.ptr, f->datalen);
01274 }
01275 pa->sentringing = 0;
01276 }
01277 break;
01278 case AST_CONTROL_PROCEEDING:
01279 ast_verb(3, "%s is proceeding passing it to %s\n", c->name, in->name);
01280 if (single && CAN_EARLY_BRIDGE(peerflags, in, c))
01281 ast_channel_early_bridge(in, c);
01282 if (!ast_test_flag64(outgoing, OPT_RINGBACK))
01283 ast_indicate(in, AST_CONTROL_PROCEEDING);
01284 break;
01285 case AST_CONTROL_HOLD:
01286 ast_verb(3, "Call on %s placed on hold\n", c->name);
01287 ast_indicate(in, AST_CONTROL_HOLD);
01288 break;
01289 case AST_CONTROL_UNHOLD:
01290 ast_verb(3, "Call on %s left from hold\n", c->name);
01291 ast_indicate(in, AST_CONTROL_UNHOLD);
01292 break;
01293 case AST_CONTROL_OFFHOOK:
01294 case AST_CONTROL_FLASH:
01295
01296 break;
01297 case AST_CONTROL_CC:
01298 if (!ignore_cc) {
01299 ast_handle_cc_control_frame(in, c, f->data.ptr);
01300 cc_frame_received = 1;
01301 }
01302 break;
01303 case -1:
01304 if (!ast_test_flag64(outgoing, OPT_RINGBACK | OPT_MUSICBACK)) {
01305 ast_verb(3, "%s stopped sounds\n", c->name);
01306 ast_indicate(in, -1);
01307 pa->sentringing = 0;
01308 }
01309 break;
01310 default:
01311 ast_debug(1, "Dunno what to do with control type %d\n", f->subclass.integer);
01312 }
01313 } else if (single) {
01314 switch (f->frametype) {
01315 case AST_FRAME_VOICE:
01316 case AST_FRAME_IMAGE:
01317 case AST_FRAME_TEXT:
01318 if (ast_write(in, f)) {
01319 ast_log(LOG_WARNING, "Unable to write frame\n");
01320 }
01321 break;
01322 case AST_FRAME_HTML:
01323 if (!ast_test_flag64(outgoing, DIAL_NOFORWARDHTML) && ast_channel_sendhtml(in, f->subclass.integer, f->data.ptr, f->datalen) == -1) {
01324 ast_log(LOG_WARNING, "Unable to send URL\n");
01325 }
01326 break;
01327 default:
01328 break;
01329 }
01330 }
01331 ast_frfree(f);
01332 }
01333 if (winner == in) {
01334 struct ast_frame *f = ast_read(in);
01335 #if 0
01336 if (f && (f->frametype != AST_FRAME_VOICE))
01337 printf("Frame type: %d, %d\n", f->frametype, f->subclass);
01338 else if (!f || (f->frametype != AST_FRAME_VOICE))
01339 printf("Hangup received on %s\n", in->name);
01340 #endif
01341 if (!f || ((f->frametype == AST_FRAME_CONTROL) && (f->subclass.integer == AST_CONTROL_HANGUP))) {
01342
01343 *to = -1;
01344 strcpy(pa->status, "CANCEL");
01345 ast_cdr_noanswer(in->cdr);
01346 if (f) {
01347 if (f->data.uint32) {
01348 in->hangupcause = f->data.uint32;
01349 }
01350 ast_frfree(f);
01351 }
01352 if (is_cc_recall) {
01353 ast_cc_completed(in, "CC completed, although the caller hung up (cancelled)");
01354 }
01355 return NULL;
01356 }
01357
01358
01359 if (f->frametype == AST_FRAME_DTMF) {
01360 if (ast_test_flag64(peerflags, OPT_DTMF_EXIT)) {
01361 const char *context;
01362 ast_channel_lock(in);
01363 context = pbx_builtin_getvar_helper(in, "EXITCONTEXT");
01364 if (onedigit_goto(in, context, (char) f->subclass.integer, 1)) {
01365 ast_verb(3, "User hit %c to disconnect call.\n", f->subclass.integer);
01366 *to = 0;
01367 ast_cdr_noanswer(in->cdr);
01368 *result = f->subclass.integer;
01369 strcpy(pa->status, "CANCEL");
01370 ast_frfree(f);
01371 ast_channel_unlock(in);
01372 if (is_cc_recall) {
01373 ast_cc_completed(in, "CC completed, but the caller used DTMF to exit");
01374 }
01375 return NULL;
01376 }
01377 ast_channel_unlock(in);
01378 }
01379
01380 if (ast_test_flag64(peerflags, OPT_CALLER_HANGUP) &&
01381 detect_disconnect(in, f->subclass.integer, featurecode)) {
01382 ast_verb(3, "User requested call disconnect.\n");
01383 *to = 0;
01384 strcpy(pa->status, "CANCEL");
01385 ast_cdr_noanswer(in->cdr);
01386 ast_frfree(f);
01387 if (is_cc_recall) {
01388 ast_cc_completed(in, "CC completed, but the caller hung up with DTMF");
01389 }
01390 return NULL;
01391 }
01392 }
01393
01394
01395 if (single && (f->frametype == AST_FRAME_HTML) && !ast_test_flag64(outgoing, DIAL_NOFORWARDHTML))
01396 if (ast_channel_sendhtml(outgoing->chan, f->subclass.integer, f->data.ptr, f->datalen) == -1)
01397 ast_log(LOG_WARNING, "Unable to send URL\n");
01398
01399 if (single && ((f->frametype == AST_FRAME_VOICE) || (f->frametype == AST_FRAME_DTMF_BEGIN) || (f->frametype == AST_FRAME_DTMF_END))) {
01400 if (ast_write(outgoing->chan, f))
01401 ast_log(LOG_WARNING, "Unable to forward voice or dtmf\n");
01402 }
01403 if (single && (f->frametype == AST_FRAME_CONTROL)) {
01404 if ((f->subclass.integer == AST_CONTROL_HOLD) ||
01405 (f->subclass.integer == AST_CONTROL_UNHOLD) ||
01406 (f->subclass.integer == AST_CONTROL_VIDUPDATE) ||
01407 (f->subclass.integer == AST_CONTROL_SRCUPDATE)) {
01408 ast_verb(3, "%s requested special control %d, passing it to %s\n", in->name, f->subclass.integer, outgoing->chan->name);
01409 ast_indicate_data(outgoing->chan, f->subclass.integer, f->data.ptr, f->datalen);
01410 } else if (f->subclass.integer == AST_CONTROL_CONNECTED_LINE) {
01411 if (ast_channel_connected_line_macro(in, outgoing->chan, f, 0, 1)) {
01412 ast_indicate_data(outgoing->chan, f->subclass.integer, f->data.ptr, f->datalen);
01413 }
01414 } else if (f->subclass.integer == AST_CONTROL_REDIRECTING) {
01415 if (ast_channel_redirecting_macro(in, outgoing->chan, f, 0, 1)) {
01416 ast_indicate_data(outgoing->chan, f->subclass.integer, f->data.ptr, f->datalen);
01417 }
01418 }
01419 }
01420 ast_frfree(f);
01421 }
01422 if (!*to)
01423 ast_verb(3, "Nobody picked up in %d ms\n", orig);
01424 if (!*to || ast_check_hangup(in))
01425 ast_cdr_noanswer(in->cdr);
01426 }
01427
01428 #ifdef HAVE_EPOLL
01429 for (epollo = outgoing; epollo; epollo = epollo->next) {
01430 if (epollo->chan)
01431 ast_poll_channel_del(in, epollo->chan);
01432 }
01433 #endif
01434
01435 if (is_cc_recall) {
01436 ast_cc_completed(in, "Recall completed!");
01437 }
01438 return peer;
01439 }
01440
01441 static int detect_disconnect(struct ast_channel *chan, char code, struct ast_str *featurecode)
01442 {
01443 struct ast_flags features = { AST_FEATURE_DISCONNECT };
01444 struct ast_call_feature feature = { 0, };
01445 int res;
01446
01447 ast_str_append(&featurecode, 1, "%c", code);
01448
01449 res = ast_feature_detect(chan, &features, ast_str_buffer(featurecode), &feature);
01450
01451 if (res != AST_FEATURE_RETURN_STOREDIGITS) {
01452 ast_str_reset(featurecode);
01453 }
01454 if (feature.feature_mask & AST_FEATURE_DISCONNECT) {
01455 return 1;
01456 }
01457
01458 return 0;
01459 }
01460
01461 static void replace_macro_delimiter(char *s)
01462 {
01463 for (; *s; s++)
01464 if (*s == '^')
01465 *s = ',';
01466 }
01467
01468
01469 static int valid_priv_reply(struct ast_flags64 *opts, int res)
01470 {
01471 if (res < '1')
01472 return 0;
01473 if (ast_test_flag64(opts, OPT_PRIVACY) && res <= '5')
01474 return 1;
01475 if (ast_test_flag64(opts, OPT_SCREENING) && res <= '4')
01476 return 1;
01477 return 0;
01478 }
01479
01480 static int do_privacy(struct ast_channel *chan, struct ast_channel *peer,
01481 struct ast_flags64 *opts, char **opt_args, struct privacy_args *pa)
01482 {
01483
01484 int res2;
01485 int loopcount = 0;
01486
01487
01488
01489
01490
01491
01492
01493
01494
01495 if (ast_test_flag64(opts, OPT_MUSICBACK) && !ast_strlen_zero(opt_args[OPT_ARG_MUSICBACK])) {
01496 char *original_moh = ast_strdupa(chan->musicclass);
01497 ast_indicate(chan, -1);
01498 ast_string_field_set(chan, musicclass, opt_args[OPT_ARG_MUSICBACK]);
01499 ast_moh_start(chan, opt_args[OPT_ARG_MUSICBACK], NULL);
01500 ast_string_field_set(chan, musicclass, original_moh);
01501 } else if (ast_test_flag64(opts, OPT_RINGBACK)) {
01502 ast_indicate(chan, AST_CONTROL_RINGING);
01503 pa->sentringing++;
01504 }
01505
01506
01507 res2 = ast_autoservice_start(chan);
01508
01509 for (loopcount = 0; loopcount < 3; loopcount++) {
01510 if (res2 && loopcount == 0)
01511 break;
01512 if (!res2)
01513 res2 = ast_play_and_wait(peer, "priv-callpending");
01514 if (!valid_priv_reply(opts, res2))
01515 res2 = 0;
01516
01517
01518
01519 if (!res2)
01520 res2 = ast_play_and_wait(peer, pa->privintro);
01521 if (!valid_priv_reply(opts, res2))
01522 res2 = 0;
01523
01524 if (!res2) {
01525
01526 if (ast_test_flag64(opts, OPT_PRIVACY))
01527 res2 = ast_play_and_wait(peer, "priv-callee-options");
01528 if (ast_test_flag64(opts, OPT_SCREENING))
01529 res2 = ast_play_and_wait(peer, "screen-callee-options");
01530 }
01531
01532
01533
01534
01535
01536
01537
01538
01539
01540
01541
01542
01543
01544
01545
01546
01547 if (valid_priv_reply(opts, res2))
01548 break;
01549
01550 res2 = ast_play_and_wait(peer, "vm-sorry");
01551 }
01552
01553 if (ast_test_flag64(opts, OPT_MUSICBACK)) {
01554 ast_moh_stop(chan);
01555 } else if (ast_test_flag64(opts, OPT_RINGBACK)) {
01556 ast_indicate(chan, -1);
01557 pa->sentringing = 0;
01558 }
01559 ast_autoservice_stop(chan);
01560 if (ast_test_flag64(opts, OPT_PRIVACY) && (res2 >= '1' && res2 <= '5')) {
01561
01562 static const char * const _val[] = { "ALLOW", "DENY", "TORTURE", "KILL", "ALLOW" };
01563 static const int _flag[] = { AST_PRIVACY_ALLOW, AST_PRIVACY_DENY, AST_PRIVACY_TORTURE, AST_PRIVACY_KILL, AST_PRIVACY_ALLOW};
01564 int i = res2 - '1';
01565 ast_verb(3, "--Set privacy database entry %s/%s to %s\n",
01566 opt_args[OPT_ARG_PRIVACY], pa->privcid, _val[i]);
01567 ast_privacy_set(opt_args[OPT_ARG_PRIVACY], pa->privcid, _flag[i]);
01568 }
01569 switch (res2) {
01570 case '1':
01571 break;
01572 case '2':
01573 ast_copy_string(pa->status, "NOANSWER", sizeof(pa->status));
01574 break;
01575 case '3':
01576 ast_copy_string(pa->status, "TORTURE", sizeof(pa->status));
01577 break;
01578 case '4':
01579 ast_copy_string(pa->status, "DONTCALL", sizeof(pa->status));
01580 break;
01581 case '5':
01582
01583 if (ast_test_flag64(opts, OPT_PRIVACY))
01584 break;
01585
01586 default:
01587
01588
01589
01590
01591 ast_log(LOG_NOTICE, "privacy: no valid response from the callee. Sending the caller to voicemail, the callee isn't responding\n");
01592
01593
01594 break;
01595 }
01596
01597 if (res2 == '1') {
01598
01599
01600 if (strncmp(pa->privcid, "NOCALLERID", 10) == 0 || ast_test_flag64(opts, OPT_SCREEN_NOINTRO)) {
01601 ast_filedelete(pa->privintro, NULL);
01602 if (ast_fileexists(pa->privintro, NULL, NULL) > 0)
01603 ast_log(LOG_NOTICE, "privacy: ast_filedelete didn't do its job on %s\n", pa->privintro);
01604 else
01605 ast_verb(3, "Successfully deleted %s intro file\n", pa->privintro);
01606 }
01607 return 0;
01608 } else {
01609 ast_hangup(peer);
01610 return -1;
01611 }
01612 }
01613
01614
01615 static int setup_privacy_args(struct privacy_args *pa,
01616 struct ast_flags64 *opts, char *opt_args[], struct ast_channel *chan)
01617 {
01618 char callerid[60];
01619 int res;
01620 char *l;
01621 int silencethreshold;
01622
01623 if (chan->caller.id.number.valid
01624 && !ast_strlen_zero(chan->caller.id.number.str)) {
01625 l = ast_strdupa(chan->caller.id.number.str);
01626 ast_shrink_phone_number(l);
01627 if (ast_test_flag64(opts, OPT_PRIVACY) ) {
01628 ast_verb(3, "Privacy DB is '%s', clid is '%s'\n", opt_args[OPT_ARG_PRIVACY], l);
01629 pa->privdb_val = ast_privacy_check(opt_args[OPT_ARG_PRIVACY], l);
01630 } else {
01631 ast_verb(3, "Privacy Screening, clid is '%s'\n", l);
01632 pa->privdb_val = AST_PRIVACY_UNKNOWN;
01633 }
01634 } else {
01635 char *tnam, *tn2;
01636
01637 tnam = ast_strdupa(chan->name);
01638
01639 for (tn2 = tnam; *tn2; tn2++) {
01640 if (*tn2 == '/')
01641 *tn2 = '=';
01642 }
01643 ast_verb(3, "Privacy-- callerid is empty\n");
01644
01645 snprintf(callerid, sizeof(callerid), "NOCALLERID_%s%s", chan->exten, tnam);
01646 l = callerid;
01647 pa->privdb_val = AST_PRIVACY_UNKNOWN;
01648 }
01649
01650 ast_copy_string(pa->privcid, l, sizeof(pa->privcid));
01651
01652 if (strncmp(pa->privcid, "NOCALLERID", 10) != 0 && ast_test_flag64(opts, OPT_SCREEN_NOCALLERID)) {
01653
01654 ast_verb(3, "CallerID set (%s); N option set; Screening should be off\n", pa->privcid);
01655 pa->privdb_val = AST_PRIVACY_ALLOW;
01656 } else if (ast_test_flag64(opts, OPT_SCREEN_NOCALLERID) && strncmp(pa->privcid, "NOCALLERID", 10) == 0) {
01657 ast_verb(3, "CallerID blank; N option set; Screening should happen; dbval is %d\n", pa->privdb_val);
01658 }
01659
01660 if (pa->privdb_val == AST_PRIVACY_DENY) {
01661 ast_verb(3, "Privacy DB reports PRIVACY_DENY for this callerid. Dial reports unavailable\n");
01662 ast_copy_string(pa->status, "NOANSWER", sizeof(pa->status));
01663 return 0;
01664 } else if (pa->privdb_val == AST_PRIVACY_KILL) {
01665 ast_copy_string(pa->status, "DONTCALL", sizeof(pa->status));
01666 return 0;
01667 } else if (pa->privdb_val == AST_PRIVACY_TORTURE) {
01668 ast_copy_string(pa->status, "TORTURE", sizeof(pa->status));
01669 return 0;
01670 } else if (pa->privdb_val == AST_PRIVACY_UNKNOWN) {
01671
01672
01673
01674
01675
01676 snprintf(pa->privintro, sizeof(pa->privintro), "%s/sounds/priv-callerintros", ast_config_AST_DATA_DIR);
01677 if ((res = ast_mkdir(pa->privintro, 0755))) {
01678 ast_log(LOG_WARNING, "privacy: can't create directory priv-callerintros: %s\n", strerror(res));
01679 return -1;
01680 }
01681
01682 snprintf(pa->privintro, sizeof(pa->privintro), "priv-callerintros/%s", pa->privcid);
01683 if (ast_fileexists(pa->privintro, NULL, NULL ) > 0 && strncmp(pa->privcid, "NOCALLERID", 10) != 0) {
01684
01685
01686
01687 } else {
01688 int duration;
01689
01690
01691
01692
01693
01694
01695
01696 silencethreshold = ast_dsp_get_threshold_from_settings(THRESHOLD_SILENCE);
01697 ast_answer(chan);
01698 res = ast_play_and_record(chan, "priv-recordintro", pa->privintro, 4, "gsm", &duration, silencethreshold, 2000, 0);
01699
01700
01701 if (res == -1) {
01702
01703 ast_filedelete(pa->privintro, NULL);
01704 if (ast_fileexists(pa->privintro, NULL, NULL) > 0)
01705 ast_log(LOG_NOTICE, "privacy: ast_filedelete didn't do its job on %s\n", pa->privintro);
01706 else
01707 ast_verb(3, "Successfully deleted %s intro file\n", pa->privintro);
01708 return -1;
01709 }
01710 if (!ast_streamfile(chan, "vm-dialout", chan->language) )
01711 ast_waitstream(chan, "");
01712 }
01713 }
01714 return 1;
01715 }
01716
01717 static void end_bridge_callback(void *data)
01718 {
01719 char buf[80];
01720 time_t end;
01721 struct ast_channel *chan = data;
01722
01723 if (!chan->cdr) {
01724 return;
01725 }
01726
01727 time(&end);
01728
01729 ast_channel_lock(chan);
01730 if (chan->cdr->answer.tv_sec) {
01731 snprintf(buf, sizeof(buf), "%ld", (long) end - chan->cdr->answer.tv_sec);
01732 pbx_builtin_setvar_helper(chan, "ANSWEREDTIME", buf);
01733 }
01734
01735 if (chan->cdr->start.tv_sec) {
01736 snprintf(buf, sizeof(buf), "%ld", (long) end - chan->cdr->start.tv_sec);
01737 pbx_builtin_setvar_helper(chan, "DIALEDTIME", buf);
01738 }
01739 ast_channel_unlock(chan);
01740 }
01741
01742 static void end_bridge_callback_data_fixup(struct ast_bridge_config *bconfig, struct ast_channel *originator, struct ast_channel *terminator) {
01743 bconfig->end_bridge_callback_data = originator;
01744 }
01745
01746 static int dial_handle_playtones(struct ast_channel *chan, const char *data)
01747 {
01748 struct ast_tone_zone_sound *ts = NULL;
01749 int res;
01750 const char *str = data;
01751
01752 if (ast_strlen_zero(str)) {
01753 ast_debug(1,"Nothing to play\n");
01754 return -1;
01755 }
01756
01757 ts = ast_get_indication_tone(chan->zone, str);
01758
01759 if (ts && ts->data[0]) {
01760 res = ast_playtones_start(chan, 0, ts->data, 0);
01761 } else {
01762 res = -1;
01763 }
01764
01765 if (ts) {
01766 ts = ast_tone_zone_sound_unref(ts);
01767 }
01768
01769 if (res) {
01770 ast_log(LOG_WARNING, "Unable to start playtone \'%s\'\n", str);
01771 }
01772
01773 return res;
01774 }
01775
01776 static int dial_exec_full(struct ast_channel *chan, const char *data, struct ast_flags64 *peerflags, int *continue_exec)
01777 {
01778 int res = -1;
01779 char *rest, *cur;
01780 struct chanlist *outgoing = NULL;
01781 struct ast_channel *peer;
01782 int to;
01783 struct cause_args num = { chan, 0, 0, 0 };
01784 int cause;
01785 char numsubst[256];
01786 char *cid_num = NULL, *cid_name = NULL, *cid_tag = NULL, *cid_pres = NULL;
01787
01788 struct ast_bridge_config config = { { 0, } };
01789 struct timeval calldurationlimit = { 0, };
01790 char *dtmfcalled = NULL, *dtmfcalling = NULL, *dtmf_progress=NULL;
01791 struct privacy_args pa = {
01792 .sentringing = 0,
01793 .privdb_val = 0,
01794 .status = "INVALIDARGS",
01795 };
01796 int sentringing = 0, moh = 0;
01797 const char *outbound_group = NULL;
01798 int result = 0;
01799 char *parse;
01800 int opermode = 0;
01801 int delprivintro = 0;
01802 AST_DECLARE_APP_ARGS(args,
01803 AST_APP_ARG(peers);
01804 AST_APP_ARG(timeout);
01805 AST_APP_ARG(options);
01806 AST_APP_ARG(url);
01807 );
01808 struct ast_flags64 opts = { 0, };
01809 char *opt_args[OPT_ARG_ARRAY_SIZE];
01810 struct ast_datastore *datastore = NULL;
01811 int fulldial = 0, num_dialed = 0;
01812 int ignore_cc = 0;
01813 char device_name[AST_CHANNEL_NAME];
01814
01815
01816 pbx_builtin_setvar_helper(chan, "DIALSTATUS", "");
01817 pbx_builtin_setvar_helper(chan, "DIALEDPEERNUMBER", "");
01818 pbx_builtin_setvar_helper(chan, "DIALEDPEERNAME", "");
01819 pbx_builtin_setvar_helper(chan, "ANSWEREDTIME", "");
01820 pbx_builtin_setvar_helper(chan, "DIALEDTIME", "");
01821
01822 if (ast_strlen_zero(data)) {
01823 ast_log(LOG_WARNING, "Dial requires an argument (technology/number)\n");
01824 pbx_builtin_setvar_helper(chan, "DIALSTATUS", pa.status);
01825 return -1;
01826 }
01827
01828 parse = ast_strdupa(data);
01829
01830 AST_STANDARD_APP_ARGS(args, parse);
01831
01832 if (!ast_strlen_zero(args.options) &&
01833 ast_app_parse_options64(dial_exec_options, &opts, opt_args, args.options)) {
01834 pbx_builtin_setvar_helper(chan, "DIALSTATUS", pa.status);
01835 goto done;
01836 }
01837
01838 if (ast_strlen_zero(args.peers)) {
01839 ast_log(LOG_WARNING, "Dial requires an argument (technology/number)\n");
01840 pbx_builtin_setvar_helper(chan, "DIALSTATUS", pa.status);
01841 goto done;
01842 }
01843
01844 if (ast_cc_call_init(chan, &ignore_cc)) {
01845 goto done;
01846 }
01847
01848 if (ast_test_flag64(&opts, OPT_SCREEN_NOINTRO) && !ast_strlen_zero(opt_args[OPT_ARG_SCREEN_NOINTRO])) {
01849 delprivintro = atoi(opt_args[OPT_ARG_SCREEN_NOINTRO]);
01850
01851 if (delprivintro < 0 || delprivintro > 1) {
01852 ast_log(LOG_WARNING, "Unknown argument %d specified to n option, ignoring\n", delprivintro);
01853 delprivintro = 0;
01854 }
01855 }
01856
01857 if (!ast_test_flag64(&opts, OPT_RINGBACK)) {
01858 opt_args[OPT_ARG_RINGBACK] = NULL;
01859 }
01860
01861 if (ast_test_flag64(&opts, OPT_OPERMODE)) {
01862 opermode = ast_strlen_zero(opt_args[OPT_ARG_OPERMODE]) ? 1 : atoi(opt_args[OPT_ARG_OPERMODE]);
01863 ast_verb(3, "Setting operator services mode to %d.\n", opermode);
01864 }
01865
01866 if (ast_test_flag64(&opts, OPT_DURATION_STOP) && !ast_strlen_zero(opt_args[OPT_ARG_DURATION_STOP])) {
01867 calldurationlimit.tv_sec = atoi(opt_args[OPT_ARG_DURATION_STOP]);
01868 if (!calldurationlimit.tv_sec) {
01869 ast_log(LOG_WARNING, "Dial does not accept S(%s), hanging up.\n", opt_args[OPT_ARG_DURATION_STOP]);
01870 pbx_builtin_setvar_helper(chan, "DIALSTATUS", pa.status);
01871 goto done;
01872 }
01873 ast_verb(3, "Setting call duration limit to %.3lf seconds.\n", calldurationlimit.tv_sec + calldurationlimit.tv_usec / 1000000.0);
01874 }
01875
01876 if (ast_test_flag64(&opts, OPT_SENDDTMF) && !ast_strlen_zero(opt_args[OPT_ARG_SENDDTMF])) {
01877 dtmf_progress = opt_args[OPT_ARG_SENDDTMF];
01878 dtmfcalled = strsep(&dtmf_progress, ":");
01879 dtmfcalling = strsep(&dtmf_progress, ":");
01880 }
01881
01882 if (ast_test_flag64(&opts, OPT_DURATION_LIMIT) && !ast_strlen_zero(opt_args[OPT_ARG_DURATION_LIMIT])) {
01883 if (ast_bridge_timelimit(chan, &config, opt_args[OPT_ARG_DURATION_LIMIT], &calldurationlimit))
01884 goto done;
01885 }
01886
01887 if (ast_test_flag64(&opts, OPT_FORCECLID) && !ast_strlen_zero(opt_args[OPT_ARG_FORCECLID]))
01888 ast_callerid_parse(opt_args[OPT_ARG_FORCECLID], &cid_name, &cid_num);
01889 if (ast_test_flag64(&opts, OPT_FORCE_CID_TAG) && !ast_strlen_zero(opt_args[OPT_ARG_FORCE_CID_TAG]))
01890 cid_tag = ast_strdupa(opt_args[OPT_ARG_FORCE_CID_TAG]);
01891 if (ast_test_flag64(&opts, OPT_FORCE_CID_PRES) && !ast_strlen_zero(opt_args[OPT_ARG_FORCE_CID_PRES]))
01892 cid_pres = ast_strdupa(opt_args[OPT_ARG_FORCE_CID_PRES]);
01893 if (ast_test_flag64(&opts, OPT_RESETCDR) && chan->cdr)
01894 ast_cdr_reset(chan->cdr, NULL);
01895 if (ast_test_flag64(&opts, OPT_PRIVACY) && ast_strlen_zero(opt_args[OPT_ARG_PRIVACY]))
01896 opt_args[OPT_ARG_PRIVACY] = ast_strdupa(chan->exten);
01897
01898 if (ast_test_flag64(&opts, OPT_PRIVACY) || ast_test_flag64(&opts, OPT_SCREENING)) {
01899 res = setup_privacy_args(&pa, &opts, opt_args, chan);
01900 if (res <= 0)
01901 goto out;
01902 res = -1;
01903 }
01904
01905 if (ast_test_flag64(&opts, OPT_DTMF_EXIT) || ast_test_flag64(&opts, OPT_CALLER_HANGUP)) {
01906 __ast_answer(chan, 0, 0);
01907 }
01908
01909 if (continue_exec)
01910 *continue_exec = 0;
01911
01912
01913
01914 ast_channel_lock(chan);
01915 if ((outbound_group = pbx_builtin_getvar_helper(chan, "OUTBOUND_GROUP_ONCE"))) {
01916 outbound_group = ast_strdupa(outbound_group);
01917 pbx_builtin_setvar_helper(chan, "OUTBOUND_GROUP_ONCE", NULL);
01918 } else if ((outbound_group = pbx_builtin_getvar_helper(chan, "OUTBOUND_GROUP"))) {
01919 outbound_group = ast_strdupa(outbound_group);
01920 }
01921 ast_channel_unlock(chan);
01922 ast_copy_flags64(peerflags, &opts, OPT_DTMF_EXIT | OPT_GO_ON | OPT_ORIGINAL_CLID | OPT_CALLER_HANGUP | OPT_IGNORE_FORWARDING | OPT_IGNORE_CONNECTEDLINE |
01923 OPT_CANCEL_TIMEOUT | OPT_ANNOUNCE | OPT_CALLEE_MACRO | OPT_CALLEE_GOSUB | OPT_FORCECLID);
01924
01925
01926 rest = args.peers;
01927 while ((cur = strsep(&rest, "&")) ) {
01928 struct chanlist *tmp;
01929 struct ast_channel *tc;
01930
01931 char *number = cur;
01932 char *interface = ast_strdupa(number);
01933 char *tech = strsep(&number, "/");
01934
01935 struct ast_dialed_interface *di;
01936 AST_LIST_HEAD(, ast_dialed_interface) *dialed_interfaces;
01937 num_dialed++;
01938 if (!number) {
01939 ast_log(LOG_WARNING, "Dial argument takes format (technology/[device:]number1)\n");
01940 goto out;
01941 }
01942 if (!(tmp = ast_calloc(1, sizeof(*tmp))))
01943 goto out;
01944 if (opts.flags) {
01945 ast_copy_flags64(tmp, &opts,
01946 OPT_CANCEL_ELSEWHERE |
01947 OPT_CALLEE_TRANSFER | OPT_CALLER_TRANSFER |
01948 OPT_CALLEE_HANGUP | OPT_CALLER_HANGUP |
01949 OPT_CALLEE_MONITOR | OPT_CALLER_MONITOR |
01950 OPT_CALLEE_PARK | OPT_CALLER_PARK |
01951 OPT_CALLEE_MIXMONITOR | OPT_CALLER_MIXMONITOR |
01952 OPT_RINGBACK | OPT_MUSICBACK | OPT_FORCECLID);
01953 ast_set2_flag64(tmp, args.url, DIAL_NOFORWARDHTML);
01954 }
01955 ast_copy_string(numsubst, number, sizeof(numsubst));
01956
01957
01958 ast_channel_lock(chan);
01959 datastore = ast_channel_datastore_find(chan, &dialed_interface_info, NULL);
01960
01961
01962
01963
01964
01965
01966 ast_party_connected_line_copy(&tmp->connected, &chan->connected);
01967 ast_channel_unlock(chan);
01968
01969 if (datastore)
01970 dialed_interfaces = datastore->data;
01971 else {
01972 if (!(datastore = ast_datastore_alloc(&dialed_interface_info, NULL))) {
01973 ast_log(LOG_WARNING, "Unable to create channel datastore for dialed interfaces. Aborting!\n");
01974 chanlist_free(tmp);
01975 goto out;
01976 }
01977
01978 datastore->inheritance = DATASTORE_INHERIT_FOREVER;
01979
01980 if (!(dialed_interfaces = ast_calloc(1, sizeof(*dialed_interfaces)))) {
01981 ast_datastore_free(datastore);
01982 chanlist_free(tmp);
01983 goto out;
01984 }
01985
01986 datastore->data = dialed_interfaces;
01987 AST_LIST_HEAD_INIT(dialed_interfaces);
01988
01989 ast_channel_lock(chan);
01990 ast_channel_datastore_add(chan, datastore);
01991 ast_channel_unlock(chan);
01992 }
01993
01994 AST_LIST_LOCK(dialed_interfaces);
01995 AST_LIST_TRAVERSE(dialed_interfaces, di, list) {
01996 if (!strcasecmp(di->interface, interface)) {
01997 ast_log(LOG_WARNING, "Skipping dialing interface '%s' again since it has already been dialed\n",
01998 di->interface);
01999 break;
02000 }
02001 }
02002 AST_LIST_UNLOCK(dialed_interfaces);
02003
02004 if (di) {
02005 fulldial++;
02006 chanlist_free(tmp);
02007 continue;
02008 }
02009
02010
02011
02012
02013
02014 if (strcasecmp(tech, "Local")) {
02015 if (!(di = ast_calloc(1, sizeof(*di) + strlen(interface)))) {
02016 AST_LIST_UNLOCK(dialed_interfaces);
02017 chanlist_free(tmp);
02018 goto out;
02019 }
02020 strcpy(di->interface, interface);
02021
02022 AST_LIST_LOCK(dialed_interfaces);
02023 AST_LIST_INSERT_TAIL(dialed_interfaces, di, list);
02024 AST_LIST_UNLOCK(dialed_interfaces);
02025 }
02026
02027 tc = ast_request(tech, chan->nativeformats, chan, numsubst, &cause);
02028 if (!tc) {
02029
02030 ast_log(LOG_WARNING, "Unable to create channel of type '%s' (cause %d - %s)\n",
02031 tech, cause, ast_cause2str(cause));
02032 handle_cause(cause, &num);
02033 if (!rest)
02034 chan->hangupcause = cause;
02035 chanlist_free(tmp);
02036 if (!ignore_cc && (cause == AST_CAUSE_BUSY || cause == AST_CAUSE_CONGESTION)) {
02037 if (!ast_cc_callback(chan, tech, numsubst, ast_cc_busy_interface)) {
02038 ast_cc_extension_monitor_add_dialstring(chan, interface, "");
02039 }
02040 }
02041 continue;
02042 }
02043 ast_channel_get_device_name(tc, device_name, sizeof(device_name));
02044 if (!ignore_cc) {
02045 ast_cc_extension_monitor_add_dialstring(chan, interface, device_name);
02046 }
02047 pbx_builtin_setvar_helper(tc, "DIALEDPEERNUMBER", numsubst);
02048
02049 ast_channel_lock(tc);
02050 while (ast_channel_trylock(chan)) {
02051 CHANNEL_DEADLOCK_AVOIDANCE(tc);
02052 }
02053
02054 if (!outgoing && !rest && CAN_EARLY_BRIDGE(peerflags, chan, tc)) {
02055 ast_rtp_instance_early_bridge_make_compatible(tc, chan);
02056 }
02057
02058
02059 ast_channel_inherit_variables(chan, tc);
02060 ast_channel_datastore_inherit(chan, tc);
02061
02062 tc->appl = "AppDial";
02063 tc->data = "(Outgoing Line)";
02064 memset(&tc->whentohangup, 0, sizeof(tc->whentohangup));
02065
02066
02067 if (!tc->caller.id.number.valid) {
02068 if (chan->connected.id.number.valid) {
02069 struct ast_party_caller caller;
02070
02071 ast_party_caller_set_init(&caller, &tc->caller);
02072 caller.id = chan->connected.id;
02073 caller.ani = chan->connected.ani;
02074 ast_channel_set_caller_event(tc, &caller, NULL);
02075 } else if (!ast_strlen_zero(chan->dialed.number.str)) {
02076 ast_set_callerid(tc, chan->dialed.number.str, NULL, NULL);
02077 } else if (!ast_strlen_zero(S_OR(chan->macroexten, chan->exten))) {
02078 ast_set_callerid(tc, S_OR(chan->macroexten, chan->exten), NULL, NULL);
02079 }
02080 ast_set_flag64(tmp, DIAL_CALLERID_ABSENT);
02081 }
02082
02083 if (ast_test_flag64(peerflags, OPT_FORCECLID) && !ast_strlen_zero(opt_args[OPT_ARG_FORCECLID])) {
02084 struct ast_party_connected_line connected;
02085 int pres;
02086
02087 ast_party_connected_line_set_init(&connected, &tmp->chan->connected);
02088 if (cid_pres) {
02089 pres = ast_parse_caller_presentation(cid_pres);
02090 if (pres < 0) {
02091 pres = AST_PRES_ALLOWED_USER_NUMBER_PASSED_SCREEN;
02092 }
02093 } else {
02094 pres = AST_PRES_ALLOWED_USER_NUMBER_PASSED_SCREEN;
02095 }
02096 if (cid_num) {
02097 connected.id.number.valid = 1;
02098 connected.id.number.str = cid_num;
02099 connected.id.number.presentation = pres;
02100 }
02101 if (cid_name) {
02102 connected.id.name.valid = 1;
02103 connected.id.name.str = cid_name;
02104 connected.id.name.presentation = pres;
02105 }
02106 connected.id.tag = cid_tag;
02107 ast_channel_set_connected_line(tmp->chan, &connected, NULL);
02108 } else {
02109 ast_connected_line_copy_from_caller(&tc->connected, &chan->caller);
02110 }
02111
02112 ast_party_redirecting_copy(&tc->redirecting, &chan->redirecting);
02113
02114 tc->dialed.transit_network_select = chan->dialed.transit_network_select;
02115
02116 if (!ast_strlen_zero(chan->accountcode)) {
02117 ast_string_field_set(tc, peeraccount, chan->accountcode);
02118 }
02119 if (ast_strlen_zero(tc->musicclass))
02120 ast_string_field_set(tc, musicclass, chan->musicclass);
02121
02122
02123 tc->adsicpe = chan->adsicpe;
02124 tc->transfercapability = chan->transfercapability;
02125
02126
02127 if (outbound_group)
02128 ast_app_group_set_channel(tc, outbound_group);
02129
02130 if (ast_test_flag(chan, AST_FLAG_ANSWERED_ELSEWHERE))
02131 ast_set_flag(tc, AST_FLAG_ANSWERED_ELSEWHERE);
02132
02133
02134 if (ast_test_flag64(&opts, OPT_CANCEL_ELSEWHERE))
02135 ast_set_flag(tc, AST_FLAG_ANSWERED_ELSEWHERE);
02136
02137
02138
02139 ast_string_field_set(tc, dialcontext, ast_strlen_zero(chan->macrocontext) ? chan->context : chan->macrocontext);
02140 if (!ast_strlen_zero(chan->macroexten))
02141 ast_copy_string(tc->exten, chan->macroexten, sizeof(tc->exten));
02142 else
02143 ast_copy_string(tc->exten, chan->exten, sizeof(tc->exten));
02144
02145 ast_channel_unlock(tc);
02146 res = ast_call(tc, numsubst, 0);
02147
02148
02149 if (chan->cdr)
02150 ast_cdr_setdestchan(chan->cdr, tc->name);
02151
02152
02153 if (res) {
02154
02155 ast_debug(1, "ast call on peer returned %d\n", res);
02156 ast_verb(3, "Couldn't call %s\n", numsubst);
02157 if (tc->hangupcause) {
02158 chan->hangupcause = tc->hangupcause;
02159 }
02160 ast_channel_unlock(chan);
02161 ast_cc_call_failed(chan, tc, interface);
02162 ast_hangup(tc);
02163 tc = NULL;
02164 chanlist_free(tmp);
02165 continue;
02166 } else {
02167 const char *tmpexten = ast_strdupa(S_OR(chan->macroexten, chan->exten));
02168 senddialevent(chan, tc, numsubst);
02169 ast_verb(3, "Called %s\n", numsubst);
02170 ast_channel_unlock(chan);
02171 if (!ast_test_flag64(peerflags, OPT_ORIGINAL_CLID)) {
02172 char cidname[AST_MAX_EXTENSION];
02173 ast_set_callerid(tc, tmpexten, get_cid_name(cidname, sizeof(cidname), chan), NULL);
02174 }
02175 }
02176
02177
02178
02179 ast_set_flag64(tmp, DIAL_STILLGOING);
02180 tmp->chan = tc;
02181 tmp->next = outgoing;
02182 outgoing = tmp;
02183
02184 if (outgoing->chan->_state == AST_STATE_UP)
02185 break;
02186 }
02187
02188 if (ast_strlen_zero(args.timeout)) {
02189 to = -1;
02190 } else {
02191 to = atoi(args.timeout);
02192 if (to > 0)
02193 to *= 1000;
02194 else {
02195 ast_log(LOG_WARNING, "Invalid timeout specified: '%s'. Setting timeout to infinite\n", args.timeout);
02196 to = -1;
02197 }
02198 }
02199
02200 if (!outgoing) {
02201 strcpy(pa.status, "CHANUNAVAIL");
02202 if (fulldial == num_dialed) {
02203 res = -1;
02204 goto out;
02205 }
02206 } else {
02207
02208 strcpy(pa.status, "NOANSWER");
02209 if (ast_test_flag64(outgoing, OPT_MUSICBACK)) {
02210 moh = 1;
02211 if (!ast_strlen_zero(opt_args[OPT_ARG_MUSICBACK])) {
02212 char *original_moh = ast_strdupa(chan->musicclass);
02213 ast_string_field_set(chan, musicclass, opt_args[OPT_ARG_MUSICBACK]);
02214 ast_moh_start(chan, opt_args[OPT_ARG_MUSICBACK], NULL);
02215 ast_string_field_set(chan, musicclass, original_moh);
02216 } else {
02217 ast_moh_start(chan, NULL, NULL);
02218 }
02219 ast_indicate(chan, AST_CONTROL_PROGRESS);
02220 } else if (ast_test_flag64(outgoing, OPT_RINGBACK)) {
02221 if (!ast_strlen_zero(opt_args[OPT_ARG_RINGBACK])) {
02222 if (dial_handle_playtones(chan, opt_args[OPT_ARG_RINGBACK])){
02223 ast_indicate(chan, AST_CONTROL_RINGING);
02224 sentringing++;
02225 } else {
02226 ast_indicate(chan, AST_CONTROL_PROGRESS);
02227 }
02228 } else {
02229 ast_indicate(chan, AST_CONTROL_RINGING);
02230 sentringing++;
02231 }
02232 }
02233 }
02234
02235 peer = wait_for_answer(chan, outgoing, &to, peerflags, opt_args, &pa, &num, &result, dtmf_progress, ignore_cc);
02236
02237
02238
02239
02240
02241
02242
02243 if (!ast_channel_datastore_remove(chan, datastore))
02244 ast_datastore_free(datastore);
02245 if (!peer) {
02246 if (result) {
02247 res = result;
02248 } else if (to) {
02249 res = -1;
02250 } else {
02251 res = 0;
02252 }
02253
02254
02255
02256 if (chan->hangupcause == AST_CAUSE_INVALID_NUMBER_FORMAT) {
02257 res = AST_PBX_INCOMPLETE;
02258 }
02259
02260
02261 } else {
02262 const char *number;
02263
02264 if (ast_test_flag64(&opts, OPT_CALLER_ANSWER))
02265 ast_answer(chan);
02266
02267 strcpy(pa.status, "ANSWER");
02268 pbx_builtin_setvar_helper(chan, "DIALSTATUS", pa.status);
02269
02270
02271
02272 hanguptree(outgoing, peer, 1);
02273 outgoing = NULL;
02274
02275 if (chan->cdr) {
02276 ast_cdr_setdestchan(chan->cdr, peer->name);
02277 ast_cdr_setanswer(chan->cdr, peer->cdr->answer);
02278 }
02279 if (peer->name)
02280 pbx_builtin_setvar_helper(chan, "DIALEDPEERNAME", peer->name);
02281
02282 ast_channel_lock(peer);
02283 number = pbx_builtin_getvar_helper(peer, "DIALEDPEERNUMBER");
02284 if (!number)
02285 number = numsubst;
02286 pbx_builtin_setvar_helper(chan, "DIALEDPEERNUMBER", number);
02287 ast_channel_unlock(peer);
02288
02289 if (!ast_strlen_zero(args.url) && ast_channel_supports_html(peer) ) {
02290 ast_debug(1, "app_dial: sendurl=%s.\n", args.url);
02291 ast_channel_sendurl( peer, args.url );
02292 }
02293 if ( (ast_test_flag64(&opts, OPT_PRIVACY) || ast_test_flag64(&opts, OPT_SCREENING)) && pa.privdb_val == AST_PRIVACY_UNKNOWN) {
02294 if (do_privacy(chan, peer, &opts, opt_args, &pa)) {
02295 res = 0;
02296 goto out;
02297 }
02298 }
02299 if (!ast_test_flag64(&opts, OPT_ANNOUNCE) || ast_strlen_zero(opt_args[OPT_ARG_ANNOUNCE])) {
02300 res = 0;
02301 } else {
02302 int digit = 0;
02303 struct ast_channel *chans[2];
02304 struct ast_channel *active_chan;
02305
02306 chans[0] = chan;
02307 chans[1] = peer;
02308
02309
02310
02311
02312 res = ast_streamfile(peer, opt_args[OPT_ARG_ANNOUNCE], peer->language);
02313 if (res) {
02314 res = 0;
02315 ast_log(LOG_ERROR, "error streaming file '%s' to callee\n", opt_args[OPT_ARG_ANNOUNCE]);
02316 }
02317
02318 ast_set_flag(peer, AST_FLAG_END_DTMF_ONLY);
02319 while (peer->stream) {
02320 int ms;
02321
02322 ms = ast_sched_wait(peer->sched);
02323
02324 if (ms < 0 && !peer->timingfunc) {
02325 ast_stopstream(peer);
02326 break;
02327 }
02328 if (ms < 0)
02329 ms = 1000;
02330
02331 active_chan = ast_waitfor_n(chans, 2, &ms);
02332 if (active_chan) {
02333 struct ast_frame *fr = ast_read(active_chan);
02334 if (!fr) {
02335 ast_hangup(peer);
02336 res = -1;
02337 goto done;
02338 }
02339 switch(fr->frametype) {
02340 case AST_FRAME_DTMF_END:
02341 digit = fr->subclass.integer;
02342 if (active_chan == peer && strchr(AST_DIGIT_ANY, res)) {
02343 ast_stopstream(peer);
02344 res = ast_senddigit(chan, digit, 0);
02345 }
02346 break;
02347 case AST_FRAME_CONTROL:
02348 switch (fr->subclass.integer) {
02349 case AST_CONTROL_HANGUP:
02350 ast_frfree(fr);
02351 ast_hangup(peer);
02352 res = -1;
02353 goto done;
02354 default:
02355 break;
02356 }
02357 break;
02358 default:
02359
02360 break;
02361 }
02362 ast_frfree(fr);
02363 }
02364 ast_sched_runq(peer->sched);
02365 }
02366 ast_clear_flag(peer, AST_FLAG_END_DTMF_ONLY);
02367 }
02368
02369 if (chan && peer && ast_test_flag64(&opts, OPT_GOTO) && !ast_strlen_zero(opt_args[OPT_ARG_GOTO])) {
02370
02371
02372 ast_clear_flag(chan->cdr, AST_CDR_FLAG_DIALED);
02373 ast_clear_flag(peer->cdr, AST_CDR_FLAG_DIALED);
02374
02375 replace_macro_delimiter(opt_args[OPT_ARG_GOTO]);
02376 ast_parseable_goto(chan, opt_args[OPT_ARG_GOTO]);
02377
02378 ast_copy_string(peer->context, chan->context, sizeof(peer->context));
02379 ast_copy_string(peer->exten, chan->exten, sizeof(peer->exten));
02380 peer->priority = chan->priority + 2;
02381 ast_pbx_start(peer);
02382 hanguptree(outgoing, NULL, ast_test_flag64(&opts, OPT_CANCEL_ELSEWHERE) ? 1 : 0);
02383 if (continue_exec)
02384 *continue_exec = 1;
02385 res = 0;
02386 goto done;
02387 }
02388
02389 if (ast_test_flag64(&opts, OPT_CALLEE_MACRO) && !ast_strlen_zero(opt_args[OPT_ARG_CALLEE_MACRO])) {
02390 struct ast_app *theapp;
02391 const char *macro_result;
02392
02393 res = ast_autoservice_start(chan);
02394 if (res) {
02395 ast_log(LOG_ERROR, "Unable to start autoservice on calling channel\n");
02396 res = -1;
02397 }
02398
02399 theapp = pbx_findapp("Macro");
02400
02401 if (theapp && !res) {
02402
02403 ast_copy_string(peer->context, chan->context, sizeof(peer->context));
02404 ast_copy_string(peer->exten, chan->exten, sizeof(peer->exten));
02405
02406 replace_macro_delimiter(opt_args[OPT_ARG_CALLEE_MACRO]);
02407 res = pbx_exec(peer, theapp, opt_args[OPT_ARG_CALLEE_MACRO]);
02408 ast_debug(1, "Macro exited with status %d\n", res);
02409 res = 0;
02410 } else {
02411 ast_log(LOG_ERROR, "Could not find application Macro\n");
02412 res = -1;
02413 }
02414
02415 if (ast_autoservice_stop(chan) < 0) {
02416 res = -1;
02417 }
02418
02419 ast_channel_lock(peer);
02420
02421 if (!res && (macro_result = pbx_builtin_getvar_helper(peer, "MACRO_RESULT"))) {
02422 char *macro_transfer_dest;
02423
02424 if (!strcasecmp(macro_result, "BUSY")) {
02425 ast_copy_string(pa.status, macro_result, sizeof(pa.status));
02426 ast_set_flag64(peerflags, OPT_GO_ON);
02427 res = -1;
02428 } else if (!strcasecmp(macro_result, "CONGESTION") || !strcasecmp(macro_result, "CHANUNAVAIL")) {
02429 ast_copy_string(pa.status, macro_result, sizeof(pa.status));
02430 ast_set_flag64(peerflags, OPT_GO_ON);
02431 res = -1;
02432 } else if (!strcasecmp(macro_result, "CONTINUE")) {
02433
02434
02435
02436
02437 ast_set_flag64(peerflags, OPT_GO_ON);
02438 res = -1;
02439 } else if (!strcasecmp(macro_result, "ABORT")) {
02440
02441 res = -1;
02442 } else if (!strncasecmp(macro_result, "GOTO:", 5) && (macro_transfer_dest = ast_strdupa(macro_result + 5))) {
02443 res = -1;
02444
02445 if (strchr(macro_transfer_dest, '^')) {
02446 replace_macro_delimiter(macro_transfer_dest);
02447 if (!ast_parseable_goto(chan, macro_transfer_dest))
02448 ast_set_flag64(peerflags, OPT_GO_ON);
02449 }
02450 }
02451 }
02452
02453 ast_channel_unlock(peer);
02454 }
02455
02456 if (ast_test_flag64(&opts, OPT_CALLEE_GOSUB) && !ast_strlen_zero(opt_args[OPT_ARG_CALLEE_GOSUB])) {
02457 struct ast_app *theapp;
02458 const char *gosub_result;
02459 char *gosub_args, *gosub_argstart;
02460 int res9 = -1;
02461
02462 res9 = ast_autoservice_start(chan);
02463 if (res9) {
02464 ast_log(LOG_ERROR, "Unable to start autoservice on calling channel\n");
02465 res9 = -1;
02466 }
02467
02468 theapp = pbx_findapp("Gosub");
02469
02470 if (theapp && !res9) {
02471 replace_macro_delimiter(opt_args[OPT_ARG_CALLEE_GOSUB]);
02472
02473
02474 ast_copy_string(peer->context, "app_dial_gosub_virtual_context", sizeof(peer->context));
02475 ast_copy_string(peer->exten, "s", sizeof(peer->exten));
02476 peer->priority = 0;
02477
02478 gosub_argstart = strchr(opt_args[OPT_ARG_CALLEE_GOSUB], ',');
02479 if (gosub_argstart) {
02480 *gosub_argstart = 0;
02481 if (asprintf(&gosub_args, "%s,s,1(%s)", opt_args[OPT_ARG_CALLEE_GOSUB], gosub_argstart + 1) < 0) {
02482 ast_log(LOG_WARNING, "asprintf() failed: %s\n", strerror(errno));
02483 gosub_args = NULL;
02484 }
02485 *gosub_argstart = ',';
02486 } else {
02487 if (asprintf(&gosub_args, "%s,s,1", opt_args[OPT_ARG_CALLEE_GOSUB]) < 0) {
02488 ast_log(LOG_WARNING, "asprintf() failed: %s\n", strerror(errno));
02489 gosub_args = NULL;
02490 }
02491 }
02492
02493 if (gosub_args) {
02494 res9 = pbx_exec(peer, theapp, gosub_args);
02495 if (!res9) {
02496 struct ast_pbx_args args;
02497
02498 memset(&args, 0, sizeof(args));
02499 args.no_hangup_chan = 1;
02500 ast_pbx_run_args(peer, &args);
02501 }
02502 ast_free(gosub_args);
02503 ast_debug(1, "Gosub exited with status %d\n", res9);
02504 } else {
02505 ast_log(LOG_ERROR, "Could not Allocate string for Gosub arguments -- Gosub Call Aborted!\n");
02506 }
02507
02508 } else if (!res9) {
02509 ast_log(LOG_ERROR, "Could not find application Gosub\n");
02510 res9 = -1;
02511 }
02512
02513 if (ast_autoservice_stop(chan) < 0) {
02514 ast_log(LOG_ERROR, "Could not stop autoservice on calling channel\n");
02515 res9 = -1;
02516 }
02517
02518 ast_channel_lock(peer);
02519
02520 if (!res9 && (gosub_result = pbx_builtin_getvar_helper(peer, "GOSUB_RESULT"))) {
02521 char *gosub_transfer_dest;
02522 const char *gosub_retval = pbx_builtin_getvar_helper(peer, "GOSUB_RETVAL");
02523
02524
02525 if (gosub_retval) {
02526 pbx_builtin_setvar_helper(chan, "GOSUB_RETVAL", gosub_retval);
02527 }
02528
02529 if (!strcasecmp(gosub_result, "BUSY")) {
02530 ast_copy_string(pa.status, gosub_result, sizeof(pa.status));
02531 ast_set_flag64(peerflags, OPT_GO_ON);
02532 res = -1;
02533 } else if (!strcasecmp(gosub_result, "CONGESTION") || !strcasecmp(gosub_result, "CHANUNAVAIL")) {
02534 ast_copy_string(pa.status, gosub_result, sizeof(pa.status));
02535 ast_set_flag64(peerflags, OPT_GO_ON);
02536 res = -1;
02537 } else if (!strcasecmp(gosub_result, "CONTINUE")) {
02538
02539
02540
02541
02542 ast_set_flag64(peerflags, OPT_GO_ON);
02543 res = -1;
02544 } else if (!strcasecmp(gosub_result, "ABORT")) {
02545
02546 res = -1;
02547 } else if (!strncasecmp(gosub_result, "GOTO:", 5) && (gosub_transfer_dest = ast_strdupa(gosub_result + 5))) {
02548 res = -1;
02549
02550 if (strchr(gosub_transfer_dest, '^')) {
02551 replace_macro_delimiter(gosub_transfer_dest);
02552 if (!ast_parseable_goto(chan, gosub_transfer_dest))
02553 ast_set_flag64(peerflags, OPT_GO_ON);
02554 }
02555 }
02556 }
02557
02558 ast_channel_unlock(peer);
02559 }
02560
02561 if (!res) {
02562 if (!ast_tvzero(calldurationlimit)) {
02563 struct timeval whentohangup = calldurationlimit;
02564 peer->whentohangup = ast_tvadd(ast_tvnow(), whentohangup);
02565 }
02566 if (!ast_strlen_zero(dtmfcalled)) {
02567 ast_verb(3, "Sending DTMF '%s' to the called party.\n", dtmfcalled);
02568 res = ast_dtmf_stream(peer, chan, dtmfcalled, 250, 0);
02569 }
02570 if (!ast_strlen_zero(dtmfcalling)) {
02571 ast_verb(3, "Sending DTMF '%s' to the calling party.\n", dtmfcalling);
02572 res = ast_dtmf_stream(chan, peer, dtmfcalling, 250, 0);
02573 }
02574 }
02575
02576 if (res) {
02577 res = -1;
02578 } else {
02579 if (ast_test_flag64(peerflags, OPT_CALLEE_TRANSFER))
02580 ast_set_flag(&(config.features_callee), AST_FEATURE_REDIRECT);
02581 if (ast_test_flag64(peerflags, OPT_CALLER_TRANSFER))
02582 ast_set_flag(&(config.features_caller), AST_FEATURE_REDIRECT);
02583 if (ast_test_flag64(peerflags, OPT_CALLEE_HANGUP))
02584 ast_set_flag(&(config.features_callee), AST_FEATURE_DISCONNECT);
02585 if (ast_test_flag64(peerflags, OPT_CALLER_HANGUP))
02586 ast_set_flag(&(config.features_caller), AST_FEATURE_DISCONNECT);
02587 if (ast_test_flag64(peerflags, OPT_CALLEE_MONITOR))
02588 ast_set_flag(&(config.features_callee), AST_FEATURE_AUTOMON);
02589 if (ast_test_flag64(peerflags, OPT_CALLER_MONITOR))
02590 ast_set_flag(&(config.features_caller), AST_FEATURE_AUTOMON);
02591 if (ast_test_flag64(peerflags, OPT_CALLEE_PARK))
02592 ast_set_flag(&(config.features_callee), AST_FEATURE_PARKCALL);
02593 if (ast_test_flag64(peerflags, OPT_CALLER_PARK))
02594 ast_set_flag(&(config.features_caller), AST_FEATURE_PARKCALL);
02595 if (ast_test_flag64(peerflags, OPT_CALLEE_MIXMONITOR))
02596 ast_set_flag(&(config.features_callee), AST_FEATURE_AUTOMIXMON);
02597 if (ast_test_flag64(peerflags, OPT_CALLER_MIXMONITOR))
02598 ast_set_flag(&(config.features_caller), AST_FEATURE_AUTOMIXMON);
02599 if (ast_test_flag64(peerflags, OPT_GO_ON))
02600 ast_set_flag(&(config.features_caller), AST_FEATURE_NO_H_EXTEN);
02601
02602 config.end_bridge_callback = end_bridge_callback;
02603 config.end_bridge_callback_data = chan;
02604 config.end_bridge_callback_data_fixup = end_bridge_callback_data_fixup;
02605
02606 if (moh) {
02607 moh = 0;
02608 ast_moh_stop(chan);
02609 } else if (sentringing) {
02610 sentringing = 0;
02611 ast_indicate(chan, -1);
02612 }
02613
02614 ast_deactivate_generator(chan);
02615 chan->visible_indication = 0;
02616
02617 res = ast_channel_make_compatible(chan, peer);
02618 if (res < 0) {
02619 ast_log(LOG_WARNING, "Had to drop call because I couldn't make %s compatible with %s\n", chan->name, peer->name);
02620 ast_hangup(peer);
02621 res = -1;
02622 goto done;
02623 }
02624 if (opermode) {
02625 struct oprmode oprmode;
02626
02627 oprmode.peer = peer;
02628 oprmode.mode = opermode;
02629
02630 ast_channel_setoption(chan, AST_OPTION_OPRMODE, &oprmode, sizeof(oprmode), 0);
02631 }
02632 res = ast_bridge_call(chan, peer, &config);
02633 }
02634
02635 strcpy(peer->context, chan->context);
02636
02637 if (ast_test_flag64(&opts, OPT_PEER_H)
02638 && ast_exists_extension(peer, peer->context, "h", 1,
02639 S_COR(peer->caller.id.number.valid, peer->caller.id.number.str, NULL))) {
02640 int autoloopflag;
02641 int found;
02642 int res9;
02643
02644 strcpy(peer->exten, "h");
02645 peer->priority = 1;
02646 autoloopflag = ast_test_flag(peer, AST_FLAG_IN_AUTOLOOP);
02647 ast_set_flag(peer, AST_FLAG_IN_AUTOLOOP);
02648
02649 while ((res9 = ast_spawn_extension(peer, peer->context, peer->exten,
02650 peer->priority,
02651 S_COR(peer->caller.id.number.valid, peer->caller.id.number.str, NULL),
02652 &found, 1)) == 0) {
02653 peer->priority++;
02654 }
02655
02656 if (found && res9) {
02657
02658 ast_debug(1, "Spawn extension (%s,%s,%d) exited non-zero on '%s'\n", peer->context, peer->exten, peer->priority, peer->name);
02659 ast_verb(2, "Spawn extension (%s, %s, %d) exited non-zero on '%s'\n", peer->context, peer->exten, peer->priority, peer->name);
02660 }
02661 ast_set2_flag(peer, autoloopflag, AST_FLAG_IN_AUTOLOOP);
02662 }
02663 if (!ast_check_hangup(peer) && ast_test_flag64(&opts, OPT_CALLEE_GO_ON)) {
02664 if(!ast_strlen_zero(opt_args[OPT_ARG_CALLEE_GO_ON])) {
02665 replace_macro_delimiter(opt_args[OPT_ARG_CALLEE_GO_ON]);
02666 ast_parseable_goto(peer, opt_args[OPT_ARG_CALLEE_GO_ON]);
02667 } else {
02668 int res;
02669 res = ast_goto_if_exists(peer, chan->context, chan->exten, (chan->priority) + 1);
02670 if (res == AST_PBX_GOTO_FAILED) {
02671 ast_hangup(peer);
02672 goto out;
02673 }
02674 }
02675 ast_pbx_start(peer);
02676 } else {
02677 if (!ast_check_hangup(chan))
02678 chan->hangupcause = peer->hangupcause;
02679 ast_hangup(peer);
02680 }
02681 }
02682 out:
02683 if (moh) {
02684 moh = 0;
02685 ast_moh_stop(chan);
02686 } else if (sentringing) {
02687 sentringing = 0;
02688 ast_indicate(chan, -1);
02689 }
02690
02691 if (delprivintro && ast_fileexists(pa.privintro, NULL, NULL) > 0) {
02692 ast_filedelete(pa.privintro, NULL);
02693 if (ast_fileexists(pa.privintro, NULL, NULL) > 0) {
02694 ast_log(LOG_NOTICE, "privacy: ast_filedelete didn't do its job on %s\n", pa.privintro);
02695 } else {
02696 ast_verb(3, "Successfully deleted %s intro file\n", pa.privintro);
02697 }
02698 }
02699
02700 ast_channel_early_bridge(chan, NULL);
02701 hanguptree(outgoing, NULL, 0);
02702 pbx_builtin_setvar_helper(chan, "DIALSTATUS", pa.status);
02703 senddialendevent(chan, pa.status);
02704 ast_debug(1, "Exiting with DIALSTATUS=%s.\n", pa.status);
02705
02706 if ((ast_test_flag64(peerflags, OPT_GO_ON)) && !ast_check_hangup(chan) && (res != AST_PBX_INCOMPLETE)) {
02707 if (!ast_tvzero(calldurationlimit))
02708 memset(&chan->whentohangup, 0, sizeof(chan->whentohangup));
02709 res = 0;
02710 }
02711
02712 done:
02713 if (config.warning_sound) {
02714 ast_free((char *)config.warning_sound);
02715 }
02716 if (config.end_sound) {
02717 ast_free((char *)config.end_sound);
02718 }
02719 if (config.start_sound) {
02720 ast_free((char *)config.start_sound);
02721 }
02722 ast_ignore_cc(chan);
02723 return res;
02724 }
02725
02726 static int dial_exec(struct ast_channel *chan, const char *data)
02727 {
02728 struct ast_flags64 peerflags;
02729
02730 memset(&peerflags, 0, sizeof(peerflags));
02731
02732 return dial_exec_full(chan, data, &peerflags, NULL);
02733 }
02734
02735 static int retrydial_exec(struct ast_channel *chan, const char *data)
02736 {
02737 char *parse;
02738 const char *context = NULL;
02739 int sleepms = 0, loops = 0, res = -1;
02740 struct ast_flags64 peerflags = { 0, };
02741 AST_DECLARE_APP_ARGS(args,
02742 AST_APP_ARG(announce);
02743 AST_APP_ARG(sleep);
02744 AST_APP_ARG(retries);
02745 AST_APP_ARG(dialdata);
02746 );
02747
02748 if (ast_strlen_zero(data)) {
02749 ast_log(LOG_WARNING, "RetryDial requires an argument!\n");
02750 return -1;
02751 }
02752
02753 parse = ast_strdupa(data);
02754 AST_STANDARD_APP_ARGS(args, parse);
02755
02756 if (!ast_strlen_zero(args.sleep) && (sleepms = atoi(args.sleep)))
02757 sleepms *= 1000;
02758
02759 if (!ast_strlen_zero(args.retries)) {
02760 loops = atoi(args.retries);
02761 }
02762
02763 if (!args.dialdata) {
02764 ast_log(LOG_ERROR, "%s requires a 4th argument (dialdata)\n", rapp);
02765 goto done;
02766 }
02767
02768 if (sleepms < 1000)
02769 sleepms = 10000;
02770
02771 if (!loops)
02772 loops = -1;
02773
02774 ast_channel_lock(chan);
02775 context = pbx_builtin_getvar_helper(chan, "EXITCONTEXT");
02776 context = !ast_strlen_zero(context) ? ast_strdupa(context) : NULL;
02777 ast_channel_unlock(chan);
02778
02779 res = 0;
02780 while (loops) {
02781 int continue_exec;
02782
02783 chan->data = "Retrying";
02784 if (ast_test_flag(chan, AST_FLAG_MOH))
02785 ast_moh_stop(chan);
02786
02787 res = dial_exec_full(chan, args.dialdata, &peerflags, &continue_exec);
02788 if (continue_exec)
02789 break;
02790
02791 if (res == 0) {
02792 if (ast_test_flag64(&peerflags, OPT_DTMF_EXIT)) {
02793 if (!ast_strlen_zero(args.announce)) {
02794 if (ast_fileexists(args.announce, NULL, chan->language) > 0) {
02795 if (!(res = ast_streamfile(chan, args.announce, chan->language)))
02796 ast_waitstream(chan, AST_DIGIT_ANY);
02797 } else
02798 ast_log(LOG_WARNING, "Announce file \"%s\" specified in Retrydial does not exist\n", args.announce);
02799 }
02800 if (!res && sleepms) {
02801 if (!ast_test_flag(chan, AST_FLAG_MOH))
02802 ast_moh_start(chan, NULL, NULL);
02803 res = ast_waitfordigit(chan, sleepms);
02804 }
02805 } else {
02806 if (!ast_strlen_zero(args.announce)) {
02807 if (ast_fileexists(args.announce, NULL, chan->language) > 0) {
02808 if (!(res = ast_streamfile(chan, args.announce, chan->language)))
02809 res = ast_waitstream(chan, "");
02810 } else
02811 ast_log(LOG_WARNING, "Announce file \"%s\" specified in Retrydial does not exist\n", args.announce);
02812 }
02813 if (sleepms) {
02814 if (!ast_test_flag(chan, AST_FLAG_MOH))
02815 ast_moh_start(chan, NULL, NULL);
02816 if (!res)
02817 res = ast_waitfordigit(chan, sleepms);
02818 }
02819 }
02820 }
02821
02822 if (res < 0 || res == AST_PBX_INCOMPLETE) {
02823 break;
02824 } else if (res > 0) {
02825 if (onedigit_goto(chan, context, (char) res, 1)) {
02826 res = 0;
02827 break;
02828 }
02829 }
02830 loops--;
02831 }
02832 if (loops == 0)
02833 res = 0;
02834 else if (res == 1)
02835 res = 0;
02836
02837 if (ast_test_flag(chan, AST_FLAG_MOH))
02838 ast_moh_stop(chan);
02839 done:
02840 return res;
02841 }
02842
02843 static int unload_module(void)
02844 {
02845 int res;
02846 struct ast_context *con;
02847
02848 res = ast_unregister_application(app);
02849 res |= ast_unregister_application(rapp);
02850
02851 if ((con = ast_context_find("app_dial_gosub_virtual_context"))) {
02852 ast_context_remove_extension2(con, "s", 1, NULL, 0);
02853 ast_context_destroy(con, "app_dial");
02854 }
02855
02856 return res;
02857 }
02858
02859 static int load_module(void)
02860 {
02861 int res;
02862 struct ast_context *con;
02863
02864 con = ast_context_find_or_create(NULL, NULL, "app_dial_gosub_virtual_context", "app_dial");
02865 if (!con)
02866 ast_log(LOG_ERROR, "Dial virtual context 'app_dial_gosub_virtual_context' does not exist and unable to create\n");
02867 else
02868 ast_add_extension2(con, 1, "s", 1, NULL, NULL, "NoOp", ast_strdup(""), ast_free_ptr, "app_dial");
02869
02870 res = ast_register_application_xml(app, dial_exec);
02871 res |= ast_register_application_xml(rapp, retrydial_exec);
02872
02873 return res;
02874 }
02875
02876 AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Dialing Application");