]> git.ipfire.org Git - thirdparty/asterisk.git/commitdiff
fix inherited softhangup issue in ast_goto_if_exists()
authorAnthony Minessale II <anthmct@yahoo.com>
Tue, 23 Nov 2004 20:25:02 +0000 (20:25 +0000)
committerAnthony Minessale II <anthmct@yahoo.com>
Tue, 23 Nov 2004 20:25:02 +0000 (20:25 +0000)
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@4325 65c4cc65-6c06-0410-ace0-fbb531ad65f3

include/asterisk/pbx.h
pbx.c

index 4343dc35cc53e58e3be9931c999ae945ff4c7cae..37c72d6c91e3f6bb36292a3048a29560824c2f7d 100755 (executable)
@@ -581,6 +581,8 @@ extern int pbx_set_autofallthrough(int newval);
 int ast_goto_if_exists(struct ast_channel *chan, char* context, char *exten, int priority);
 /* I can find neither parsable nor parseable at dictionary.com, but google gives me 169000 hits for parseable and only 49,800 for parsable */
 int ast_parseable_goto(struct ast_channel *chan, const char *goto_string);
+int ast_explicit_goto(struct ast_channel *chan, const char *context, const char *exten, int priority);
+int ast_async_goto_if_exists(struct ast_channel *chan, char* context, char *exten, int priority);
 #if defined(__cplusplus) || defined(c_plusplus)
 }
 #endif
diff --git a/pbx.c b/pbx.c
index bc954d72b0e9632521fe9646e19b13fcee7d0a80..5ae63735e9f4adb43be14ed03241886c3d28fb4e 100755 (executable)
--- a/pbx.c
+++ b/pbx.c
@@ -3844,6 +3844,19 @@ int ast_add_extension(const char *context, int replace, const char *extension, i
        return -1;
 }
 
+int ast_explicit_goto(struct ast_channel *chan, const char *context, const char *exten, int priority) {
+       if(chan && !ast_check_hangup(chan)) {
+               if (context && !ast_strlen_zero(context))
+                       strncpy(chan->context, context, sizeof(chan->context) - 1);
+               if (exten && !ast_strlen_zero(exten))
+                       strncpy(chan->exten, exten, sizeof(chan->context) - 1);
+               if (priority)
+                       chan->priority = priority - 1;  
+               return 0;
+       }
+       return -1;
+}
+
 int ast_async_goto(struct ast_channel *chan, const char *context, const char *exten, int priority)
 {
        int res = 0;
@@ -3851,12 +3864,7 @@ int ast_async_goto(struct ast_channel *chan, const char *context, const char *ex
 
        if (chan->pbx) {
                /* This channel is currently in the PBX */
-               if (context && !ast_strlen_zero(context))
-                       strncpy(chan->context, context, sizeof(chan->context) - 1);
-               if (exten && !ast_strlen_zero(exten))
-                       strncpy(chan->exten, exten, sizeof(chan->context) - 1);
-               if (priority)
-                       chan->priority = priority - 1;
+               ast_explicit_goto(chan, context, exten, priority);
                ast_softhangup_nolock(chan, AST_SOFTHANGUP_ASYNCGOTO);
        } else {
                /* In order to do it when the channel doesn't really exist within
@@ -3871,19 +3879,11 @@ int ast_async_goto(struct ast_channel *chan, const char *context, const char *ex
                        tmpchan->readformat = chan->readformat;
                        tmpchan->writeformat = chan->writeformat;
                        /* Setup proper location */
-                       if (context && !ast_strlen_zero(context))
-                               strncpy(tmpchan->context, context, sizeof(tmpchan->context) - 1);
-                       else
-                               strncpy(tmpchan->context, chan->context, sizeof(tmpchan->context) - 1);
-                       if (exten && !ast_strlen_zero(exten))
-                               strncpy(tmpchan->exten, exten, sizeof(tmpchan->exten) - 1);
-                       else
-                               strncpy(tmpchan->exten, chan->exten, sizeof(tmpchan->exten) - 1);
-                       if (priority)
-                               tmpchan->priority = priority;
-                       else
-                               tmpchan->priority = chan->priority;
-                       
+                       ast_explicit_goto(tmpchan,
+                                                         (context && !ast_strlen_zero(context)) ? context : chan->context,
+                                                         (exten && !ast_strlen_zero(exten)) ? exten : chan->exten,
+                                                         priority ? priority : chan->priority);
+
                        /* Masquerade into temp channel */
                        ast_channel_masquerade(tmpchan, chan);
                
@@ -5423,15 +5423,17 @@ int ast_context_verify_includes(struct ast_context *con)
 }
 
 
-int ast_goto_if_exists(struct ast_channel *chan, char* context, char *exten, int priority
+static int __ast_goto_if_exists(struct ast_channel *chan, char* context, char *exten, int priority, int async
 {
+       int (*goto_func)(struct ast_channel *chan, const char *context, const char *exten, int priority) = async ? ast_async_goto : ast_explicit_goto;
+
        if(chan) {
                if(ast_exists_extension(chan, 
                                                                context ? context : chan->context,
                                                                exten ? exten : chan->exten,
                                                                priority ? priority : chan->priority,
                                                                chan->cid.cid_num)) {
-                       return ast_async_goto(chan,
+                       return goto_func(chan,
                                                                  context ? context : chan->context,
                                                                  exten ? exten : chan->exten,
                                                                  priority ? priority : chan->priority);
@@ -5442,6 +5444,14 @@ int ast_goto_if_exists(struct ast_channel *chan, char* context, char *exten, int
        return -2;
 }
 
+int ast_goto_if_exists(struct ast_channel *chan, char* context, char *exten, int priority) {
+       return __ast_goto_if_exists(chan, context, exten, priority, 0);
+}
+
+int ast_async_goto_if_exists(struct ast_channel *chan, char* context, char *exten, int priority) {
+       return __ast_goto_if_exists(chan, context, exten, priority, 1);
+}
+
 int ast_parseable_goto(struct ast_channel *chan, const char *goto_string) 
 {
        char *s;