Asterisk - The Open Source Telephony Project GIT-master-80b953f
Loading...
Searching...
No Matches
Functions | Variables
res_cdrel_custom.c File Reference

Common logic for the CDR and CEL Custom Backends. More...

#include "asterisk.h"
#include "asterisk/module.h"
#include "cdrel_custom/cdrel.h"
Include dependency graph for res_cdrel_custom.c:

Go to the source code of this file.

Functions

static void __reg_module (void)
 
static void __unreg_module (void)
 
struct ast_moduleAST_MODULE_SELF_SYM (void)
 
const char * cdrel_basename (const char *path)
 
enum cdrel_data_type cdrel_data_type_from_str (const char *str)
 
const char * cdrel_get_field_flags (struct ast_flags *flags, struct ast_str **str)
 
static enum ast_module_load_result load_module (void)
 
static int unload_module (void)
 

Variables

static struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_GLOBAL_SYMBOLS | AST_MODFLAG_LOAD_ORDER , .description = "Combined logic for CDR/CEL Custom modules" , .key = ASTERISK_GPL_KEY , .buildopt_sum = AST_BUILDOPT_SUM, .support_level = AST_MODULE_SUPPORT_CORE, .load = load_module, .unload = unload_module, .load_pri = AST_MODPRI_CDR_DRIVER, }
 
static const struct ast_module_infoast_module_info = &__mod_info
 
cdrel_backend_writer cdrel_backend_writers [cdrel_format_type_end]
 
const char * cdrel_data_type_map []
 
cdrel_dummy_channel_alloc cdrel_dummy_channel_allocators [cdrel_format_type_end]
 
static const char * cdrel_field_flags_map []
 
cdrel_field_formatter cdrel_field_formatters [cdrel_data_type_end]
 
cdrel_field_getter cdrel_field_getters [cdrel_record_type_end][cdrel_data_type_end]
 
const char * cdrel_module_type_map []
 
const char * cdrel_record_type_map []
 

Detailed Description

Common logic for the CDR and CEL Custom Backends.

Author
George Joseph gjose.nosp@m.ph@s.nosp@m.angom.nosp@m.a.co.nosp@m.m

All source files are in the res/cdrel_custom directory.

