From 7c85dd54651a9044a3a9d0fbfea205a467b8425f Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Sat, 22 Nov 2008 01:50:21 +0000 Subject: [PATCH] add patch from MODENDP-152 git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@10514 d0543943-73ff-0310-b7d9-9358b9ac24b2 --- src/mod/endpoints/mod_sofia/mod_sofia.h | 1 + src/mod/endpoints/mod_sofia/sofia.c | 46 ++++++++++++++++++++++++- 2 files changed, 46 insertions(+), 1 deletion(-) diff --git a/src/mod/endpoints/mod_sofia/mod_sofia.h b/src/mod/endpoints/mod_sofia/mod_sofia.h index 4a58c7788e..838a0ee65c 100644 --- a/src/mod/endpoints/mod_sofia/mod_sofia.h +++ b/src/mod/endpoints/mod_sofia/mod_sofia.h @@ -75,6 +75,7 @@ typedef struct private_object private_object_t; #define MY_EVENT_UNREGISTER "sofia::unregister" #define MY_EVENT_EXPIRE "sofia::expire" #define MY_EVENT_GATEWAY_STATE "sofia::gateway_state" +#define MY_EVENT_NOTIFY_REFER "sofia::notify_refer" #define MULTICAST_EVENT "multicast::event" #define SOFIA_REPLACES_HEADER "_sofia_replaces_" diff --git a/src/mod/endpoints/mod_sofia/sofia.c b/src/mod/endpoints/mod_sofia/sofia.c index 7f986bbaff..9d5edbdf7f 100644 --- a/src/mod/endpoints/mod_sofia/sofia.c +++ b/src/mod/endpoints/mod_sofia/sofia.c @@ -84,6 +84,7 @@ void sofia_handle_sip_i_notify(switch_core_session_t *session, int status, { switch_channel_t *channel = NULL; private_object_t *tech_pvt = NULL; + switch_event_t *s_event = NULL; /* make sure we have a proper event */ if (!sip || !sip->sip_event) { @@ -95,7 +96,7 @@ void sofia_handle_sip_i_notify(switch_core_session_t *session, int status, nua_respond(nh, SIP_200_OK, NUTAG_WITH_THIS(nua), TAG_END()); return; } - + if (session) { channel = switch_core_session_get_channel(session); switch_assert(channel != NULL); @@ -103,6 +104,49 @@ void sofia_handle_sip_i_notify(switch_core_session_t *session, int status, switch_assert(tech_pvt != NULL); } + /* For additional NOTIFY event packages see http://www.iana.org/assignments/sip-events. */ + if (!strcasecmp(sip->sip_event->o_type, "refer")) { + if (switch_event_create_subclass(&s_event, SWITCH_EVENT_CUSTOM, MY_EVENT_NOTIFY_REFER) == SWITCH_STATUS_SUCCESS) { + switch_event_add_header_string(s_event, SWITCH_STACK_BOTTOM, "content-type", sip->sip_content_type->c_type); + switch_event_add_body(s_event, "%s", sip->sip_payload->pl_data); + } + } + + /* add common headers for the NOTIFY to the switch_event and fire if it exists */ + if (s_event != NULL) { + switch_event_add_header_string(s_event, SWITCH_STACK_BOTTOM, "event-package", sip->sip_event->o_type); + switch_event_add_header_string(s_event, SWITCH_STACK_BOTTOM, "event-id", sip->sip_event->o_id); + + switch_event_add_header(s_event, SWITCH_STACK_BOTTOM, "contact", "%s@%s", + sip->sip_contact->m_url->url_user, sip->sip_contact->m_url->url_host); + switch_event_add_header(s_event, SWITCH_STACK_BOTTOM, "from", "%s@%s", + sip->sip_from->a_url->url_user, sip->sip_from->a_url->url_host); + switch_event_add_header_string(s_event, SWITCH_STACK_BOTTOM, "from-tag", sip->sip_from->a_tag); + switch_event_add_header(s_event, SWITCH_STACK_BOTTOM, "to", "%s@%s", + sip->sip_to->a_url->url_user, sip->sip_to->a_url->url_host); + switch_event_add_header_string(s_event, SWITCH_STACK_BOTTOM, "to-tag", sip->sip_to->a_tag); + + if (sip->sip_call_id && sip->sip_call_id->i_id) { + switch_event_add_header_string(s_event, SWITCH_STACK_BOTTOM, "call-id", sip->sip_call_id->i_id); + } + if (sip->sip_subscription_state && sip->sip_subscription_state->ss_substate) { + switch_event_add_header_string(s_event, SWITCH_STACK_BOTTOM, "subscription-substate", sip->sip_subscription_state->ss_substate); + } + if (sip->sip_subscription_state && sip->sip_subscription_state->ss_reason) { + switch_event_add_header_string(s_event, SWITCH_STACK_BOTTOM, "subscription-reason", sip->sip_subscription_state->ss_reason); + } + if (sip->sip_subscription_state && sip->sip_subscription_state->ss_retry_after) { + switch_event_add_header_string(s_event, SWITCH_STACK_BOTTOM, "subscription-retry-after", sip->sip_subscription_state->ss_retry_after); + } + if (sip->sip_subscription_state && sip->sip_subscription_state->ss_expires) { + switch_event_add_header_string(s_event, SWITCH_STACK_BOTTOM, "subscription-expires", sip->sip_subscription_state->ss_expires); + } + if (session) { + switch_event_add_header_string(s_event, SWITCH_STACK_BOTTOM, "UniqueID", switch_core_session_get_uuid(session)); + } + switch_event_fire(&s_event); + } + if (!strcasecmp(sip->sip_event->o_type, "refer")) { if (session && channel && tech_pvt) { if (sip->sip_payload && sip->sip_payload->pl_data) {