#include "asterisk.h"
#include <sqlite.h>
#include "asterisk/channel.h"
#include "asterisk/module.h"
#include "asterisk/utils.h"
#include "asterisk/paths.h"
Go to the source code of this file.
Defines | |
#define | DATE_FORMAT "%Y-%m-%d %T" |
#define | LOG_UNIQUEID 0 |
#define | LOG_USERFIELD 0 |
Functions | |
static void | __reg_module (void) |
static void | __unreg_module (void) |
static int | load_module (void) |
static int | sqlite_log (struct ast_cdr *cdr) |
static int | unload_module (void) |
Variables | |
static struct ast_module_info | __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_DEFAULT , .description = "SQLite CDR Backend" , .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 = "a9c98e5d177805051735cb5b0b16b0a0" , .load = load_module, .unload = unload_module, } |
static struct ast_module_info * | ast_module_info = &__mod_info |
static sqlite * | db = NULL |
static char * | name = "sqlite" |
static char | sql_create_table [] |
SQL table format. | |
static ast_mutex_t | sqlite_lock = ((ast_mutex_t) PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP ) |
Definition in file cdr_sqlite.c.
#define DATE_FORMAT "%Y-%m-%d %T" |
Definition at line 56 of file cdr_sqlite.c.
#define LOG_UNIQUEID 0 |
#define LOG_USERFIELD 0 |
static void __reg_module | ( | void | ) | [static] |
Definition at line 214 of file cdr_sqlite.c.
static void __unreg_module | ( | void | ) | [static] |
Definition at line 214 of file cdr_sqlite.c.
static int load_module | ( | void | ) | [static] |
Definition at line 170 of file cdr_sqlite.c.
References ast_cdr_register(), ast_config_AST_LOG_DIR, AST_FILE_MODE, ast_free, ast_log(), LOG_ERROR, LOG_WARNING, and sqlite_log().
00171 { 00172 char *zErr; 00173 char fn[PATH_MAX]; 00174 int res; 00175 00176 ast_log(LOG_WARNING, "This module has been marked deprecated in favor of " 00177 "using cdr_sqlite3_custom. (May be removed after Asterisk 1.6)\n"); 00178 00179 /* is the database there? */ 00180 snprintf(fn, sizeof(fn), "%s/cdr.db", ast_config_AST_LOG_DIR); 00181 db = sqlite_open(fn, AST_FILE_MODE, &zErr); 00182 if (!db) { 00183 ast_log(LOG_ERROR, "cdr_sqlite: %s\n", zErr); 00184 ast_free(zErr); 00185 return -1; 00186 } 00187 00188 /* is the table there? */ 00189 res = sqlite_exec(db, "SELECT COUNT(AcctId) FROM cdr;", NULL, NULL, NULL); 00190 if (res) { 00191 res = sqlite_exec(db, sql_create_table, NULL, NULL, &zErr); 00192 if (res) { 00193 ast_log(LOG_ERROR, "cdr_sqlite: Unable to create table 'cdr': %s\n", zErr); 00194 ast_free(zErr); 00195 goto err; 00196 } 00197 00198 /* TODO: here we should probably create an index */ 00199 } 00200 00201 res = ast_cdr_register(name, ast_module_info->description, sqlite_log); 00202 if (res) { 00203 ast_log(LOG_ERROR, "Unable to register SQLite CDR handling\n"); 00204 return -1; 00205 } 00206 return 0; 00207 00208 err: 00209 if (db) 00210 sqlite_close(db); 00211 return -1; 00212 }
static int sqlite_log | ( | struct ast_cdr * | cdr | ) | [static] |
Definition at line 90 of file cdr_sqlite.c.
References ast_cdr::accountcode, ast_cdr::amaflags, ast_cdr::answer, ast_free, ast_localtime(), ast_log(), ast_mutex_lock(), ast_mutex_unlock(), ast_strftime(), ast_cdr::billsec, ast_cdr::channel, ast_cdr::clid, DATE_FORMAT, ast_cdr::dcontext, ast_cdr::disposition, ast_cdr::dst, ast_cdr::dstchannel, ast_cdr::duration, ast_cdr::end, ast_cdr::lastapp, ast_cdr::lastdata, LOG_ERROR, LOG_UNIQUEID, LOG_USERFIELD, sqlite_lock, ast_cdr::src, ast_cdr::start, ast_cdr::uniqueid, and ast_cdr::userfield.
Referenced by load_module().
00091 { 00092 int res = 0; 00093 char *zErr = 0; 00094 struct ast_tm tm; 00095 char startstr[80], answerstr[80], endstr[80]; 00096 int count; 00097 00098 ast_mutex_lock(&sqlite_lock); 00099 00100 ast_localtime(&cdr->start, &tm, NULL); 00101 ast_strftime(startstr, sizeof(startstr), DATE_FORMAT, &tm); 00102 00103 ast_localtime(&cdr->answer, &tm, NULL); 00104 ast_strftime(answerstr, sizeof(answerstr), DATE_FORMAT, &tm); 00105 00106 ast_localtime(&cdr->end, &tm, NULL); 00107 ast_strftime(endstr, sizeof(endstr), DATE_FORMAT, &tm); 00108 00109 for(count=0; count<5; count++) { 00110 res = sqlite_exec_printf(db, 00111 "INSERT INTO cdr (" 00112 "clid,src,dst,dcontext," 00113 "channel,dstchannel,lastapp,lastdata, " 00114 "start,answer,end," 00115 "duration,billsec,disposition,amaflags, " 00116 "accountcode" 00117 # if LOG_UNIQUEID 00118 ",uniqueid" 00119 # endif 00120 # if LOG_USERFIELD 00121 ",userfield" 00122 # endif 00123 ") VALUES (" 00124 "'%q', '%q', '%q', '%q', " 00125 "'%q', '%q', '%q', '%q', " 00126 "'%q', '%q', '%q', " 00127 "%d, %d, %d, %d, " 00128 "'%q'" 00129 # if LOG_UNIQUEID 00130 ",'%q'" 00131 # endif 00132 # if LOG_USERFIELD 00133 ",'%q'" 00134 # endif 00135 ")", NULL, NULL, &zErr, 00136 cdr->clid, cdr->src, cdr->dst, cdr->dcontext, 00137 cdr->channel, cdr->dstchannel, cdr->lastapp, cdr->lastdata, 00138 startstr, answerstr, endstr, 00139 cdr->duration, cdr->billsec, cdr->disposition, cdr->amaflags, 00140 cdr->accountcode 00141 # if LOG_UNIQUEID 00142 ,cdr->uniqueid 00143 # endif 00144 # if LOG_USERFIELD 00145 ,cdr->userfield 00146 # endif 00147 ); 00148 if (res != SQLITE_BUSY && res != SQLITE_LOCKED) 00149 break; 00150 usleep(200); 00151 } 00152 00153 if (zErr) { 00154 ast_log(LOG_ERROR, "cdr_sqlite: %s\n", zErr); 00155 ast_free(zErr); 00156 } 00157 00158 ast_mutex_unlock(&sqlite_lock); 00159 return res; 00160 }
static int unload_module | ( | void | ) | [static] |
Definition at line 162 of file cdr_sqlite.c.
References ast_cdr_unregister().
00163 { 00164 if (db) 00165 sqlite_close(db); 00166 ast_cdr_unregister(name); 00167 return 0; 00168 }
struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_DEFAULT , .description = "SQLite CDR Backend" , .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 = "a9c98e5d177805051735cb5b0b16b0a0" , .load = load_module, .unload = unload_module, } [static] |
Definition at line 214 of file cdr_sqlite.c.
struct ast_module_info* ast_module_info = &__mod_info [static] |
Definition at line 214 of file cdr_sqlite.c.
sqlite* db = NULL [static] |
Definition at line 59 of file cdr_sqlite.c.
Referenced by ast_config_internal_load(), ast_destroy_realtime(), ast_load_realtime_helper(), ast_load_realtime_multientry(), ast_realtime_require_field(), ast_store_realtime(), ast_unload_realtime(), and ast_update_realtime().
char* name = "sqlite" [static] |
Definition at line 58 of file cdr_sqlite.c.
char sql_create_table[] [static] |
ast_mutex_t sqlite_lock = ((ast_mutex_t) PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP ) [static] |