Changeset 1816


Ignore:
Timestamp:
Feb 22, 2008 8:36:06 AM (12 years ago)
Author:
bennylp
Message:

Ticket #492: Bug in strict route processing when challenged with 401/407 response

Location:
pjproject/trunk/pjsip
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • pjproject/trunk/pjsip/include/pjsip/sip_transport.h

    r1748 r1816  
    496496    /** The message in this buffer. */ 
    497497    pjsip_msg           *msg; 
     498 
     499    /** Strict route header saved by #pjsip_process_route_set(), to be 
     500     *  restored by #pjsip_restore_strict_route_set(). 
     501     */ 
     502    pjsip_route_hdr     *saved_strict_route; 
    498503 
    499504    /** Buffer to the printed text representation of the message. When the 
  • pjproject/trunk/pjsip/include/pjsip/sip_util.h

    r1748 r1816  
    220220PJ_DECL(pj_status_t) pjsip_process_route_set(pjsip_tx_data *tdata, 
    221221                                             pjsip_host_info *dest_info ); 
     222 
     223 
     224/** 
     225 * Swap the request URI and strict route back to the original position 
     226 * before #pjsip_process_route_set() function is called. If no strict 
     227 * route URI was found by #pjsip_process_route_set(), this function will 
     228 * do nothing. 
     229 * 
     230 * This function should only used internally by PJSIP client authentication 
     231 * module. 
     232 * 
     233 * @param tdata     Transmit data containing request message. 
     234 */ 
     235PJ_DECL(void) pjsip_restore_strict_route_set(pjsip_tx_data *tdata); 
     236 
    222237 
    223238/** 
  • pjproject/trunk/pjsip/src/pjsip/sip_auth_client.c

    r1569 r1816  
    10991099    via->branch_param.slen = 0; 
    11001100 
     1101    /* Restore strict route set. 
     1102     * See http://trac.pjsip.org/repos/ticket/492 
     1103     */ 
     1104    pjsip_restore_strict_route_set(tdata); 
     1105 
    11011106    /* Must invalidate the message! */ 
    11021107    pjsip_tx_data_invalidate_msg(tdata); 
  • pjproject/trunk/pjsip/src/pjsip/sip_util.c

    r1417 r1816  
    721721    PJ_ASSERT_RETURN(dest_info != NULL, PJ_EINVAL); 
    722722 
     723    /* Assert if the request contains strict route and strict 
     724     * route processing has been applied before. We need to 
     725     * restore the strict route with pjsip_restore_strict_route_set() 
     726     * before we can call this function again, otherwise strict 
     727     * route will be swapped twice! 
     728     */ 
     729    PJ_ASSERT_RETURN(tdata->saved_strict_route==NULL, PJ_EBUG); 
     730 
    723731    /* Find the first and last "Route" headers from the message. */ 
    724732    last_route_hdr = first_route_hdr = (pjsip_route_hdr*) 
     
    776784                              pjsip_uri_get_uri((pjsip_uri*)topmost_route_uri); 
    777785            pj_list_erase(first_route_hdr); 
     786            tdata->saved_strict_route = first_route_hdr; 
    778787            if (first_route_hdr == last_route_hdr) 
    779                 last_route_hdr = NULL; 
     788                first_route_hdr = last_route_hdr = NULL; 
    780789        } 
    781790 
     
    807816    /* Success. */ 
    808817    return PJ_SUCCESS;   
     818} 
     819 
     820 
     821/* 
     822 * Swap the request URI and strict route back to the original position 
     823 * before #pjsip_process_route_set() function is called. This function 
     824 * should only used internally by PJSIP client authentication module. 
     825 */ 
     826PJ_DEF(void) pjsip_restore_strict_route_set(pjsip_tx_data *tdata) 
     827{ 
     828    pjsip_route_hdr *first_route_hdr, *last_route_hdr; 
     829 
     830    /* Check if we have found strict route before */ 
     831    if (tdata->saved_strict_route == NULL) { 
     832        /* This request doesn't contain strict route */ 
     833        return; 
     834    } 
     835 
     836    /* Find the first "Route" headers from the message. */ 
     837    first_route_hdr = (pjsip_route_hdr*) 
     838                      pjsip_msg_find_hdr(tdata->msg, PJSIP_H_ROUTE, NULL); 
     839 
     840    if (first_route_hdr == NULL) { 
     841        /* User has modified message route? We don't expect this! */ 
     842        pj_assert(!"Message route was modified?"); 
     843        tdata->saved_strict_route = NULL; 
     844        return; 
     845    } 
     846 
     847    /* Find last Route header */ 
     848    last_route_hdr = first_route_hdr; 
     849    while (last_route_hdr->next != (void*)&tdata->msg->hdr) { 
     850        pjsip_route_hdr *hdr; 
     851        hdr = (pjsip_route_hdr*) 
     852              pjsip_msg_find_hdr(tdata->msg, PJSIP_H_ROUTE,  
     853                                 last_route_hdr->next); 
     854        if (!hdr) 
     855            break; 
     856        last_route_hdr = hdr; 
     857    } 
     858 
     859    /* Put the last Route header as request URI, delete last Route 
     860     * header, and insert the saved strict route as the first Route. 
     861     */ 
     862    tdata->msg->line.req.uri = last_route_hdr->name_addr.uri; 
     863    pj_list_insert_before(first_route_hdr, tdata->saved_strict_route); 
     864    pj_list_erase(last_route_hdr); 
     865 
     866    /* Reset */ 
     867    tdata->saved_strict_route = NULL; 
    809868} 
    810869 
Note: See TracChangeset for help on using the changeset viewer.