- Timestamp:
- Mar 22, 2008 9:33:52 AM (17 years ago)
- Location:
- pjproject/trunk
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
pjproject/trunk/pjsip-apps/src/pjsua/pjsua_app.c
r1886 r1889 695 695 696 696 case OPT_AUTO_UPDATE_NAT: /* OPT_AUTO_UPDATE_NAT */ 697 cur_acc->a uto_update_nat= pj_strtoul(pj_cstr(&tmp, pj_optarg));697 cur_acc->allow_contact_rewrite = pj_strtoul(pj_cstr(&tmp, pj_optarg)); 698 698 break; 699 699 … … 1149 1149 1150 1150 /* */ 1151 //if (acc_cfg->auto_update_nat)1151 if (acc_cfg->allow_contact_rewrite==0) 1152 1152 { 1153 pj_ansi_sprintf(line, "-- auto-update-nat%i\n",1154 (int)acc_cfg->a uto_update_nat);1153 pj_ansi_sprintf(line, "--contact-rewrite %i\n", 1154 (int)acc_cfg->allow_contact_rewrite); 1155 1155 pj_strcat2(result, line); 1156 1156 } -
pjproject/trunk/pjsip/include/pjsua-lib/pjsua.h
r1823 r1889 2027 2027 2028 2028 /** 2029 * This option is useful for keeping the UDP transport address up to 2030 * date with the NAT public mapped address. When this option is 2031 * enabled and STUN is configured, the library will keep track of 2032 * the public IP address from the response of REGISTER request. Once 2033 * it detects that the address has changed, it will unregister current 2034 * Contact, update the UDP transport address, and register a new 2035 * Contact to the registrar. 2029 * This option is used to update the UDP transport address and the Contact 2030 * header of REGISTER request. When this option is enabled, the library 2031 * will keep track of the public IP address from the response of REGISTER 2032 * request. Once it detects that the address has changed, it will 2033 * unregister current Contact, update the Contact with transport address 2034 * learned from Via header, and register a new Contact to the registrar. 2035 * This will also update the public name of UDP transport if STUN is 2036 * configured. 2036 2037 * 2037 2038 * Default: 1 (yes) 2038 2039 */ 2039 pj_bool_t a uto_update_nat;2040 pj_bool_t allow_contact_rewrite; 2040 2041 2041 2042 /** -
pjproject/trunk/pjsip/include/pjsua-lib/pjsua_internal.h
r1774 r1889 85 85 pj_str_t display; /**< Display name, if any. */ 86 86 pj_str_t user_part; /**< User part of local URI. */ 87 pj_str_t contact; /**< Our Contact URI for REGISTER */ 87 88 88 89 pj_str_t srv_domain; /**< Host part of reg server. */ -
pjproject/trunk/pjsip/src/pjsua-lib/pjsua_acc.c
r1655 r1889 485 485 pjsip_transport *tp; 486 486 const pj_str_t *via_addr; 487 pj_pool_t *pool; 487 488 int rport; 489 pjsip_sip_uri *uri; 488 490 pjsip_via_hdr *via; 489 491 … … 491 493 492 494 /* Only update if account is configured to auto-update */ 493 if (acc->cfg.a uto_update_nat== PJ_FALSE)495 if (acc->cfg.allow_contact_rewrite == PJ_FALSE) 494 496 return PJ_FALSE; 495 497 496 /* Only update if registration uses UDP transport */ 497 if (tp->key.type != PJSIP_TRANSPORT_UDP) 498 #if 0 499 // Always update 500 // See http://lists.pjsip.org/pipermail/pjsip_lists.pjsip.org/2008-March/002178.html 501 502 /* For UDP, only update if STUN is enabled (for now). 503 * For TCP/TLS, always check. 504 */ 505 if ((tp->key.type == PJSIP_TRANSPORT_UDP && 506 (pjsua_var.ua_cfg.stun_domain.slen != 0 || 507 (pjsua_var.ua_cfg.stun_host.slen != 0)) || 508 (tp->key.type == PJSIP_TRANSPORT_TCP) || 509 (tp->key.type == PJSIP_TRANSPORT_TLS)) 510 { 511 /* Yes we will check */ 512 } else { 498 513 return PJ_FALSE; 499 500 /* Only update if STUN is enabled (for now) */ 501 if (pjsua_var.ua_cfg.stun_domain.slen == 0 && 502 pjsua_var.ua_cfg.stun_host.slen == 0) 503 { 504 return PJ_FALSE; 505 } 514 } 515 #endif 506 516 507 517 /* Get the received and rport info */ … … 510 520 /* Remote doesn't support rport */ 511 521 rport = via->sent_by.port; 522 if (rport==0) 523 rport = pjsip_transport_get_default_port_for_type(tp->key.type); 512 524 } else 513 525 rport = via->rport_param; … … 518 530 via_addr = &via->sent_by.host; 519 531 520 /* Compare received and rport with transport published address */ 521 if (tp->local_name.port == rport && 522 pj_stricmp(&tp->local_name.host, via_addr)==0) 532 /* Compare received and rport with the URI in our registration */ 533 pool = pjsua_pool_create("tmp", 512, 512); 534 uri = (pjsip_sip_uri*) 535 pjsip_parse_uri(pool, acc->contact.ptr, acc->contact.slen, 0); 536 pj_assert(uri != NULL); 537 uri = pjsip_uri_get_uri(uri); 538 539 if (uri->port == 0) 540 uri->port = pjsip_transport_get_default_port_for_type(tp->key.type); 541 542 if (uri->port == rport && 543 pj_stricmp(&uri->host, via_addr)==0) 523 544 { 524 545 /* Address doesn't change */ 546 pj_pool_release(pool); 525 547 return PJ_FALSE; 526 548 } … … 532 554 "(%.*s:%d --> %.*s:%d). Updating registration..", 533 555 acc->index, 534 (int) tp->local_name.host.slen,535 tp->local_name.host.ptr,536 tp->local_name.port,556 (int)uri->host.slen, 557 uri->host.ptr, 558 uri->port, 537 559 (int)via_addr->slen, 538 560 via_addr->ptr, … … 546 568 } 547 569 548 /* Update transport address */ 549 pj_strdup_with_null(tp->pool, &tp->local_name.host, via_addr); 550 tp->local_name.port = rport; 570 /* Update account's Contact header */ 571 { 572 char *tmp; 573 int len; 574 575 tmp = pj_pool_alloc(pool, PJSIP_MAX_URL_SIZE); 576 len = pj_ansi_snprintf(tmp, PJSIP_MAX_URL_SIZE, 577 "<sip:%.*s@%.*s:%d;transport=%s>", 578 (int)acc->user_part.slen, 579 acc->user_part.ptr, 580 (int)via_addr->slen, 581 via_addr->ptr, 582 rport, 583 tp->type_name); 584 if (len < 1) { 585 PJ_LOG(1,(THIS_FILE, "URI too long")); 586 pj_pool_release(pool); 587 return PJ_FALSE; 588 } 589 pj_strdup2(pjsua_var.pool, &acc->contact, tmp); 590 } 591 592 /* For UDP transport, if STUN is enabled then update the transport's 593 * published name as well. 594 */ 595 if (tp->key.type==PJSIP_TRANSPORT_UDP && 596 (pjsua_var.ua_cfg.stun_domain.slen != 0 || 597 pjsua_var.ua_cfg.stun_host.slen != 0)) 598 { 599 pj_strdup_with_null(tp->pool, &tp->local_name.host, via_addr); 600 tp->local_name.port = rport; 601 } 551 602 552 603 /* Perform new registration */ 553 604 pjsua_acc_set_registration(acc->index, PJ_TRUE); 605 606 pj_pool_release(pool); 554 607 555 608 return PJ_TRUE; … … 864 917 { 865 918 pjsua_acc *acc; 866 pj_str_t contact;867 919 pj_pool_t *pool; 868 920 pj_status_t status; … … 894 946 895 947 pool = pjsua_pool_create("tmpregc", 512, 512); 896 status = pjsua_acc_create_uac_contact( pool, &contact, 897 acc_id, &acc->cfg.reg_uri); 898 if (status != PJ_SUCCESS) { 899 pjsua_perror(THIS_FILE, "Unable to generate suitable Contact header" 900 " for registration", 901 status); 902 pjsip_regc_destroy(acc->regc); 903 pj_pool_release(pool); 904 acc->regc = NULL; 905 return status; 948 949 if (acc->contact.slen == 0) { 950 pj_str_t tmp_contact; 951 952 status = pjsua_acc_create_uac_contact( pool, &tmp_contact, 953 acc_id, &acc->cfg.reg_uri); 954 if (status != PJ_SUCCESS) { 955 pjsua_perror(THIS_FILE, "Unable to generate suitable Contact header" 956 " for registration", 957 status); 958 pjsip_regc_destroy(acc->regc); 959 pj_pool_release(pool); 960 acc->regc = NULL; 961 return status; 962 } 963 964 pj_strdup_with_null(pjsua_var.pool, &acc->contact, &tmp_contact); 906 965 } 907 966 … … 910 969 &acc->cfg.id, 911 970 &acc->cfg.id, 912 1, & contact,971 1, &acc->contact, 913 972 acc->cfg.reg_timeout); 914 973 if (status != PJ_SUCCESS) { -
pjproject/trunk/pjsip/src/pjsua-lib/pjsua_core.c
r1873 r1889 143 143 cfg->reg_timeout = PJSUA_REG_INTERVAL; 144 144 cfg->transport_id = PJSUA_INVALID_ID; 145 cfg->a uto_update_nat= PJ_TRUE;145 cfg->allow_contact_rewrite = PJ_TRUE; 146 146 cfg->require_100rel = pjsua_var.ua_cfg.require_100rel; 147 147 cfg->ka_interval = 15;
Note: See TracChangeset
for help on using the changeset viewer.