Changeset 1889 for pjproject/trunk/pjsip/src/pjsua-lib/pjsua_acc.c
- Timestamp:
- Mar 22, 2008 9:33:52 AM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
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) {
Note: See TracChangeset
for help on using the changeset viewer.