| Asterisk - The Open Source Telephony Project GIT-master-27fb039
    | 
PostgreSQL plugin for Asterisk RealTime Architecture. More...
#include "asterisk.h"#include <libpq-fe.h>#include "asterisk/file.h"#include "asterisk/channel.h"#include "asterisk/pbx.h"#include "asterisk/config.h"#include "asterisk/module.h"#include "asterisk/lock.h"#include "asterisk/utils.h"#include "asterisk/cli.h"
Go to the source code of this file.
| Data Structures | |
| struct | columns | 
| struct | tables::psql_columns | 
| struct | psql_tables | 
| struct | tables | 
| Macros | |
| #define | ESCAPE_CLAUSE (USE_BACKSLASH_AS_STRING ? " ESCAPE '\\'" : " ESCAPE '\\\\'") | 
| #define | ESCAPE_STRING(buffer, stringname) | 
| #define | has_schema_support (version > 70300 ? 1 : 0) | 
| #define | IS_SQL_LIKE_CLAUSE(x) ((x) && ast_ends_with(x, " LIKE")) | 
| #define | MAX_DB_OPTION_SIZE 64 | 
| #define | release_table(table) ast_rwlock_unlock(&(table)->lock); | 
| #define | RES_CONFIG_PGSQL_CONF "res_pgsql.conf" | 
| #define | USE_BACKSLASH_AS_STRING (version >= 90100 ? 1 : 0) | 
| Enumerations | |
| enum | { RQ_WARN , RQ_CREATECLOSE , RQ_CREATECHAR } | 
| Functions | |
| static void | __reg_module (void) | 
| static void | __unreg_module (void) | 
| static int | _pgsql_exec (const char *database, const char *tablename, const char *sql, PGresult **result) | 
| Helper function for pgsql_exec. For running queries, use pgsql_exec() | |
| struct ast_module * | AST_MODULE_SELF_SYM (void) | 
| AST_THREADSTORAGE_CUSTOM_SCOPE (escapebuf_buf, NULL, ast_free_ptr, static) | |
| AST_THREADSTORAGE_CUSTOM_SCOPE (findtable_buf, NULL, ast_free_ptr, static) | |
| AST_THREADSTORAGE_CUSTOM_SCOPE (semibuf_buf, NULL, ast_free_ptr, static) | |
| AST_THREADSTORAGE_CUSTOM_SCOPE (sql_buf, NULL, ast_free_ptr, static) | |
| AST_THREADSTORAGE_CUSTOM_SCOPE (where_buf, NULL, ast_free_ptr, static) | |
| static struct ast_config * | config_pgsql (const char *database, const char *table, const char *file, struct ast_config *cfg, struct ast_flags flags, const char *suggested_incl, const char *who_asked) | 
| static int | destroy_pgsql (const char *database, const char *table, const char *keyfield, const char *lookup, const struct ast_variable *fields) | 
| static void | destroy_table (struct tables *table) | 
| static struct columns * | find_column (struct tables *t, const char *colname) | 
| static struct tables * | find_table (const char *database, const char *orig_tablename) | 
| static char * | handle_cli_realtime_pgsql_cache (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) | 
| static char * | handle_cli_realtime_pgsql_status (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) | 
| static int | load_module (void) | 
| static int | parse_config (int reload) | 
| static int | pgsql_exec (const char *database, const char *tablename, const char *sql, PGresult **result) | 
| Do a postgres query, with reconnection support. | |
| static int | pgsql_reconnect (const char *database) | 
| static struct ast_config * | realtime_multi_pgsql (const char *database, const char *table, const struct ast_variable *fields) | 
| static struct ast_variable * | realtime_pgsql (const char *database, const char *tablename, const struct ast_variable *fields) | 
| static int | reload (void) | 
| static int | require_pgsql (const char *database, const char *tablename, va_list ap) | 
| static int | store_pgsql (const char *database, const char *table, const struct ast_variable *fields) | 
| static int | unload_module (void) | 
| static int | unload_pgsql (const char *database, const char *tablename) | 
| static int | update2_pgsql (const char *database, const char *tablename, const struct ast_variable *lookup_fields, const struct ast_variable *update_fields) | 
| static int | update_pgsql (const char *database, const char *tablename, const char *keyfield, const char *lookup, const struct ast_variable *fields) | 
PostgreSQL plugin for Asterisk RealTime Architecture.
PostgreSQL http://www.postgresql.org
Definition in file res_config_pgsql.c.
| #define ESCAPE_CLAUSE (USE_BACKSLASH_AS_STRING ? " ESCAPE '\\'" : " ESCAPE '\\\\'") | 
Definition at line 389 of file res_config_pgsql.c.
| #define ESCAPE_STRING | ( | buffer, | |
| stringname | |||
| ) | 
Definition at line 99 of file res_config_pgsql.c.
| #define has_schema_support (version > 70300 ? 1 : 0) | 
Definition at line 54 of file res_config_pgsql.c.
| #define IS_SQL_LIKE_CLAUSE | ( | x | ) | ((x) && ast_ends_with(x, " LIKE")) | 
Definition at line 388 of file res_config_pgsql.c.
| #define MAX_DB_OPTION_SIZE 64 | 
Definition at line 57 of file res_config_pgsql.c.
| #define release_table | ( | table | ) | ast_rwlock_unlock(&(table)->lock); | 
Definition at line 373 of file res_config_pgsql.c.
| #define RES_CONFIG_PGSQL_CONF "res_pgsql.conf" | 
Definition at line 50 of file res_config_pgsql.c.
| #define USE_BACKSLASH_AS_STRING (version >= 90100 ? 1 : 0) | 
Definition at line 55 of file res_config_pgsql.c.
| anonymous enum | 
| Enumerator | |
|---|---|
| RQ_WARN | |
| RQ_CREATECLOSE | |
| RQ_CREATECHAR | |
Definition at line 92 of file res_config_pgsql.c.
| 
 | static | 
