Debian Codegraph @

cel/cel_custom.c

raw symbols SCIP
1 /*
2 * Asterisk -- An open source telephony toolkit.
3 *
4 * Copyright (C) 2009, Digium, Inc.
5 *
6 * Steve Murphy <[email protected]>
7 * much borrowed from cdr code (cdr_custom.c), author Mark Spencer
8 *
9 * See http://www.asterisk.org for more information about
10 * the Asterisk project. Please do not directly contact
11 * any of the maintainers of this project for assistance;
12 * the project provides a web site, mailing lists and IRC
13 * channels for your use.
14 *
15 * This program is free software, distributed under the terms of
16 * the GNU General Public License Version 2. See the LICENSE file
17 * at the top of the source tree.
18 */
19
20 /*! \file
21 *
22 * \brief Custom Comma Separated Value CEL records.
23 *
24 * \author Steve Murphy <[email protected]>
25 * Logs in LOG_DIR/cel_custom
26 * \ingroup cel_drivers
27 *
28 * The logic for this module now resides in res/res_cdrel_custom.c.
29 *
30 */
31
32 /*** MODULEINFO
33 <depend>res_cdrel_custom</depend>
34 <support_level>core</support_level>
35 ***/
36
37 #include "asterisk.h"
38
39 #include "asterisk/cel.h"
40 #include "asterisk/module.h"
41 #include "asterisk/res_cdrel_custom.h"
42
43 #define CONFIG "cel_custom.conf"
44
45 #define CUSTOM_BACKEND_NAME "CEL Custom CSV Logging"
46
47 static struct cdrel_configs *configs;
48
49 /*!
50 * Protects in-flight log transactions from reloads.
51 */
52 static ast_rwlock_t configs_lock;
53
54 #define CDREL_RECORD_TYPE cdrel_record_cel
55 #define CDREL_BACKEND_TYPE cdrel_backend_text
56
57 static void custom_log(struct ast_event *event)
58 {
59 ast_rwlock_rdlock(&configs_lock);
60 cdrel_logger(configs, event);
61 ast_rwlock_unlock(&configs_lock);
62 }
63
64 static int unload_module(void)
65 {
66 int res = 0;
67
68 ast_rwlock_wrlock(&configs_lock);
69 res = cdrel_unload_module(CDREL_BACKEND_TYPE, CDREL_RECORD_TYPE, configs, CUSTOM_BACKEND_NAME);
70 ast_rwlock_unlock(&configs_lock);
71 if (res == 0) {
72 ast_rwlock_destroy(&configs_lock);
73 }
74
75 return res;
76 }
77
78 static enum ast_module_load_result load_module(void)
79 {
80 if (ast_rwlock_init(&configs_lock) != 0) {
81 return AST_MODULE_LOAD_DECLINE;
82 }
83
84 configs = cdrel_load_module(CDREL_BACKEND_TYPE, CDREL_RECORD_TYPE, CONFIG, CUSTOM_BACKEND_NAME, custom_log);
85
86 return configs ? AST_MODULE_LOAD_SUCCESS : AST_MODULE_LOAD_DECLINE;
87 }
88
89 static int reload(void)
90 {
91 int res = 0;
92 ast_rwlock_wrlock(&configs_lock);
93 res = cdrel_reload_module(CDREL_BACKEND_TYPE, CDREL_RECORD_TYPE, &configs, CONFIG);
94 ast_rwlock_unlock(&configs_lock);
95 return res;
96 }
97
98 AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_LOAD_ORDER, "Customizable Comma Separated Values CEL Backend",
99 .support_level = AST_MODULE_SUPPORT_CORE,
100 .load = load_module,
101 .unload = unload_module,
102 .reload = reload,
103 .load_pri = AST_MODPRI_CDR_DRIVER,
104 .requires = "cel,res_cdrel_custom",
105 );