Asterisk - The Open Source Telephony Project GIT-master-d856a3e
|
MySQL CDR backend. More...
#include "asterisk.h"
#include <sys/stat.h>
#include <mysql/mysql.h>
#include <mysql/errmsg.h>
#include "asterisk/channel.h"
#include "asterisk/logger.h"
#include "asterisk/config.h"
#include "asterisk/module.h"
#include "asterisk/lock.h"
#include "asterisk/options.h"
#include "asterisk/cli.h"
#include "asterisk/utils.h"
#include "asterisk/threadstorage.h"
#include "asterisk/strings.h"
Go to the source code of this file.
Data Structures | |
struct | columns |
struct | databases |
struct | tables::mysql_columns |
struct | mysql_conn |
struct | mysql_tables |
struct | tables |
Macros | |
#define | ESCAPE_STRING(buf, var) |
#define | IS_SQL_LIKE_CLAUSE(x) ((x) && ast_ends_with(x, " LIKE")) |
#define | READHANDLE 0 |
#define | release_database(a) ast_mutex_unlock(&(a)->lock) |
#define | RES_CONFIG_MYSQL_CONF "res_config_mysql.conf" |
#define | RES_CONFIG_MYSQL_CONF_OLD "res_mysql.conf" |
#define | WRITEHANDLE 1 |
Enumerations | |
enum | requirements { RQ_WARN , RQ_CREATECLOSE , RQ_CREATECHAR } |
Functions | |
static void | __init_find_buf (void) |
static void | __init_modify2_buf (void) |
static void | __init_modify3_buf (void) |
static void | __init_modify_buf (void) |
static void | __init_scratch2_buf (void) |
static void | __init_scratch_buf (void) |
static void | __init_sql2_buf (void) |
static void | __init_sql_buf (void) |
static void | __reg_module (void) |
static void | __unreg_module (void) |
struct ast_module * | AST_MODULE_SELF_SYM (void) |
static struct ast_config * | config_mysql (const char *database, const char *table, const char *file, struct ast_config *cfg, struct ast_flags config_flags, const char *unused, const char *who_asked) |
static char * | decode_chunk (char *chunk) |
static int | destroy_mysql (const char *database, const char *table, const char *keyfield, const char *lookup, const struct ast_variable *rt_fields) |
static void | destroy_table (struct tables *table) |
static struct columns * | find_column (struct tables *table, const char *colname) |
static struct mysql_conn * | find_database (const char *database, int for_write) |
static struct tables * | find_table (const char *database, const char *tablename) |
static char * | handle_cli_realtime_mysql_cache (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) |
static char * | handle_cli_realtime_mysql_status (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) |
static int | load_module (void) |
static int | load_mysql_config (struct ast_config *config, const char *category, struct mysql_conn *conn) |
static int | mysql_reconnect (struct mysql_conn *conn) |
static int | parse_config (int reload) |
static struct ast_config * | realtime_multi_mysql (const char *database, const char *table, const struct ast_variable *rt_fields) |
static struct ast_variable * | realtime_mysql (const char *database, const char *table, const struct ast_variable *rt_fields) |
static void | release_table (struct tables *table) |
static int | reload (void) |
static int | require_mysql (const char *database, const char *tablename, va_list ap) |
static int | store_mysql (const char *database, const char *table, const struct ast_variable *rt_fields) |
static int | unload_module (void) |
static int | unload_mysql (const char *database, const char *tablename) |
static int | update2_mysql (const char *database, const char *tablename, const struct ast_variable *lookup_fields, const struct ast_variable *update_fields) |
static int | update_mysql (const char *database, const char *tablename, const char *keyfield, const char *lookup, const struct ast_variable *rt_fields) |
Variables | |
static struct ast_module_info | __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_LOAD_ORDER , .description = "MySQL RealTime Configuration Driver" , .key = "This paragraph is copyright (c) 2006 by Digium, Inc. \In order for your module to load, it must return this \key via a function called \"key\". Any code which \includes this paragraph must be licensed under the GNU \General Public License version 2 or later (at your \option). In addition to Digium's general reservations \of rights, Digium expressly reserves the right to \allow other parties to license this paragraph under \different terms. Any use of Digium, Inc. trademarks or \logos (including \"Asterisk\" or \"Digium\") without \express written permission of Digium, Inc. is prohibited.\n" , .buildopt_sum = AST_BUILDOPT_SUM, .support_level = AST_MODULE_SUPPORT_EXTENDED, .load = load_module, .unload = unload_module, .reload = reload, .load_pri = AST_MODPRI_REALTIME_DRIVER, .requires = "extconfig", } |
static const struct ast_module_info * | ast_module_info = &__mod_info |
static struct ast_cli_entry | cli_realtime_mysql_status [] |
static struct databases | databases = { .first = NULL, .last = NULL, .lock = { PTHREAD_RWLOCK_INITIALIZER , NULL, {1, 0} } , } |
static char * | ESCAPE_CLAUSE = " ESCAPE '\\\\'" |
static struct ast_threadstorage | find_buf = { .once = PTHREAD_ONCE_INIT , .key_init = __init_find_buf , .custom_init = NULL , } |
static struct ast_threadstorage | modify2_buf = { .once = PTHREAD_ONCE_INIT , .key_init = __init_modify2_buf , .custom_init = NULL , } |
static struct ast_threadstorage | modify3_buf = { .once = PTHREAD_ONCE_INIT , .key_init = __init_modify3_buf , .custom_init = NULL , } |
static struct ast_threadstorage | modify_buf = { .once = PTHREAD_ONCE_INIT , .key_init = __init_modify_buf , .custom_init = NULL , } |
static struct ast_config_engine | mysql_engine |
static struct mysql_tables | mysql_tables = { .first = NULL, .last = NULL, .lock = { PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP , NULL, {1, 0} } , } |
static struct ast_threadstorage | scratch2_buf = { .once = PTHREAD_ONCE_INIT , .key_init = __init_scratch2_buf , .custom_init = NULL , } |
static struct ast_threadstorage | scratch_buf = { .once = PTHREAD_ONCE_INIT , .key_init = __init_scratch_buf , .custom_init = NULL , } |
static struct ast_threadstorage | sql2_buf = { .once = PTHREAD_ONCE_INIT , .key_init = __init_sql2_buf , .custom_init = NULL , } |
static struct ast_threadstorage | sql_buf = { .once = PTHREAD_ONCE_INIT , .key_init = __init_sql_buf , .custom_init = NULL , } |
MySQL CDR backend.
Definition in file res_config_mysql.c.
Definition at line 54 of file res_config_mysql.c.
#define IS_SQL_LIKE_CLAUSE | ( | x | ) | ((x) && ast_ends_with(x, " LIKE")) |
Definition at line 305 of file res_config_mysql.c.
#define READHANDLE 0 |
Definition at line 51 of file res_config_mysql.c.
#define release_database | ( | a | ) | ast_mutex_unlock(&(a)->lock) |
Definition at line 162 of file res_config_mysql.c.
#define RES_CONFIG_MYSQL_CONF "res_config_mysql.conf" |
Definition at line 49 of file res_config_mysql.c.
#define RES_CONFIG_MYSQL_CONF_OLD "res_mysql.conf" |
Definition at line 50 of file res_config_mysql.c.
#define WRITEHANDLE 1 |
Definition at line 52 of file res_config_mysql.c.
enum requirements |
|
static |
Definition at line 74 of file res_config_mysql.c.
|
static |
Definition at line 78 of file res_config_mysql.c.
|
static |
Definition at line 79 of file res_config_mysql.c.
|
static |
Definition at line 77 of file res_config_mysql.c.
|
static |
Definition at line 76 of file res_config_mysql.c.
|
static |
Definition at line 75 of file res_config_mysql.c.
|
static |
Definition at line 73 of file res_config_mysql.c.
|
static |
Definition at line 72 of file res_config_mysql.c.
|
static |
Definition at line 1563 of file res_config_mysql.c.
|
static |
Definition at line 1563 of file res_config_mysql.c.
struct ast_module * AST_MODULE_SELF_SYM | ( | void | ) |
Definition at line 1563 of file res_config_mysql.c.
|
static |
Definition at line 876 of file res_config_mysql.c.
References ast_category_append(), ast_category_new_dynamic, ast_clear_flag, ast_config_internal_load(), ast_debug, ast_log, ast_str_buffer(), ast_str_set(), ast_str_strlen(), ast_str_thread_get(), ast_variable_append(), ast_variable_new, CONFIG_FLAG_FILEUNCHANGED, make_ari_stubs::file, find_database(), last, LOG_WARNING, mysql_reconnect(), NULL, release_database, RES_CONFIG_MYSQL_CONF, result, sql_buf, and table.
|
static |
Definition at line 293 of file res_config_mysql.c.
Referenced by realtime_multi_mysql(), and realtime_mysql().
|
static |
Definition at line 810 of file res_config_mysql.c.
References ast_debug, ast_log, ast_str_append(), ast_str_buffer(), ast_str_set(), ast_str_strlen(), ast_str_thread_get(), ast_strlen_zero(), buf, ESCAPE_STRING, find_database(), LOG_WARNING, mysql_reconnect(), ast_variable::name, ast_variable::next, release_database, scratch_buf, sql_buf, table, and ast_variable::value.
|
static |
Definition at line 164 of file res_config_mysql.c.
References ast_free, AST_LIST_REMOVE_HEAD, ast_mutex_destroy, ast_mutex_lock, ast_mutex_unlock, columns::list, and table.
Referenced by find_table(), unload_module(), and unload_mysql().
Definition at line 280 of file res_config_mysql.c.
References AST_LIST_TRAVERSE, columns::list, columns::name, and table.
Referenced by update2_mysql(), and update_mysql().
|
static |
Definition at line 132 of file res_config_mysql.c.
References ast_alloca, ast_mutex_lock, AST_RWLIST_RDLOCK, AST_RWLIST_TRAVERSE, AST_RWLIST_UNLOCK, and ast_strdupa.
Referenced by config_mysql(), destroy_mysql(), find_table(), realtime_multi_mysql(), realtime_mysql(), store_mysql(), update2_mysql(), and update_mysql().
|
static |
Definition at line 176 of file res_config_mysql.c.
References ast_calloc, AST_LIST_HEAD_INIT_NOLOCK, AST_LIST_INSERT_TAIL, AST_LIST_LOCK, AST_LIST_TRAVERSE, AST_LIST_UNLOCK, ast_log, ast_mutex_init, ast_mutex_lock, ast_str_buffer(), ast_str_set(), ast_str_strlen(), ast_str_thread_get(), ast_verb, destroy_table(), columns::dflt, find_buf, find_database(), columns::len, LOG_ERROR, mysql_reconnect(), columns::name, columns::null, NULL, release_database, result, table, and columns::type.
Referenced by handle_cli_realtime_mysql_cache(), require_mysql(), update2_mysql(), and update_mysql().
|
static |
Definition at line 1394 of file res_config_mysql.c.
References a, ast_cli(), AST_LIST_LOCK, AST_LIST_TRAVERSE, AST_LIST_UNLOCK, AST_RWLIST_RDLOCK, AST_RWLIST_TRAVERSE, AST_RWLIST_UNLOCK, ast_strdup, CLI_GENERATE, CLI_INIT, CLI_SUCCESS, tables::columns, ast_cli_entry::command, tables::database, find_table(), columns::len, columns::list, tables::list, columns::name, tables::name, NULL, release_table(), columns::type, and ast_cli_entry::usage.
|
static |
Definition at line 1474 of file res_config_mysql.c.
References a, ast_cli(), AST_RWLIST_RDLOCK, AST_RWLIST_TRAVERSE, AST_RWLIST_UNLOCK, ast_strdup, ast_strlen_zero(), CLI_GENERATE, CLI_INIT, CLI_SHOWUSAGE, CLI_SUCCESS, ast_cli_entry::command, mysql_reconnect(), NULL, status, type, and ast_cli_entry::usage.
|
static |
Definition at line 1149 of file res_config_mysql.c.
References ast_cli_register_multiple, ast_config_engine_register(), ast_verb, cli_realtime_mysql_status, mysql_engine, and parse_config().
|
static |
Definition at line 1242 of file res_config_mysql.c.
References ast_copy_string(), ast_debug, ast_log, ast_strlen_zero(), ast_variable_retrieve(), config, conn, LOG_WARNING, RQ_CREATECHAR, RQ_CREATECLOSE, and RQ_WARN.
Referenced by parse_config().
|
static |
Definition at line 1327 of file res_config_mysql.c.
References ast_debug, ast_log, ast_strlen_zero(), conn, LOG_ERROR, LOG_WARNING, and NULL.
Referenced by config_mysql(), destroy_mysql(), find_table(), handle_cli_realtime_mysql_status(), realtime_multi_mysql(), realtime_mysql(), store_mysql(), update2_mysql(), and update_mysql().
|
static |
Definition at line 1193 of file res_config_mysql.c.
References ast_calloc, ast_category_browse(), ast_config_destroy(), ast_config_load, ast_log, ast_mutex_init, AST_RWLIST_INSERT_TAIL, AST_RWLIST_TRAVERSE, AST_RWLIST_UNLOCK, AST_RWLIST_WRLOCK, config, CONFIG_FLAG_FILEUNCHANGED, CONFIG_STATUS_FILEINVALID, CONFIG_STATUS_FILEMISSING, CONFIG_STATUS_FILEUNCHANGED, load_mysql_config(), LOG_ERROR, LOG_WARNING, NULL, reload(), RES_CONFIG_MYSQL_CONF, and RES_CONFIG_MYSQL_CONF_OLD.
Referenced by load_module(), and reload().
|
static |
Definition at line 420 of file res_config_mysql.c.
References ast_category_append(), ast_category_new_anonymous, ast_category_rename(), ast_config_destroy(), ast_config_new(), ast_debug, ast_log, ast_str_append(), ast_str_buffer(), ast_str_set(), ast_str_strlen(), ast_str_thread_get(), ast_strdupa, ast_strip(), ast_strlen_zero(), ast_variable_append(), ast_variable_new, buf, decode_chunk(), ESCAPE_CLAUSE, ESCAPE_STRING, find_database(), IS_SQL_LIKE_CLAUSE, LOG_WARNING, mysql_reconnect(), name, ast_variable::name, ast_variable::next, NULL, release_database, result, scratch_buf, sql_buf, strsep(), table, ast_variable::value, and var.
|
static |
Definition at line 310 of file res_config_mysql.c.
References ast_debug, ast_log, ast_str_append(), ast_str_buffer(), ast_str_set(), ast_str_strlen(), ast_str_thread_get(), ast_strlen_zero(), ast_variable_new, buf, decode_chunk(), ESCAPE_CLAUSE, ESCAPE_STRING, find_database(), IS_SQL_LIKE_CLAUSE, LOG_WARNING, mysql_reconnect(), name, ast_variable::name, ast_variable::next, NULL, release_database, result, scratch_buf, sql_buf, strsep(), table, ast_variable::value, and var.
|
static |
Definition at line 273 of file res_config_mysql.c.
References ast_mutex_unlock, and table.
Referenced by handle_cli_realtime_mysql_cache(), require_mysql(), update2_mysql(), and update_mysql().
|
static |
Definition at line 1186 of file res_config_mysql.c.
References ast_verb, and parse_config().
Referenced by __ast_http_load(), __ast_udptl_reload(), __init_manager(), _dsp_init(), aco_process_config(), ast_cli_perms_init(), ast_res_pjsip_init_options_handling(), iax_provision_reload(), load_config(), load_indications(), parse_config(), private_enum_init(), process_config(), reload_config(), rtp_reload(), set_config(), sip_options_synchronize(), sorcery_config_internal_load(), sorcery_memory_cache_ami_stale_object(), and sorcery_memory_cache_stale().
|
static |
Definition at line 973 of file res_config_mysql.c.
References AST_LIST_TRAVERSE, ast_log, ast_rq_is_int(), tables::database, find_table(), columns::len, tables::list, LOG_WARNING, columns::name, release_table(), RQ_CHAR, RQ_DATE, RQ_DATETIME, RQ_FLOAT, RQ_INTEGER1, RQ_INTEGER2, RQ_INTEGER3, RQ_INTEGER4, RQ_INTEGER8, RQ_UINTEGER1, RQ_UINTEGER2, RQ_UINTEGER3, RQ_UINTEGER4, RQ_UINTEGER8, strcasestr(), table, type, and columns::type.
|
static |
Definition at line 752 of file res_config_mysql.c.
References ast_debug, ast_log, ast_str_append(), ast_str_buffer(), ast_str_set(), ast_str_strlen(), ast_str_thread_get(), buf, ESCAPE_STRING, find_database(), LOG_WARNING, mysql_reconnect(), ast_variable::name, ast_variable::next, release_database, scratch_buf, sql2_buf, sql_buf, table, and ast_variable::value.
|
static |
Definition at line 1159 of file res_config_mysql.c.
References ast_cli_unregister_multiple(), ast_config_engine_deregister(), ast_free, AST_LIST_LOCK, AST_LIST_REMOVE_HEAD, AST_LIST_UNLOCK, ast_mutex_destroy, AST_RWLIST_REMOVE_HEAD, AST_RWLIST_UNLOCK, AST_RWLIST_WRLOCK, ast_verb, cli_realtime_mysql_status, destroy_table(), tables::list, mysql_engine, and table.
|
static |
Definition at line 957 of file res_config_mysql.c.
References AST_LIST_LOCK, AST_LIST_REMOVE_CURRENT, AST_LIST_TRAVERSE_SAFE_BEGIN, AST_LIST_TRAVERSE_SAFE_END, AST_LIST_UNLOCK, destroy_table(), tables::list, and tables::name.
|
static |
Definition at line 655 of file res_config_mysql.c.
References ast_debug, ast_log, ast_str_append(), ast_str_buffer(), ast_str_set(), ast_str_strlen(), ast_str_thread_get(), buf, ESCAPE_STRING, find_column(), find_database(), find_table(), first, LOG_ERROR, LOG_WARNING, mysql_reconnect(), ast_variable::name, ast_variable::next, NULL, release_database, release_table(), scratch_buf, sql2_buf, sql_buf, table, and ast_variable::value.
|
static |
Definition at line 554 of file res_config_mysql.c.
References ast_debug, ast_log, ast_str_append(), ast_str_buffer(), ast_str_set(), ast_str_strlen(), ast_str_thread_get(), buf, ESCAPE_STRING, find_column(), find_database(), find_table(), LOG_ERROR, LOG_WARNING, mysql_reconnect(), ast_variable::name, ast_variable::next, NULL, release_database, release_table(), scratch_buf, sql_buf, table, and ast_variable::value.
|
static |
Definition at line 1563 of file res_config_mysql.c.
|
static |
Definition at line 1563 of file res_config_mysql.c.
|
static |
Definition at line 127 of file res_config_mysql.c.
Referenced by load_module(), and unload_module().
|
static |
|
static |
Definition at line 308 of file res_config_mysql.c.
Referenced by realtime_multi_mysql(), and realtime_mysql().
|
static |
Definition at line 74 of file res_config_mysql.c.
Referenced by find_table().
|
static |
Definition at line 78 of file res_config_mysql.c.
|
static |
Definition at line 79 of file res_config_mysql.c.
|
static |
Definition at line 77 of file res_config_mysql.c.
|
static |
Definition at line 1136 of file res_config_mysql.c.
Referenced by load_module(), and unload_module().
|
static |
|
static |
Definition at line 76 of file res_config_mysql.c.
|
static |
Definition at line 75 of file res_config_mysql.c.
Referenced by destroy_mysql(), realtime_multi_mysql(), realtime_mysql(), store_mysql(), update2_mysql(), and update_mysql().
|
static |
Definition at line 73 of file res_config_mysql.c.
Referenced by store_mysql(), and update2_mysql().
|
static |
Definition at line 72 of file res_config_mysql.c.
Referenced by config_mysql(), destroy_mysql(), realtime_multi_mysql(), realtime_mysql(), store_mysql(), update2_mysql(), and update_mysql().