]> git.ipfire.org Git - thirdparty/asterisk.git/commitdiff
Dialplan functions should not actually return 0, unless they have modified the
authorTilghman Lesher <tilghman@meg.abyt.es>
Mon, 6 Oct 2008 20:52:04 +0000 (20:52 +0000)
committerTilghman Lesher <tilghman@meg.abyt.es>
Mon, 6 Oct 2008 20:52:04 +0000 (20:52 +0000)
workspace.  To signal an error (and no change to the workspace), -1 should be
returned instead.
(closes issue #13340)
 Reported by: kryptolus
 Patches:
       20080827__bug13340__2.diff.txt uploaded by Corydon76 (license 14)

git-svn-id: https://origsvn.digium.com/svn/asterisk/branches/1.4@146799 65c4cc65-6c06-0410-ace0-fbb531ad65f3

apps/app_speech_utils.c
channels/chan_iax2.c
channels/chan_sip.c
funcs/func_callerid.c
funcs/func_cdr.c
funcs/func_curl.c
funcs/func_groupcount.c
funcs/func_math.c
funcs/func_odbc.c
funcs/func_timeout.c
res/res_smdi.c

index 64d0f1bc48df4aa5b3e3903943c1eddc2080bbbe..6e498f29fb4a64183bc54d66ac25371a96dfe5b5 100644 (file)
@@ -193,8 +193,11 @@ static int speech_text(struct ast_channel *chan, char *cmd, char *data,
        if (data == NULL || speech == NULL || !(result = find_result(speech->results, data)))
                 return -1;
 
-       if (result->text != NULL)
+       if (result->text != NULL) {
                ast_copy_string(buf, result->text, len);
+       } else {
+               buf[0] = '\0';
+       }
 
         return 0;
 }
@@ -219,8 +222,11 @@ static int speech_grammar(struct ast_channel *chan, char *cmd, char *data,
        if (data == NULL || speech == NULL || !(result = find_result(speech->results, data)))
                 return -1;
 
-       if (result->grammar != NULL)
+       if (result->grammar != NULL) {
                ast_copy_string(buf, result->grammar, len);
+       } else {
+               buf[0] = '\0';
+       }
 
         return 0;
 }
@@ -322,6 +328,8 @@ static int speech_read(struct ast_channel *chan, char *cmd, char *data,
                }
                snprintf(tmp, sizeof(tmp), "%d", results);
                ast_copy_string(buf, tmp, len);
+       } else {
+               buf[0] = '\0';
        }
 
        return 0;
index 0d972bd25e18b1d174dec5d8daa5e751b06fa0ef..5d593dd0c20d741e92f2a41a5a4b067202305206 100644 (file)
@@ -10695,7 +10695,11 @@ static int function_iaxpeer(struct ast_channel *chan, char *cmd, char *data, cha
                index = atoi(codecnum);
                if((codec = ast_codec_pref_index(&peer->prefs, index))) {
                        ast_copy_string(buf, ast_getformatname(codec), len);
+               } else {
+                       buf[0] = '\0';
                }
+       } else {
+               buf[0] = '\0';
        }
 
        peer_unref(peer);
index 9d9f9cb7d9dd2a46172cbd4c9f0f349b47807035..07b923629a76865e2c2994120ebe87acc5c14efb 100644 (file)
@@ -12001,7 +12001,11 @@ static int function_sippeer(struct ast_channel *chan, char *cmd, char *data, cha
                index = atoi(codecnum);
                if((codec = ast_codec_pref_index(&peer->prefs, index))) {
                        ast_copy_string(buf, ast_getformatname(codec), len);
+               } else {
+                       buf[0] = '\0';
                }
+       } else {
+               buf[0] = '\0';
        }
 
        ASTOBJ_UNREF(peer, sip_destroy_peer);
