Asterisk - The Open Source Telephony Project  18.5.0
Data Structures | Functions | Variables
cdr_sqlite3_custom.c File Reference

Custom SQLite3 CDR records. More...

#include "asterisk.h"
#include <sqlite3.h>
#include "asterisk/paths.h"
#include "asterisk/channel.h"
#include "asterisk/cdr.h"
#include "asterisk/module.h"
#include "asterisk/config.h"
#include "asterisk/pbx.h"
#include "asterisk/utils.h"
#include "asterisk/cli.h"
#include "asterisk/app.h"
Include dependency graph for cdr_sqlite3_custom.c:

Go to the source code of this file.

Data Structures

struct  sql_values
 
struct  values
 

Functions

static void free_config (int reload)
 
static int load_column_config (const char *tmp)
 
static int load_values_config (const char *tmp)
 

Variables

static int busy_timeout
 
static char * columns
 
static const char config_file [] = "cdr_sqlite3_custom.conf"
 
static sqlite3 * db = NULL
 
static const char desc [] = "Customizable SQLite3 CDR Backend"
 
static ast_mutex_t lock = { PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP , NULL, {1, 0} }
 
static const char name [] = "cdr_sqlite3_custom"
 
static struct sql_values sql_values = { .first = NULL, .last = NULL, .lock = { PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP , NULL, {1, 0} } , }
 
static char table [80]
 

Detailed Description

Custom SQLite3 CDR records.

Author
Adapted by Alejandro Rios aleja.nosp@m.ndro.nosp@m..rios.nosp@m.@ava.nosp@m.tar.c.nosp@m.om.c.nosp@m.o and Russell Bryant russe.nosp@m.ll@d.nosp@m.igium.nosp@m..com from cdr_mysql_custom by Edward Eastman ed@dm.nosp@m.3.co.nosp@m..uk, and cdr_sqlite by Holger Schurig hs423.nosp@m.3@ma.nosp@m.il.mn.nosp@m.-sol.nosp@m.ution.nosp@m.s.de

Definition in file cdr_sqlite3_custom.c.

Function Documentation

◆ free_config()

static void free_config ( int  reload)
static

Referenced by load_values_config().

◆ load_column_config()

static int load_column_config ( const char *  tmp)
static

Definition at line 75 of file cdr_sqlite3_custom.c.

References ast_free, ast_log, ast_str_append(), ast_str_buffer(), ast_str_create, ast_str_strlen(), ast_strdup, ast_strip(), ast_strlen_zero, LOG_ERROR, LOG_WARNING, NULL, strsep(), and table.

Referenced by load_values_config().

76 {
77  char *col = NULL;
78  char *cols = NULL, *save = NULL;
79  char *escaped = NULL;
80  struct ast_str *column_string = NULL;
81 
82  if (ast_strlen_zero(tmp)) {
83  ast_log(LOG_WARNING, "Column names not specified. Module not loaded.\n");
84  return -1;
85  }
86  if (!(column_string = ast_str_create(1024))) {
87  ast_log(LOG_ERROR, "Out of memory creating temporary buffer for column list for table '%s.'\n", table);
88  return -1;
89  }
90  if (!(save = cols = ast_strdup(tmp))) {
91  ast_log(LOG_ERROR, "Out of memory creating temporary buffer for column list for table '%s.'\n", table);
92  ast_free(column_string);
93  return -1;
94  }
95  while ((col = strsep(&cols, ","))) {
96  col = ast_strip(col);
97  escaped = sqlite3_mprintf("%q", col);
98  if (!escaped) {
99  ast_log(LOG_ERROR, "Out of memory creating entry for column '%s' in table '%s.'\n", col, table);
100  ast_free(column_string);
101  ast_free(save);
102  return -1;
103  }
104  ast_str_append(&column_string, 0, "%s%s", ast_str_strlen(column_string) ? "," : "", escaped);
105  sqlite3_free(escaped);
106  }
107  if (!(columns = ast_strdup(ast_str_buffer(column_string)))) {
108  ast_log(LOG_ERROR, "Out of memory copying columns string for table '%s.'\n", table);
109  ast_free(column_string);
110  ast_free(save);
111  return -1;
112  }
113  ast_free(column_string);
114  ast_free(save);
115 
116  return 0;
117 }
#define LOG_WARNING
Definition: logger.h:274
char * ast_str_buffer(const struct ast_str *buf)
Returns the string buffer within the ast_str buf.
Definition: strings.h:714
static int tmp()
Definition: bt_open.c:389
int ast_str_append(struct ast_str **buf, ssize_t max_len, const char *fmt,...)
Append to a thread local dynamic string.
Definition: strings.h:1091
#define ast_strdup(str)
A wrapper for strdup()
Definition: astmm.h:243
#define NULL
Definition: resample.c:96
#define ast_strlen_zero(foo)
Definition: strings.h:52
#define ast_log
Definition: astobj2.c:42
char * ast_strip(char *s)
Strip leading/trailing whitespace from a string.
Definition: strings.h:219
static char table[80]
#define LOG_ERROR
Definition: logger.h:285
The descriptor of a dynamic string XXX storage will be optimized later if needed We use the ts field ...
Definition: strings.h:584
#define ast_free(a)
Definition: astmm.h:182
size_t ast_str_strlen(const struct ast_str *buf)
Returns the current length of the string stored within buf.
Definition: strings.h:688
char * strsep(char **str, const char *delims)
#define ast_str_create(init_len)
Create a malloc&#39;ed dynamic length string.
Definition: strings.h:620

◆ load_values_config()

static int load_values_config ( const char *  tmp)
static

Variable Documentation

◆ busy_timeout

int busy_timeout
static

Definition at line 64 of file cdr_sqlite3_custom.c.

Referenced by load_values_config().

◆ columns

char* columns
static

Definition at line 63 of file cdr_sqlite3_custom.c.

◆ config_file

const char config_file[] = "cdr_sqlite3_custom.conf"
static

Definition at line 56 of file cdr_sqlite3_custom.c.

Referenced by load_values_config().

◆ db

sqlite3* db = NULL
static

◆ desc

const char desc[] = "Customizable SQLite3 CDR Backend"
static

Definition at line 58 of file cdr_sqlite3_custom.c.

Referenced by load_values_config().

◆ lock

ast_mutex_t lock = { PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP , NULL, {1, 0} }
static

Definition at line 54 of file cdr_sqlite3_custom.c.

Referenced by load_values_config().

◆ name

const char name[] = "cdr_sqlite3_custom"
static

Definition at line 59 of file cdr_sqlite3_custom.c.

Referenced by load_values_config().

◆ sql_values

struct sql_values sql_values = { .first = NULL, .last = NULL, .lock = { PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP , NULL, {1, 0} } , }
static

◆ table

char table[80]
static

Definition at line 62 of file cdr_sqlite3_custom.c.

Referenced by load_column_config(), and load_values_config().