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