Ignore:
Timestamp:
Jun 19, 2007 10:35:49 AM (17 years ago)
Author:
bennylp
Message:

Ticket #338: handle maddr parameter in URI when sending outgoing requests

File:
1 edited

Legend:

Unmodified
Added
Removed
  • pjproject/trunk/pjsip/src/pjsip/sip_util.c

    r1317 r1375  
    629629 
    630630 
    631 /* 
    632  * Find which destination to be used to send the request message, based 
    633  * on the request URI and Route headers in the message. The procedure 
    634  * used here follows the guidelines on sending the request in RFC 3261 
    635  * chapter 8.1.2. 
    636  */ 
    637 PJ_DEF(pj_status_t) pjsip_get_request_dest(const pjsip_tx_data *tdata, 
    638                                            pjsip_host_info *dest_info ) 
    639 { 
    640     const pjsip_uri *target_uri; 
    641     const pjsip_route_hdr *first_route_hdr; 
    642      
    643     PJ_ASSERT_RETURN(tdata->msg->type == PJSIP_REQUEST_MSG,  
    644                      PJSIP_ENOTREQUESTMSG); 
    645     PJ_ASSERT_RETURN(dest_info != NULL, PJ_EINVAL); 
    646  
    647     /* Get the first "Route" header from the message. 
    648      */ 
    649     first_route_hdr = (const pjsip_route_hdr*)  
    650                       pjsip_msg_find_hdr(tdata->msg, PJSIP_H_ROUTE, NULL); 
    651     if (first_route_hdr) { 
    652         target_uri = first_route_hdr->name_addr.uri; 
    653     } else { 
    654         target_uri = tdata->msg->line.req.uri; 
    655     } 
    656  
    657  
     631/* Fill-up destination information from a target URI */ 
     632static pj_status_t get_dest_info(const pjsip_uri *target_uri,  
     633                                 pj_pool_t *pool, 
     634                                 pjsip_host_info *dest_info) 
     635{ 
    658636    /* The target URI must be a SIP/SIPS URL so we can resolve it's address. 
    659637     * Otherwise we're in trouble (i.e. there's no host part in tel: URL). 
     
    665643        const pjsip_sip_uri *url=(const pjsip_sip_uri*)pjsip_uri_get_uri(uri); 
    666644        dest_info->flag |= (PJSIP_TRANSPORT_SECURE | PJSIP_TRANSPORT_RELIABLE); 
    667         pj_strdup(tdata->pool, &dest_info->addr.host, &url->host); 
     645        if (url->maddr_param.slen) 
     646            pj_strdup(pool, &dest_info->addr.host, &url->maddr_param); 
     647        else 
     648            pj_strdup(pool, &dest_info->addr.host, &url->host); 
    668649        dest_info->addr.port = url->port; 
    669650        dest_info->type =  
     
    673654        pjsip_uri *uri = (pjsip_uri*) target_uri; 
    674655        const pjsip_sip_uri *url=(const pjsip_sip_uri*)pjsip_uri_get_uri(uri); 
    675         pj_strdup(tdata->pool, &dest_info->addr.host, &url->host); 
     656        if (url->maddr_param.slen) 
     657            pj_strdup(pool, &dest_info->addr.host, &url->maddr_param); 
     658        else 
     659            pj_strdup(pool, &dest_info->addr.host, &url->host); 
    676660        dest_info->addr.port = url->port; 
    677661        dest_info->type =  
     
    690674 
    691675/* 
     676 * Find which destination to be used to send the request message, based 
     677 * on the request URI and Route headers in the message. The procedure 
     678 * used here follows the guidelines on sending the request in RFC 3261 
     679 * chapter 8.1.2. 
     680 */ 
     681PJ_DEF(pj_status_t) pjsip_get_request_dest(const pjsip_tx_data *tdata, 
     682                                           pjsip_host_info *dest_info ) 
     683{ 
     684    const pjsip_uri *target_uri; 
     685    const pjsip_route_hdr *first_route_hdr; 
     686     
     687    PJ_ASSERT_RETURN(tdata->msg->type == PJSIP_REQUEST_MSG,  
     688                     PJSIP_ENOTREQUESTMSG); 
     689    PJ_ASSERT_RETURN(dest_info != NULL, PJ_EINVAL); 
     690 
     691    /* Get the first "Route" header from the message. 
     692     */ 
     693    first_route_hdr = (const pjsip_route_hdr*)  
     694                      pjsip_msg_find_hdr(tdata->msg, PJSIP_H_ROUTE, NULL); 
     695    if (first_route_hdr) { 
     696        target_uri = first_route_hdr->name_addr.uri; 
     697    } else { 
     698        target_uri = tdata->msg->line.req.uri; 
     699    } 
     700 
     701    return get_dest_info(target_uri, (pj_pool_t*)tdata->pool, dest_info); 
     702} 
     703 
     704 
     705/* 
    692706 * Process route-set found in the request and calculate 
    693707 * the destination to be used to send the request message, based 
     
    702716    const pjsip_name_addr *topmost_route_uri; 
    703717    pjsip_route_hdr *first_route_hdr, *last_route_hdr; 
     718    pj_status_t status; 
    704719     
    705720    PJ_ASSERT_RETURN(tdata->msg->type == PJSIP_REQUEST_MSG,  
     
    772787    } 
    773788 
    774     /* The target URI must be a SIP/SIPS URL so we can resolve it's address. 
    775      * Otherwise we're in trouble (i.e. there's no host part in tel: URL). 
    776      */ 
    777     pj_bzero(dest_info, sizeof(*dest_info)); 
    778  
    779     if (PJSIP_URI_SCHEME_IS_SIPS(target_uri)) { 
    780         pjsip_uri *uri = (pjsip_uri*) target_uri; 
    781         const pjsip_sip_uri *url=(const pjsip_sip_uri*)pjsip_uri_get_uri(uri); 
    782         dest_info->flag |= (PJSIP_TRANSPORT_SECURE | PJSIP_TRANSPORT_RELIABLE); 
    783         pj_strdup(tdata->pool, &dest_info->addr.host, &url->host); 
    784         dest_info->addr.port = url->port; 
    785         dest_info->type =  
    786             pjsip_transport_get_type_from_name(&url->transport_param); 
    787  
    788     } else if (PJSIP_URI_SCHEME_IS_SIP(target_uri)) { 
    789         pjsip_uri *uri = (pjsip_uri*) target_uri; 
    790         const pjsip_sip_uri *url=(const pjsip_sip_uri*)pjsip_uri_get_uri(uri); 
    791         pj_strdup(tdata->pool, &dest_info->addr.host, &url->host); 
    792         dest_info->addr.port = url->port; 
    793         dest_info->type =  
    794             pjsip_transport_get_type_from_name(&url->transport_param); 
    795         dest_info->flag =  
    796             pjsip_transport_get_flag_from_type(dest_info->type); 
    797     } else { 
    798         pj_assert(!"Unsupported URI scheme!"); 
    799         PJ_TODO(SUPPORT_REQUEST_ADDR_RESOLUTION_FOR_TEL_URI); 
    800         return PJSIP_EINVALIDSCHEME; 
    801     } 
     789    /* Fill up the destination host/port from the URI. */ 
     790    status = get_dest_info(target_uri, tdata->pool, dest_info); 
     791    if (status != PJ_SUCCESS) 
     792        return status; 
    802793 
    803794    /* If target URI is different than request URI, replace  
Note: See TracChangeset for help on using the changeset viewer.