diff --git a/src/mod/endpoints/mod_sofia/sofia_glue.c b/src/mod/endpoints/mod_sofia/sofia_glue.c index fafe68abd0..51d75e1e75 100644 --- a/src/mod/endpoints/mod_sofia/sofia_glue.c +++ b/src/mod/endpoints/mod_sofia/sofia_glue.c @@ -27,6 +27,7 @@ * Ken Rice, Asteria Solutions Group, Inc * Paul D. Tinsley * Bret McDanel + * Eliot Gable * * * sofia_glue.c -- SOFIA SIP Endpoint (code to tie sofia to freeswitch) @@ -1169,6 +1170,7 @@ switch_status_t sofia_glue_do_invite(switch_core_session_t *session) const char *screen = "no"; const char *invite_params = switch_channel_get_variable(tech_pvt->channel, "sip_invite_params"); const char *invite_to_params = switch_channel_get_variable(tech_pvt->channel, "sip_invite_to_params"); + const char *invite_to_uri = switch_channel_get_variable(tech_pvt->channel, "sip_invite_to_uri"); const char *invite_contact_params = switch_channel_get_variable(tech_pvt->channel, "sip_invite_contact_params"); const char *invite_from_params = switch_channel_get_variable(tech_pvt->channel, "sip_invite_from_params"); const char *from_var = switch_channel_get_variable(tech_pvt->channel, "sip_from_uri"); @@ -1260,7 +1262,7 @@ switch_status_t sofia_glue_do_invite(switch_core_session_t *session) url_str = sofia_overcome_sip_uri_weakness(session, url, tech_pvt->transport, SWITCH_TRUE, invite_params); invite_contact = sofia_overcome_sip_uri_weakness(session, tech_pvt->invite_contact, tech_pvt->transport, SWITCH_FALSE, invite_contact_params); from_str = sofia_overcome_sip_uri_weakness(session, use_from_str, 0, SWITCH_TRUE, invite_from_params); - to_str = sofia_overcome_sip_uri_weakness(session, tech_pvt->dest_to, 0, SWITCH_FALSE, invite_to_params ? invite_to_params : invite_params); + to_str = sofia_overcome_sip_uri_weakness(session, invite_to_uri ? invite_to_uri : tech_pvt->dest_to, 0, SWITCH_FALSE, invite_to_params ? invite_to_params : invite_params); /* @@ -1435,6 +1437,7 @@ switch_status_t sofia_glue_do_invite(switch_core_session_t *session) nua_invite(tech_pvt->nh, NUTAG_AUTOANSWER(0), NUTAG_SESSION_TIMER(session_timeout), + TAG_IF(!switch_strlen_zero(sendto), NTATAG_DEFAULT_PROXY(sendto)), TAG_IF(!switch_strlen_zero(tech_pvt->rpid), SIPTAG_HEADER_STR(tech_pvt->rpid)), TAG_IF(!switch_strlen_zero(alert_info), SIPTAG_HEADER_STR(alert_info)), TAG_IF(!switch_strlen_zero(extra_headers), SIPTAG_HEADER_STR(extra_headers)), @@ -3019,7 +3022,9 @@ int sofia_glue_init_sql(sofia_profile_t *profile) " server_user VARCHAR(255),\n" " server_host VARCHAR(255),\n" " profile_name VARCHAR(255),\n" - " hostname VARCHAR(255)\n" + " hostname VARCHAR(255),\n" + " network_ip VARCHAR(255),\n" + " network_port VARCHAR(6)\n" ");\n"; @@ -3032,7 +3037,9 @@ int sofia_glue_init_sql(sofia_profile_t *profile) " expires INTEGER,\n" " user_agent VARCHAR(255),\n" " profile_name VARCHAR(255),\n" - " hostname VARCHAR(255)\n" + " hostname VARCHAR(255),\n" + " network_ip VARCHAR(255),\n" + " network_port VARCHAR(6)\n" ");\n"; char dialog_sql[] = @@ -3104,6 +3111,8 @@ int sofia_glue_init_sql(sofia_profile_t *profile) "create index sr_expires on sip_registrations (expires)", "create index sr_hostname on sip_registrations (hostname)", "create index sr_status on sip_registrations (status)", + "create index sr_network_ip on sip_registrations (network_ip)", + "create index sr_network_port on sip_registrations (network_port)", "create index ss_call_id on sip_subscriptions (call_id)", "create index ss_hostname on sip_subscriptions (hostname)", "create index ss_sip_user on sip_subscriptions (sip_user)", @@ -3136,7 +3145,8 @@ 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); test_sql = switch_mprintf("delete from sip_registrations where (contact like '%%TCP%%' " - "or status like '%%TCP%%' or status like '%%TLS%%') and hostname='%q'", + "or status like '%%TCP%%' or status like '%%TLS%%') and hostname='%q' " + "and network_ip!='-1' and network_port!='-1'", mod_sofia_globals.hostname); if (switch_odbc_handle_exec(profile->master_odbc, test_sql, NULL) != SWITCH_ODBC_SUCCESS) { @@ -3146,7 +3156,7 @@ int sofia_glue_init_sql(sofia_profile_t *profile) free(test_sql); - test_sql = switch_mprintf("delete from sip_subscriptions where hostname='%q'", mod_sofia_globals.hostname); + test_sql = switch_mprintf("delete from sip_subscriptions where hostname='%q' and network_ip!='-1' and network_port!='-1'", mod_sofia_globals.hostname); if (switch_odbc_handle_exec(profile->master_odbc, test_sql, NULL) != SWITCH_ODBC_SUCCESS) { switch_odbc_handle_exec(profile->master_odbc, "DROP TABLE sip_subscriptions", NULL); @@ -3198,7 +3208,8 @@ int sofia_glue_init_sql(sofia_profile_t *profile) } test_sql = switch_mprintf("delete from sip_registrations where (contact like '%%TCP%%' " - "or status like '%%TCP%%' or status like '%%TLS%%') and hostname='%q'", + "or status like '%%TCP%%' or status like '%%TLS%%') and hostname='%q' " + "and network_ip!='-1' and network_port!='-1'", mod_sofia_globals.hostname); switch_core_db_test_reactive(profile->master_db, test_sql, "DROP TABLE sip_registrations", reg_sql); @@ -3244,6 +3255,8 @@ int sofia_glue_init_sql(sofia_profile_t *profile) switch_core_db_exec(profile->master_db, "create index if not exists sr_expires on sip_registrations (expires)", NULL, NULL, NULL); switch_core_db_exec(profile->master_db, "create index if not exists sr_hostname on sip_registrations (hostname)", NULL, NULL, NULL); switch_core_db_exec(profile->master_db, "create index if not exists sr_status on sip_registrations (status)", NULL, NULL, NULL); + switch_core_db_exec(profile->master_db, "create index if not exists sr_network_ip on sip_registrations (network_ip)", NULL, NULL, NULL); + switch_core_db_exec(profile->master_db, "create index if not exists sr_network_port on sip_registrations (network_port)", NULL, NULL, NULL); switch_core_db_exec(profile->master_db, "create index if not exists ss_call_id on sip_subscriptions (call_id)", NULL, NULL, NULL); switch_core_db_exec(profile->master_db, "create index if not exists ss_hostname on sip_subscriptions (hostname)", NULL, NULL, NULL); diff --git a/src/mod/endpoints/mod_sofia/sofia_reg.c b/src/mod/endpoints/mod_sofia/sofia_reg.c index 682588f84c..9eecb33bc4 100644 --- a/src/mod/endpoints/mod_sofia/sofia_reg.c +++ b/src/mod/endpoints/mod_sofia/sofia_reg.c @@ -29,6 +29,7 @@ * Bret McDanel * Marcel Barbulescu * David Knell <> + * Eliot Gable * * * sofia_ref.c -- SOFIA SIP Endpoint (registration code) @@ -653,6 +654,7 @@ uint8_t sofia_reg_handle_register(nua_t *nua, sofia_profile_t *profile, nua_hand const char *rpid = "unknown"; const char *display = "\"user\""; char network_ip[80]; + char network_port_c[6]; char url_ip[80]; char *register_gateway = NULL; int network_port; @@ -669,6 +671,8 @@ uint8_t sofia_reg_handle_register(nua_t *nua, sofia_profile_t *profile, nua_hand get_addr(network_ip, sizeof(network_ip), my_addrinfo->ai_addr,my_addrinfo->ai_addrlen); network_port = get_port(my_addrinfo->ai_addr); + snprintf(network_port_c, sizeof(network_port_c), "%d", network_port); + snprintf(url_ip, sizeof(url_ip), my_addrinfo->ai_addr->sa_family == AF_INET6 ? "[%s]" : "%s", network_ip); expires = sip->sip_expires; @@ -940,11 +944,11 @@ uint8_t sofia_reg_handle_register(nua_t *nua, sofia_profile_t *profile, nua_hand switch_find_local_ip(guess_ip4, sizeof(guess_ip4), AF_INET); sql = switch_mprintf("insert into sip_registrations " - "(call_id,sip_user,sip_host,presence_hosts,contact,status,rpid,expires,user_agent,server_user,server_host,profile_name,hostname) " - "values ('%q','%q', '%q','%q','%q','%q', '%q', %ld, '%q', '%q', '%q', '%q', '%q')", + "(call_id,sip_user,sip_host,presence_hosts,contact,status,rpid,expires,user_agent,server_user,server_host,profile_name,hostname,network_ip,network_port) " + "values ('%q','%q', '%q','%q','%q','%q', '%q', %ld, '%q', '%q', '%q', '%q', '%q', '%q', '%q')", call_id, to_user, reg_host, profile->presence_hosts ? profile->presence_hosts : reg_host, contact_str, reg_desc, rpid, (long) switch_epoch_time_now(NULL) + (long) exptime * 2, - agent, from_user, guess_ip4, profile->name, mod_sofia_globals.hostname); + agent, from_user, guess_ip4, profile->name, mod_sofia_globals.hostname, network_ip, network_port_c); if (sql) { sofia_glue_execute_sql(profile, &sql, SWITCH_TRUE); @@ -965,6 +969,8 @@ uint8_t sofia_reg_handle_register(nua_t *nua, sofia_profile_t *profile, nua_hand switch_event_add_header(s_event, SWITCH_STACK_BOTTOM, "expires", "%ld", (long) exptime); switch_event_add_header_string(s_event, SWITCH_STACK_BOTTOM, "to-user", from_user); switch_event_add_header_string(s_event, SWITCH_STACK_BOTTOM, "to-host", from_host); + switch_event_add_header_string(s_event, SWITCH_STACK_BOTTOM, "network-ip", network_ip); + switch_event_add_header_string(s_event, SWITCH_STACK_BOTTOM, "network-port", network_port_c); switch_event_fire(&s_event); }