Definition at line 1754 of file res_config_pgsql.c.
| 
 | static | 
Definition at line 1754 of file res_config_pgsql.c.
| 
 | static | 
Helper function for pgsql_exec. For running queries, use pgsql_exec()
Connect if not currently connected. Run the given query.
| database | database name we are connected to (used for error logging) | 
| tablename | table name we are connected to (used for error logging) | 
| sql | sql query string to execute | 
| result | pointer for where to store the result handle | 
Definition at line 145 of file res_config_pgsql.c.
References ast_debug, ast_log, LOG_ERROR, LOG_NOTICE, NULL, pgsql_reconnect(), pgsqlConn, and result.
Referenced by pgsql_exec().
| struct ast_module * AST_MODULE_SELF_SYM | ( | void | ) | 
Definition at line 1754 of file res_config_pgsql.c.
| AST_THREADSTORAGE_CUSTOM_SCOPE | ( | escapebuf_buf | , | 
| NULL | , | ||
| ast_free_ptr | , | ||
| static | |||
| ) | 
| AST_THREADSTORAGE_CUSTOM_SCOPE | ( | findtable_buf | , | 
| NULL | , | ||
| ast_free_ptr | , | ||
| static | |||
| ) | 
| AST_THREADSTORAGE_CUSTOM_SCOPE | ( | semibuf_buf | , | 
| NULL | , | ||
| ast_free_ptr | , | ||
| static | |||
| ) | 
| AST_THREADSTORAGE_CUSTOM_SCOPE | ( | sql_buf | , | 
| NULL | , | ||
| ast_free_ptr | , | ||
| static | |||
| ) | 
| AST_THREADSTORAGE_CUSTOM_SCOPE | ( | where_buf | , | 
| NULL | , | ||
| ast_free_ptr | , | ||
| static | |||
| ) | 
| 
 | static | 
Definition at line 1133 of file res_config_pgsql.c.
References ast_category_append(), ast_category_new_dynamic, ast_config_internal_load(), ast_copy_string(), ast_debug, ast_log, ast_mutex_lock, ast_mutex_unlock, ast_str_buffer(), ast_str_set(), ast_str_thread_get(), ast_variable_append(), ast_variable_new, dbname, last, LOG_WARNING, NULL, pgsql_exec(), pgsql_lock, RAII_VAR, RES_CONFIG_PGSQL_CONF, and result.
| 
 | static | 
Definition at line 1053 of file res_config_pgsql.c.
References ast_debug, ast_log, ast_mutex_lock, ast_mutex_unlock, ast_str_append(), ast_str_buffer(), ast_str_set(), ast_str_thread_get(), ast_strlen_zero(), dbname, ESCAPE_STRING, LOG_WARNING, ast_variable::name, ast_variable::next, NULL, pgsql_exec(), pgsql_lock, pgsql_reconnect(), pgsqlConn, RAII_VAR, result, and ast_variable::value.
| 
 | static | 
