mirror of
https://github.com/signalwire/freeswitch.git
synced 2026-07-24 05:02:10 +00:00
improvements
git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@5967 d0543943-73ff-0310-b7d9-9358b9ac24b2
This commit is contained in:
@@ -257,12 +257,11 @@ void event_handler(switch_event_t *event)
|
||||
char *contact_str = switch_event_get_header(event, "orig-contact");
|
||||
char *exp_str = switch_event_get_header(event, "orig-expires");
|
||||
char *rpid = switch_event_get_header(event, "orig-rpid");
|
||||
char *call_id = switch_event_get_header(event, "orig-call-id");
|
||||
long expires = (long) time(NULL) + atol(exp_str);
|
||||
char *profile_name = switch_event_get_header(event, "orig-profile-name");
|
||||
sofia_profile_t *profile = NULL;
|
||||
char *icontact = NULL, *p;
|
||||
|
||||
|
||||
|
||||
if (!rpid) {
|
||||
rpid = "unknown";
|
||||
}
|
||||
@@ -272,13 +271,7 @@ void event_handler(switch_event_t *event)
|
||||
return;
|
||||
}
|
||||
if (sofia_test_pflag(profile, PFLAG_MULTIREG)) {
|
||||
icontact = sofia_glue_get_url_from_contact(contact_str, 1);
|
||||
|
||||
if ((p = strchr(icontact, ';'))) {
|
||||
*p = '\0';
|
||||
}
|
||||
sql = switch_mprintf("delete from sip_registrations where user='%q' and host='%q' and contact like '%%%q%%'", from_user, from_host, icontact);
|
||||
switch_safe_free(icontact);
|
||||
sql = switch_mprintf("delete from sip_registrations where call_id='%q'", call_id);
|
||||
} else {
|
||||
sql = switch_mprintf("delete from sip_registrations where user='%q' and host='%q'", from_user, from_host);
|
||||
}
|
||||
@@ -287,8 +280,8 @@ void event_handler(switch_event_t *event)
|
||||
sofia_glue_execute_sql(profile, SWITCH_FALSE, sql, NULL);
|
||||
switch_safe_free(sql);
|
||||
|
||||
sql = switch_mprintf("insert into sip_registrations values ('%q','%q','%q','Regestered', '%q', %ld)",
|
||||
from_user, from_host, contact_str, rpid, expires);
|
||||
sql = switch_mprintf("insert into sip_registrations values ('%q', '%q','%q','%q','Regestered', '%q', %ld)",
|
||||
call_id, from_user, from_host, contact_str, rpid, expires);
|
||||
|
||||
if (sql) {
|
||||
sofia_glue_execute_sql(profile, SWITCH_FALSE, sql, NULL);
|
||||
|
||||
@@ -1550,6 +1550,7 @@ int sofia_glue_init_sql(sofia_profile_t *profile)
|
||||
|
||||
char reg_sql[] =
|
||||
"CREATE TABLE sip_registrations (\n"
|
||||
" call_id VARCHAR(255),\n"
|
||||
" user VARCHAR(255),\n"
|
||||
" host VARCHAR(255),\n"
|
||||
" contact VARCHAR(1024),\n"
|
||||
@@ -1591,18 +1592,29 @@ int sofia_glue_init_sql(sofia_profile_t *profile)
|
||||
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Connected ODBC DSN: %s\n", profile->odbc_dsn);
|
||||
|
||||
switch_odbc_handle_exec(profile->master_odbc, reg_sql, NULL);
|
||||
switch_odbc_handle_exec(profile->master_odbc, sub_sql, NULL);
|
||||
switch_odbc_handle_exec(profile->master_odbc, auth_sql, NULL);
|
||||
if (switch_odbc_handle_exec(profile->master_odbc, "select call_id from sip_registrations", NULL) != SWITCH_ODBC_SUCCESS) {
|
||||
switch_odbc_handle_exec(profile->master_odbc, "DROP TABLE sip_registrations", NULL);
|
||||
switch_odbc_handle_exec(profile->master_odbc, reg_sql, NULL);
|
||||
}
|
||||
|
||||
if (switch_odbc_handle_exec(profile->master_odbc, "select contact from sip_subscriptions", NULL) != SWITCH_ODBC_SUCCESS) {
|
||||
switch_odbc_handle_exec(profile->master_odbc, "DROP TABLE sip_subscriptions", NULL);
|
||||
switch_odbc_handle_exec(profile->master_odbc, sub_sql, NULL);
|
||||
}
|
||||
|
||||
if (switch_odbc_handle_exec(profile->master_odbc, "select nonce from sip_authentication", NULL) != SWITCH_ODBC_SUCCESS) {
|
||||
switch_odbc_handle_exec(profile->master_odbc, "DROP TABLE sip_authentication", NULL);
|
||||
switch_odbc_handle_exec(profile->master_odbc, auth_sql, NULL);
|
||||
}
|
||||
} else {
|
||||
#endif
|
||||
if (!(profile->master_db = switch_core_db_open_file(profile->dbname))) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
switch_core_db_test_reactive(profile->master_db, "select contact from sip_registrations", reg_sql);
|
||||
switch_core_db_test_reactive(profile->master_db, "select contact from sip_subscriptions", sub_sql);
|
||||
switch_core_db_test_reactive(profile->master_db, "select * from sip_authentication", auth_sql);
|
||||
switch_core_db_test_reactive(profile->master_db, "select call_id from sip_registrations", "DROP TABLE sip_registrations", reg_sql);
|
||||
switch_core_db_test_reactive(profile->master_db, "select contact from sip_subscriptions", "DROP TABLE sip_subscriptions", sub_sql);
|
||||
switch_core_db_test_reactive(profile->master_db, "select * from sip_authentication", "DROP TABLE sip_authentication", auth_sql);
|
||||
|
||||
#ifdef SWITCH_HAVE_ODBC
|
||||
}
|
||||
|
||||
@@ -340,6 +340,7 @@ uint8_t sofia_reg_handle_register(nua_t * nua, sofia_profile_t *profile, nua_han
|
||||
char *register_gateway = NULL;
|
||||
int network_port;
|
||||
int cd = 0;
|
||||
char *call_id = NULL;
|
||||
|
||||
/* all callers must confirm that sip, sip->sip_request and sip->sip_contact are not NULL */
|
||||
assert(sip != NULL && sip->sip_contact != NULL && sip->sip_request != NULL);
|
||||
@@ -412,9 +413,11 @@ uint8_t sofia_reg_handle_register(nua_t * nua, sofia_profile_t *profile, nua_han
|
||||
}
|
||||
|
||||
if (v_event && *v_event) {
|
||||
register_gateway = switch_event_get_header(*v_event, "register-gateway");
|
||||
|
||||
if ((v_contact_str = switch_event_get_header(*v_event, "force-contact"))) {
|
||||
char *exp_var;
|
||||
|
||||
register_gateway = switch_event_get_header(*v_event, "sip-register-gateway");
|
||||
|
||||
if ((v_contact_str = switch_event_get_header(*v_event, "sip-force-contact"))) {
|
||||
if (!strcasecmp(v_contact_str, "nat-connectile-dysfunction") || !strcasecmp(v_contact_str, "NDLB-connectile-dysfunction")) {
|
||||
if (contact->m_url->url_params) {
|
||||
snprintf(contact_str, sizeof(contact_str), "%s <sip:%s@%s:%d;%s>",
|
||||
@@ -423,6 +426,7 @@ uint8_t sofia_reg_handle_register(nua_t * nua, sofia_profile_t *profile, nua_han
|
||||
snprintf(contact_str, sizeof(contact_str), "%s <sip:%s@%s:%d>", display, contact->m_url->url_user, network_ip, network_port);
|
||||
}
|
||||
cd = 1;
|
||||
exptime = 20;
|
||||
} else {
|
||||
char *p;
|
||||
switch_copy_string(contact_str, v_contact_str, sizeof(contact_str));
|
||||
@@ -433,6 +437,13 @@ uint8_t sofia_reg_handle_register(nua_t * nua, sofia_profile_t *profile, nua_han
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ((exp_var = switch_event_get_header(*v_event, "sip-force-expires"))) {
|
||||
int tmp = atoi(exp_var);
|
||||
if (tmp > 0) {
|
||||
exptime = tmp;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (auth_res != AUTH_OK && !stale) {
|
||||
@@ -459,25 +470,23 @@ uint8_t sofia_reg_handle_register(nua_t * nua, sofia_profile_t *profile, nua_han
|
||||
if (regtype != REG_REGISTER) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
call_id = sip_header_as_string(profile->home, (void *) sip->sip_call_id);
|
||||
assert(call_id);
|
||||
|
||||
|
||||
if (exptime) {
|
||||
|
||||
|
||||
if (sofia_test_pflag(profile, PFLAG_MULTIREG)) {
|
||||
char *icontact, *p;
|
||||
icontact = sofia_glue_get_url_from_contact(contact_str, 1);
|
||||
if ((p = strchr(icontact, ';'))) {
|
||||
*p = '\0';
|
||||
}
|
||||
|
||||
sql = switch_mprintf("delete from sip_registrations where user='%q' and host='%q' and contact like '%%%q%%'", to_user, to_host, icontact);
|
||||
switch_safe_free(icontact);
|
||||
sql = switch_mprintf("delete from sip_registrations where call_id='%q'", call_id);
|
||||
} else {
|
||||
sql = switch_mprintf("delete from sip_registrations where user='%q' and host='%q'", to_user, to_host);
|
||||
}
|
||||
switch_mutex_lock(profile->ireg_mutex);
|
||||
sofia_glue_execute_sql(profile, SWITCH_FALSE, sql, NULL);
|
||||
switch_safe_free(sql);
|
||||
sql = switch_mprintf("insert into sip_registrations values ('%q','%q','%q','%q', '%q', %ld)",
|
||||
|
||||
sql = switch_mprintf("insert into sip_registrations values ('%q', '%q','%q','%q','%q', '%q', %ld)", call_id,
|
||||
to_user, to_host, contact_str, cd ? "Registered(NATHACK)" : "Registered", rpid, (long) time(NULL) + (long) exptime * 2);
|
||||
|
||||
|
||||
@@ -493,6 +502,7 @@ uint8_t sofia_reg_handle_register(nua_t * nua, sofia_profile_t *profile, nua_han
|
||||
switch_event_add_header(s_event, SWITCH_STACK_BOTTOM, "from-user", "%s", to_user);
|
||||
switch_event_add_header(s_event, SWITCH_STACK_BOTTOM, "from-host", "%s", to_host);
|
||||
switch_event_add_header(s_event, SWITCH_STACK_BOTTOM, "contact", "%s", contact_str);
|
||||
switch_event_add_header(s_event, SWITCH_STACK_BOTTOM, "call-id", "%s", call_id);
|
||||
switch_event_add_header(s_event, SWITCH_STACK_BOTTOM, "rpid", "%s", rpid);
|
||||
switch_event_add_header(s_event, SWITCH_STACK_BOTTOM, "expires", "%ld", (long) exptime);
|
||||
switch_event_fire(&s_event);
|
||||
@@ -509,7 +519,6 @@ uint8_t sofia_reg_handle_register(nua_t * nua, sofia_profile_t *profile, nua_han
|
||||
switch_event_add_header(event, SWITCH_STACK_BOTTOM, "login", "%s", profile->url);
|
||||
switch_event_add_header(event, SWITCH_STACK_BOTTOM, "rpid", "%s", rpid);
|
||||
switch_event_add_header(event, SWITCH_STACK_BOTTOM, "from", "%s@%s", to_user, to_host);
|
||||
|
||||
switch_event_add_header(event, SWITCH_STACK_BOTTOM, "status", "Registered");
|
||||
switch_event_add_header(event, SWITCH_STACK_BOTTOM, "event_type", "presence");
|
||||
switch_event_fire(&event);
|
||||
@@ -521,13 +530,16 @@ uint8_t sofia_reg_handle_register(nua_t * nua, sofia_profile_t *profile, nua_han
|
||||
if ((p = strchr(icontact, ';'))) {
|
||||
*p = '\0';
|
||||
}
|
||||
if ((p = strchr(icontact + 4, ':'))) {
|
||||
*p = '\0';
|
||||
}
|
||||
if ((sql = switch_mprintf("delete from sip_subscriptions where user='%q' and host='%q' and contact like '%%%q%%'", to_user, to_host, icontact))) {
|
||||
sofia_glue_execute_sql(profile, SWITCH_FALSE, sql, profile->ireg_mutex);
|
||||
switch_safe_free(sql);
|
||||
sql = NULL;
|
||||
}
|
||||
|
||||
if ((sql = switch_mprintf("delete from sip_registrations where user='%q' and host='%q' and contact like '%%%q%%'", to_user, to_host, icontact))) {
|
||||
if ((sql = switch_mprintf("delete from sip_registrations where call_id='%q'", to_user, to_host, call_id))) {
|
||||
sofia_glue_execute_sql(profile, SWITCH_FALSE, sql, profile->ireg_mutex);
|
||||
switch_safe_free(sql);
|
||||
sql = NULL;
|
||||
@@ -565,8 +577,21 @@ uint8_t sofia_reg_handle_register(nua_t * nua, sofia_profile_t *profile, nua_han
|
||||
switch_event_fire(&event);
|
||||
}
|
||||
|
||||
|
||||
if (call_id) {
|
||||
su_free(profile->home, call_id);
|
||||
}
|
||||
|
||||
if (regtype == REG_REGISTER) {
|
||||
nua_respond(nh, SIP_200_OK, SIPTAG_CONTACT(contact), NUTAG_WITH_THIS(nua), TAG_END());
|
||||
char *new_contact = NULL;
|
||||
if (exptime) {
|
||||
new_contact = switch_mprintf("%s;expires=%ld", contact_str, (long)exptime);
|
||||
nua_respond(nh, SIP_200_OK, SIPTAG_CONTACT_STR(new_contact), NUTAG_WITH_THIS(nua), TAG_END());
|
||||
switch_safe_free(new_contact);
|
||||
} else {
|
||||
nua_respond(nh, SIP_200_OK, SIPTAG_CONTACT(contact), NUTAG_WITH_THIS(nua), TAG_END());
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user