69 [
cdrel_record_cel] =
"CSV_QUOTE CALLERID CHANNEL eventtype eventtime eventenum userdeftype eventextra BRIDGEPEER",
74 [
cdrel_record_cel] =
"eventtype eventtime eventenum userdeftype eventextra BRIDGEPEER",
97 char *tmp_field =
NULL;
104 if (input_field_template[0] ==
'"') {
117 if (tmp_field[0] ==
'\'') {
138 while (tmp_field[0] ==
'$') {
176 ptr = strchr(tmp_field,
'(');
196 result.unknown_functions++;
203 if (strcmp(
"CSV_QUOTE", func_name) == 0) {
205 }
else if (strcmp(
"CDR", func_name) == 0) {
217 if (tmp_field[0] ==
'"' || tmp_field[0] ==
'\'') {
230 if (
result.parse_failed) {
231 tmp_field = input_field_template;
237 if (
result.functions == 0) {
266 const char *output_filename,
const char *input_template,
struct ast_vector_string *fields)
269 char *field_template =
NULL;
282 ast_debug(2,
"field: '%s' literal: %d quote: %d cdr: %d failed: %d funcs: %d unknfuncs: %d\n",
result.result,
294 literal =
"literal^";
305 uservar =
"uservar^";
307 literal =
"literal^";
313 if (!field_template || res < 0) {
322 ast_debug(2,
" field template: %s\n", field_template);
341 char *field_name =
NULL;
343 char *tmp_data =
NULL;
344 char *closeparen =
NULL;
345 char *qualifier =
NULL;
356 rtn_field =
ast_calloc(1,
sizeof(*field) + strlen(input_field_template) + 1);
360 memcpy(rtn_field, registered_field,
sizeof(*registered_field));
361 strcpy(rtn_field->
data, input_field_template);
369 if (input_field_template[0] ==
'"' || input_field_template[0] ==
'\'') {
372 ast_debug(3,
" Using qualifier 'literal' for field '%s' flags: %s\n", data,
374 field_name =
"literal";
377 data = strchr(field_name,
'(');
382 closeparen = strchr(data,
')');
390 char *data_swap =
NULL;
403 ast_debug(3,
" Using qualifier '%s' for field '%s' flags: %s\n", qualifier,
406 field_name =
"uservar";
409 ast_debug(3,
" Using qualifier '%s' for field '%s' flags: %s\n", qualifier,
412 field_name =
"literal";
414 forced_output_data_type = fodt;
415 ast_debug(3,
" Using qualifier '%s' for field '%s' flags: %s\n", qualifier,
420 if (strcasecmp(qualifier,
"quote") == 0) {
422 ast_debug(3,
" Using qualifier '%s' for field '%s' flags: %s\n", qualifier,
426 if (strcasecmp(qualifier,
"noquote") == 0) {
428 ast_debug(3,
" Using qualifier '%s' for field '%s' flags: %s\n", qualifier,
432 if (strchr(qualifier,
'%') !=
NULL) {
436 ast_debug(3,
" Using qualifier '%s' for field '%s' flags: %s\n", qualifier,
442 config->config_filename,
config->output_filename, field_name, data);
453 ast_log(
LOG_WARNING,
"%s->%s: Literal field '%s' must be formatted as \"name: value\" when using the 'json' format\n",
455 input_field_template);
464 if (!registered_field) {
473 " Only timeval types can use custom format strings.\n",
481 field =
ast_calloc(1,
sizeof(*registered_field) + strlen(input_field_template) + 1);
485 memcpy(field, registered_field,
sizeof(*field));
488 strcpy(field->data, data);
496 field->name = field->data;
510 char *ptr = strchr(data,
':');
521 ptr = field->data + strlen(field->data);
540 field->output_data_type = forced_output_data_type;
542 field->flags = field_flags;
565 ast_debug(2,
"%s->%s: Field '%s' processed -> name:'%s' input_type:%s output_type:%s flags:'%s' data:'%s'\n",
625 sqlite3_finalize(
config->insert);
630 sqlite3_close(
config->db);
657 const char *
config_filename,
const char *output_filename,
const char *
template)
661 const char *file_suffix =
"";
675 config->record_type = record_type;
676 config->backend_type = backend_type;
678 config->config_type = config_type;
682 config->separator[0] =
',';
683 switch(backend_type) {
708 if (output_filename[0] ==
'/') {
711 const char *subdir =
dirname_map[backend_type][record_type];
754 if (
ast_str_append(&column_string, 0,
"%s%s", *column_count ?
"," :
"", col) <= 0) {
792 char *placeholders =
NULL;
796 res = sqlite3_open(
config->output_filename, &
config->db);
797 if (res != SQLITE_OK) {
806 sql = sqlite3_mprintf(
"SELECT COUNT(*) FROM %q;",
config->db_table);
812 if (res != SQLITE_OK) {
817 sql = sqlite3_mprintf(
"CREATE TABLE %q (AcctId INTEGER PRIMARY KEY, %s)",
821 if (res != SQLITE_OK) {
832 sqlite3_stmt *get_stmt;
833 int existing_columns = 0;
836 sql = sqlite3_mprintf(
"SELECT * FROM %q;",
config->db_table);
840 res = sqlite3_prepare_v2(
config->db, sql, -1, &get_stmt,
NULL);
842 if (res != SQLITE_OK) {
852 existing_columns = sqlite3_column_count(get_stmt);
853 sqlite3_finalize(get_stmt);
855 if ((config_columns + 1) != existing_columns) {
856 ast_log(
LOG_WARNING,
"%s->%s: The number of fields in the config (%d) doesn't equal the"
857 " nummber of data columns (%d) in the existing %s table. This config is disabled.\n",
859 config_columns, existing_columns - 1,
config->db_table);
870 sql = sqlite3_mprintf(
"INSERT INTO %q VALUES (NULL,%s)",
config->db_table, placeholders);
876 res = sqlite3_prepare_v3(
config->db, sql, -1, SQLITE_PREPARE_PERSISTENT, &
config->insert,
NULL);
877 if (res != SQLITE_OK) {
880 sql, sqlite3_errmsg(
config->db));
903 int column_count = 0;
905 int field_check_passed = 0;
909 char *tmp_fields =
NULL;
937 category_name,
template, field_templates);
938 if (field_check_passed) {
944 ast_log(
LOG_NOTICE,
"%s->%s: Unable to upgrade legacy config to advanced. Continuing to process as legacy\n",
970 config->busy_timeout = 1000;
981 ast_log(
LOG_WARNING,
"%s->%s: Invalid busy_timeout value '%s' specified. Using 1000 instead.\n",
1008 if (value_count != column_count) {
1011 column_count, value_count);
1051 ast_log(
LOG_ERROR,
"Unable to load %s. Not logging %ss to custom database\n",
1095 int field_check_passed = 0;
1114 if (!field_check_passed) {
1130 config->quote_escape[0] =
'"';
1131 config->separator[0] =
',';
1167 char *tmp_fields =
NULL;
1183 config->separator[0] =
',';
1185 config->quote_escape[0] =
'\\';
1281 ast_log(
LOG_WARNING,
"%s: %s mapping must have both a filename and a template at line %d\n",
1379 struct cdrel_configs *
configs,
const char *filename,
int reload)
1381 switch(output_type) {
1392 struct cdrel_configs **
configs,
const char *filename)
1395 struct cdrel_configs *old_configs = *
configs;
1396 struct cdrel_configs *new_configs =
NULL;
1402 new_configs =
ast_malloc(
sizeof(*new_configs));
1411 res =
load_config_file(output_type, record_type, new_configs, filename, 1);
1432 enum cdrel_record_type record_type,
const char *filename,
const char *backend_name,
1460 struct cdrel_configs *
configs,
const char *backend_name)
#define ast_strdup(str)
A wrapper for strdup()
#define ast_strdupa(s)
duplicate a string in memory from the stack
#define ast_asprintf(ret, fmt,...)
A wrapper for asprintf()
#define ast_calloc(num, len)
A wrapper for calloc()
#define ast_malloc(len)
A wrapper for malloc()
int ast_cdr_unregister(const char *name)
Unregister a CDR handling engine.
int ast_cdr_register(const char *name, const char *desc, ast_cdrbe be)
Register a CDR handling engine.
Private header for res_cdrel_custom.
const char * cdrel_basename(const char *path)
const struct cdrel_field * get_registered_field_by_name(enum cdrel_record_type record_type, const char *name)
enum cdrel_data_type cdrel_data_type_from_str(const char *str)
#define DATA_TYPE_STR(_dt)
#define MODULE_TYPE_STR(_mt)
@ cdrel_data_type_strings_end
@ cdrel_quoting_method_all
@ cdrel_quoting_method_none
@ cdrel_quoting_method_non_numeric
@ cdrel_quoting_method_minimal
#define RECORD_TYPE_STR(_rt)
cdrel_dummy_channel_alloc cdrel_dummy_channel_allocators[cdrel_format_type_end]
const char * cdrel_get_field_flags(struct ast_flags *flags, struct ast_str **str)
int ast_cel_backend_unregister(const char *name)
Unregister a CEL backend.
int ast_cel_backend_register(const char *name, ast_cel_backend_cb backend_callback)
Register a CEL backend.
static const char config[]
static char * config_filename
Configuration File Parser.
#define ast_config_load(filename, flags)
Load a config file.
const char * ast_category_get_name(const struct ast_category *category)
Return the name of the category.
#define CONFIG_STATUS_FILEUNCHANGED
@ CONFIG_FLAG_FILEUNCHANGED
#define CONFIG_STATUS_FILEINVALID
int ast_parse_arg(const char *arg, enum ast_parse_flags flags, void *p_result,...)
The argument parsing routine.
void ast_config_destroy(struct ast_config *cfg)
Destroys a config.
struct ast_variable * ast_category_first(struct ast_category *cat)
given a pointer to a category, return the root variable.
const char * ast_variable_find(const struct ast_category *category, const char *variable)
Gets a variable value from a specific category structure by name.
struct ast_category * ast_category_browse_filtered(struct ast_config *config, const char *category_name, struct ast_category *prev, const char *filter)
Browse categories with filters.
#define ast_debug(level,...)
Log a DEBUG message.
#define ast_mutex_init(pmutex)
#define ast_mutex_destroy(a)
Asterisk module definitions.
@ AST_MODULE_LOAD_SUCCESS
@ AST_MODULE_LOAD_DECLINE
Module has failed to load, may be in an inconsistent state.
Asterisk file paths, configured in asterisk.conf.
const char * ast_config_AST_LOG_DIR
static const char * special_vars[]
static void config_free(struct cdrel_config *config)
static struct cdrel_config * load_database_config(enum cdrel_record_type record_type, struct ast_category *category, const char *config_filename)
static int unregister_backend(enum cdrel_record_type record_type, const char *backend_name)
static struct cdrel_config * load_text_file_legacy_config(enum cdrel_record_type record_type, const char *config_filename, const char *output_filename, const char *template)
static struct field_parse_result parse_field(enum cdrel_record_type record_type, char *input_field_template)
static void field_template_vector_free(struct ast_vector_string *fields)
static int load_fields(struct cdrel_config *config, struct ast_vector_string *fields)
static struct cdrel_field * field_alloc(struct cdrel_config *config, const char *input_field_template)
static int register_backend(enum cdrel_record_type record_type, const char *backend_name, void *log_cb)
static int load_text_file_legacy_mappings(enum cdrel_record_type record_type, struct cdrel_configs *configs, struct ast_category *category, const char *config_filename)
static int open_database(struct cdrel_config *config)
int cdrel_reload_module(enum cdrel_backend_type output_type, enum cdrel_record_type record_type, struct cdrel_configs **configs, const char *filename)
Perform module reload.
static int load_config_file(enum cdrel_backend_type output_type, enum cdrel_record_type record_type, struct cdrel_configs *configs, const char *filename, int reload)
static int load_database_config_file(enum cdrel_record_type record_type, struct cdrel_configs *configs, const char *config_filename, int reload)
int cdrel_unload_module(enum cdrel_backend_type backend_type, enum cdrel_record_type record_type, struct cdrel_configs *configs, const char *backend_name)
Perform module unload.
struct cdrel_configs * cdrel_load_module(enum cdrel_backend_type backend_type, enum cdrel_record_type record_type, const char *filename, const char *backend_name, void *log_cb)
Perform initial module load.
static const char * dirname_map[cdrel_backend_type_end][cdrel_record_type_end]
static char * make_stmt_placeholders(int columns)
static struct cdrel_config * load_text_file_advanced_config(enum cdrel_record_type record_type, struct ast_category *category, const char *config_filename)
static int parse_legacy_template(enum cdrel_record_type record_type, const char *config_filename, const char *output_filename, const char *input_template, struct ast_vector_string *fields)
static int load_text_file_config_file(enum cdrel_record_type record_type, struct cdrel_configs *configs, const char *config_filename, int reload)
static int load_database_columns(struct cdrel_config *config, const char *columns, int *column_count)
static const char * allowed_functions[]
#define ast_calloc_with_stringfields(n, type, size)
Allocate a structure with embedded stringfields in a single allocation.
#define ast_string_field_set(x, field, data)
Set a field to a simple string value.
#define ast_string_field_build(x, field, fmt, args...)
Set a field to a complex (built) value.
#define ast_string_field_free_memory(x)
free all memory - to be called before destroying the object
int ast_str_append(struct ast_str **buf, ssize_t max_len, const char *fmt,...)
Append to a thread local dynamic string.
int ast_strings_equal(const char *str1, const char *str2)
Compare strings for equality checking for NULL.
#define S_OR(a, b)
returns the equivalent of logic or for strings: first one if not empty, otherwise second one.
char * ast_unescape_c(char *s)
Convert some C escape sequences.
static int force_inline attribute_pure ast_ends_with(const char *str, const char *suffix)
Checks whether a string ends with another.
static force_inline int attribute_pure ast_strlen_zero(const char *s)
#define ast_str_tmp(init_len, __expr)
Provides a temporary ast_str and returns a copy of its buffer.
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_str_create(init_len)
Create a malloc'ed dynamic length string.
char *attribute_pure ast_str_buffer(const struct ast_str *buf)
Returns the string buffer within the ast_str buf.
void ast_copy_string(char *dst, const char *src, size_t size)
Size-limited null-terminating string copy.
char * ast_strip(char *s)
Strip leading/trailing whitespace from a string.
char * ast_strsep(char **s, const char sep, uint32_t flags)
Act like strsep but ignore separators inside quotes.
Structure used to handle boolean flags.
Support for dynamic strings.
Structure for variables, used for configurations and for channel variables.
struct ast_variable * next
String vector definitions.
struct cdrel_config::@455 fields
const ast_string_field output_filename
enum cdrel_record_type record_type
enum cdrel_data_type input_data_type
static struct prometheus_general_config * config_alloc(void)
#define ast_test_flag(p, flag)
#define RAII_VAR(vartype, varname, initval, dtor)
Declare a variable that will call a destructor function when it goes out of scope.
#define ast_clear_flag(p, flag)
#define ast_set_flag(p, flag)
#define AST_VECTOR_RESET(vec, cleanup)
Reset vector.
#define AST_VECTOR_SIZE(vec)
Get the number of elements in a vector.
#define AST_VECTOR_FREE(vec)
Deallocates this vector.
#define AST_VECTOR_PTR_FREE(vec)
Deallocates this vector pointer.
#define AST_VECTOR_INIT(vec, size)
Initialize a vector.
#define AST_VECTOR_APPEND(vec, elem)
Append an element to a vector, growing the vector if needed.
#define AST_VECTOR_GET(vec, idx)
Get an element from a vector.