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

Protected header for the CDR and CEL Custom Backends. More...

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Enumerations

enum  cdrel_backend_type { cdrel_backend_text = 0 , cdrel_backend_db , cdrel_backend_type_end }
 
enum  cdrel_record_type { cdrel_record_cdr = 0 , cdrel_record_cel , cdrel_record_type_end }
 

Functions

 AST_VECTOR (cdrel_configs, struct cdrel_config *)
 
struct cdrel_configs * cdrel_load_module (enum cdrel_backend_type backend_type, enum cdrel_record_type record_type, const char *config_filename, const char *backend_name, void *logging_cb)
 Perform initial module load.
 
int cdrel_logger (struct cdrel_configs *configs, void *data)
 Log a record. The module's logging_cb must call this.
 
int cdrel_reload_module (enum cdrel_backend_type backend_type, enum cdrel_record_type record_type, struct cdrel_configs **configs, const char *config_filename)
 Perform module 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.
 

Detailed Description

Protected header 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
Warning
This file should be included only by CDR and CEL backends.

Definition in file res_cdrel_custom.h.

Enumeration Type Documentation

◆ cdrel_backend_type

Enumerator
cdrel_backend_text 

Text file: DSV or JSON

cdrel_backend_db 

Database (currently only sqlite3)

cdrel_backend_type_end 

Sentinel

Definition at line 33 of file res_cdrel_custom.h.

33 {
34 cdrel_backend_text = 0, /*!< Text file: DSV or JSON */
35 cdrel_backend_db, /*!< Database (currently only sqlite3) */
36 cdrel_backend_type_end, /*!< Sentinel */
37};
@ cdrel_backend_db
@ cdrel_backend_text
@ cdrel_backend_type_end

◆ cdrel_record_type

Enumerator
cdrel_record_cdr 

Call Detail Records

cdrel_record_cel 

Channel Event Log records

cdrel_record_type_end 

Sentinel

Definition at line 40 of file res_cdrel_custom.h.

40 {
41 cdrel_record_cdr = 0, /*!< Call Detail Records */
42 cdrel_record_cel, /*!< Channel Event Log records */
43 cdrel_record_type_end, /*!< Sentinel */
44};
@ cdrel_record_cel
@ cdrel_record_cdr
@ cdrel_record_type_end

Function Documentation

◆ AST_VECTOR()

AST_VECTOR ( cdrel_configs  ,
struct cdrel_config  
)

◆ cdrel_load_module()

struct cdrel_configs * cdrel_load_module ( enum cdrel_backend_type  backend_type,
enum cdrel_record_type  record_type,
const char *  config_filename,
const char *  backend_name,
void *  logging_cb 
)

Perform initial module load.

Needs to be called by each "custom" module

Parameters
backend_typeOne of cdrel_backend_type.
record_typeOne of cdrel_record_type.
config_filenameThe config file name.
backend_nameThe name to register the backend as.
logging_cbThe logging callback to register with CDR or CEL.
Returns
A pointer to a VECTOR or config objects read from the config file.

Definition at line 1431 of file res/cdrel_custom/config.c.

1434{
1435 struct cdrel_configs *configs = ast_calloc(1, sizeof(*configs));
1436 if (!configs) {
1437 return NULL;
1438 }
1439 ast_debug(1, "Loading %s %s\n", RECORD_TYPE_STR(record_type), MODULE_TYPE_STR(backend_type));
1440
1441 if (AST_VECTOR_INIT(configs, 5) != 0) {
1442 cdrel_unload_module(backend_type, record_type, configs, backend_name);
1443 return NULL;
1444 }
1445
1446 if (load_config_file(backend_type, record_type, configs, filename, 0) != 0) {
1447 cdrel_unload_module(backend_type, record_type, configs, backend_name);
1448 return NULL;
1449 }
1450
1451 if (register_backend(record_type, backend_name, log_cb)) {
1452 cdrel_unload_module(backend_type, record_type, configs, backend_name);
1453 return NULL;
1454 }
1455
1456 return configs;
1457}
#define ast_calloc(num, len)
A wrapper for calloc()
Definition astmm.h:202
#define MODULE_TYPE_STR(_mt)
Definition cdrel.h:45
#define RECORD_TYPE_STR(_rt)
Definition cdrel.h:42
#define ast_debug(level,...)
Log a DEBUG message.
static int register_backend(enum cdrel_record_type record_type, const char *backend_name, void *log_cb)
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)
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.
#define NULL
Definition resample.c:96
#define AST_VECTOR_INIT(vec, size)
Initialize a vector.
Definition vector.h:124

References ast_calloc, ast_debug, AST_VECTOR_INIT, cdrel_unload_module(), load_config_file(), MODULE_TYPE_STR, NULL, RECORD_TYPE_STR, and register_backend().

Referenced by load_module(), load_module(), load_module(), and load_module().

◆ cdrel_logger()

int cdrel_logger ( struct cdrel_configs *  configs,
void *  data 
)

Log a record. The module's logging_cb must call this.

Warning
This function MUST be called with the module's config_lock held for reading to prevent reloads from happening while we're logging.
Parameters
configsA pointer to the VECTOR of config objects returned by cdrel_load_module.
dataA pointer to an ast_cdr or ast_event object to log.
Return values
0Success.
-1Failure.

Definition at line 270 of file loggers.c.