Definition at line 118 of file res_config_pgsql.c.
References ast_free, AST_LIST_REMOVE_HEAD, ast_rwlock_destroy, ast_rwlock_unlock, ast_rwlock_wrlock, tables::columns, columns::list, and tables::lock.
Referenced by find_table(), unload_module(), and unload_pgsql().
Definition at line 375 of file res_config_pgsql.c.
References AST_LIST_TRAVERSE, tables::columns, columns::list, columns::name, and NULL.
Referenced by update2_pgsql(), and update_pgsql().
| 
 | static | 
Definition at line 251 of file res_config_pgsql.c.
References ast_alloca, ast_calloc, ast_debug, AST_LIST_HEAD_INIT_NOLOCK, AST_LIST_INSERT_TAIL, AST_LIST_LOCK, AST_LIST_TRAVERSE, AST_LIST_UNLOCK, ast_log, ast_mutex_lock, ast_mutex_unlock, ast_rwlock_init, ast_rwlock_rdlock, ast_str_buffer(), ast_str_set(), ast_str_thread_get(), ast_strdupa, ast_strlen_zero(), ast_verb, tables::columns, destroy_table(), has_schema_support, columns::hasdefault, columns::len, tables::lock, LOG_ERROR, columns::name, tables::name, columns::notnull, NULL, pgsql_exec(), pgsql_lock, pgsqlConn, RAII_VAR, result, tables::table, and columns::type.
Referenced by handle_cli_realtime_pgsql_cache(), require_pgsql(), update2_pgsql(), and update_pgsql().
| 
 | static | 
Definition at line 1647 of file res_config_pgsql.c.
References a, ast_cli(), AST_LIST_LOCK, AST_LIST_TRAVERSE, AST_LIST_UNLOCK, ast_strdup, CLI_GENERATE, CLI_INIT, tables::columns, ast_cli_entry::command, find_table(), columns::len, columns::list, tables::list, columns::name, tables::name, columns::notnull, NULL, release_table, columns::type, and ast_cli_entry::usage.
| 
 | static | 
Definition at line 1701 of file res_config_pgsql.c.
References a, ast_cli(), ast_cli_print_timestr_fromseconds(), ast_mutex_lock, ast_mutex_unlock, ast_strlen_zero(), buf, CLI_FAILURE, CLI_GENERATE, CLI_INIT, CLI_SHOWUSAGE, CLI_SUCCESS, ast_cli_entry::command, connect_time, dbhost, dbname, dbport, dbsock, dbuser, NULL, pgsql_lock, pgsqlConn, and ast_cli_entry::usage.
| 
 | static | 
Definition at line 1390 of file res_config_pgsql.c.
References ARRAY_LEN, ast_cli_register_multiple, ast_config_engine_register(), AST_MODULE_LOAD_DECLINE, cli_realtime, parse_config(), and pgsql_engine.
| 
 | static | 
Definition at line 1435 of file res_config_pgsql.c.
References ast_config_destroy(), ast_config_load, ast_copy_string(), ast_debug, ast_log, ast_mutex_lock, ast_mutex_unlock, ast_strlen_zero(), ast_true(), ast_variable_retrieve(), ast_verb, config, CONFIG_FLAG_FILEUNCHANGED, CONFIG_STATUS_FILEINVALID, CONFIG_STATUS_FILEMISSING, CONFIG_STATUS_FILEUNCHANGED, dbappname, dbhost, dbname, dbpass, dbport, dbsock, dbuser, DEBUG_ATLEAST, LOG_DEBUG, LOG_WARNING, NULL, order_multi_row_results_by_initial_column, pgsql_lock, pgsql_reconnect(), pgsqlConn, RES_CONFIG_PGSQL_CONF, RQ_CREATECHAR, RQ_CREATECLOSE, and RQ_WARN.
| 
 | static | 
Do a postgres query, with reconnection support.
Connect if not currently connected. Run the given query and if we're disconnected afterwards, reconnect and query again.
| database | database name we are connected to (used for error logging) | 
| tablename | table name we are connected to (used for error logging) | 
| sql | sql query string to execute | 
| result | pointer for where to store the result handle | 
Definition at line 219 of file res_config_pgsql.c.
References _pgsql_exec(), ast_debug, ast_log, LOG_NOTICE, and result.
Referenced by config_pgsql(), destroy_pgsql(), find_table(), realtime_multi_pgsql(), realtime_pgsql(), require_pgsql(), store_pgsql(), update2_pgsql(), and update_pgsql().
| 
 | static | 
