use a macro instead of an inline function, so that backtraces will report the caller...
[asterisk-bristuff.git] / res / res_odbc.c
bloba88fa5b38f0e3216b5b91e8d28a34cea3d5b7c48
1 /*
2 * Asterisk -- An open source telephony toolkit.
4 * Copyright (C) 1999 - 2005, Digium, Inc.
6 * Mark Spencer <markster@digium.com>
8 * res_odbc.c <ODBC resource manager>
9 * Copyright (C) 2004 - 2005 Anthony Minessale II <anthmct@yahoo.com>
11 * See http://www.asterisk.org for more information about
12 * the Asterisk project. Please do not directly contact
13 * any of the maintainers of this project for assistance;
14 * the project provides a web site, mailing lists and IRC
15 * channels for your use.
17 * This program is free software, distributed under the terms of
18 * the GNU General Public License Version 2. See the LICENSE file
19 * at the top of the source tree.
22 /*! \file
24 * \brief ODBC resource manager
26 * \author Mark Spencer <markster@digium.com>
27 * \author Anthony Minessale II <anthmct@yahoo.com>
29 * \arg See also: \ref cdr_odbc
32 /*** MODULEINFO
33 <depend>unixodbc</depend>
34 <depend>ltdl</depend>
35 ***/
37 #include "asterisk.h"
39 ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
41 #include <stdio.h>
42 #include <stdlib.h>
43 #include <unistd.h>
44 #include <string.h>
46 #include "asterisk/file.h"
47 #include "asterisk/logger.h"
48 #include "asterisk/channel.h"
49 #include "asterisk/config.h"
50 #include "asterisk/options.h"
51 #include "asterisk/pbx.h"
52 #include "asterisk/module.h"
53 #include "asterisk/cli.h"
54 #include "asterisk/lock.h"
55 #include "asterisk/res_odbc.h"
57 struct odbc_class
59 AST_LIST_ENTRY(odbc_class) list;
60 char name[80];
61 char dsn[80];
62 char username[80];
63 char password[80];
64 SQLHENV env;
65 unsigned int haspool:1; /* Boolean - TDS databases need this */
66 unsigned int limit:10; /* Gives a limit of 1023 maximum */
67 unsigned int count:10; /* Running count of pooled connections */
68 unsigned int delme:1; /* Purge the class */
69 AST_LIST_HEAD(, odbc_obj) odbc_obj;
72 AST_LIST_HEAD_STATIC(odbc_list, odbc_class);
74 static odbc_status odbc_obj_connect(struct odbc_obj *obj);
75 static odbc_status odbc_obj_disconnect(struct odbc_obj *obj);
76 static int odbc_register_class(struct odbc_class *class, int connect);
79 SQLHSTMT ast_odbc_prepare_and_execute(struct odbc_obj *obj, SQLHSTMT (*prepare_cb)(struct odbc_obj *obj, void *data), void *data)
81 int res = 0, i, attempt;
82 SQLINTEGER nativeerror=0, numfields=0;
83 SQLSMALLINT diagbytes=0;
84 unsigned char state[10], diagnostic[256];
85 SQLHSTMT stmt;
87 for (attempt = 0; attempt < 2; attempt++) {
88 /* This prepare callback may do more than just prepare -- it may also
89 * bind parameters, bind results, etc. The real key, here, is that
90 * when we disconnect, all handles become invalid for most databases.
91 * We must therefore redo everything when we establish a new
92 * connection. */
93 stmt = prepare_cb(obj, data);
95 if (stmt) {
96 res = SQLExecute(stmt);
97 if ((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO) && (res != SQL_NO_DATA)) {
98 if (res == SQL_ERROR) {
99 SQLGetDiagField(SQL_HANDLE_STMT, stmt, 1, SQL_DIAG_NUMBER, &numfields, SQL_IS_INTEGER, &diagbytes);
100 for (i = 0; i < numfields; i++) {
101 SQLGetDiagRec(SQL_HANDLE_STMT, stmt, i + 1, state, &nativeerror, diagnostic, sizeof(diagnostic), &diagbytes);
102 ast_log(LOG_WARNING, "SQL Execute returned an error %d: %s: %s (%d)\n", res, state, diagnostic, diagbytes);
103 if (i > 10) {
104 ast_log(LOG_WARNING, "Oh, that was good. There are really %d diagnostics?\n", (int)numfields);
105 break;
110 ast_log(LOG_WARNING, "SQL Execute error %d! Attempting a reconnect...\n", res);
111 SQLFreeHandle(SQL_HANDLE_STMT, stmt);
112 stmt = NULL;
114 obj->up = 0;
116 * While this isn't the best way to try to correct an error, this won't automatically
117 * fail when the statement handle invalidates.
119 /* XXX Actually, it might, if we're using a non-pooled connection. Possible race here. XXX */
120 odbc_obj_disconnect(obj);
121 odbc_obj_connect(obj);
122 continue;
124 break;
125 } else {
126 ast_log(LOG_WARNING, "SQL Prepare failed. Attempting a reconnect...\n");
127 odbc_obj_disconnect(obj);
128 odbc_obj_connect(obj);
132 return stmt;
135 int ast_odbc_smart_execute(struct odbc_obj *obj, SQLHSTMT stmt)
137 int res = 0, i;
138 SQLINTEGER nativeerror=0, numfields=0;
139 SQLSMALLINT diagbytes=0;
140 unsigned char state[10], diagnostic[256];
142 res = SQLExecute(stmt);
143 if ((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO) && (res != SQL_NO_DATA)) {
144 if (res == SQL_ERROR) {
145 SQLGetDiagField(SQL_HANDLE_STMT, stmt, 1, SQL_DIAG_NUMBER, &numfields, SQL_IS_INTEGER, &diagbytes);
146 for (i = 0; i < numfields; i++) {
147 SQLGetDiagRec(SQL_HANDLE_STMT, stmt, i + 1, state, &nativeerror, diagnostic, sizeof(diagnostic), &diagbytes);
148 ast_log(LOG_WARNING, "SQL Execute returned an error %d: %s: %s (%d)\n", res, state, diagnostic, diagbytes);
149 if (i > 10) {
150 ast_log(LOG_WARNING, "Oh, that was good. There are really %d diagnostics?\n", (int)numfields);
151 break;
155 #if 0
156 /* This is a really bad method of trying to correct a dead connection. It
157 * only ever really worked with MySQL. It will not work with any other
158 * database, since most databases prepare their statements on the server,
159 * and if you disconnect, you invalidate the statement handle. Hence, if
160 * you disconnect, you're going to fail anyway, whether you try to execute
161 * a second time or not.
163 ast_log(LOG_WARNING, "SQL Execute error %d! Attempting a reconnect...\n", res);
164 ast_mutex_lock(&obj->lock);
165 obj->up = 0;
166 ast_mutex_unlock(&obj->lock);
167 odbc_obj_disconnect(obj);
168 odbc_obj_connect(obj);
169 res = SQLExecute(stmt);
170 #endif
173 return res;
177 int ast_odbc_sanity_check(struct odbc_obj *obj)
179 char *test_sql = "select 1";
180 SQLHSTMT stmt;
181 int res = 0;
183 if (obj->up) {
184 res = SQLAllocHandle(SQL_HANDLE_STMT, obj->con, &stmt);
185 if ((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO)) {
186 obj->up = 0;
187 } else {
188 res = SQLPrepare(stmt, (unsigned char *)test_sql, SQL_NTS);
189 if ((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO)) {
190 obj->up = 0;
191 } else {
192 res = SQLExecute(stmt);
193 if ((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO)) {
194 obj->up = 0;
198 SQLFreeHandle (SQL_HANDLE_STMT, stmt);
201 if (!obj->up) { /* Try to reconnect! */
202 ast_log(LOG_WARNING, "Connection is down attempting to reconnect...\n");
203 odbc_obj_disconnect(obj);
204 odbc_obj_connect(obj);
206 return obj->up;
209 static int load_odbc_config(void)
211 static char *cfg = "res_odbc.conf";
212 struct ast_config *config;
213 struct ast_variable *v;
214 char *cat, *dsn, *username, *password;
215 int enabled, pooling, limit;
216 int connect = 0, res = 0;
218 struct odbc_class *new;
220 config = ast_config_load(cfg);
221 if (!config) {
222 ast_log(LOG_WARNING, "Unable to load config file res_odbc.conf\n");
223 return -1;
225 for (cat = ast_category_browse(config, NULL); cat; cat=ast_category_browse(config, cat)) {
226 if (!strcasecmp(cat, "ENV")) {
227 for (v = ast_variable_browse(config, cat); v; v = v->next) {
228 setenv(v->name, v->value, 1);
229 ast_log(LOG_NOTICE, "Adding ENV var: %s=%s\n", v->name, v->value);
231 } else {
232 /* Reset all to defaults for each class of odbc connections */
233 dsn = username = password = NULL;
234 enabled = 1;
235 connect = 0;
236 pooling = 0;
237 limit = 0;
238 for (v = ast_variable_browse(config, cat); v; v = v->next) {
239 if (!strcasecmp(v->name, "pooling")) {
240 if (ast_true(v->value))
241 pooling = 1;
242 } else if (!strcasecmp(v->name, "limit")) {
243 sscanf(v->value, "%d", &limit);
244 if (ast_true(v->value) && !limit) {
245 ast_log(LOG_WARNING, "Limit should be a number, not a boolean: '%s'. Setting limit to 1023 for ODBC class '%s'.\n", v->value, cat);
246 limit = 1023;
247 } else if (ast_false(v->value)) {
248 ast_log(LOG_WARNING, "Limit should be a number, not a boolean: '%s'. Disabling ODBC class '%s'.\n", v->value, cat);
249 enabled = 0;
250 break;
252 } else if (!strcasecmp(v->name, "enabled")) {
253 enabled = ast_true(v->value);
254 } else if (!strcasecmp(v->name, "pre-connect")) {
255 connect = ast_true(v->value);
256 } else if (!strcasecmp(v->name, "dsn")) {
257 dsn = v->value;
258 } else if (!strcasecmp(v->name, "username")) {
259 username = v->value;
260 } else if (!strcasecmp(v->name, "password")) {
261 password = v->value;
265 if (enabled && !ast_strlen_zero(dsn)) {
266 new = ast_calloc(1, sizeof(*new));
268 if (!new) {
269 res = -1;
270 break;
273 if (cat)
274 ast_copy_string(new->name, cat, sizeof(new->name));
275 if (dsn)
276 ast_copy_string(new->dsn, dsn, sizeof(new->dsn));
277 if (username)
278 ast_copy_string(new->username, username, sizeof(new->username));
279 if (password)
280 ast_copy_string(new->password, password, sizeof(new->password));
282 SQLAllocHandle(SQL_HANDLE_ENV, SQL_NULL_HANDLE, &new->env);
283 res = SQLSetEnvAttr(new->env, SQL_ATTR_ODBC_VERSION, (void *) SQL_OV_ODBC3, 0);
285 if ((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO)) {
286 ast_log(LOG_WARNING, "res_odbc: Error SetEnv\n");
287 SQLFreeHandle(SQL_HANDLE_ENV, new->env);
288 return res;
291 if (pooling) {
292 new->haspool = pooling;
293 if (limit) {
294 new->limit = limit;
295 } else {
296 ast_log(LOG_WARNING, "Pooling without also setting a limit is pointless. Changing limit from 0 to 5.\n");
297 new->limit = 5;
301 odbc_register_class(new, connect);
302 ast_log(LOG_NOTICE, "Registered ODBC class '%s' dsn->[%s]\n", cat, dsn);
306 ast_config_destroy(config);
307 return res;
310 static int odbc_show_command(int fd, int argc, char **argv)
312 struct odbc_class *class;
313 struct odbc_obj *current;
315 AST_LIST_LOCK(&odbc_list);
316 AST_LIST_TRAVERSE(&odbc_list, class, list) {
317 if ((argc == 2) || (argc == 3 && !strcmp(argv[2], "all")) || (!strcmp(argv[2], class->name))) {
318 int count = 0;
319 ast_cli(fd, "Name: %s\nDSN: %s\n", class->name, class->dsn);
321 if (class->haspool) {
322 ast_cli(fd, "Pooled: yes\nLimit: %d\nConnections in use: %d\n", class->limit, class->count);
324 AST_LIST_TRAVERSE(&(class->odbc_obj), current, list) {
325 ast_cli(fd, " Connection %d: %s\n", ++count, current->up && ast_odbc_sanity_check(current) ? "connected" : "disconnected");
327 } else {
328 /* Should only ever be one of these */
329 AST_LIST_TRAVERSE(&(class->odbc_obj), current, list) {
330 ast_cli(fd, "Pooled: no\nConnected: %s\n", current->up && ast_odbc_sanity_check(current) ? "yes" : "no");
334 ast_cli(fd, "\n");
337 AST_LIST_UNLOCK(&odbc_list);
339 return 0;
342 static char show_usage[] =
343 "Usage: odbc show [<class>]\n"
344 " List settings of a particular ODBC class.\n"
345 " or, if not specified, all classes.\n";
347 static struct ast_cli_entry cli_odbc[] = {
348 { { "odbc", "show", NULL },
349 odbc_show_command, "List ODBC DSN(s)",
350 show_usage },
353 static int odbc_register_class(struct odbc_class *class, int connect)
355 struct odbc_obj *obj;
356 if (class) {
357 AST_LIST_LOCK(&odbc_list);
358 AST_LIST_INSERT_HEAD(&odbc_list, class, list);
359 AST_LIST_UNLOCK(&odbc_list);
361 if (connect) {
362 /* Request and release builds a connection */
363 obj = ast_odbc_request_obj(class->name, 0);
364 if (obj)
365 ast_odbc_release_obj(obj);
368 return 0;
369 } else {
370 ast_log(LOG_WARNING, "Attempted to register a NULL class?\n");
371 return -1;
375 void ast_odbc_release_obj(struct odbc_obj *obj)
377 /* For pooled connections, this frees the connection to be
378 * reused. For non-pooled connections, it does nothing. */
379 obj->used = 0;
382 struct odbc_obj *ast_odbc_request_obj(const char *name, int check)
384 struct odbc_obj *obj = NULL;
385 struct odbc_class *class;
387 AST_LIST_LOCK(&odbc_list);
388 AST_LIST_TRAVERSE(&odbc_list, class, list) {
389 if (!strcmp(class->name, name))
390 break;
392 AST_LIST_UNLOCK(&odbc_list);
394 if (!class)
395 return NULL;
397 AST_LIST_LOCK(&class->odbc_obj);
398 if (class->haspool) {
399 /* Recycle connections before building another */
400 AST_LIST_TRAVERSE(&class->odbc_obj, obj, list) {
401 if (! obj->used) {
402 obj->used = 1;
403 break;
407 if (!obj && (class->count < class->limit)) {
408 class->count++;
409 obj = ast_calloc(1, sizeof(*obj));
410 if (!obj) {
411 AST_LIST_UNLOCK(&class->odbc_obj);
412 return NULL;
414 ast_mutex_init(&obj->lock);
415 obj->parent = class;
416 if (odbc_obj_connect(obj) == ODBC_FAIL) {
417 ast_log(LOG_WARNING, "Failed to connect to %s\n", name);
418 ast_mutex_destroy(&obj->lock);
419 free(obj);
420 obj = NULL;
421 class->count--;
422 } else {
423 obj->used = 1;
424 AST_LIST_INSERT_TAIL(&class->odbc_obj, obj, list);
427 } else {
428 /* Non-pooled connection: multiple modules can use the same connection. */
429 AST_LIST_TRAVERSE(&class->odbc_obj, obj, list) {
430 /* Non-pooled connection: if there is an entry, return it */
431 break;
434 if (!obj) {
435 /* No entry: build one */
436 obj = ast_calloc(1, sizeof(*obj));
437 if (!obj) {
438 AST_LIST_UNLOCK(&class->odbc_obj);
439 return NULL;
441 ast_mutex_init(&obj->lock);
442 obj->parent = class;
443 if (odbc_obj_connect(obj) == ODBC_FAIL) {
444 ast_log(LOG_WARNING, "Failed to connect to %s\n", name);
445 ast_mutex_destroy(&obj->lock);
446 free(obj);
447 obj = NULL;
448 } else {
449 AST_LIST_INSERT_HEAD(&class->odbc_obj, obj, list);
453 AST_LIST_UNLOCK(&class->odbc_obj);
455 if (obj && check) {
456 ast_odbc_sanity_check(obj);
458 return obj;
461 static odbc_status odbc_obj_disconnect(struct odbc_obj *obj)
463 int res;
464 ast_mutex_lock(&obj->lock);
466 res = SQLDisconnect(obj->con);
468 if (res == ODBC_SUCCESS) {
469 ast_log(LOG_WARNING, "res_odbc: disconnected %d from %s [%s]\n", res, obj->parent->name, obj->parent->dsn);
470 } else {
471 ast_log(LOG_WARNING, "res_odbc: %s [%s] already disconnected\n",
472 obj->parent->name, obj->parent->dsn);
474 obj->up = 0;
475 ast_mutex_unlock(&obj->lock);
476 return ODBC_SUCCESS;
479 static odbc_status odbc_obj_connect(struct odbc_obj *obj)
481 int res;
482 SQLINTEGER err;
483 short int mlen;
484 unsigned char msg[200], stat[10];
485 #ifdef NEEDTRACE
486 SQLINTEGER enable = 1;
487 char *tracefile = "/tmp/odbc.trace";
488 #endif
489 ast_mutex_lock(&obj->lock);
491 res = SQLAllocHandle(SQL_HANDLE_DBC, obj->parent->env, &obj->con);
493 if ((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO)) {
494 ast_log(LOG_WARNING, "res_odbc: Error AllocHDB %d\n", res);
495 ast_mutex_unlock(&obj->lock);
496 return ODBC_FAIL;
498 SQLSetConnectAttr(obj->con, SQL_LOGIN_TIMEOUT, (SQLPOINTER *) 10, 0);
499 #ifdef NEEDTRACE
500 SQLSetConnectAttr(obj->con, SQL_ATTR_TRACE, &enable, SQL_IS_INTEGER);
501 SQLSetConnectAttr(obj->con, SQL_ATTR_TRACEFILE, tracefile, strlen(tracefile));
502 #endif
504 if (obj->up) {
505 odbc_obj_disconnect(obj);
506 ast_log(LOG_NOTICE, "Re-connecting %s\n", obj->parent->name);
507 } else {
508 ast_log(LOG_NOTICE, "Connecting %s\n", obj->parent->name);
511 res = SQLConnect(obj->con,
512 (SQLCHAR *) obj->parent->dsn, SQL_NTS,
513 (SQLCHAR *) obj->parent->username, SQL_NTS,
514 (SQLCHAR *) obj->parent->password, SQL_NTS);
516 if ((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO)) {
517 SQLGetDiagRec(SQL_HANDLE_DBC, obj->con, 1, stat, &err, msg, 100, &mlen);
518 ast_mutex_unlock(&obj->lock);
519 ast_log(LOG_WARNING, "res_odbc: Error SQLConnect=%d errno=%d %s\n", res, (int)err, msg);
520 return ODBC_FAIL;
521 } else {
522 ast_log(LOG_NOTICE, "res_odbc: Connected to %s [%s]\n", obj->parent->name, obj->parent->dsn);
523 obj->up = 1;
526 ast_mutex_unlock(&obj->lock);
527 return ODBC_SUCCESS;
530 static int reload(void)
532 static char *cfg = "res_odbc.conf";
533 struct ast_config *config;
534 struct ast_variable *v;
535 char *cat, *dsn, *username, *password;
536 int enabled, pooling, limit;
537 int connect = 0, res = 0;
539 struct odbc_class *new, *class;
540 struct odbc_obj *current;
542 /* First, mark all to be purged */
543 AST_LIST_LOCK(&odbc_list);
544 AST_LIST_TRAVERSE(&odbc_list, class, list) {
545 class->delme = 1;
548 config = ast_config_load(cfg);
549 if (config) {
550 for (cat = ast_category_browse(config, NULL); cat; cat=ast_category_browse(config, cat)) {
551 if (!strcasecmp(cat, "ENV")) {
552 for (v = ast_variable_browse(config, cat); v; v = v->next) {
553 setenv(v->name, v->value, 1);
554 ast_log(LOG_NOTICE, "Adding ENV var: %s=%s\n", v->name, v->value);
556 } else {
557 /* Reset all to defaults for each class of odbc connections */
558 dsn = username = password = NULL;
559 enabled = 1;
560 connect = 0;
561 pooling = 0;
562 limit = 0;
563 for (v = ast_variable_browse(config, cat); v; v = v->next) {
564 if (!strcasecmp(v->name, "pooling")) {
565 pooling = 1;
566 } else if (!strcasecmp(v->name, "limit")) {
567 sscanf(v->value, "%d", &limit);
568 if (ast_true(v->value) && !limit) {
569 ast_log(LOG_WARNING, "Limit should be a number, not a boolean: '%s'. Setting limit to 1023 for ODBC class '%s'.\n", v->value, cat);
570 limit = 1023;
571 } else if (ast_false(v->value)) {
572 ast_log(LOG_WARNING, "Limit should be a number, not a boolean: '%s'. Disabling ODBC class '%s'.\n", v->value, cat);
573 enabled = 0;
574 break;
576 } else if (!strcasecmp(v->name, "enabled")) {
577 enabled = ast_true(v->value);
578 } else if (!strcasecmp(v->name, "pre-connect")) {
579 connect = ast_true(v->value);
580 } else if (!strcasecmp(v->name, "dsn")) {
581 dsn = v->value;
582 } else if (!strcasecmp(v->name, "username")) {
583 username = v->value;
584 } else if (!strcasecmp(v->name, "password")) {
585 password = v->value;
589 if (enabled && !ast_strlen_zero(dsn)) {
590 /* First, check the list to see if it already exists */
591 AST_LIST_TRAVERSE(&odbc_list, class, list) {
592 if (!strcmp(class->name, cat)) {
593 class->delme = 0;
594 break;
598 if (class) {
599 new = class;
600 } else {
601 new = ast_calloc(1, sizeof(*new));
604 if (!new) {
605 res = -1;
606 break;
609 if (cat)
610 ast_copy_string(new->name, cat, sizeof(new->name));
611 if (dsn)
612 ast_copy_string(new->dsn, dsn, sizeof(new->dsn));
613 if (username)
614 ast_copy_string(new->username, username, sizeof(new->username));
615 if (password)
616 ast_copy_string(new->password, password, sizeof(new->password));
618 if (!class) {
619 SQLAllocHandle(SQL_HANDLE_ENV, SQL_NULL_HANDLE, &new->env);
620 res = SQLSetEnvAttr(new->env, SQL_ATTR_ODBC_VERSION, (void *) SQL_OV_ODBC3, 0);
622 if ((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO)) {
623 ast_log(LOG_WARNING, "res_odbc: Error SetEnv\n");
624 SQLFreeHandle(SQL_HANDLE_ENV, new->env);
625 AST_LIST_UNLOCK(&odbc_list);
626 return res;
630 if (pooling) {
631 new->haspool = pooling;
632 if (limit) {
633 new->limit = limit;
634 } else {
635 ast_log(LOG_WARNING, "Pooling without also setting a limit is pointless. Changing limit from 0 to 5.\n");
636 new->limit = 5;
640 if (class) {
641 ast_log(LOG_NOTICE, "Refreshing ODBC class '%s' dsn->[%s]\n", cat, dsn);
642 } else {
643 odbc_register_class(new, connect);
644 ast_log(LOG_NOTICE, "Registered ODBC class '%s' dsn->[%s]\n", cat, dsn);
649 ast_config_destroy(config);
652 /* Purge classes that we know can go away (pooled with 0, only) */
653 AST_LIST_TRAVERSE_SAFE_BEGIN(&odbc_list, class, list) {
654 if (class->delme && class->haspool && class->count == 0) {
655 AST_LIST_TRAVERSE_SAFE_BEGIN(&(class->odbc_obj), current, list) {
656 AST_LIST_REMOVE_CURRENT(&(class->odbc_obj), list);
657 odbc_obj_disconnect(current);
658 ast_mutex_destroy(&current->lock);
659 free(current);
661 AST_LIST_TRAVERSE_SAFE_END;
663 AST_LIST_REMOVE_CURRENT(&odbc_list, list);
664 free(class);
667 AST_LIST_TRAVERSE_SAFE_END;
668 AST_LIST_UNLOCK(&odbc_list);
670 return 0;
673 static int unload_module(void)
675 /* Prohibit unloading */
676 return -1;
679 static int load_module(void)
681 if(load_odbc_config() == -1)
682 return AST_MODULE_LOAD_DECLINE;
683 ast_cli_register_multiple(cli_odbc, sizeof(cli_odbc) / sizeof(struct ast_cli_entry));
684 ast_log(LOG_NOTICE, "res_odbc loaded.\n");
685 return 0;
688 AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_GLOBAL_SYMBOLS, "ODBC Resource",
689 .load = load_module,
690 .unload = unload_module,
691 .reload = reload,