From c61033c80590866d079d394df6b72dc2eb2331cd Mon Sep 17 00:00:00 2001 From: Thomas Ries Date: Thu, 27 May 2004 20:17:02 +0000 Subject: [PATCH] - Route header processing (RFC3261, 16.6, step 6) --- ChangeLog | 2 +- src/proxy.c | 56 +++++++++++++++++++++++++++++++++++++++++------------ 2 files changed, 45 insertions(+), 13 deletions(-) diff --git a/ChangeLog b/ChangeLog index 6379ffe..b5aa01c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,6 +1,6 @@ 0.5.7 ===== - 27-May-2004: - use a present Route header to determine next-hop + 27-May-2004: - Route header processing (RFC3261, 16.6, step 6) 25-May-2004: - sip_utils.c:sip_del_myvia check for NULL list 24-May-2004: - included doc/sample_* to package 23-May-2004: - doc/: added configuration example for X-Lite diff --git a/src/proxy.c b/src/proxy.c index 3400561..25602da 100644 --- a/src/proxy.c +++ b/src/proxy.c @@ -104,6 +104,8 @@ int proxy_request (osip_message_t *request, struct sockaddr_in *from) { this modified request. NOT IMPLEMENTED*/ + + /* * Check if I am listed at the topmost Route header (if any Route * header is existing at all). If so, remove it from the list and @@ -131,18 +133,6 @@ int proxy_request (osip_message_t *request, struct sockaddr_in *from) { /* request->routes will be freed by osip_message_free() */ DEBUGC(DBCLASS_PROXY, "removed Route header pointing to myself"); } - - /* rewrite request URI to now topmost Route header */ - url=osip_message_get_uri(request); - route = (osip_route_t *) osip_list_get(request->routes, 0); - if (route && route->url && route->url->host) { - DEBUGC(DBCLASS_PROXY, "rewriting request URI from %s to %s", - url->host, route->url->host); - osip_uri_free(url); - url=NULL; - osip_uri_clone(route->url, &url); - } - } @@ -510,7 +500,49 @@ int proxy_request (osip_message_t *request, struct sockaddr_in *from) { /* * RFC 3261, Section 16.6 step 6 * Proxy Behavior - Request Forwarding - Postprocess routing information + * + * If the copy contains a Route header field, the proxy MUST + * inspect the URI in its first value. If that URI does not + * contain an lr parameter, the proxy MUST modify the copy as + * follows: + * + * - The proxy MUST place the Request-URI into the Route header + * field as the last value. + * + * - The proxy MUST then place the first Route header field value + * into the Request-URI and remove that value from the Route + * header field. */ + if (request->routes && !osip_list_eol(request->routes, 0)) { + osip_route_t *route=NULL; + osip_uri_param_t *param=NULL; + + route = (osip_route_t *) osip_list_get(request->routes, 0); + if (route->url) { + /* check for non existing lr parameter */ + if (osip_uri_uparam_get_byname(route->url, "lr", ¶m) != 0) { + osip_route_t *new_route=NULL; + url=osip_message_get_uri(request); + + /* push Request URI into Route header list at the last position */ + osip_route_init(&new_route); + osip_uri_clone(url, &new_route->url); + osip_list_add(request->routes, new_route, -1); + + + /* rewrite request URI to now topmost Route header */ + DEBUGC(DBCLASS_PROXY, "Route header w/o 'lr': rewriting request " + "URI from %s to %s", url->host, route->url->host); + osip_uri_free(url); + url=NULL; + osip_uri_clone(route->url, &url); + /* remove first Route header from list & free */ + osip_list_remove(request->routes, 0); + osip_route_free(route); + route = NULL; + } + } + } /* * RFC 3261, Section 16.6 step 7