index ef3c447bb521b587dba6c27ff28ef145cf2ff0b0..19b8f413f49046df04d69317d4de30d8238f8535 100644 (file)
@@ -41,6 +41,7 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
 static int callerid_read(struct ast_channel *chan, char *cmd, char *data,
                         char *buf, size_t len)
 {
+       int res = -1;
        char *opt = data;
 
        if (!chan)
@@ -54,12 +55,15 @@ static int callerid_read(struct ast_channel *chan, char *cmd, char *data,
 
                if (!strncasecmp("all", data, 3)) {
                        snprintf(buf, len, "\"%s\" <%s>", name, num);
+                       res = 0;
                } else if (!strncasecmp("name", data, 4)) {
                        ast_copy_string(buf, name, len);
+                       res = 0;
                } else if (!strncasecmp("num", data, 3) ||
                           !strncasecmp("number", data, 6)) {
 
                        ast_copy_string(buf, num, len);
+                       res = 0;
                } else {
                        ast_log(LOG_ERROR, "Unknown callerid data type '%s'.\n", data);
                }
@@ -70,26 +74,32 @@ static int callerid_read(struct ast_channel *chan, char *cmd, char *data,
                        snprintf(buf, len, "\"%s\" <%s>",
                                 S_OR(chan->cid.cid_name, ""),
                                 S_OR(chan->cid.cid_num, ""));
+                       res = 0;
                } else if (!strncasecmp("name", data, 4)) {
                        if (chan->cid.cid_name) {
                                ast_copy_string(buf, chan->cid.cid_name, len);
+                               res = 0;
                        }
                } else if (!strncasecmp("num", data, 3)
                                   || !strncasecmp("number", data, 6)) {
                        if (chan->cid.cid_num) {
                                ast_copy_string(buf, chan->cid.cid_num, len);
+                               res = 0;
                        }
                } else if (!strncasecmp("ani", data, 3)) {
                        if (chan->cid.cid_ani) {
                                ast_copy_string(buf, chan->cid.cid_ani, len);
+                               res = 0;
                        }
                } else if (!strncasecmp("dnid", data, 4)) {
                        if (chan->cid.cid_dnid) {
                                ast_copy_string(buf, chan->cid.cid_dnid, len);
+                               res = 0;
                        }
                } else if (!strncasecmp("rdnis", data, 5)) {
                        if (chan->cid.cid_rdnis) {
                                ast_copy_string(buf, chan->cid.cid_rdnis, len);
+                               res = 0;
                        }
                } else {
                        ast_log(LOG_ERROR, "Unknown callerid data type '%s'.\n", data);
@@ -98,7 +108,7 @@ static int callerid_read(struct ast_channel *chan, char *cmd, char *data,
                ast_channel_unlock(chan);
        }
 
-       return 0;
+       return res;
 }
 
 static int callerid_write(struct ast_channel *chan, char *cmd, char *data,
index 08dedcb1e9a3764e72f6f0524afc4465ec94ef66..4e90246c4c323cb549c339d151d6421670edddb6 100644 (file)
@@ -88,7 +88,7 @@ static int cdr_read(struct ast_channel *chan, char *cmd, char *parse,
                       ast_test_flag(&flags, OPT_RECURSIVE),
                           ast_test_flag(&flags, OPT_UNPARSED));
 
-       return 0;
+       return ret ? 0 : -1;
 }
 
 static int cdr_write(struct ast_channel *chan, char *cmd, char *parse,
index bc6eadee08684940aa0af81016d604310b663264..2c71cf7a2eb8f7654aa304f2014687acb4fe9eb8 100644 (file)
@@ -97,6 +97,7 @@ AST_THREADSTORAGE_CUSTOM(curl_instance, curl_instance_init, curl_instance_cleanu
 
 static int curl_internal(struct MemoryStruct *chunk, char *url, char *post)
 {
+       int ret;
        CURL **curl;
 
        if (!(curl = ast_threadstorage_get(&curl_instance, sizeof(*curl))))
@@ -119,16 +120,17 @@ static int curl_internal(struct MemoryStruct *chunk, char *url, char *post)
                curl_easy_setopt(*curl, CURLOPT_POSTFIELDS, post);
        }
 
-       curl_easy_perform(*curl);
+       ret = curl_easy_perform(*curl);
 
        if (post)
                curl_easy_setopt(*curl, CURLOPT_POST, 0);
 
-       return 0;
+       return ret ? -1 : 0;
 }
 
 static int acf_curl_exec(struct ast_channel *chan, char *cmd, char *info, char *buf, size_t len)
 {
+       int ret = -1;
        struct ast_module_user *u;
        struct MemoryStruct chunk = { NULL, 0 };
        AST_DECLARE_APP_ARGS(args,
@@ -159,6 +161,7 @@ static int acf_curl_exec(struct ast_channel *chan, char *cmd, char *info, char *
                        ast_copy_string(buf, chunk.memory, len);
                        free(chunk.memory);
                }
+               ret = 0;
        } else {
                ast_log(LOG_ERROR, "Cannot allocate curl structure\n");
        }
@@ -168,7 +171,7 @@ static int acf_curl_exec(struct ast_channel *chan, char *cmd, char *info, char *
 
        ast_module_user_remove(u);
 
-       return 0;
+       return ret;
 }
 
 struct ast_custom_function acf_curl = {
index bb2bcf49c1927c3d8cd3283bb2337757ae53a01e..7f6f8937bf104492dab018b27edbdd3b4eff4bd2 100644 (file)
@@ -39,6 +39,7 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
 static int group_count_function_read(struct ast_channel *chan, char *cmd,
                                     char *data, char *buf, size_t len)
 {
+       int ret = -1;
        int count = -1;
        char group[80] = "", category[80] = "";
 
@@ -64,12 +65,14 @@ static int group_count_function_read(struct ast_channel *chan, char *cmd,
                ast_app_group_list_unlock();
        }
 
-       if ((count = ast_app_group_get_count(group, category)) == -1)
+       if ((count = ast_app_group_get_count(group, category)) == -1) {
                ast_log(LOG_NOTICE, "No group could be found for channel '%s'\n", chan->name);
-       else
+       } else {
                snprintf(buf, len, "%d", count);
+               ret = 0;
+       }
 
-       return 0;
+       return ret;
 }
 
 static struct ast_custom_function group_count_function = {
@@ -96,9 +99,10 @@ static int group_match_count_function_read(struct ast_channel *chan,
        if (!ast_strlen_zero(group)) {
                count = ast_app_group_match_get_count(group, category);
                snprintf(buf, len, "%d", count);
+               return 0;
        }
 
-       return 0;
+       return -1;
 }
 
 static struct ast_custom_function group_match_count_function = {
@@ -116,6 +120,7 @@ static struct ast_custom_function group_match_count_function = {
 static int group_function_read(struct ast_channel *chan, char *cmd,
                               char *data, char *buf, size_t len)
 {
+       int ret = -1;
        struct ast_group_info *gi = NULL;
        
        ast_app_group_list_lock();
@@ -129,12 +134,14 @@ static int group_function_read(struct ast_channel *chan, char *cmd,
                        break;
        }
        
-       if (gi)
+       if (gi) {
                ast_copy_string(buf, gi->group, len);
+               ret = 0;
+       }
        
        ast_app_group_list_unlock();
        
-       return 0;
+       return ret;
 }
 
 static int group_function_write(struct ast_channel *chan, char *cmd,
index cefc94d934357481e8aeb3dad215a2cfe4c70d9e..edded75755d9ca4215522c212da910727a579229 100644 (file)
@@ -78,14 +78,14 @@ static int math(struct ast_channel *chan, char *cmd, char *parse,
        );
 
        if (ast_strlen_zero(parse)) {
-               ast_log(LOG_WARNING, "Syntax: Math(<number1><op><number 2>[,<type_of_result>]) - missing argument!\n");
+               ast_log(LOG_WARNING, "Syntax: MATH(<number1><op><number 2>[,<type_of_result>]) - missing argument!\n");
                return -1;
        }
 
        AST_STANDARD_APP_ARGS(args, parse);
 
        if (args.argc < 1) {
-               ast_log(LOG_WARNING, "Syntax: Math(<number1><op><number 2>[,<type_of_result>]) - missing argument!\n");
+               ast_log(LOG_WARNING, "Syntax: MATH(<number1><op><number 2>[,<type_of_result>]) - missing argument!\n");
                return -1;
        }
 
index ce25d0feec864039fbdb08e4a9dd04440994537f..b0a13adefc8f7d68f89e48f30cab11c0b88967a0 100644 (file)
@@ -218,7 +218,7 @@ static int acf_odbc_read(struct ast_channel *chan, char *cmd, char *s, char *buf
        struct odbc_obj *obj;
        struct acf_odbc_query *query;
        char sql[2048] = "", varname[15];
-       int res, x, buflen = 0, escapecommas, bogus_chan = 0;
+       int res, x, buflen = 1, escapecommas, bogus_chan = 0;
        AST_DECLARE_APP_ARGS(args,
                AST_APP_ARG(field)[100];
        );
index f327e7608a6cf51d1defe4c62ff67fa4cd5025de..5b935605ae5d0ede2e2c98ca2b2c39419b3ec306 100644 (file)
@@ -80,7 +80,7 @@ static int timeout_read(struct ast_channel *chan, char *cmd, char *data,
 
        default:
                ast_log(LOG_ERROR, "Unknown timeout type specified.\n");
-               break;
+               return -1;
        }
 
        return 0;
index 83a5e1f7cf4e2400fa96d7b82ab6c0b049e2ea59..406a740c9cac7dd3b02b9574e2558624e4a764ea 100644 (file)
@@ -1265,7 +1265,7 @@ static int smdi_msg_read(struct ast_channel *chan, char *cmd, char *data, char *
 return_error:
        ast_module_user_remove(u);
 
-       return 0;
+       return res;
 }
 
 static struct ast_custom_function smdi_msg_retrieve_function = {