Ignore:
Timestamp:
Mar 18, 2007 9:29:45 AM (13 years ago)
Author:
bennylp
Message:

Fixed ticket #187: Bug with destination address calculation for strict route set (thanks Hoi-Ho Chan)

File:
1 edited

Legend:

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

    r974 r1079  
    626626 * chapter 8.1.2. 
    627627 */ 
    628 PJ_DEF(pj_status_t) pjsip_get_request_addr( pjsip_tx_data *tdata, 
     628PJ_DEF(pj_status_t) pjsip_get_request_dest(const pjsip_tx_data *tdata, 
     629                                           pjsip_host_info *dest_info ) 
     630{ 
     631    const pjsip_uri *target_uri; 
     632    const pjsip_route_hdr *first_route_hdr; 
     633     
     634    PJ_ASSERT_RETURN(tdata->msg->type == PJSIP_REQUEST_MSG,  
     635                     PJSIP_ENOTREQUESTMSG); 
     636    PJ_ASSERT_RETURN(dest_info != NULL, PJ_EINVAL); 
     637 
     638    /* Get the first "Route" header from the message. 
     639     */ 
     640    first_route_hdr = pjsip_msg_find_hdr(tdata->msg, PJSIP_H_ROUTE, NULL); 
     641    if (first_route_hdr) { 
     642        target_uri = first_route_hdr->name_addr.uri; 
     643    } else { 
     644        target_uri = tdata->msg->line.req.uri; 
     645    } 
     646 
     647 
     648    /* The target URI must be a SIP/SIPS URL so we can resolve it's address. 
     649     * Otherwise we're in trouble (i.e. there's no host part in tel: URL). 
     650     */ 
     651    pj_bzero(dest_info, sizeof(*dest_info)); 
     652 
     653    if (PJSIP_URI_SCHEME_IS_SIPS(target_uri)) { 
     654        pjsip_uri *uri = (pjsip_uri*) target_uri; 
     655        const pjsip_sip_uri *url=(const pjsip_sip_uri*)pjsip_uri_get_uri(uri); 
     656        dest_info->flag |= (PJSIP_TRANSPORT_SECURE | PJSIP_TRANSPORT_RELIABLE); 
     657        pj_strdup(tdata->pool, &dest_info->addr.host, &url->host); 
     658        dest_info->addr.port = url->port; 
     659        dest_info->type =  
     660            pjsip_transport_get_type_from_name(&url->transport_param); 
     661 
     662    } else if (PJSIP_URI_SCHEME_IS_SIP(target_uri)) { 
     663        pjsip_uri *uri = (pjsip_uri*) target_uri; 
     664        const pjsip_sip_uri *url=(const pjsip_sip_uri*)pjsip_uri_get_uri(uri); 
     665        pj_strdup(tdata->pool, &dest_info->addr.host, &url->host); 
     666        dest_info->addr.port = url->port; 
     667        dest_info->type =  
     668            pjsip_transport_get_type_from_name(&url->transport_param); 
     669        dest_info->flag =  
     670            pjsip_transport_get_flag_from_type(dest_info->type); 
     671    } else { 
     672        pj_assert(!"Unsupported URI scheme!"); 
     673        PJ_TODO(SUPPORT_REQUEST_ADDR_RESOLUTION_FOR_TEL_URI); 
     674        return PJSIP_EINVALIDSCHEME; 
     675    } 
     676 
     677    return PJ_SUCCESS; 
     678} 
     679 
     680 
     681/* 
     682 * Process route-set found in the request and calculate 
     683 * the destination to be used to send the request message, based 
     684 * on the request URI and Route headers in the message. The procedure 
     685 * used here follows the guidelines on sending the request in RFC 3261 
     686 * chapter 8.1.2. 
     687 */ 
     688PJ_DEF(pj_status_t) pjsip_process_route_set(pjsip_tx_data *tdata, 
    629689                                            pjsip_host_info *dest_info ) 
    630690{ 
     
    637697    PJ_ASSERT_RETURN(dest_info != NULL, PJ_EINVAL); 
    638698 
    639     /* Get the first "Route" header from the message. If the message doesn't 
    640      * have any "Route" headers but the endpoint has, then copy the "Route" 
    641      * headers from the endpoint first. 
    642      */ 
     699    /* Find the first and last "Route" headers from the message. */ 
    643700    last_route_hdr = first_route_hdr =  
    644701        pjsip_msg_find_hdr(tdata->msg, PJSIP_H_ROUTE, NULL); 
     
    9471004 
    9481005    /* Get destination name to contact. */ 
    949     status = pjsip_get_request_addr(tdata, &dest_info); 
     1006    status = pjsip_process_route_set(tdata, &dest_info); 
    9501007    if (status != PJ_SUCCESS) 
    9511008        return status; 
Note: See TracChangeset for help on using the changeset viewer.