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