271{
272 struct ast_channel *dummy = NULL;
273 int ix = 0;
274 int skip_legacy = 0;
275 int res = 0;
276
277 for(ix = 0; ix < AST_VECTOR_SIZE(configs); ix++) {
279 void *chan_or_data = NULL;
280
281 if (config->config_type == cdrel_config_legacy) {
282 if (skip_legacy) {
283 continue;
284 }
285 if (!dummy) {
286 dummy = config->dummy_channel_alloc(config, data);
287 if (!dummy) {
288 ast_log(LOG_ERROR, "Unable to fabricate channel from CEL event for '%s'\n",
289 config->output_filename);
290 skip_legacy = 1;
291 res--;
292 continue;
293 }
294 }
295 chan_or_data = dummy;
296 } else {
297 chan_or_data = data;
298 }
299 res += logger_callbacks[config->backend_type][config->config_type](config, chan_or_data);
300 }
301
302 if (dummy) {
304 }
305 return res;
306}
#define ast_log
Definition astobj2.c:42
@ cdrel_config_legacy
Definition cdrel.h:55
static const char config[]
static void dummy(char *unused,...)
#define ast_channel_unref(c)
Decrease channel reference count.
Definition channel.h:3018
#define LOG_ERROR
static const cdrel_logger_cb logger_callbacks[cdrel_backend_type_end][cdrel_config_type_end]
Definition loggers.c:238
Main Channel structure associated with a channel.
#define AST_VECTOR_SIZE(vec)
Get the number of elements in a vector.
Definition vector.h:620
#define AST_VECTOR_GET(vec, idx)
Get an element from a vector.
Definition vector.h:691

References ast_channel_unref, ast_log, AST_VECTOR_GET, AST_VECTOR_SIZE, cdrel_config_legacy, config, dummy(), LOG_ERROR, logger_callbacks, and NULL.

Referenced by custom_log(), custom_log(), custom_log(), and custom_log().

◆ cdrel_reload_module()

int cdrel_reload_module ( enum cdrel_backend_type  backend_type,
enum cdrel_record_type  record_type,
struct cdrel_configs **  configs,
const char *  config_filename 
)

Perform module reload.

Needs to be called by each "custom" module

Warning
This function MUST be called with the module's config_lock held for writing to prevent reloads from happening while we're logging.
Parameters
backend_typeOne of cdrel_backend_type.
record_typeOne of cdrel_record_type.
configsA pointer to the VECTOR of config objects returned by cdrel_load_module.
config_filenameThe config file name.
Return values
AST_MODULE_LOAD_SUCCESS
AST_MODULE_LOAD_DECLINE

Definition at line 1391 of file res/cdrel_custom/config.c.

1393{
1394 int res = 0;
1395 struct cdrel_configs *old_configs = *configs;
1396 struct cdrel_configs *new_configs = NULL;
1397
1398 /*
1399 * Save new config to a temporary vector to make sure the
1400 * configs are valid before swapping them in.
1401 */
1402 new_configs = ast_malloc(sizeof(*new_configs));
1403 if (!new_configs) {
1405 }
1406
1407 if (AST_VECTOR_INIT(new_configs, AST_VECTOR_SIZE(old_configs)) != 0) {
1409 }
1410
1411 res = load_config_file(output_type, record_type, new_configs, filename, 1);
1412 if (res != 0) {
1413 AST_VECTOR_RESET(new_configs, config_free);
1414 AST_VECTOR_PTR_FREE(new_configs);
1416 }
1417
1418 /* Now swap the new ones in. */
1419 *configs = new_configs;
1420
1421 /* Free the old ones. */
1422 AST_VECTOR_RESET(old_configs, config_free);
1423 AST_VECTOR_PTR_FREE(old_configs);
1424
1426
1427
1428 return -1;
1429}
#define ast_malloc(len)
A wrapper for malloc()
Definition astmm.h:191
@ AST_MODULE_LOAD_SUCCESS
Definition module.h:70
@ AST_MODULE_LOAD_DECLINE
Module has failed to load, may be in an inconsistent state.
Definition module.h:78
static void config_free(struct cdrel_config *config)
#define AST_VECTOR_RESET(vec, cleanup)
Reset vector.
Definition vector.h:636
#define AST_VECTOR_PTR_FREE(vec)
Deallocates this vector pointer.
Definition vector.h:200

References ast_malloc, AST_MODULE_LOAD_DECLINE, AST_MODULE_LOAD_SUCCESS, AST_VECTOR_INIT, AST_VECTOR_PTR_FREE, AST_VECTOR_RESET, AST_VECTOR_SIZE, config_free(), load_config_file(), and NULL.

Referenced by reload(), reload(), reload(), and reload().

◆ cdrel_unload_module()

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.

Needs to be called by each "custom" module

Warning
This function MUST be called with the module's config_lock held for writing to prevent the module from being unloaded while we're logging.
Parameters
backend_typeOne of cdrel_backend_type.
record_typeOne of cdrel_record_type.
configsA pointer to the VECTOR of config objects returned by cdrel_load_module.
backend_nameThe backend name to unregister.
Return values
0Success.
-1Failure.

Definition at line 1459 of file res/cdrel_custom/config.c.

1461{
1462 if (unregister_backend(record_type, backend_name) != 0) {
1463 return -1;
1464 }
1465
1468
1469 return 0;
1470}
static int unregister_backend(enum cdrel_record_type record_type, const char *backend_name)

References AST_VECTOR_PTR_FREE, AST_VECTOR_RESET, config_free(), and unregister_backend().

Referenced by cdrel_load_module(), unload_module(), unload_module(), unload_module(), and unload_module().