Ignore:
Timestamp:
Sep 4, 2013 10:07:45 AM (11 years ago)
Author:
ming
Message:

Closed #1696: IP change detection (Contact rewrite method) based on REGISTER final response

File:
1 edited

Legend:

Unmodified
Added
Removed
  • pjproject/trunk/pjsip/src/pjsua-lib/pjsua_acc.c

    r4580 r4586  
    14951495/* Update NAT address from the REGISTER response */ 
    14961496static pj_bool_t acc_check_nat_addr(pjsua_acc *acc, 
     1497                                    int contact_rewrite_method, 
    14971498                                    struct pjsip_regc_cbparam *param) 
    14981499{ 
     
    16791680                         via_addr->ptr, 
    16801681                         rport, 
    1681                          acc->cfg.contact_rewrite_method)); 
    1682  
    1683     pj_assert(acc->cfg.contact_rewrite_method == 1 || 
    1684               acc->cfg.contact_rewrite_method == 2); 
    1685  
    1686     if (acc->cfg.contact_rewrite_method == 1) { 
     1682                         contact_rewrite_method)); 
     1683 
     1684    pj_assert(contact_rewrite_method == PJSUA_CONTACT_REWRITE_UNREGISTER || 
     1685              contact_rewrite_method == PJSUA_CONTACT_REWRITE_NO_UNREG || 
     1686              contact_rewrite_method == PJSUA_CONTACT_REWRITE_ALWAYS_UPDATE); 
     1687 
     1688    if (contact_rewrite_method == PJSUA_CONTACT_REWRITE_UNREGISTER) { 
    16871689        /* Unregister current contact */ 
    16881690        pjsua_acc_set_registration(acc->index, PJ_FALSE); 
     
    17621764    } 
    17631765 
    1764     if (acc->cfg.contact_rewrite_method == 2 && acc->regc != NULL) { 
     1766    if (contact_rewrite_method == PJSUA_CONTACT_REWRITE_NO_UNREG && 
     1767        acc->regc != NULL) 
     1768    { 
    17651769        pjsip_regc_update_contact(acc->regc, 1, &acc->reg_contact); 
    17661770    } 
    17671771 
    17681772    /* Perform new registration */ 
    1769     pjsua_acc_set_registration(acc->index, PJ_TRUE); 
     1773    if (contact_rewrite_method < PJSUA_CONTACT_REWRITE_ALWAYS_UPDATE) { 
     1774        pjsua_acc_set_registration(acc->index, PJ_TRUE); 
     1775    } 
    17701776 
    17711777    pj_pool_release(pool); 
     
    20592065} 
    20602066 
     2067static void regc_tsx_cb(struct pjsip_regc_tsx_cb_param *param) 
     2068{ 
     2069    pjsua_acc *acc = (pjsua_acc*) param->cbparam.token; 
     2070 
     2071    PJSUA_LOCK(); 
     2072 
     2073    if (param->cbparam.regc != acc->regc) { 
     2074        PJSUA_UNLOCK(); 
     2075        return; 
     2076    } 
     2077 
     2078    pj_log_push_indent(); 
     2079 
     2080    if ((acc->cfg.contact_rewrite_method & 
     2081         PJSUA_CONTACT_REWRITE_ALWAYS_UPDATE) == 
     2082        PJSUA_CONTACT_REWRITE_ALWAYS_UPDATE && 
     2083        param->cbparam.code >= 400 && 
     2084        param->cbparam.rdata) 
     2085    { 
     2086        if (acc_check_nat_addr(acc, PJSUA_CONTACT_REWRITE_ALWAYS_UPDATE, 
     2087                               &param->cbparam)) 
     2088        { 
     2089            param->contact_cnt = 1; 
     2090            param->contact[0] = acc->reg_contact; 
     2091        } 
     2092    } 
     2093 
     2094    PJSUA_UNLOCK(); 
     2095    pj_log_pop_indent(); 
     2096} 
     2097 
    20612098/* 
    20622099 * This callback is called by pjsip_regc when outgoing register 
     
    21272164 
    21282165            /* Check NAT bound address */ 
    2129             if (acc_check_nat_addr(acc, param)) { 
     2166            if (acc_check_nat_addr(acc, (acc->cfg.contact_rewrite_method & 3), 
     2167                                   param)) 
     2168            { 
    21302169                PJSUA_UNLOCK(); 
    21312170                pj_log_pop_indent(); 
     
    22712310        return status; 
    22722311    } 
     2312 
     2313    pjsip_regc_set_reg_tsx_cb(acc->regc, regc_tsx_cb); 
    22732314 
    22742315    /* If account is locked to specific transport, then set transport to 
Note: See TracChangeset for help on using the changeset viewer.