"config.c": Contains common configuration file parsing the ultimate goal of which is to create a vector of cdrel_config structures for each of the cdr_custom, cdr_sqlite3_custom, cel_custom and cel_sqlite3_custom modules. Each cdrel_config object represents an output file defined in their respective config files. Each one contains a vector of cdrel_field objects, one for each field in the output record, plus settings like the output file name, backend type (text file or database), config type ((legacy or advanced), the field separator and quote character to use.

Each cdrel_field object contains an abstract field id that points to a ast_cdr structure member or CEL event field id along with an input type and an output type. The registry of cdrel_fields is located in registry.c.

"loggers.c": Contains the common "cdrel_logger" entrypoint that the individual modules call to log a record. It takes the module's cdrel_configs vector and the record to log it got from the core cel.c and cdr.c. It then looks up and runs the logger implementation based on the backend type (text file or database) and config type (legacy or advanced).

"getters_cdr.c", "getters_cel.c": Contain the getters that retrieve values from the ast_cdr or ast_event structures based on the field id and input type defined for that field and create a cdrel_value wrapper object for it.

"writers.c": Contains common backend writers for the text file and database backends.

The load-time flow...

Each of the individual cdr/cel custom modules call the common cdrel_load_module function with their backend_type, record_type (cdr or cel), config file name, and the logging callback that should be registered with the core cdr or cel facility.

cdrel_load_module calls the config load function appropriate for the backend type, each of which parses the config file and, if successful, registers the calling module with the cdr or cel core and creates a vector of cdrel_config objects that is passed back to the calling module. That vector contains the context for all future operations.

The run-time flow...

The core cdr and cel modules use their registries of backends and call the callback function registered by the 4 cdr and cel custom modules. No changes there.

Each of those modules call the common cdrel_logger function with their cdrel_configs vector and the actual ast_cdr or ast_event structure to log. The cdrel_logger function iterates over the cdrel_configs vector and for each invokes the logger implementation specific to the backend type (text file or database) and config type (legacy or advanced).

For legacy config types, the logger implementation simply calls ast_str_substitute_variables() on the whole opaque format and writes the result to the text file or database.

For advanced configs, the logger implementation iterates over each field in the cdrel_config's fields vector and for each, calls the appropriate getter based on the record type (cdr or cel) and field id. Each getter call returns a cdrel_value object which is then passed to a field formatter looked up based on the field's data type (string, int32, etc). The formatter is also passed the cdrel_config object and the desired output type and returns the final value in another cdrel_value object formatted with any quoting, etc. needed. The logger accumulates the output cdrel_values (which are all now strings) in another vector and after all fields have been processed, hands the vector over to one of the backend writers.

The backend writer concatenates the cdrel_values into an output record using the config's separator setting and writes it to the text file or database. For the JSON output format, it creates a simple name/value pair output record.

The identification of field data types, field ids, record types and backend types is all done at config load time and saved in the cdrel_config and cdrel_field objects. The callbacks for getters, formatters and writers are also loaded when the res_cdrel_custom module loads and stored in arrays indexed by their enum values. The result is that at run time, simple array indexing is all that's needed to get the proper getter, formatter and writer for any logging request.

Definition in file res_cdrel_custom.c.

Function Documentation

◆ __reg_module()

static void __reg_module ( void  )
static

Definition at line 258 of file res_cdrel_custom.c.

◆ __unreg_module()

static void __unreg_module ( void  )
static

Definition at line 258 of file res_cdrel_custom.c.

◆ AST_MODULE_SELF_SYM()

struct ast_module * AST_MODULE_SELF_SYM ( void  )

Definition at line 258 of file res_cdrel_custom.c.

◆ cdrel_basename()

const char * cdrel_basename ( const char *  path)

Definition at line 219 of file res_cdrel_custom.c.

220{
221 int i = 0;
222 const char *basename = path;
223
224 if (ast_strlen_zero(path)) {
225 return path;
226 }
227 i = strlen(path) - 1;
228 while(i >= 0) {
229 if (path[i] == '/') {
230 basename = &path[i + 1];
231 break;
232 }
233 i--;
234 }
235 return basename;
236}
static force_inline int attribute_pure ast_strlen_zero(const char *s)
Definition strings.h:65

References ast_strlen_zero().

Referenced by config_alloc(), field_alloc(), format_string(), load_database_columns(), load_database_config(), load_fields(), load_text_file_advanced_config(), load_text_file_legacy_config(), load_text_file_legacy_mappings(), open_database(), and parse_legacy_template().

◆ cdrel_data_type_from_str()

enum cdrel_data_type cdrel_data_type_from_str ( const char *  str)

Definition at line 179 of file res_cdrel_custom.c.

180{
181 enum cdrel_data_type data_type = 0;
182 for (data_type = 0; data_type < cdrel_data_type_end; data_type++) {
183 if (strcasecmp(cdrel_data_type_map[data_type], str) == 0) {
184 return data_type;
185 }
186
187 }
188 return cdrel_data_type_end;
189}
const char * str
Definition app_jack.c:150
cdrel_data_type
Definition cdrel.h:72
@ cdrel_data_type_end
Definition cdrel.h:88
const char * cdrel_data_type_map[]

References cdrel_data_type_end, cdrel_data_type_map, and str.

Referenced by field_alloc().

◆ cdrel_get_field_flags()

const char * cdrel_get_field_flags ( struct ast_flags flags,
struct ast_str **  str 
)

Definition at line 201 of file res_cdrel_custom.c.

202{
203 int ix = 0;
204 int res = 0;
205 int trues = 0;
206
207 for (ix = 0; ix < CDREL_FIELD_FLAG_LAST; ix++) {
208 if (ast_test_flag(flags, (1 << ix))) {
209 res = ast_str_append(str, -1, "%s%s", trues++ ? "," : "", cdrel_field_flags_map[ix]);
210 if (res < 0) {
211 return "";
212 }
213 }
214 }
215 return ast_str_buffer(*str);
216}
#define CDREL_FIELD_FLAG_LAST
Definition cdrel.h:101
static const char * cdrel_field_flags_map[]
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:1139
char *attribute_pure ast_str_buffer(const struct ast_str *buf)
Returns the string buffer within the ast_str buf.
Definition strings.h:761
#define ast_test_flag(p, flag)
Definition utils.h:64

References ast_str_append(), ast_str_buffer(), ast_test_flag, CDREL_FIELD_FLAG_LAST, cdrel_field_flags_map, and str.

Referenced by field_alloc(), and format_string().

◆ load_module()

static enum ast_module_load_result load_module ( void  )
static

Definition at line 243 of file res_cdrel_custom.c.

244{
245 load_cdr();
246 load_cel();
248 load_writers();
250}
int load_cel(void)
int load_cdr(void)
int load_formatters(void)
Definition formatters.c:189
int load_writers(void)
Definition writers.c:221
@ AST_MODULE_LOAD_SUCCESS
Definition module.h:70

References AST_MODULE_LOAD_SUCCESS, load_cdr(), load_cel(), load_formatters(), and load_writers().

◆ unload_module()

static int unload_module ( void  )
static

Definition at line 238 of file res_cdrel_custom.c.

239{
240 return 0;
241}

Variable Documentation

◆ __mod_info

struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_GLOBAL_SYMBOLS | AST_MODFLAG_LOAD_ORDER , .description = "Combined logic for CDR/CEL Custom modules" , .key = ASTERISK_GPL_KEY , .buildopt_sum = AST_BUILDOPT_SUM, .support_level = AST_MODULE_SUPPORT_CORE, .load = load_module, .unload = unload_module, .load_pri = AST_MODPRI_CDR_DRIVER, }
static

