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

Common log entrypoint from the cdr/cel modules. More...

#include "cdrel.h"
#include "asterisk/pbx.h"
#include "asterisk/vector.h"
Include dependency graph for loggers.c:

Go to the source code of this file.

Typedefs

typedef int(* cdrel_logger_cb) (struct cdrel_config *config, void *data)
 

Functions

 AST_THREADSTORAGE_CUSTOM_SCOPE (custom_buf, NULL, ast_free_ptr, static)
 
int cdrel_logger (struct cdrel_configs *configs, void *data)
 Log a record. The module's logging_cb must call this.
 
static void free_value (void *data)
 
static void free_value_vector (void *data)
 
static int log_advanced_record (struct cdrel_config *config, void *data)
 
static int log_legacy_database_record (struct cdrel_config *config, void *data)
 
static int log_legacy_dsv_record (struct cdrel_config *config, void *data)
 

Variables

static const cdrel_logger_cb logger_callbacks [cdrel_backend_type_end][cdrel_config_type_end]
 

Detailed Description

Common log entrypoint from the cdr/cel modules.

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

Definition in file loggers.c.

Typedef Documentation

◆ cdrel_logger_cb

typedef int(* cdrel_logger_cb) (struct cdrel_config *config, void *data)

Definition at line 236 of file loggers.c.

Function Documentation

◆ AST_THREADSTORAGE_CUSTOM_SCOPE()

AST_THREADSTORAGE_CUSTOM_SCOPE ( custom_buf  ,
NULL  ,
ast_free_ptr  ,
static   
)

◆ 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
#define NULL
Definition resample.c:96
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().

◆ free_value()

static void free_value ( void *  data)
static

Definition at line 45 of file loggers.c.

46{
47 struct cdrel_value *val = data;
48 if (val->data_type == cdrel_type_string) {
49 ast_free(val->values.string);
50 val->values.string = NULL;
51 }
53}
#define ast_free(a)
Definition astmm.h:180
@ cdrel_type_string
Definition cdrel.h:73

References ast_free, cdrel_type_string, and NULL.

Referenced by free_value_vector().

◆ free_value_vector()

static void free_value_vector ( void *  data)
static

Definition at line 61 of file loggers.c.

62{
63 struct cdrel_values *values = data;
65 AST_VECTOR_PTR_FREE(values);
66}
static void free_value(void *data)
Definition loggers.c:45
#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_VECTOR_PTR_FREE, AST_VECTOR_RESET, and free_value().

Referenced by log_advanced_record(), and log_legacy_database_record().

◆ log_advanced_record()

static int log_advanced_record ( struct cdrel_config config,
void *  data 
)
static

Definition at line 174 of file loggers.c.

175{
176 int ix = 0;
177 int res = 0;
178 size_t field_count = AST_VECTOR_SIZE(&config->fields);
179 RAII_VAR(struct cdrel_values *, values, ast_calloc(1, sizeof(*values)), free_value_vector);
180
181 if (!values) {
182 return -1;
183 }
184
185 res = AST_VECTOR_INIT(values, field_count);
186 if (res != 0) {
187 return -1;
188 }
189
190 for (ix = 0; ix < AST_VECTOR_SIZE(&config->fields); ix++) {
191 struct cdrel_field *field = AST_VECTOR_GET(&config->fields, ix);
192 struct cdrel_value input_value = { 0, };
193 struct cdrel_value *output_value = ast_calloc(1, sizeof(*output_value));
194
195 if (!output_value) {
196 return -1;
197 }
198 output_value->mallocd = 1;
199
200 /*
201 * Get a field from a CDR structure or CEL event into an cdrel_value.
202 */
203 res = cdrel_field_getters[config->record_type][field->input_data_type](data, config, field, &input_value);
204 if (res != 0) {
205 ast_free(output_value);
206 return -1;
207 }
208
209 /*
210 * Set the output data type to the type we want to see in the output.
211 */
212 output_value->data_type = field->output_data_type;
213
214 /*
215 * Now call the formatter based on the INPUT data type.
216 */
217 res = cdrel_field_formatters[input_value.data_type](config, field, &input_value, output_value);
218 if (res != 0) {
219 ast_free(output_value);
220 return -1;
221 }
222
223 res = AST_VECTOR_APPEND(values, output_value);
224 if (res != 0) {
225 ast_free(output_value);
226 return -1;
227 }
228 }
229 return cdrel_backend_writers[config->format_type](config, values);
230}
#define ast_calloc(num, len)
A wrapper for calloc()
Definition astmm.h:202
cdrel_field_formatter cdrel_field_formatters[cdrel_data_type_end]
cdrel_backend_writer cdrel_backend_writers[cdrel_format_type_end]
cdrel_field_getter cdrel_field_getters[cdrel_record_type_end][cdrel_data_type_end]
static void free_value_vector(void *data)
Definition loggers.c:61
enum cdrel_data_type input_data_type
Definition cdrel.h:274
union cdrel_value::@454 values
enum cdrel_data_type data_type
Definition cdrel.h:175
int mallocd
Definition cdrel.h:176
#define RAII_VAR(vartype, varname, initval, dtor)
Declare a variable that will call a destructor function when it goes out of scope.
Definition utils.h:981
#define AST_VECTOR_INIT(vec, size)
Initialize a vector.
Definition vector.h:124
#define AST_VECTOR_APPEND(vec, elem)
Append an element to a vector, growing the vector if needed.
Definition vector.h:267

