From: Mike Jerris Date: Wed, 30 Nov 2016 22:31:55 +0000 (-0700) Subject: FS-9782: [mod_sofia] on recovery, flip the order of the record route on inbound calls... X-Git-Tag: v1.8.0~1023 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b338bb559b19194ccb1160d52c3ec7254b002dc4;p=thirdparty%2Ffreeswitch.git FS-9782: [mod_sofia] on recovery, flip the order of the record route on inbound calls only, use the record route in the same order on inbound calls and in reverse order on outbound calls as the initial route set when doing the recover invite. Account for the call direction based on how sip considers it, not based on freeswitch direction so inbound calls after recovery are treated as outbound in this logic --- diff --git a/src/mod/endpoints/mod_sofia/sofia.c b/src/mod/endpoints/mod_sofia/sofia.c index 1a1cd2a0f7..e5243e6781 100644 --- a/src/mod/endpoints/mod_sofia/sofia.c +++ b/src/mod/endpoints/mod_sofia/sofia.c @@ -216,52 +216,44 @@ static void extract_header_vars(sofia_profile_t *profile, sip_t const *sip, if (sip->sip_record_route) { sip_record_route_t *rrp; - switch_stream_handle_t stream = { 0 }; + switch_stream_handle_t forward_stream = { 0 }; + switch_stream_handle_t reverse_stream = { 0 }; int x = 0; + char *tmp[128] = { 0 }; + int y = 0; - SWITCH_STANDARD_STREAM(stream); - - if (switch_channel_direction(channel) == SWITCH_CALL_DIRECTION_OUTBOUND) { - char *tmp[128] = { 0 }; - int y = 0; - switch_stream_handle_t route_stream = { 0 }; - SWITCH_STANDARD_STREAM(route_stream); - - for(rrp = sip->sip_record_route; rrp; rrp = rrp->r_next) { - char *rr = sip_header_as_string(nh->nh_home, (void *) rrp); - stream.write_function(&stream, x == 0 ? "%s" : ",%s", rr); - tmp[y++] = rr; - if (y == 127) break; - x++; - } + SWITCH_STANDARD_STREAM(forward_stream); + SWITCH_STANDARD_STREAM(reverse_stream); - y--; + for(rrp = sip->sip_record_route; rrp; rrp = rrp->r_next) { + char *rr = sip_header_as_string(nh->nh_home, (void *) rrp); + forward_stream.write_function(&forward_stream, x == 0 ? "%s" : ",%s", rr); + tmp[y++] = rr; + if (y == 127) break; + x++; + } - x = 0; + y--; - while(y >= 0) { - route_stream.write_function(&route_stream, x == 0 ? "%s" : ",%s", tmp[y]); - su_free(nh->nh_home, tmp[y]); - y--; - x++; - } + x = 0; - switch_channel_set_variable(channel, "sip_invite_route_uri", (char *)route_stream.data); - free(route_stream.data); + while(y >= 0) { + reverse_stream.write_function(&reverse_stream, x == 0 ? "%s" : ",%s", tmp[y]); + su_free(nh->nh_home, tmp[y]); + y--; + x++; + } + if (switch_channel_direction(channel) == SWITCH_CALL_DIRECTION_OUTBOUND || switch_channel_test_flag(channel, CF_RECOVERED)) { + switch_channel_set_variable(channel, "sip_invite_route_uri", (char *)reverse_stream.data); + switch_channel_set_variable(channel, "sip_invite_record_route", (char *)forward_stream.data); } else { - for(rrp = sip->sip_record_route; rrp; rrp = rrp->r_next) { - char *rr = sip_header_as_string(nh->nh_home, (void *) rrp); - - stream.write_function(&stream, x == 0 ? "%s" : ",%s", rr); - su_free(nh->nh_home, rr); - - x++; - } + switch_channel_set_variable(channel, "sip_invite_route_uri", (char *)forward_stream.data); + switch_channel_set_variable(channel, "sip_invite_record_route", (char *)reverse_stream.data); } - switch_channel_set_variable(channel, "sip_invite_record_route", (char *)stream.data); - free(stream.data); + free(reverse_stream.data); + free(forward_stream.data); } if (sip->sip_via) {