Changeset 1454


Ignore:
Timestamp:
Sep 27, 2007 2:07:07 PM (17 years ago)
Author:
bennylp
Message:

Ticket #381: auto-update the IP address in Contact according to the address/port received in REGISTER response

Location:
pjproject/trunk/pjsip
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • pjproject/trunk/pjsip/build/pjsua_lib.dsp

    r1098 r1454  
    4141# PROP Intermediate_Dir ".\output\pjsua-lib-i386-win32-vc6-release" 
    4242# PROP Target_Dir "" 
     43F90=df.exe 
    4344# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_MBCS" /D "_LIB" /YX /FD /c 
    4445# ADD CPP /nologo /MD /W4 /GX /Zi /O2 /I "../include" /I "../../pjmedia/include" /I "../../pjlib-util/include" /I "../../pjlib/include" /I "../../pjnath/include" /D "NDEBUG" /D PJ_WIN32=1 /D PJ_M_I386=1 /D "WIN32" /D "_MBCS" /D "_LIB" /FR /FD /c 
     
    6566# PROP Intermediate_Dir ".\output\pjsua-lib-i386-win32-vc6-debug" 
    6667# PROP Target_Dir "" 
     68F90=df.exe 
    6769# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_MBCS" /D "_LIB" /YX /FD /GZ /c 
    6870# ADD CPP /nologo /MTd /W4 /Gm /GX /ZI /Od /I "../include" /I "../../pjmedia/include" /I "../../pjlib-util/include" /I "../../pjlib/include" /I "../../pjnath/include" /D "_DEBUG" /D PJ_WIN32=1 /D PJ_M_I386=1 /D "WIN32" /D "_MBCS" /D "_LIB" /FR /FD /GZ /c 
  • pjproject/trunk/pjsip/include/pjsua-lib/pjsua.h

    r1435 r1454  
    18481848    pjsua_transport_id  transport_id; 
    18491849 
     1850    /** 
     1851     * This option is useful for keeping the UDP transport address up to 
     1852     * date with the NAT public mapped address. When this option is  
     1853     * enabled and STUN is configured, the library will keep track of 
     1854     * the public IP address from the response of REGISTER request. Once 
     1855     * it detects that the address has changed, it will unregister current 
     1856     * Contact, update the UDP transport address, and register a new 
     1857     * Contact to the registrar. 
     1858     * 
     1859     * Default: 1 (yes) 
     1860     */ 
     1861    pj_bool_t auto_update_nat; 
     1862 
    18501863} pjsua_acc_config; 
    18511864 
  • pjproject/trunk/pjsip/src/pjsua-lib/pjsua_acc.c

    r1424 r1454  
    455455 
    456456 
     457/* Update NAT address from the REGISTER response */ 
     458static pj_bool_t acc_check_nat_addr(pjsua_acc *acc, 
     459                                    struct pjsip_regc_cbparam *param) 
     460{ 
     461    pjsip_transport *tp; 
     462    const pj_str_t *via_addr; 
     463    int rport; 
     464    pjsip_via_hdr *via; 
     465 
     466    tp = param->rdata->tp_info.transport; 
     467 
     468    /* Only update if account is configured to auto-update */ 
     469    if (acc->cfg.auto_update_nat == PJ_FALSE) 
     470        return PJ_FALSE; 
     471 
     472    /* Only update if registration uses UDP transport */ 
     473    if (tp->key.type != PJSIP_TRANSPORT_UDP) 
     474        return PJ_FALSE; 
     475 
     476    /* Only update if STUN is enabled (for now) */ 
     477    if (pjsua_var.ua_cfg.stun_domain.slen == 0 && 
     478        pjsua_var.ua_cfg.stun_host.slen == 0) 
     479    { 
     480        return PJ_FALSE; 
     481    } 
     482 
     483    /* Get the received and rport info */ 
     484    via = param->rdata->msg_info.via; 
     485    if (via->rport_param < 1) { 
     486        /* Remote doesn't support rport */ 
     487        rport = via->sent_by.port; 
     488    } else 
     489        rport = via->rport_param; 
     490 
     491    if (via->recvd_param.slen != 0) 
     492        via_addr = &via->recvd_param; 
     493    else 
     494        via_addr = &via->sent_by.host; 
     495 
     496    /* Compare received and rport with transport published address */ 
     497    if (tp->local_name.port == rport && 
     498        pj_stricmp(&tp->local_name.host, via_addr)==0) 
     499    { 
     500        /* Address doesn't change */ 
     501        return PJ_FALSE; 
     502    } 
     503 
     504    /* At this point we've detected that the address as seen by registrar. 
     505     * has changed. 
     506     */ 
     507    PJ_LOG(3,(THIS_FILE, "IP address change detected for account %d " 
     508                         "(%.*s:%d --> %.*s:%d). Updating registration..", 
     509                         acc->index, 
     510                         (int)tp->local_name.host.slen, 
     511                         tp->local_name.host.ptr, 
     512                         tp->local_name.port, 
     513                         (int)via_addr->slen, 
     514                         via_addr->ptr, 
     515                         rport)); 
     516 
     517    /* Unregister current contact */ 
     518    pjsua_acc_set_registration(acc->index, PJ_FALSE); 
     519    if (acc->regc != NULL) { 
     520        pjsip_regc_destroy(acc->regc); 
     521        acc->regc = NULL; 
     522    } 
     523 
     524    /* Update transport address */ 
     525    pj_strdup_with_null(tp->pool, &tp->local_name.host, via_addr); 
     526    tp->local_name.port = rport; 
     527 
     528    /* Perform new registration */ 
     529    pjsua_acc_set_registration(acc->index, PJ_TRUE); 
     530 
     531    return PJ_TRUE; 
     532} 
     533 
    457534/* 
    458535 * This callback is called by pjsip_regc when outgoing register 
     
    463540 
    464541    pjsua_acc *acc = (pjsua_acc*) param->token; 
     542 
     543    if (param->regc != acc->regc) 
     544        return; 
    465545 
    466546    PJSUA_LOCK(); 
     
    490570                      pjsua_var.acc[acc->index].cfg.id.ptr)); 
    491571        } else { 
     572            /* Check NAT bound address */ 
     573            if (acc_check_nat_addr(acc, param)) { 
     574                /* Update address, don't notify application yet */ 
     575                PJSUA_UNLOCK(); 
     576                return; 
     577            } 
     578 
    492579            PJ_LOG(3, (THIS_FILE,  
    493580                       "%s: registration success, status=%d (%.*s), " 
  • pjproject/trunk/pjsip/src/pjsua-lib/pjsua_core.c

    r1426 r1454  
    141141    cfg->reg_timeout = PJSUA_REG_INTERVAL; 
    142142    cfg->transport_id = PJSUA_INVALID_ID; 
     143    cfg->auto_update_nat = PJ_TRUE; 
    143144} 
    144145 
Note: See TracChangeset for help on using the changeset viewer.