Merge work to make U(...) option work for Dial
authorTilghman Lesher <tilghman@meg.abyt.es>
Wed, 20 Jun 2007 17:35:08 +0000 (17:35 +0000)
committerTilghman Lesher <tilghman@meg.abyt.es>
Wed, 20 Jun 2007 17:35:08 +0000 (17:35 +0000)
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@70358 65c4cc65-6c06-0410-ace0-fbb531ad65f3

apps/app_dial.c
pbx/pbx_ael.c

index c8b0007..3ce59e7 100644 (file)
@@ -194,9 +194,7 @@ static char *descrip =
 "           GOSUB_RESULT to specify the following actions after the Gosub returns.\n" 
 "           * ABORT        Hangup both legs of the call.\n"
 "           * CONGESTION   Behave as if line congestion was encountered.\n"
-"           * BUSY         Behave as if a busy signal was encountered. This will also\n"
-"                          have the application jump to priority n+101 if the\n"
-"                          'j' option is set.\n"
+"           * BUSY         Behave as if a busy signal was encountered.\n"
 "           * CONTINUE     Hangup the called party and allow the calling party\n"
 "                          to continue dialplan execution at the next priority.\n"
 "           * GOTO:<context>^<exten>^<priority> - Transfer the call to the\n"
@@ -226,6 +224,10 @@ static char *rdescrip =
 "  The 'dialargs' are specified in the same format that arguments are provided\n"
 "to the Dial application.\n";
 
+static char *kapp = "KeepAlive";
+static char *ksynopsis = "DO NOT USE";
+static char *kdescrip = "";
+
 enum {
        OPT_ANNOUNCE =          (1 << 0),
        OPT_RESETCDR =          (1 << 1),
@@ -1634,6 +1636,8 @@ static int dial_exec_full(struct ast_channel *chan, void *data, struct ast_flags
                if (ast_test_flag(&opts, OPT_CALLEE_GOSUB) && !ast_strlen_zero(opt_args[OPT_ARG_CALLEE_GOSUB])) {
                        struct ast_app *theapp;
                        const char *gosub_result;
+                       char *gosub_args, *gosub_argstart;
+                       ast_log(LOG_ERROR, "In OPT_CALLEE_GOSUB code!\n");
 
                        res = ast_autoservice_start(chan);
                        if (res) {
@@ -1645,9 +1649,33 @@ static int dial_exec_full(struct ast_channel *chan, void *data, struct ast_flags
 
                        if (theapp && !res) {   /* XXX why check res here ? */
                                replace_macro_delimiter(opt_args[OPT_ARG_CALLEE_GOSUB]);
-                               res = pbx_exec(peer, theapp, opt_args[OPT_ARG_CALLEE_GOSUB]);
-                               if (option_debug)
-                                       ast_log(LOG_DEBUG, "Gosub exited with status %d\n", res);
+
+                               /* Set where we came from */
+                               ast_copy_string(peer->context, "app_dial_gosub_virtual_context", sizeof(peer->context));
+                               ast_copy_string(peer->exten, "s", sizeof(peer->exten));
+                               peer->priority = 0;
+
+                               ast_log(LOG_ERROR, "Gosub stuff is: %s\n", opt_args[OPT_ARG_CALLEE_GOSUB]);
+                               gosub_argstart = strchr(opt_args[OPT_ARG_CALLEE_GOSUB], '|');
+                               if (gosub_argstart) {
+                                       *gosub_argstart = 0;
+                                       asprintf(&gosub_args, "%s|s|1(%s)", opt_args[OPT_ARG_CALLEE_GOSUB], gosub_argstart + 1);
+                                       *gosub_argstart = '|';
+                               } else {
+                                       asprintf(&gosub_args, "%s|s|1", opt_args[OPT_ARG_CALLEE_GOSUB]);
+                               }
+                               ast_log(LOG_DEBUG, "Gosub_args is: %s\n", gosub_args);
+                               if (gosub_args) {
+                                       ast_log(LOG_ERROR, "About to pbx_exec!\n");
+                                       res = pbx_exec(peer, theapp, gosub_args);
+                                       ast_pbx_run(peer);
+                                       ast_log(LOG_ERROR, "pbx_exec returns %d!\n", res);
+                                       free(gosub_args);
+                                       if (option_debug)
+                                               ast_log(LOG_DEBUG, "Gosub exited with status %d\n", res);
+                               } else
+                                       ast_log(LOG_ERROR, "Could not Allocate string for Gosub arguments -- Gosub Call Aborted!\n");
+                               
                                res = 0;
                        } else {
                                ast_log(LOG_ERROR, "Could not find application Gosub\n");
@@ -1910,24 +1938,45 @@ static int retrydial_exec(struct ast_channel *chan, void *data)
        return res;
 }
 
+static int keepalive_exec(struct ast_channel *chan, void *data)
+{
+       return AST_PBX_KEEPALIVE;
+}
+
 static int unload_module(void)
 {
        int res;
+       struct ast_context *con;
 
        res = ast_unregister_application(app);
        res |= ast_unregister_application(rapp);
+       res |= ast_unregister_application(kapp);
 
        ast_module_user_hangup_all();
-       
+
+       if ((con = ast_context_find("app_dial_gosub_virtual_context"))) {
+               ast_context_remove_extension2(con, "s", 1, NULL);
+       }
+
        return res;
 }
 
 static int load_module(void)
 {
        int res;
+       struct ast_context *con;
+
+       con = ast_context_find("app_dial_gosub_virtual_context");
+       if (!con)
+               con = ast_context_create(NULL, "app_dial_gosub_virtual_context", "app_dial");
+       if (!con)
+               ast_log(LOG_ERROR, "Dial virtual context 'app_dial_gosub_virtual_context' does not exist and unable to create\n");
+       else
+               ast_add_extension2(con, 1, "s", 1, NULL, NULL, "KeepAlive", ast_strdup(""), ast_free, "app_dial");
 
        res = ast_register_application(app, dial_exec, synopsis, descrip);
        res |= ast_register_application(rapp, retrydial_exec, rsynopsis, rdescrip);
+       res |= ast_register_application(kapp, keepalive_exec, ksynopsis, kdescrip);
        
        return res;
 }
index c2b12aa..66ea629 100644 (file)
@@ -3886,7 +3886,7 @@ void ast_compile_ael2(struct ast_context **local_contexts, struct pval *root)
                                struct ael_priority *np2 = new_prio();
                                np2->type = AEL_APPCALL;
                                np2->app = strdup("Set");
-                               snprintf(buf,sizeof(buf),"%s=${ARG%d}", lp->u1.str, argc++);
+                               snprintf(buf,sizeof(buf),"LOCAL(%s)=${ARG%d}", lp->u1.str, argc++);
                                remove_spaces_before_equals(buf);
                                np2->appargs = strdup(buf);
                                linkprio(exten, np2);