Debian Codegraph @

cel/cel_sqlite3_custom.c

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