Debian Codegraph @

res/cdrel_custom/getters_cdr.c

raw symbols SCIP
1 /*
2 * Asterisk -- An open source telephony toolkit.
3 *
4 * Copyright (C) 2026, Sangoma Technologies Corporation
5 *
6 * George Joseph <[email protected]>
7 *
8 * See http://www.asterisk.org for more information about
9 * the Asterisk project. Please do not directly contact
10 * any of the maintainers of this project for assistance;
11 * the project provides a web site, mailing lists and IRC
12 * channels for your use.
13 *
14 * This program is free software, distributed under the terms of
15 * the GNU General Public License Version 2. See the LICENSE file
16 * at the top of the source tree.
17 */
18
19 /*!
20 * \file
21 * \author George Joseph <[email protected]>
22 *
23 * \brief CDR Getters
24 *
25 */
26
27 #include "cdrel.h"
28 #include "asterisk/cdr.h"
29
30 static int cdr_get_string(void *record, struct cdrel_config *config,
31 struct cdrel_field *field, struct cdrel_value *value)
32 {
33 struct ast_cdr *cdr = record;
34 value->data_type = field->input_data_type;
35 value->field_name = field->name;
36 value->values.string = CDR_FIELD(cdr, field->field_id);
37 return 0;
38 }
39
40 #define DEFINE_CDR_GETTER(_sname, _ename, _type) \
41 static int cdr_get_ ## _ename (void *record, struct cdrel_config *config, \
42 struct cdrel_field *field, struct cdrel_value *value) \
43 { \
44 struct ast_cdr *cdr = record; \
45 value->data_type = field->input_data_type; \
46 value->field_name = field->name; \
47 value->values._sname = *(_type *)CDR_FIELD(cdr, field->field_id); \
48 return 0; \
49 }\
50
51 DEFINE_CDR_GETTER(int32, int32, int32_t)
52 DEFINE_CDR_GETTER(uint32, uint32, uint32_t)
53 DEFINE_CDR_GETTER(int64, int64, int64_t)
54 DEFINE_CDR_GETTER(uint64, uint64, uint64_t)
55 DEFINE_CDR_GETTER(tv, timeval, struct timeval)
56 DEFINE_CDR_GETTER(doubler, double, double)
57
58 static int cdr_get_literal(void *record, struct cdrel_config *config,
59 struct cdrel_field *field, struct cdrel_value *value)
60 {
61 value->data_type = cdrel_type_string;
62 value->field_name = field->name;
63 value->values.string = field->data;
64 return 0;
65 }
66
67 static int cdr_get_uservar(void *record, struct cdrel_config *config,
68 struct cdrel_field *field, struct cdrel_value *value)
69 {
70 struct ast_cdr *cdr = record;
71 struct ast_var_t *variables;
72 const char *rtn = NULL;
73
74 value->data_type = cdrel_type_string;
75 value->field_name = field->name;
76 AST_LIST_TRAVERSE(&cdr->varshead, variables, entries) {
77 if (strcasecmp(field->data, ast_var_name(variables)) == 0) {
78 rtn = ast_var_value(variables);
79 }
80 }
81
82 value->values.string = (char *)S_OR(rtn, "");
83 return 0;
84 }
85
86 static struct ast_channel *dummy_chan_alloc_cdr(struct cdrel_config *config, void *data)
87 {
88 struct ast_cdr *cdr = data;
89 struct ast_channel *dummy = NULL;
90
91 dummy = ast_dummy_channel_alloc();
92 if (!dummy) {
93 ast_log(LOG_ERROR, "Unable to fabricate channel from CDR for '%s'\n",
94 config->output_filename);
95 return NULL;
96 }
97 ast_channel_cdr_set(dummy, ast_cdr_dup(cdr));
98 return dummy;
99 }
100
101 int load_cdr(void)
102 {
103 ast_debug(1, "Loading CDR getters\n");
104 cdrel_field_getters[cdrel_record_cdr][cdrel_type_string] = cdr_get_string;
105 cdrel_field_getters[cdrel_record_cdr][cdrel_type_literal] = cdr_get_literal;
106 cdrel_field_getters[cdrel_record_cdr][cdrel_type_int32] = cdr_get_int32;
107 cdrel_field_getters[cdrel_record_cdr][cdrel_type_uint32] = cdr_get_uint32;
108 cdrel_field_getters[cdrel_record_cdr][cdrel_type_int64] = cdr_get_int64;
109 cdrel_field_getters[cdrel_record_cdr][cdrel_type_uint64] = cdr_get_uint64;
110 cdrel_field_getters[cdrel_record_cdr][cdrel_type_timeval] = cdr_get_timeval;
111 cdrel_field_getters[cdrel_record_cdr][cdrel_type_double] = cdr_get_double;
112 cdrel_field_getters[cdrel_record_cdr][cdrel_type_uservar] = cdr_get_uservar;
113 cdrel_dummy_channel_allocators[cdrel_record_cdr] = dummy_chan_alloc_cdr;
114
115 return 0;
116 }