diff --git a/src/mod/endpoints/mod_sofia/sofia.c b/src/mod/endpoints/mod_sofia/sofia.c index a32cf56ab1..c5e2dfaa21 100644 --- a/src/mod/endpoints/mod_sofia/sofia.c +++ b/src/mod/endpoints/mod_sofia/sofia.c @@ -9673,6 +9673,8 @@ void sofia_handle_sip_i_invite(switch_core_session_t *session, nua_t *nua, sofia tech_pvt->x_freeswitch_support_remote = switch_core_session_strdup(session, un->un_value); } else if (!strcasecmp(un->un_name, "Geolocation")) { switch_channel_set_variable(channel, "sip_geolocation", un->un_value); + } else if (!strcasecmp(un->un_name, "Geolocation-Error")) { + switch_channel_set_variable(channel, "sip_geolocation_error", un->un_value); } else if (!strncasecmp(un->un_name, "X-", 2) || !strncasecmp(un->un_name, "P-", 2) || !strcasecmp(un->un_name, "User-to-User")) { if (!zstr(un->un_value)) { char new_name[512] = ""; diff --git a/src/mod/endpoints/mod_sofia/sofia_presence.c b/src/mod/endpoints/mod_sofia/sofia_presence.c index 50ee7d36c0..e8e4b5b825 100644 --- a/src/mod/endpoints/mod_sofia/sofia_presence.c +++ b/src/mod/endpoints/mod_sofia/sofia_presence.c @@ -4807,6 +4807,8 @@ void sofia_presence_handle_sip_i_message(int status, char *p; char *full_from; char proto[512] = SOFIA_CHAT_PROTO; + sip_unknown_t *un; + int first_history_info = 1; full_from = sip_header_as_string(nh->nh_home, (void *) sip->sip_from); @@ -4852,10 +4854,76 @@ void sofia_presence_handle_sip_i_message(int status, } else { switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "type", "text/plain"); } - + switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "from_full", full_from); switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "sip_profile", profile->name); + + if (sip->sip_call_info) { + sip_call_info_t *call_info = sip->sip_call_info; + char *ci = sip_header_as_string(nua_handle_home(nh), (void *) call_info); + switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "sip_call_info", ci); + } + + /* Loop thru unknown Headers Here so we can do something with them */ + for (un = sip->sip_unknown; un; un = un->un_next) { + if (!strncasecmp(un->un_name, "Diversion", 9)) { + /* Basic Diversion Support for Diversion Indication in SIP */ + /* draft-levy-sip-diversion-08 */ + if (!zstr(un->un_value)) { + char *tmp_name; + if ((tmp_name = switch_mprintf("%s%s", SOFIA_SIP_HEADER_PREFIX, un->un_name))) { + switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, tmp_name, un->un_value); + free(tmp_name); + } + } + } else if (!strncasecmp(un->un_name, "History-Info", 12)) { + if (first_history_info) { + /* If the header exists first time, make sure to remove old info and re-set the variable */ + switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "sip_history_info", un->un_value); + first_history_info = 0; + } else { + /* Append the History-Info into one long string */ + const char *history_var = switch_channel_get_variable(channel, "sip_history_info"); + if (!zstr(history_var)) { + char *tmp_str; + if ((tmp_str = switch_mprintf("%s, %s", history_var, un->un_value))) { + switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "sip_history_info", tmp_str); + free(tmp_str); + } else { + switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "sip_history_info", un->un_value); + } + } else { + switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "sip_history_info", un->un_value); + } + } + } else if (!strcasecmp(un->un_name, "Geolocation")) { + switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "sip_geolocation", un->un_value); + } else if (!strcasecmp(un->un_name, "Geolocation-Error")) { + switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "sip_geolocation_error", un->un_value); + } else if (!strncasecmp(un->un_name, "X-", 2) || !strncasecmp(un->un_name, "P-", 2) || !strcasecmp(un->un_name, "User-to-User")) { + if (!zstr(un->un_value)) { + char new_name[512] = ""; + int reps = 0; + for (;;) { + char postfix[25] = ""; + if (reps > 0) { + switch_snprintf(postfix, sizeof(postfix), "-%d", reps); + } + reps++; + switch_snprintf(new_name, sizeof(new_name), "%s%s%s", SOFIA_SIP_HEADER_PREFIX, un->un_name, postfix); + + if (switch_channel_get_variable(channel, new_name)) { + continue; + } + + switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, new_name, un->un_value); + break; + } + } + } + } + if (msg) { switch_event_add_body(event, "%s", msg); }