From 079f48458e024a87c4ce6336a6f88d50a18d4f25 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Wed, 8 Jun 2011 11:09:03 -0500 Subject: [PATCH 01/10] add check_sync to sofia cli (like flush_inbound_reg without the unreg) --- src/mod/endpoints/mod_sofia/mod_sofia.c | 15 +++++ src/mod/endpoints/mod_sofia/mod_sofia.h | 2 + src/mod/endpoints/mod_sofia/sofia_reg.c | 86 +++++++++++++++++++++++++ 3 files changed, 103 insertions(+) diff --git a/src/mod/endpoints/mod_sofia/mod_sofia.c b/src/mod/endpoints/mod_sofia/mod_sofia.c index 31d437d7b0..69f7b24f30 100644 --- a/src/mod/endpoints/mod_sofia/mod_sofia.c +++ b/src/mod/endpoints/mod_sofia/mod_sofia.c @@ -3273,6 +3273,19 @@ static switch_status_t cmd_profile(char **argv, int argc, switch_stream_handle_t goto done; } + if (!strcasecmp(argv[1], "check_sync")) { + if (argc > 2) { + sofia_reg_check_call_id(profile, argv[2]); + stream->write_function(stream, "+OK syncing all registrations matching specified call_id\n"); + } else { + sofia_reg_check_sync(profile); + stream->write_function(stream, "+OK syncing all registrations\n"); + } + + goto done; + } + + if (!strcasecmp(argv[1], "flush_inbound_reg")) { int reboot = 0; @@ -3853,6 +3866,7 @@ SWITCH_STANDARD_API(sofia_function) " watchdog \n\n" "sofia profile [start | stop | restart | rescan]\n" " flush_inbound_reg [ | <[user]@domain>] [reboot]\n" + " check_sync [ | <[user]@domain>]\n" " [register | unregister] [ | all]\n" " killgw \n" " [stun-auto-disable | stun-enabled] [true | false]]\n" @@ -5158,6 +5172,7 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_sofia_load) switch_console_set_complete("add sofia profile ::sofia::list_profiles restart"); switch_console_set_complete("add sofia profile ::sofia::list_profiles flush_inbound_reg"); + switch_console_set_complete("add sofia profile ::sofia::list_profiles check_sync"); switch_console_set_complete("add sofia profile ::sofia::list_profiles register ::sofia::list_profile_gateway"); switch_console_set_complete("add sofia profile ::sofia::list_profiles unregister ::sofia::list_profile_gateway"); switch_console_set_complete("add sofia profile ::sofia::list_profiles killgw ::sofia::list_profile_gateway"); diff --git a/src/mod/endpoints/mod_sofia/mod_sofia.h b/src/mod/endpoints/mod_sofia/mod_sofia.h index 4b41189a02..ed57e81e1e 100644 --- a/src/mod/endpoints/mod_sofia/mod_sofia.h +++ b/src/mod/endpoints/mod_sofia/mod_sofia.h @@ -983,6 +983,8 @@ void sofia_glue_tech_patch_sdp(private_object_t *tech_pvt); switch_status_t sofia_glue_tech_proxy_remote_addr(private_object_t *tech_pvt); void sofia_presence_event_thread_start(void); void sofia_reg_expire_call_id(sofia_profile_t *profile, const char *call_id, int reboot); +void sofia_reg_check_call_id(sofia_profile_t *profile, const char *call_id); +void sofia_reg_check_sync(sofia_profile_t *profile); switch_status_t sofia_glue_tech_choose_video_port(private_object_t *tech_pvt, int force); switch_status_t sofia_glue_tech_set_video_codec(private_object_t *tech_pvt, int force); char *sofia_glue_get_register_host(const char *uri); diff --git a/src/mod/endpoints/mod_sofia/sofia_reg.c b/src/mod/endpoints/mod_sofia/sofia_reg.c index fa837eb830..df02436ecd 100644 --- a/src/mod/endpoints/mod_sofia/sofia_reg.c +++ b/src/mod/endpoints/mod_sofia/sofia_reg.c @@ -733,6 +733,92 @@ void sofia_reg_check_expire(sofia_profile_t *profile, time_t now, int reboot) } + +int sofia_reg_check_callback(void *pArg, int argc, char **argv, char **columnNames) +{ + sofia_profile_t *profile = (sofia_profile_t *) pArg; + + sofia_reg_send_reboot(profile, argv[1], argv[2], argv[3], argv[7], argv[11]); + + return 0; +} + +void sofia_reg_check_call_id(sofia_profile_t *profile, const char *call_id) +{ + char *sql = NULL; + char *sqlextra = NULL; + char *dup = strdup(call_id); + char *host = NULL, *user = NULL; + + switch_assert(dup); + + if ((host = strchr(dup, '@'))) { + *host++ = '\0'; + user = dup; + } else { + host = dup; + } + + if (!host) { + host = "none"; + } + + if (zstr(user)) { + sqlextra = switch_mprintf(" or (sip_host='%q')", host); + } else { + sqlextra = switch_mprintf(" or (sip_user='%q' and sip_host='%q')", user, host); + } + + sql = switch_mprintf("select call_id,sip_user,sip_host,contact,status,rpid,expires" + ",user_agent,server_user,server_host,profile_name,network_ip" + " from sip_registrations where call_id='%q' %s", call_id, sqlextra); + + switch_mutex_lock(profile->ireg_mutex); + sofia_glue_execute_sql_callback(profile, NULL, sql, sofia_reg_check_callback, profile); + switch_mutex_unlock(profile->ireg_mutex); + + switch_safe_free(sql); + switch_safe_free(sqlextra); + switch_safe_free(dup); + +} + +void sofia_reg_check_sync(sofia_profile_t *profile) +{ + char sql[1024]; + + switch_mutex_lock(profile->ireg_mutex); + + switch_snprintf(sql, sizeof(sql), "select call_id,sip_user,sip_host,contact,status,rpid,expires" + ",user_agent,server_user,server_host,profile_name,network_ip" + " from sip_registrations where expires > 0"); + + + sofia_glue_execute_sql_callback(profile, NULL, sql, sofia_reg_del_callback, profile); + switch_snprintf(sql, sizeof(sql), "delete from sip_registrations where expires > 0 and hostname='%s'", mod_sofia_globals.hostname); + sofia_glue_actually_execute_sql(profile, sql, NULL); + + + switch_snprintf(sql, sizeof(sql), "delete from sip_presence where expires > 0 and hostname='%s'", mod_sofia_globals.hostname); + sofia_glue_actually_execute_sql(profile, sql, NULL); + + switch_snprintf(sql, sizeof(sql), "delete from sip_authentication where expires > 0 and hostname='%s'", mod_sofia_globals.hostname); + sofia_glue_actually_execute_sql(profile, sql, NULL); + + switch_snprintf(sql, sizeof(sql), "select sub_to_user,sub_to_host,call_id from sip_subscriptions where expires >= -1 and hostname='%s'", + mod_sofia_globals.hostname); + sofia_glue_execute_sql_callback(profile, NULL, sql, sofia_sub_del_callback, profile); + + switch_snprintf(sql, sizeof(sql), "delete from sip_subscriptions where expires >= -1 and hostname='%s'", mod_sofia_globals.hostname); + sofia_glue_actually_execute_sql(profile, sql, NULL); + + switch_snprintf(sql, sizeof(sql), "delete from sip_dialogs where expires >= -1 and hostname='%s'", mod_sofia_globals.hostname); + sofia_glue_actually_execute_sql(profile, sql, NULL); + + switch_mutex_unlock(profile->ireg_mutex); + +} + char *sofia_reg_find_reg_url(sofia_profile_t *profile, const char *user, const char *host, char *val, switch_size_t len) { struct callback_t cbt = { 0 }; From e8962d568796b90e1f32944b8b870571accd7620 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Wed, 8 Jun 2011 15:08:41 -0500 Subject: [PATCH 02/10] move muted/unmuted indications to main thread via flags --- .../mod_conference/mod_conference.c | 47 ++++++++++++------- 1 file changed, 31 insertions(+), 16 deletions(-) diff --git a/src/mod/applications/mod_conference/mod_conference.c b/src/mod/applications/mod_conference/mod_conference.c index bd8559f95a..d08eb94d09 100644 --- a/src/mod/applications/mod_conference/mod_conference.c +++ b/src/mod/applications/mod_conference/mod_conference.c @@ -141,7 +141,9 @@ typedef enum { MFLAG_MINTWO = (1 << 13), MFLAG_MUTE_DETECT = (1 << 14), MFLAG_DIST_DTMF = (1 << 15), - MFLAG_MOD = (1 << 16) + MFLAG_MOD = (1 << 16), + MFLAG_INDICATE_MUTE = (1 << 17), + MFLAG_INDICATE_UNMUTE = (1 << 18) } member_flag_t; typedef enum { @@ -2745,6 +2747,30 @@ static void conference_loop_output(conference_member_t *member) switch_mutex_unlock(member->write_mutex); + if (switch_test_flag(member, MFLAG_INDICATE_MUTE)) { + if (!zstr(member->conference->muted_sound)) { + conference_member_play_file(member, member->conference->muted_sound, 0); + } else { + char msg[512]; + + switch_snprintf(msg, sizeof(msg), "Muted"); + conference_member_say(member, msg, 0); + } + switch_clear_flag(member, MFLAG_INDICATE_MUTE); + } + + if (switch_test_flag(member, MFLAG_INDICATE_UNMUTE)) { + if (!zstr(member->conference->unmuted_sound)) { + conference_member_play_file(member, member->conference->unmuted_sound, 0); + } else { + char msg[512]; + + switch_snprintf(msg, sizeof(msg), "Un-Muted"); + conference_member_say(member, msg, 0); + } + switch_clear_flag(member, MFLAG_INDICATE_UNMUTE); + } + if (switch_core_session_private_event_count(member->session)) { switch_channel_set_app_flag(channel, CF_APP_TAGGED); switch_ivr_parse_all_events(member->session); @@ -3608,18 +3634,12 @@ static switch_status_t conf_api_sub_mute(conference_member_t *member, switch_str switch_clear_flag_locked(member, MFLAG_CAN_SPEAK); switch_clear_flag_locked(member, MFLAG_TALKING); + switch_set_flag(member, MFLAG_INDICATE_MUTE); - if (!zstr(member->conference->muted_sound)) { - conference_member_play_file(member, member->conference->muted_sound, 0); - } else { - char msg[512]; - - switch_snprintf(msg, sizeof(msg), "Muted"); - conference_member_say(member, msg, 0); - } if (stream != NULL) { stream->write_function(stream, "OK mute %u\n", member->id); } + if (test_eflag(member->conference, EFLAG_MUTE_MEMBER) && switch_event_create_subclass(&event, SWITCH_EVENT_CUSTOM, CONF_EVENT_MAINT) == SWITCH_STATUS_SUCCESS) { conference_add_event_member_data(member, event); @@ -3684,17 +3704,12 @@ static switch_status_t conf_api_sub_unmute(conference_member_t *member, switch_s return SWITCH_STATUS_GENERR; switch_set_flag_locked(member, MFLAG_CAN_SPEAK); + switch_set_flag(member, MFLAG_INDICATE_UNMUTE); + if (stream != NULL) { stream->write_function(stream, "OK unmute %u\n", member->id); } - if (!zstr(member->conference->unmuted_sound)) { - conference_member_play_file(member, member->conference->unmuted_sound, 0); - } else { - char msg[512]; - switch_snprintf(msg, sizeof(msg), "Un-Muted"); - conference_member_say(member, msg, 0); - } if (test_eflag(member->conference, EFLAG_UNMUTE_MEMBER) && switch_event_create_subclass(&event, SWITCH_EVENT_CUSTOM, CONF_EVENT_MAINT) == SWITCH_STATUS_SUCCESS) { conference_add_event_member_data(member, event); From 07a797522ab5824988b4904dab072f18ee1f25d0 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Wed, 8 Jun 2011 18:50:21 -0500 Subject: [PATCH 03/10] FS-3214 try this patch --- src/include/switch_types.h | 4 +++- src/mod/applications/mod_spandsp/mod_spandsp_fax.c | 6 +++++- src/mod/endpoints/mod_sofia/mod_sofia.c | 6 ++++++ src/mod/endpoints/mod_sofia/sofia.c | 13 +++++++++++++ src/mod/endpoints/mod_sofia/sofia_glue.c | 1 + 5 files changed, 28 insertions(+), 2 deletions(-) diff --git a/src/include/switch_types.h b/src/include/switch_types.h index 2b2b3de45d..bf5d5d88ea 100644 --- a/src/include/switch_types.h +++ b/src/include/switch_types.h @@ -1120,7 +1120,9 @@ typedef enum { typedef enum { CF_APP_TAGGED = (1 << 0), - CF_APP_T38 = (1 << 1) + CF_APP_T38 = (1 << 1), + CF_APP_T38_REQ = (1 << 2), + CF_APP_T38_FAIL = (1 << 3) } switch_channel_app_flag_t; diff --git a/src/mod/applications/mod_spandsp/mod_spandsp_fax.c b/src/mod/applications/mod_spandsp/mod_spandsp_fax.c index 119294f4bd..e4457bd5b9 100644 --- a/src/mod/applications/mod_spandsp/mod_spandsp_fax.c +++ b/src/mod/applications/mod_spandsp/mod_spandsp_fax.c @@ -904,6 +904,7 @@ static t38_mode_t request_t38(pvt_t *pvt) switch_channel_set_private(channel, "t38_options", t38_options); pvt->t38_mode = T38_MODE_REQUESTED; + switch_channel_set_app_flag_key("T38", channel, CF_APP_T38_REQ); /* This will send a request for t.38 mode */ msg.from = __FILE__; @@ -1173,7 +1174,10 @@ void mod_spandsp_fax_process_fax(switch_core_session_t *session, const char *dat switch (pvt->t38_mode) { case T38_MODE_REQUESTED: { - if (switch_channel_test_app_flag_key("T38", channel, CF_APP_T38)) { + if (switch_channel_test_app_flag_key("T38", channel, CF_APP_T38_FAIL)) { + pvt->t38_mode = T38_MODE_REFUSED; + continue; + } else if (switch_channel_test_app_flag_key("T38", channel, CF_APP_T38)) { switch_core_session_message_t msg = { 0 }; pvt->t38_mode = T38_MODE_NEGOTIATED; spanfax_init(pvt, T38_MODE); diff --git a/src/mod/endpoints/mod_sofia/mod_sofia.c b/src/mod/endpoints/mod_sofia/mod_sofia.c index 69f7b24f30..86fa140046 100644 --- a/src/mod/endpoints/mod_sofia/mod_sofia.c +++ b/src/mod/endpoints/mod_sofia/mod_sofia.c @@ -524,6 +524,12 @@ switch_status_t sofia_on_hangup(switch_core_session_t *session) if (!sofia_test_flag(tech_pvt, TFLAG_BYE)) { char *cid = generate_pai_str(tech_pvt); + if (sip_cause > 299) { + switch_channel_clear_app_flag_key("T38", tech_pvt->channel, CF_APP_T38); + switch_channel_clear_app_flag_key("T38", tech_pvt->channel, CF_APP_T38_REQ); + switch_channel_set_app_flag_key("T38", tech_pvt->channel, CF_APP_T38_FAIL); + } + nua_respond(tech_pvt->nh, sip_cause, sip_status_phrase(sip_cause), TAG_IF(!zstr(reason), SIPTAG_REASON_STR(reason)), TAG_IF(cid, SIPTAG_HEADER_STR(cid)), TAG_IF(!zstr(bye_headers), SIPTAG_HEADER_STR(bye_headers)), TAG_END()); diff --git a/src/mod/endpoints/mod_sofia/sofia.c b/src/mod/endpoints/mod_sofia/sofia.c index 12b0280974..c5efbf63bb 100644 --- a/src/mod/endpoints/mod_sofia/sofia.c +++ b/src/mod/endpoints/mod_sofia/sofia.c @@ -4161,6 +4161,16 @@ static void sofia_handle_sip_r_invite(switch_core_session_t *session, int status tech_pvt->last_sdp_str = switch_core_session_strdup(session, sip->sip_payload->pl_data); } + + if (status > 299 && switch_channel_test_app_flag_key("T38", tech_pvt->channel, CF_APP_T38_REQ)) { + switch_channel_set_private(channel, "t38_options", NULL); + switch_channel_clear_app_flag_key("T38", tech_pvt->channel, CF_APP_T38); + switch_channel_clear_app_flag_key("T38", tech_pvt->channel, CF_APP_T38_REQ); + switch_channel_set_app_flag_key("T38", tech_pvt->channel, CF_APP_T38_FAIL); + switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "%s T38 invite failed\n", switch_channel_get_name(tech_pvt->channel)); + } + + if (sofia_test_pflag(profile, PFLAG_MANAGE_SHARED_APPEARANCE)) { if (channel && sip->sip_call_info) { char *p; @@ -4462,6 +4472,9 @@ static void sofia_handle_sip_r_invite(switch_core_session_t *session, int status switch_channel_set_private(other_channel, "t38_options", NULL); sofia_clear_flag(tech_pvt, TFLAG_T38_PASSTHRU); sofia_clear_flag(other_tech_pvt, TFLAG_T38_PASSTHRU); + switch_channel_clear_app_flag_key("T38", tech_pvt->channel, CF_APP_T38); + switch_channel_clear_app_flag_key("T38", tech_pvt->channel, CF_APP_T38_REQ); + switch_channel_set_app_flag_key("T38", tech_pvt->channel, CF_APP_T38_FAIL); } else if (status == 200 && sofia_test_flag(tech_pvt, TFLAG_T38_PASSTHRU) && has_t38 && sip->sip_payload && sip->sip_payload->pl_data) { switch_t38_options_t *t38_options = sofia_glue_extract_t38_options(session, sip->sip_payload->pl_data); diff --git a/src/mod/endpoints/mod_sofia/sofia_glue.c b/src/mod/endpoints/mod_sofia/sofia_glue.c index b308b6038e..a0f71a9466 100644 --- a/src/mod/endpoints/mod_sofia/sofia_glue.c +++ b/src/mod/endpoints/mod_sofia/sofia_glue.c @@ -4391,6 +4391,7 @@ uint8_t sofia_glue_negotiate_sdp(switch_core_session_t *session, const char *r_s switch_t38_options_t *t38_options = tech_process_udptl(tech_pvt, sdp, m); if (switch_true(switch_channel_get_variable(channel, "refuse_t38"))) { + switch_channel_clear_app_flag_key("T38", tech_pvt->channel, CF_APP_T38); match = 0; goto done; } else { From e2ed8c08ef4dec7d872f6d67227d4a4ffcc40b27 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Wed, 8 Jun 2011 19:32:18 -0500 Subject: [PATCH 04/10] pop :: off the domain name in mwi events to hint at the profile --- src/mod/endpoints/mod_sofia/sofia_presence.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/mod/endpoints/mod_sofia/sofia_presence.c b/src/mod/endpoints/mod_sofia/sofia_presence.c index 1d65a15081..404c50c80d 100644 --- a/src/mod/endpoints/mod_sofia/sofia_presence.c +++ b/src/mod/endpoints/mod_sofia/sofia_presence.c @@ -364,6 +364,7 @@ static void actual_sofia_presence_mwi_event_handler(switch_event_t *event) const char *call_id; const char *sub_call_id; int for_everyone = 0; + char *tmp_pname; switch_assert(event != NULL); @@ -389,8 +390,15 @@ static void actual_sofia_presence_mwi_event_handler(switch_event_t *event) switch_assert(dup_account != NULL); switch_split_user_domain(dup_account, &user, &host); + if (host && (tmp_pname = strstr(host, "::"))) { + *tmp_pname = '\0'; + tmp_pname += 2; + pname = tmp_pname; + profile = sofia_glue_find_profile(pname); + } - if ((pname = switch_event_get_header(event, "sofia-profile"))) { + + if (!profile && (pname = switch_event_get_header(event, "sofia-profile"))) { profile = sofia_glue_find_profile(pname); } From d3ea42d82acb1e0b4431769bff6f11eb8e30b35c Mon Sep 17 00:00:00 2001 From: Jeff Lenk Date: Thu, 9 Jun 2011 09:52:11 -0500 Subject: [PATCH 05/10] FS-3334 --resolve libdingaling this was a small leak --- libs/libdingaling/src/libdingaling.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/libs/libdingaling/src/libdingaling.c b/libs/libdingaling/src/libdingaling.c index bbf26ca5c9..76b19f118f 100644 --- a/libs/libdingaling/src/libdingaling.c +++ b/libs/libdingaling/src/libdingaling.c @@ -1908,6 +1908,8 @@ void ldl_handle_send_msg(ldl_handle_t *handle, char *from, char *to, const char int on = 0; int len = 0; char *my_body = strdup(body); + char *my_body_base = my_body; + assert(handle != NULL); assert(body != NULL); @@ -1952,7 +1954,9 @@ void ldl_handle_send_msg(ldl_handle_t *handle, char *from, char *to, const char free(bdup); } - free(my_body); + if (my_body_base) { + free(my_body_base); + } apr_queue_push(handle->queue, msg); msg = NULL; From 7330a06f998eab44de797d964bd26b8e0c8fe349 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Thu, 9 Jun 2011 10:22:40 -0500 Subject: [PATCH 06/10] FS-3214 try this patch too --- src/mod/endpoints/mod_sofia/mod_sofia.h | 1 + src/mod/endpoints/mod_sofia/sofia.c | 4 ++-- src/mod/endpoints/mod_sofia/sofia_glue.c | 4 ++++ 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/mod/endpoints/mod_sofia/mod_sofia.h b/src/mod/endpoints/mod_sofia/mod_sofia.h index ed57e81e1e..b996167074 100644 --- a/src/mod/endpoints/mod_sofia/mod_sofia.h +++ b/src/mod/endpoints/mod_sofia/mod_sofia.h @@ -295,6 +295,7 @@ typedef enum { TFLAG_NOTIMER_DURING_BRIDGE, TFLAG_JB_PAUSED, TFLAG_3PCC_INVITE, + TFLAG_NOREPLY, /* No new flags below this line */ TFLAG_MAX } TFLAGS; diff --git a/src/mod/endpoints/mod_sofia/sofia.c b/src/mod/endpoints/mod_sofia/sofia.c index c5efbf63bb..734fa4f6d0 100644 --- a/src/mod/endpoints/mod_sofia/sofia.c +++ b/src/mod/endpoints/mod_sofia/sofia.c @@ -5244,8 +5244,8 @@ static void sofia_handle_sip_i_state(switch_core_session_t *session, int status, if (tech_pvt->num_codecs) { match = sofia_glue_negotiate_sdp(session, r_sdp); } - - if (match && switch_channel_test_app_flag_key("T38", tech_pvt->channel, CF_APP_T38)) { + + if (match && sofia_test_flag(tech_pvt, TFLAG_NOREPLY)) { goto done; } diff --git a/src/mod/endpoints/mod_sofia/sofia_glue.c b/src/mod/endpoints/mod_sofia/sofia_glue.c index a0f71a9466..dba65d2aac 100644 --- a/src/mod/endpoints/mod_sofia/sofia_glue.c +++ b/src/mod/endpoints/mod_sofia/sofia_glue.c @@ -4389,6 +4389,10 @@ uint8_t sofia_glue_negotiate_sdp(switch_core_session_t *session, const char *r_s if (got_udptl && m->m_type == sdp_media_image && m->m_port) { switch_t38_options_t *t38_options = tech_process_udptl(tech_pvt, sdp, m); + + if (switch_channel_test_app_flag_key("T38", tech_pvt->channel, CF_APP_T38)) { + sofia_set_flag(tech_pvt, TFLAG_NOREPLY); + } if (switch_true(switch_channel_get_variable(channel, "refuse_t38"))) { switch_channel_clear_app_flag_key("T38", tech_pvt->channel, CF_APP_T38); From 7200408062444ff4ed4f50477a69f49bba3bea4d Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Thu, 9 Jun 2011 10:36:35 -0500 Subject: [PATCH 07/10] revert e2ed8c08ef4dec7d872f6d67227d4a4ffcc40b27 --- src/mod/endpoints/mod_sofia/sofia_presence.c | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/src/mod/endpoints/mod_sofia/sofia_presence.c b/src/mod/endpoints/mod_sofia/sofia_presence.c index 404c50c80d..1d65a15081 100644 --- a/src/mod/endpoints/mod_sofia/sofia_presence.c +++ b/src/mod/endpoints/mod_sofia/sofia_presence.c @@ -364,7 +364,6 @@ static void actual_sofia_presence_mwi_event_handler(switch_event_t *event) const char *call_id; const char *sub_call_id; int for_everyone = 0; - char *tmp_pname; switch_assert(event != NULL); @@ -390,15 +389,8 @@ static void actual_sofia_presence_mwi_event_handler(switch_event_t *event) switch_assert(dup_account != NULL); switch_split_user_domain(dup_account, &user, &host); - if (host && (tmp_pname = strstr(host, "::"))) { - *tmp_pname = '\0'; - tmp_pname += 2; - pname = tmp_pname; - profile = sofia_glue_find_profile(pname); - } - - if (!profile && (pname = switch_event_get_header(event, "sofia-profile"))) { + if ((pname = switch_event_get_header(event, "sofia-profile"))) { profile = sofia_glue_find_profile(pname); } From b14340a5daf2318a25c5ebbda85bcc47b2e39697 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Thu, 9 Jun 2011 10:45:28 -0500 Subject: [PATCH 08/10] dig into the database to figure out what profile to send mwi on when they are not willing to alais the domain to the profile =/ --- src/mod/endpoints/mod_sofia/sofia_presence.c | 27 +++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/src/mod/endpoints/mod_sofia/sofia_presence.c b/src/mod/endpoints/mod_sofia/sofia_presence.c index 1d65a15081..a7490f6a8b 100644 --- a/src/mod/endpoints/mod_sofia/sofia_presence.c +++ b/src/mod/endpoints/mod_sofia/sofia_presence.c @@ -396,9 +396,30 @@ static void actual_sofia_presence_mwi_event_handler(switch_event_t *event) if (!profile) { if (!host || !(profile = sofia_glue_find_profile(host))) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Cannot find profile %s\n", switch_str_nil(host)); - switch_safe_free(dup_account); - return; + char *sql; + switch_hash_index_t *hi; + void *val; + const void *vvar; + char buf[512] = ""; + + sql = switch_mprintf("select profile_name from sip_registrations where sip_host='%s' or mwi_host='%s'", host, host); + + switch_mutex_lock(mod_sofia_globals.hash_mutex); + for (hi = switch_hash_first(NULL, mod_sofia_globals.profile_hash); hi; hi = switch_hash_next(hi)) { + switch_hash_this(hi, &vvar, NULL, &val); + profile = (sofia_profile_t *) val; + sofia_glue_execute_sql2str(profile, profile->ireg_mutex, sql, buf, sizeof(buf)); + if (!zstr(buf)) { + break; + } + } + switch_mutex_unlock(mod_sofia_globals.hash_mutex); + + if (!(profile = sofia_glue_find_profile(buf))) { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Cannot find profile %s\n", switch_str_nil(host)); + switch_safe_free(dup_account); + return; + } } } From 7d2e2ce0714385bfb9e39d6bdab48d1c78bf6bd6 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Thu, 9 Jun 2011 10:57:04 -0500 Subject: [PATCH 09/10] FS-3214 forgot 1 important line --- src/mod/endpoints/mod_sofia/sofia.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/mod/endpoints/mod_sofia/sofia.c b/src/mod/endpoints/mod_sofia/sofia.c index 734fa4f6d0..5b130850b2 100644 --- a/src/mod/endpoints/mod_sofia/sofia.c +++ b/src/mod/endpoints/mod_sofia/sofia.c @@ -5246,6 +5246,7 @@ static void sofia_handle_sip_i_state(switch_core_session_t *session, int status, } if (match && sofia_test_flag(tech_pvt, TFLAG_NOREPLY)) { + sofia_clear_flag(tech_pvt, TFLAG_NOREPLY); goto done; } From 7e6b59ffe1ca488c20e0632e1745ff68addcc20c Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Thu, 9 Jun 2011 12:17:32 -0500 Subject: [PATCH 10/10] add some various api util --- src/include/switch_apr.h | 2 ++ src/include/switch_buffer.h | 2 ++ src/include/switch_core.h | 30 +++++++++++++++++++++-- src/switch_buffer.c | 16 +++++++++++++ src/switch_core_hash.c | 47 +++++++++++++++++++++++++++++++++++++ 5 files changed, 95 insertions(+), 2 deletions(-) diff --git a/src/include/switch_apr.h b/src/include/switch_apr.h index 2306075e1f..c7279b6a8c 100644 --- a/src/include/switch_apr.h +++ b/src/include/switch_apr.h @@ -1202,6 +1202,8 @@ SWITCH_DECLARE(switch_status_t) switch_socket_send(switch_socket_t *sock, const */ SWITCH_DECLARE(switch_status_t) switch_socket_sendto(switch_socket_t *sock, switch_sockaddr_t *where, int32_t flags, const char *buf, switch_size_t *len); + +SWITCH_DECLARE(switch_status_t) switch_socket_send_nonblock(switch_socket_t *sock, const char *buf, switch_size_t *len); /** * @param from The apr_sockaddr_t to fill in the recipient info diff --git a/src/include/switch_buffer.h b/src/include/switch_buffer.h index 75b5929b9b..751439d1ad 100644 --- a/src/include/switch_buffer.h +++ b/src/include/switch_buffer.h @@ -109,6 +109,8 @@ SWITCH_DECLARE(switch_size_t) switch_buffer_read(_In_ switch_buffer_t *buffer, _ */ SWITCH_DECLARE(switch_size_t) switch_buffer_peek(_In_ switch_buffer_t *buffer, _In_ void *data, _In_ switch_size_t datalen); +SWITCH_DECLARE(switch_size_t) switch_buffer_peek_zerocopy(_In_ switch_buffer_t *buffer, _Out_ const void **ptr); + /*! \brief Read data endlessly from a switch_buffer_t * \param buffer any buffer of type switch_buffer_t * \param data pointer to the read data to be returned diff --git a/src/include/switch_core.h b/src/include/switch_core.h index 681fbf4dc6..9e16346199 100644 --- a/src/include/switch_core.h +++ b/src/include/switch_core.h @@ -1227,7 +1227,15 @@ SWITCH_DECLARE(switch_status_t) switch_core_hash_insert(_In_ switch_hash_t *hash \note the string key must be a constant or a dynamic string */ SWITCH_DECLARE(switch_status_t) switch_core_hash_insert_locked(_In_ switch_hash_t *hash, _In_z_ const char *key, _In_opt_ const void *data, - _In_ switch_mutex_t *mutex); + _In_opt_ switch_mutex_t *mutex); +/*! + \brief Retrieve data from a given hash + \param hash the hash to retrieve from + \param key the key to retrieve + \param mutex optional rwlock to wrlock + \return a pointer to the data held in the key +*/ +SWITCH_DECLARE(switch_status_t) switch_core_hash_insert_wrlock(switch_hash_t *hash, const char *key, const void *data, switch_thread_rwlock_t *rwlock); /*! \brief Delete data from a hash based on desired key @@ -1244,7 +1252,16 @@ SWITCH_DECLARE(switch_status_t) switch_core_hash_delete(_In_ switch_hash_t *hash \param mutex optional mutex to lock \return SWITCH_STATUS_SUCCESS if the data is deleted */ -SWITCH_DECLARE(switch_status_t) switch_core_hash_delete_locked(_In_ switch_hash_t *hash, _In_z_ const char *key, _In_ switch_mutex_t *mutex); +SWITCH_DECLARE(switch_status_t) switch_core_hash_delete_locked(_In_ switch_hash_t *hash, _In_z_ const char *key, _In_opt_ switch_mutex_t *mutex); + +/*! + \brief Delete data from a hash based on desired key + \param hash the hash to delete from + \param key the key from which to delete the data + \param mutex optional rwlock to wrlock + \return SWITCH_STATUS_SUCCESS if the data is deleted +*/ +SWITCH_DECLARE(switch_status_t) switch_core_hash_delete_wrlock(_In_ switch_hash_t *hash, _In_z_ const char *key, _In_opt_ switch_thread_rwlock_t *rwlock); /*! \brief Delete data from a hash based on callback function @@ -1272,6 +1289,15 @@ SWITCH_DECLARE(void *) switch_core_hash_find(_In_ switch_hash_t *hash, _In_z_ co */ SWITCH_DECLARE(void *) switch_core_hash_find_locked(_In_ switch_hash_t *hash, _In_z_ const char *key, _In_ switch_mutex_t *mutex); +/*! + \brief Retrieve data from a given hash + \param hash the hash to retrieve from + \param key the key to retrieve + \param mutex optional rwlock to rdlock + \return a pointer to the data held in the key +*/ +SWITCH_DECLARE(void *) switch_core_hash_find_rdlock(_In_ switch_hash_t *hash, _In_z_ const char *key, _In_ switch_thread_rwlock_t *rwlock); + /*! \brief Gets the first element of a hashtable \param depricate_me [deprecated] NULL diff --git a/src/switch_buffer.c b/src/switch_buffer.c index 39d7bf04a1..0f104f5500 100644 --- a/src/switch_buffer.c +++ b/src/switch_buffer.c @@ -224,6 +224,22 @@ SWITCH_DECLARE(switch_size_t) switch_buffer_peek(switch_buffer_t *buffer, void * return reading; } +SWITCH_DECLARE(switch_size_t) switch_buffer_peek_zerocopy(switch_buffer_t *buffer, const void **ptr) +{ + switch_size_t reading = 0; + + if (buffer->used < 1) { + buffer->used = 0; + return 0; + } else { + reading = buffer->used; + } + + *ptr = buffer->head; + + return reading; +} + SWITCH_DECLARE(switch_size_t) switch_buffer_write(switch_buffer_t *buffer, const void *data, switch_size_t datalen) { switch_size_t freespace, actual_freespace; diff --git a/src/switch_core_hash.c b/src/switch_core_hash.c index 8d04e9c5f3..c47281db97 100644 --- a/src/switch_core_hash.c +++ b/src/switch_core_hash.c @@ -96,6 +96,21 @@ SWITCH_DECLARE(switch_status_t) switch_core_hash_insert_locked(switch_hash_t *ha return SWITCH_STATUS_SUCCESS; } +SWITCH_DECLARE(switch_status_t) switch_core_hash_insert_wrlock(switch_hash_t *hash, const char *key, const void *data, switch_thread_rwlock_t *rwlock) +{ + if (rwlock) { + switch_thread_rwlock_wrlock(rwlock); + } + + sqlite3HashInsert(&hash->table, key, (int) strlen(key) + 1, (void *) data); + + if (rwlock) { + switch_thread_rwlock_unlock(rwlock); + } + + return SWITCH_STATUS_SUCCESS; +} + SWITCH_DECLARE(switch_status_t) switch_core_hash_delete(switch_hash_t *hash, const char *key) { sqlite3HashInsert(&hash->table, key, (int) strlen(key) + 1, NULL); @@ -117,6 +132,21 @@ SWITCH_DECLARE(switch_status_t) switch_core_hash_delete_locked(switch_hash_t *ha return SWITCH_STATUS_SUCCESS; } +SWITCH_DECLARE(switch_status_t) switch_core_hash_delete_wrlock(switch_hash_t *hash, const char *key, switch_thread_rwlock_t *rwlock) +{ + if (rwlock) { + switch_thread_rwlock_wrlock(rwlock); + } + + sqlite3HashInsert(&hash->table, key, (int) strlen(key) + 1, NULL); + + if (rwlock) { + switch_thread_rwlock_unlock(rwlock); + } + + return SWITCH_STATUS_SUCCESS; +} + SWITCH_DECLARE(switch_status_t) switch_core_hash_delete_multi(switch_hash_t *hash, switch_hash_delete_callback_t callback, void *pData) { switch_hash_index_t *hi = NULL; @@ -175,6 +205,23 @@ SWITCH_DECLARE(void *) switch_core_hash_find_locked(switch_hash_t *hash, const c return val; } +SWITCH_DECLARE(void *) switch_core_hash_find_rdlock(switch_hash_t *hash, const char *key, switch_thread_rwlock_t *rwlock) +{ + void *val; + + if (rwlock) { + switch_thread_rwlock_rdlock(rwlock); + } + + val = sqlite3HashFind(&hash->table, key, (int) strlen(key) + 1); + + if (rwlock) { + switch_thread_rwlock_unlock(rwlock); + } + + return val; +} + SWITCH_DECLARE(switch_hash_index_t *) switch_hash_first(char *depricate_me, switch_hash_t *hash) { return (switch_hash_index_t *) sqliteHashFirst(&hash->table);