~ubuntu-branches/ubuntu/quantal/asterisk/quantal

« back to all changes in this revision

Viewing changes to apps/app_dial.c

  • Committer: Bazaar Package Importer
  • Author(s): Jean-Michel Dault
  • Date: 2010-02-16 14:08:54 UTC
  • mfrom: (1.2.5 upstream) (8.3.4 sid)
  • Revision ID: james.westby@ubuntu.com-20100216140854-rb2godspb9lduazl
Tags: 1:1.6.2.2-1ubuntu1
* Merge from Debian: security update
  * Changes:
  - debian/control: Change Maintainer
  - debian/control: Removed Uploaders field.
  - debian/control: Removed Debian Vcs-Svn entry and replaced with
      ubuntu-voip Vcs-Bzr, to reflect divergence in packages.
  - debian/asterisk.init : chown /dev/dahdi
  - debian/backports/hardy : add file
  - debian/backports/asterisk.init.hardy : add file

Show diffs side-by-side

added added

removed removed

Lines of Context:
32
32
 
33
33
#include "asterisk.h"
34
34
 
35
 
ASTERISK_FILE_VERSION(__FILE__, "$Revision: 208596 $")
 
35
ASTERISK_FILE_VERSION(__FILE__, "$Revision: 227831 $")
36
36
 
37
37
#include <sys/time.h>
38
38
#include <sys/signal.h>
253
253
                                        Macro()</para></warning>
254
254
                                </option>
255
255
                                <option name="n">
 
256
                                        <argument name="delete">
 
257
                                                <para>With <replaceable>delete</replaceable> either not specified or set to <literal>0</literal>,
 
258
                                                the recorded introduction will not be deleted if the caller hangs up while the remote party has not
 
259
                                                yet answered.</para>
 
260
                                                <para>With <replaceable>delete</replaceable> set to <literal>1</literal>, the introduction will
 
261
                                                always be deleted.</para>
 
262
                                        </argument>
256
263
                                        <para>This option is a modifier for the call screening/privacy mode. (See the 
257
264
                                        <literal>p</literal> and <literal>P</literal> options.) It specifies
258
265
                                        that no introductions are to be saved in the <directory>priv-callerintros</directory>
507
514
        OPT_ARG_PRIVACY,
508
515
        OPT_ARG_DURATION_STOP,
509
516
        OPT_ARG_OPERMODE,
 
517
        OPT_ARG_SCREEN_NOINTRO,
510
518
        /* note: this entry _MUST_ be the last one in the enum */
511
519
        OPT_ARG_ARRAY_SIZE,
512
520
};
530
538
        AST_APP_OPTION_ARG('L', OPT_DURATION_LIMIT, OPT_ARG_DURATION_LIMIT),
531
539
        AST_APP_OPTION_ARG('m', OPT_MUSICBACK, OPT_ARG_MUSICBACK),
532
540
        AST_APP_OPTION_ARG('M', OPT_CALLEE_MACRO, OPT_ARG_CALLEE_MACRO),
533
 
        AST_APP_OPTION('n', OPT_SCREEN_NOINTRO),
 
541
        AST_APP_OPTION_ARG('n', OPT_SCREEN_NOINTRO, OPT_ARG_SCREEN_NOINTRO),
534
542
        AST_APP_OPTION('N', OPT_SCREEN_NOCLID),
535
543
        AST_APP_OPTION('o', OPT_ORIGINAL_CLID),
536
544
        AST_APP_OPTION_ARG('O', OPT_OPERMODE, OPT_ARG_OPERMODE),
549
557
 
550
558
#define CAN_EARLY_BRIDGE(flags,chan,peer) (!ast_test_flag64(flags, OPT_CALLEE_HANGUP | \
551
559
        OPT_CALLER_HANGUP | OPT_CALLEE_TRANSFER | OPT_CALLER_TRANSFER | \
552
 
        OPT_CALLEE_MONITOR | OPT_CALLER_MONITOR | OPT_CALLEE_PARK | OPT_CALLER_PARK) && \
 
560
        OPT_CALLEE_MONITOR | OPT_CALLER_MONITOR | OPT_CALLEE_PARK |  \
 
561
        OPT_CALLER_PARK | OPT_ANNOUNCE | OPT_CALLEE_MACRO | OPT_CALLEE_GOSUB) && \
553
562
        !chan->audiohooks && !peer->audiohooks)
554
563
 
