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