Add a missing part of the connected line work into trunk.
[asterisk/asterisk.git] / apps / app_dial.c
index c24a566..66e8bb8 100644 (file)
@@ -132,10 +132,13 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
                                        <para>Execute the <literal>h</literal> extension for peer after the call ends</para>
                                </option>
                                <option name="f">
-                                       <para>Force the callerid of the <emphasis>calling</emphasis> channel to be set as the
-                                       extension associated with the channel using a dialplan <literal>hint</literal>.
+                                       <argument name="x" required="false" />
+                                       <para>If <replaceable>x</replaceable> is not provided, force the callerid of the <emphasis>calling</emphasis> 
+                                       channel to be set as the extension associated with the channel using a dialplan <literal>hint</literal>.
                                        For example, some PSTNs do not allow CallerID to be set to anything
-                                       other than the number assigned to the caller.</para>
+                                       other than the number assigned to the caller. If <replaceable>x</replaceable> is provided, though, then
+                                       this option behaves quite differently. Any outgoing channel created will have its connected party information
+                                       set to <replaceable>x</replaceable></para>
                                </option>
                                <option name="F" argsep="^">
                                        <argument name="context" required="false" />
@@ -546,6 +549,7 @@ enum {
        OPT_ARG_DURATION_STOP,
        OPT_ARG_OPERMODE,
        OPT_ARG_SCREEN_NOINTRO,
+       OPT_ARG_FORCECLID,
        /* note: this entry _MUST_ be the last one in the enum */
        OPT_ARG_ARRAY_SIZE,
 };
@@ -558,7 +562,7 @@ AST_APP_OPTIONS(dial_exec_options, BEGIN_OPTIONS
        AST_APP_OPTION('d', OPT_DTMF_EXIT),
        AST_APP_OPTION_ARG('D', OPT_SENDDTMF, OPT_ARG_SENDDTMF),
        AST_APP_OPTION('e', OPT_PEER_H),
-       AST_APP_OPTION('f', OPT_FORCECLID),
+       AST_APP_OPTION_ARG('f', OPT_FORCECLID, OPT_ARG_FORCECLID),
        AST_APP_OPTION_ARG('F', OPT_CALLEE_GO_ON, OPT_ARG_CALLEE_GO_ON),
        AST_APP_OPTION('g', OPT_GO_ON),
        AST_APP_OPTION_ARG('G', OPT_GOTO, OPT_ARG_GOTO),
@@ -1623,7 +1627,7 @@ static int dial_exec_full(struct ast_channel *chan, const char *data, struct ast
        struct cause_args num = { chan, 0, 0, 0 };
        int cause;
        char numsubst[256];
-       char cidname[AST_MAX_EXTENSION] = "";
+       char *cid_num = NULL, *cid_name = NULL;
 
        struct ast_bridge_config config = { { 0, } };
        struct timeval calldurationlimit = { 0, };
@@ -1718,6 +1722,8 @@ static int dial_exec_full(struct ast_channel *chan, const char *data, struct ast
                        goto done;
        }
 
+       if (ast_test_flag64(&opts, OPT_FORCECLID) && !ast_strlen_zero(opt_args[OPT_ARG_FORCECLID]))
+               ast_callerid_parse(opt_args[OPT_ARG_FORCECLID], &cid_name, &cid_num);
        if (ast_test_flag64(&opts, OPT_RESETCDR) && chan->cdr)
                ast_cdr_reset(chan->cdr, NULL);
        if (ast_test_flag64(&opts, OPT_PRIVACY) && ast_strlen_zero(opt_args[OPT_ARG_PRIVACY]))
@@ -1748,7 +1754,7 @@ static int dial_exec_full(struct ast_channel *chan, const char *data, struct ast
        }
        ast_channel_unlock(chan);       
        ast_copy_flags64(peerflags, &opts, OPT_DTMF_EXIT | OPT_GO_ON | OPT_ORIGINAL_CLID | OPT_CALLER_HANGUP | OPT_IGNORE_FORWARDING | OPT_IGNORE_CONNECTEDLINE |
-                        OPT_CANCEL_TIMEOUT | OPT_ANNOUNCE | OPT_CALLEE_MACRO | OPT_CALLEE_GOSUB);
+                        OPT_CANCEL_TIMEOUT | OPT_ANNOUNCE | OPT_CALLEE_MACRO | OPT_CALLEE_GOSUB | OPT_FORCECLID);
 
        /* loop through the list of dial destinations */
        rest = args.peers;
@@ -1894,8 +1900,18 @@ static int dial_exec_full(struct ast_channel *chan, const char *data, struct ast
                        }
                        ast_set_flag64(tmp, DIAL_NOCONNECTEDLINE);
                }
-               
-               ast_connected_line_copy_from_caller(&tc->connected, &chan->cid);
+
+               if (ast_test_flag64(peerflags, OPT_FORCECLID) && !ast_strlen_zero(opt_args[OPT_ARG_FORCECLID])) {
+                       struct ast_party_connected_line connected;
+
+                       ast_party_connected_line_set_init(&connected, &tmp->chan->connected);
+                       connected.id.number = cid_num;
+                       connected.id.name = cid_name;
+                       connected.id.number_presentation = AST_PRES_ALLOWED_USER_NUMBER_PASSED_SCREEN;
+                       ast_channel_set_connected_line(tmp->chan, &connected);
+               } else {
+                       ast_connected_line_copy_from_caller(&tmp->chan->connected, &chan->cid);
+               }
 
                S_REPLACE(tc->cid.cid_rdnis, ast_strdup(chan->cid.cid_rdnis));
                ast_party_redirecting_copy(&tc->redirecting, &chan->redirecting);
@@ -1958,6 +1974,7 @@ static int dial_exec_full(struct ast_channel *chan, const char *data, struct ast
                        ast_verb(3, "Called %s\n", numsubst);
                        ast_channel_unlock(chan);
                        if (!ast_test_flag64(peerflags, OPT_ORIGINAL_CLID)) {
+                               char cidname[AST_MAX_EXTENSION];
                                ast_set_callerid(tc, tmpexten, get_cid_name(cidname, sizeof(cidname), chan), NULL);
                        }
                }