Definition at line 258 of file res_cdrel_custom.c.

◆ ast_module_info

const struct ast_module_info* ast_module_info = &__mod_info
static

Definition at line 258 of file res_cdrel_custom.c.

◆ cdrel_backend_writers

Definition at line 137 of file res_cdrel_custom.c.

Referenced by load_writers(), and log_advanced_record().

◆ cdrel_data_type_map

const char* cdrel_data_type_map[]

Definition at line 160 of file res_cdrel_custom.c.

160 {
161 [cdrel_type_string] = "string",
162 [cdrel_type_timeval] = "timeval",
163 [cdrel_type_literal] = "literal",
164 [cdrel_type_amaflags] = "amaflags",
165 [cdrel_type_disposition] = "disposition",
166 [cdrel_type_uservar] = "uservar",
167 [cdrel_type_event_type] = "event_type",
168 [cdrel_type_event_enum] = "event_enum",
169 [cdrel_type_cel_timefmt] = "cel_timefmt",
170 [cdrel_data_type_strings_end] = "!!STRINGS END!!",
171 [cdrel_type_int32] = "int32",
172 [cdrel_type_uint32] = "uint32",
173 [cdrel_type_int64] = "int64",
174 [cdrel_type_uint64] = "uint64",
175 [cdrel_type_double] = "double",
176 [cdrel_data_type_end] = "!!END!!",
177};
@ cdrel_type_event_type
Definition cdrel.h:79
@ cdrel_data_type_strings_end
Definition cdrel.h:82
@ cdrel_type_cel_timefmt
Definition cdrel.h:81
@ cdrel_type_amaflags
Definition cdrel.h:76
@ cdrel_type_event_enum
Definition cdrel.h:80
@ cdrel_type_disposition
Definition cdrel.h:77
@ cdrel_type_uint64
Definition cdrel.h:86
@ cdrel_type_uservar
Definition cdrel.h:78
@ cdrel_type_double
Definition cdrel.h:87
@ cdrel_type_int64
Definition cdrel.h:85
@ cdrel_type_literal
Definition cdrel.h:75
@ cdrel_type_int32
Definition cdrel.h:83
@ cdrel_type_string
Definition cdrel.h:73
@ cdrel_type_timeval
Definition cdrel.h:74
@ cdrel_type_uint32
Definition cdrel.h:84

