Created
May 10, 2018 20:43
-
-
Save ar45/89d725ddddbdd626147db486fa2bab7a to your computer and use it in GitHub Desktop.
FS Multiple record route patch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
commit ffb37bc73c801bbdb2f29829b45a3ecee9d1ba9d | |
Author: Aron Podrigal <aron@mongotel.com> | |
Date: Thu May 10 16:02:35 2018 +0000 | |
Record route multiple | |
Do not strip `<>` | |
diff --git a/src/mod/endpoints/mod_sofia/sofia_glue.c b/src/mod/endpoints/mod_sofia/sofia_glue.c | |
index 9d4b5f9..3270fb7 100644 | |
--- a/src/mod/endpoints/mod_sofia/sofia_glue.c | |
+++ b/src/mod/endpoints/mod_sofia/sofia_glue.c | |
@@ -2952,18 +2952,62 @@ char *sofia_glue_gen_contact_str(sofia_profile_t *profile, sip_t const *sip, nua | |
} | |
if (sip->sip_record_route) { | |
+#define ROUTE_MAX_HEADERS 10 | |
+ char *route; | |
+ int count = 0; | |
+ char *routes[ROUTE_MAX_HEADERS] = {0}; | |
+ //int routes_len[ROUTE_MAX_HEADERS] = {0}; | |
+ int buf_len_required = 1; | |
+ int buf_len_avail; | |
+ char *route_encoded_buf = NULL; | |
+ char *buf_p = NULL; | |
char *full_contact = sip_header_as_string(nh->nh_home, (void *) contact); | |
- char *route = sofia_glue_strip_uri(sip_header_as_string(nh->nh_home, (void *) sip->sip_record_route)); | |
- char *full_contact_dup; | |
- char *route_encoded; | |
- int route_encoded_len; | |
- full_contact_dup = sofia_glue_get_url_from_contact(full_contact, 1); | |
- route_encoded_len = (int)(strlen(route) * 3) + 1; | |
- switch_zmalloc(route_encoded, route_encoded_len); | |
- switch_url_encode(route, route_encoded, route_encoded_len); | |
- contact_str = switch_mprintf("%s <%s;fs_path=%s>", display, full_contact_dup, route_encoded); | |
- free(full_contact_dup); | |
- free(route_encoded); | |
+ char *full_contact_dup = sofia_glue_get_url_from_contact(full_contact, 1); | |
+ | |
+ for (sip_route_t *rr = sip->sip_record_route; rr; rr = rr->r_next) { | |
+ int route_len; | |
+ int route_encoded_len; | |
+ | |
+ if (count >= ROUTE_MAX_HEADERS) { | |
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Message exceeds ROUTE_MAX_HEADERS of %d\n", ROUTE_MAX_HEADERS); | |
+ break; | |
+ } | |
+ | |
+ route = sip_header_as_string(nh->nh_home, (void *) rr); | |
+ route_len = (int)strlen(route); | |
+ route_encoded_len = (route_len * 3) + (count ? 3 : 0); | |
+ routes[count] = route; | |
+ //routes_len[count] = route_encoded_len; | |
+ buf_len_required += route_encoded_len; | |
+ count++; | |
+ } | |
+ | |
+ switch_zmalloc(route_encoded_buf, buf_len_required); | |
+ buf_p = route_encoded_buf; | |
+ buf_len_avail = buf_len_required; | |
+ | |
+ for (int i = 0; i < count; i++) { | |
+ int actual_encoded_len; | |
+ route = routes[i]; | |
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Adding Route: #%d: [%s]\n", i, route); | |
+ if (i) { | |
+ switch_copy_string(buf_p, "%2C", buf_len_avail); | |
+ buf_p += 3; | |
+ buf_len_avail -= 3; | |
+ } | |
+ | |
+ switch_url_encode(route, buf_p, buf_len_avail); | |
+ actual_encoded_len = strlen(buf_p); | |
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Route encoded: #%d encoded len=%d: [%s]\n", i, actual_encoded_len, buf_p); | |
+ buf_p += actual_encoded_len; | |
+ buf_len_avail -= actual_encoded_len; | |
+ } | |
+ | |
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Final route: count %d: [%s]\n", count, route_encoded_buf); | |
+ contact_str = switch_mprintf("%s <%s;fs_path=%s>", display, full_contact_dup, route_encoded_buf); | |
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Route: [%s] with count of %d\n", contact_str, count); | |
+ free(route_encoded_buf); | |
+ switch_safe_free(full_contact_dup); | |
} | |
else if (np->is_nat && np->fs_path) { | |
char *full_contact = sip_header_as_string(nh->nh_home, (void *) contact); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment