#include "asterisk.h"
#include <sys/types.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <errno.h>
#include "asterisk/module.h"
#include "asterisk/file.h"
#include "asterisk/logger.h"
#include "asterisk/options.h"
#include "asterisk/channel.h"
#include "asterisk/pbx.h"
#include "asterisk/config.h"
#include "asterisk/res_odbc.h"
#include "asterisk/app.h"

Go to the source code of this file.
Data Structures | |
| struct | acf_odbc_query |
| struct | queries |
Enumerations | |
| enum | { OPT_ESCAPECOMMAS = (1 << 0) } |
Functions | |
| static void | __reg_module (void) |
| static void | __unreg_module (void) |
| static int | acf_escape (struct ast_channel *chan, char *cmd, char *data, char *buf, size_t len) |
| static int | acf_odbc_read (struct ast_channel *chan, char *cmd, char *s, char *buf, size_t len) |
| static int | acf_odbc_write (struct ast_channel *chan, char *cmd, char *s, const char *value) |
| static int | free_acf_query (struct acf_odbc_query *query) |
| static SQLHSTMT | generic_prepare (struct odbc_obj *obj, void *data) |
| static int | init_acf_query (struct ast_config *cfg, char *catg, struct acf_odbc_query **query) |
| static int | load_module (void) |
| static int | odbc_load_module (void) |
| static int | odbc_unload_module (void) |
| static int | reload (void) |
| static int | unload_module (void) |
Variables | |
| static struct ast_module_info | __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_DEFAULT | AST_MODFLAG_BUILDSUM, .description = "ODBC lookups" , .key = "This paragraph is copyright (c) 2006 by Digium, Inc. \In order for your module to load, it must return this \key via a function called \"key\". Any code which \includes this paragraph must be licensed under the GNU \General Public License version 2 or later (at your \option). In addition to Digium's general reservations \of rights, Digium expressly reserves the right to \allow other parties to license this paragraph under \different terms. Any use of Digium, Inc. trademarks or \logos (including \"Asterisk\" or \"Digium\") without \express written permission of Digium, Inc. is prohibited.\n" , .buildopt_sum = AST_BUILDOPT_SUM, .load = load_module, .unload = unload_module, .reload = reload, } |
| static const struct ast_module_info * | ast_module_info = &__mod_info |
| static char * | config = "func_odbc.conf" |
| static struct ast_custom_function | escape_function |
| enum { ... } | odbc_option_flags |
Definition in file func_odbc.c.
| anonymous enum |
Definition at line 55 of file func_odbc.c.
00055 { 00056 OPT_ESCAPECOMMAS = (1 << 0), 00057 } odbc_option_flags;
| static void __reg_module | ( | void | ) | [static] |
Definition at line 669 of file func_odbc.c.
| static void __unreg_module | ( | void | ) | [static] |
Definition at line 669 of file func_odbc.c.
| static int acf_escape | ( | struct ast_channel * | chan, | |
| char * | cmd, | |||
| char * | data, | |||
| char * | buf, | |||
| size_t | len | |||
| ) | [static] |
Definition at line 376 of file func_odbc.c.
00377 { 00378 char *out = buf; 00379 00380 for (; *data && out - buf < len; data++) { 00381 if (*data == '\'') { 00382 *out = '\''; 00383 out++; 00384 } 00385 *out++ = *data; 00386 } 00387 *out = '\0'; 00388 00389 return 0; 00390 }
| static int acf_odbc_read | ( | struct ast_channel * | chan, | |
| char * | cmd, | |||
| char * | s, | |||
| char * | buf, | |||
| size_t | len | |||
| ) | [static] |
Definition at line 215 of file func_odbc.c.
References acf_odbc_query::acf, AST_APP_ARG, ast_autoservice_start(), ast_autoservice_stop(), ast_channel_alloc(), ast_channel_free(), AST_DECLARE_APP_ARGS, AST_LIST_LOCK, AST_LIST_TRAVERSE, AST_LIST_UNLOCK, ast_log(), ast_odbc_prepare_and_execute(), ast_odbc_release_obj(), ast_odbc_request_obj(), AST_STANDARD_APP_ARGS, ast_test_flag, ast_verbose(), acf_odbc_query::dsn, generic_prepare(), acf_odbc_query::list, LOG_ERROR, LOG_WARNING, ast_custom_function::name, OPT_ESCAPECOMMAS, option_verbose, pbx_builtin_pushvar_helper(), pbx_builtin_setvar_helper(), pbx_substitute_variables_helper(), acf_odbc_query::sql_read, and VERBOSE_PREFIX_4.
Referenced by init_acf_query().
00216 { 00217 struct odbc_obj *obj; 00218 struct acf_odbc_query *query; 00219 char sql[2048] = "", varname[15]; 00220 int res, x, buflen = 1, escapecommas, bogus_chan = 0; 00221 AST_DECLARE_APP_ARGS(args, 00222 AST_APP_ARG(field)[100]; 00223 ); 00224 SQLHSTMT stmt; 00225 SQLSMALLINT colcount=0; 00226 SQLLEN indicator; 00227 00228 AST_LIST_LOCK(&queries); 00229 AST_LIST_TRAVERSE(&queries, query, list) { 00230 if (!strcmp(query->acf->name, cmd)) { 00231 break; 00232 } 00233 } 00234 00235 if (!query) { 00236 ast_log(LOG_ERROR, "No such function '%s'\n", cmd); 00237 AST_LIST_UNLOCK(&queries); 00238 return -1; 00239 } 00240 00241 obj = ast_odbc_request_obj(query->dsn, 0); 00242 00243 if (!obj) { 00244 ast_log(LOG_ERROR, "No such DSN registered (or out of connections): %s (check res_odbc.conf)\n", query->dsn); 00245 AST_LIST_UNLOCK(&queries); 00246 return -1; 00247 } 00248 00249 if (!chan) { 00250 if ((chan = ast_channel_alloc(0, 0, "", "", "", "", "", 0, "Bogus/func_odbc"))) 00251 bogus_chan = 1; 00252 } 00253 00254 if (chan) 00255 ast_autoservice_start(chan); 00256 00257 AST_STANDARD_APP_ARGS(args, s); 00258 for (x = 0; x < args.argc; x++) { 00259 snprintf(varname, sizeof(varname), "ARG%d", x + 1); 00260 pbx_builtin_pushvar_helper(chan, varname, args.field[x]); 00261 } 00262 00263 pbx_substitute_variables_helper(chan, query->sql_read, sql, sizeof(sql) - 1); 00264 00265 /* Restore prior values */ 00266 for (x = 0; x < args.argc; x++) { 00267 snprintf(varname, sizeof(varname), "ARG%d", x + 1); 00268 pbx_builtin_setvar_helper(chan, varname, NULL); 00269 } 00270 00271 /* Save this flag, so we can release the lock */ 00272 escapecommas = ast_test_flag(query, OPT_ESCAPECOMMAS); 00273 00274 AST_LIST_UNLOCK(&queries); 00275 00276 stmt = ast_odbc_prepare_and_execute(obj, generic_prepare, sql); 00277 00278 if (!stmt) { 00279 ast_odbc_release_obj(obj); 00280 if (chan) 00281 ast_autoservice_stop(chan); 00282 if (bogus_chan) 00283 ast_channel_free(chan); 00284 return -1; 00285 } 00286 00287 res = SQLNumResultCols(stmt, &colcount); 00288 if ((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO)) { 00289 ast_log(LOG_WARNING, "SQL Column Count error!\n[%s]\n\n", sql); 00290 SQLCloseCursor(stmt); 00291 SQLFreeHandle (SQL_HANDLE_STMT, stmt); 00292 ast_odbc_release_obj(obj); 00293 if (chan) 00294 ast_autoservice_stop(chan); 00295 if (bogus_chan) 00296 ast_channel_free(chan); 00297 return -1; 00298 } 00299 00300 *buf = '\0'; 00301 00302 res = SQLFetch(stmt); 00303 if ((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO)) { 00304 int res1 = -1; 00305 if (res == SQL_NO_DATA) { 00306 if (option_verbose > 3) { 00307 ast_verbose(VERBOSE_PREFIX_4 "Found no rows [%s]\n", sql); 00308 } 00309 res1 = 0; 00310 } else if (option_verbose > 3) { 00311 ast_log(LOG_WARNING, "Error %d in FETCH [%s]\n", res, sql); 00312 } 00313 SQLCloseCursor(stmt); 00314 SQLFreeHandle(SQL_HANDLE_STMT, stmt); 00315 ast_odbc_release_obj(obj); 00316 if (chan) 00317 ast_autoservice_stop(chan); 00318 if (bogus_chan) 00319 ast_channel_free(chan); 00320 return res1; 00321 } 00322 00323 for (x = 0; x < colcount; x++) { 00324 int i; 00325 char coldata[256]; 00326 00327 buflen = strlen(buf); 00328 res = SQLGetData(stmt, x + 1, SQL_CHAR, coldata, sizeof(coldata), &indicator); 00329 if (indicator == SQL_NULL_DATA) { 00330 coldata[0] = '\0'; 00331 res = SQL_SUCCESS; 00332 } 00333 00334 if ((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO)) { 00335 ast_log(LOG_WARNING, "SQL Get Data error!\n[%s]\n\n", sql); 00336 SQLCloseCursor(stmt); 00337 SQLFreeHandle(SQL_HANDLE_STMT, stmt); 00338 ast_odbc_release_obj(obj); 00339 if (chan) 00340 ast_autoservice_stop(chan); 00341 if (bogus_chan) 00342 ast_channel_free(chan); 00343 return -1; 00344 } 00345 00346 /* Copy data, encoding '\' and ',' for the argument parser */ 00347 for (i = 0; i < sizeof(coldata); i++) { 00348 if (escapecommas && (coldata[i] == '\\' || coldata[i] == ',')) { 00349 buf[buflen++] = '\\'; 00350 } 00351 buf[buflen++] = coldata[i]; 00352 00353 if (buflen >= len - 2) 00354 break; 00355 00356 if (coldata[i] == '\0') 00357 break; 00358 } 00359 00360 buf[buflen - 1] = ','; 00361 buf[buflen] = '\0'; 00362 } 00363 /* Trim trailing comma */ 00364 buf[buflen - 1] = '\0'; 00365 00366 SQLCloseCursor(stmt); 00367 SQLFreeHandle(SQL_HANDLE_STMT, stmt); 00368 ast_odbc_release_obj(obj); 00369 if (chan) 00370 ast_autoservice_stop(chan); 00371 if (bogus_chan) 00372 ast_channel_free(chan); 00373 return 0; 00374 }
| static int acf_odbc_write | ( | struct ast_channel * | chan, | |
| char * | cmd, | |||
| char * | s, | |||
| const char * | value | |||
| ) | [static] |
Definition at line 96 of file func_odbc.c.
References acf_odbc_query::acf, AST_APP_ARG, ast_autoservice_start(), ast_autoservice_stop(), ast_channel_alloc(), ast_channel_free(), AST_DECLARE_APP_ARGS, AST_LIST_LOCK, AST_LIST_TRAVERSE, AST_LIST_UNLOCK, ast_log(), AST_NONSTANDARD_APP_ARGS, ast_odbc_prepare_and_execute(), ast_odbc_release_obj(), ast_odbc_request_obj(), AST_STANDARD_APP_ARGS, ast_strdupa, acf_odbc_query::dsn, generic_prepare(), acf_odbc_query::list, LOG_ERROR, ast_custom_function::name, pbx_builtin_pushvar_helper(), pbx_builtin_setvar_helper(), pbx_substitute_variables_helper(), acf_odbc_query::sql_write, and t.
Referenced by init_acf_query().
00097 { 00098 struct odbc_obj *obj; 00099 struct acf_odbc_query *query; 00100 char *t, buf[2048]="", varname[15]; 00101 int i, bogus_chan = 0; 00102 AST_DECLARE_APP_ARGS(values, 00103 AST_APP_ARG(field)[100]; 00104 ); 00105 AST_DECLARE_APP_ARGS(args, 00106 AST_APP_ARG(field)[100]; 00107 ); 00108 SQLHSTMT stmt; 00109 SQLLEN rows=0; 00110 00111 AST_LIST_LOCK(&queries); 00112 AST_LIST_TRAVERSE(&queries, query, list) { 00113 if (!strcmp(query->acf->name, cmd)) { 00114 break; 00115 } 00116 } 00117 00118 if (!query) { 00119 ast_log(LOG_ERROR, "No such function '%s'\n", cmd); 00120 AST_LIST_UNLOCK(&queries); 00121 return -1; 00122 } 00123 00124 obj = ast_odbc_request_obj(query->dsn, 0); 00125 00126 if (!obj) { 00127 ast_log(LOG_ERROR, "No database handle available with the name of '%s' (check res_odbc.conf)\n", query->dsn); 00128 AST_LIST_UNLOCK(&queries); 00129 return -1; 00130 } 00131 00132 if (!chan) { 00133 if ((chan = ast_channel_alloc(0, 0, "", "", "", "", "", 0, "Bogus/func_odbc"))) 00134 bogus_chan = 1; 00135 } 00136 00137 if (chan) 00138 ast_autoservice_start(chan); 00139 00140 /* Parse our arguments */ 00141 t = value ? ast_strdupa(value) : ""; 00142 00143 if (!s || !t) { 00144 ast_log(LOG_ERROR, "Out of memory\n"); 00145 AST_LIST_UNLOCK(&queries); 00146 if (chan) 00147 ast_autoservice_stop(chan); 00148 if (bogus_chan) 00149 ast_channel_free(chan); 00150 return -1; 00151 } 00152 00153 AST_STANDARD_APP_ARGS(args, s); 00154 for (i = 0; i < args.argc; i++) { 00155 snprintf(varname, sizeof(varname), "ARG%d", i + 1); 00156 pbx_builtin_pushvar_helper(chan, varname, args.field[i]); 00157 } 00158 00159 /* Parse values, just like arguments */ 00160 /* Can't use the pipe, because app Set removes them */ 00161 AST_NONSTANDARD_APP_ARGS(values, t, ','); 00162 for (i = 0; i < values.argc; i++) { 00163 snprintf(varname, sizeof(varname), "VAL%d", i + 1); 00164 pbx_builtin_pushvar_helper(chan, varname, values.field[i]); 00165 } 00166 00167 /* Additionally set the value as a whole (but push an empty string if value is NULL) */ 00168 pbx_builtin_pushvar_helper(chan, "VALUE", value ? value : ""); 00169 00170 pbx_substitute_variables_helper(chan, query->sql_write, buf, sizeof(buf) - 1); 00171 00172 /* Restore prior values */ 00173 for (i = 0; i < args.argc; i++) { 00174 snprintf(varname, sizeof(varname), "ARG%d", i + 1); 00175 pbx_builtin_setvar_helper(chan, varname, NULL); 00176 } 00177 00178 for (i = 0; i < values.argc; i++) { 00179 snprintf(varname, sizeof(varname), "VAL%d", i + 1); 00180 pbx_builtin_setvar_helper(chan, varname, NULL); 00181 } 00182 pbx_builtin_setvar_helper(chan, "VALUE", NULL); 00183 00184 AST_LIST_UNLOCK(&queries); 00185 00186 stmt = ast_odbc_prepare_and_execute(obj, generic_prepare, buf); 00187 00188 if (stmt) { 00189 /* Rows affected */ 00190 SQLRowCount(stmt, &rows); 00191 } 00192 00193 /* Output the affected rows, for all cases. In the event of failure, we 00194 * flag this as -1 rows. Note that this is different from 0 affected rows 00195 * which would be the case if we succeeded in our query, but the values did 00196 * not change. */ 00197 snprintf(varname, sizeof(varname), "%d", (int)rows); 00198 pbx_builtin_setvar_helper(chan, "ODBCROWS", varname); 00199 00200 if (stmt) { 00201 SQLCloseCursor(stmt); 00202 SQLFreeHandle(SQL_HANDLE_STMT, stmt); 00203 } 00204 if (obj) 00205 ast_odbc_release_obj(obj); 00206 00207 if (chan) 00208 ast_autoservice_stop(chan); 00209 if (bogus_chan) 00210 ast_channel_free(chan); 00211 00212 return 0; 00213 }
| static int free_acf_query | ( | struct acf_odbc_query * | query | ) | [static] |
Definition at line 540 of file func_odbc.c.
References acf_odbc_query::acf, ast_custom_function::desc, free, ast_custom_function::name, and ast_custom_function::syntax.
Referenced by odbc_load_module(), odbc_unload_module(), and reload().
00541 { 00542 if (query) { 00543 if (query->acf) { 00544 if (query->acf->name) 00545 free((char *)query->acf->name); 00546 if (query->acf->syntax) 00547 free((char *)query->acf->syntax); 00548 if (query->acf->desc) 00549 free((char *)query->acf->desc); 00550 free(query->acf); 00551 } 00552 free(query); 00553 } 00554 return 0; 00555 }
| static SQLHSTMT generic_prepare | ( | struct odbc_obj * | obj, | |
| void * | data | |||
| ) | [static] |
Definition at line 70 of file func_odbc.c.
References ast_log(), and LOG_WARNING.
Referenced by acf_odbc_read(), and acf_odbc_write().
00071 { 00072 int res; 00073 char *sql = data; 00074 SQLHSTMT stmt; 00075 00076 res = SQLAllocHandle (SQL_HANDLE_STMT, obj->con, &stmt); 00077 if ((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO)) { 00078 ast_log(LOG_WARNING, "SQL Alloc Handle failed!\n"); 00079 return NULL; 00080 } 00081 00082 res = SQLPrepare(stmt, (unsigned char *)sql, SQL_NTS); 00083 if ((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO)) { 00084 ast_log(LOG_WARNING, "SQL Prepare failed![%s]\n", sql); 00085 SQLCloseCursor(stmt); 00086 SQLFreeHandle (SQL_HANDLE_STMT, stmt); 00087 return NULL; 00088 } 00089 00090 return stmt; 00091 }
| static int init_acf_query | ( | struct ast_config * | cfg, | |
| char * | catg, | |||
| struct acf_odbc_query ** | query | |||
| ) | [static] |
Definition at line 404 of file func_odbc.c.
References acf_odbc_query::acf, acf_odbc_read(), acf_odbc_write(), asprintf, ast_calloc, ast_clear_flag, ast_copy_string(), ast_false(), ast_log(), ast_set_flag, ast_strlen_zero(), ast_variable_retrieve(), errno, free, LOG_ERROR, LOG_WARNING, OPT_ESCAPECOMMAS, ast_custom_function::read, and ast_custom_function::synopsis.
Referenced by odbc_load_module(), and reload().
00405 { 00406 const char *tmp; 00407 int res; 00408 00409 if (!cfg || !catg) { 00410 return -1; 00411 } 00412 00413 *query = ast_calloc(1, sizeof(struct acf_odbc_query)); 00414 if (! (*query)) 00415 return -1; 00416 00417 if ((tmp = ast_variable_retrieve(cfg, catg, "dsn"))) { 00418 ast_copy_string((*query)->dsn, tmp, sizeof((*query)->dsn)); 00419 } else if ((tmp = ast_variable_retrieve(cfg, catg, "writehandle")) || (tmp = ast_variable_retrieve(cfg, catg, "readhandle"))) { 00420 ast_log(LOG_WARNING, "Separate read and write handles are not supported in this version of func_odbc.so\n"); 00421 ast_copy_string((*query)->dsn, tmp, sizeof((*query)->dsn)); 00422 } else { 00423 free(*query); 00424 *query = NULL; 00425 ast_log(LOG_ERROR, "No database handle was specified for func_odbc class '%s'\n", catg); 00426 return -1; 00427 } 00428 00429 if ((tmp = ast_variable_retrieve(cfg, catg, "read")) || (tmp = ast_variable_retrieve(cfg, catg, "readsql"))) { 00430 ast_copy_string((*query)->sql_read, tmp, sizeof((*query)->sql_read)); 00431 } 00432 00433 if ((tmp = ast_variable_retrieve(cfg, catg, "write")) || (tmp = ast_variable_retrieve(cfg, catg, "writesql"))) { 00434 ast_copy_string((*query)->sql_write, tmp, sizeof((*query)->sql_write)); 00435 } 00436 00437 /* Allow escaping of embedded commas in fields to be turned off */ 00438 ast_set_flag((*query), OPT_ESCAPECOMMAS); 00439 if ((tmp = ast_variable_retrieve(cfg, catg, "escapecommas"))) { 00440 if (ast_false(tmp)) 00441 ast_clear_flag((*query), OPT_ESCAPECOMMAS); 00442 } 00443 00444 (*query)->acf = ast_calloc(1, sizeof(struct ast_custom_function)); 00445 if (! (*query)->acf) { 00446 free(*query); 00447 *query = NULL; 00448 return -1; 00449 } 00450 00451 if ((tmp = ast_variable_retrieve(cfg, catg, "prefix")) && !ast_strlen_zero(tmp)) { 00452 if (asprintf((char **)&((*query)->acf->name), "%s_%s", tmp, catg) < 0) { 00453 ast_log(LOG_WARNING, "asprintf() failed: %s\n", strerror(errno)); 00454 } 00455 } else { 00456 if (asprintf((char **)&((*query)->acf->name), "ODBC_%s", catg) < 0) { 00457 ast_log(LOG_WARNING, "asprintf() failed: %s\n", strerror(errno)); 00458 } 00459 } 00460 00461 if (!((*query)->acf->name)) { 00462 free((*query)->acf); 00463 free(*query); 00464 *query = NULL; 00465 return -1; 00466 } 00467 00468 if (asprintf((char **)&((*query)->acf->syntax), "%s(<arg1>[...[,<argN>]])", (*query)->acf->name) < 0) { 00469 ast_log(LOG_WARNING, "asprintf() failed: %s\n", strerror(errno)); 00470 (*query)->acf->syntax = NULL; 00471 } 00472 00473 if (!((*query)->acf->syntax)) { 00474 free((char *)(*query)->acf->name); 00475 free((*query)->acf); 00476 free(*query); 00477 *query = NULL; 00478 return -1; 00479 } 00480 00481 res = 0; 00482 (*query)->acf->synopsis = "Runs the referenced query with the specified arguments"; 00483 if (!ast_strlen_zero((*query)->sql_read) && !ast_strlen_zero((*query)->sql_write)) { 00484 res = asprintf((char **)&((*query)->acf->desc), 00485 "Runs the following query, as defined in func_odbc.conf, performing\n" 00486 "substitution of the arguments into the query as specified by ${ARG1},\n" 00487 "${ARG2}, ... ${ARGn}. When setting the function, the values are provided\n" 00488 "either in whole as ${VALUE} or parsed as ${VAL1}, ${VAL2}, ... ${VALn}.\n" 00489 "\nRead:\n%s\n\nWrite:\n%s\n", 00490 (*query)->sql_read, 00491 (*query)->sql_write); 00492 } else if (!ast_strlen_zero((*query)->sql_read)) { 00493 res = asprintf((char **)&((*query)->acf->desc), 00494 "Runs the following query, as defined in func_odbc.conf, performing\n" 00495 "substitution of the arguments into the query as specified by ${ARG1},\n" 00496 "${ARG2}, ... ${ARGn}. This function may only be read, not set.\n\nSQL:\n%s\n", 00497 (*query)->sql_read); 00498 } else if (!ast_strlen_zero((*query)->sql_write)) { 00499 res = asprintf((char **)&((*query)->acf->desc), 00500 "Runs the following query, as defined in func_odbc.conf, performing\n" 00501 "substitution of the arguments into the query as specified by ${ARG1},\n" 00502 "${ARG2}, ... ${ARGn}. The values are provided either in whole as\n" 00503 "${VALUE} or parsed as ${VAL1}, ${VAL2}, ... ${VALn}.\n" 00504 "This function may only be set.\nSQL:\n%s\n", 00505 (*query)->sql_write); 00506 } else { 00507 ast_log(LOG_ERROR, "No SQL was found for func_odbc class '%s'\n", catg); 00508 } 00509 00510 if (res < 0) { 00511 ast_log(LOG_WARNING, "asprintf() failed: %s\n", strerror(errno)); 00512 (*query)->acf->desc = NULL; 00513 } 00514 00515 /* Could be out of memory, or could be we have neither sql_read nor sql_write */ 00516 if (!((*query)->acf->desc)) { 00517 free((char *)(*query)->acf->syntax); 00518 free((char *)(*query)->acf->name); 00519 free((*query)->acf); 00520 free(*query); 00521 *query = NULL; 00522 return -1; 00523 } 00524 00525 if (ast_strlen_zero((*query)->sql_read)) { 00526 (*query)->acf->read = NULL; 00527 } else { 00528 (*query)->acf->read = acf_odbc_read; 00529 } 00530 00531 if (ast_strlen_zero((*query)->sql_write)) { 00532 (*query)->acf->write = NULL; 00533 } else { 00534 (*query)->acf->write = acf_odbc_write; 00535 } 00536 00537 return 0; 00538 }
| static int load_module | ( | void | ) | [static] |
Definition at line 658 of file func_odbc.c.
References odbc_load_module().
00659 { 00660 return odbc_load_module(); 00661 }
| static int odbc_load_module | ( | void | ) | [static] |
Definition at line 557 of file func_odbc.c.
References acf_odbc_query::acf, ast_category_browse(), ast_config_destroy(), ast_config_load(), ast_custom_function_register(), AST_LIST_INSERT_HEAD, AST_LIST_LOCK, AST_LIST_UNLOCK, ast_log(), AST_MODULE_LOAD_DECLINE, escape_function, free_acf_query(), init_acf_query(), acf_odbc_query::list, and LOG_NOTICE.
Referenced by load_module().
00558 { 00559 int res = 0; 00560 struct ast_config *cfg; 00561 char *catg; 00562 00563 AST_LIST_LOCK(&queries); 00564 00565 cfg = ast_config_load(config); 00566 if (!cfg) { 00567 ast_log(LOG_NOTICE, "Unable to load config for func_odbc: %s\n", config); 00568 AST_LIST_UNLOCK(&queries); 00569 return AST_MODULE_LOAD_DECLINE; 00570 } 00571 00572 for (catg = ast_category_browse(cfg, NULL); 00573 catg; 00574 catg = ast_category_browse(cfg, catg)) { 00575 struct acf_odbc_query *query = NULL; 00576 00577 if (init_acf_query(cfg, catg, &query)) { 00578 free_acf_query(query); 00579 } else { 00580 AST_LIST_INSERT_HEAD(&queries, query, list); 00581 ast_custom_function_register(query->acf); 00582 } 00583 } 00584 00585 ast_config_destroy(cfg); 00586 ast_custom_function_register(&escape_function); 00587 00588 AST_LIST_UNLOCK(&queries); 00589 return res; 00590 }
| static int odbc_unload_module | ( | void | ) | [static] |
Definition at line 592 of file func_odbc.c.
References acf_odbc_query::acf, ast_custom_function_unregister(), AST_LIST_EMPTY, AST_LIST_LOCK, AST_LIST_REMOVE_HEAD, AST_LIST_UNLOCK, escape_function, free_acf_query(), and acf_odbc_query::list.
Referenced by unload_module().
00593 { 00594 struct acf_odbc_query *query; 00595 00596 AST_LIST_LOCK(&queries); 00597 while (!AST_LIST_EMPTY(&queries)) { 00598 query = AST_LIST_REMOVE_HEAD(&queries, list); 00599 ast_custom_function_unregister(query->acf); 00600 free_acf_query(query); 00601 } 00602 00603 ast_custom_function_unregister(&escape_function); 00604 00605 /* Allow any threads waiting for this lock to pass (avoids a race) */ 00606 AST_LIST_UNLOCK(&queries); 00607 AST_LIST_LOCK(&queries); 00608 00609 AST_LIST_UNLOCK(&queries); 00610 return 0; 00611 }
| static int reload | ( | void | ) | [static] |
Definition at line 613 of file func_odbc.c.
References acf_odbc_query::acf, ast_category_browse(), ast_config_destroy(), ast_config_load(), ast_custom_function_register(), ast_custom_function_unregister(), AST_LIST_EMPTY, AST_LIST_INSERT_HEAD, AST_LIST_LOCK, AST_LIST_REMOVE_HEAD, AST_LIST_UNLOCK, ast_log(), free_acf_query(), init_acf_query(), acf_odbc_query::list, LOG_ERROR, and LOG_WARNING.
00614 { 00615 int res = 0; 00616 struct ast_config *cfg; 00617 struct acf_odbc_query *oldquery; 00618 char *catg; 00619 00620 AST_LIST_LOCK(&queries); 00621 00622 while (!AST_LIST_EMPTY(&queries)) { 00623 oldquery = AST_LIST_REMOVE_HEAD(&queries, list); 00624 ast_custom_function_unregister(oldquery->acf); 00625 free_acf_query(oldquery); 00626 } 00627 00628 cfg = ast_config_load(config); 00629 if (!cfg) { 00630 ast_log(LOG_WARNING, "Unable to load config for func_odbc: %s\n", config); 00631 goto reload_out; 00632 } 00633 00634 for (catg = ast_category_browse(cfg, NULL); 00635 catg; 00636 catg = ast_category_browse(cfg, catg)) { 00637 struct acf_odbc_query *query = NULL; 00638 00639 if (init_acf_query(cfg, catg, &query)) { 00640 ast_log(LOG_ERROR, "Cannot initialize query %s\n", catg); 00641 } else { 00642 AST_LIST_INSERT_HEAD(&queries, query, list); 00643 ast_custom_function_register(query->acf); 00644 } 00645 } 00646 00647 ast_config_destroy(cfg); 00648 reload_out: 00649 AST_LIST_UNLOCK(&queries); 00650 return res; 00651 }
| static int unload_module | ( | void | ) | [static] |
Definition at line 653 of file func_odbc.c.
References odbc_unload_module().
00654 { 00655 return odbc_unload_module(); 00656 }
struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_DEFAULT | AST_MODFLAG_BUILDSUM, .description = "ODBC lookups" , .key = "This paragraph is copyright (c) 2006 by Digium, Inc. \In order for your module to load, it must return this \key via a function called \"key\". Any code which \includes this paragraph must be licensed under the GNU \General Public License version 2 or later (at your \option). In addition to Digium's general reservations \of rights, Digium expressly reserves the right to \allow other parties to license this paragraph under \different terms. Any use of Digium, Inc. trademarks or \logos (including \"Asterisk\" or \"Digium\") without \express written permission of Digium, Inc. is prohibited.\n" , .buildopt_sum = AST_BUILDOPT_SUM, .load = load_module, .unload = unload_module, .reload = reload, } [static] |
Definition at line 669 of file func_odbc.c.
const struct ast_module_info* ast_module_info = &__mod_info [static] |
Definition at line 669 of file func_odbc.c.
char* config = "func_odbc.conf" [static] |
Definition at line 53 of file func_odbc.c.
struct ast_custom_function escape_function [static] |
Definition at line 392 of file func_odbc.c.
Referenced by odbc_load_module(), and odbc_unload_module().
| enum { ... } odbc_option_flags |
1.5.9