555
564
/*
753
762
                char *new_cid_num, *new_cid_name;
754
763
                struct ast_channel *src;
755
764
 
756
 
                ast_rtp_make_compatible(c, in, single);
 
765
                if (CAN_EARLY_BRIDGE(peerflags, c, in)) {
 
766
                        ast_rtp_make_compatible(c, in, single);
 
767
                }
757
768
                if (ast_test_flag64(o, OPT_FORCECLID)) {
758
769
                        new_cid_num = ast_strdup(S_OR(in->macroexten, in->exten));
759
770
                        new_cid_name = NULL; /* XXX no name ? */
962
973
                                        if (single && CAN_EARLY_BRIDGE(peerflags, in, c))
963
974
                                                ast_channel_early_bridge(in, c);
964
975
                                        if (!ast_test_flag64(outgoing, OPT_RINGBACK))
965
 
                                                ast_indicate(in, AST_CONTROL_PROGRESS);
 
976
                                                if (single || (!single && !pa->sentringing)) {
 
977
                                                        ast_indicate(in, AST_CONTROL_PROGRESS);
 
978
                                                }
966
979
                                        break;
967
980
                                case AST_CONTROL_VIDUPDATE:
968
981
                                        ast_verb(3, "%s requested a video update, passing it to %s\n", c->name, in->name);
1524
1537
        int result = 0;
1525
1538
        char *parse;
1526
1539
        int opermode = 0;
 
1540
        int delprivintro = 0;
1527
1541
        AST_DECLARE_APP_ARGS(args,
1528
1542
                AST_APP_ARG(peers);
1529
1543
                AST_APP_ARG(timeout);
1565
1579
        }
1566
1580
 
1567
1581
 
 
1582
        if (ast_test_flag64(&opts, OPT_SCREEN_NOINTRO) && !ast_strlen_zero(opt_args[OPT_ARG_SCREEN_NOINTRO])) {
 
1583
                delprivintro = atoi(opt_args[OPT_ARG_SCREEN_NOINTRO]);
 
1584
 
 
1585
                if (delprivintro < 0 || delprivintro > 1) {
 
1586
                        ast_log(LOG_WARNING, "Unknown argument %d specified to n option, ignoring\n", delprivintro);
 
1587
                        delprivintro = 0;
 
1588
                }
 
1589
        }
 
1590
 
1568
1591
        if (ast_test_flag64(&opts, OPT_OPERMODE)) {
1569
1592
                opermode = ast_strlen_zero(opt_args[OPT_ARG_OPERMODE]) ? 1 : atoi(opt_args[OPT_ARG_OPERMODE]);
1570
1593
                ast_verb(3, "Setting operator services mode to %d.\n", opermode);
1619
1642
                outbound_group = ast_strdupa(outbound_group);
1620
1643
        }
1621
1644
        ast_channel_unlock(chan);       
1622
 
        ast_copy_flags64(peerflags, &opts, OPT_DTMF_EXIT | OPT_GO_ON | OPT_ORIGINAL_CLID | OPT_CALLER_HANGUP | OPT_IGNORE_FORWARDING);
 
1645
        ast_copy_flags64(peerflags, &opts, OPT_DTMF_EXIT | OPT_GO_ON | OPT_ORIGINAL_CLID | OPT_CALLER_HANGUP | OPT_IGNORE_FORWARDING | OPT_ANNOUNCE | OPT_CALLEE_MACRO | OPT_CALLEE_GOSUB);
1623
1646
 
1624
1647
        /* loop through the list of dial destinations */
1625
1648
        rest = args.peers;
1670
1693
                        datastore->inheritance = DATASTORE_INHERIT_FOREVER;
1671
1694
 
1672
1695
                        if (!(dialed_interfaces = ast_calloc(1, sizeof(*dialed_interfaces)))) {
 
1696
                                ast_datastore_free(datastore);
1673
1697
                                ast_free(tmp);
1674
1698
                                goto out;
1675
1699
                        }
1729
1753
                pbx_builtin_setvar_helper(tc, "DIALEDPEERNUMBER", numsubst);
1730
1754
 
1731
1755
                /* Setup outgoing SDP to match incoming one */
1732
 
                ast_rtp_make_compatible(tc, chan, !outgoing && !rest);
 
1756
                if (CAN_EARLY_BRIDGE(peerflags, chan, tc)) {
 
1757
                        ast_rtp_make_compatible(tc, chan, !outgoing && !rest);
 
1758
                }
1733
1759
                
1734
1760
                /* Inherit specially named variables from parent channel */
1735
1761
                ast_channel_inherit_variables(chan, tc);
1912
1938
                        res = 0;
