61 #define CUSTOM_LOG_DIR "/cdr_custom"
62 #define CONFIG "cdr_custom.conf"
66 static const char name[] =
"cdr-custom";
79 static void free_config(
void)
83 while ((sink = AST_RWLIST_REMOVE_HEAD(&
sinks, list))) {
84 ast_mutex_destroy(&sink->lock);
90 static int load_config(
void)
98 if (!cfg || cfg == CONFIG_STATUS_FILEINVALID) {
99 ast_log(LOG_ERROR,
"Unable to load " CONFIG
". Not logging custom CSV CDRs.\n");
103 var = ast_variable_browse(cfg,
"mappings");
105 if (!ast_strlen_zero(var->
name) && !ast_strlen_zero(var->
value)) {
109 ast_log(LOG_ERROR,
"Unable to allocate memory for configuration settings.\n");
116 ast_mutex_init(&sink->lock);
118 AST_RWLIST_INSERT_TAIL(&
sinks, sink, list);
120 ast_log(LOG_NOTICE,
"Mapping must have both a filename and a format at line %d\n", var->lineno);
129 static int custom_log(
struct ast_cdr *cdr)
142 ast_log(LOG_ERROR,
"Unable to allocate channel for variable subsitution.\n");
162 ast_mutex_lock(&config->lock);
167 if ((out = fopen(config->filename,
"a"))) {
172 ast_log(LOG_ERROR,
"Unable to re-open master file %s : %s\n", config->filename, strerror(errno));
175 ast_mutex_unlock(&config->lock);
185 static int unload_module(
void)
193 ast_log(LOG_ERROR,
"Unable to lock sink list. Unload failed.\n");
205 ast_log(LOG_ERROR,
"Unable to lock sink list. Load failed.\n");
215 static int reload(
void)
218 ast_log(LOG_ERROR,
"Unable to lock sink list. Load failed.\n");
228 AST_MODULE_INFO(
ASTERISK_GPL_KEY, AST_MODFLAG_LOAD_ORDER,
"Customizable Comma Separated Values CDR Backend",
229 .support_level = AST_MODULE_SUPPORT_CORE,
231 .unload = unload_module,
struct ast_variable * next
#define AST_THREADSTORAGE(name)
Define a thread storage variable.
Main Channel structure associated with a channel.
Asterisk locking-related definitions:
Asterisk main include file. File version handling, generic pbx functions.
int ast_cdr_unregister(const char *name)
Unregister a CDR handling engine.
String manipulation functions.
#define ast_channel_unref(c)
Decrease channel reference count.
Time-related functions and macros.
char * ast_str_buffer(const struct ast_str *buf)
Returns the string buffer within the ast_str buf.
#define AST_RWLIST_RDLOCK(head)
Read locks a list.
Structure for variables, used for configurations and for channel variables.
struct ast_cdr * ast_cdr_dup(struct ast_cdr *cdr)
Duplicate a public CDR.
void ast_str_substitute_variables(struct ast_str **buf, ssize_t maxlen, struct ast_channel *chan, const char *templ)
#define AST_RWLIST_WRLOCK(head)
Write locks a list.
#define ast_calloc_with_stringfields(n, type, size)
Allocate a structure with embedded stringfields in a single allocation.
#define AST_DECLARE_STRING_FIELDS(field_list)
Declare the fields needed in a structure.
Definitions to aid in the use of thread local storage.
#define AST_RWLIST_HEAD_STATIC(name, type)
Defines a structure to be used to hold a read/write list of specified type, statically initialized...
Configuration File Parser.
#define ast_config_load(filename, flags)
Load a config file.
int ast_cdr_register(const char *name, const char *desc, ast_cdrbe be)
Register a CDR handling engine.
General Asterisk PBX channel definitions.
Asterisk file paths, configured in asterisk.conf.
#define ast_dummy_channel_alloc()
Create a fake channel structure.
#define AST_STRING_FIELD(name)
Declare a string field.
Core PBX routines and definitions.
Responsible for call detail data.
Support for dynamic strings.
#define AST_LIST_TRAVERSE(head, var, field)
Loops over (traverses) the entries in a list.
Module has failed to load, may be in an inconsistent state.
#define ast_string_field_build(x, field, fmt, args...)
Set a field to a complex (built) value.
Structure used to handle boolean flags.
#define AST_RWLIST_UNLOCK(head)
Attempts to unlock a read/write based list.
struct ast_str * ast_str_thread_get(struct ast_threadstorage *ts, size_t init_len)
Retrieve a thread locally stored dynamic string.
void ast_config_destroy(struct ast_config *cfg)
Destroys a config.
#define ASTERISK_GPL_KEY
The text the key() function should return.
Asterisk module definitions.
#define ast_string_field_free_memory(x)
free all memory - to be called before destroying the object
Structure for mutex and tracking information.