summaryrefslogtreecommitdiff
path: root/pjsip/src/pjsip/sip_util.c
diff options
context:
space:
mode:
authorBenny Prijono <bennylp@teluu.com>2007-06-19 10:35:49 +0000
committerBenny Prijono <bennylp@teluu.com>2007-06-19 10:35:49 +0000
commit568524345dffc7a17c633af1f084509e2713de7f (patch)
treed818b32ce2dd563532d75c243f3dcd26a4715377 /pjsip/src/pjsip/sip_util.c
parentab7724374248c4d5fb3eb62a6a0d4c44e6cd7e5c (diff)
Ticket #338: handle maddr parameter in URI when sending outgoing requests
git-svn-id: http://svn.pjsip.org/repos/pjproject/trunk@1375 74dad513-b988-da41-8d7b-12977e46ad98
Diffstat (limited to 'pjsip/src/pjsip/sip_util.c')
-rw-r--r--pjsip/src/pjsip/sip_util.c103
1 files changed, 47 insertions, 56 deletions
diff --git a/pjsip/src/pjsip/sip_util.c b/pjsip/src/pjsip/sip_util.c
index be9b4827..4aad8c2a 100644
--- a/pjsip/src/pjsip/sip_util.c
+++ b/pjsip/src/pjsip/sip_util.c
@@ -628,33 +628,11 @@ on_missing_hdr:
}
-/*
- * Find which destination to be used to send the request message, based
- * on the request URI and Route headers in the message. The procedure
- * used here follows the guidelines on sending the request in RFC 3261
- * chapter 8.1.2.
- */
-PJ_DEF(pj_status_t) pjsip_get_request_dest(const pjsip_tx_data *tdata,
- pjsip_host_info *dest_info )
+/* Fill-up destination information from a target URI */
+static pj_status_t get_dest_info(const pjsip_uri *target_uri,
+ pj_pool_t *pool,
+ pjsip_host_info *dest_info)
{
- const pjsip_uri *target_uri;
- const pjsip_route_hdr *first_route_hdr;
-
- PJ_ASSERT_RETURN(tdata->msg->type == PJSIP_REQUEST_MSG,
- PJSIP_ENOTREQUESTMSG);
- PJ_ASSERT_RETURN(dest_info != NULL, PJ_EINVAL);
-
- /* Get the first "Route" header from the message.
- */
- first_route_hdr = (const pjsip_route_hdr*)
- pjsip_msg_find_hdr(tdata->msg, PJSIP_H_ROUTE, NULL);
- if (first_route_hdr) {
- target_uri = first_route_hdr->name_addr.uri;
- } else {
- target_uri = tdata->msg->line.req.uri;
- }
-
-
/* The target URI must be a SIP/SIPS URL so we can resolve it's address.
* Otherwise we're in trouble (i.e. there's no host part in tel: URL).
*/
@@ -664,7 +642,10 @@ PJ_DEF(pj_status_t) pjsip_get_request_dest(const pjsip_tx_data *tdata,
pjsip_uri *uri = (pjsip_uri*) target_uri;
const pjsip_sip_uri *url=(const pjsip_sip_uri*)pjsip_uri_get_uri(uri);
dest_info->flag |= (PJSIP_TRANSPORT_SECURE | PJSIP_TRANSPORT_RELIABLE);
- pj_strdup(tdata->pool, &dest_info->addr.host, &url->host);
+ if (url->maddr_param.slen)
+ pj_strdup(pool, &dest_info->addr.host, &url->maddr_param);
+ else
+ pj_strdup(pool, &dest_info->addr.host, &url->host);
dest_info->addr.port = url->port;
dest_info->type =
pjsip_transport_get_type_from_name(&url->transport_param);
@@ -672,7 +653,10 @@ PJ_DEF(pj_status_t) pjsip_get_request_dest(const pjsip_tx_data *tdata,
} else if (PJSIP_URI_SCHEME_IS_SIP(target_uri)) {
pjsip_uri *uri = (pjsip_uri*) target_uri;
const pjsip_sip_uri *url=(const pjsip_sip_uri*)pjsip_uri_get_uri(uri);
- pj_strdup(tdata->pool, &dest_info->addr.host, &url->host);
+ if (url->maddr_param.slen)
+ pj_strdup(pool, &dest_info->addr.host, &url->maddr_param);
+ else
+ pj_strdup(pool, &dest_info->addr.host, &url->host);
dest_info->addr.port = url->port;
dest_info->type =
pjsip_transport_get_type_from_name(&url->transport_param);
@@ -689,6 +673,36 @@ PJ_DEF(pj_status_t) pjsip_get_request_dest(const pjsip_tx_data *tdata,
/*
+ * Find which destination to be used to send the request message, based
+ * on the request URI and Route headers in the message. The procedure
+ * used here follows the guidelines on sending the request in RFC 3261
+ * chapter 8.1.2.
+ */
+PJ_DEF(pj_status_t) pjsip_get_request_dest(const pjsip_tx_data *tdata,
+ pjsip_host_info *dest_info )
+{
+ const pjsip_uri *target_uri;
+ const pjsip_route_hdr *first_route_hdr;
+
+ PJ_ASSERT_RETURN(tdata->msg->type == PJSIP_REQUEST_MSG,
+ PJSIP_ENOTREQUESTMSG);
+ PJ_ASSERT_RETURN(dest_info != NULL, PJ_EINVAL);
+
+ /* Get the first "Route" header from the message.
+ */
+ first_route_hdr = (const pjsip_route_hdr*)
+ pjsip_msg_find_hdr(tdata->msg, PJSIP_H_ROUTE, NULL);
+ if (first_route_hdr) {
+ target_uri = first_route_hdr->name_addr.uri;
+ } else {
+ target_uri = tdata->msg->line.req.uri;
+ }
+
+ return get_dest_info(target_uri, (pj_pool_t*)tdata->pool, dest_info);
+}
+
+
+/*
* Process route-set found in the request and calculate
* the destination to be used to send the request message, based
* on the request URI and Route headers in the message. The procedure
@@ -701,6 +715,7 @@ PJ_DEF(pj_status_t) pjsip_process_route_set(pjsip_tx_data *tdata,
const pjsip_uri *new_request_uri, *target_uri;
const pjsip_name_addr *topmost_route_uri;
pjsip_route_hdr *first_route_hdr, *last_route_hdr;
+ pj_status_t status;
PJ_ASSERT_RETURN(tdata->msg->type == PJSIP_REQUEST_MSG,
PJSIP_ENOTREQUESTMSG);
@@ -771,34 +786,10 @@ PJ_DEF(pj_status_t) pjsip_process_route_set(pjsip_tx_data *tdata,
target_uri = new_request_uri = tdata->msg->line.req.uri;
}
- /* The target URI must be a SIP/SIPS URL so we can resolve it's address.
- * Otherwise we're in trouble (i.e. there's no host part in tel: URL).
- */
- pj_bzero(dest_info, sizeof(*dest_info));
-
- if (PJSIP_URI_SCHEME_IS_SIPS(target_uri)) {
- pjsip_uri *uri = (pjsip_uri*) target_uri;
- const pjsip_sip_uri *url=(const pjsip_sip_uri*)pjsip_uri_get_uri(uri);
- dest_info->flag |= (PJSIP_TRANSPORT_SECURE | PJSIP_TRANSPORT_RELIABLE);
- pj_strdup(tdata->pool, &dest_info->addr.host, &url->host);
- dest_info->addr.port = url->port;
- dest_info->type =
- pjsip_transport_get_type_from_name(&url->transport_param);
-
- } else if (PJSIP_URI_SCHEME_IS_SIP(target_uri)) {
- pjsip_uri *uri = (pjsip_uri*) target_uri;
- const pjsip_sip_uri *url=(const pjsip_sip_uri*)pjsip_uri_get_uri(uri);
- pj_strdup(tdata->pool, &dest_info->addr.host, &url->host);
- dest_info->addr.port = url->port;
- dest_info->type =
- pjsip_transport_get_type_from_name(&url->transport_param);
- dest_info->flag =
- pjsip_transport_get_flag_from_type(dest_info->type);
- } else {
- pj_assert(!"Unsupported URI scheme!");
- PJ_TODO(SUPPORT_REQUEST_ADDR_RESOLUTION_FOR_TEL_URI);
- return PJSIP_EINVALIDSCHEME;
- }
+ /* Fill up the destination host/port from the URI. */
+ status = get_dest_info(target_uri, tdata->pool, dest_info);
+ if (status != PJ_SUCCESS)
+ return status;
/* If target URI is different than request URI, replace
* request URI add put the original URI in the last Route header.