Merged revisions 87262 via svnmerge from
authorTilghman Lesher <tilghman@meg.abyt.es>
Sun, 28 Oct 2007 14:11:01 +0000 (14:11 +0000)
committerTilghman Lesher <tilghman@meg.abyt.es>
Sun, 28 Oct 2007 14:11:01 +0000 (14:11 +0000)
https://origsvn.digium.com/svn/asterisk/branches/1.4

........
r87262 | tilghman | 2007-10-28 08:46:55 -0500 (Sun, 28 Oct 2007) | 7 lines

Add autoservice to several more functions which might delay in their responses.
Also, make sure that func_odbc functions have a channel on which to set
variables.
Reported by russell
Fixed by tilghman
Closes issue #11099

........

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

funcs/func_cut.c
funcs/func_odbc.c
funcs/func_realtime.c
funcs/func_strings.c

index 7b4f0f4..82a564b 100644 (file)
@@ -126,7 +126,7 @@ static int cut_internal(struct ast_channel *chan, char *data, char *buffer, size
        );
 
        memset(buffer, 0, buflen); 
-       
+
        parse = ast_strdupa(data);
 
        AST_STANDARD_APP_ARGS(args, parse);
@@ -235,6 +235,9 @@ static int acf_cut_exec(struct ast_channel *chan, const char *cmd, char *data, c
 {
        int ret = -1;
 
+       if (chan)
+               ast_autoservice_start(chan);
+
        switch (cut_internal(chan, data, buf, len)) {
        case ERROR_NOARG:
                ast_log(LOG_ERROR, "Syntax: CUT(<varname>,<char-delim>,<range-spec>) - missing argument!\n");
@@ -252,6 +255,9 @@ static int acf_cut_exec(struct ast_channel *chan, const char *cmd, char *data, c
                ast_log(LOG_ERROR, "Unknown internal error\n");
        }
 
+       if (chan)
+               ast_autoservice_stop(chan);
+
        return ret;
 }
 
index f9272fe..069eaf7 100644 (file)
@@ -139,7 +139,7 @@ static int acf_odbc_write(struct ast_channel *chan, const char *cmd, char *s, co
        struct odbc_obj *obj = NULL;
        struct acf_odbc_query *query;
        char *t, buf[2048]="", varname[15];
-       int i, dsn;
+       int i, dsn, bogus_chan = 0;
        AST_DECLARE_APP_ARGS(values,
                AST_APP_ARG(field)[100];
        );
@@ -162,12 +162,24 @@ static int acf_odbc_write(struct ast_channel *chan, const char *cmd, char *s, co
                return -1;
        }
 
+       if (!chan) {
+               if ((chan = ast_channel_alloc(0, 0, "", "", "", "", "", 0, "Bogus/func_odbc")))
+                       bogus_chan = 1;
+       }
+
+       if (chan)
+               ast_autoservice_start(chan);
+
        /* Parse our arguments */
        t = value ? ast_strdupa(value) : "";
 
        if (!s || !t) {
                ast_log(LOG_ERROR, "Out of memory\n");
                AST_LIST_UNLOCK(&queries);
+               if (chan)
+                       ast_autoservice_stop(chan);
+               if (bogus_chan)
+                       ast_channel_free(chan);
                return -1;
        }
 
@@ -232,6 +244,11 @@ static int acf_odbc_write(struct ast_channel *chan, const char *cmd, char *s, co
        if (obj)
                ast_odbc_release_obj(obj);
 
+       if (chan)
+               ast_autoservice_stop(chan);
+       if (bogus_chan)
+               ast_channel_free(chan);
+
        return 0;
 }
 
@@ -240,7 +257,7 @@ static int acf_odbc_read(struct ast_channel *chan, const char *cmd, char *s, cha
        struct odbc_obj *obj = NULL;
        struct acf_odbc_query *query;
        char sql[2048] = "", varname[15], colnames[2048] = "", rowcount[12] = "-1";
-       int res, x, y, buflen = 0, escapecommas, rowlimit = 1, dsn;
+       int res, x, y, buflen = 0, escapecommas, rowlimit = 1, dsn, bogus_chan = 0;
        AST_DECLARE_APP_ARGS(args,
                AST_APP_ARG(field)[100];
        );
@@ -265,6 +282,14 @@ static int acf_odbc_read(struct ast_channel *chan, const char *cmd, char *s, cha
                return -1;
        }
 
+       if (!chan) {
+               if ((chan = ast_channel_alloc(0, 0, "", "", "", "", "", 0, "Bogus/func_odbc")))
+                       bogus_chan = 1;
+       }
+
+       if (chan)
+               ast_autoservice_start(chan);
+
        AST_STANDARD_APP_ARGS(args, s);
        for (x = 0; x < args.argc; x++) {
                snprintf(varname, sizeof(varname), "ARG%d", x + 1);
@@ -306,6 +331,10 @@ static int acf_odbc_read(struct ast_channel *chan, const char *cmd, char *s, cha
                if (obj)
                        ast_odbc_release_obj(obj);
                pbx_builtin_setvar_helper(chan, "ODBCROWS", rowcount);
+               if (chan)
+                       ast_autoservice_stop(chan);
+               if (bogus_chan)
+                       ast_channel_free(chan);
                return -1;
        }
 
@@ -316,6 +345,10 @@ static int acf_odbc_read(struct ast_channel *chan, const char *cmd, char *s, cha
                SQLFreeHandle (SQL_HANDLE_STMT, stmt);
                ast_odbc_release_obj(obj);
                pbx_builtin_setvar_helper(chan, "ODBCROWS", rowcount);
+               if (chan)
+                       ast_autoservice_stop(chan);
+               if (bogus_chan)
+                       ast_channel_free(chan);
                return -1;
        }
 
@@ -333,6 +366,10 @@ static int acf_odbc_read(struct ast_channel *chan, const char *cmd, char *s, cha
                SQLFreeHandle(SQL_HANDLE_STMT, stmt);
                ast_odbc_release_obj(obj);
                pbx_builtin_setvar_helper(chan, "ODBCROWS", rowcount);
+               if (chan)
+                       ast_autoservice_stop(chan);
+               if (bogus_chan)
+                       ast_channel_free(chan);
                return res1;
        }
 
@@ -380,6 +417,10 @@ static int acf_odbc_read(struct ast_channel *chan, const char *cmd, char *s, cha
                                                SQLFreeHandle(SQL_HANDLE_STMT, stmt);
                                                ast_odbc_release_obj(obj);
                                                pbx_builtin_setvar_helper(chan, "ODBCROWS", rowcount);
+                                               if (chan)
+                                                       ast_autoservice_stop(chan);
+                                               if (bogus_chan)
+                                                       ast_channel_free(chan);
                                                return -1;
                                        }
                                        resultset = tmp;
@@ -456,6 +497,10 @@ end_acf_read:
                        SQLCloseCursor(stmt);
                        SQLFreeHandle(SQL_HANDLE_STMT, stmt);
                        ast_odbc_release_obj(obj);
+                       if (chan)
+                               ast_autoservice_stop(chan);
+                       if (bogus_chan)
+                               ast_channel_free(chan);
                        return -1;
                }
                odbc_store->data = resultset;
@@ -464,6 +509,10 @@ end_acf_read:
        SQLCloseCursor(stmt);
        SQLFreeHandle(SQL_HANDLE_STMT, stmt);
        ast_odbc_release_obj(obj);
+       if (chan)
+               ast_autoservice_stop(chan);
+       if (bogus_chan)
+               ast_channel_free(chan);
        return 0;
 }
 
index 1f67fcb..bc9063f 100644 (file)
@@ -71,9 +71,14 @@ static int function_realtime_read(struct ast_channel *chan, const char *cmd, cha
        if (!args.delim2)
                args.delim2 = "=";
 
+       if (chan)
+               ast_autoservice_start(chan);
+
        head = ast_load_realtime_all(args.family, args.fieldmatch, args.value, NULL);
 
        if (!head)
+               if (chan)
+                       ast_autoservice_stop(chan);
                return -1;
 
        resultslen = 0;
@@ -88,6 +93,9 @@ static int function_realtime_read(struct ast_channel *chan, const char *cmd, cha
                ast_str_append(&out, 0, "%s%s%s%s", var->name, args.delim2, var->value, args.delim1);
        ast_copy_string(buf, out->str, len);
 
+       if (chan)
+               ast_autoservice_stop(chan);
+
        return 0;
 }
 
@@ -106,6 +114,9 @@ static int function_realtime_write(struct ast_channel *chan, const char *cmd, ch
                return -1;
        }
 
+       if (chan)
+               ast_autoservice_start(chan);
+
        AST_STANDARD_APP_ARGS(args, data);
 
        res = ast_update_realtime(args.family, args.fieldmatch, args.value, args.field, (char *)value, NULL);
@@ -114,6 +125,9 @@ static int function_realtime_write(struct ast_channel *chan, const char *cmd, ch
                ast_log(LOG_WARNING, "Failed to update. Check the debug log for possible data repository related entries.\n");
        }
 
+       if (chan)
+               ast_autoservice_stop(chan);
+
        return 0;
 }
 
index 3230b67..f4869f4 100644 (file)
@@ -57,6 +57,9 @@ static int function_fieldqty(struct ast_channel *chan, const char *cmd,
        char delim[2] = "";
        size_t delim_used;
 
+       if (chan)
+               ast_autoservice_start(chan);
+
        AST_STANDARD_APP_ARGS(args, parse);
        if (args.delim) {
                ast_get_encoded_char(args.delim, delim, &delim_used);
@@ -76,6 +79,9 @@ static int function_fieldqty(struct ast_channel *chan, const char *cmd,
        }
        snprintf(buf, len, "%d", fieldcount);
 
+       if (chan)
+               ast_autoservice_stop(chan);
+
        return 0;
 }
 
@@ -255,13 +261,19 @@ static int array(struct ast_channel *chan, const char *cmd, char *var,
        if (!var || !value2)
                return -1;
 
+       if (chan)
+               ast_autoservice_start(chan);
+
        if (!strcmp(cmd, "HASH")) {
                const char *var2 = pbx_builtin_getvar_helper(chan, "~ODBCFIELDS~");
                origvar = var;
                if (var2)
                        var = ast_strdupa(var2);
-               else
+               else {
+                       if (chan)
+                               ast_autoservice_stop(chan);
                        return -1;
+               }
                ishash = 1;
        }
 
@@ -298,6 +310,9 @@ static int array(struct ast_channel *chan, const char *cmd, char *var,
                }
        }
 
+       if (chan)
+               ast_autoservice_stop(chan);
+
        return 0;
 }
 
@@ -726,7 +741,11 @@ static int function_eval(struct ast_channel *chan, const char *cmd, char *data,
                return -1;
        }
 
+       if (chan)
+               ast_autoservice_start(chan);
        pbx_substitute_variables_helper(chan, data, buf, len - 1);
+       if (chan)
+               ast_autoservice_stop(chan);
 
        return 0;
 }