Changeset 1547


Ignore:
Timestamp:
Nov 4, 2007 2:05:13 AM (16 years ago)
Author:
bennylp
Message:

Fixed bug with detecting successful unregistration request. Previously, successful unregistration was mistakenly treated as successful registration when it contains no Contact header and has positive Expires header value

File:
1 edited

Legend:

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

    r1518 r1547  
    683683        pjsip_contact_hdr *contact[PJSIP_REGC_MAX_CONTACT]; 
    684684        pjsip_rx_data *rdata; 
    685         pj_int32_t expiration = 0xFFFF; 
     685        enum { NOEXP = 0x1FFFFFFF }; 
     686        pj_int32_t expiration = NOEXP; 
    686687 
    687688        if (tsx->status_code/100 == 2) { 
     
    689690            pjsip_contact_hdr *hdr; 
    690691            pjsip_msg *msg; 
     692            pj_bool_t has_our_contact = PJ_FALSE; 
    691693            pjsip_expires_hdr *expires; 
    692694 
    693695            rdata = event->body.tsx_state.src.rdata; 
    694696            msg = rdata->msg_info.msg; 
     697 
     698            /* Record all Contact headers in the response */ 
    695699            hdr = (pjsip_contact_hdr*) 
    696700                  pjsip_msg_find_hdr( msg, PJSIP_H_CONTACT, NULL); 
     
    704708            } 
    705709 
     710            /* Set default expiration value to the value of Expires hdr */ 
    706711            expires = (pjsip_expires_hdr*) 
    707712                      pjsip_msg_find_hdr(msg, PJSIP_H_EXPIRES, NULL); 
     
    710715                expiration = expires->ivalue; 
    711716             
     717            /* Enumerate all Contact headers found in the response and 
     718             * find the Contact(s) that we register. 
     719             */ 
    712720            for (i=0; i<contact_cnt; ++i) { 
    713                 hdr = contact[i]; 
    714                 if (hdr->expires >= 0 && hdr->expires < expiration) { 
    715                     pjsip_contact_hdr *our_contact; 
     721                pjsip_contact_hdr *our_contact; 
     722 
     723                our_contact = (pjsip_contact_hdr*) 
     724                              regc->contact_hdr_list.next; 
     725 
     726                while ((void*)our_contact != (void*)&regc->contact_hdr_list) { 
     727 
    716728                    const pjsip_uri *uri1, *uri2; 
    717729 
    718                     our_contact = (pjsip_contact_hdr*) 
    719                                   regc->contact_hdr_list.next; 
    720                     if ((void*)our_contact==(void*)&regc->contact_hdr_list.next) 
    721                         continue; 
    722  
    723                     /* Only set expiration time if this is the same Contact 
    724                      * that we register. 
     730                    /* Compare URIs. 
     731                     * Exclude the display name when comparing the URI since 
     732                     * server may not return it. 
    725733                     */ 
    726734 
    727                     /* Exclude the display name when comparing the URI. 
    728                      * This is because a well known open source proxy server 
    729                      * doesn't return the display name in the Contact header 
    730                      * of the REGISTER response. 
    731                      */ 
    732                     uri1 = pjsip_uri_get_uri(hdr->uri); 
     735                    uri1 = pjsip_uri_get_uri(contact[i]->uri); 
    733736                    uri2 = pjsip_uri_get_uri(our_contact->uri); 
    734737                    if (pjsip_uri_cmp(PJSIP_URI_IN_CONTACT_HDR, uri1, uri2)==0) 
    735738                    { 
    736                         expiration = contact[i]->expires; 
     739                        has_our_contact = PJ_TRUE; 
     740 
     741                        if (contact[i]->expires >= 0 &&  
     742                            contact[i]->expires < expiration)  
     743                        { 
     744                            /* Get the lowest expiration time. */ 
     745                            expiration = contact[i]->expires; 
     746                        } 
    737747                    } 
     748 
     749                    our_contact = our_contact->next; 
    738750                } 
    739751            } 
    740752 
    741             if (regc->auto_reg && expiration != 0 && expiration != 0xFFFF) { 
     753            /* When the response doesn't contain our Contact header, that 
     754             * means we have been unregistered. 
     755             */ 
     756            if (!has_our_contact) 
     757                expiration = 0; 
     758 
     759            /* Schedule next registration */ 
     760            if (regc->auto_reg && expiration != 0 && expiration != NOEXP) { 
    742761                pj_time_val delay = { 0, 0}; 
    743762 
     
    770789 
    771790        /* Call callback. */ 
    772         if (expiration == 0xFFFF) expiration = -1; 
     791        if (expiration == NOEXP) expiration = -1; 
    773792        call_callback(regc, PJ_SUCCESS, tsx->status_code,  
    774793                      (rdata ? &rdata->msg_info.msg->line.status.reason  
Note: See TracChangeset for help on using the changeset viewer.