summaryrefslogtreecommitdiff
path: root/pjsip/src/pjsip/sip_util.c
diff options
context:
space:
mode:
authorBenny Prijono <bennylp@teluu.com>2008-02-22 08:36:06 +0000
committerBenny Prijono <bennylp@teluu.com>2008-02-22 08:36:06 +0000
commit604b84d7eac9b00fd43dd52a35a23359f106277c (patch)
treeef783c2b47e7f22ece491baa31a701e3dbda2c1d /pjsip/src/pjsip/sip_util.c
parent2fe9c49e7d023c2efcc69ff835c49a3c3d8662e5 (diff)
Ticket #492: Bug in strict route processing when challenged with 401/407 response
git-svn-id: http://svn.pjsip.org/repos/pjproject/trunk@1816 74dad513-b988-da41-8d7b-12977e46ad98
Diffstat (limited to 'pjsip/src/pjsip/sip_util.c')
-rw-r--r--pjsip/src/pjsip/sip_util.c61
1 files changed, 60 insertions, 1 deletions
diff --git a/pjsip/src/pjsip/sip_util.c b/pjsip/src/pjsip/sip_util.c
index c48ff865..988547aa 100644
--- a/pjsip/src/pjsip/sip_util.c
+++ b/pjsip/src/pjsip/sip_util.c
@@ -720,6 +720,14 @@ PJ_DEF(pj_status_t) pjsip_process_route_set(pjsip_tx_data *tdata,
PJSIP_ENOTREQUESTMSG);
PJ_ASSERT_RETURN(dest_info != NULL, PJ_EINVAL);
+ /* Assert if the request contains strict route and strict
+ * route processing has been applied before. We need to
+ * restore the strict route with pjsip_restore_strict_route_set()
+ * before we can call this function again, otherwise strict
+ * route will be swapped twice!
+ */
+ PJ_ASSERT_RETURN(tdata->saved_strict_route==NULL, PJ_EBUG);
+
/* Find the first and last "Route" headers from the message. */
last_route_hdr = first_route_hdr = (pjsip_route_hdr*)
pjsip_msg_find_hdr(tdata->msg, PJSIP_H_ROUTE, NULL);
@@ -775,8 +783,9 @@ PJ_DEF(pj_status_t) pjsip_process_route_set(pjsip_tx_data *tdata,
new_request_uri = (const pjsip_uri*)
pjsip_uri_get_uri((pjsip_uri*)topmost_route_uri);
pj_list_erase(first_route_hdr);
+ tdata->saved_strict_route = first_route_hdr;
if (first_route_hdr == last_route_hdr)
- last_route_hdr = NULL;
+ first_route_hdr = last_route_hdr = NULL;
}
target_uri = (pjsip_uri*)topmost_route_uri;
@@ -809,6 +818,56 @@ PJ_DEF(pj_status_t) pjsip_process_route_set(pjsip_tx_data *tdata,
}
+/*
+ * Swap the request URI and strict route back to the original position
+ * before #pjsip_process_route_set() function is called. This function
+ * should only used internally by PJSIP client authentication module.
+ */
+PJ_DEF(void) pjsip_restore_strict_route_set(pjsip_tx_data *tdata)
+{
+ pjsip_route_hdr *first_route_hdr, *last_route_hdr;
+
+ /* Check if we have found strict route before */
+ if (tdata->saved_strict_route == NULL) {
+ /* This request doesn't contain strict route */
+ return;
+ }
+
+ /* Find the first "Route" headers from the message. */
+ first_route_hdr = (pjsip_route_hdr*)
+ pjsip_msg_find_hdr(tdata->msg, PJSIP_H_ROUTE, NULL);
+
+ if (first_route_hdr == NULL) {
+ /* User has modified message route? We don't expect this! */
+ pj_assert(!"Message route was modified?");
+ tdata->saved_strict_route = NULL;
+ return;
+ }
+
+ /* Find last Route header */
+ last_route_hdr = first_route_hdr;
+ while (last_route_hdr->next != (void*)&tdata->msg->hdr) {
+ pjsip_route_hdr *hdr;
+ hdr = (pjsip_route_hdr*)
+ pjsip_msg_find_hdr(tdata->msg, PJSIP_H_ROUTE,
+ last_route_hdr->next);
+ if (!hdr)
+ break;
+ last_route_hdr = hdr;
+ }
+
+ /* Put the last Route header as request URI, delete last Route
+ * header, and insert the saved strict route as the first Route.
+ */
+ tdata->msg->line.req.uri = last_route_hdr->name_addr.uri;
+ pj_list_insert_before(first_route_hdr, tdata->saved_strict_route);
+ pj_list_erase(last_route_hdr);
+
+ /* Reset */
+ tdata->saved_strict_route = NULL;
+}
+
+
/* Transport callback for sending stateless request.
* This is one of the most bizzare function in pjsip, so
* good luck if you happen to debug this function!!