Debian Codegraph @

cdr/cdr_sqlite3_custom.c

raw symbols SCIP
1 /*
2 * Asterisk -- An open source telephony toolkit.
3 *
4 * Copyright (C) 1999 - 2007, Digium, Inc.
5 *
6 * Mark Spencer <[email protected]> and others.
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 * \brief Custom SQLite3 CDR records.
22 *
23 * \author Adapted by Alejandro Rios <[email protected]> and
24 * Russell Bryant <[email protected]> from
25 * cdr_mysql_custom by Edward Eastman <[email protected]>,
26 * and cdr_sqlite by Holger Schurig <[email protected]>
27 *
28 * \arg See also \ref AstCDR
29 *
30 * \ingroup cdr_drivers
31 *
32 * The logic for this module now resides in res/res_cdrel_custom.c.
33 *
34 */
35
36 /*** MODULEINFO
37 <depend>res_cdrel_custom</depend>
38 <depend>sqlite3</depend>
39 <support_level>extended</support_level>
40 ***/
41
42 #include "asterisk.h"
43
44 #include <sqlite3.h>
45
46 #include "asterisk/cdr.h"
47 #include "asterisk/module.h"
48 #include "asterisk/res_cdrel_custom.h"
49
50 #define CONFIG "cdr_sqlite3_custom.conf"
51
52 #define CUSTOM_BACKEND_NAME "CDR sqlite3 custom backend"
53
54 static struct cdrel_configs *configs;
55
56 /*!
57 * Protects in-flight log transactions from reloads.
58 */
59 static ast_rwlock_t configs_lock;
60
61 #define CDREL_RECORD_TYPE cdrel_record_cdr
62 #define CDREL_BACKEND_TYPE cdrel_backend_db
63
64 static int custom_log(struct ast_cdr *cdr)
65 {
66 int res = 0;
67
68 ast_rwlock_rdlock(&configs_lock);
69 res = cdrel_logger(configs, cdr);
70 ast_rwlock_unlock(&configs_lock);
71
72 return res;
73 }
74
75 static int unload_module(void)
76 {
77 int res = 0;
78
79 ast_rwlock_wrlock(&configs_lock);
80 res = cdrel_unload_module(CDREL_BACKEND_TYPE, CDREL_RECORD_TYPE, configs, CUSTOM_BACKEND_NAME);
81 ast_rwlock_unlock(&configs_lock);
82 if (res == 0) {
83 ast_rwlock_destroy(&configs_lock);
84 }
85
86 return res;
87 }
88
89 static enum ast_module_load_result load_module(void)
90 {
91 if (ast_rwlock_init(&configs_lock) != 0) {
92 return AST_MODULE_LOAD_DECLINE;
93 }
94
95 configs = cdrel_load_module(CDREL_BACKEND_TYPE, CDREL_RECORD_TYPE, CONFIG, CUSTOM_BACKEND_NAME, custom_log);
96
97 return configs ? AST_MODULE_LOAD_SUCCESS : AST_MODULE_LOAD_DECLINE;
98 }
99
100 static int reload(void)
101 {
102 int res = 0;
103 ast_rwlock_wrlock(&configs_lock);
104 res = cdrel_reload_module(CDREL_BACKEND_TYPE, CDREL_RECORD_TYPE, &configs, CONFIG);
105 ast_rwlock_unlock(&configs_lock);
106 return res;
107 }
108
109 AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_LOAD_ORDER, "SQLite3 Custom CDR Module",
110 .support_level = AST_MODULE_SUPPORT_EXTENDED,
111 .load = load_module,
112 .unload = unload_module,
113 .reload = reload,
114 .load_pri = AST_MODPRI_CDR_DRIVER,
115 .requires = "cdr,res_cdrel_custom",
116 );