Definition at line 1587 of file res_config_pgsql.c.
References ast_copy_string(), ast_debug, ast_free, ast_log, ast_str_append(), ast_str_buffer(), ast_str_create, ast_str_set(), ast_strlen_zero(), connect_time, dbappname, dbhost, dbname, dbpass, dbport, dbsock, dbuser, LOG_ERROR, NULL, pgsqlConn, S_OR, and version.
| 
 | static | 
Definition at line 525 of file res_config_pgsql.c.
References ast_calloc, ast_category_append(), ast_category_new_anonymous, ast_category_rename(), ast_config_destroy(), ast_config_new(), ast_debug, ast_free, ast_log, ast_mutex_lock, ast_mutex_unlock, ast_realtime_decode_chunk(), ast_str_append(), ast_str_buffer(), ast_str_set(), ast_str_thread_get(), ast_strdupa, ast_strip(), ast_strlen_zero(), ast_variable_append(), ast_variable_new, dbname, ESCAPE_CLAUSE, ESCAPE_STRING, IS_SQL_LIKE_CLAUSE, LOG_ERROR, LOG_WARNING, ast_variable::name, ast_variable::next, NULL, order_multi_row_results_by_initial_column, pgsql_exec(), pgsql_lock, pgsql_reconnect(), pgsqlConn, RAII_VAR, result, strsep(), ast_variable::value, and var.
| 
 | static | 
Definition at line 391 of file res_config_pgsql.c.
References ast_calloc, ast_debug, ast_free, ast_log, ast_mutex_lock, ast_mutex_unlock, ast_realtime_decode_chunk(), ast_str_append(), ast_str_buffer(), ast_str_set(), ast_str_thread_get(), ast_strip(), ast_strlen_zero(), ast_variable_new, dbname, ESCAPE_CLAUSE, ESCAPE_STRING, IS_SQL_LIKE_CLAUSE, LOG_ERROR, LOG_WARNING, ast_variable::name, ast_variable::next, NULL, pgsql_exec(), pgsql_lock, pgsql_reconnect(), pgsqlConn, RAII_VAR, result, strsep(), ast_variable::value, and var.
| 
 | static | 
Definition at line 1428 of file res_config_pgsql.c.
References parse_config().
| 
 | static | 
Definition at line 1212 of file res_config_pgsql.c.
References ast_debug, ast_free, AST_LIST_TRAVERSE, ast_log, ast_mutex_lock, ast_mutex_unlock, ast_rq_is_int(), ast_str_buffer(), ast_str_create, ast_str_set(), tables::database, dbname, find_table(), columns::len, tables::list, LOG_ERROR, LOG_WARNING, columns::name, pgsql_exec(), pgsql_lock, release_table, result, RQ_CHAR, RQ_CREATECHAR, 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, RQ_WARN, tables::table, type, and columns::type.
| 
 | static | 
Definition at line 970 of file res_config_pgsql.c.
References ast_debug, ast_log, ast_mutex_lock, ast_mutex_unlock, ast_str_append(), ast_str_buffer(), ast_str_set(), ast_str_thread_get(), buf, dbname, ESCAPE_STRING, LOG_WARNING, ast_variable::name, ast_variable::next, NULL, pgsql_exec(), pgsql_lock, pgsql_reconnect(), pgsqlConn, RAII_VAR, result, and ast_variable::value.
| 
 | static | 
Definition at line 1402 of file res_config_pgsql.c.
References ARRAY_LEN, ast_cli_unregister_multiple(), ast_config_engine_deregister(), AST_LIST_LOCK, AST_LIST_REMOVE_HEAD, AST_LIST_UNLOCK, ast_mutex_lock, ast_mutex_unlock, cli_realtime, destroy_table(), tables::list, NULL, pgsql_engine, pgsql_lock, pgsqlConn, and tables::table.
| 
 | static | 
Definition at line 1348 of file res_config_pgsql.c.
References ast_debug, AST_LIST_LOCK, AST_LIST_REMOVE_CURRENT, AST_LIST_TRAVERSE_SAFE_BEGIN, AST_LIST_TRAVERSE_SAFE_END, AST_LIST_UNLOCK, tables::database, dbname, destroy_table(), tables::list, and tables::name.
| 
 | static | 