Referenced by cdrel_data_type_from_str().

◆ cdrel_dummy_channel_allocators

cdrel_dummy_channel_alloc cdrel_dummy_channel_allocators[cdrel_format_type_end]

Definition at line 142 of file res_cdrel_custom.c.

Referenced by config_alloc(), load_cdr(), and load_cel().

◆ cdrel_field_flags_map

const char* cdrel_field_flags_map[]
static

Definition at line 191 of file res_cdrel_custom.c.

191 {
192 [CDREL_FIELD_FLAG_QUOTE] = "quote",
193 [CDREL_FIELD_FLAG_NOQUOTE] = "noquote",
194 [CDREL_FIELD_FLAG_TYPE_FORCED] = "type_forced",
195 [CDREL_FIELD_FLAG_USERVAR] = "uservar",
196 [CDREL_FIELD_FLAG_LITERAL] = "literal",
197 [CDREL_FIELD_FLAG_FORMAT_SPEC] = "format_spec",
198 [CDREL_FIELD_FLAG_LAST] = "LAST",
199};
#define CDREL_FIELD_FLAG_USERVAR
Definition cdrel.h:98
#define CDREL_FIELD_FLAG_LITERAL
Definition cdrel.h:99
#define CDREL_FIELD_FLAG_TYPE_FORCED
Definition cdrel.h:97
#define CDREL_FIELD_FLAG_FORMAT_SPEC
Definition cdrel.h:100
#define CDREL_FIELD_FLAG_QUOTE
Definition cdrel.h:95
#define CDREL_FIELD_FLAG_NOQUOTE
Definition cdrel.h:96

Referenced by cdrel_get_field_flags().

◆ cdrel_field_formatters

cdrel_field_formatter cdrel_field_formatters[cdrel_data_type_end]

Definition at line 132 of file res_cdrel_custom.c.

Referenced by load_formatters(), and log_advanced_record().

◆ cdrel_field_getters

Definition at line 127 of file res_cdrel_custom.c.

Referenced by load_cdr(), load_cel(), and log_advanced_record().

◆ cdrel_module_type_map

const char* cdrel_module_type_map[]
Initial value:
= {
[cdrel_backend_text] = "Custom ",
[cdrel_backend_db] = "SQLITE3 Custom",
[cdrel_backend_type_end] = "!!END!!",
}
@ cdrel_backend_db
@ cdrel_backend_text
@ cdrel_backend_type_end

Definition at line 154 of file res_cdrel_custom.c.

154 {
155 [cdrel_backend_text] = "Custom ",
156 [cdrel_backend_db] = "SQLITE3 Custom",
157 [cdrel_backend_type_end] = "!!END!!",
158};

◆ cdrel_record_type_map

const char* cdrel_record_type_map[]
Initial value:
= {
[cdrel_record_cdr] = "CDR",
[cdrel_record_cel] = "CEL",
[cdrel_record_type_end] = "!!END!!",
}
@ cdrel_record_cel
@ cdrel_record_cdr
@ cdrel_record_type_end

Definition at line 148 of file res_cdrel_custom.c.

148 {
149 [cdrel_record_cdr] = "CDR",
150 [cdrel_record_cel] = "CEL",
151 [cdrel_record_type_end] = "!!END!!",
152};