| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
#ifndef _CDREL_H |
| 28 |
#define _CDREL_H |
| 29 |
|
| 30 |
#include <sqlite3.h> |
| 31 |
|
| 32 |
#include "asterisk.h" |
| 33 |
#include "asterisk/cdr.h" |
| 34 |
#include "asterisk/cel.h" |
| 35 |
#include "asterisk/event.h" |
| 36 |
#include "asterisk/lock.h" |
| 37 |
#include "asterisk/strings.h" |
| 38 |
#include "asterisk/vector.h" |
| 39 |
#include "asterisk/res_cdrel_custom.h" |
| 40 |
|
| 41 |
extern const char *cdrel_record_type_map[]; |
| 42 |
#define RECORD_TYPE_STR(_rt) (cdrel_record_type_map[_rt]) |
| 43 |
|
| 44 |
extern const char *cdrel_module_type_map[]; |
| 45 |
#define MODULE_TYPE_STR(_mt) (cdrel_module_type_map[_mt]) |
| 46 |
|
| 47 |
enum cdrel_text_format_type { |
| 48 |
cdrel_format_dsv = 0, |
| 49 |
cdrel_format_json, |
| 50 |
cdrel_format_sql, |
| 51 |
cdrel_format_type_end, |
| 52 |
}; |
| 53 |
|
| 54 |
enum cdrel_config_type { |
| 55 |
cdrel_config_legacy = 0, |
| 56 |
cdrel_config_advanced, |
| 57 |
cdrel_config_type_end, |
| 58 |
}; |
| 59 |
|
| 60 |
enum cdrel_quoting_method { |
| 61 |
cdrel_quoting_method_none = 0, |
| 62 |
cdrel_quoting_method_all, |
| 63 |
cdrel_quoting_method_minimal, |
| 64 |
cdrel_quoting_method_non_numeric, |
| 65 |
cdrel_quoting_method_end, |
| 66 |
}; |
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
enum cdrel_data_type { |
| 73 |
cdrel_type_string = 0, |
| 74 |
cdrel_type_timeval, |
| 75 |
cdrel_type_literal, |
| 76 |
cdrel_type_amaflags, |
| 77 |
cdrel_type_disposition, |
| 78 |
cdrel_type_uservar, |
| 79 |
cdrel_type_event_type, |
| 80 |
cdrel_type_event_enum, |
| 81 |
cdrel_type_cel_timefmt, |
| 82 |
cdrel_data_type_strings_end, |
| 83 |
cdrel_type_int32, |
| 84 |
cdrel_type_uint32, |
| 85 |
cdrel_type_int64, |
| 86 |
cdrel_type_uint64, |
| 87 |
cdrel_type_double, |
| 88 |
cdrel_data_type_end |
| 89 |
}; |
| 90 |
|
| 91 |
extern const char *cdrel_data_type_map[]; |
| 92 |
#define DATA_TYPE_STR(_dt) (_dt < cdrel_data_type_end ? cdrel_data_type_map[_dt] : NULL) |
| 93 |
enum cdrel_data_type cdrel_data_type_from_str(const char *str); |
| 94 |
|
| 95 |
#define CDREL_FIELD_FLAG_QUOTE (0) |
| 96 |
#define CDREL_FIELD_FLAG_NOQUOTE (1) |
| 97 |
#define CDREL_FIELD_FLAG_TYPE_FORCED (2) |
| 98 |
#define CDREL_FIELD_FLAG_USERVAR (3) |
| 99 |
#define CDREL_FIELD_FLAG_LITERAL (4) |
| 100 |
#define CDREL_FIELD_FLAG_FORMAT_SPEC (5) |
| 101 |
#define CDREL_FIELD_FLAG_LAST (6) |
| 102 |
|
| 103 |
enum cdrel_field_flags { |
| 104 |
cdrel_flag_quote = (1 << CDREL_FIELD_FLAG_QUOTE), |
| 105 |
cdrel_flag_noquote = (1 << CDREL_FIELD_FLAG_NOQUOTE), |
| 106 |
cdrel_flag_type_forced = (1 << CDREL_FIELD_FLAG_TYPE_FORCED), |
| 107 |
cdrel_flag_uservar = (1 << CDREL_FIELD_FLAG_USERVAR), |
| 108 |
cdrel_flag_literal = (1 << CDREL_FIELD_FLAG_LITERAL), |
| 109 |
cdrel_flag_format_spec = (1 << CDREL_FIELD_FLAG_FORMAT_SPEC), |
| 110 |
cdrel_field_flags_end = (1 << CDREL_FIELD_FLAG_LAST), |
| 111 |
}; |
| 112 |
|
| 113 |
|
| 114 |
|
| 115 |
|
| 116 |
|
| 117 |
|
| 118 |
#define AST_EVENT_IE_CEL_LITERAL (AST_EVENT_IE_TOTAL + 1) |
| 119 |
#define AST_EVENT_IE_CEL_EVENT_ENUM (AST_EVENT_IE_TOTAL + 2) |
| 120 |
#define LAST_CEL_ID AST_EVENT_IE_CEL_EVENT_ENUM |
| 121 |
|
| 122 |
|
| 123 |
|
| 124 |
|
| 125 |
|
| 126 |
|
| 127 |
|
| 128 |
|
| 129 |
|
| 130 |
|
| 131 |
|
| 132 |
|
| 133 |
#define CDR_OFFSET_SHIFT (LAST_CEL_ID + 1) |
| 134 |
#define CDR_OFFSETOF(_field) (offsetof(struct ast_cdr, _field) + CDR_OFFSET_SHIFT) |
| 135 |
#define CDR_FIELD(__cdr, __offset) (((void *)__cdr) + __offset - CDR_OFFSET_SHIFT) |
| 136 |
|
| 137 |
enum cdr_field_id { |
| 138 |
cdr_field_literal = -1, |
| 139 |
cdr_field_clid = CDR_OFFSETOF(clid), |
| 140 |
cdr_field_src = CDR_OFFSETOF(src), |
| 141 |
cdr_field_dst = CDR_OFFSETOF(dst), |
| 142 |
cdr_field_dcontext = CDR_OFFSETOF(dcontext), |
| 143 |
cdr_field_channel = CDR_OFFSETOF(channel), |
| 144 |
cdr_field_dstchannel = CDR_OFFSETOF(dstchannel), |
| 145 |
cdr_field_lastapp = CDR_OFFSETOF(lastapp), |
| 146 |
cdr_field_lastdata = CDR_OFFSETOF(lastdata), |
| 147 |
cdr_field_start = CDR_OFFSETOF(start), |
| 148 |
cdr_field_answer = CDR_OFFSETOF(answer), |
| 149 |
cdr_field_end = CDR_OFFSETOF(end), |
| 150 |
cdr_field_duration = CDR_OFFSETOF(duration), |
| 151 |
cdr_field_billsec = CDR_OFFSETOF(billsec), |
| 152 |
cdr_field_disposition = CDR_OFFSETOF(disposition), |
| 153 |
cdr_field_amaflags = CDR_OFFSETOF(amaflags), |
| 154 |
cdr_field_accountcode = CDR_OFFSETOF(accountcode), |
| 155 |
cdr_field_peeraccount = CDR_OFFSETOF(peeraccount), |
| 156 |
cdr_field_flags = CDR_OFFSETOF(flags), |
| 157 |
cdr_field_uniqueid = CDR_OFFSETOF(uniqueid), |
| 158 |
cdr_field_linkedid = CDR_OFFSETOF(linkedid), |
| 159 |
cdr_field_tenantid = CDR_OFFSETOF(tenantid), |
| 160 |
cdr_field_peertenantid = CDR_OFFSETOF(peertenantid), |
| 161 |
cdr_field_userfield = CDR_OFFSETOF(userfield), |
| 162 |
cdr_field_sequence = CDR_OFFSETOF(sequence), |
| 163 |
cdr_field_varshead = CDR_OFFSETOF(varshead), |
| 164 |
}; |
| 165 |
|
| 166 |
|
| 167 |
struct cdrel_field; |
| 168 |
|
| 169 |
|
| 170 |
|
| 171 |
|
| 172 |
|
| 173 |
struct cdrel_value { |
| 174 |
char *field_name; |
| 175 |
enum cdrel_data_type data_type; |
| 176 |
int mallocd; |
| 177 |
union { |
| 178 |
char *string; |
| 179 |
int32_t int32; |
| 180 |
uint32_t uint32; |
| 181 |
int64_t int64; |
| 182 |
uint64_t uint64; |
| 183 |
struct timeval tv; |
| 184 |
double doubler; |
| 185 |
} values; |
| 186 |
}; |
| 187 |
|
| 188 |
|
| 189 |
|
| 190 |
|
| 191 |
|
| 192 |
AST_VECTOR(cdrel_values, struct cdrel_value *); |
| 193 |
|
| 194 |
|
| 195 |
|
| 196 |
|
| 197 |
|
| 198 |
|
| 199 |
|
| 200 |
|
| 201 |
|
| 202 |
|
| 203 |
|
| 204 |
|
| 205 |
typedef int (*cdrel_field_getter)(void *record, struct cdrel_config *config, |
| 206 |
struct cdrel_field *field, struct cdrel_value *value); |
| 207 |
|
| 208 |
|
| 209 |
|
| 210 |
|
| 211 |
|
| 212 |
|
| 213 |
extern cdrel_field_getter cdrel_field_getters[cdrel_record_type_end][cdrel_data_type_end]; |
| 214 |
|
| 215 |
|
| 216 |
|
| 217 |
|
| 218 |
|
| 219 |
|
| 220 |
|
| 221 |
|
| 222 |
|
| 223 |
|
| 224 |
|
| 225 |
|
| 226 |
typedef int (*cdrel_field_formatter)(struct cdrel_config *config, |
| 227 |
struct cdrel_field *field, struct cdrel_value *input_value, struct cdrel_value *output_value); |
| 228 |
|
| 229 |
|
| 230 |
|
| 231 |
|
| 232 |
|
| 233 |
|
| 234 |
extern cdrel_field_formatter cdrel_field_formatters[cdrel_data_type_end]; |
| 235 |
|
| 236 |
|
| 237 |
|
| 238 |
|
| 239 |
|
| 240 |
|
| 241 |
|
| 242 |
|
| 243 |
|
| 244 |
|
| 245 |
typedef int (*cdrel_backend_writer)(struct cdrel_config *config, struct cdrel_values *values); |
| 246 |
|
| 247 |
|
| 248 |
|
| 249 |
|
| 250 |
|
| 251 |
|
| 252 |
extern cdrel_backend_writer cdrel_backend_writers[cdrel_format_type_end]; |
| 253 |
|
| 254 |
|
| 255 |
|
| 256 |
|
| 257 |
|
| 258 |
|
| 259 |
|
| 260 |
|
| 261 |
|
| 262 |
|
| 263 |
|
| 264 |
|
| 265 |
typedef struct ast_channel * (*cdrel_dummy_channel_alloc)(struct cdrel_config *config, void *record); |
| 266 |
extern cdrel_dummy_channel_alloc cdrel_dummy_channel_allocators[cdrel_format_type_end]; |
| 267 |
|
| 268 |
|
| 269 |
|
| 270 |
struct cdrel_field { |
| 271 |
enum cdrel_record_type record_type; |
| 272 |
int field_id; |
| 273 |
char *name; |
| 274 |
enum cdrel_data_type input_data_type; |
| 275 |
enum cdrel_data_type output_data_type; |
| 276 |
struct ast_flags flags; |
| 277 |
char data[1]; |
| 278 |
}; |
| 279 |
|
| 280 |
|
| 281 |
struct cdrel_config { |
| 282 |
enum cdrel_record_type record_type; |
| 283 |
AST_DECLARE_STRING_FIELDS( |
| 284 |
AST_STRING_FIELD(config_filename); |
| 285 |
AST_STRING_FIELD(output_filename); |
| 286 |
AST_STRING_FIELD(template); |
| 287 |
AST_STRING_FIELD(db_columns); |
| 288 |
AST_STRING_FIELD(db_table); |
| 289 |
); |
| 290 |
sqlite3 *db; |
| 291 |
sqlite3_stmt *insert; |
| 292 |
int busy_timeout; |
| 293 |
cdrel_dummy_channel_alloc dummy_channel_alloc; |
| 294 |
enum cdrel_backend_type backend_type; |
| 295 |
enum cdrel_config_type config_type; |
| 296 |
enum cdrel_text_format_type format_type; |
| 297 |
enum cdrel_quoting_method quoting_method; |
| 298 |
char separator[2]; |
| 299 |
char quote[2]; |
| 300 |
char quote_escape[2]; |
| 301 |
AST_VECTOR(, struct cdrel_field *) fields; |
| 302 |
ast_mutex_t lock; |
| 303 |
}; |
| 304 |
|
| 305 |
|
| 306 |
|
| 307 |
|
| 308 |
|
| 309 |
|
| 310 |
|
| 311 |
|
| 312 |
|
| 313 |
|
| 314 |
const struct cdrel_field *get_registered_field_by_name(enum cdrel_record_type record_type, |
| 315 |
const char *name); |
| 316 |
|
| 317 |
|
| 318 |
|
| 319 |
|
| 320 |
|
| 321 |
|
| 322 |
|
| 323 |
|
| 324 |
|
| 325 |
|
| 326 |
int write_record_to_file(struct cdrel_config *config, struct ast_str *record); |
| 327 |
|
| 328 |
|
| 329 |
|
| 330 |
|
| 331 |
|
| 332 |
|
| 333 |
|
| 334 |
|
| 335 |
|
| 336 |
|
| 337 |
int write_record_to_database(struct cdrel_config *config, struct cdrel_values *values); |
| 338 |
|
| 339 |
|
| 340 |
|
| 341 |
|
| 342 |
|
| 343 |
|
| 344 |
|
| 345 |
|
| 346 |
const char *cdrel_basename(const char *path); |
| 347 |
|
| 348 |
|
| 349 |
|
| 350 |
|
| 351 |
|
| 352 |
|
| 353 |
|
| 354 |
|
| 355 |
|
| 356 |
const char *cdrel_get_field_flags(struct ast_flags *flags, struct ast_str **str); |
| 357 |
|
| 358 |
|
| 359 |
int load_cdr(void); |
| 360 |
int load_cel(void); |
| 361 |
int load_formatters(void); |
| 362 |
int load_writers(void); |
| 363 |
|
| 364 |
#endif |