mirror of
https://github.com/asterisk/asterisk.git
synced 2025-11-01 11:32:25 +00:00
Simplify some nested functions, as suggested by Russell on -dev
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@151732 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
@@ -145,7 +145,7 @@ static int acf_odbc_write(struct ast_channel *chan, const char *cmd, char *s, co
|
||||
);
|
||||
SQLHSTMT stmt = NULL;
|
||||
SQLLEN rows=0;
|
||||
struct ast_str *buf = ast_str_create(16);
|
||||
struct ast_str *buf = ast_str_thread_get(&sql_buf, 16);
|
||||
|
||||
if (!buf) {
|
||||
return -1;
|
||||
@@ -275,7 +275,7 @@ static int acf_odbc_read(struct ast_channel *chan, const char *cmd, char *s, cha
|
||||
SQLSMALLINT collength;
|
||||
struct odbc_datastore *resultset = NULL;
|
||||
struct odbc_datastore_row *row = NULL;
|
||||
struct ast_str *sql = ast_str_create(16);
|
||||
struct ast_str *sql = ast_str_thread_get(&sql_buf, 16);
|
||||
|
||||
if (!sql) {
|
||||
return -1;
|
||||
@@ -297,12 +297,14 @@ static int acf_odbc_read(struct ast_channel *chan, const char *cmd, char *s, cha
|
||||
}
|
||||
|
||||
if (!chan) {
|
||||
if ((chan = ast_channel_alloc(0, 0, "", "", "", "", "", 0, "Bogus/func_odbc")))
|
||||
if ((chan = ast_channel_alloc(0, 0, "", "", "", "", "", 0, "Bogus/func_odbc"))) {
|
||||
bogus_chan = 1;
|
||||
}
|
||||
}
|
||||
|
||||
if (chan)
|
||||
if (chan) {
|
||||
ast_autoservice_start(chan);
|
||||
}
|
||||
|
||||
AST_STANDARD_APP_ARGS(args, s);
|
||||
for (x = 0; x < args.argc; x++) {
|
||||
@@ -324,32 +326,38 @@ static int acf_odbc_read(struct ast_channel *chan, const char *cmd, char *s, cha
|
||||
if (ast_test_flag(query, OPT_MULTIROW)) {
|
||||
resultset = ast_calloc(1, sizeof(*resultset));
|
||||
AST_LIST_HEAD_INIT(resultset);
|
||||
if (query->rowlimit)
|
||||
if (query->rowlimit) {
|
||||
rowlimit = query->rowlimit;
|
||||
else
|
||||
} else {
|
||||
rowlimit = INT_MAX;
|
||||
}
|
||||
}
|
||||
AST_RWLIST_UNLOCK(&queries);
|
||||
|
||||
for (dsn = 0; dsn < 5; dsn++) {
|
||||
if (!ast_strlen_zero(query->readhandle[dsn])) {
|
||||
obj = ast_odbc_request_obj(query->readhandle[dsn], 0);
|
||||
if (obj)
|
||||
if (obj) {
|
||||
stmt = ast_odbc_direct_execute(obj, generic_execute, sql->str);
|
||||
}
|
||||
if (stmt)
|
||||
}
|
||||
if (stmt) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!stmt) {
|
||||
ast_log(LOG_ERROR, "Unable to execute query [%s]\n", sql->str);
|
||||
if (obj)
|
||||
if (obj) {
|
||||
ast_odbc_release_obj(obj);
|
||||
}
|
||||
pbx_builtin_setvar_helper(chan, "ODBCROWS", rowcount);
|
||||
if (chan)
|
||||
if (chan) {
|
||||
ast_autoservice_stop(chan);
|
||||
if (bogus_chan)
|
||||
}
|
||||
if (bogus_chan) {
|
||||
ast_channel_free(chan);
|
||||
}
|
||||
ast_free(sql);
|
||||
return -1;
|
||||
}
|
||||
@@ -361,10 +369,12 @@ 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)
|
||||
if (chan) {
|
||||
ast_autoservice_stop(chan);
|
||||
if (bogus_chan)
|
||||
}
|
||||
if (bogus_chan) {
|
||||
ast_channel_free(chan);
|
||||
}
|
||||
ast_free(sql);
|
||||
return -1;
|
||||
}
|
||||
@@ -935,17 +945,25 @@ static char *cli_odbc_read(struct ast_cli_entry *e, int cmd, struct ast_cli_args
|
||||
int rows = 0, res, x;
|
||||
SQLSMALLINT colcount = 0, collength;
|
||||
SQLLEN indicator;
|
||||
|
||||
for (dsn = 0; dsn < 5; dsn++) {
|
||||
if (!ast_strlen_zero(query->readhandle[dsn])) {
|
||||
ast_debug(1, "Found handle %s\n", query->readhandle[dsn]);
|
||||
if ((obj = ast_odbc_request_obj(query->readhandle[dsn], 0))) {
|
||||
ast_debug(1, "Got obj\n");
|
||||
if ((stmt = ast_odbc_direct_execute(obj, generic_execute, sql->str))) {
|
||||
struct ast_str *coldata = ast_str_thread_get(&coldata_buf, 16);
|
||||
char colname[256];
|
||||
SQLULEN maxcol;
|
||||
|
||||
for (dsn = 0; dsn < 5; dsn++) {
|
||||
if (ast_strlen_zero(query->readhandle[dsn])) {
|
||||
continue;
|
||||
}
|
||||
ast_debug(1, "Found handle %s\n", query->readhandle[dsn]);
|
||||
if (!(obj = ast_odbc_request_obj(query->readhandle[dsn], 0))) {
|
||||
continue;
|
||||
}
|
||||
|
||||
ast_debug(1, "Got obj\n");
|
||||
if (!(stmt = ast_odbc_direct_execute(obj, generic_execute, sql->str))) {
|
||||
ast_odbc_release_obj(obj);
|
||||
continue;
|
||||
}
|
||||
|
||||
executed = 1;
|
||||
|
||||
res = SQLNumResultCols(stmt, &colcount);
|
||||
@@ -955,6 +973,7 @@ static char *cli_odbc_read(struct ast_cli_entry *e, int cmd, struct ast_cli_args
|
||||
SQLFreeHandle (SQL_HANDLE_STMT, stmt);
|
||||
ast_odbc_release_obj(obj);
|
||||
AST_RWLIST_UNLOCK(&queries);
|
||||
return CLI_SUCCESS;
|
||||
}
|
||||
|
||||
res = SQLFetch(stmt);
|
||||
@@ -1014,14 +1033,11 @@ static char *cli_odbc_read(struct ast_cli_entry *e, int cmd, struct ast_cli_args
|
||||
break;
|
||||
}
|
||||
ast_odbc_release_obj(obj);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!executed) {
|
||||
ast_cli(a->fd, "Failed to execute query. [%s]\n", sql->str);
|
||||
}
|
||||
} else {
|
||||
} else { /* No execution, just print out the resulting SQL */
|
||||
ast_cli(a->fd, "%s\n", sql->str);
|
||||
}
|
||||
AST_RWLIST_UNLOCK(&queries);
|
||||
@@ -1132,9 +1148,17 @@ static char *cli_odbc_write(struct ast_cli_entry *e, int cmd, struct ast_cli_arg
|
||||
SQLLEN rows = -1;
|
||||
|
||||
for (dsn = 0; dsn < 5; dsn++) {
|
||||
if (!ast_strlen_zero(query->writehandle[dsn])) {
|
||||
if ((obj = ast_odbc_request_obj(query->writehandle[dsn], 0))) {
|
||||
if ((stmt = ast_odbc_direct_execute(obj, generic_execute, sql->str))) {
|
||||
if (ast_strlen_zero(query->writehandle[dsn])) {
|
||||
continue;
|
||||
}
|
||||
if (!(obj = ast_odbc_request_obj(query->writehandle[dsn], 0))) {
|
||||
continue;
|
||||
}
|
||||
if (!(stmt = ast_odbc_direct_execute(obj, generic_execute, sql->str))) {
|
||||
ast_odbc_release_obj(obj);
|
||||
continue;
|
||||
}
|
||||
|
||||
SQLRowCount(stmt, &rows);
|
||||
SQLCloseCursor(stmt);
|
||||
SQLFreeHandle(SQL_HANDLE_STMT, stmt);
|
||||
@@ -1143,15 +1167,11 @@ static char *cli_odbc_write(struct ast_cli_entry *e, int cmd, struct ast_cli_arg
|
||||
executed = 1;
|
||||
break;
|
||||
}
|
||||
ast_odbc_release_obj(obj);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!executed) {
|
||||
ast_cli(a->fd, "Failed to execute query.\n");
|
||||
}
|
||||
} else {
|
||||
} else { /* No execution, just print out the resulting SQL */
|
||||
ast_cli(a->fd, "%s\n", sql->str);
|
||||
}
|
||||
AST_RWLIST_UNLOCK(&queries);
|
||||
|
||||
Reference in New Issue
Block a user