60 static const char desc[] =
"Customizable SQLite3 CDR Backend";
61 static const char name[] =
"cdr_sqlite3_custom";
62 static sqlite3 *
db = NULL;
79 char *cols = NULL, *save = NULL;
81 struct ast_str *column_string = NULL;
88 ast_log(
LOG_ERROR,
"Out of memory creating temporary buffer for column list for table '%s.'\n", table);
92 ast_log(
LOG_ERROR,
"Out of memory creating temporary buffer for column list for table '%s.'\n", table);
96 while ((col =
strsep(&cols,
","))) {
98 escaped = sqlite3_mprintf(
"%q", col);
100 ast_log(
LOG_ERROR,
"Out of memory creating entry for column '%s' in table '%s.'\n", col, table);
106 sqlite3_free(escaped);
109 ast_log(
LOG_ERROR,
"Out of memory copying columns string for table '%s.'\n", table);
122 char *vals = NULL, *save = NULL;
134 ast_log(
LOG_ERROR,
"Out of memory creating temporary buffer for value '%s'\n", tmp);
138 for (i = 0; i <
val.argc; i++) {
141 value =
ast_calloc(
sizeof(
char),
sizeof(*value) + strlen(v));
163 ast_log(
LOG_WARNING,
"Failed to %sload configuration file. %s\n", reload ?
"re" :
"", reload ?
"" :
"Module not activated.");
184 strcpy(table,
"cdr");
201 ast_verb(3,
"cdr_sqlite3_custom: Logging CDR records to table '%s' in 'master.db'\n", table);
227 static int write_cdr(
struct ast_cdr *cdr)
242 char subst_buf[2048];
249 ast_log(
LOG_ERROR,
"Unable to allocate channel for variable subsitution.\n");
257 escaped = sqlite3_mprintf(
"%q", subst_buf);
259 sqlite3_free(escaped);
261 sql = sqlite3_mprintf(
"INSERT INTO %q (%s) VALUES (%s)", table, columns,
ast_str_buffer(value_string));
267 if (sqlite3_exec(db, sql, NULL, NULL, &error) != SQLITE_OK) {
293 char filename[PATH_MAX];
303 res = sqlite3_open(filename, &db);
304 if (res != SQLITE_OK) {
309 sqlite3_busy_timeout(db, 1000);
311 sql = sqlite3_mprintf(
"SELECT COUNT(AcctId) FROM %q;", table);
312 res = sqlite3_exec(db, sql, NULL, NULL, NULL);
314 if (res != SQLITE_OK) {
316 sql = sqlite3_mprintf(
"CREATE TABLE %q (AcctId INTEGER PRIMARY KEY, %s)", table, columns);
317 res = sqlite3_exec(db, sql, NULL, NULL, &error);
319 if (res != SQLITE_OK) {
void pbx_substitute_variables_helper(struct ast_channel *c, const char *cp1, char *cp2, int count)
Main Channel structure associated with a channel.
Asterisk main include file. File version handling, generic pbx functions.
const char * ast_variable_retrieve(const struct ast_config *config, const char *category, const char *variable)
Gets a variable.
char * strsep(char **str, const char *delims)
#define ast_channel_unref(c)
Decrease channel reference count.
struct ast_variable * ast_variable_browse(const struct ast_config *config, const char *category)
Goes through variables.
char * ast_str_buffer(const struct ast_str *buf)
Returns the string buffer within the ast_str buf.
static void dummy(char *unused,...)
#define AST_DECLARE_APP_ARGS(name, arglist)
Declare a structure to hold an application's arguments.
Structure for variables, used for configurations and for channel variables.
static int load_values_config(const char *tmp)
struct ast_cdr * ast_cdr_dup(struct ast_cdr *cdr)
Duplicate a record.
Configuration File Parser.
int ast_str_append(struct ast_str **buf, ssize_t max_len, const char *fmt,...)
Append to a thread local dynamic string.
struct ast_str * ast_str_create(size_t init_len)
Create a malloc'ed dynamic length string.
#define ast_mutex_lock(a)
#define AST_MODULE_INFO(keystr, flags_to_set, desc, fields...)
static int load_module(void)
#define ast_verb(level,...)
void ast_config_destroy(struct ast_config *config)
Destroys a config.
#define CONFIG_STATUS_FILEMISSING
char * ast_strip_quoted(char *s, const char *beg_quotes, const char *end_quotes)
Strip leading/trailing whitespace and quotes from a string.
#define ast_debug(level,...)
Log a DEBUG message.
int ast_cdr_register(const char *name, const char *desc, ast_cdrbe be)
Register a CDR handling engine.
General Asterisk PBX channel definitions.
Asterisk file paths, configured in asterisk.conf.
static void free_config(int reload)
#define ast_config_load(filename, flags)
Load a config file.
static force_inline int attribute_pure ast_strlen_zero(const char *s)
static const char config_file[]
char * ast_strip(char *s)
Strip leading/trailing whitespace from a string.
#define AST_LIST_REMOVE_HEAD(head, field)
Removes and returns the head entry from a list.
Core PBX routines and definitions.
#define AST_LIST_HEAD_STATIC(name, type)
Defines a structure to be used to hold a list of specified type, statically initialized.
Responsible for call detail data.
#define AST_LIST_INSERT_TAIL(head, elm, field)
Appends a list entry to the tail of a list.
The descriptor of a dynamic string XXX storage will be optimized later if needed We use the ts field ...
void ast_log(int level, const char *file, int line, const char *function, const char *fmt,...)
Used for sending a log message This is the standard logger function. Probably the only way you will i...
static int load_config(void)
const char * ast_config_AST_LOG_DIR
#define AST_LIST_TRAVERSE(head, var, field)
Loops over (traverses) the entries in a list.
#define AST_LIST_ENTRY(type)
Declare a forward link structure inside a list entry.
Structure used to handle boolean flags.
size_t ast_str_strlen(const struct ast_str *buf)
Returns the current length of the string stored within buf.
Standard Command Line Interface.
void ast_copy_string(char *dst, const char *src, size_t size)
Size-limited null-terminating string copy.
Application convenience functions, designed to give consistent look and feel to Asterisk apps...
static int load_column_config(const char *tmp)
#define AST_STANDARD_RAW_ARGS(args, parse)
#define AST_APP_ARG(name)
Define an application argument.
#define CONFIG_STATUS_FILEINVALID
struct ast_channel * ast_dummy_channel_alloc(void)
Create a fake channel structure.
#define ASTERISK_GPL_KEY
The text the key() function should return.
Asterisk module definitions.
#define AST_MUTEX_DEFINE_STATIC(mutex)
void ast_cdr_unregister(const char *name)
Unregister a CDR handling engine.
#define ASTERISK_FILE_VERSION(file, version)
Register/unregister a source code file with the core.
#define CONFIG_STATUS_FILEUNCHANGED
#define ast_mutex_unlock(a)