Debian Codegraph @

cdr/cdr_custom.c

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