Files
asterisk/cel/cel_sqlite3_custom.c
T

112 lines
2.8 KiB
C
Raw Normal View History

/*
* Asterisk -- An open source telephony toolkit.
*
* Copyright (C) 2007, Digium, Inc.
*
* Steve Murphy <murf@digium.com> borrowed code from cdr,
* Mark Spencer <markster@digium.com> and others.
*
* See http://www.asterisk.org for more information about
* the Asterisk project. Please do not directly contact
* any of the maintainers of this project for assistance;
* the project provides a web site, mailing lists and IRC
* channels for your use.
*
* This program is free software, distributed under the terms of
* the GNU General Public License Version 2. See the LICENSE file
* at the top of the source tree.
*/
/*! \file
*
* \brief Custom SQLite3 CEL records.
*
* \author Adapted by Steve Murphy <murf@digium.com> from
* Alejandro Rios <alejandro.rios@avatar.com.co> and
* Russell Bryant <russell@digium.com> from
* cdr_mysql_custom by Edward Eastman <ed@dm3.co.uk>,
* and cdr_sqlite by Holger Schurig <hs4233@mail.mn-solutions.de>
* \ingroup cel_drivers
2026-01-27 12:57:21 -07:00
*
* The logic for this module now resides in res/res_cdrel_custom.c.
*
*/
/*** MODULEINFO
2026-01-27 12:57:21 -07:00
<depend>res_cdrel_custom</depend>
<depend>sqlite3</depend>
2011-07-14 20:28:54 +00:00
<support_level>extended</support_level>
***/
#include "asterisk.h"
#include <sqlite3.h>
#include "asterisk/cel.h"
#include "asterisk/module.h"
2026-01-27 12:57:21 -07:00
#include "asterisk/res_cdrel_custom.h"
2026-01-27 12:57:21 -07:00
#define CONFIG "cel_sqlite3_custom.conf"
2026-01-27 12:57:21 -07:00
#define CUSTOM_BACKEND_NAME "CEL sqlite3 custom backend"
2026-01-27 12:57:21 -07:00
static struct cdrel_configs *configs;
2012-09-22 20:43:30 +00:00
/*!
2026-01-27 12:57:21 -07:00
* Protects in-flight log transactions from reloads.
2012-09-22 20:43:30 +00:00
*/
2026-01-27 12:57:21 -07:00
static ast_rwlock_t configs_lock;
2026-01-27 12:57:21 -07:00
#define CDREL_RECORD_TYPE cdrel_record_cel
#define CDREL_BACKEND_TYPE cdrel_backend_db
2026-01-27 12:57:21 -07:00
static void custom_log(struct ast_event *event)
{
2026-01-27 12:57:21 -07:00
ast_rwlock_rdlock(&configs_lock);
cdrel_logger(configs, event);
ast_rwlock_unlock(&configs_lock);
}
static int unload_module(void)
{
2026-01-27 12:57:21 -07:00
int res = 0;
2026-01-27 12:57:21 -07:00
ast_rwlock_wrlock(&configs_lock);
res = cdrel_unload_module(CDREL_BACKEND_TYPE, CDREL_RECORD_TYPE, configs, CUSTOM_BACKEND_NAME);
ast_rwlock_unlock(&configs_lock);
if (res == 0) {
ast_rwlock_destroy(&configs_lock);
}
2026-01-27 12:57:21 -07:00
return res;
}
2026-01-27 12:57:21 -07:00
static enum ast_module_load_result load_module(void)
{
2026-01-27 12:57:21 -07:00
if (ast_rwlock_init(&configs_lock) != 0) {
return AST_MODULE_LOAD_DECLINE;
}
2026-01-27 12:57:21 -07:00
configs = cdrel_load_module(CDREL_BACKEND_TYPE, CDREL_RECORD_TYPE, CONFIG, CUSTOM_BACKEND_NAME, custom_log);
2026-01-27 12:57:21 -07:00
return configs ? AST_MODULE_LOAD_SUCCESS : AST_MODULE_LOAD_DECLINE;
}
static int reload(void)
{
int res = 0;
2026-01-27 12:57:21 -07:00
ast_rwlock_wrlock(&configs_lock);
res = cdrel_reload_module(CDREL_BACKEND_TYPE, CDREL_RECORD_TYPE, &configs, CONFIG);
ast_rwlock_unlock(&configs_lock);
return res;
}
AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_LOAD_ORDER, "SQLite3 Custom CEL Module",
.support_level = AST_MODULE_SUPPORT_EXTENDED,
.load = load_module,
.unload = unload_module,
.reload = reload,
.load_pri = AST_MODPRI_CDR_DRIVER,
2026-01-27 12:57:21 -07:00
.requires = "cel,res_cdrel_custom",
);