refactor db stuff to use single string dsn to avoid code duplication and introduce switch_sql_queue_manager api to create transactional sql queues to aggregate a bunch of sql stmts into transactions

This commit is contained in:
Anthony Minessale
2012-10-09 20:20:32 -05:00
parent fc764b27bf
commit e1fe289672
20 changed files with 766 additions and 553 deletions
+4 -3
View File
@@ -626,9 +626,10 @@ struct sofia_profile {
uint32_t rtp_timeout_sec;
uint32_t rtp_hold_timeout_sec;
char *odbc_dsn;
char *odbc_user;
char *odbc_pass;
// switch_odbc_handle_t *master_odbc;
char *pre_trans_execute;
char *post_trans_execute;
char *inner_pre_trans_execute;
char *inner_post_trans_execute;
switch_queue_t *sql_queue;
char *acl[SOFIA_MAX_ACL];
uint32_t acl_count;
+9 -11
View File
@@ -4414,17 +4414,15 @@ switch_status_t config_sofia(int reload, char *profile_name)
sofia_set_flag(profile, TFLAG_CAPTURE);
nua_set_params(profile->nua, TPTAG_CAPT(mod_sofia_globals.capture_server), TAG_END());
} else if (!strcasecmp(var, "odbc-dsn") && !zstr(val)) {
if (switch_odbc_available() || switch_pgsql_available()) {
profile->odbc_dsn = switch_core_strdup(profile->pool, val);
if ((profile->odbc_user = strchr(profile->odbc_dsn, ':'))) {
*profile->odbc_user++ = '\0';
if ((profile->odbc_pass = strchr(profile->odbc_user, ':'))) {
*profile->odbc_pass++ = '\0';
}
}
} else {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "NEITHER ODBC NOR PGSQL ARE AVAILABLE!\n");
}
profile->odbc_dsn = switch_core_strdup(profile->pool, val);
} else if (!strcasecmp(var, "db-pre-trans-execute") && !zstr(val)) {
profile->pre_trans_execute = switch_core_strdup(profile->pool, val);
} else if (!strcasecmp(var, "db-post-trans-execute") && !zstr(val)) {
profile->post_trans_execute = switch_core_strdup(profile->pool, val);
} else if (!strcasecmp(var, "db-inner-pre-trans-execute") && !zstr(val)) {
profile->inner_pre_trans_execute = switch_core_strdup(profile->pool, val);
} else if (!strcasecmp(var, "db-inner-post-trans-execute") && !zstr(val)) {
profile->inner_post_trans_execute = switch_core_strdup(profile->pool, val);
} else if (!strcasecmp(var, "forward-unsolicited-mwi-notify")) {
if (switch_true(val)) {
sofia_set_pflag(profile, PFLAG_FORWARD_MWI_NOTIFY);
+19 -25
View File
@@ -36,8 +36,8 @@
#include "mod_sofia.h"
#include <switch_stun.h>
switch_cache_db_handle_t *sofia_glue_get_db_handle(sofia_profile_t *profile);
switch_cache_db_handle_t *_sofia_glue_get_db_handle(sofia_profile_t *profile, const char *file, const char *func, int line);
#define sofia_glue_get_db_handle(_p) _sofia_glue_get_db_handle(_p, __FILE__, __SWITCH_FUNC__, __LINE__)
void sofia_glue_set_image_sdp(private_object_t *tech_pvt, switch_t38_options_t *t38_options, int insist)
{
@@ -6361,33 +6361,22 @@ void sofia_glue_execute_sql_now(sofia_profile_t *profile, char **sqlp, switch_bo
}
switch_cache_db_handle_t *sofia_glue_get_db_handle(sofia_profile_t *profile)
switch_cache_db_handle_t *_sofia_glue_get_db_handle(sofia_profile_t *profile, const char *file, const char *func, int line)
{
switch_cache_db_connection_options_t options = { {0} };
switch_cache_db_handle_t *dbh = NULL;
char *dsn;
if (!zstr(profile->odbc_dsn)) {
char *dsn;
if ((dsn = strstr(profile->odbc_dsn, "pgsql;")) != NULL) {
options.pgsql_options.dsn = (char*)(dsn + 6);
if (switch_cache_db_get_db_handle(&dbh, SCDB_TYPE_PGSQL, &options) != SWITCH_STATUS_SUCCESS)
dbh = NULL;
} else {
options.odbc_options.dsn = profile->odbc_dsn;
options.odbc_options.user = profile->odbc_user;
options.odbc_options.pass = profile->odbc_pass;
if (switch_cache_db_get_db_handle(&dbh, SCDB_TYPE_ODBC, &options) != SWITCH_STATUS_SUCCESS)
dbh = NULL;
}
return dbh;
dsn = profile->odbc_dsn;
} else {
options.core_db_options.db_path = profile->dbname;
if (switch_cache_db_get_db_handle(&dbh, SCDB_TYPE_CORE_DB, &options) != SWITCH_STATUS_SUCCESS)
dbh = NULL;
return dbh;
dsn = profile->dbname;
}
if (_switch_cache_db_get_db_handle_dsn(&dbh, dsn, file, func, line) != SWITCH_STATUS_SUCCESS) {
dbh = NULL;
}
return dbh;
}
void sofia_glue_actually_execute_sql_trans(sofia_profile_t *profile, char *sql, switch_mutex_t *mutex)
@@ -6403,7 +6392,12 @@ void sofia_glue_actually_execute_sql_trans(sofia_profile_t *profile, char *sql,
switch_mutex_lock(mutex);
}
switch_cache_db_persistant_execute_trans(dbh, sql, 1);
switch_cache_db_persistant_execute_trans_full(dbh, sql, 1,
profile->pre_trans_execute,
profile->post_trans_execute,
profile->inner_pre_trans_execute,
profile->inner_post_trans_execute
);
switch_cache_db_release_db_handle(&dbh);