From 93f96addc3e2ac889927ba4d0cae7126242e0e02 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Thu, 26 Jul 2012 12:32:51 -0500 Subject: [PATCH] FS-4453 confirm this fixes your problem please --- src/mod/endpoints/mod_sofia/sofia.c | 1 + src/mod/endpoints/mod_sofia/sofia_presence.c | 48 ++++++++++++-------- src/switch_loadable_module.c | 3 ++ 3 files changed, 32 insertions(+), 20 deletions(-) diff --git a/src/mod/endpoints/mod_sofia/sofia.c b/src/mod/endpoints/mod_sofia/sofia.c index 11a5c8d0fc..628bd81d1f 100644 --- a/src/mod/endpoints/mod_sofia/sofia.c +++ b/src/mod/endpoints/mod_sofia/sofia.c @@ -755,6 +755,7 @@ void sofia_handle_sip_r_message(int status, sofia_profile_t *profile, nua_handle call_id = sip->sip_call_id->i_id; + switch_mutex_lock(profile->flag_mutex); mstatus = switch_core_hash_find(profile->chat_hash, call_id); switch_mutex_unlock(profile->flag_mutex); diff --git a/src/mod/endpoints/mod_sofia/sofia_presence.c b/src/mod/endpoints/mod_sofia/sofia_presence.c index 594cb4c61e..f147d6d471 100644 --- a/src/mod/endpoints/mod_sofia/sofia_presence.c +++ b/src/mod/endpoints/mod_sofia/sofia_presence.c @@ -130,8 +130,9 @@ switch_status_t sofia_presence_chat_send(switch_event_t *message_event) char *extra_headers = NULL; char uuid_str[SWITCH_UUID_FORMATTED_LENGTH + 1]; int mstatus = 0, sanity = 0; + const char *blocking; + int is_blocking = 0; - proto = switch_event_get_header(message_event, "proto"); from_proto = switch_event_get_header(message_event, "from_proto"); from = switch_event_get_header(message_event, "from"); @@ -140,7 +141,9 @@ switch_status_t sofia_presence_chat_send(switch_event_t *message_event) body = switch_event_get_body(message_event); type = switch_event_get_header(message_event, "type"); from_full = switch_event_get_header(message_event, "from_full"); - + blocking = switch_event_get_header(message_event, "blocking"); + is_blocking = switch_true(blocking); + network_ip = switch_event_get_header(message_event, "to_sip_ip"); network_port = switch_event_get_header(message_event, "to_sip_port"); @@ -328,11 +331,13 @@ switch_status_t sofia_presence_chat_send(switch_event_t *message_event) switch_snprintf(header, sizeof(header), "X-FS-Sending-Message: %s", switch_core_get_uuid()); switch_uuid_str(uuid_str, sizeof(uuid_str)); - - switch_mutex_lock(profile->flag_mutex); - switch_core_hash_insert(profile->chat_hash, uuid_str, &mstatus); - switch_mutex_unlock(profile->flag_mutex); - + + if (is_blocking) { + switch_mutex_lock(profile->flag_mutex); + switch_core_hash_insert(profile->chat_hash, uuid_str, &mstatus); + switch_mutex_unlock(profile->flag_mutex); + } + nua_message(msg_nh, TAG_IF(dst->route_uri, NUTAG_PROXY(dst->route_uri)), TAG_IF(route_uri, NUTAG_PROXY(route_uri)), @@ -347,20 +352,23 @@ switch_status_t sofia_presence_chat_send(switch_event_t *message_event) SIPTAG_HEADER_STR(header), TAG_IF(!zstr(extra_headers), SIPTAG_HEADER_STR(extra_headers)), TAG_END()); - - - sanity = 200; - while(!mstatus && --sanity) { - switch_yield(100000); - } - - if (!(mstatus > 199 && mstatus < 300)) { - status = SWITCH_STATUS_FALSE; - } - switch_mutex_lock(profile->flag_mutex); - switch_core_hash_delete(profile->chat_hash, uuid_str); - switch_mutex_unlock(profile->flag_mutex); + + if (is_blocking) { + sanity = 200; + + while(!mstatus && --sanity) { + switch_yield(100000); + } + + if (!(mstatus > 199 && mstatus < 300)) { + status = SWITCH_STATUS_FALSE; + } + + switch_mutex_lock(profile->flag_mutex); + switch_core_hash_delete(profile->chat_hash, uuid_str); + switch_mutex_unlock(profile->flag_mutex); + } sofia_glue_free_destination(dst); switch_safe_free(dup_dest); diff --git a/src/switch_loadable_module.c b/src/switch_loadable_module.c index 045733dfa5..15c4739775 100644 --- a/src/switch_loadable_module.c +++ b/src/switch_loadable_module.c @@ -758,6 +758,9 @@ SWITCH_DECLARE(switch_status_t) switch_core_chat_send_args(const char *dest_prot switch_event_add_header_string(message_event, SWITCH_STACK_BOTTOM, "type", type); switch_event_add_header_string(message_event, SWITCH_STACK_BOTTOM, "hint", hint); switch_event_add_header_string(message_event, SWITCH_STACK_BOTTOM, "skip_global_process", "true"); + if (blocking) { + switch_event_add_header_string(message_event, SWITCH_STACK_BOTTOM, "blocking", "true"); + } if (body) { switch_event_add_body(message_event, "%s", body);