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

This commit is contained in:
Mike Jerris 2016-11-30 15:31:55 -07:00
parent a39b862e1d
commit b338bb559b
1 changed files with 33 additions and 41 deletions

View File

@ -216,20 +216,18 @@ 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;
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);
SWITCH_STANDARD_STREAM(forward_stream);
SWITCH_STANDARD_STREAM(reverse_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);
forward_stream.write_function(&forward_stream, x == 0 ? "%s" : ",%s", rr);
tmp[y++] = rr;
if (y == 127) break;
x++;
@ -240,28 +238,22 @@ static void extract_header_vars(sofia_profile_t *profile, sip_t const *sip,
x = 0;
while(y >= 0) {
route_stream.write_function(&route_stream, x == 0 ? "%s" : ",%s", tmp[y]);
reverse_stream.write_function(&reverse_stream, x == 0 ? "%s" : ",%s", tmp[y]);
su_free(nh->nh_home, tmp[y]);
y--;
x++;
}
switch_channel_set_variable(channel, "sip_invite_route_uri", (char *)route_stream.data);
free(route_stream.data);
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) {