1913
1939
                } else {
1914
1940
                        int digit = 0;
1915
 
                        /* Start autoservice on the other chan */
1916
 
                        res = ast_autoservice_start(chan);
1917
 
                        /* Now Stream the File */
1918
 
                        if (!res)
1919
 
                                res = ast_streamfile(peer, opt_args[OPT_ARG_ANNOUNCE], peer->language);
1920
 
                        if (!res) {
1921
 
                                digit = ast_waitstream(peer, AST_DIGIT_ANY);
1922
 
                        }
1923
 
                        /* Ok, done. stop autoservice */
1924
 
                        res = ast_autoservice_stop(chan);
1925
 
                        if (digit > 0 && !res)
1926
 
                                res = ast_senddigit(chan, digit, 0);
1927
 
                        else
1928
 
                                res = digit;
1929
 
 
 
1941
                        struct ast_channel *chans[2];
 
1942
                        struct ast_channel *active_chan;
 
1943
 
 
1944
                        chans[0] = chan;
 
1945
                        chans[1] = peer;
 
1946
 
 
1947
                        /* we need to stream the announcment while monitoring the caller for a hangup */
 
1948
 
 
1949
                        /* stream the file */
 
1950
                        res = ast_streamfile(peer, opt_args[OPT_ARG_ANNOUNCE], peer->language);
 
1951
                        if (res) {
 
1952
                                res = 0;
 
1953
                                ast_log(LOG_ERROR, "error streaming file '%s' to callee\n", opt_args[OPT_ARG_ANNOUNCE]);
 
1954
                        }
 
1955
 
 
1956
                        ast_set_flag(peer, AST_FLAG_END_DTMF_ONLY);
 
1957
                        while (peer->stream) {
 
1958
                                int ms;
 
1959
 
 
1960
                                ms = ast_sched_wait(peer->sched);
 
1961
 
 
1962
                                if (ms < 0 && !peer->timingfunc) {
 
1963
                                        ast_stopstream(peer);
 
1964
                                        break;
 
1965
                                }
 
1966
                                if (ms < 0)
 
1967
                                        ms = 1000;
 
1968
 
 
1969
                                active_chan = ast_waitfor_n(chans, 2, &ms);
 
1970
                                if (active_chan) {
 
1971
                                        struct ast_frame *fr = ast_read(active_chan);
 
1972
                                        if (!fr) {
 
1973
                                                ast_hangup(peer);
 
1974
                                                res = -1;
 
1975
                                                goto done;
 
1976
                                        }
 
1977
                                        switch(fr->frametype) {
 
1978
                                                case AST_FRAME_DTMF_END:
 
1979
                                                        digit = fr->subclass;
 
1980
                                                        if (active_chan == peer && strchr(AST_DIGIT_ANY, res)) {
 
1981
                                                                ast_stopstream(peer);
 
1982
                                                                res = ast_senddigit(chan, digit, 0);
 
1983
                                                        }
 
1984
                                                        break;
 
1985
                                                case AST_FRAME_CONTROL:
 
1986
                                                        switch (fr->subclass) {
 
1987
                                                                case AST_CONTROL_HANGUP:
 
1988
                                                                        ast_frfree(fr);
 
1989
                                                                        ast_hangup(peer);
 
1990
                                                                        res = -1;
 
1991
                                                                        goto done;
 
1992
                                                                default:
 
1993
                                                                        break;
 
1994
                                                        }
 
1995
                                                        break;
 
1996
                                                default:
 
1997
                                                        /* Ignore all others */
 
1998
                                                        break;
 
1999
                                        }
 
2000
                                        ast_frfree(fr);
 
2001
                                }
 
2002
                                ast_sched_runq(peer->sched);
 
2003
                        }
 
2004
                        ast_clear_flag(peer, AST_FLAG_END_DTMF_ONLY);
1930
2005
                }
1931
2006
 
1932
2007
                if (chan && peer && ast_test_flag64(&opts, OPT_GOTO) && !ast_strlen_zero(opt_args[OPT_ARG_GOTO])) {
2223
2298
                sentringing = 0;
2224
2299
                ast_indicate(chan, -1);
2225
2300
        }
 
2301
 
 
2302
        if (delprivintro && ast_fileexists(pa.privintro, NULL, NULL) > 0) {
 
2303
                ast_filedelete(pa.privintro, NULL);
 
2304
                if (ast_fileexists(pa.privintro, NULL, NULL) > 0) {
 
2305
                        ast_log(LOG_NOTICE, "privacy: ast_filedelete didn't do its job on %s\n", pa.privintro);
 
2306
                } else {
 
2307
                        ast_verb(3, "Successfully deleted %s intro file\n", pa.privintro);
 
2308
                }
 
2309
        }
 
2310
 
2226
2311
        ast_channel_early_bridge(chan, NULL);
2227
2312
        hanguptree(outgoing, NULL, 0); /* In this case, there's no answer anywhere */
2228
2313
        pbx_builtin_setvar_helper(chan, "DIALSTATUS", pa.status);