diff --git a/src/mod/endpoints/mod_sofia/mod_sofia.c b/src/mod/endpoints/mod_sofia/mod_sofia.c index 908b82817b..e697eb66b5 100644 --- a/src/mod/endpoints/mod_sofia/mod_sofia.c +++ b/src/mod/endpoints/mod_sofia/mod_sofia.c @@ -285,7 +285,7 @@ switch_status_t sofia_on_hangup(switch_core_session_t *session) if (switch_test_flag(tech_pvt, TFLAG_ANS)) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Sending BYE to %s\n", switch_channel_get_name(channel)); - nua_bye(tech_pvt->nh, SIPTAG_REASON_STR(reason), TAG_END()); + nua_bye(tech_pvt->nh, SIPTAG_RECORD_ROUTE_STR(tech_pvt->record_route), SIPTAG_REASON_STR(reason), TAG_END()); } else { if (switch_test_flag(tech_pvt, TFLAG_OUTBOUND)) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Sending CANCEL to %s\n", switch_channel_get_name(channel)); @@ -386,7 +386,9 @@ static switch_status_t sofia_answer_channel(switch_core_session_t *session) } } + printf("XXXXXXXXXXXXXXXXXXXXXXXXWTF [%s]\n", tech_pvt->record_route); nua_respond(tech_pvt->nh, SIP_200_OK, + SIPTAG_RECORD_ROUTE_STR(tech_pvt->record_route), NUTAG_AUTOANSWER(0), NUTAG_SESSION_TIMER(session_timeout), SIPTAG_CONTACT_STR(tech_pvt->reply_contact), diff --git a/src/mod/endpoints/mod_sofia/mod_sofia.h b/src/mod/endpoints/mod_sofia/mod_sofia.h index fe9b0c393c..7cd5c3e02f 100644 --- a/src/mod/endpoints/mod_sofia/mod_sofia.h +++ b/src/mod/endpoints/mod_sofia/mod_sofia.h @@ -381,6 +381,7 @@ struct private_object { char *gateway_name; char *local_crypto_key; char *remote_crypto_key; + char *record_route; int crypto_tag; unsigned char local_raw_key[SWITCH_RTP_MAX_CRYPTO_LEN]; unsigned char remote_raw_key[SWITCH_RTP_MAX_CRYPTO_LEN]; @@ -421,6 +422,8 @@ struct private_object { uint32_t video_count; sofia_dtmf_t dtmf_type; int q850_cause; + char *remote_ip; + int remote_port; }; struct callback_t { diff --git a/src/mod/endpoints/mod_sofia/sofia.c b/src/mod/endpoints/mod_sofia/sofia.c index eb2e21a6c6..6e1d76221f 100644 --- a/src/mod/endpoints/mod_sofia/sofia.c +++ b/src/mod/endpoints/mod_sofia/sofia.c @@ -2586,7 +2586,7 @@ void sofia_handle_sip_i_invite(nua_t *nua, sofia_profile_t *profile, nua_handle_ uint32_t sess_max = switch_core_session_limit(0); int is_auth = 0, calling_myself = 0; su_addrinfo_t *my_addrinfo = msg_addrinfo(nua_current_request(nua)); - + int network_port = 0; if (sess_count >= sess_max || !(profile->pflags & PFLAG_RUNNING)) { nua_respond(nh, 503, "Maximum Calls In Progress", SIPTAG_RETRY_AFTER_STR("300"), TAG_END()); @@ -2601,6 +2601,7 @@ void sofia_handle_sip_i_invite(nua_t *nua, sofia_profile_t *profile, nua_handle_ get_addr(network_ip, sizeof(network_ip), &((struct sockaddr_in *) my_addrinfo->ai_addr)->sin_addr); + network_port = ntohs(((struct sockaddr_in *) msg_addrinfo(nua_current_request(nua))->ai_addr)->sin_port); if (profile->acl_count) { uint32_t x = 0; @@ -2649,6 +2650,17 @@ void sofia_handle_sip_i_invite(nua_t *nua, sofia_profile_t *profile, nua_handle_ } switch_mutex_init(&tech_pvt->flag_mutex, SWITCH_MUTEX_NESTED, switch_core_session_get_pool(session)); + tech_pvt->remote_ip = switch_core_session_strdup(session, network_ip); + tech_pvt->remote_port = network_port; + + if (sip->sip_contact && sip->sip_contact->m_url) { + tech_pvt->record_route = switch_core_session_sprintf(session, "", + sip->sip_contact->m_url->url_user, + tech_pvt->remote_ip, + tech_pvt->remote_port); + } + + if (*key != '\0') { tech_pvt->key = switch_core_session_strdup(session, key); } diff --git a/src/switch_console.c b/src/switch_console.c index e6eedd6a81..4b865e309a 100644 --- a/src/switch_console.c +++ b/src/switch_console.c @@ -584,8 +584,16 @@ SWITCH_DECLARE(switch_status_t) switch_console_set_complete(const char *string) switch_stream_handle_t mystream = { 0 }; SWITCH_STANDARD_STREAM(mystream); - if (!strcasecmp(argv[0], "add")) { - mystream.write_function(&mystream, "insert into complete values ("); + + if (!strcasecmp(argv[0], "stickyadd")) { + mystream.write_function(&mystream, "insert into complete values (1,"); + for(x = 0; x < 10; x++) { + mystream.write_function(&mystream, "'%s'%s", switch_str_nil(argv[x+1]), x == 9 ? ")" : ", "); + } + switch_core_db_persistant_execute(db, mystream.data, 5); + status = SWITCH_STATUS_SUCCESS; + } else if (!strcasecmp(argv[0], "add")) { + mystream.write_function(&mystream, "insert into complete values (0,"); for(x = 0; x < 10; x++) { mystream.write_function(&mystream, "'%s'%s", switch_str_nil(argv[x+1]), x == 9 ? ")" : ", "); } @@ -627,11 +635,19 @@ SWITCH_DECLARE(switch_status_t) switch_console_set_alias(const char *string) switch_core_db_t *db = switch_core_db_handle(); char *sql = NULL; - if (!strcasecmp(argv[0], "add") && argc == 3) { + + if (!strcasecmp(argv[0], "stickyadd") && argc == 3) { sql = switch_mprintf("delete from aliases where alias='%q'", argv[1]); switch_core_db_persistant_execute(db, sql, 5); switch_safe_free(sql); - sql = switch_mprintf("insert into aliases (alias, command) values ('%q','%q')", argv[1], argv[2]); + sql = switch_mprintf("insert into aliases (sticky, alias, command) values (1, '%q','%q')", argv[1], argv[2]); + switch_core_db_persistant_execute(db, sql, 5); + status = SWITCH_STATUS_SUCCESS; + } else if (!strcasecmp(argv[0], "add") && argc == 3) { + sql = switch_mprintf("delete from aliases where alias='%q'", argv[1]); + switch_core_db_persistant_execute(db, sql, 5); + switch_safe_free(sql); + sql = switch_mprintf("insert into aliases (sticky, alias, command) values (0, '%q','%q')", argv[1], argv[2]); switch_core_db_persistant_execute(db, sql, 5); status = SWITCH_STATUS_SUCCESS; } else if (!strcasecmp(argv[0], "del") && argc == 2) { diff --git a/src/switch_core_sqldb.c b/src/switch_core_sqldb.c index 8931fef30a..7fd40e0e9d 100644 --- a/src/switch_core_sqldb.c +++ b/src/switch_core_sqldb.c @@ -368,6 +368,7 @@ void switch_core_sqldb_start(switch_memory_pool_t *pool) } else { char create_complete_sql[] = "CREATE TABLE complete (\n" + " sticky INTEGER,\n" " a1 VARCHAR(255),\n" " a2 VARCHAR(255),\n" " a3 VARCHAR(255),\n" @@ -382,6 +383,7 @@ void switch_core_sqldb_start(switch_memory_pool_t *pool) char create_alias_sql[] = "CREATE TABLE aliases (\n" + " sticky INTEGER,\n" " alias VARCHAR(255),\n" " command VARCHAR(255)\n" ");\n"; @@ -445,8 +447,10 @@ void switch_core_sqldb_start(switch_memory_pool_t *pool) switch_core_db_exec(sql_manager.db, "PRAGMA cache_size=8000", NULL, NULL, NULL); switch_core_db_exec(sql_manager.db, "PRAGMA temp_store=MEMORY;", NULL, NULL, NULL); - switch_core_db_test_reactive(sql_manager.db, "select a1 from complete", "DROP TABLE complete", create_complete_sql); - switch_core_db_test_reactive(sql_manager.db, "select alias from aliases", "DROP TABLE aliases", create_alias_sql); + switch_core_db_test_reactive(sql_manager.db, "select sticky from complete", "DROP TABLE complete", create_complete_sql); + switch_core_db_test_reactive(sql_manager.db, "select sticky from aliases", "DROP TABLE aliases", create_alias_sql); + switch_core_db_exec(sql_manager.db, "delete from complete where sticky=0", NULL, NULL, NULL); + switch_core_db_exec(sql_manager.db, "delete from aliases where sticky=0", NULL, NULL, NULL); switch_core_db_exec(sql_manager.db, create_channels_sql, NULL, NULL, NULL); switch_core_db_exec(sql_manager.db, create_calls_sql, NULL, NULL, NULL); switch_core_db_exec(sql_manager.db, create_interfaces_sql, NULL, NULL, NULL);