Changeset 1431


Ignore:
Timestamp:
Sep 11, 2007 9:04:51 AM (17 years ago)
Author:
bennylp
Message:

Fixed ticket #371: Bug with REGISTER expiration calculation (thanks Philippe Leuba)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • pjproject/trunk/pjsip/src/pjsip-ua/sip_reg.c

    r1417 r1431  
    6666    pjsip_from_hdr              *from_hdr; 
    6767    pjsip_to_hdr                *to_hdr; 
    68     char                        *contact_buf; 
    69     pjsip_generic_string_hdr    *contact_hdr; 
     68    pjsip_hdr                    contact_hdr_list; 
    7069    pjsip_expires_hdr           *expires_hdr; 
    7170    pjsip_contact_hdr           *unreg_contact_hdr; 
     
    110109    regc->token = token; 
    111110    regc->cb = cb; 
    112     regc->contact_buf = (char*)pj_pool_alloc(pool, PJSIP_REGC_CONTACT_BUF_SIZE); 
    113111    regc->expires = PJSIP_REGC_EXPIRATION_NOT_SPECIFIED; 
    114112 
     
    119117    pj_list_init(&regc->route_set); 
    120118    pj_list_init(&regc->hdr_list); 
     119    pj_list_init(&regc->contact_hdr_list); 
    121120 
    122121    /* Done */ 
     
    191190                                const pj_str_t contact[] ) 
    192191{ 
     192    const pj_str_t CONTACT = { "Contact", 7 }; 
    193193    int i; 
    194     char *s; 
    195     const pj_str_t contact_STR = { "Contact", 7}; 
    196  
    197     /* Concatenate contacts. */ 
    198     for (i=0, s=regc->contact_buf; i<contact_cnt; ++i) { 
    199         if ((s-regc->contact_buf) + contact[i].slen + 2 > PJSIP_REGC_CONTACT_BUF_SIZE) { 
    200             return PJSIP_EURITOOLONG; 
     194     
     195    /* Clear existing contacts */ 
     196    pj_list_init(&regc->contact_hdr_list); 
     197 
     198    for (i=0; i<contact_cnt; ++i) { 
     199        pjsip_hdr *hdr; 
     200        pj_str_t tmp; 
     201 
     202        pj_strdup_with_null(regc->pool, &tmp, &contact[i]); 
     203        hdr = pjsip_parse_hdr(regc->pool, &CONTACT, tmp.ptr, tmp.slen, NULL); 
     204        if (hdr == NULL) { 
     205            PJ_LOG(4,(THIS_FILE, "Invalid Contact URI: \"%.*s\"",  
     206                     (int)tmp.slen, tmp.ptr)); 
     207            return PJSIP_EINVALIDURI; 
    201208        } 
    202         pj_memcpy(s, contact[i].ptr, contact[i].slen); 
    203         s += contact[i].slen; 
    204  
    205         if (i != contact_cnt - 1) { 
    206             *s++ = ','; 
    207             *s++ = ' '; 
    208         } 
    209     } 
    210  
    211     /* Set "Contact" header. */ 
    212     regc->contact_hdr = pjsip_generic_string_hdr_create(regc->pool,  
    213                                                         &contact_STR, 
    214                                                         NULL); 
    215     regc->contact_hdr->hvalue.ptr = regc->contact_buf; 
    216     regc->contact_hdr->hvalue.slen = (s - regc->contact_buf); 
     209 
     210        pj_list_push_back(&regc->contact_hdr_list, hdr); 
     211    } 
    217212 
    218213    return PJ_SUCCESS; 
     
    425420{ 
    426421    pjsip_msg *msg; 
     422    pjsip_hdr *hdr; 
    427423    pj_status_t status; 
    428424    pjsip_tx_data *tdata; 
     
    434430        return status; 
    435431 
    436     /* Add Contact header. */ 
    437432    msg = tdata->msg; 
    438     pjsip_msg_add_hdr(msg, (pjsip_hdr*) 
    439                            pjsip_hdr_shallow_clone(tdata->pool,  
    440                                                    regc->contact_hdr)); 
     433 
     434    /* Add Contact headers. */ 
     435    hdr = regc->contact_hdr_list.next; 
     436    while (hdr != &regc->contact_hdr_list) { 
     437        pjsip_msg_add_hdr(msg, (pjsip_hdr*) 
     438                               pjsip_hdr_shallow_clone(tdata->pool, hdr)); 
     439        hdr = hdr->next; 
     440    } 
     441 
    441442    if (regc->expires_hdr) 
    442443        pjsip_msg_add_hdr(msg, (pjsip_hdr*) 
     
    462463    pjsip_tx_data *tdata; 
    463464    pjsip_msg *msg; 
     465    pjsip_hdr *hdr; 
    464466    pj_status_t status; 
    465467 
     
    476478 
    477479    msg = tdata->msg; 
    478     pjsip_msg_add_hdr(msg, (pjsip_hdr*) 
    479                            pjsip_hdr_shallow_clone(tdata->pool,  
    480                                                    regc->contact_hdr)); 
     480 
     481    /* Add Contact headers. */ 
     482    hdr = regc->contact_hdr_list.next; 
     483    while (hdr != &regc->contact_hdr_list) { 
     484        pjsip_msg_add_hdr(msg, (pjsip_hdr*) 
     485                               pjsip_hdr_shallow_clone(tdata->pool, hdr)); 
     486        hdr = hdr->next; 
     487    } 
     488 
    481489    pjsip_msg_add_hdr( msg, (pjsip_hdr*)regc->unreg_expires_hdr); 
    482490 
     
    681689            for (i=0; i<contact_cnt; ++i) { 
    682690                hdr = contact[i]; 
    683                 if (hdr->expires >= 0 && hdr->expires < expiration) 
    684                     expiration = contact[i]->expires; 
     691                if (hdr->expires >= 0 && hdr->expires < expiration) { 
     692                    pjsip_contact_hdr *our_contact; 
     693 
     694                    our_contact = (pjsip_contact_hdr*) 
     695                                  regc->contact_hdr_list.next; 
     696                    if ((void*)our_contact==(void*)&regc->contact_hdr_list.next) 
     697                        continue; 
     698 
     699                    /* Only set expiration time if this is the same Contact 
     700                     * that we register. 
     701                     */ 
     702                    if (pjsip_uri_cmp(PJSIP_URI_IN_CONTACT_HDR,  
     703                                      hdr->uri,  
     704                                      our_contact->uri)==0)  
     705                    { 
     706                        expiration = contact[i]->expires; 
     707                    } 
     708                } 
    685709            } 
    686710 
Note: See TracChangeset for help on using the changeset viewer.