2007-03-13 21:22:33 +00:00
|
|
|
/*
|
|
|
|
|
* Asterisk -- An open source telephony toolkit.
|
|
|
|
|
*
|
|
|
|
|
* Copyright (C) 1999 - 2007, Digium, Inc.
|
|
|
|
|
*
|
|
|
|
|
* 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.
|
|
|
|
|
*/
|
|
|
|
|
|
2010-02-26 08:45:11 +00:00
|
|
|
/*!
|
|
|
|
|
* \file
|
2007-03-13 21:22:33 +00:00
|
|
|
* \brief Custom SQLite3 CDR records.
|
|
|
|
|
*
|
|
|
|
|
* \author Adapted by Alejandro Rios <alejandro.rios@avatar.com.co> and
|
2008-11-20 17:48:58 +00:00
|
|
|
* Russell Bryant <russell@digium.com> from
|
2007-03-13 21:22:33 +00:00
|
|
|
* cdr_mysql_custom by Edward Eastman <ed@dm3.co.uk>,
|
|
|
|
|
* and cdr_sqlite by Holger Schurig <hs4233@mail.mn-solutions.de>
|
2008-11-20 17:48:58 +00:00
|
|
|
*
|
2007-03-13 21:22:33 +00:00
|
|
|
* \arg See also \ref AstCDR
|
|
|
|
|
*
|
|
|
|
|
* \ingroup cdr_drivers
|
2026-01-27 12:57:21 -07:00
|
|
|
*
|
|
|
|
|
* The logic for this module now resides in res/res_cdrel_custom.c.
|
|
|
|
|
*
|
2007-03-13 21:22:33 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/*** MODULEINFO
|
2026-01-27 12:57:21 -07:00
|
|
|
<depend>res_cdrel_custom</depend>
|
2007-03-13 21:22:33 +00:00
|
|
|
<depend>sqlite3</depend>
|
2011-07-14 20:28:54 +00:00
|
|
|
<support_level>extended</support_level>
|
2007-03-13 21:22:33 +00:00
|
|
|
***/
|
|
|
|
|
|
|
|
|
|
#include "asterisk.h"
|
|
|
|
|
|
|
|
|
|
#include <sqlite3.h>
|
|
|
|
|
|
|
|
|
|
#include "asterisk/cdr.h"
|
|
|
|
|
#include "asterisk/module.h"
|
2026-01-27 12:57:21 -07:00
|
|
|
#include "asterisk/res_cdrel_custom.h"
|
2007-03-13 21:22:33 +00:00
|
|
|
|
2026-01-27 12:57:21 -07:00
|
|
|
#define CONFIG "cdr_sqlite3_custom.conf"
|
2007-03-13 21:22:33 +00:00
|
|
|
|
2026-01-27 12:57:21 -07:00
|
|
|
#define CUSTOM_BACKEND_NAME "CDR sqlite3 custom backend"
|
2007-12-06 21:57:28 +00:00
|
|
|
|
2026-01-27 12:57:21 -07:00
|
|
|
static struct cdrel_configs *configs;
|
2007-03-13 21:22:33 +00:00
|
|
|
|
2026-01-27 12:57:21 -07:00
|
|
|
/*!
|
|
|
|
|
* Protects in-flight log transactions from reloads.
|
|
|
|
|
*/
|
|
|
|
|
static ast_rwlock_t configs_lock;
|
2007-12-06 21:57:28 +00:00
|
|
|
|
2026-01-27 12:57:21 -07:00
|
|
|
#define CDREL_RECORD_TYPE cdrel_record_cdr
|
|
|
|
|
#define CDREL_BACKEND_TYPE cdrel_backend_db
|
2007-03-13 21:22:33 +00:00
|
|
|
|
2026-01-27 12:57:21 -07:00
|
|
|
static int custom_log(struct ast_cdr *cdr)
|
2007-03-13 21:22:33 +00:00
|
|
|
{
|
|
|
|
|
int res = 0;
|
2009-03-02 17:18:48 +00:00
|
|
|
|
2026-01-27 12:57:21 -07:00
|
|
|
ast_rwlock_rdlock(&configs_lock);
|
|
|
|
|
res = cdrel_logger(configs, cdr);
|
|
|
|
|
ast_rwlock_unlock(&configs_lock);
|
2007-03-13 21:22:33 +00:00
|
|
|
|
|
|
|
|
return res;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int unload_module(void)
|
|
|
|
|
{
|
2026-01-27 12:57:21 -07:00
|
|
|
int res = 0;
|
2007-03-13 21:22:33 +00:00
|
|
|
|
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);
|
|
|
|
|
}
|
2009-06-22 16:09:50 +00:00
|
|
|
|
2026-01-27 12:57:21 -07:00
|
|
|
return res;
|
2007-03-13 21:22:33 +00:00
|
|
|
}
|
|
|
|
|
|
2026-01-27 12:57:21 -07:00
|
|
|
static enum ast_module_load_result load_module(void)
|
2007-03-13 21:22:33 +00:00
|
|
|
{
|
2026-01-27 12:57:21 -07:00
|
|
|
if (ast_rwlock_init(&configs_lock) != 0) {
|
2007-09-17 21:52:07 +00:00
|
|
|
return AST_MODULE_LOAD_DECLINE;
|
2008-12-13 08:36:35 +00:00
|
|
|
}
|
2007-03-13 21:22:33 +00:00
|
|
|
|
2026-01-27 12:57:21 -07:00
|
|
|
configs = cdrel_load_module(CDREL_BACKEND_TYPE, CDREL_RECORD_TYPE, CONFIG, CUSTOM_BACKEND_NAME, custom_log);
|
2007-03-13 21:22:33 +00:00
|
|
|
|
2026-01-27 12:57:21 -07:00
|
|
|
return configs ? AST_MODULE_LOAD_SUCCESS : AST_MODULE_LOAD_DECLINE;
|
2007-03-13 21:22:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int reload(void)
|
|
|
|
|
{
|
2009-06-22 16:09:50 +00:00
|
|
|
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);
|
2009-06-22 16:09:50 +00:00
|
|
|
return res;
|
2007-03-13 21:22:33 +00:00
|
|
|
}
|
|
|
|
|
|
2010-07-20 19:35:02 +00:00
|
|
|
AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_LOAD_ORDER, "SQLite3 Custom CDR Module",
|
2014-07-25 16:47:17 +00:00
|
|
|
.support_level = AST_MODULE_SUPPORT_EXTENDED,
|
2007-03-13 21:22:33 +00:00
|
|
|
.load = load_module,
|
|
|
|
|
.unload = unload_module,
|
|
|
|
|
.reload = reload,
|
2010-07-20 19:35:02 +00:00
|
|
|
.load_pri = AST_MODPRI_CDR_DRIVER,
|
2026-01-27 12:57:21 -07:00
|
|
|
.requires = "cdr,res_cdrel_custom",
|
2007-03-13 21:22:33 +00:00
|
|
|
);
|