2 * Asterisk -- An open source telephony toolkit.
4 * Copyright (C) 2006, Proformatique
6 * Written by Richard Braun <rbraun@proformatique.com>
8 * Based on res_sqlite3 by Anthony Minessale II,
9 * and res_config_mysql by Matthew Boehm
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.
23 * \page res_config_sqlite
25 * \section intro_sec Presentation
27 * res_config_sqlite is a module for the Asterisk Open Source PBX to
28 * support SQLite 2 databases. It can be used to fetch configuration
29 * from a database (static configuration files and/or using the Asterisk
30 * RealTime Architecture - ARA). It can also be used to log CDR entries.
31 * Note that Asterisk already comes with a module named cdr_sqlite.
32 * There are two reasons for including it in res_config_sqlite:
33 * the first is that rewriting it was a training to learn how to write a
34 * simple module for Asterisk, the other is to have the same database open for
35 * all kinds of operations, which improves reliability and performance.
37 * \section conf_sec Configuration
39 * The main configuration file is res_config_sqlite.conf.sample It must be readable or
40 * res_config_sqlite will fail to start. It is suggested to use the sample file
41 * in this package as a starting point. The file has only one section
42 * named <code>general</code>. Here are the supported parameters :
45 * <dt><code>dbfile</code></dt>
46 * <dd>The absolute path to the SQLite database (the file can be non existent,
47 * res_config_sqlite will create it if it has the appropriate rights)</dd>
48 * <dt><code>config_table</code></dt>
49 * <dd>The table used for static configuration</dd>
50 * <dt><code>cdr_table</code></dt>
51 * <dd>The table used to store CDR entries (if ommitted, CDR support is
55 * To use res_config_sqlite for static and/or RealTime configuration, refer to the
56 * Asterisk documentation. The file tables.sql can be used to create the
59 * \section status_sec Driver status
61 * The CLI command <code>show sqlite status</code> returns status information
62 * about the running driver.
64 * \section credits_sec Credits
66 * res_config_sqlite was developed by Richard Braun at the Proformatique company.
71 * \brief res_config_sqlite module.
74 /*! \li \ref res_config_sqlite.c uses the configuration file \ref res_config_sqlite.conf
75 * \addtogroup configuration_file Configuration Files
79 * \page res_config_sqlite.conf res_config_sqlite.conf
80 * \verbinclude res_config_sqlite.conf.sample
84 <depend>sqlite</depend>
85 <support_level>extended</support_level>
89 ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
93 #include "asterisk/logger.h"
94 #include "asterisk/app.h"
95 #include "asterisk/pbx.h"
96 #include "asterisk/cdr.h"
97 #include "asterisk/cli.h"
98 #include "asterisk/lock.h"
99 #include "asterisk/config.h"
100 #include "asterisk/module.h"
101 #include "asterisk/linkedlists.h"
103 #define MACRO_BEGIN do {
104 #define MACRO_END } while (0)
106 #define RES_CONFIG_SQLITE_NAME "res_config_sqlite"
107 #define RES_CONFIG_SQLITE_DRIVER "sqlite"
108 #define RES_CONFIG_SQLITE_DESCRIPTION "Resource Module for SQLite 2"
109 #define RES_CONFIG_SQLITE_CONF_FILE "res_config_sqlite.conf"
112 RES_CONFIG_SQLITE_CONFIG_ID,
113 RES_CONFIG_SQLITE_CONFIG_CAT_METRIC,
114 RES_CONFIG_SQLITE_CONFIG_VAR_METRIC,
115 RES_CONFIG_SQLITE_CONFIG_COMMENTED,
116 RES_CONFIG_SQLITE_CONFIG_FILENAME,
117 RES_CONFIG_SQLITE_CONFIG_CATEGORY,
118 RES_CONFIG_SQLITE_CONFIG_VAR_NAME,
119 RES_CONFIG_SQLITE_CONFIG_VAR_VAL,
120 RES_CONFIG_SQLITE_CONFIG_COLUMNS,
123 #define SET_VAR(config, to, from) \
127 __error = set_var(&to, #to, from->value); \
130 ast_config_destroy(config); \
136 AST_THREADSTORAGE(sql_buf);
137 AST_THREADSTORAGE(where_buf);
140 * Maximum number of loops before giving up executing a query. Calls to
141 * sqlite_xxx() functions which can return SQLITE_BUSY
142 * are enclosed by RES_CONFIG_SQLITE_BEGIN and RES_CONFIG_SQLITE_END, e.g.
147 * RES_CONFIG_SQLITE_BEGIN
148 * error = sqlite_exec(db, query, NULL, NULL, &errormsg);
149 * RES_CONFIG_SQLITE_END(error)
155 #define RES_CONFIG_SQLITE_MAX_LOOPS 10
158 * Macro used before executing a query.
160 * \see RES_CONFIG_SQLITE_MAX_LOOPS.
162 #define RES_CONFIG_SQLITE_BEGIN \
166 for (__i = 0; __i < RES_CONFIG_SQLITE_MAX_LOOPS; __i++) {
169 * Macro used after executing a query.
171 * \see RES_CONFIG_SQLITE_MAX_LOOPS.
173 #define RES_CONFIG_SQLITE_END(error) \
174 if (error != SQLITE_BUSY) \
181 * Structure sent to the SQLite callback function for static configuration.
183 * \see add_cfg_entry()
185 struct cfg_entry_args {
186 struct ast_config *cfg;
187 struct ast_category *cat;
189 struct ast_flags flags;
190 const char *who_asked;
194 * Structure sent to the SQLite callback function for RealTime configuration.
196 * \see add_rt_cfg_entry()
198 struct rt_cfg_entry_args {
199 struct ast_variable *var;
200 struct ast_variable *last;
204 * Structure sent to the SQLite callback function for RealTime configuration
205 * (realtime_multi_handler()).
207 * \see add_rt_multi_cfg_entry()
209 struct rt_multi_cfg_entry_args {
210 struct ast_config *cfg;
215 * \brief Allocate a variable.
216 * \param var the address of the variable to set (it will be allocated)
217 * \param name the name of the variable (for error handling)
218 * \param value the value to store in var
219 * \retval 0 on success
220 * \retval 1 if an allocation error occurred
222 static int set_var(char **var, const char *name, const char *value);
225 * \brief Load the configuration file.
226 * \see unload_config()
228 * This function sets dbfile, config_table, and cdr_table. It calls
229 * check_vars() before returning, and unload_config() if an error occurred.
231 * \retval 0 on success
232 * \retval 1 if an error occurred
234 static int load_config(void);
237 * \brief Free resources related to configuration.
240 static void unload_config(void);
243 * \brief Asterisk callback function for CDR support.
244 * \param cdr the CDR entry Asterisk sends us.
246 * Asterisk will call this function each time a CDR entry must be logged if
247 * CDR support is enabled.
249 * \retval 0 on success
250 * \retval 1 if an error occurred
252 static int cdr_handler(struct ast_cdr *cdr);
255 * \brief SQLite callback function for static configuration.
257 * This function is passed to the SQLite engine as a callback function to
258 * parse a row and store it in a struct ast_config object. It relies on
259 * resulting rows being sorted by category.
261 * \param arg a pointer to a struct cfg_entry_args object
262 * \param argc number of columns
263 * \param argv values in the row
264 * \param columnNames names and types of the columns
265 * \retval 0 on success
266 * \retval 1 if an error occurred
267 * \see cfg_entry_args
268 * \see sql_get_config_table
269 * \see config_handler()
271 static int add_cfg_entry(void *arg, int argc, char **argv, char **columnNames);
274 * \brief Asterisk callback function for static configuration.
276 * Asterisk will call this function when it loads its static configuration,
277 * which usually happens at startup and reload.
279 * \param database the database to use (ignored)
280 * \param table the table to use
281 * \param file the file to load from the database
282 * \param cfg the struct ast_config object to use when storing variables
283 * \param flags Optional flags. Not used.
284 * \param suggested_incl suggest include.
287 * \retval NULL if an error occurred
288 * \see add_cfg_entry()
290 static struct ast_config * config_handler(const char *database, const char *table, const char *file,
291 struct ast_config *cfg, struct ast_flags flags, const char *suggested_incl, const char *who_asked);
294 * \brief SQLite callback function for RealTime configuration.
296 * This function is passed to the SQLite engine as a callback function to
297 * parse a row and store it in a linked list of struct ast_variable objects.
299 * \param arg a pointer to a struct rt_cfg_entry_args object
300 * \param argc number of columns
301 * \param argv values in the row
302 * \param columnNames names and types of the columns
303 * \retval 0 on success.
304 * \retval 1 if an error occurred.
305 * \see rt_cfg_entry_args
306 * \see realtime_handler()
308 static int add_rt_cfg_entry(void *arg, int argc, char **argv,
312 * \brief Asterisk callback function for RealTime configuration.
314 * Asterisk will call this function each time it requires a variable
315 * through the RealTime architecture. ap is a list of parameters and
316 * values used to find a specific row, e.g one parameter "name" and
317 * one value "123" so that the SQL query becomes <code>SELECT * FROM
318 * table WHERE name = '123';</code>.
320 * \param database the database to use (ignored)
321 * \param table the table to use
322 * \param fields list of parameters and values to match
324 * \retval a linked list of struct ast_variable objects
325 * \retval NULL if an error occurred
326 * \see add_rt_cfg_entry()
328 static struct ast_variable * realtime_handler(const char *database,
329 const char *table, const struct ast_variable *fields);
332 * \brief SQLite callback function for RealTime configuration.
334 * This function performs the same actions as add_rt_cfg_entry() except
335 * that the rt_multi_cfg_entry_args structure is designed to store
336 * categories in addition to variables.
338 * \param arg a pointer to a struct rt_multi_cfg_entry_args object
339 * \param argc number of columns
340 * \param argv values in the row
341 * \param columnNames names and types of the columns
342 * \retval 0 on success.
343 * \retval 1 if an error occurred.
344 * \see rt_multi_cfg_entry_args
345 * \see realtime_multi_handler()
347 static int add_rt_multi_cfg_entry(void *arg, int argc, char **argv,
351 * \brief Asterisk callback function for RealTime configuration.
353 * This function performs the same actions as realtime_handler() except
354 * that it can store variables per category, and can return several
357 * \param database the database to use (ignored)
358 * \param table the table to use
359 * \param fields list of parameters and values to match
360 * \retval a struct ast_config object storing categories and variables.
361 * \retval NULL if an error occurred.
363 * \see add_rt_multi_cfg_entry()
365 static struct ast_config * realtime_multi_handler(const char *database,
366 const char *table, const struct ast_variable *fields);
369 * \brief Asterisk callback function for RealTime configuration (variable
372 * Asterisk will call this function each time a variable has been modified
373 * internally and must be updated in the backend engine. keyfield and entity
374 * are used to find the row to update, e.g. <code>UPDATE table SET ... WHERE
375 * keyfield = 'entity';</code>. ap is a list of parameters and values with the
376 * same format as the other realtime functions.
378 * \param database the database to use (ignored)
379 * \param table the table to use
380 * \param keyfield the column of the matching cell
381 * \param entity the value of the matching cell
382 * \param fields list of parameters and new values to update in the database
383 * \retval the number of affected rows.
384 * \retval -1 if an error occurred.
386 static int realtime_update_handler(const char *database, const char *table,
387 const char *keyfield, const char *entity, const struct ast_variable *fields);
388 static int realtime_update2_handler(const char *database, const char *table,
389 const struct ast_variable *lookup_fields, const struct ast_variable *update_fields);
392 * \brief Asterisk callback function for RealTime configuration (variable
395 * Asterisk will call this function each time a variable has been created
396 * internally and must be stored in the backend engine.
397 * are used to find the row to update, e.g. ap is a list of parameters and
398 * values with the same format as the other realtime functions.
400 * \param database the database to use (ignored)
401 * \param table the table to use
402 * \param fields list of parameters and new values to insert into the database
403 * \retval the rowid of inserted row.
404 * \retval -1 if an error occurred.
406 static int realtime_store_handler(const char *database, const char *table,
407 const struct ast_variable *fields);
410 * \brief Asterisk callback function for RealTime configuration (destroys
413 * Asterisk will call this function each time a variable has been destroyed
414 * internally and must be removed from the backend engine. keyfield and entity
415 * are used to find the row to delete, e.g. <code>DELETE FROM table WHERE
416 * keyfield = 'entity';</code>. ap is a list of parameters and values with the
417 * same format as the other realtime functions.
419 * \param database the database to use (ignored)
420 * \param table the table to use
421 * \param keyfield the column of the matching cell
422 * \param entity the value of the matching cell
423 * \param fields list of additional parameters for cell matching
424 * \retval the number of affected rows.
425 * \retval -1 if an error occurred.
427 static int realtime_destroy_handler(const char *database, const char *table,
428 const char *keyfield, const char *entity, const struct ast_variable *fields);
431 * \brief Asterisk callback function for the CLI status command.
433 * \param e CLI command
435 * \param a CLI argument list
436 * \return RESULT_SUCCESS
438 static char *handle_cli_show_sqlite_status(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a);
439 static char *handle_cli_sqlite_show_tables(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a);
441 static int realtime_require_handler(const char *database, const char *table, va_list ap);
442 static int realtime_unload_handler(const char *unused, const char *tablename);
444 /*! The SQLite database object. */
447 /*! Set to 1 if CDR support is enabled. */
450 /*! Set to 1 if the CDR callback function was registered. */
451 static int cdr_registered;
453 /*! Set to 1 if the CLI status command callback function was registered. */
454 static int cli_status_registered;
456 /*! The path of the database file. */
459 /*! The name of the static configuration table. */
460 static char *config_table;
462 /*! The name of the table used to store CDR entries. */
463 static char *cdr_table;
466 * The structure specifying all callback functions used by Asterisk for static
467 * and RealTime configuration.
469 static struct ast_config_engine sqlite_engine =
471 .name = RES_CONFIG_SQLITE_DRIVER,
472 .load_func = config_handler,
473 .realtime_func = realtime_handler,
474 .realtime_multi_func = realtime_multi_handler,
475 .store_func = realtime_store_handler,
476 .destroy_func = realtime_destroy_handler,
477 .update_func = realtime_update_handler,
478 .update2_func = realtime_update2_handler,
479 .require_func = realtime_require_handler,
480 .unload_func = realtime_unload_handler,
484 * The mutex used to prevent simultaneous access to the SQLite database.
486 AST_MUTEX_DEFINE_STATIC(mutex);
489 * Structure containing details and callback functions for the CLI status
492 static struct ast_cli_entry cli_status[] = {
493 AST_CLI_DEFINE(handle_cli_show_sqlite_status, "Show status information about the SQLite 2 driver"),
494 AST_CLI_DEFINE(handle_cli_sqlite_show_tables, "Cached table information about the SQLite 2 driver"),
497 struct sqlite_cache_columns {
500 unsigned char isint; /*!< By definition, only INTEGER PRIMARY KEY is an integer; everything else is a string. */
501 AST_RWLIST_ENTRY(sqlite_cache_columns) list;
504 struct sqlite_cache_tables {
506 AST_RWLIST_HEAD(_columns, sqlite_cache_columns) columns;
507 AST_RWLIST_ENTRY(sqlite_cache_tables) list;
510 static AST_RWLIST_HEAD_STATIC(sqlite_tables, sqlite_cache_tables);
513 * Taken from Asterisk 1.2 cdr_sqlite.so.
516 /*! SQL query format to create the CDR table if non existent. */
517 static char *sql_create_cdr_table =
518 "CREATE TABLE '%q' (\n"
520 " clid VARCHAR(80) NOT NULL DEFAULT '',\n"
521 " src VARCHAR(80) NOT NULL DEFAULT '',\n"
522 " dst VARCHAR(80) NOT NULL DEFAULT '',\n"
523 " dcontext VARCHAR(80) NOT NULL DEFAULT '',\n"
524 " channel VARCHAR(80) NOT NULL DEFAULT '',\n"
525 " dstchannel VARCHAR(80) NOT NULL DEFAULT '',\n"
526 " lastapp VARCHAR(80) NOT NULL DEFAULT '',\n"
527 " lastdata VARCHAR(80) NOT NULL DEFAULT '',\n"
528 " start DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00',\n"
529 " answer DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00',\n"
530 " end DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00',\n"
531 " duration INT(11) NOT NULL DEFAULT 0,\n"
532 " billsec INT(11) NOT NULL DEFAULT 0,\n"
533 " disposition VARCHAR(45) NOT NULL DEFAULT '',\n"
534 " amaflags INT(11) NOT NULL DEFAULT 0,\n"
535 " accountcode VARCHAR(20) NOT NULL DEFAULT '',\n"
536 " uniqueid VARCHAR(32) NOT NULL DEFAULT '',\n"
537 " userfield VARCHAR(255) NOT NULL DEFAULT '',\n"
538 " PRIMARY KEY (id)\n"
542 * SQL query format to describe the table structure
544 #define sql_table_structure "SELECT sql FROM sqlite_master WHERE type='table' AND tbl_name='%s'"
547 * SQL query format to fetch the static configuration of a file.
548 * Rows must be sorted by category.
550 * \see add_cfg_entry()
552 #define sql_get_config_table \
555 " WHERE filename = '%q' AND commented = 0" \
556 " ORDER BY cat_metric ASC, var_metric ASC;"
558 static void free_table(struct sqlite_cache_tables *tblptr)
560 struct sqlite_cache_columns *col;
562 /* Obtain a write lock to ensure there are no read locks outstanding */
563 AST_RWLIST_WRLOCK(&(tblptr->columns));
564 while ((col = AST_RWLIST_REMOVE_HEAD(&(tblptr->columns), list))) {
567 AST_RWLIST_UNLOCK(&(tblptr->columns));
568 AST_RWLIST_HEAD_DESTROY(&(tblptr->columns));
572 static int find_table_cb(void *vtblptr, int argc, char **argv, char **columnNames)
574 struct sqlite_cache_tables *tblptr = vtblptr;
575 char *sql = ast_strdupa(argv[0]), *start, *end, *type, *remainder;
577 AST_DECLARE_APP_ARGS(fie,
578 AST_APP_ARG(ld)[100]; /* This means we support up to 100 columns per table */
580 struct sqlite_cache_columns *col;
582 /* This is really fun. We get to parse an SQL statement to figure out
583 * what columns are in the table.
585 if ((start = strchr(sql, '(')) && (end = strrchr(sql, ')'))) {
593 AST_STANDARD_APP_ARGS(fie, start);
594 for (i = 0; i < fie.argc; i++) {
595 fie.ld[i] = ast_skip_blanks(fie.ld[i]);
596 ast_debug(5, "Found field: %s\n", fie.ld[i]);
597 if (strncasecmp(fie.ld[i], "PRIMARY KEY", 11) == 0 && (start = strchr(fie.ld[i], '(')) && (end = strchr(fie.ld[i], ')'))) {
599 AST_RWLIST_TRAVERSE(&(tblptr->columns), col, list) {
600 if (strcasecmp(start + 1, col->name) == 0 && strcasestr(col->type, "INTEGER")) {
606 /* type delimiter could be any space character */
607 for (type = fie.ld[i]; *type > 32; type++);
609 type = ast_skip_blanks(type);
610 for (remainder = type; *remainder > 32; remainder++);
612 if (!(col = ast_calloc(1, sizeof(*col) + strlen(fie.ld[i]) + strlen(type) + 2))) {
615 col->name = (char *)col + sizeof(*col);
616 col->type = (char *)col + sizeof(*col) + strlen(fie.ld[i]) + 1;
617 strcpy(col->name, fie.ld[i]); /* SAFE */
618 strcpy(col->type, type); /* SAFE */
619 if (strcasestr(col->type, "INTEGER") && strcasestr(col->type, "PRIMARY KEY")) {
622 AST_LIST_INSERT_TAIL(&(tblptr->columns), col, list);
627 static struct sqlite_cache_tables *find_table(const char *tablename)
629 struct sqlite_cache_tables *tblptr;
631 char *sql, *errstr = NULL;
633 AST_RWLIST_RDLOCK(&sqlite_tables);
635 for (i = 0; i < 2; i++) {
636 AST_RWLIST_TRAVERSE(&sqlite_tables, tblptr, list) {
637 if (strcmp(tblptr->name, tablename) == 0) {
642 AST_RWLIST_RDLOCK(&(tblptr->columns));
643 AST_RWLIST_UNLOCK(&sqlite_tables);
648 AST_RWLIST_UNLOCK(&sqlite_tables);
649 AST_RWLIST_WRLOCK(&sqlite_tables);
653 /* Table structure not cached; build the structure now */
654 if (ast_asprintf(&sql, sql_table_structure, tablename) < 0) {
657 if (!(tblptr = ast_calloc(1, sizeof(*tblptr) + strlen(tablename) + 1))) {
658 AST_RWLIST_UNLOCK(&sqlite_tables);
659 ast_log(LOG_ERROR, "Memory error. Cannot cache table '%s'\n", tablename);
663 tblptr->name = (char *)tblptr + sizeof(*tblptr);
664 strcpy(tblptr->name, tablename); /* SAFE */
665 AST_RWLIST_HEAD_INIT(&(tblptr->columns));
667 ast_debug(1, "About to query table structure: %s\n", sql);
669 ast_mutex_lock(&mutex);
670 if ((err = sqlite_exec(db, sql, find_table_cb, tblptr, &errstr))) {
671 ast_mutex_unlock(&mutex);
672 ast_log(LOG_WARNING, "SQLite error %d: %s\n", err, errstr);
675 AST_RWLIST_UNLOCK(&sqlite_tables);
679 ast_mutex_unlock(&mutex);
682 if (AST_LIST_EMPTY(&(tblptr->columns))) {
684 AST_RWLIST_UNLOCK(&sqlite_tables);
688 AST_RWLIST_INSERT_TAIL(&sqlite_tables, tblptr, list);
689 AST_RWLIST_RDLOCK(&(tblptr->columns));
690 AST_RWLIST_UNLOCK(&sqlite_tables);
694 #define release_table(a) AST_RWLIST_UNLOCK(&((a)->columns))
696 static int set_var(char **var, const char *name, const char *value)
701 *var = ast_strdup(value);
704 ast_log(LOG_WARNING, "Unable to allocate variable %s\n", name);
711 static int check_vars(void)
714 ast_log(LOG_ERROR, "Required parameter undefined: dbfile\n");
718 use_cdr = (cdr_table != NULL);
723 static int load_config(void)
725 struct ast_config *config;
726 struct ast_variable *var;
728 struct ast_flags config_flags = { 0 };
730 config = ast_config_load(RES_CONFIG_SQLITE_CONF_FILE, config_flags);
732 if (config == CONFIG_STATUS_FILEMISSING || config == CONFIG_STATUS_FILEINVALID) {
733 ast_log(LOG_ERROR, "Unable to load " RES_CONFIG_SQLITE_CONF_FILE "\n");
737 for (var = ast_variable_browse(config, "general"); var; var = var->next) {
738 if (!strcasecmp(var->name, "dbfile"))
739 SET_VAR(config, dbfile, var);
740 else if (!strcasecmp(var->name, "config_table"))
741 SET_VAR(config, config_table, var);
742 else if (!strcasecmp(var->name, "cdr_table")) {
743 SET_VAR(config, cdr_table, var);
745 ast_log(LOG_WARNING, "Unknown parameter : %s\n", var->name);
748 ast_config_destroy(config);
749 error = check_vars();
759 static void unload_config(void)
761 struct sqlite_cache_tables *tbl;
764 ast_free(config_table);
768 AST_RWLIST_WRLOCK(&sqlite_tables);
769 while ((tbl = AST_RWLIST_REMOVE_HEAD(&sqlite_tables, list))) {
772 AST_RWLIST_UNLOCK(&sqlite_tables);
775 static int cdr_handler(struct ast_cdr *cdr)
777 char *errormsg = NULL, *tmp, workspace[500];
779 struct sqlite_cache_tables *tbl = find_table(cdr_table);
780 struct sqlite_cache_columns *col;
781 struct ast_str *sql1 = ast_str_create(160), *sql2 = ast_str_create(16);
785 ast_log(LOG_WARNING, "No such table: %s\n", cdr_table);
789 ast_str_set(&sql1, 0, "INSERT INTO %s (", cdr_table);
790 ast_str_set(&sql2, 0, ") VALUES (");
792 AST_RWLIST_TRAVERSE(&(tbl->columns), col, list) {
794 ast_cdr_format_var(cdr, col->name, &tmp, workspace, sizeof(workspace), 1);
798 if (sscanf(tmp, "%30d", &scannum) == 1) {
799 ast_str_append(&sql1, 0, "%s%s", first ? "" : ",", col->name);
800 ast_str_append(&sql2, 0, "%s%d", first ? "" : ",", scannum);
803 ast_cdr_format_var(cdr, col->name, &tmp, workspace, sizeof(workspace), 0);
807 ast_str_append(&sql1, 0, "%s%s", first ? "" : ",", col->name);
808 tmp = sqlite_mprintf("%Q", tmp);
809 ast_str_append(&sql2, 0, "%s%s", first ? "" : ",", tmp);
816 ast_str_append(&sql1, 0, "%s)", ast_str_buffer(sql2));
819 ast_debug(1, "SQL query: %s\n", ast_str_buffer(sql1));
821 ast_mutex_lock(&mutex);
823 RES_CONFIG_SQLITE_BEGIN
824 error = sqlite_exec(db, ast_str_buffer(sql1), NULL, NULL, &errormsg);
825 RES_CONFIG_SQLITE_END(error)
827 ast_mutex_unlock(&mutex);
832 ast_log(LOG_ERROR, "%s\n", S_OR(errormsg, sqlite_error_string(error)));
833 sqlite_freemem(errormsg);
836 sqlite_freemem(errormsg);
841 static int add_cfg_entry(void *arg, int argc, char **argv, char **columnNames)
843 struct cfg_entry_args *args;
844 struct ast_variable *var;
846 if (argc != RES_CONFIG_SQLITE_CONFIG_COLUMNS) {
847 ast_log(LOG_WARNING, "Corrupt table\n");
853 if (!strcmp(argv[RES_CONFIG_SQLITE_CONFIG_VAR_NAME], "#include")) {
854 struct ast_config *cfg;
857 val = argv[RES_CONFIG_SQLITE_CONFIG_VAR_VAL];
858 cfg = ast_config_internal_load(val, args->cfg, args->flags, "", args->who_asked);
861 ast_log(LOG_WARNING, "Unable to include %s\n", val);
869 if (!args->cat_name || strcmp(args->cat_name, argv[RES_CONFIG_SQLITE_CONFIG_CATEGORY])) {
870 args->cat = ast_category_new(argv[RES_CONFIG_SQLITE_CONFIG_CATEGORY], "", 99999);
873 ast_log(LOG_WARNING, "Unable to allocate category\n");
877 ast_free(args->cat_name);
878 args->cat_name = ast_strdup(argv[RES_CONFIG_SQLITE_CONFIG_CATEGORY]);
880 if (!args->cat_name) {
881 ast_category_destroy(args->cat);
885 ast_category_append(args->cfg, args->cat);
888 var = ast_variable_new(argv[RES_CONFIG_SQLITE_CONFIG_VAR_NAME], argv[RES_CONFIG_SQLITE_CONFIG_VAR_VAL], "");
891 ast_log(LOG_WARNING, "Unable to allocate variable\n");
895 ast_variable_append(args->cat, var);
900 static struct ast_config *config_handler(const char *database, const char *table, const char *file,
901 struct ast_config *cfg, struct ast_flags flags, const char *suggested_incl, const char *who_asked)
903 struct cfg_entry_args args;
904 char *query, *errormsg = NULL;
909 ast_log(LOG_ERROR, "Table name unspecified\n");
913 table = config_table;
915 query = sqlite_mprintf(sql_get_config_table, table, file);
918 ast_log(LOG_WARNING, "Unable to allocate SQL query\n");
922 ast_debug(1, "SQL query: %s\n", query);
925 args.cat_name = NULL;
927 args.who_asked = who_asked;
929 ast_mutex_lock(&mutex);
931 RES_CONFIG_SQLITE_BEGIN
932 error = sqlite_exec(db, query, add_cfg_entry, &args, &errormsg);
933 RES_CONFIG_SQLITE_END(error)
935 ast_mutex_unlock(&mutex);
937 ast_free(args.cat_name);
938 sqlite_freemem(query);
941 ast_log(LOG_ERROR, "%s\n", S_OR(errormsg, sqlite_error_string(error)));
942 sqlite_freemem(errormsg);
945 sqlite_freemem(errormsg);
950 static int add_rt_cfg_entry(void *arg, int argc, char **argv, char **columnNames)
952 struct rt_cfg_entry_args *args;
953 struct ast_variable *var;
958 for (i = 0; i < argc; i++) {
962 if (!(var = ast_variable_new(columnNames[i], argv[i], "")))
971 args->last->next = var;
979 static struct ast_variable * realtime_handler(const char *database, const char *table, const struct ast_variable *fields)
981 char *query, *errormsg = NULL, *op, *tmp_str;
982 struct rt_cfg_entry_args args;
983 const struct ast_variable *field = fields;
987 ast_log(LOG_WARNING, "Table name unspecified\n");
995 op = (strchr(field->name, ' ') == NULL) ? " =" : "";
997 /* \cond DOXYGEN_CAN_PARSE_THIS */
999 #define QUERY "SELECT * FROM '%q' WHERE%s %q%s '%q'"
1002 query = sqlite_mprintf(QUERY, table, (config_table && !strcmp(config_table, table)) ? " commented = 0 AND" : "", field->name, op, field->value);
1005 ast_log(LOG_WARNING, "Unable to allocate SQL query\n");
1009 while ((field = field->next)) {
1010 op = (strchr(field->name, ' ') == NULL) ? " =" : "";
1011 tmp_str = sqlite_mprintf("%s AND %q%s '%q'", query, field->name, op, field->value);
1012 sqlite_freemem(query);
1015 ast_log(LOG_WARNING, "Unable to reallocate SQL query\n");
1022 tmp_str = sqlite_mprintf("%s LIMIT 1;", query);
1023 sqlite_freemem(query);
1026 ast_log(LOG_WARNING, "Unable to reallocate SQL query\n");
1031 ast_debug(1, "SQL query: %s\n", query);
1035 ast_mutex_lock(&mutex);
1037 RES_CONFIG_SQLITE_BEGIN
1038 error = sqlite_exec(db, query, add_rt_cfg_entry, &args, &errormsg);
1039 RES_CONFIG_SQLITE_END(error)
1041 ast_mutex_unlock(&mutex);
1043 sqlite_freemem(query);
1046 ast_log(LOG_WARNING, "%s\n", S_OR(errormsg, sqlite_error_string(error)));
1047 sqlite_freemem(errormsg);
1048 ast_variables_destroy(args.var);
1051 sqlite_freemem(errormsg);
1056 static int add_rt_multi_cfg_entry(void *arg, int argc, char **argv, char **columnNames)
1058 struct rt_multi_cfg_entry_args *args;
1059 struct ast_category *cat;
1060 struct ast_variable *var;
1068 * cat_name should always be set here, since initfield is forged from
1069 * params[0] in realtime_multi_handler(), which is a search parameter
1072 for (i = 0; i < argc; i++) {
1073 if (!strcmp(args->initfield, columnNames[i]))
1078 ast_log(LOG_ERROR, "Bogus SQL results, cat_name is NULL !\n");
1082 if (!(cat = ast_category_new(cat_name, "", 99999))) {
1083 ast_log(LOG_WARNING, "Unable to allocate category\n");
1087 ast_category_append(args->cfg, cat);
1089 for (i = 0; i < argc; i++) {
1094 if (!(var = ast_variable_new(columnNames[i], argv[i], ""))) {
1095 ast_log(LOG_WARNING, "Unable to allocate variable\n");
1099 ast_variable_append(cat, var);
1105 static struct ast_config *realtime_multi_handler(const char *database,
1106 const char *table, const struct ast_variable *fields)
1108 char *query, *errormsg = NULL, *op, *tmp_str, *initfield;
1109 struct rt_multi_cfg_entry_args args;
1110 const struct ast_variable *field = fields;
1111 struct ast_config *cfg;
1115 ast_log(LOG_WARNING, "Table name unspecified\n");
1123 if (!(cfg = ast_config_new())) {
1124 ast_log(LOG_WARNING, "Unable to allocate configuration structure\n");
1128 if (!(initfield = ast_strdup(field->name))) {
1129 ast_config_destroy(cfg);
1133 tmp_str = strchr(initfield, ' ');
1138 op = (!strchr(field->name, ' ')) ? " =" : "";
1141 * Asterisk sends us an already escaped string when searching for
1142 * "exten LIKE" (uh!). Handle it separately.
1144 tmp_str = (!strcmp(field->value, "\\_%")) ? "_%" : (char *)field->value;
1146 /* \cond DOXYGEN_CAN_PARSE_THIS */
1148 #define QUERY "SELECT * FROM '%q' WHERE%s %q%s '%q'"
1151 if (!(query = sqlite_mprintf(QUERY, table, (config_table && !strcmp(config_table, table)) ? " commented = 0 AND" : "", field->name, op, tmp_str))) {
1152 ast_log(LOG_WARNING, "Unable to allocate SQL query\n");
1153 ast_config_destroy(cfg);
1154 ast_free(initfield);
1158 while ((field = field->next)) {
1159 op = (!strchr(field->name, ' ')) ? " =" : "";
1160 tmp_str = sqlite_mprintf("%s AND %q%s '%q'", query, field->name, op, field->value);
1161 sqlite_freemem(query);
1164 ast_log(LOG_WARNING, "Unable to reallocate SQL query\n");
1165 ast_config_destroy(cfg);
1166 ast_free(initfield);
1173 if (!(tmp_str = sqlite_mprintf("%s ORDER BY %q;", query, initfield))) {
1174 ast_log(LOG_WARNING, "Unable to reallocate SQL query\n");
1175 sqlite_freemem(query);
1176 ast_config_destroy(cfg);
1177 ast_free(initfield);
1181 sqlite_freemem(query);
1183 ast_debug(1, "SQL query: %s\n", query);
1185 args.initfield = initfield;
1187 ast_mutex_lock(&mutex);
1189 RES_CONFIG_SQLITE_BEGIN
1190 error = sqlite_exec(db, query, add_rt_multi_cfg_entry, &args, &errormsg);
1191 RES_CONFIG_SQLITE_END(error)
1193 ast_mutex_unlock(&mutex);
1195 sqlite_freemem(query);
1196 ast_free(initfield);
1199 ast_log(LOG_WARNING, "%s\n", S_OR(errormsg, sqlite_error_string(error)));
1200 sqlite_freemem(errormsg);
1201 ast_config_destroy(cfg);
1204 sqlite_freemem(errormsg);
1209 static int realtime_update_handler(const char *database, const char *table,
1210 const char *keyfield, const char *entity, const struct ast_variable *fields)
1212 char *query, *errormsg = NULL, *tmp_str;
1213 const struct ast_variable *field = fields;
1214 int error, rows_num;
1217 ast_log(LOG_WARNING, "Table name unspecified\n");
1225 /* \cond DOXYGEN_CAN_PARSE_THIS */
1227 #define QUERY "UPDATE '%q' SET %q = '%q'"
1230 if (!(query = sqlite_mprintf(QUERY, table, field->name, field->value))) {
1231 ast_log(LOG_WARNING, "Unable to allocate SQL query\n");
1235 while ((field = field->next)) {
1236 tmp_str = sqlite_mprintf("%s, %q = '%q'", query, field->name, field->value);
1237 sqlite_freemem(query);
1240 ast_log(LOG_WARNING, "Unable to reallocate SQL query\n");
1247 if (!(tmp_str = sqlite_mprintf("%s WHERE %q = '%q';", query, keyfield, entity))) {
1248 ast_log(LOG_WARNING, "Unable to reallocate SQL query\n");
1249 sqlite_freemem(query);
1253 sqlite_freemem(query);
1255 ast_debug(1, "SQL query: %s\n", query);
1257 ast_mutex_lock(&mutex);
1259 RES_CONFIG_SQLITE_BEGIN
1260 error = sqlite_exec(db, query, NULL, NULL, &errormsg);
1261 RES_CONFIG_SQLITE_END(error)
1264 rows_num = sqlite_changes(db);
1268 ast_mutex_unlock(&mutex);
1270 sqlite_freemem(query);
1273 ast_log(LOG_WARNING, "%s\n", S_OR(errormsg, sqlite_error_string(error)));
1275 sqlite_freemem(errormsg);
1280 static int realtime_update2_handler(const char *database, const char *table,
1281 const struct ast_variable *lookup_fields, const struct ast_variable *update_fields)
1283 char *errormsg = NULL, *tmp1, *tmp2;
1284 int error, rows_num, first = 1;
1285 struct ast_str *sql = ast_str_thread_get(&sql_buf, 100);
1286 struct ast_str *where = ast_str_thread_get(&where_buf, 100);
1287 const struct ast_variable *field;
1290 ast_log(LOG_WARNING, "Table name unspecified\n");
1298 ast_str_set(&sql, 0, "UPDATE %s SET", table);
1299 ast_str_set(&where, 0, " WHERE");
1301 for (field = lookup_fields; field; field = field->next) {
1302 ast_str_append(&where, 0, "%s %s = %s",
1303 first ? "" : " AND",
1304 tmp1 = sqlite_mprintf("%q", field->name),
1305 tmp2 = sqlite_mprintf("%Q", field->value));
1306 sqlite_freemem(tmp1);
1307 sqlite_freemem(tmp2);
1312 ast_log(LOG_ERROR, "No criteria specified on update to '%s@%s'!\n", table, database);
1317 for (field = update_fields; field; field = field->next) {
1318 ast_str_append(&sql, 0, "%s %s = %s",
1320 tmp1 = sqlite_mprintf("%q", field->name),
1321 tmp2 = sqlite_mprintf("%Q", field->value));
1322 sqlite_freemem(tmp1);
1323 sqlite_freemem(tmp2);
1327 ast_str_append(&sql, 0, " %s", ast_str_buffer(where));
1328 ast_debug(1, "SQL query: %s\n", ast_str_buffer(sql));
1330 ast_mutex_lock(&mutex);
1332 RES_CONFIG_SQLITE_BEGIN
1333 error = sqlite_exec(db, ast_str_buffer(sql), NULL, NULL, &errormsg);
1334 RES_CONFIG_SQLITE_END(error)
1337 rows_num = sqlite_changes(db);
1342 ast_mutex_unlock(&mutex);
1345 ast_log(LOG_WARNING, "%s\n", S_OR(errormsg, sqlite_error_string(error)));
1347 sqlite_freemem(errormsg);
1352 static int realtime_store_handler(const char *database, const char *table, const struct ast_variable *fields)
1354 char *errormsg = NULL, *tmp_str, *tmp_keys = NULL, *tmp_keys2 = NULL, *tmp_vals = NULL, *tmp_vals2 = NULL;
1355 const struct ast_variable *field = fields;
1359 ast_log(LOG_WARNING, "Table name unspecified\n");
1367 /* \cond DOXYGEN_CAN_PARSE_THIS */
1369 #define QUERY "INSERT into '%q' (%s) VALUES (%s);"
1374 tmp_keys = sqlite_mprintf("%s, %q", tmp_keys2, field->name);
1375 sqlite_freemem(tmp_keys2);
1377 tmp_keys = sqlite_mprintf("%q", field->name);
1380 ast_log(LOG_WARNING, "Unable to reallocate SQL query\n");
1381 sqlite_freemem(tmp_vals);
1386 tmp_vals = sqlite_mprintf("%s, '%q'", tmp_vals2, field->value);
1387 sqlite_freemem(tmp_vals2);
1389 tmp_vals = sqlite_mprintf("'%q'", field->value);
1392 ast_log(LOG_WARNING, "Unable to reallocate SQL query\n");
1393 sqlite_freemem(tmp_keys);
1398 tmp_keys2 = tmp_keys;
1399 tmp_vals2 = tmp_vals;
1400 } while ((field = field->next));
1402 if (!(tmp_str = sqlite_mprintf(QUERY, table, tmp_keys, tmp_vals))) {
1403 ast_log(LOG_WARNING, "Unable to reallocate SQL query\n");
1404 sqlite_freemem(tmp_keys);
1405 sqlite_freemem(tmp_vals);
1409 sqlite_freemem(tmp_keys);
1410 sqlite_freemem(tmp_vals);
1412 ast_debug(1, "SQL query: %s\n", tmp_str);
1414 ast_mutex_lock(&mutex);
1416 RES_CONFIG_SQLITE_BEGIN
1417 error = sqlite_exec(db, tmp_str, NULL, NULL, &errormsg);
1418 RES_CONFIG_SQLITE_END(error)
1421 rows_id = sqlite_last_insert_rowid(db);
1426 ast_mutex_unlock(&mutex);
1428 sqlite_freemem(tmp_str);
1431 ast_log(LOG_WARNING, "%s\n", S_OR(errormsg, sqlite_error_string(error)));
1433 sqlite_freemem(errormsg);
1438 static int realtime_destroy_handler(const char *database, const char *table,
1439 const char *keyfield, const char *entity, const struct ast_variable *fields)
1441 char *query, *errormsg = NULL, *tmp_str;
1442 const struct ast_variable *field;
1443 int error, rows_num;
1446 ast_log(LOG_WARNING, "Table name unspecified\n");
1450 /* \cond DOXYGEN_CAN_PARSE_THIS */
1452 #define QUERY "DELETE FROM '%q' WHERE"
1455 if (!(query = sqlite_mprintf(QUERY, table))) {
1456 ast_log(LOG_WARNING, "Unable to allocate SQL query\n");
1460 for (field = fields; field; field = field->next) {
1461 tmp_str = sqlite_mprintf("%s %q = '%q' AND", query, field->name, field->value);
1462 sqlite_freemem(query);
1465 ast_log(LOG_WARNING, "Unable to reallocate SQL query\n");
1472 if (!(tmp_str = sqlite_mprintf("%s %q = '%q';", query, keyfield, entity))) {
1473 ast_log(LOG_WARNING, "Unable to reallocate SQL query\n");
1474 sqlite_freemem(query);
1477 sqlite_freemem(query);
1479 ast_debug(1, "SQL query: %s\n", query);
1481 ast_mutex_lock(&mutex);
1483 RES_CONFIG_SQLITE_BEGIN
1484 error = sqlite_exec(db, query, NULL, NULL, &errormsg);
1485 RES_CONFIG_SQLITE_END(error)
1488 rows_num = sqlite_changes(db);
1493 ast_mutex_unlock(&mutex);
1495 sqlite_freemem(query);
1498 ast_log(LOG_WARNING, "%s\n", S_OR(errormsg, sqlite_error_string(error)));
1500 sqlite_freemem(errormsg);
1505 static int realtime_require_handler(const char *unused, const char *tablename, va_list ap)
1507 struct sqlite_cache_tables *tbl = find_table(tablename);
1508 struct sqlite_cache_columns *col;
1516 while ((elm = va_arg(ap, char *))) {
1517 type = va_arg(ap, require_type);
1519 /* Check if the field matches the criteria */
1520 AST_RWLIST_TRAVERSE(&tbl->columns, col, list) {
1521 if (strcmp(col->name, elm) == 0) {
1522 /* SQLite only has two types - the 32-bit integer field that
1523 * is the key column, and everything else (everything else
1526 if (col->isint && !ast_rq_is_int(type)) {
1527 ast_log(LOG_WARNING, "Realtime table %s: column '%s' is an integer field, but Asterisk requires that it not be!\n", tablename, col->name);
1534 ast_log(LOG_WARNING, "Realtime table %s requires column '%s', but that column does not exist!\n", tablename, elm);
1537 AST_RWLIST_UNLOCK(&(tbl->columns));
1541 static int realtime_unload_handler(const char *unused, const char *tablename)
1543 struct sqlite_cache_tables *tbl;
1544 AST_RWLIST_WRLOCK(&sqlite_tables);
1545 AST_RWLIST_TRAVERSE_SAFE_BEGIN(&sqlite_tables, tbl, list) {
1546 if (!strcasecmp(tbl->name, tablename)) {
1547 AST_RWLIST_REMOVE_CURRENT(list);
1551 AST_RWLIST_TRAVERSE_SAFE_END
1552 AST_RWLIST_UNLOCK(&sqlite_tables);
1556 static char *handle_cli_show_sqlite_status(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
1560 e->command = "sqlite show status";
1562 "Usage: sqlite show status\n"
1563 " Show status information about the SQLite 2 driver\n";
1570 return CLI_SHOWUSAGE;
1572 ast_cli(a->fd, "SQLite database path: %s\n", dbfile);
1573 ast_cli(a->fd, "config_table: ");
1576 ast_cli(a->fd, "unspecified, must be present in extconfig.conf\n");
1578 ast_cli(a->fd, "%s\n", config_table);
1580 ast_cli(a->fd, "cdr_table: ");
1583 ast_cli(a->fd, "unspecified, CDR support disabled\n");
1585 ast_cli(a->fd, "%s\n", cdr_table);
1590 static char *handle_cli_sqlite_show_tables(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
1592 struct sqlite_cache_tables *tbl;
1593 struct sqlite_cache_columns *col;
1598 e->command = "sqlite show tables";
1600 "Usage: sqlite show tables\n"
1601 " Show table information about the SQLite 2 driver\n";
1608 return CLI_SHOWUSAGE;
1610 AST_RWLIST_RDLOCK(&sqlite_tables);
1611 AST_RWLIST_TRAVERSE(&sqlite_tables, tbl, list) {
1613 ast_cli(a->fd, "Table %s:\n", tbl->name);
1614 AST_RWLIST_TRAVERSE(&(tbl->columns), col, list) {
1615 fprintf(stderr, "%s\n", col->name);
1616 ast_cli(a->fd, " %20.20s %-30.30s\n", col->name, col->type);
1619 AST_RWLIST_UNLOCK(&sqlite_tables);
1622 ast_cli(a->fd, "No tables currently in cache\n");
1628 static int unload_module(void)
1630 if (cdr_registered && ast_cdr_unregister(RES_CONFIG_SQLITE_NAME)) {
1634 if (cli_status_registered) {
1635 ast_cli_unregister_multiple(cli_status, ARRAY_LEN(cli_status));
1638 ast_config_engine_deregister(&sqlite_engine);
1649 * \brief Load the module
1651 * Module loading including tests for configuration or dependencies.
1652 * This function can return AST_MODULE_LOAD_FAILURE, AST_MODULE_LOAD_DECLINE,
1653 * or AST_MODULE_LOAD_SUCCESS. If a dependency or environment variable fails
1654 * tests return AST_MODULE_LOAD_FAILURE. If the module can not load the
1655 * configuration file or other non-critical problem return
1656 * AST_MODULE_LOAD_DECLINE. On success return AST_MODULE_LOAD_SUCCESS.
1658 static int load_module(void)
1660 char *errormsg = NULL;
1665 cli_status_registered = 0;
1667 config_table = NULL;
1669 error = load_config();
1672 return AST_MODULE_LOAD_DECLINE;
1674 if (!(db = sqlite_open(dbfile, 0660, &errormsg))) {
1675 ast_log(LOG_ERROR, "%s\n", S_OR(errormsg, sqlite_error_string(error)));
1676 sqlite_freemem(errormsg);
1681 sqlite_freemem(errormsg);
1683 ast_config_engine_register(&sqlite_engine);
1688 /* \cond DOXYGEN_CAN_PARSE_THIS */
1690 #define QUERY "SELECT COUNT(id) FROM %Q;"
1693 query = sqlite_mprintf(QUERY, cdr_table);
1696 ast_log(LOG_ERROR, "Unable to allocate SQL query\n");
1701 ast_debug(1, "SQL query: %s\n", query);
1703 RES_CONFIG_SQLITE_BEGIN
1704 error = sqlite_exec(db, query, NULL, NULL, &errormsg);
1705 RES_CONFIG_SQLITE_END(error)
1707 sqlite_freemem(query);
1713 if (error != SQLITE_ERROR) {
1714 ast_log(LOG_ERROR, "%s\n", S_OR(errormsg, sqlite_error_string(error)));
1715 sqlite_freemem(errormsg);
1720 sqlite_freemem(errormsg);
1722 query = sqlite_mprintf(sql_create_cdr_table, cdr_table);
1725 ast_log(LOG_ERROR, "Unable to allocate SQL query\n");
1730 ast_debug(1, "SQL query: %s\n", query);
1732 RES_CONFIG_SQLITE_BEGIN
1733 error = sqlite_exec(db, query, NULL, NULL, &errormsg);
1734 RES_CONFIG_SQLITE_END(error)
1736 sqlite_freemem(query);
1739 ast_log(LOG_ERROR, "%s\n", S_OR(errormsg, sqlite_error_string(error)));
1740 sqlite_freemem(errormsg);
1745 sqlite_freemem(errormsg);
1748 error = ast_cdr_register(RES_CONFIG_SQLITE_NAME, RES_CONFIG_SQLITE_DESCRIPTION, cdr_handler);
1758 error = ast_cli_register_multiple(cli_status, ARRAY_LEN(cli_status));
1765 cli_status_registered = 1;
1770 AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_LOAD_ORDER, "Realtime SQLite configuration",
1771 .load = load_module,
1772 .unload = unload_module,
1773 .load_pri = AST_MODPRI_REALTIME_DRIVER,