Definition at line 844 of file res_config_pgsql.c.
References ast_debug, ast_log, ast_mutex_lock, ast_mutex_unlock, ast_str_append(), ast_str_buffer(), ast_str_set(), ast_str_thread_get(), tables::database, dbname, ESCAPE_STRING, find_column(), find_table(), first, LOG_ERROR, LOG_NOTICE, LOG_WARNING, ast_variable::name, ast_variable::next, NULL, pgsql_exec(), pgsql_lock, pgsql_reconnect(), pgsqlConn, RAII_VAR, release_table, result, tables::table, and ast_variable::value.
| 
 | static | 
Definition at line 702 of file res_config_pgsql.c.
References ast_debug, AST_LIST_TRAVERSE, ast_log, ast_mutex_lock, ast_mutex_unlock, ast_str_append(), ast_str_buffer(), ast_str_set(), ast_str_thread_get(), tables::columns, dbname, ESCAPE_STRING, find_column(), find_table(), columns::list, LOG_ERROR, LOG_NOTICE, LOG_WARNING, columns::name, ast_variable::name, ast_variable::next, NULL, pgsql_exec(), pgsql_lock, pgsql_reconnect(), pgsqlConn, RAII_VAR, release_table, result, tables::table, and ast_variable::value.
| 
 | static | 
Definition at line 1754 of file res_config_pgsql.c.
| 
 | static | 
Definition at line 1754 of file res_config_pgsql.c.
| 
 | static | 
Definition at line 94 of file res_config_pgsql.c.
Referenced by load_module(), and unload_module().
| 
 | static | 
Definition at line 84 of file res_config_pgsql.c.
Referenced by handle_cli_realtime_pgsql_status(), and pgsql_reconnect().
| 
 | static | 
Definition at line 81 of file res_config_pgsql.c.
Referenced by parse_config(), and pgsql_reconnect().
| 
 | static | 
Definition at line 77 of file res_config_pgsql.c.
Referenced by handle_cli_realtime_pgsql_status(), parse_config(), and pgsql_reconnect().
| 
 | static | 
Definition at line 80 of file res_config_pgsql.c.
Referenced by config_pgsql(), db_open(), destroy_pgsql(), handle_cli_realtime_pgsql_status(), parse_config(), pgsql_reconnect(), realtime_multi_pgsql(), realtime_pgsql(), require_pgsql(), store_pgsql(), unload_pgsql(), update2_pgsql(), and update_pgsql().
| 
 | static | 
Definition at line 79 of file res_config_pgsql.c.
Referenced by parse_config(), and pgsql_reconnect().
| 
 | static | 
Definition at line 83 of file res_config_pgsql.c.
Referenced by handle_cli_realtime_pgsql_status(), parse_config(), and pgsql_reconnect().
| 
 | static | 
Definition at line 82 of file res_config_pgsql.c.
Referenced by handle_cli_realtime_pgsql_status(), parse_config(), and pgsql_reconnect().
| 
 | static | 
Definition at line 78 of file res_config_pgsql.c.
Referenced by handle_cli_realtime_pgsql_status(), parse_config(), and pgsql_reconnect().
| 
 | static | 
Definition at line 85 of file res_config_pgsql.c.
Referenced by parse_config(), and realtime_multi_pgsql().
| 
 | static | 
Definition at line 1377 of file res_config_pgsql.c.
Referenced by load_module(), and unload_module().
| 
 | static | 
Definition at line 43 of file res_config_pgsql.c.
Referenced by config_pgsql(), destroy_pgsql(), find_table(), handle_cli_realtime_pgsql_status(), parse_config(), realtime_multi_pgsql(), realtime_pgsql(), require_pgsql(), store_pgsql(), unload_module(), update2_pgsql(), and update_pgsql().
| 
 | static | 
Definition at line 52 of file res_config_pgsql.c.
Referenced by _pgsql_exec(), destroy_pgsql(), find_table(), handle_cli_realtime_pgsql_status(), parse_config(), pgsql_reconnect(), realtime_multi_pgsql(), realtime_pgsql(), store_pgsql(), unload_module(), update2_pgsql(), and update_pgsql().
| 
 | static | 
| enum { ... } requirements | 
| 
 | static | 
Definition at line 53 of file res_config_pgsql.c.
Referenced by pgsql_reconnect().