Wed Jan 8 2020 09:49:59

Asterisk developer's documentation


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"

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 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 }
 
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 } , }
 
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

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

Definition at line 76 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, and strsep().

77 {
78  char *col = NULL;
79  char *cols = NULL, *save = NULL;
80  char *escaped = NULL;
81  struct ast_str *column_string = NULL;
82 
83  if (ast_strlen_zero(tmp)) {
84  ast_log(LOG_WARNING, "Column names not specified. Module not loaded.\n");
85  return -1;
86  }
87  if (!(column_string = ast_str_create(1024))) {
88  ast_log(LOG_ERROR, "Out of memory creating temporary buffer for column list for table '%s.'\n", table);
89  return -1;
90  }
91  if (!(save = cols = ast_strdup(tmp))) {
92  ast_log(LOG_ERROR, "Out of memory creating temporary buffer for column list for table '%s.'\n", table);
93  ast_free(column_string);
94  return -1;
95  }
96  while ((col = strsep(&cols, ","))) {
97  col = ast_strip(col);
98  escaped = sqlite3_mprintf("%q", col);
99  if (!escaped) {
100  ast_log(LOG_ERROR, "Out of memory creating entry for column '%s' in table '%s.'\n", col, table);
101  ast_free(column_string);
102  ast_free(save);
103  return -1;
104  }
105  ast_str_append(&column_string, 0, "%s%s", ast_str_strlen(column_string) ? "," : "", escaped);
106  sqlite3_free(escaped);
107  }
108  if (!(columns = ast_strdup(ast_str_buffer(column_string)))) {
109  ast_log(LOG_ERROR, "Out of memory copying columns string for table '%s.'\n", table);
110  ast_free(column_string);
111  ast_free(save);
112  return -1;
113  }
114  ast_free(column_string);
115  ast_free(save);
116 
117  return 0;
118 }
char * strsep(char **str, const char *delims)
#define ast_strdup(a)
Definition: astmm.h:109
#define LOG_WARNING
Definition: logger.h:144
char * ast_str_buffer(const struct ast_str *buf)
Returns the string buffer within the ast_str buf.
Definition: strings.h:497
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:900
struct ast_str * ast_str_create(size_t init_len)
Create a malloc&#39;ed dynamic length string.
Definition: strings.h:420
static force_inline int attribute_pure ast_strlen_zero(const char *s)
Definition: strings.h:63
char * ast_strip(char *s)
Strip leading/trailing whitespace from a string.
Definition: strings.h:155
static char table[80]
#define LOG_ERROR
Definition: logger.h:155
The descriptor of a dynamic string XXX storage will be optimized later if needed We use the ts field ...
Definition: strings.h:364
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...
Definition: logger.c:1207
#define ast_free(a)
Definition: astmm.h:97
size_t ast_str_strlen(const struct ast_str *buf)
Returns the current length of the string stored within buf.
Definition: strings.h:471

Variable Documentation

char* columns
static

Definition at line 65 of file cdr_sqlite3_custom.c.

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

Definition at line 58 of file cdr_sqlite3_custom.c.

sqlite3* db = NULL
static

Definition at line 62 of file cdr_sqlite3_custom.c.

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

Definition at line 60 of file cdr_sqlite3_custom.c.

ast_mutex_t lock = { PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP , NULL, 1 }
static

Definition at line 56 of file cdr_sqlite3_custom.c.

const char name[] = "cdr_sqlite3_custom"
static

Definition at line 61 of file cdr_sqlite3_custom.c.

struct sql_values sql_values = { .first = NULL, .last = NULL, .lock = { PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP , NULL, 1 } , }
static
char table[80]
static

Definition at line 64 of file cdr_sqlite3_custom.c.