include "logger.h" and errno.h from asterisk.h - usage shows that they
[asterisk/asterisk.git] / apps / app_dial.c
index 87b3dcc..dfaa682 100644 (file)
 
 ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
 
-#include <stdlib.h>
-#include <errno.h>
-#include <unistd.h>
-#include <string.h>
-#include <stdlib.h>
-#include <stdio.h>
 #include <sys/time.h>
 #include <sys/signal.h>
 #include <sys/stat.h>
@@ -42,7 +36,6 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
 
 #include "asterisk/lock.h"
 #include "asterisk/file.h"
-#include "asterisk/logger.h"
 #include "asterisk/channel.h"
 #include "asterisk/pbx.h"
 #include "asterisk/options.h"
@@ -278,7 +271,7 @@ enum {
        OPT_ARG_ARRAY_SIZE,
 };
 
-AST_APP_OPTIONS(dial_exec_options, {
+AST_APP_OPTIONS(dial_exec_options, BEGIN_OPTIONS
        AST_APP_OPTION_ARG('A', OPT_ANNOUNCE, OPT_ARG_ANNOUNCE),
        AST_APP_OPTION('C', OPT_RESETCDR),
        AST_APP_OPTION('c', OPT_CANCEL_ELSEWHERE),
@@ -311,9 +304,11 @@ AST_APP_OPTIONS(dial_exec_options, {
        AST_APP_OPTION_ARG('U', OPT_CALLEE_GOSUB, OPT_ARG_CALLEE_GOSUB),
        AST_APP_OPTION('w', OPT_CALLEE_MONITOR),
        AST_APP_OPTION('W', OPT_CALLER_MONITOR),
-});
+END_OPTIONS );
 
-#define CAN_EARLY_BRIDGE(flags) (!ast_test_flag64(flags, OPT_CALLEE_HANGUP) && !ast_test_flag64(flags, OPT_CALLER_HANGUP) && !ast_test_flag64(flags, OPT_CALLEE_TRANSFER) && !ast_test_flag64(flags, OPT_CALLER_TRANSFER) && !ast_test_flag64(flags, OPT_CALLEE_MONITOR) && !ast_test_flag64(flags, OPT_CALLER_MONITOR) && !ast_test_flag64(flags, OPT_CALLEE_PARK) && !ast_test_flag64(flags, OPT_CALLER_PARK))
+#define CAN_EARLY_BRIDGE(flags) (!ast_test_flag64(flags, OPT_CALLEE_HANGUP | \
+       OPT_CALLER_HANGUP | OPT_CALLEE_TRANSFER | OPT_CALLER_TRANSFER | \
+       OPT_CALLEE_MONITOR | OPT_CALLER_MONITOR | OPT_CALLEE_PARK | OPT_CALLER_PARK))
 
 /*
  * The list of active channels
@@ -1404,6 +1399,7 @@ static int dial_exec_full(struct ast_channel *chan, void *data, struct ast_flags
                tc->cid.cid_pres = chan->cid.cid_pres;
                tc->cid.cid_ton = chan->cid.cid_ton;
                tc->cid.cid_tns = chan->cid.cid_tns;
+               tc->cid.cid_ani2 = chan->cid.cid_ani2;
                tc->adsicpe = chan->adsicpe;
                tc->transfercapability = chan->transfercapability;
 
@@ -1789,20 +1785,20 @@ static int dial_exec_full(struct ast_channel *chan, void *data, struct ast_flags
 
                if (ast_test_flag64(&opts, OPT_PEER_H) && ast_exists_extension(peer, peer->context, "h", 1, peer->cid.cid_num)) {
                        int autoloopflag;
+                       int found;
                        strcpy(peer->exten, "h");
                        peer->priority = 1;
                        autoloopflag = ast_test_flag(peer, AST_FLAG_IN_AUTOLOOP);       /* save value to restore at the end */
                        ast_set_flag(peer, AST_FLAG_IN_AUTOLOOP);
                        
-                       while (ast_exists_extension(peer, peer->context, peer->exten, peer->priority, peer->cid.cid_num)) {
-                               if ((res = ast_spawn_extension(peer, peer->context, peer->exten, peer->priority, peer->cid.cid_num))) {
-                                       /* Something bad happened, or a hangup has been requested. */
-                                       ast_debug(1, "Spawn extension (%s,%s,%d) exited non-zero on '%s'\n", peer->context, peer->exten, peer->priority, peer->name);
-                                       ast_verb(2, "Spawn extension (%s, %s, %d) exited non-zero on '%s'\n", peer->context, peer->exten, peer->priority, peer->name);
-                                       break;
-                               }
+                       while ((res = ast_spawn_extension(peer, peer->context, peer->exten, peer->priority, peer->cid.cid_num, &found,1))) {
                                peer->priority++;
                        }
+                       if (found && res) {
+                               /* Something bad happened, or a hangup has been requested. */
+                               ast_debug(1, "Spawn extension (%s,%s,%d) exited non-zero on '%s'\n", peer->context, peer->exten, peer->priority, peer->name);
+                               ast_verb(2, "Spawn extension (%s, %s, %d) exited non-zero on '%s'\n", peer->context, peer->exten, peer->priority, peer->name);
+                       }
                        ast_set2_flag(peer, autoloopflag, AST_FLAG_IN_AUTOLOOP);  /* set it back the way it was */
                }
                if (res != AST_PBX_NO_HANGUP_PEER) {