References ast_calloc, ast_free, AST_VECTOR_APPEND, AST_VECTOR_GET, AST_VECTOR_INIT, AST_VECTOR_SIZE, cdrel_backend_writers, cdrel_field_formatters, cdrel_field_getters, config, cdrel_value::data_type, free_value_vector(), cdrel_field::input_data_type, cdrel_value::mallocd, cdrel_field::output_data_type, RAII_VAR, and cdrel_value::values.

◆ log_legacy_database_record()

static int log_legacy_database_record ( struct cdrel_config config,
void *  data 
)
static

Definition at line 111 of file loggers.c.

112{
113 struct ast_channel *dummy = data;
114 int ix = 0;
115 int res = 0;
116 char subst_buf[2048];
117 size_t field_count = AST_VECTOR_SIZE(&config->fields);
118 RAII_VAR(struct cdrel_values *, values, ast_calloc(1, sizeof(*values)), free_value_vector);
119
120 if (!values) {
121 return -1;
122 }
123
124 res = AST_VECTOR_INIT(values, field_count);
125 if (res != 0) {
126 return -1;
127 }
128
129 if (config->db == NULL) {
130 return -1;
131 }
132
133 for (ix = 0; ix < AST_VECTOR_SIZE(&config->fields); ix++) {
134 struct cdrel_field *field = AST_VECTOR_GET(&config->fields, ix);
135 struct cdrel_value *output_value = ast_calloc(1, sizeof(*output_value));
136
137 if (!output_value) {
138 return -1;
139 }
140 output_value->mallocd = 1;
141
142 pbx_substitute_variables_helper(dummy, field->data, subst_buf, sizeof(subst_buf) - 1);
143 output_value->data_type = cdrel_type_string;
144
145 output_value->field_name = field->name;
146 output_value->values.string = ast_strdup(ast_strip_quoted(subst_buf, "'\"", "'\""));
147 if (!output_value->values.string) {
148 return -1;
149 }
150
151 res = AST_VECTOR_APPEND(values, output_value);
152 if (res != 0) {
153 ast_free(output_value);
154 return -1;
155 }
156 }
157
159}
#define ast_strdup(str)
A wrapper for strdup()
Definition astmm.h:241
int write_record_to_database(struct cdrel_config *config, struct cdrel_values *values)
Definition writers.c:169
void pbx_substitute_variables_helper(struct ast_channel *c, const char *cp1, char *cp2, int count)
Definition ael_main.c:211
char * ast_strip_quoted(char *s, const char *beg_quotes, const char *end_quotes)
Strip leading/trailing whitespace and quotes from a string.
Definition utils.c:1852
const char * data
char data[1]
Definition cdrel.h:277
char * name
Definition cdrel.h:273
char * field_name
Definition cdrel.h:174
char * string
Definition cdrel.h:178

References ast_calloc, ast_free, ast_strdup, ast_strip_quoted(), AST_VECTOR_APPEND, AST_VECTOR_GET, AST_VECTOR_INIT, AST_VECTOR_SIZE, cdrel_type_string, config, ast_channel::data, cdrel_field::data, cdrel_value::data_type, dummy(), cdrel_value::field_name, free_value_vector(), cdrel_value::mallocd, cdrel_field::name, NULL, pbx_substitute_variables_helper(), RAII_VAR, cdrel_value::string, cdrel_value::values, and write_record_to_database().

◆ log_legacy_dsv_record()

static int log_legacy_dsv_record ( struct cdrel_config config,
void *  data 
)
static

Definition at line 82 of file loggers.c.

83{
84 struct ast_channel *dummy = data;
85 struct ast_str *str;
86
87 if (!(str = ast_str_thread_get(&custom_buf, 1024))) {
88 return -1;
89 }
91
93
95}
const char * str
Definition app_jack.c:150
int write_record_to_file(struct cdrel_config *config, struct ast_str *record)
Definition writers.c:50
void ast_str_substitute_variables(struct ast_str **buf, ssize_t maxlen, struct ast_channel *chan, const char *templ)
void ast_str_reset(struct ast_str *buf)
Reset the content of a dynamic string. Useful before a series of ast_str_append.
Definition strings.h:693
struct ast_str * ast_str_thread_get(struct ast_threadstorage *ts, size_t init_len)
Retrieve a thread locally stored dynamic string.
Definition strings.h:909
Support for dynamic strings.
Definition strings.h:623

References ast_str_reset(), ast_str_substitute_variables(), ast_str_thread_get(), config, ast_channel::data, dummy(), str, and write_record_to_file().

Variable Documentation

◆ logger_callbacks

Definition at line 238 of file loggers.c.

238 {
242 },
243 [cdrel_backend_db] = {
246 },
247};
@ cdrel_config_advanced
Definition cdrel.h:56
static int log_advanced_record(struct cdrel_config *config, void *data)
Definition loggers.c:174
static int log_legacy_database_record(struct cdrel_config *config, void *data)
Definition loggers.c:111
static int log_legacy_dsv_record(struct cdrel_config *config, void *data)
Definition loggers.c:82
@ cdrel_backend_db
@ cdrel_backend_text

Referenced by cdrel_logger().