- Timestamp:
- Aug 7, 2012 2:18:15 AM (12 years ago)
- Location:
- pjproject/trunk
- Files:
-
- 11 edited
Legend:
- Unmodified
- Added
- Removed
-
pjproject/trunk/pjlib/include/pj/addr_resolv.h
r3553 r4218 118 118 119 119 /** 120 * Get the interface IP address to send data to the specified destination. 121 * 122 * @param af The desired address family to query. Valid values 123 * are pj_AF_INET() or pj_AF_INET6(). 124 * @param dst The destination host. 125 * @param itf_addr On successful resolution, the address family and address 126 * part of this socket address will be filled up with the host 127 * IP address, in network byte order. Other parts of the socket 128 * address should be ignored. 129 * @param allow_resolve If \a dst may contain hostname (instead of IP 130 * address), specify whether hostname resolution should 131 * be performed. If not, default interface address will 132 * be returned. 133 * @param p_dst_addr If not NULL, it will be filled with the IP address of 134 * the destination host. 135 * 136 * @return PJ_SUCCESS on success, or the appropriate error code. 137 */ 138 PJ_DECL(pj_status_t) pj_getipinterface(int af, 139 const pj_str_t *dst, 140 pj_sockaddr *itf_addr, 141 pj_bool_t allow_resolve, 142 pj_sockaddr *p_dst_addr); 143 144 /** 120 145 * Get the IP address of the default interface. Default interface is the 121 146 * interface of the default route. -
pjproject/trunk/pjlib/src/pj/sock_common.c
r3841 r4218 957 957 } 958 958 959 /* Get the default IP interface */ 960 PJ_DEF(pj_status_t) pj_getdefaultipinterface(int af, pj_sockaddr *addr) 961 { 959 /* Get IP interface for sending to the specified destination */ 960 PJ_DEF(pj_status_t) pj_getipinterface(int af, 961 const pj_str_t *dst, 962 pj_sockaddr *itf_addr, 963 pj_bool_t allow_resolve, 964 pj_sockaddr *p_dst_addr) 965 { 966 pj_sockaddr dst_addr; 962 967 pj_sock_t fd; 963 pj_str_t cp;964 pj_sockaddr a;965 968 int len; 966 969 pj_uint8_t zero[64]; 967 970 pj_status_t status; 968 971 969 addr->addr.sa_family = (pj_uint16_t)af; 970 972 pj_sockaddr_init(af, &dst_addr, NULL, 53); 973 status = pj_inet_pton(af, dst, pj_sockaddr_get_addr(&dst_addr)); 974 if (status != PJ_SUCCESS) { 975 /* "dst" is not an IP address. */ 976 if (allow_resolve) { 977 status = pj_sockaddr_init(af, &dst_addr, dst, 53); 978 } else { 979 pj_str_t cp; 980 981 if (af == PJ_AF_INET) { 982 cp = pj_str("1.1.1.1"); 983 } else { 984 cp = pj_str("1::1"); 985 } 986 status = pj_sockaddr_init(af, &dst_addr, &cp, 53); 987 } 988 989 if (status != PJ_SUCCESS) 990 return status; 991 } 992 993 /* Create UDP socket and connect() to the destination IP */ 971 994 status = pj_sock_socket(af, pj_SOCK_DGRAM(), 0, &fd); 972 995 if (status != PJ_SUCCESS) { 973 996 return status; 974 997 } 998 999 status = pj_sock_connect(fd, &dst_addr, pj_sockaddr_get_len(&dst_addr)); 1000 if (status != PJ_SUCCESS) { 1001 pj_sock_close(fd); 1002 return status; 1003 } 1004 1005 len = sizeof(*itf_addr); 1006 status = pj_sock_getsockname(fd, itf_addr, &len); 1007 if (status != PJ_SUCCESS) { 1008 pj_sock_close(fd); 1009 return status; 1010 } 1011 1012 pj_sock_close(fd); 1013 1014 /* Check that the address returned is not zero */ 1015 pj_bzero(zero, sizeof(zero)); 1016 if (pj_memcmp(pj_sockaddr_get_addr(itf_addr), zero, 1017 pj_sockaddr_get_addr_len(itf_addr))==0) 1018 { 1019 return PJ_ENOTFOUND; 1020 } 1021 1022 if (p_dst_addr) 1023 *p_dst_addr = dst_addr; 1024 1025 return PJ_SUCCESS; 1026 } 1027 1028 /* Get the default IP interface */ 1029 PJ_DEF(pj_status_t) pj_getdefaultipinterface(int af, pj_sockaddr *addr) 1030 { 1031 pj_str_t cp; 975 1032 976 1033 if (af == PJ_AF_INET) { … … 979 1036 cp = pj_str("1::1"); 980 1037 } 981 status = pj_sockaddr_init(af, &a, &cp, 53); 982 if (status != PJ_SUCCESS) { 983 pj_sock_close(fd); 984 return status; 985 } 986 987 status = pj_sock_connect(fd, &a, pj_sockaddr_get_len(&a)); 988 if (status != PJ_SUCCESS) { 989 pj_sock_close(fd); 990 return status; 991 } 992 993 len = sizeof(a); 994 status = pj_sock_getsockname(fd, &a, &len); 995 if (status != PJ_SUCCESS) { 996 pj_sock_close(fd); 997 return status; 998 } 999 1000 pj_sock_close(fd); 1001 1002 /* Check that the address returned is not zero */ 1003 pj_bzero(zero, sizeof(zero)); 1004 if (pj_memcmp(pj_sockaddr_get_addr(&a), zero, 1005 pj_sockaddr_get_addr_len(&a))==0) 1006 { 1007 return PJ_ENOTFOUND; 1008 } 1009 1010 pj_sockaddr_copy_addr(addr, &a); 1011 1012 /* Success */ 1013 return PJ_SUCCESS; 1038 1039 return pj_getipinterface(af, &cp, addr, PJ_FALSE, NULL); 1014 1040 } 1015 1041 -
pjproject/trunk/pjsip-apps/src/pjsua/pjsua_app.c
r4216 r4218 225 225 puts (""); 226 226 puts ("SIP Account options:"); 227 puts (" --use-ims Enable 3GPP/IMS related settings on this account");228 #if defined(PJMEDIA_HAS_SRTP) && (PJMEDIA_HAS_SRTP != 0)229 puts (" --use-srtp=N Use SRTP? 0:disabled, 1:optional, 2:mandatory,");230 puts (" 3:optional by duplicating media offer (def:0)");231 puts (" --srtp-secure=N SRTP require secure SIP? 0:no, 1:tls, 2:sips (def:1)");232 #endif233 227 puts (" --registrar=url Set the URL of registrar server"); 234 228 puts (" --id=url Set the URL of local ID (used in From header)"); 229 puts (" --realm=string Set realm"); 230 puts (" --username=string Set authentication username"); 231 puts (" --password=string Set authentication password"); 235 232 puts (" --contact=url Optionally override the Contact information"); 236 233 puts (" --contact-params=S Append the specified parameters S in Contact header"); … … 244 241 puts (" --reg-use-proxy=N Control the use of proxy settings in REGISTER."); 245 242 puts (" 0=no proxy, 1=outbound only, 2=acc only, 3=all (default)"); 246 puts (" --realm=string Set realm");247 puts (" --username=string Set authentication username");248 puts (" --password=string Set authentication password");249 243 puts (" --publish Send presence PUBLISH for this account"); 250 244 puts (" --mwi Subscribe to message summary/waiting indication"); 245 puts (" --use-ims Enable 3GPP/IMS related settings on this account"); 246 #if defined(PJMEDIA_HAS_SRTP) && (PJMEDIA_HAS_SRTP != 0) 247 puts (" --use-srtp=N Use SRTP? 0:disabled, 1:optional, 2:mandatory,"); 248 puts (" 3:optional by duplicating media offer (def:0)"); 249 puts (" --srtp-secure=N SRTP require secure SIP? 0:no, 1:tls, 2:sips (def:1)"); 250 #endif 251 251 puts (" --use-100rel Require reliable provisional response (100rel)"); 252 252 puts (" --use-timer=N Use SIP session timers? (default=1)"); … … 258 258 puts (" --auto-update-nat=N Where N is 0 or 1 to enable/disable SIP traversal behind"); 259 259 puts (" symmetric NAT (default 1)"); 260 puts (" --disable-stun Disable STUN for this account"); 260 261 puts (" --next-cred Add another credentials"); 261 262 puts (""); … … 590 591 #endif 591 592 OPT_AUTO_UPDATE_NAT,OPT_USE_COMPACT_FORM,OPT_DIS_CODEC, 592 OPT_ NO_FORCE_LR,593 OPT_DISABLE_STUN, OPT_NO_FORCE_LR, 593 594 OPT_TIMER, OPT_TIMER_SE, OPT_TIMER_MIN_SE, 594 595 OPT_VIDEO, OPT_EXTRA_AUDIO, … … 630 631 { "contact-uri-params",1,0, OPT_CONTACT_URI_PARAMS}, 631 632 { "auto-update-nat", 1, 0, OPT_AUTO_UPDATE_NAT}, 633 { "disable-stun",0,0, OPT_DISABLE_STUN}, 632 634 { "use-compact-form", 0, 0, OPT_USE_COMPACT_FORM}, 633 635 { "accept-redirect", 1, 0, OPT_ACCEPT_REDIRECT}, … … 1022 1024 break; 1023 1025 1026 case OPT_DISABLE_STUN: 1027 cur_acc->sip_stun_use = PJSUA_STUN_USE_DISABLED; 1028 cur_acc->media_stun_use = PJSUA_STUN_USE_DISABLED; 1029 break; 1030 1024 1031 case OPT_USE_COMPACT_FORM: 1025 1032 /* enable compact form - from Ticket #342 */ … … 1172 1179 1173 1180 case OPT_USE_ICE: 1174 cfg->media_cfg.enable_ice = PJ_TRUE; 1181 cfg->media_cfg.enable_ice = 1182 cur_acc->ice_cfg.enable_ice = PJ_TRUE; 1175 1183 break; 1176 1184 1177 1185 case OPT_ICE_REGULAR: 1178 cfg->media_cfg.ice_opt.aggressive = PJ_FALSE; 1186 cfg->media_cfg.ice_opt.aggressive = 1187 cur_acc->ice_cfg.ice_opt.aggressive = PJ_FALSE; 1179 1188 break; 1180 1189 1181 1190 case OPT_USE_TURN: 1182 cfg->media_cfg.enable_turn = PJ_TRUE; 1191 cfg->media_cfg.enable_turn = 1192 cur_acc->turn_cfg.enable_turn = PJ_TRUE; 1183 1193 break; 1184 1194 1185 1195 case OPT_ICE_MAX_HOSTS: 1186 cfg->media_cfg.ice_max_host_cands = my_atoi(pj_optarg); 1196 cfg->media_cfg.ice_max_host_cands = 1197 cur_acc->ice_cfg.ice_max_host_cands = my_atoi(pj_optarg); 1187 1198 break; 1188 1199 1189 1200 case OPT_ICE_NO_RTCP: 1190 cfg->media_cfg.ice_no_rtcp = PJ_TRUE; 1201 cfg->media_cfg.ice_no_rtcp = 1202 cur_acc->ice_cfg.ice_no_rtcp = PJ_TRUE; 1191 1203 break; 1192 1204 1193 1205 case OPT_TURN_SRV: 1194 cfg->media_cfg.turn_server = pj_str(pj_optarg); 1206 cfg->media_cfg.turn_server = 1207 cur_acc->turn_cfg.turn_server = pj_str(pj_optarg); 1195 1208 break; 1196 1209 1197 1210 case OPT_TURN_TCP: 1198 cfg->media_cfg.turn_conn_type = PJ_TURN_TP_TCP; 1211 cfg->media_cfg.turn_conn_type = 1212 cur_acc->turn_cfg.turn_conn_type = PJ_TURN_TP_TCP; 1199 1213 break; 1200 1214 1201 1215 case OPT_TURN_USER: 1202 cfg->media_cfg.turn_auth_cred.type = PJ_STUN_AUTH_CRED_STATIC; 1203 cfg->media_cfg.turn_auth_cred.data.static_cred.realm = pj_str("*"); 1204 cfg->media_cfg.turn_auth_cred.data.static_cred.username = pj_str(pj_optarg); 1216 cfg->media_cfg.turn_auth_cred.type = 1217 cur_acc->turn_cfg.turn_auth_cred.type = PJ_STUN_AUTH_CRED_STATIC; 1218 cfg->media_cfg.turn_auth_cred.data.static_cred.realm = 1219 cur_acc->turn_cfg.turn_auth_cred.data.static_cred.realm = pj_str("*"); 1220 cfg->media_cfg.turn_auth_cred.data.static_cred.username = 1221 cur_acc->turn_cfg.turn_auth_cred.data.static_cred.username = pj_str(pj_optarg); 1205 1222 break; 1206 1223 1207 1224 case OPT_TURN_PASSWD: 1208 cfg->media_cfg.turn_auth_cred.data.static_cred.data_type = PJ_STUN_PASSWD_PLAIN; 1209 cfg->media_cfg.turn_auth_cred.data.static_cred.data = pj_str(pj_optarg); 1225 cfg->media_cfg.turn_auth_cred.data.static_cred.data_type = 1226 cur_acc->turn_cfg.turn_auth_cred.data.static_cred.data_type = PJ_STUN_PASSWD_PLAIN; 1227 cfg->media_cfg.turn_auth_cred.data.static_cred.data = 1228 cur_acc->turn_cfg.turn_auth_cred.data.static_cred.data = pj_str(pj_optarg); 1210 1229 break; 1211 1230 … … 1576 1595 { 1577 1596 acfg->cred_count++; 1597 } 1598 1599 if (acfg->ice_cfg.enable_ice) { 1600 acfg->ice_cfg_use = PJSUA_ICE_CONFIG_USE_CUSTOM; 1601 } 1602 if (acfg->turn_cfg.enable_turn) { 1603 acfg->turn_cfg_use = PJSUA_TURN_CONFIG_USE_CUSTOM; 1578 1604 } 1579 1605 … … 1772 1798 if (acc_cfg->mwi_enabled) 1773 1799 pj_strcat2(result, "--mwi\n"); 1800 1801 if (acc_cfg->sip_stun_use != PJSUA_STUN_USE_DEFAULT || 1802 acc_cfg->media_stun_use != PJSUA_STUN_USE_DEFAULT) 1803 { 1804 pj_strcat2(result, "--disable-stun\n"); 1805 } 1806 1807 /* Media Transport*/ 1808 if (acc_cfg->ice_cfg.enable_ice) 1809 pj_strcat2(result, "--use-ice\n"); 1810 1811 if (acc_cfg->ice_cfg.ice_opt.aggressive == PJ_FALSE) 1812 pj_strcat2(result, "--ice-regular\n"); 1813 1814 if (acc_cfg->turn_cfg.enable_turn) 1815 pj_strcat2(result, "--use-turn\n"); 1816 1817 if (acc_cfg->ice_cfg.ice_max_host_cands >= 0) { 1818 pj_ansi_sprintf(line, "--ice_max_host_cands %d\n", 1819 acc_cfg->ice_cfg.ice_max_host_cands); 1820 pj_strcat2(result, line); 1821 } 1822 1823 if (acc_cfg->ice_cfg.ice_no_rtcp) 1824 pj_strcat2(result, "--ice-no-rtcp\n"); 1825 1826 if (acc_cfg->turn_cfg.turn_server.slen) { 1827 pj_ansi_sprintf(line, "--turn-srv %.*s\n", 1828 (int)acc_cfg->turn_cfg.turn_server.slen, 1829 acc_cfg->turn_cfg.turn_server.ptr); 1830 pj_strcat2(result, line); 1831 } 1832 1833 if (acc_cfg->turn_cfg.turn_conn_type == PJ_TURN_TP_TCP) 1834 pj_strcat2(result, "--turn-tcp\n"); 1835 1836 if (acc_cfg->turn_cfg.turn_auth_cred.data.static_cred.username.slen) { 1837 pj_ansi_sprintf(line, "--turn-user %.*s\n", 1838 (int)acc_cfg->turn_cfg.turn_auth_cred.data.static_cred.username.slen, 1839 acc_cfg->turn_cfg.turn_auth_cred.data.static_cred.username.ptr); 1840 pj_strcat2(result, line); 1841 } 1842 1843 if (acc_cfg->turn_cfg.turn_auth_cred.data.static_cred.data.slen) { 1844 pj_ansi_sprintf(line, "--turn-passwd %.*s\n", 1845 (int)acc_cfg->turn_cfg.turn_auth_cred.data.static_cred.data.slen, 1846 acc_cfg->turn_cfg.turn_auth_cred.data.static_cred.data.ptr); 1847 pj_strcat2(result, line); 1848 } 1774 1849 } 1775 1850 … … 1967 2042 } 1968 2043 #endif 1969 1970 /* Media Transport*/1971 if (config->media_cfg.enable_ice)1972 pj_strcat2(&cfg, "--use-ice\n");1973 1974 if (config->media_cfg.ice_opt.aggressive == PJ_FALSE)1975 pj_strcat2(&cfg, "--ice-regular\n");1976 1977 if (config->media_cfg.enable_turn)1978 pj_strcat2(&cfg, "--use-turn\n");1979 1980 if (config->media_cfg.ice_max_host_cands >= 0) {1981 pj_ansi_sprintf(line, "--ice_max_host_cands %d\n",1982 config->media_cfg.ice_max_host_cands);1983 pj_strcat2(&cfg, line);1984 }1985 1986 if (config->media_cfg.ice_no_rtcp)1987 pj_strcat2(&cfg, "--ice-no-rtcp\n");1988 1989 if (config->media_cfg.turn_server.slen) {1990 pj_ansi_sprintf(line, "--turn-srv %.*s\n",1991 (int)config->media_cfg.turn_server.slen,1992 config->media_cfg.turn_server.ptr);1993 pj_strcat2(&cfg, line);1994 }1995 1996 if (config->media_cfg.turn_conn_type == PJ_TURN_TP_TCP)1997 pj_strcat2(&cfg, "--turn-tcp\n");1998 1999 if (config->media_cfg.turn_auth_cred.data.static_cred.username.slen) {2000 pj_ansi_sprintf(line, "--turn-user %.*s\n",2001 (int)config->media_cfg.turn_auth_cred.data.static_cred.username.slen,2002 config->media_cfg.turn_auth_cred.data.static_cred.username.ptr);2003 pj_strcat2(&cfg, line);2004 }2005 2006 if (config->media_cfg.turn_auth_cred.data.static_cred.data.slen) {2007 pj_ansi_sprintf(line, "--turn-passwd %.*s\n",2008 (int)config->media_cfg.turn_auth_cred.data.static_cred.data.slen,2009 config->media_cfg.turn_auth_cred.data.static_cred.data.ptr);2010 pj_strcat2(&cfg, line);2011 }2012 2044 2013 2045 /* Media */ -
pjproject/trunk/pjsip/include/pjsip/sip_transport.h
r4173 r4218 1077 1077 * the transport type in the request. 1078 1078 * 1079 * @see pjsip_tpmgr_find_local_addr2() 1080 * 1079 1081 * @param tpmgr The transport manager. 1080 1082 * @param pool Pool to allocate memory for the IP address. … … 1092 1094 pj_str_t *ip_addr, 1093 1095 int *port); 1096 1097 /** 1098 * Parameter for pjsip_tpmgr_find_local_addr2() function. 1099 */ 1100 typedef struct pjsip_tpmgr_fla2_param 1101 { 1102 /** 1103 * Specify transport type to use. This must be set. 1104 */ 1105 pjsip_transport_type_e tp_type; 1106 1107 /** 1108 * Optional pointer to preferred transport, if any. 1109 */ 1110 const pjsip_tpselector *tp_sel; 1111 1112 /** 1113 * Destination host, if known. The destination host is needed 1114 * if \a local_if field below is set. 1115 */ 1116 pj_str_t dst_host; 1117 1118 /** 1119 * Specify if the function should return which local interface 1120 * to use for the specified destination in \a dst_host. By definition, 1121 * the returned address will always be local interface address. 1122 */ 1123 pj_bool_t local_if; 1124 1125 /** 1126 * The returned address. 1127 */ 1128 pj_str_t ret_addr; 1129 1130 /** 1131 * The returned port. 1132 */ 1133 pj_uint16_t ret_port; 1134 1135 /** 1136 * Returned pointer to the transport. Only set if local_if is set. 1137 */ 1138 const void *ret_tp; 1139 1140 } pjsip_tpmgr_fla2_param; 1141 1142 /** 1143 * Initialize with default values. 1144 * 1145 * @param prm The parameter to be initialized. 1146 */ 1147 PJ_DECL(void) pjsip_tpmgr_fla2_param_default(pjsip_tpmgr_fla2_param *prm); 1148 1149 /** 1150 * Find out the appropriate local address info (IP address and port) to 1151 * advertise in Contact or Via header header based on the remote address 1152 * to be contacted. The local address info would be the address name of the 1153 * transport or listener which will be used to send the request. 1154 * 1155 * @see pjsip_tpmgr_find_local_addr() 1156 * 1157 * @param tpmgr The transport manager. 1158 * @param pool Pool to allocate memory for the IP address. 1159 * @param param Function input and output parameters. 1160 * 1161 * @return PJ_SUCCESS, or the appropriate error code. 1162 */ 1163 PJ_DECL(pj_status_t) pjsip_tpmgr_find_local_addr2(pjsip_tpmgr *tpmgr, 1164 pj_pool_t *pool, 1165 pjsip_tpmgr_fla2_param *prm); 1094 1166 1095 1167 /** -
pjproject/trunk/pjsip/include/pjsua-lib/pjsua.h
r4212 r4218 2568 2568 2569 2569 /** 2570 * This enumeration controls the use of STUN in the account. 2571 */ 2572 typedef enum pjsua_stun_use 2573 { 2574 /** 2575 * Follow the default setting in the global \a pjsua_config. 2576 */ 2577 PJSUA_STUN_USE_DEFAULT, 2578 2579 /** 2580 * Disable STUN. If STUN is not enabled in the global \a pjsua_config, 2581 * this setting has no effect. 2582 */ 2583 PJSUA_STUN_USE_DISABLED 2584 2585 } pjsua_stun_use; 2586 2587 /** 2588 * This enumeration controls the use of ICE settings in the account. 2589 */ 2590 typedef enum pjsua_ice_config_use 2591 { 2592 /** 2593 * Use the default settings in the global \a pjsua_media_config. 2594 */ 2595 PJSUA_ICE_CONFIG_USE_DEFAULT, 2596 2597 /** 2598 * Use the custom \a pjsua_ice_config setting in the account. 2599 */ 2600 PJSUA_ICE_CONFIG_USE_CUSTOM 2601 2602 } pjsua_ice_config_use; 2603 2604 /** 2605 * This enumeration controls the use of TURN settings in the account. 2606 */ 2607 typedef enum pjsua_turn_config_use 2608 { 2609 /** 2610 * Use the default setting in the global \a pjsua_media_config. 2611 */ 2612 PJSUA_TURN_CONFIG_USE_DEFAULT, 2613 2614 /** 2615 * Use the custom \a pjsua_turn_config setting in the account. 2616 */ 2617 PJSUA_TURN_CONFIG_USE_CUSTOM 2618 2619 } pjsua_turn_config_use; 2620 2621 /** 2622 * ICE setting. This setting is used in the pjsua_acc_config. 2623 */ 2624 typedef struct pjsua_ice_config 2625 { 2626 /** 2627 * Enable ICE. 2628 */ 2629 pj_bool_t enable_ice; 2630 2631 /** 2632 * Set the maximum number of host candidates. 2633 * 2634 * Default: -1 (maximum not set) 2635 */ 2636 int ice_max_host_cands; 2637 2638 /** 2639 * ICE session options. 2640 */ 2641 pj_ice_sess_options ice_opt; 2642 2643 /** 2644 * Disable RTCP component. 2645 * 2646 * Default: no 2647 */ 2648 pj_bool_t ice_no_rtcp; 2649 2650 } pjsua_ice_config; 2651 2652 /** 2653 * TURN setting. This setting is used in the pjsua_acc_config. 2654 */ 2655 typedef struct pjsua_turn_config 2656 { 2657 /** 2658 * Enable TURN candidate in ICE. 2659 */ 2660 pj_bool_t enable_turn; 2661 2662 /** 2663 * Specify TURN domain name or host name, in in "DOMAIN:PORT" or 2664 * "HOST:PORT" format. 2665 */ 2666 pj_str_t turn_server; 2667 2668 /** 2669 * Specify the connection type to be used to the TURN server. Valid 2670 * values are PJ_TURN_TP_UDP or PJ_TURN_TP_TCP. 2671 * 2672 * Default: PJ_TURN_TP_UDP 2673 */ 2674 pj_turn_tp_type turn_conn_type; 2675 2676 /** 2677 * Specify the credential to authenticate with the TURN server. 2678 */ 2679 pj_stun_auth_cred turn_auth_cred; 2680 2681 } pjsua_turn_config; 2682 2683 /** 2570 2684 * This structure describes account configuration to be specified when 2571 2685 * adding a new account with #pjsua_acc_add(). Application MUST initialize … … 2968 3082 2969 3083 /** 3084 * Control the use of STUN for the SIP signaling. 3085 * 3086 * Default: PJSUA_STUN_USE_DEFAULT 3087 */ 3088 pjsua_stun_use sip_stun_use; 3089 3090 /** 3091 * Control the use of STUN for the media transports. 3092 * 3093 * Default: PJSUA_STUN_USE_DEFAULT 3094 */ 3095 pjsua_stun_use media_stun_use; 3096 3097 /** 3098 * Control the use of ICE in the account. By default, the settings in the 3099 * \a pjsua_media_config will be used. 3100 * 3101 * Default: PJSUA_ICE_CONFIG_USE_DEFAULT 3102 */ 3103 pjsua_ice_config_use ice_cfg_use; 3104 3105 /** 3106 * The custom ICE setting for this account. This setting will only be 3107 * used if \a ice_cfg_use is set to PJSUA_ICE_CONFIG_USE_CUSTOM 3108 */ 3109 pjsua_ice_config ice_cfg; 3110 3111 /** 3112 * Control the use of TURN in the account. By default, the settings in the 3113 * \a pjsua_media_config will be used 3114 * 3115 * Default: PJSUA_TURN_CONFIG_USE_DEFAULT 3116 */ 3117 pjsua_turn_config_use turn_cfg_use; 3118 3119 /** 3120 * The custom TURN setting for this account. This setting will only be 3121 * used if \a turn_cfg_use is set to PJSUA_TURN_CONFIG_USE_CUSTOM 3122 */ 3123 pjsua_turn_config turn_cfg; 3124 3125 /** 2970 3126 * Specify whether secure media transport should be used for this account. 2971 3127 * Valid values are PJMEDIA_SRTP_DISABLED, PJMEDIA_SRTP_OPTIONAL, and … … 2974 3130 * Default: #PJSUA_DEFAULT_USE_SRTP 2975 3131 */ 2976 pjmedia_srtp_use use_srtp;3132 pjmedia_srtp_use use_srtp; 2977 3133 2978 3134 /** … … 3070 3226 } pjsua_acc_config; 3071 3227 3228 3229 /** 3230 * Initialize ICE config from a media config. If the \a pool argument 3231 * is NULL, a simple memcpy() will be used. 3232 * 3233 * @param pool Memory to duplicate strings. 3234 * @param dst Destination config. 3235 * @param src Source config. 3236 */ 3237 PJ_DECL(void) pjsua_ice_config_from_media_config(pj_pool_t *pool, 3238 pjsua_ice_config *dst, 3239 const pjsua_media_config *src); 3240 3241 /** 3242 * Clone. If the \a pool argument is NULL, a simple memcpy() will be used. 3243 * 3244 * @param pool Memory to duplicate strings. 3245 * @param dst Destination config. 3246 * @param src Source config. 3247 */ 3248 PJ_DECL(void) pjsua_ice_config_dup( pj_pool_t *pool, 3249 pjsua_ice_config *dst, 3250 const pjsua_ice_config *src); 3251 3252 /** 3253 * Initialize TURN config from a media config. If the \a pool argument 3254 * is NULL, a simple memcpy() will be used. 3255 * 3256 * @param pool Memory to duplicate strings. 3257 * @param dst Destination config. 3258 * @param src Source config. 3259 */ 3260 PJ_DECL(void) pjsua_turn_config_from_media_config(pj_pool_t *pool, 3261 pjsua_turn_config *dst, 3262 const pjsua_media_config *src); 3263 3264 /** 3265 * Clone. If the \a pool argument is NULL, a simple memcpy() will be used. 3266 * 3267 * @param pool Memory to duplicate strings. 3268 * @param dst Destination config. 3269 * @param src Source config. 3270 */ 3271 PJ_DECL(void) pjsua_turn_config_dup(pj_pool_t *pool, 3272 pjsua_turn_config *dst, 3273 const pjsua_turn_config *src); 3072 3274 3073 3275 /** -
pjproject/trunk/pjsip/include/pjsua-lib/pjsua_internal.h
r4175 r4218 584 584 pj_status_t normalize_route_uri(pj_pool_t *pool, pj_str_t *uri); 585 585 586 /* acc use stun? */ 587 pj_bool_t pjsua_sip_acc_is_using_stun(pjsua_acc_id acc_id); 588 589 /* Get local transport address suitable to be used for Via or Contact address 590 * to send request to the specified destination URI. 591 */ 592 pj_status_t pjsua_acc_get_uac_addr(pjsua_acc_id acc_id, 593 pj_pool_t *pool, 594 const pj_str_t *dst_uri, 595 pjsip_host_port *addr, 596 pjsip_transport_type_e *p_tp_type, 597 int *p_secure, 598 const void **p_tp); 599 586 600 /** 587 601 * Handle incoming invite request. -
pjproject/trunk/pjsip/src/pjsip/sip_transport.c
r4094 r4218 25 25 #include <pjsip/sip_errno.h> 26 26 #include <pjsip/sip_module.h> 27 #include <pj/addr_resolv.h> 27 28 #include <pj/except.h> 28 29 #include <pj/os.h> … … 1081 1082 } 1082 1083 1084 PJ_DECL(void) pjsip_tpmgr_fla2_param_default(pjsip_tpmgr_fla2_param *prm) 1085 { 1086 pj_bzero(prm, sizeof(*prm)); 1087 } 1083 1088 1084 1089 /***************************************************************************** … … 1139 1144 } 1140 1145 1141 1146 /* Get the interface to send packet to the specified address */ 1147 static pj_status_t get_net_interface(pjsip_transport_type_e tp_type, 1148 const pj_str_t *dst, 1149 pj_str_t *itf_str_addr) 1150 { 1151 int af; 1152 pj_sockaddr itf_addr; 1153 pj_status_t status; 1154 1155 af = (tp_type & PJSIP_TRANSPORT_IPV6)? PJ_AF_INET6 : PJ_AF_INET; 1156 status = pj_getipinterface(af, dst, &itf_addr, PJ_FALSE, NULL); 1157 if (status != PJ_SUCCESS) 1158 return status; 1159 1160 /* Print address */ 1161 pj_sockaddr_print(&itf_addr, itf_str_addr->ptr, 1162 PJ_INET6_ADDRSTRLEN, 0); 1163 itf_str_addr->slen = pj_ansi_strlen(itf_str_addr->ptr); 1164 1165 return PJ_SUCCESS; 1166 } 1142 1167 1143 1168 /* … … 1150 1175 * the transport type in the request. 1151 1176 */ 1177 PJ_DEF(pj_status_t) pjsip_tpmgr_find_local_addr2(pjsip_tpmgr *tpmgr, 1178 pj_pool_t *pool, 1179 pjsip_tpmgr_fla2_param *prm) 1180 { 1181 char tmp_buf[PJ_INET6_ADDRSTRLEN+10]; 1182 pj_str_t tmp_str = { tmp_buf, 0 }; 1183 pj_status_t status = PJSIP_EUNSUPTRANSPORT; 1184 unsigned flag; 1185 1186 /* Sanity checks */ 1187 PJ_ASSERT_RETURN(tpmgr && pool && prm, PJ_EINVAL); 1188 1189 prm->ret_addr.slen = 0; 1190 prm->ret_port = 0; 1191 prm->ret_tp = NULL; 1192 1193 flag = pjsip_transport_get_flag_from_type(prm->tp_type); 1194 1195 if (prm->tp_sel && prm->tp_sel->type == PJSIP_TPSELECTOR_TRANSPORT && 1196 prm->tp_sel->u.transport) 1197 { 1198 const pjsip_transport *tp = prm->tp_sel->u.transport; 1199 if (prm->local_if) { 1200 status = get_net_interface(tp->key.type, &prm->dst_host, 1201 &tmp_str); 1202 if (status != PJ_SUCCESS) 1203 goto on_return; 1204 pj_strdup(pool, &prm->ret_addr, &tmp_str); 1205 prm->ret_port = pj_sockaddr_get_port(&tp->local_addr); 1206 prm->ret_tp = tp; 1207 } else { 1208 pj_strdup(pool, &prm->ret_addr, &tp->local_name.host); 1209 prm->ret_port = tp->local_name.port; 1210 } 1211 status = PJ_SUCCESS; 1212 1213 } else if (prm->tp_sel && prm->tp_sel->type == PJSIP_TPSELECTOR_LISTENER && 1214 prm->tp_sel->u.listener) 1215 { 1216 if (prm->local_if) { 1217 status = get_net_interface(prm->tp_sel->u.listener->type, 1218 &prm->dst_host, &tmp_str); 1219 if (status != PJ_SUCCESS) 1220 goto on_return; 1221 pj_strdup(pool, &prm->ret_addr, &tmp_str); 1222 } else { 1223 pj_strdup(pool, &prm->ret_addr, 1224 &prm->tp_sel->u.listener->addr_name.host); 1225 } 1226 prm->ret_port = prm->tp_sel->u.listener->addr_name.port; 1227 status = PJ_SUCCESS; 1228 1229 } else if ((flag & PJSIP_TRANSPORT_DATAGRAM) != 0) { 1230 pj_sockaddr remote; 1231 int addr_len; 1232 pjsip_transport *tp; 1233 1234 pj_bzero(&remote, sizeof(remote)); 1235 if (prm->tp_type & PJSIP_TRANSPORT_IPV6) { 1236 addr_len = sizeof(pj_sockaddr_in6); 1237 remote.addr.sa_family = pj_AF_INET6(); 1238 } else { 1239 addr_len = sizeof(pj_sockaddr_in); 1240 remote.addr.sa_family = pj_AF_INET(); 1241 } 1242 1243 status = pjsip_tpmgr_acquire_transport(tpmgr, prm->tp_type, &remote, 1244 addr_len, NULL, &tp); 1245 1246 if (status == PJ_SUCCESS) { 1247 if (prm->local_if) { 1248 status = get_net_interface(tp->key.type, &prm->dst_host, 1249 &tmp_str); 1250 if (status != PJ_SUCCESS) 1251 goto on_return; 1252 pj_strdup(pool, &prm->ret_addr, &tmp_str); 1253 prm->ret_port = pj_sockaddr_get_port(&tp->local_addr); 1254 prm->ret_tp = tp; 1255 } else { 1256 pj_strdup(pool, &prm->ret_addr, &tp->local_name.host); 1257 prm->ret_port = tp->local_name.port; 1258 } 1259 1260 pjsip_transport_dec_ref(tp); 1261 } 1262 1263 } else { 1264 /* For connection oriented transport, enum the factories */ 1265 pjsip_tpfactory *f; 1266 1267 pj_lock_acquire(tpmgr->lock); 1268 1269 f = tpmgr->factory_list.next; 1270 while (f != &tpmgr->factory_list) { 1271 if (f->type == prm->tp_type) 1272 break; 1273 f = f->next; 1274 } 1275 1276 if (f != &tpmgr->factory_list) { 1277 if (prm->local_if) { 1278 status = get_net_interface(f->type, &prm->dst_host, 1279 &tmp_str); 1280 if (status != PJ_SUCCESS) 1281 goto on_return; 1282 pj_strdup(pool, &prm->ret_addr, &tmp_str); 1283 } else { 1284 pj_strdup(pool, &prm->ret_addr, &f->addr_name.host); 1285 } 1286 prm->ret_port = f->addr_name.port; 1287 status = PJ_SUCCESS; 1288 } 1289 pj_lock_release(tpmgr->lock); 1290 } 1291 1292 on_return: 1293 return status; 1294 } 1295 1152 1296 PJ_DEF(pj_status_t) pjsip_tpmgr_find_local_addr( pjsip_tpmgr *tpmgr, 1153 1297 pj_pool_t *pool, … … 1157 1301 int *port) 1158 1302 { 1159 pj_status_t status = PJSIP_EUNSUPTRANSPORT; 1160 unsigned flag; 1161 1162 /* Sanity checks */ 1163 PJ_ASSERT_RETURN(tpmgr && pool && ip_addr && port, PJ_EINVAL); 1164 1165 ip_addr->slen = 0; 1166 *port = 0; 1167 1168 flag = pjsip_transport_get_flag_from_type(type); 1169 1170 if (sel && sel->type == PJSIP_TPSELECTOR_TRANSPORT && 1171 sel->u.transport) 1172 { 1173 pj_strdup(pool, ip_addr, &sel->u.transport->local_name.host); 1174 *port = sel->u.transport->local_name.port; 1175 status = PJ_SUCCESS; 1176 1177 } else if (sel && sel->type == PJSIP_TPSELECTOR_LISTENER && 1178 sel->u.listener) 1179 { 1180 pj_strdup(pool, ip_addr, &sel->u.listener->addr_name.host); 1181 *port = sel->u.listener->addr_name.port; 1182 status = PJ_SUCCESS; 1183 1184 } else if ((flag & PJSIP_TRANSPORT_DATAGRAM) != 0) { 1185 1186 pj_sockaddr remote; 1187 int addr_len; 1188 pjsip_transport *tp; 1189 1190 pj_bzero(&remote, sizeof(remote)); 1191 if (type & PJSIP_TRANSPORT_IPV6) { 1192 addr_len = sizeof(pj_sockaddr_in6); 1193 remote.addr.sa_family = pj_AF_INET6(); 1194 } else { 1195 addr_len = sizeof(pj_sockaddr_in); 1196 remote.addr.sa_family = pj_AF_INET(); 1197 } 1198 1199 status = pjsip_tpmgr_acquire_transport(tpmgr, type, &remote, 1200 addr_len, NULL, &tp); 1201 1202 if (status == PJ_SUCCESS) { 1203 pj_strdup(pool, ip_addr, &tp->local_name.host); 1204 *port = tp->local_name.port; 1205 status = PJ_SUCCESS; 1206 1207 pjsip_transport_dec_ref(tp); 1208 } 1209 1210 } else { 1211 /* For connection oriented transport, enum the factories */ 1212 pjsip_tpfactory *f; 1213 1214 pj_lock_acquire(tpmgr->lock); 1215 1216 f = tpmgr->factory_list.next; 1217 while (f != &tpmgr->factory_list) { 1218 if (f->type == type) 1219 break; 1220 f = f->next; 1221 } 1222 1223 if (f != &tpmgr->factory_list) { 1224 pj_strdup(pool, ip_addr, &f->addr_name.host); 1225 *port = f->addr_name.port; 1226 status = PJ_SUCCESS; 1227 } 1228 pj_lock_release(tpmgr->lock); 1229 } 1230 1231 return status; 1303 pjsip_tpmgr_fla2_param prm; 1304 pj_status_t status; 1305 1306 pjsip_tpmgr_fla2_param_default(&prm); 1307 prm.tp_type = type; 1308 prm.tp_sel = sel; 1309 1310 status = pjsip_tpmgr_find_local_addr2(tpmgr, pool, &prm); 1311 if (status != PJ_SUCCESS) 1312 return status; 1313 1314 *ip_addr = prm.ret_addr; 1315 *port = prm.ret_port; 1316 1317 return PJ_SUCCESS; 1232 1318 } 1233 1319 -
pjproject/trunk/pjsip/src/pjsua-lib/pjsua_acc.c
r4185 r4218 134 134 pjsua_transport_config_dup(pool, &dst->rtp_cfg, &src->rtp_cfg); 135 135 136 pjsua_ice_config_dup(pool, &dst->ice_cfg, &src->ice_cfg); 137 pjsua_turn_config_dup(pool, &dst->turn_cfg, &src->turn_cfg); 138 136 139 pj_strdup(pool, &dst->ka_data, &src->ka_data); 137 140 } … … 284 287 */ 285 288 #if PJSUA_ADD_ICE_TAGS 286 if ( pjsua_var.media_cfg.enable_ice) {289 if (acc_cfg->ice_cfg.enable_ice) { 287 290 unsigned new_len; 288 291 pj_str_t new_prm; … … 347 350 acc->rfc5626_regprm.slen = len; 348 351 } 352 } 353 354 /* If account's ICE and TURN customization is not set, then 355 * initialize it with the settings from the global media config. 356 */ 357 if (acc->cfg.ice_cfg_use == PJSUA_ICE_CONFIG_USE_DEFAULT) { 358 pjsua_ice_config_from_media_config(NULL, &acc->cfg.ice_cfg, 359 &pjsua_var.media_cfg); 360 } 361 if (acc->cfg.turn_cfg_use == PJSUA_TURN_CONFIG_USE_DEFAULT) { 362 pjsua_turn_config_from_media_config(NULL, &acc->cfg.turn_cfg, 363 &pjsua_var.media_cfg); 349 364 } 350 365 … … 1153 1168 } 1154 1169 1170 /* Video settings */ 1171 acc->cfg.vid_in_auto_show = cfg->vid_in_auto_show; 1172 acc->cfg.vid_out_auto_transmit = cfg->vid_out_auto_transmit; 1173 acc->cfg.vid_wnd_flags = cfg->vid_wnd_flags; 1174 acc->cfg.vid_cap_dev = cfg->vid_cap_dev; 1175 acc->cfg.vid_rend_dev = cfg->vid_rend_dev; 1176 acc->cfg.vid_stream_rc_cfg = cfg->vid_stream_rc_cfg; 1177 1178 /* Media settings */ 1179 if (pj_stricmp(&acc->cfg.rtp_cfg.public_addr, &cfg->rtp_cfg.public_addr) || 1180 pj_stricmp(&acc->cfg.rtp_cfg.bound_addr, &cfg->rtp_cfg.bound_addr)) 1181 { 1182 pjsua_transport_config_dup(acc->pool, &acc->cfg.rtp_cfg, 1183 &cfg->rtp_cfg); 1184 } else { 1185 /* ..to save memory by not using the pool */ 1186 acc->cfg.rtp_cfg = cfg->rtp_cfg; 1187 } 1188 1189 /* STUN and Media customization */ 1190 if (acc->cfg.sip_stun_use != cfg->sip_stun_use) { 1191 acc->cfg.sip_stun_use = cfg->sip_stun_use; 1192 update_reg = PJ_TRUE; 1193 } 1194 acc->cfg.media_stun_use = cfg->media_stun_use; 1195 1196 /* ICE settings */ 1197 acc->cfg.ice_cfg_use = cfg->ice_cfg_use; 1198 switch (acc->cfg.ice_cfg_use) { 1199 case PJSUA_ICE_CONFIG_USE_DEFAULT: 1200 /* Copy ICE settings from media settings so that we don't need to 1201 * check the media config if we look for ICE config. 1202 */ 1203 pjsua_ice_config_from_media_config(NULL, &acc->cfg.ice_cfg, 1204 &pjsua_var.media_cfg); 1205 break; 1206 case PJSUA_ICE_CONFIG_USE_CUSTOM: 1207 pjsua_ice_config_dup(acc->pool, &acc->cfg.ice_cfg, &cfg->ice_cfg); 1208 break; 1209 } 1210 1211 /* TURN settings */ 1212 acc->cfg.turn_cfg_use = cfg->turn_cfg_use; 1213 switch (acc->cfg.turn_cfg_use) { 1214 case PJSUA_TURN_CONFIG_USE_DEFAULT: 1215 /* Copy TURN settings from media settings so that we don't need to 1216 * check the media config if we look for TURN config. 1217 */ 1218 pjsua_turn_config_from_media_config(NULL, &acc->cfg.turn_cfg, 1219 &pjsua_var.media_cfg); 1220 break; 1221 case PJSUA_TURN_CONFIG_USE_CUSTOM: 1222 pjsua_turn_config_dup(acc->pool, &acc->cfg.turn_cfg, 1223 &cfg->turn_cfg); 1224 break; 1225 } 1226 1227 acc->cfg.use_srtp = cfg->use_srtp; 1228 1229 /* Call hold type */ 1230 acc->cfg.call_hold_type = cfg->call_hold_type; 1231 1155 1232 /* Unregister first */ 1156 1233 if (unreg_first) { … … 1174 1251 pjsua_start_mwi(acc_id, PJ_TRUE); 1175 1252 } 1176 1177 /* Video settings */1178 acc->cfg.vid_in_auto_show = cfg->vid_in_auto_show;1179 acc->cfg.vid_out_auto_transmit = cfg->vid_out_auto_transmit;1180 acc->cfg.vid_wnd_flags = cfg->vid_wnd_flags;1181 acc->cfg.vid_cap_dev = cfg->vid_cap_dev;1182 acc->cfg.vid_rend_dev = cfg->vid_rend_dev;1183 1184 /* Call hold type */1185 acc->cfg.call_hold_type = cfg->call_hold_type;1186 1253 1187 1254 on_return: … … 1516 1583 char *tmp; 1517 1584 const char *beginquote, *endquote; 1585 char transport_param[32]; 1518 1586 int len; 1519 1587 … … 1526 1594 } 1527 1595 1596 /* Don't add transport parameter if it's UDP */ 1597 if (tp->key.type != PJSIP_TRANSPORT_UDP && 1598 tp->key.type != PJSIP_TRANSPORT_UDP6) 1599 { 1600 pj_ansi_snprintf(transport_param, sizeof(transport_param), 1601 ";transport=%s", 1602 pjsip_transport_get_type_name(tp->key.type)); 1603 } else { 1604 transport_param[0] = '\0'; 1605 } 1606 1528 1607 tmp = (char*) pj_pool_alloc(pool, PJSIP_MAX_URL_SIZE); 1529 1608 len = pj_ansi_snprintf(tmp, PJSIP_MAX_URL_SIZE, 1530 "<sip:%.*s%s%s%.*s%s:%d ;transport=%s%.*s%s>%.*s",1609 "<sip:%.*s%s%s%.*s%s:%d%s%.*s%s>%.*s", 1531 1610 (int)acc->user_part.slen, 1532 1611 acc->user_part.ptr, … … 1537 1616 endquote, 1538 1617 rport, 1539 t p->type_name,1618 transport_param, 1540 1619 (int)acc->cfg.contact_uri_params.slen, 1541 1620 acc->cfg.contact_uri_params.ptr, … … 2147 2226 } 2148 2227 2228 pj_bool_t pjsua_sip_acc_is_using_stun(pjsua_acc_id acc_id) 2229 { 2230 pjsua_acc *acc = &pjsua_var.acc[acc_id]; 2231 2232 return acc->cfg.sip_stun_use != PJSUA_STUN_USE_DISABLED && 2233 pjsua_var.ua_cfg.stun_srv_cnt != 0; 2234 } 2149 2235 2150 2236 /* … … 2154 2240 pj_bool_t renew) 2155 2241 { 2242 pjsua_acc *acc; 2156 2243 pj_status_t status = 0; 2157 2244 pjsip_tx_data *tdata = 0; … … 2166 2253 2167 2254 PJSUA_LOCK(); 2255 2256 acc = &pjsua_var.acc[acc_id]; 2168 2257 2169 2258 /* Cancel any re-registration timer */ … … 2233 2322 &pjsua_var.acc[acc_id].via_addr, 2234 2323 pjsua_var.acc[acc_id].via_tp); 2324 } else if (!pjsua_sip_acc_is_using_stun(acc_id)) { 2325 /* Choose local interface to use in Via if acc is not using 2326 * STUN 2327 */ 2328 pjsua_acc_get_uac_addr(acc_id, tdata->pool, 2329 &acc->cfg.reg_uri, 2330 &tdata->via_addr, 2331 NULL, NULL, 2332 &tdata->via_tp); 2235 2333 } 2236 2334 … … 2613 2711 } 2614 2712 2615 2616 PJ_DEF(pj_status_t) pjsua_acc_create_uac_contact( pj_pool_t *pool, 2617 pj_str_t *contact, 2618 pjsua_acc_id acc_id, 2619 const pj_str_t *suri) 2713 /* Get local transport address suitable to be used for Via or Contact address 2714 * to send request to the specified destination URI. 2715 */ 2716 pj_status_t pjsua_acc_get_uac_addr(pjsua_acc_id acc_id, 2717 pj_pool_t *pool, 2718 const pj_str_t *dst_uri, 2719 pjsip_host_port *addr, 2720 pjsip_transport_type_e *p_tp_type, 2721 int *secure, 2722 const void **p_tp) 2620 2723 { 2621 2724 pjsua_acc *acc; … … 2623 2726 pj_status_t status; 2624 2727 pjsip_transport_type_e tp_type = PJSIP_TRANSPORT_UNSPECIFIED; 2625 pj_str_t local_addr;2728 unsigned flag; 2626 2729 pjsip_tpselector tp_sel; 2627 unsigned flag; 2628 int secure; 2629 int local_port; 2630 const char *beginquote, *endquote; 2631 char transport_param[32]; 2632 const char *ob = ";ob"; 2633 2634 2730 pjsip_tpmgr *tpmgr; 2731 pjsip_tpmgr_fla2_param tfla2_prm; 2732 2635 2733 PJ_ASSERT_RETURN(pjsua_acc_is_valid(acc_id), PJ_EINVAL); 2636 2734 acc = &pjsua_var.acc[acc_id]; 2637 2735 2638 /* If force_contact is configured, then use use it */ 2639 if (acc->cfg.force_contact.slen) { 2640 *contact = acc->cfg.force_contact; 2641 return PJ_SUCCESS; 2642 } 2643 2644 /* If route-set is configured for the account, then URI is the 2736 /* If route-set is configured for the account, then URI is the 2645 2737 * first entry of the route-set. 2646 2738 */ 2647 2739 if (!pj_list_empty(&acc->route_set)) { 2648 sip_uri = (pjsip_sip_uri*) 2740 sip_uri = (pjsip_sip_uri*) 2649 2741 pjsip_uri_get_uri(acc->route_set.next->name_addr.uri); 2650 2742 } else { … … 2652 2744 pjsip_uri *uri; 2653 2745 2654 pj_strdup_with_null(pool, &tmp, suri);2746 pj_strdup_with_null(pool, &tmp, dst_uri); 2655 2747 2656 2748 uri = pjsip_parse_uri(pool, tmp.ptr, tmp.slen, 0); … … 2672 2764 } else 2673 2765 tp_type = pjsip_transport_get_type_from_name(&sip_uri->transport_param); 2674 2766 2675 2767 if (tp_type == PJSIP_TRANSPORT_UNSPECIFIED) 2676 2768 return PJSIP_EUNSUPTRANSPORT; … … 2683 2775 2684 2776 flag = pjsip_transport_get_flag_from_type(tp_type); 2685 secure = (flag & PJSIP_TRANSPORT_SECURE) != 0;2686 2777 2687 2778 /* Init transport selector. */ 2688 pjsua_init_tpselector( pjsua_var.acc[acc_id].cfg.transport_id, &tp_sel);2779 pjsua_init_tpselector(acc->cfg.transport_id, &tp_sel); 2689 2780 2690 2781 /* Get local address suitable to send request from */ 2691 status = pjsip_tpmgr_find_local_addr(pjsip_endpt_get_tpmgr(pjsua_var.endpt), 2692 pool, tp_type, &tp_sel, 2693 &local_addr, &local_port); 2782 pjsip_tpmgr_fla2_param_default(&tfla2_prm); 2783 tfla2_prm.tp_type = tp_type; 2784 tfla2_prm.tp_sel = &tp_sel; 2785 tfla2_prm.dst_host = sip_uri->host; 2786 tfla2_prm.local_if = (!pjsua_sip_acc_is_using_stun(acc_id) || 2787 (flag & PJSIP_TRANSPORT_RELIABLE)); 2788 2789 tpmgr = pjsip_endpt_get_tpmgr(pjsua_var.endpt); 2790 status = pjsip_tpmgr_find_local_addr2(tpmgr, pool, &tfla2_prm); 2791 if (status != PJ_SUCCESS) 2792 return status; 2793 2794 addr->host = tfla2_prm.ret_addr; 2795 addr->port = tfla2_prm.ret_port; 2796 2797 if (p_tp_type) 2798 *p_tp_type = tp_type; 2799 2800 if (secure) { 2801 *secure = (flag & PJSIP_TRANSPORT_SECURE) != 0; 2802 } 2803 2804 if (p_tp) 2805 *p_tp = tfla2_prm.ret_tp; 2806 2807 return PJ_SUCCESS; 2808 } 2809 2810 2811 PJ_DEF(pj_status_t) pjsua_acc_create_uac_contact( pj_pool_t *pool, 2812 pj_str_t *contact, 2813 pjsua_acc_id acc_id, 2814 const pj_str_t *suri) 2815 { 2816 pjsua_acc *acc; 2817 pj_status_t status; 2818 pjsip_transport_type_e tp_type; 2819 pjsip_host_port addr; 2820 int secure; 2821 const char *beginquote, *endquote; 2822 char transport_param[32]; 2823 const char *ob = ";ob"; 2824 2825 2826 PJ_ASSERT_RETURN(pjsua_acc_is_valid(acc_id), PJ_EINVAL); 2827 acc = &pjsua_var.acc[acc_id]; 2828 2829 /* If force_contact is configured, then use use it */ 2830 if (acc->cfg.force_contact.slen) { 2831 *contact = acc->cfg.force_contact; 2832 return PJ_SUCCESS; 2833 } 2834 2835 status = pjsua_acc_get_uac_addr(acc_id, pool, suri, &addr, 2836 &tp_type, &secure, NULL); 2694 2837 if (status != PJ_SUCCESS) 2695 2838 return status; … … 2726 2869 (acc->user_part.slen?"@":""), 2727 2870 beginquote, 2728 (int) local_addr.slen,2729 local_addr.ptr,2871 (int)addr.host.slen, 2872 addr.host.ptr, 2730 2873 endquote, 2731 local_port,2874 addr.port, 2732 2875 transport_param, 2733 2876 (int)acc->cfg.contact_uri_params.slen, … … 2761 2904 pj_str_t local_addr; 2762 2905 pjsip_tpselector tp_sel; 2906 pjsip_tpmgr *tpmgr; 2907 pjsip_tpmgr_fla2_param tfla2_prm; 2763 2908 unsigned flag; 2764 2909 int secure; … … 2848 2993 2849 2994 /* Get local address suitable to send request from */ 2850 status = pjsip_tpmgr_find_local_addr(pjsip_endpt_get_tpmgr(pjsua_var.endpt), 2851 pool, tp_type, &tp_sel, 2852 &local_addr, &local_port); 2995 pjsip_tpmgr_fla2_param_default(&tfla2_prm); 2996 tfla2_prm.tp_type = tp_type; 2997 tfla2_prm.tp_sel = &tp_sel; 2998 tfla2_prm.dst_host = sip_uri->host; 2999 tfla2_prm.local_if = (!pjsua_sip_acc_is_using_stun(acc_id) || 3000 (flag & PJSIP_TRANSPORT_RELIABLE)); 3001 3002 tpmgr = pjsip_endpt_get_tpmgr(pjsua_var.endpt); 3003 status = pjsip_tpmgr_find_local_addr2(tpmgr, pool, &tfla2_prm); 2853 3004 if (status != PJ_SUCCESS) 2854 3005 return status; 3006 3007 local_addr = tfla2_prm.ret_addr; 3008 local_port = tfla2_prm.ret_port; 3009 2855 3010 2856 3011 /* Enclose IPv6 address in square brackets */ -
pjproject/trunk/pjsip/src/pjsua-lib/pjsua_call.c
r4204 r4218 1183 1183 if (pjsua_var.acc[acc_id].cfg.require_100rel == PJSUA_100REL_MANDATORY) 1184 1184 options |= PJSIP_INV_REQUIRE_100REL; 1185 if (pjsua_var. media_cfg.enable_ice)1185 if (pjsua_var.acc[acc_id].cfg.ice_cfg.enable_ice) 1186 1186 options |= PJSIP_INV_SUPPORT_ICE; 1187 1187 if (pjsua_var.acc[acc_id].cfg.use_timer == PJSUA_SIP_TIMER_REQUIRED) -
pjproject/trunk/pjsip/src/pjsua-lib/pjsua_core.c
r4204 r4218 197 197 const pjsua_transport_config *src) 198 198 { 199 pj_memcpy(dst, src, sizeof(*src)); 200 pj_strdup(pool, &dst->public_addr, &src->public_addr); 201 pj_strdup(pool, &dst->bound_addr, &src->bound_addr); 202 } 203 204 PJ_DEF(void) pjsua_ice_config_from_media_config( pj_pool_t *pool, 205 pjsua_ice_config *dst, 206 const pjsua_media_config *src) 207 { 208 PJ_UNUSED_ARG(pool); 209 210 dst->enable_ice = src->enable_ice; 211 dst->ice_max_host_cands = src->ice_max_host_cands; 212 dst->ice_opt = src->ice_opt; 213 dst->ice_no_rtcp = src->ice_no_rtcp; 214 } 215 216 PJ_DEF(void) pjsua_ice_config_dup( pj_pool_t *pool, 217 pjsua_ice_config *dst, 218 const pjsua_ice_config *src) 219 { 199 220 PJ_UNUSED_ARG(pool); 200 221 pj_memcpy(dst, src, sizeof(*src)); 201 222 } 202 223 224 PJ_DEF(void) pjsua_turn_config_from_media_config(pj_pool_t *pool, 225 pjsua_turn_config *dst, 226 const pjsua_media_config *src) 227 { 228 dst->enable_turn = src->enable_turn; 229 dst->turn_conn_type = src->turn_conn_type; 230 if (pool == NULL) { 231 dst->turn_server = src->turn_server; 232 dst->turn_auth_cred = src->turn_auth_cred; 233 } else { 234 if (pj_stricmp(&dst->turn_server, &src->turn_server)) 235 pj_strdup(pool, &dst->turn_server, &src->turn_server); 236 pj_stun_auth_cred_dup(pool, &dst->turn_auth_cred, 237 &src->turn_auth_cred); 238 } 239 } 240 241 PJ_DEF(void) pjsua_turn_config_dup(pj_pool_t *pool, 242 pjsua_turn_config *dst, 243 const pjsua_turn_config *src) 244 { 245 pj_memcpy(dst, src, sizeof(*src)); 246 if (pool) { 247 pj_strdup(pool, &dst->turn_server, &src->turn_server); 248 pj_stun_auth_cred_dup(pool, &dst->turn_auth_cred, 249 &src->turn_auth_cred); 250 } 251 } 252 203 253 PJ_DEF(void) pjsua_acc_config_default(pjsua_acc_config *cfg) 204 254 { 255 pjsua_media_config med_cfg; 256 205 257 pj_bzero(cfg, sizeof(*cfg)); 206 258 … … 225 277 #endif 226 278 pjsua_transport_config_default(&cfg->rtp_cfg); 279 280 pjsua_media_config_default(&med_cfg); 281 pjsua_ice_config_from_media_config(NULL, &cfg->ice_cfg, &med_cfg); 282 pjsua_turn_config_from_media_config(NULL, &cfg->turn_cfg, &med_cfg); 283 227 284 cfg->use_srtp = pjsua_var.ua_cfg.use_srtp; 228 285 cfg->srtp_secure_signaling = pjsua_var.ua_cfg.srtp_secure_signaling; … … 2806 2863 for (i=0; i<pjsua_var.ua_cfg.max_calls; ++i) { 2807 2864 pjsua_call *call = &pjsua_var.calls[i]; 2865 pjsua_acc_config *acc_cfg; 2808 2866 pjmedia_transport *tp[PJSUA_MAX_CALL_MEDIA*2]; 2809 2867 unsigned tp_cnt = 0; … … 2831 2889 } 2832 2890 2891 acc_cfg = &pjsua_var.acc[call->acc_id].cfg; 2892 2833 2893 /* Dump the media transports in this call */ 2834 2894 for (j = 0; j < tp_cnt; ++j) { … … 2839 2899 pjmedia_transport_get_info(tp[j], &tpinfo); 2840 2900 PJ_LOG(3,(THIS_FILE, " %s: %s", 2841 ( pjsua_var.media_cfg.enable_ice ? "ICE" : "UDP"),2901 (acc_cfg->ice_cfg.enable_ice ? "ICE" : "UDP"), 2842 2902 pj_sockaddr_print(&tpinfo.sock_info.rtp_addr_name, 2843 2903 addr_buf, -
pjproject/trunk/pjsip/src/pjsua-lib/pjsua_media.c
r4197 r4218 166 166 167 167 /* Perform NAT detection */ 168 status = pjsua_detect_nat_type(); 169 if (status != PJ_SUCCESS) { 170 PJ_PERROR(1,(THIS_FILE, status, "NAT type detection failed")); 168 if (pjsua_var.ua_cfg.stun_srv_cnt) { 169 status = pjsua_detect_nat_type(); 170 if (status != PJ_SUCCESS) { 171 PJ_PERROR(1,(THIS_FILE, status, "NAT type detection failed")); 172 } 171 173 } 172 174 … … 227 229 * address via STUN. 228 230 */ 229 static pj_status_t create_rtp_rtcp_sock(const pjsua_transport_config *cfg, 231 static pj_status_t create_rtp_rtcp_sock(pjsua_call_media *call_med, 232 const pjsua_transport_config *cfg, 230 233 pjmedia_sock_info *skinfo) 231 234 { … … 241 244 242 245 /* Make sure STUN server resolution has completed */ 243 status = resolve_stun_server(PJ_TRUE); 244 if (status != PJ_SUCCESS) { 245 pjsua_perror(THIS_FILE, "Error resolving STUN server", status); 246 return status; 246 if (pjsua_sip_acc_is_using_stun(call_med->call->acc_id)) { 247 status = resolve_stun_server(PJ_TRUE); 248 if (status != PJ_SUCCESS) { 249 pjsua_perror(THIS_FILE, "Error resolving STUN server", status); 250 return status; 251 } 247 252 } 248 253 … … 319 324 * and make sure that the mapped RTCP port is adjacent with the RTP. 320 325 */ 321 if (pjsua_var.stun_srv.addr.sa_family != 0) { 326 if (pjsua_sip_acc_is_using_stun(call_med->call->acc_id) && 327 pjsua_var.stun_srv.addr.sa_family != 0) 328 { 322 329 char ip_addr[32]; 323 330 pj_str_t stun_srv; … … 441 448 pj_status_t status; 442 449 443 status = create_rtp_rtcp_sock(c fg, &skinfo);450 status = create_rtp_rtcp_sock(call_med, cfg, &skinfo); 444 451 if (status != PJ_SUCCESS) { 445 452 pjsua_perror(THIS_FILE, "Unable to create RTP/RTCP socket", … … 661 668 { 662 669 char stunip[PJ_INET6_ADDRSTRLEN]; 670 pjsua_acc_config *acc_cfg; 663 671 pj_ice_strans_cfg ice_cfg; 664 672 pjmedia_ice_cb ice_cb; … … 666 674 unsigned comp_cnt; 667 675 pj_status_t status; 676 677 acc_cfg = &pjsua_var.acc[call_med->call->acc_id].cfg; 668 678 669 679 /* Make sure STUN server resolution has completed */ … … 683 693 ice_cfg.resolver = pjsua_var.resolver; 684 694 685 ice_cfg.opt = pjsua_var.media_cfg.ice_opt;695 ice_cfg.opt = acc_cfg->ice_cfg.ice_opt; 686 696 687 697 /* Configure STUN settings */ … … 691 701 ice_cfg.stun.port = pj_sockaddr_get_port(&pjsua_var.stun_srv); 692 702 } 693 if ( pjsua_var.media_cfg.ice_max_host_cands >= 0)694 ice_cfg.stun.max_host_cands = pjsua_var.media_cfg.ice_max_host_cands;703 if (acc_cfg->ice_cfg.ice_max_host_cands >= 0) 704 ice_cfg.stun.max_host_cands = acc_cfg->ice_cfg.ice_max_host_cands; 695 705 696 706 /* Copy QoS setting to STUN setting */ … … 700 710 701 711 /* Configure TURN settings */ 702 if ( pjsua_var.media_cfg.enable_turn) {703 status = parse_host_port(& pjsua_var.media_cfg.turn_server,712 if (acc_cfg->turn_cfg.enable_turn) { 713 status = parse_host_port(&acc_cfg->turn_cfg.turn_server, 704 714 &ice_cfg.turn.server, 705 715 &ice_cfg.turn.port); … … 710 720 if (ice_cfg.turn.port == 0) 711 721 ice_cfg.turn.port = 3479; 712 ice_cfg.turn.conn_type = pjsua_var.media_cfg.turn_conn_type;722 ice_cfg.turn.conn_type = acc_cfg->turn_cfg.turn_conn_type; 713 723 pj_memcpy(&ice_cfg.turn.auth_cred, 714 & pjsua_var.media_cfg.turn_auth_cred,724 &acc_cfg->turn_cfg.turn_auth_cred, 715 725 sizeof(ice_cfg.turn.auth_cred)); 716 726 … … 731 741 732 742 comp_cnt = 1; 733 if (PJMEDIA_ADVERTISE_RTCP && ! pjsua_var.media_cfg.ice_no_rtcp)743 if (PJMEDIA_ADVERTISE_RTCP && !acc_cfg->ice_cfg.ice_no_rtcp) 734 744 ++comp_cnt; 735 745 … … 859 869 860 870 /* Create the transports */ 861 if (pjsua_var. media_cfg.enable_ice) {871 if (pjsua_var.ice_cfg.enable_ice) { 862 872 status = create_ice_media_transports(&cfg); 863 873 } else { … … 1245 1255 pjsua_set_media_tp_state(call_med, PJSUA_MED_TP_CREATING); 1246 1256 1247 if (pjsua_var. media_cfg.enable_ice) {1257 if (pjsua_var.acc[call_med->call->acc_id].cfg.ice_cfg.enable_ice) { 1248 1258 status = create_ice_media_transport(tcfg, call_med, async); 1249 1259 if (async && status == PJ_EPENDING) {
Note: See TracChangeset
for help on using the changeset viewer.