Asterisk - The Open Source Telephony Project GIT-master-80b953f
Loading...
Searching...
No Matches
getters_cdr.c
Go to the documentation of this file.
1/*
2 * Asterisk -- An open source telephony toolkit.
3 *
4 * Copyright (C) 2026, Sangoma Technologies Corporation
5 *
6 * George Joseph <gjoseph@sangoma.com>
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 <gjoseph@sangoma.com>
22 *
23 * \brief CDR Getters
24 *
25 */
26
27#include "cdrel.h"
28#include "asterisk/cdr.h"
29
30static 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) \
41static 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
51DEFINE_CDR_GETTER(int32, int32, int32_t)
52DEFINE_CDR_GETTER(uint32, uint32, uint32_t)
53DEFINE_CDR_GETTER(int64, int64, int64_t)
54DEFINE_CDR_GETTER(uint64, uint64, uint64_t)
56DEFINE_CDR_GETTER(doubler, double, double)
57
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
67static 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
87{
88 struct ast_cdr *cdr = data;
89 struct ast_channel *dummy = NULL;
90
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 }
98 return dummy;
99}
100
#define ast_log
Definition astobj2.c:42
Call Detail Record API.
struct ast_cdr * ast_cdr_dup(struct ast_cdr *cdr)
Duplicate a public CDR.
Definition cdr.c:3131
Private header for res_cdrel_custom.
#define CDR_FIELD(__cdr, __offset)
Definition cdrel.h:135
@ 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
cdrel_dummy_channel_alloc cdrel_dummy_channel_allocators[cdrel_format_type_end]
cdrel_field_getter cdrel_field_getters[cdrel_record_type_end][cdrel_data_type_end]
static const char config[]
static void dummy(char *unused,...)
void ast_channel_cdr_set(struct ast_channel *chan, struct ast_cdr *value)
#define ast_dummy_channel_alloc()
Create a fake channel structure.
Definition channel.h:1328
const char * ast_var_name(const struct ast_var_t *var)
Definition chanvars.c:60
const char * ast_var_value(const struct ast_var_t *var)
Definition chanvars.c:80
static struct ast_channel * dummy_chan_alloc_cdr(struct cdrel_config *config, void *data)
Definition getters_cdr.c:86
static int cdr_get_string(void *record, struct cdrel_config *config, struct cdrel_field *field, struct cdrel_value *value)
Definition getters_cdr.c:30
#define DEFINE_CDR_GETTER(_sname, _ename, _type)
Definition getters_cdr.c:40
static int cdr_get_literal(void *record, struct cdrel_config *config, struct cdrel_field *field, struct cdrel_value *value)
Definition getters_cdr.c:58
int load_cdr(void)
static int cdr_get_uservar(void *record, struct cdrel_config *config, struct cdrel_field *field, struct cdrel_value *value)
Definition getters_cdr.c:67
#define ast_debug(level,...)
Log a DEBUG message.
#define LOG_ERROR
#define AST_LIST_TRAVERSE(head, var, field)
Loops over (traverses) the entries in a list.
@ cdrel_record_cdr
#define NULL
Definition resample.c:96
#define S_OR(a, b)
returns the equivalent of logic or for strings: first one if not empty, otherwise second one.
Definition strings.h:80
Responsible for call detail data.
Definition cdr.h:281
struct varshead varshead
Definition cdr.h:332
struct timeval start
Definition cdr.h:299
Main Channel structure associated with a channel.
struct ast_cdr * cdr
const char * data
struct ast_var_t::@220 entries
int field_id
Definition cdrel.h:272
char data[1]
Definition cdrel.h:277
enum cdrel_data_type input_data_type
Definition cdrel.h:274
char * name
Definition cdrel.h:273
int value
Definition syslog.c:37