From b24c018c45d94a895e8c1dc9f13b8311e4a5626e Mon Sep 17 00:00:00 2001 From: Brian West Date: Wed, 13 Jan 2010 01:40:11 +0000 Subject: [PATCH] SCA tweaks git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@16271 d0543943-73ff-0310-b7d9-9358b9ac24b2 --- src/include/switch_odbc.h | 5 +- .../mod_easyroute/mod_easyroute.c | 4 +- .../mod_nibblebill/mod_nibblebill.c | 2 +- .../endpoints/mod_dingaling/mod_dingaling.c | 6 +-- src/mod/endpoints/mod_sofia/sofia.c | 50 +++++++++++++++---- src/mod/endpoints/mod_sofia/sofia_glue.c | 49 +++++++++--------- src/mod/endpoints/mod_sofia/sofia_presence.c | 24 ++++++--- src/mod/endpoints/mod_sofia/sofia_reg.c | 18 ++++--- .../mod_spidermonkey_odbc.c | 4 +- src/switch_channel.c | 2 + src/switch_core_sqldb.c | 10 ++-- src/switch_odbc.c | 34 +++++++++++-- 12 files changed, 139 insertions(+), 69 deletions(-) diff --git a/src/include/switch_odbc.h b/src/include/switch_odbc.h index 7602b9c8d0..9e158b459b 100644 --- a/src/include/switch_odbc.h +++ b/src/include/switch_odbc.h @@ -56,11 +56,12 @@ SWITCH_DECLARE(switch_odbc_status_t) switch_odbc_handle_disconnect(switch_odbc_h SWITCH_DECLARE(switch_odbc_status_t) switch_odbc_handle_connect(switch_odbc_handle_t *handle); SWITCH_DECLARE(void) switch_odbc_handle_destroy(switch_odbc_handle_t **handlep); SWITCH_DECLARE(switch_odbc_state_t) switch_odbc_handle_get_state(switch_odbc_handle_t *handle); -SWITCH_DECLARE(switch_odbc_status_t) switch_odbc_handle_exec(switch_odbc_handle_t *handle, const char *sql, switch_odbc_statement_handle_t * rstmt); +SWITCH_DECLARE(switch_odbc_status_t) switch_odbc_handle_exec(switch_odbc_handle_t *handle, const char *sql, switch_odbc_statement_handle_t *rstmt, char **err); SWITCH_DECLARE(switch_odbc_status_t) switch_odbc_handle_exec_string(switch_odbc_handle_t *handle, const char *sql, char *resbuf, - size_t len); + size_t len, + char **err); SWITCH_DECLARE(switch_bool_t) switch_odbc_available(void); SWITCH_DECLARE(switch_odbc_status_t) switch_odbc_statement_handle_free(switch_odbc_statement_handle_t * stmt); diff --git a/src/mod/applications/mod_easyroute/mod_easyroute.c b/src/mod/applications/mod_easyroute/mod_easyroute.c index 6f0a621677..7d6ac2a5c0 100644 --- a/src/mod/applications/mod_easyroute/mod_easyroute.c +++ b/src/mod/applications/mod_easyroute/mod_easyroute.c @@ -152,10 +152,10 @@ static switch_status_t load_config(void) } switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Connected ODBC DSN: %s\n", globals.db_dsn); if (!globals.custom_query){ - if (switch_odbc_handle_exec(globals.master_odbc, "select count(*) from numbers", NULL) != SWITCH_STATUS_SUCCESS) { + if (switch_odbc_handle_exec(globals.master_odbc, "select count(*) from numbers", NULL, NULL) != SWITCH_STATUS_SUCCESS) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Cannot find SQL Database! (Where\'s the numbers table\?\?)\n"); } - if (switch_odbc_handle_exec(globals.master_odbc, "select count(*) from gateways", NULL) != SWITCH_STATUS_SUCCESS) { + if (switch_odbc_handle_exec(globals.master_odbc, "select count(*) from gateways", NULL, NULL) != SWITCH_STATUS_SUCCESS) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Cannot find SQL Database! (Where\'s the gateways table\?\?)\n"); } } diff --git a/src/mod/applications/mod_nibblebill/mod_nibblebill.c b/src/mod/applications/mod_nibblebill/mod_nibblebill.c index 6b84e1a0a5..679be6be3e 100644 --- a/src/mod/applications/mod_nibblebill/mod_nibblebill.c +++ b/src/mod/applications/mod_nibblebill/mod_nibblebill.c @@ -308,7 +308,7 @@ static switch_status_t bill_event(float billamount, const char *billaccount) switch_snprintf(sql, 1024, SQL_SAVE, globals.db_table, globals.db_column_cash, globals.db_column_cash, billamount, globals.db_column_account, billaccount); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Doing update query\n[%s]\n", sql); - if (switch_odbc_handle_exec(globals.master_odbc, sql, &stmt) != SWITCH_ODBC_SUCCESS) { + if (switch_odbc_handle_exec(globals.master_odbc, sql, &stmt, NULL) != SWITCH_ODBC_SUCCESS) { char *err_str; err_str = switch_odbc_handle_get_error(globals.master_odbc, stmt); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "ERR: [%s]\n[%s]\n", sql, switch_str_nil(err_str)); diff --git a/src/mod/endpoints/mod_dingaling/mod_dingaling.c b/src/mod/endpoints/mod_dingaling/mod_dingaling.c index 3dafaf06b1..04c7051f3a 100644 --- a/src/mod/endpoints/mod_dingaling/mod_dingaling.c +++ b/src/mod/endpoints/mod_dingaling/mod_dingaling.c @@ -271,7 +271,7 @@ static void mdl_execute_sql(mdl_profile_t *profile, char *sql, switch_mutex_t *m if (switch_odbc_available() && profile->odbc_dsn) { switch_odbc_statement_handle_t stmt; - if (switch_odbc_handle_exec(profile->master_odbc, sql, &stmt) != SWITCH_ODBC_SUCCESS) { + if (switch_odbc_handle_exec(profile->master_odbc, sql, &stmt, NULL) != SWITCH_ODBC_SUCCESS) { char *err_str; err_str = switch_odbc_handle_get_error(profile->master_odbc, stmt); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "ERR: [%s]\n[%s]\n", sql, switch_str_nil(err_str)); @@ -2432,7 +2432,7 @@ static switch_status_t soft_reload(void) } switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Connected ODBC DSN: %s\n", profile->odbc_dsn); - switch_odbc_handle_exec(profile->master_odbc, sub_sql, NULL); + switch_odbc_handle_exec(profile->master_odbc, sub_sql, NULL, NULL); //mdl_execute_sql(profile, sub_sql, NULL); } else { if ((db = switch_core_db_open_file(profile->dbname))) { @@ -2581,7 +2581,7 @@ static switch_status_t load_config(void) } switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Connected ODBC DSN: %s\n", profile->odbc_dsn); - switch_odbc_handle_exec(profile->master_odbc, sub_sql, NULL); + switch_odbc_handle_exec(profile->master_odbc, sub_sql, NULL, NULL); //mdl_execute_sql(profile, sub_sql, NULL); } else { if ((db = switch_core_db_open_file(profile->dbname))) { diff --git a/src/mod/endpoints/mod_sofia/sofia.c b/src/mod/endpoints/mod_sofia/sofia.c index 6dc82d7db8..10f4ccd308 100644 --- a/src/mod/endpoints/mod_sofia/sofia.c +++ b/src/mod/endpoints/mod_sofia/sofia.c @@ -3436,7 +3436,7 @@ static void sofia_handle_sip_r_invite(switch_core_session_t *session, int status if (sip && sip->sip_from && sip->sip_from->a_url && sip->sip_from->a_url->url_user && sip->sip_from->a_url->url_host && sip->sip_to && sip->sip_to->a_url && sip->sip_to->a_url->url_user && sip->sip_to->a_url->url_host) { - sql = switch_mprintf("select 'appearance-index=1' from sip_subscriptions where expires > -1 && hostname='%q' and event='call-info' and " + sql = switch_mprintf("select 'appearance-index=1' from sip_subscriptions where expires > -1 and hostname='%q' and event='call-info' and " "sub_to_user='%q' and sub_to_host='%q'", mod_sofia_globals.hostname, sip->sip_to->a_url->url_user, sip->sip_from->a_url->url_host); sofia_glue_execute_sql2str(profile, profile->ireg_mutex, sql, buf, sizeof(buf)); @@ -4242,9 +4242,20 @@ static void sofia_handle_sip_i_state(switch_core_session_t *session, int status, switch_channel_presence(tech_pvt->channel, "unknown", "unhold", NULL); } } else if (switch_stristr("sendonly", r_sdp)) { + const char *msg = "hold"; + + if (sofia_test_pflag(profile, PFLAG_MANAGE_SHARED_APPEARANCE)) { + const char *info = switch_channel_get_variable(channel, "presence_call_info"); + if (info) { + if (switch_stristr("private", info)) { + msg = "hold-private"; + } + } + } + sofia_set_flag_locked(tech_pvt, TFLAG_SIP_HOLD); switch_channel_set_flag(channel, CF_LEG_HOLDING); - switch_channel_presence(tech_pvt->channel, "unknown", "hold", NULL); + switch_channel_presence(tech_pvt->channel, "unknown", msg, NULL); } switch_core_session_queue_message(other_session, msg); @@ -5693,6 +5704,11 @@ void sofia_handle_sip_i_invite(nua_t *nua, sofia_profile_t *profile, nua_handle_ if (!destination_number && sip->sip_to && sip->sip_to->a_url) { destination_number = sip->sip_to->a_url->url_user; } + + /* The human network, OH THE HUMANITY!!! lets send invites with no number! */ + if (!destination_number && sip->sip_from && sip->sip_from->a_url) { + destination_number = sip->sip_from->a_url->url_user; + } if (destination_number) { check_decode(destination_number, session); @@ -5957,20 +5973,36 @@ void sofia_handle_sip_i_invite(nua_t *nua, sofia_profile_t *profile, nua_handle_ char cid[512] = ""; char *str; char *p = NULL; - - + const char *user = NULL, *host = NULL; + if (sip->sip_to && sip->sip_to->a_url) { + user = sip->sip_to->a_url->url_user; + host = sip->sip_to->a_url->url_host; + } + + if (!user || !host) { + if (sip->sip_from && sip->sip_from->a_url) { + if (!user) user = sip->sip_from->a_url->url_user; + if (!host) host = sip->sip_from->a_url->url_host; + } + } + + if (user && host) { if ((p = strchr(call_info_str, ';'))) { p++; } - - sql = switch_mprintf("select call_id from sip_dialogs where call_info='%q' and sip_from_user='%q' and sip_from_host='%q'", - switch_str_nil(p), sip->sip_to->a_url->url_user, sip->sip_to->a_url->url_host); + sql = switch_mprintf("select call_id from sip_dialogs where call_info='%q' and sip_from_user='%q' and sip_from_host='%q' and call_id is not null", + switch_str_nil(p), user, host); + if ((str = sofia_glue_execute_sql2str(profile, profile->ireg_mutex, sql, cid, sizeof(cid)))) { bnh = nua_handle_by_call_id(nua, str); } + if (mod_sofia_globals.debug_sla > 1) { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "PICK SQL %s [%s] [%s] %d\n", sql, str, cid, !!bnh); + } + free(sql); } } @@ -5991,7 +6023,7 @@ void sofia_handle_sip_i_invite(nua_t *nua, sofia_profile_t *profile, nua_handle_ private_object_t *b_tech_pvt = NULL; const char *app = switch_channel_get_variable(b_channel, SWITCH_CURRENT_APPLICATION_VARIABLE); const char *data = switch_channel_get_variable(b_channel, SWITCH_CURRENT_APPLICATION_DATA_VARIABLE); - + if (app && data && !strcasecmp(app, "conference")) { destination_number = switch_core_session_sprintf(b_session, "answer,conference:%s", data); dialplan = "inline"; @@ -5999,7 +6031,7 @@ void sofia_handle_sip_i_invite(nua_t *nua, sofia_profile_t *profile, nua_handle_ if (switch_core_session_check_interface(b_session, sofia_endpoint_interface)) { b_tech_pvt = switch_core_session_get_private(b_session); } - + if ((uuid = switch_channel_get_variable(b_channel, SWITCH_SIGNAL_BOND_VARIABLE))) { switch_channel_set_variable(b_channel, "presence_call_info", NULL); one_leg = 0; diff --git a/src/mod/endpoints/mod_sofia/sofia_glue.c b/src/mod/endpoints/mod_sofia/sofia_glue.c index 227ec6c556..191285e659 100644 --- a/src/mod/endpoints/mod_sofia/sofia_glue.c +++ b/src/mod/endpoints/mod_sofia/sofia_glue.c @@ -3934,9 +3934,6 @@ int sofia_glue_init_sql(sofia_profile_t *profile) "create index ssa_profile_name on sip_shared_appearance_subscriptions (profile_name)", "create index ssa_aor on sip_shared_appearance_subscriptions (aor)", "create index ssd_profile_name on sip_shared_appearance_dialogs (profile_name)", - "create index ssd_contact on sip_shared_appearance_dialogs (contact)", - "create index ssd_presence_id on sip_shared_appearance_dialogs (presence_id)", - "create index ssd_presence_data on sip_shared_appearance_dialogs (presence_data)", "create index ssd_hostname on sip_shared_appearance_dialogs (hostname)", "create index ssd_contact_str on sip_shared_appearance_dialogs (contact_str)", "create index ssd_call_id on sip_shared_appearance_dialogs (call_id)", @@ -3963,9 +3960,9 @@ int sofia_glue_init_sql(sofia_profile_t *profile) "like '%%' and mwi_user like '%%' and mwi_host like '%%'", mod_sofia_globals.hostname); - if (switch_odbc_handle_exec(odbc_dbh, test_sql, NULL) != SWITCH_ODBC_SUCCESS) { - switch_odbc_handle_exec(odbc_dbh, "DROP TABLE sip_registrations", NULL); - switch_odbc_handle_exec(odbc_dbh, reg_sql, NULL); + if (switch_odbc_handle_exec(odbc_dbh, test_sql, NULL, NULL) != SWITCH_ODBC_SUCCESS) { + switch_odbc_handle_exec(odbc_dbh, "DROP TABLE sip_registrations", NULL, NULL); + switch_odbc_handle_exec(odbc_dbh, reg_sql, NULL, NULL); } @@ -3973,7 +3970,7 @@ int sofia_glue_init_sql(sofia_profile_t *profile) if (sofia_test_pflag(profile, PFLAG_SQL_IN_TRANS)) { char *test2 = switch_mprintf("%s;%s", test_sql, test_sql); - if (switch_odbc_handle_exec(odbc_dbh, test2, NULL) != SWITCH_ODBC_SUCCESS) { + if (switch_odbc_handle_exec(odbc_dbh, test2, NULL, NULL) != SWITCH_ODBC_SUCCESS) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "GREAT SCOTT!!! Cannot execute batched statements!\n" "If you are using mysql, make sure you are using MYODBC 3.51.18 or higher and enable FLAG_MULTI_STATEMENTS\n"); sofia_clear_pflag(profile, PFLAG_SQL_IN_TRANS); @@ -3988,55 +3985,55 @@ int sofia_glue_init_sql(sofia_profile_t *profile) test_sql = switch_mprintf("delete from sip_subscriptions where hostname='%q' and network_ip like '%%' and network_port like '%%'", mod_sofia_globals.hostname); - if (switch_odbc_handle_exec(odbc_dbh, test_sql, NULL) != SWITCH_ODBC_SUCCESS) { - switch_odbc_handle_exec(odbc_dbh, "DROP TABLE sip_subscriptions", NULL); - switch_odbc_handle_exec(odbc_dbh, sub_sql, NULL); + if (switch_odbc_handle_exec(odbc_dbh, test_sql, NULL, NULL) != SWITCH_ODBC_SUCCESS) { + switch_odbc_handle_exec(odbc_dbh, "DROP TABLE sip_subscriptions", NULL, NULL); + switch_odbc_handle_exec(odbc_dbh, sub_sql, NULL, NULL); } free(test_sql); test_sql = switch_mprintf("delete from sip_dialogs where hostname='%q' and expires > 0", mod_sofia_globals.hostname); - if (switch_odbc_handle_exec(odbc_dbh, test_sql, NULL) != SWITCH_ODBC_SUCCESS) { - switch_odbc_handle_exec(odbc_dbh, "DROP TABLE sip_dialogs", NULL); - switch_odbc_handle_exec(odbc_dbh, dialog_sql, NULL); + if (switch_odbc_handle_exec(odbc_dbh, test_sql, NULL, NULL) != SWITCH_ODBC_SUCCESS) { + switch_odbc_handle_exec(odbc_dbh, "DROP TABLE sip_dialogs", NULL, NULL); + switch_odbc_handle_exec(odbc_dbh, dialog_sql, NULL, NULL); } test_sql = switch_mprintf("delete from sip_presence where hostname='%q' ", mod_sofia_globals.hostname); - if (switch_odbc_handle_exec(odbc_dbh, test_sql, NULL) != SWITCH_ODBC_SUCCESS) { - switch_odbc_handle_exec(odbc_dbh, "DROP TABLE sip_presence", NULL); - switch_odbc_handle_exec(odbc_dbh, pres_sql, NULL); + if (switch_odbc_handle_exec(odbc_dbh, test_sql, NULL, NULL) != SWITCH_ODBC_SUCCESS) { + switch_odbc_handle_exec(odbc_dbh, "DROP TABLE sip_presence", NULL, NULL); + switch_odbc_handle_exec(odbc_dbh, pres_sql, NULL, NULL); } free(test_sql); test_sql = switch_mprintf("delete from sip_authentication where hostname='%q' or last_nc >= 0", mod_sofia_globals.hostname); - if (switch_odbc_handle_exec(odbc_dbh, test_sql, NULL) != SWITCH_ODBC_SUCCESS) { - switch_odbc_handle_exec(odbc_dbh, "DROP TABLE sip_authentication", NULL); - switch_odbc_handle_exec(odbc_dbh, auth_sql, NULL); + if (switch_odbc_handle_exec(odbc_dbh, test_sql, NULL, NULL) != SWITCH_ODBC_SUCCESS) { + switch_odbc_handle_exec(odbc_dbh, "DROP TABLE sip_authentication", NULL, NULL); + switch_odbc_handle_exec(odbc_dbh, auth_sql, NULL, NULL); } free(test_sql); test_sql = switch_mprintf("delete from sip_shared_appearance_subscriptions where contact_str='' or hostname='%q' and network_ip like '%%'", mod_sofia_globals.hostname); - if (switch_odbc_handle_exec(odbc_dbh, test_sql, NULL) != SWITCH_ODBC_SUCCESS) { - switch_odbc_handle_exec(odbc_dbh, "DROP TABLE sip_shared_appearance_subscriptions", NULL); - switch_odbc_handle_exec(odbc_dbh, shared_appearance_sql, NULL); + if (switch_odbc_handle_exec(odbc_dbh, test_sql, NULL, NULL) != SWITCH_ODBC_SUCCESS) { + switch_odbc_handle_exec(odbc_dbh, "DROP TABLE sip_shared_appearance_subscriptions", NULL, NULL); + switch_odbc_handle_exec(odbc_dbh, shared_appearance_sql, NULL, NULL); } free(test_sql); test_sql = switch_mprintf("delete from sip_shared_appearance_dialogs where contact_str='' or hostname='%q' and network_ip like '%%'", mod_sofia_globals.hostname); - if (switch_odbc_handle_exec(odbc_dbh, test_sql, NULL) != SWITCH_ODBC_SUCCESS) { - switch_odbc_handle_exec(odbc_dbh, "DROP TABLE sip_shared_appearance_dialogs", NULL); - switch_odbc_handle_exec(odbc_dbh, shared_appearance_dialogs_sql, NULL); + if (switch_odbc_handle_exec(odbc_dbh, test_sql, NULL, NULL) != SWITCH_ODBC_SUCCESS) { + switch_odbc_handle_exec(odbc_dbh, "DROP TABLE sip_shared_appearance_dialogs", NULL, NULL); + switch_odbc_handle_exec(odbc_dbh, shared_appearance_dialogs_sql, NULL, NULL); } free(test_sql); for (x = 0; indexes[x]; x++) { - switch_odbc_handle_exec(odbc_dbh, indexes[x], NULL); + switch_odbc_handle_exec(odbc_dbh, indexes[x], NULL, NULL); } diff --git a/src/mod/endpoints/mod_sofia/sofia_presence.c b/src/mod/endpoints/mod_sofia/sofia_presence.c index 22d46d2024..d1572cfb38 100644 --- a/src/mod/endpoints/mod_sofia/sofia_presence.c +++ b/src/mod/endpoints/mod_sofia/sofia_presence.c @@ -599,25 +599,37 @@ static void actual_sofia_presence_event_handler(switch_event_t *event) } if (call_info) { + const char *uuid = switch_event_get_header(event, "unique-id"); + #if 0 if (mod_sofia_globals.debug_sla > 1) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "SLA EVENT:\n"); DUMP_EVENT(event); } #endif - - sql = switch_mprintf("update sip_dialogs set call_info_state='%q' where hostname='%q' and sip_dialogs.sip_from_user='%q' " - "and sip_dialogs.sip_from_host='%q' and call_info='%q'", - call_info_state, - mod_sofia_globals.hostname, - euser, host, call_info); + + if (uuid) { + sql = switch_mprintf("update sip_dialogs set call_info_state='%q' where hostname='%q' and uuid='%q'", + call_info_state, + mod_sofia_globals.hostname, + uuid); + } else { + sql = switch_mprintf("update sip_dialogs set call_info_state='%q' where hostname='%q' and sip_dialogs.sip_from_user='%q' " + "and sip_dialogs.sip_from_host='%q' and call_info='%q'", + call_info_state, + mod_sofia_globals.hostname, + euser, host, call_info); + + } if (mod_sofia_globals.debug_sla > 1) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "STATE SQL %s\n", sql); } sofia_glue_execute_sql_now(profile, &sql, SWITCH_TRUE); + + if (mod_sofia_globals.debug_sla > 1) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "PROCESS PRESENCE EVENT\n"); } diff --git a/src/mod/endpoints/mod_sofia/sofia_reg.c b/src/mod/endpoints/mod_sofia/sofia_reg.c index 2e2204d31d..86e6d0abc2 100644 --- a/src/mod/endpoints/mod_sofia/sofia_reg.c +++ b/src/mod/endpoints/mod_sofia/sofia_reg.c @@ -768,14 +768,23 @@ uint8_t sofia_reg_handle_register(nua_t *nua, sofia_profile_t *profile, nua_hand authorization = sip->sip_authorization; contact = sip->sip_contact; to = sip->sip_to; + from = sip->sip_from; + if (from) { + from_user = from->a_url->url_user; + from_host = from->a_url->url_host; + } + if (to) { to_user = to->a_url->url_user; to_host = to->a_url->url_host; } + if (!to_user) to_user = from_user; + if (!to_host) to_host = from_host; + if (!to_user || !to_host) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Can not do authorization without a complete from header\n"); + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Can not do authorization without a complete header\n"); nua_respond(nh, SIP_401_UNAUTHORIZED, NUTAG_WITH_THIS(nua), TAG_END()); switch_goto_int(r, 1, end); } @@ -784,13 +793,6 @@ uint8_t sofia_reg_handle_register(nua_t *nua, sofia_profile_t *profile, nua_hand reg_host = to_host; } - from = sip->sip_from; - - if (from) { - from_user = from->a_url->url_user; - from_host = from->a_url->url_host; - } - if (contact->m_url) { const char *port = contact->m_url->url_port; char new_port[25] = ""; diff --git a/src/mod/languages/mod_spidermonkey_odbc/mod_spidermonkey_odbc.c b/src/mod/languages/mod_spidermonkey_odbc/mod_spidermonkey_odbc.c index 2a2b990f77..43cdd4d878 100644 --- a/src/mod/languages/mod_spidermonkey_odbc/mod_spidermonkey_odbc.c +++ b/src/mod/languages/mod_spidermonkey_odbc/mod_spidermonkey_odbc.c @@ -215,7 +215,7 @@ static JSBool odbc_execute(JSContext * cx, JSObject * obj, uintN argc, jsval * a sql = JS_GetStringBytes(JS_ValueToString(cx, argv[0])); - if (switch_odbc_handle_exec(odbc_obj->handle, sql, &stmt) != SWITCH_ODBC_SUCCESS) { + if (switch_odbc_handle_exec(odbc_obj->handle, sql, &stmt, NULL) != SWITCH_ODBC_SUCCESS) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "[ODBC] Execute failed for: %s\n", sql); goto done; } @@ -253,7 +253,7 @@ static JSBool odbc_exec(JSContext * cx, JSObject * obj, uintN argc, jsval * argv sql = JS_GetStringBytes(JS_ValueToString(cx, argv[0])); - if (switch_odbc_handle_exec(odbc_obj->handle, sql, &odbc_obj->stmt) != SWITCH_ODBC_SUCCESS) { + if (switch_odbc_handle_exec(odbc_obj->handle, sql, &odbc_obj->stmt, NULL) != SWITCH_ODBC_SUCCESS) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "[ODBC] query failed: %s\n", sql); goto done; } diff --git a/src/switch_channel.c b/src/switch_channel.c index 0e980d0031..123430a1cb 100644 --- a/src/switch_channel.c +++ b/src/switch_channel.c @@ -505,6 +505,8 @@ SWITCH_DECLARE(void) switch_channel_presence(switch_channel_t *channel, const ch call_info_state = "idle"; } else if (!strcasecmp(status, "hold")) { call_info_state = "held"; + } else if (!strcasecmp(status, "hold-private")) { + call_info_state = "held-private"; } else if (!switch_channel_test_flag(channel, CF_ANSWERED)) { if (channel->direction == SWITCH_CALL_DIRECTION_OUTBOUND) { call_info_state = "progressing"; diff --git a/src/switch_core_sqldb.c b/src/switch_core_sqldb.c index b70529e4a8..f85eb1aa24 100644 --- a/src/switch_core_sqldb.c +++ b/src/switch_core_sqldb.c @@ -380,7 +380,7 @@ static switch_status_t switch_cache_db_execute_sql_real(switch_cache_db_handle_t case SCDB_TYPE_ODBC: { switch_odbc_statement_handle_t stmt = NULL; - if ((status = switch_odbc_handle_exec(dbh->native_handle.odbc_dbh, sql, &stmt)) != SWITCH_ODBC_SUCCESS) { + if ((status = switch_odbc_handle_exec(dbh->native_handle.odbc_dbh, sql, &stmt, NULL)) != SWITCH_ODBC_SUCCESS) { errmsg = switch_odbc_handle_get_error(dbh->native_handle.odbc_dbh, stmt); } switch_odbc_statement_handle_free(&stmt); @@ -548,7 +548,7 @@ SWITCH_DECLARE(char *) switch_cache_db_execute_sql2str(switch_cache_db_handle_t break; case SCDB_TYPE_ODBC: { - status = switch_odbc_handle_exec_string(dbh->native_handle.odbc_dbh, sql, str, len); + status = switch_odbc_handle_exec_string(dbh->native_handle.odbc_dbh, sql, str, len, err); } break; } @@ -738,12 +738,12 @@ SWITCH_DECLARE(switch_bool_t) switch_cache_db_test_reactive(switch_cache_db_hand switch (dbh->type) { case SCDB_TYPE_ODBC: { - if (switch_odbc_handle_exec(dbh->native_handle.odbc_dbh, test_sql, NULL) != SWITCH_ODBC_SUCCESS) { + if (switch_odbc_handle_exec(dbh->native_handle.odbc_dbh, test_sql, NULL, NULL) != SWITCH_ODBC_SUCCESS) { r = SWITCH_FALSE; if (drop_sql) { - switch_odbc_handle_exec(dbh->native_handle.odbc_dbh, drop_sql, NULL); + switch_odbc_handle_exec(dbh->native_handle.odbc_dbh, drop_sql, NULL, NULL); } - switch_odbc_handle_exec(dbh->native_handle.odbc_dbh, reactive_sql, NULL); + switch_odbc_handle_exec(dbh->native_handle.odbc_dbh, reactive_sql, NULL, NULL); } } break; diff --git a/src/switch_odbc.c b/src/switch_odbc.c index f29cb36ba0..1be5ba50e0 100644 --- a/src/switch_odbc.c +++ b/src/switch_odbc.c @@ -344,7 +344,8 @@ SWITCH_DECLARE(switch_odbc_status_t) switch_odbc_handle_connect(switch_odbc_hand SWITCH_DECLARE(switch_odbc_status_t) switch_odbc_handle_exec_string(switch_odbc_handle_t *handle, const char *sql, char *resbuf, - size_t len) + size_t len, + char **err) { #ifdef SWITCH_HAVE_ODBC switch_odbc_status_t sstatus = SWITCH_ODBC_FAIL; @@ -352,21 +353,27 @@ SWITCH_DECLARE(switch_odbc_status_t) switch_odbc_handle_exec_string(switch_odbc_ SQLCHAR name[1024]; SQLLEN m = 0; - if (switch_odbc_handle_exec(handle, sql, &stmt) == SWITCH_ODBC_SUCCESS) { + if (switch_odbc_handle_exec(handle, sql, &stmt, err) == SWITCH_ODBC_SUCCESS) { SQLSMALLINT NameLength, DataType, DecimalDigits, Nullable; SQLULEN ColumnSize; + int result; + SQLRowCount(stmt, &m); if (m <= 0) { goto done; } - if (SQLFetch(stmt) != SQL_SUCCESS) { + result = SQLExecute(stmt); + result = SQLFetch(stmt); + + if (result != SQL_SUCCESS && result != SQL_SUCCESS_WITH_INFO && result != SQL_NO_DATA) { goto done; } - + SQLDescribeCol(stmt, 1, name, sizeof(name), &NameLength, &DataType, &ColumnSize, &DecimalDigits, &Nullable); SQLGetData(stmt, 1, SQL_C_CHAR, (SQLCHAR *) resbuf, (SQLLEN) len, NULL); + sstatus = SWITCH_ODBC_SUCCESS; } else { return sstatus; @@ -380,11 +387,12 @@ SWITCH_DECLARE(switch_odbc_status_t) switch_odbc_handle_exec_string(switch_odbc_ #endif } -SWITCH_DECLARE(switch_odbc_status_t) switch_odbc_handle_exec(switch_odbc_handle_t *handle, const char *sql, switch_odbc_statement_handle_t * rstmt) +SWITCH_DECLARE(switch_odbc_status_t) switch_odbc_handle_exec(switch_odbc_handle_t *handle, const char *sql, switch_odbc_statement_handle_t *rstmt, char **err) { #ifdef SWITCH_HAVE_ODBC SQLHSTMT stmt = NULL; int result; + char *err_str = NULL; if (!db_is_up(handle)) { goto error; @@ -413,6 +421,22 @@ SWITCH_DECLARE(switch_odbc_status_t) switch_odbc_handle_exec(switch_odbc_handle_ return SWITCH_ODBC_SUCCESS; error: + + if (stmt) { + err_str = switch_odbc_handle_get_error(handle, stmt); + } + + if (err_str) { + if (!switch_stristr("already exists", err_str)) { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "ERR: [%s]\n[%s]\n", sql, switch_str_nil(err_str)); + } + if (err) { + *err = err_str; + } else { + free(err_str); + } + } + if (rstmt) { *rstmt = stmt; } else if (stmt) {