Changeset 1098 for pjproject/trunk/pjsip/src/pjsua-lib/pjsua_core.c
- Timestamp:
- Mar 23, 2007 4:34:20 PM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
pjproject/trunk/pjsip/src/pjsua-lib/pjsua_core.c
r1074 r1098 43 43 unsigned i; 44 44 45 pj_bzero(&pjsua_var, sizeof(pjsua_var)); 46 45 47 for (i=0; i<PJ_ARRAY_SIZE(pjsua_var.acc); ++i) 46 48 pjsua_var.acc[i].index = i; … … 48 50 for (i=0; i<PJ_ARRAY_SIZE(pjsua_var.tpdata); ++i) 49 51 pjsua_var.tpdata[i].index = i; 52 53 pjsua_var.stun_status = PJ_EUNKNOWN; 50 54 } 51 55 … … 467 471 if (ua_cfg->nameserver_count) { 468 472 #if PJSIP_HAS_RESOLVER 469 pj_dns_resolver *resv;470 473 unsigned i; 471 474 472 475 /* Create DNS resolver */ 473 status = pjsip_endpt_create_resolver(pjsua_var.endpt, &resv); 476 status = pjsip_endpt_create_resolver(pjsua_var.endpt, 477 &pjsua_var.resolver); 474 478 PJ_ASSERT_RETURN(status == PJ_SUCCESS, status); 475 479 476 480 /* Configure nameserver for the DNS resolver */ 477 status = pj_dns_resolver_set_ns(resv, ua_cfg->nameserver_count, 481 status = pj_dns_resolver_set_ns(pjsua_var.resolver, 482 ua_cfg->nameserver_count, 478 483 ua_cfg->nameserver, NULL); 479 484 if (status != PJ_SUCCESS) { … … 483 488 484 489 /* Set this DNS resolver to be used by the SIP resolver */ 485 status = pjsip_endpt_set_resolver(pjsua_var.endpt, resv);490 status = pjsip_endpt_set_resolver(pjsua_var.endpt, pjsua_var.resolver); 486 491 if (status != PJ_SUCCESS) { 487 492 pjsua_perror(THIS_FILE, "Error setting DNS resolver", status); … … 551 556 552 557 558 /* Start resolving STUN server */ 559 status = pjsua_resolve_stun_server(PJ_FALSE); 560 if (status != PJ_SUCCESS && status != PJ_EPENDING) { 561 pjsua_perror(THIS_FILE, "Error resolving STUN server", status); 562 return status; 563 } 564 553 565 /* Initialize PJSUA media subsystem */ 554 566 status = pjsua_media_subsys_init(media_cfg); … … 636 648 pj_gettimeofday(&now); 637 649 } while (PJ_TIME_VAL_LT(now, timeout)); 650 } 651 652 /* 653 * Resolve STUN server. 654 */ 655 pj_status_t pjsua_resolve_stun_server(pj_bool_t wait) 656 { 657 if (pjsua_var.stun_status == PJ_EUNKNOWN) { 658 /* Initialize STUN configuration */ 659 pj_stun_config_init(&pjsua_var.stun_cfg, &pjsua_var.cp.factory, 0, 660 pjsip_endpt_get_ioqueue(pjsua_var.endpt), 661 pjsip_endpt_get_timer_heap(pjsua_var.endpt)); 662 663 /* Start STUN server resolution */ 664 /* For now just do DNS A resolution */ 665 666 if (pjsua_var.ua_cfg.stun_srv.slen == 0) { 667 pjsua_var.stun_status = PJ_SUCCESS; 668 } else { 669 pj_hostent he; 670 671 pjsua_var.stun_status = 672 pj_gethostbyname(&pjsua_var.ua_cfg.stun_srv, &he); 673 674 if (pjsua_var.stun_status == PJ_SUCCESS) { 675 pj_sockaddr_in_init(&pjsua_var.stun_srv.ipv4, NULL, 0); 676 pjsua_var.stun_srv.ipv4.sin_addr = *(pj_in_addr*)he.h_addr; 677 pjsua_var.stun_srv.ipv4.sin_port = pj_htons((pj_uint16_t)3478); 678 } 679 } 680 return pjsua_var.stun_status; 681 682 } else if (pjsua_var.stun_status == PJ_EPENDING) { 683 /* STUN server resolution has been started, wait for the 684 * result. 685 */ 686 pj_assert(!"Should not happen"); 687 return PJ_EBUG; 688 689 } else { 690 /* STUN server has been resolved, return the status */ 691 return pjsua_var.stun_status; 692 } 638 693 } 639 694 … … 820 875 static pj_status_t create_sip_udp_sock(pj_in_addr bound_addr, 821 876 int port, 822 pj_bool_t use_stun,823 const pjsua_stun_config *stun_param,824 877 pj_sock_t *p_sock, 825 878 pj_sockaddr_in *p_pub_addr) 826 879 { 827 pjsua_stun_config stun; 880 char ip_addr[32]; 881 pj_str_t stun_srv; 828 882 pj_sock_t sock; 829 883 pj_status_t status; 884 885 /* Make sure STUN server resolution has completed */ 886 status = pjsua_resolve_stun_server(PJ_TRUE); 887 if (status != PJ_SUCCESS) { 888 pjsua_perror(THIS_FILE, "Error resolving STUN server", status); 889 return status; 890 } 830 891 831 892 status = pj_sock_socket(PJ_AF_INET, PJ_SOCK_DGRAM, 0, &sock); … … 857 918 } 858 919 859 /* Copy and normalize STUN param */ 860 if (use_stun) { 861 pj_memcpy(&stun, stun_param, sizeof(*stun_param)); 862 pjsua_normalize_stun_config(&stun); 920 if (pjsua_var.stun_srv.addr.sa_family != 0) { 921 pj_ansi_strcpy(ip_addr,pj_inet_ntoa(pjsua_var.stun_srv.ipv4.sin_addr)); 922 stun_srv = pj_str(ip_addr); 863 923 } else { 864 pj_bzero(&stun, sizeof(pjsua_stun_config));924 stun_srv.slen = 0; 865 925 } 866 926 … … 868 928 * the name of local host. 869 929 */ 870 if (stun .stun_srv1.slen) {930 if (stun_srv.slen) { 871 931 /* 872 932 * STUN is specified, resolve the address with STUN. 873 933 */ 874 934 status = pjstun_get_mapped_addr(&pjsua_var.cp.factory, 1, &sock, 875 &stun.stun_srv1, 876 stun.stun_port1, 877 &stun.stun_srv2, 878 stun.stun_port2, 879 p_pub_addr); 935 &stun_srv, 3478, 936 &stun_srv, 3478, 937 p_pub_addr); 880 938 if (status != PJ_SUCCESS) { 881 939 pjsua_perror(THIS_FILE, "Error resolving with STUN", status); … … 987 1045 */ 988 1046 status = create_sip_udp_sock(bound_addr.sin_addr, cfg->port, 989 cfg->use_stun, &cfg->stun_config,990 1047 &sock, &pub_addr); 991 1048 if (status != PJ_SUCCESS)
Note: See TracChangeset
for help on using the changeset viewer.