Changeset 4888
- Timestamp:
- Aug 18, 2014 8:54:43 AM (10 years ago)
- Location:
- pjproject/trunk/pjsip
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
pjproject/trunk/pjsip/include/pjsip/sip_util.h
r4347 r4888 372 372 pjsip_tx_data **p_tdata); 373 373 374 /** 375 * Get destination address and port and transport type information for the 376 * specified URI. 377 * 378 * @param target_uri The destination URI. 379 * @param request_uri Optional request URI to be considered. May be NULL. 380 * @param pool Pool to allocate memory from. 381 * @param dest_info To be filled with destination info. 382 * 383 * @return PJ_SUCCESS or the appropriate error code. 384 */ 385 PJ_DECL(pj_status_t) pjsip_get_dest_info(const pjsip_uri *target_uri, 386 const pjsip_uri *request_uri, 387 pj_pool_t *pool, 388 pjsip_host_info *dest_info); 374 389 375 390 /** -
pjproject/trunk/pjsip/include/pjsua-lib/pjsua.h
r4887 r4888 3056 3056 3057 3057 /** 3058 * Specify if source TCP port should be used as the initial Contact 3059 * address if TCP/TLS transport is used. Note that this feature will 3060 * be automatically turned off when nameserver is configured because 3061 * it may yield different destination address due to DNS SRV resolution. 3062 * Also some platforms are unable to report the local address of the 3063 * TCP socket when it is still connecting. In these cases, this 3064 * feature will also be turned off. 3065 * 3066 * Default: PJ_TRUE (yes). 3067 */ 3068 pj_bool_t contact_rewrite_use_src_port; 3069 3070 /** 3058 3071 * This option is used to overwrite the "sent-by" field of the Via header 3059 3072 * for outgoing messages with the same interface address as the one in -
pjproject/trunk/pjsip/src/pjsip/sip_util.c
r4770 r4888 802 802 803 803 /* Fill-up destination information from a target URI */ 804 static pj_status_t get_dest_info(const pjsip_uri *target_uri, 805 const pjsip_uri *request_uri,806 pj_pool_t *pool,807 pjsip_host_info *dest_info)804 PJ_DEF(pj_status_t) pjsip_get_dest_info(const pjsip_uri *target_uri, 805 const pjsip_uri *request_uri, 806 pj_pool_t *pool, 807 pjsip_host_info *dest_info) 808 808 { 809 809 /* The target URI must be a SIP/SIPS URL so we can resolve it's address. … … 908 908 } 909 909 910 return get_dest_info(target_uri, tdata->msg->line.req.uri,911 (pj_pool_t*)tdata->pool, dest_info);910 return pjsip_get_dest_info(target_uri, tdata->msg->line.req.uri, 911 (pj_pool_t*)tdata->pool, dest_info); 912 912 } 913 913 … … 1012 1012 1013 1013 /* Fill up the destination host/port from the URI. */ 1014 status = get_dest_info(target_uri, new_request_uri, tdata->pool,1015 dest_info);1014 status = pjsip_get_dest_info(target_uri, new_request_uri, tdata->pool, 1015 dest_info); 1016 1016 if (status != PJ_SUCCESS) 1017 1017 return status; … … 1510 1510 1511 1511 /* Build destination info. */ 1512 status = get_dest_info(uri, NULL, tdata->pool, &dest_info);1512 status = pjsip_get_dest_info(uri, NULL, tdata->pool, &dest_info); 1513 1513 if (status != PJ_SUCCESS) { 1514 1514 pjsip_tx_data_dec_ref(tdata); -
pjproject/trunk/pjsip/src/pjsua-lib/pjsua_acc.c
r4713 r4888 2934 2934 } 2935 2935 2936 /* 2937 * Internal: 2938 * determine if an address is a valid IP address, and if it is, 2939 * return the IP version (4 or 6). 2940 */ 2941 static int get_ip_addr_ver(const pj_str_t *host) 2942 { 2943 pj_in_addr dummy; 2944 pj_in6_addr dummy6; 2945 2946 /* First check with inet_aton() */ 2947 if (pj_inet_aton(host, &dummy) > 0) 2948 return 4; 2949 2950 /* Then check if this is an IPv6 address */ 2951 if (pj_inet_pton(pj_AF_INET6(), host, &dummy6) == PJ_SUCCESS) 2952 return 6; 2953 2954 /* Not an IP address */ 2955 return 0; 2956 } 2957 2936 2958 /* Get local transport address suitable to be used for Via or Contact address 2937 2959 * to send request to the specified destination URI. … … 3015 3037 return status; 3016 3038 3039 /* Set this as default return value. This may be changed below 3040 * for TCP/TLS 3041 */ 3017 3042 addr->host = tfla2_prm.ret_addr; 3018 3043 addr->port = tfla2_prm.ret_port; 3044 3045 /* For TCP/TLS, acc may request to specify source port */ 3046 if (acc->cfg.contact_rewrite_use_src_port) { 3047 pjsip_host_info dinfo; 3048 pjsip_transport *tp = NULL; 3049 pj_addrinfo ai; 3050 pj_bool_t log_written = PJ_FALSE; 3051 3052 status = pjsip_get_dest_info((pjsip_uri*)sip_uri, NULL, 3053 pool, &dinfo); 3054 3055 if (status==PJ_SUCCESS && (dinfo.flag & PJSIP_TRANSPORT_RELIABLE)==0) { 3056 /* Not TCP or TLS. No need to do this */ 3057 status = PJ_EINVALIDOP; 3058 log_written = PJ_TRUE; 3059 } 3060 3061 if (status==PJ_SUCCESS && 3062 get_ip_addr_ver(&dinfo.addr.host)==0 && 3063 pjsua_var.ua_cfg.nameserver_count) 3064 { 3065 /* If nameserver is configured, PJSIP will resolve destinations 3066 * by their DNS SRV record first. On the other hand, we will 3067 * resolve destination with DNS A record via pj_getaddrinfo(). 3068 * They may yield different IP addresses, hence causing different 3069 * TCP/TLS connection to be created and hence different source 3070 * address. 3071 */ 3072 PJ_LOG(4,(THIS_FILE, "Warning: cannot use source TCP/TLS socket" 3073 " address for Contact when nameserver is configured.")); 3074 status = PJ_ENOTSUP; 3075 log_written = PJ_TRUE; 3076 } 3077 3078 if (status == PJ_SUCCESS) { 3079 unsigned cnt=1; 3080 int af; 3081 3082 af = (dinfo.type & PJSIP_TRANSPORT_IPV6)? PJ_AF_INET6 : PJ_AF_INET; 3083 status = pj_getaddrinfo(af, &dinfo.addr.host, &cnt, &ai); 3084 } 3085 3086 if (status == PJ_SUCCESS) { 3087 int addr_len = pj_sockaddr_get_len(&ai.ai_addr); 3088 pj_uint16_t port = dinfo.addr.port; 3089 3090 if (port==0) { 3091 port = (dinfo.flag & PJSIP_TRANSPORT_SECURE) ? 5061 : 5060; 3092 } 3093 pj_sockaddr_set_port(&ai.ai_addr, port); 3094 status = pjsip_endpt_acquire_transport(pjsua_var.endpt, 3095 dinfo.type, 3096 &ai.ai_addr, 3097 addr_len, 3098 &tp_sel, &tp); 3099 } 3100 3101 if (status == PJ_SUCCESS && (tp->local_name.port == 0 || 3102 tp->local_name.host.slen==0 || 3103 *tp->local_name.host.ptr=='0')) 3104 { 3105 /* Trap zero port or "0.0.0.0" address. */ 3106 /* The TCP/TLS transport is still connecting and unfortunately 3107 * this OS doesn't report the bound local address in this state. 3108 */ 3109 PJ_LOG(4,(THIS_FILE, "Unable to get transport local port " 3110 "for Contact address (OS doesn't support)")); 3111 status = PJ_ENOTSUP; 3112 log_written = PJ_TRUE; 3113 } 3114 3115 if (status == PJ_SUCCESS) { 3116 /* Got the local transport address */ 3117 pj_strdup(pool, &addr->host, &tp->local_name.host); 3118 addr->port = tp->local_name.port; 3119 } 3120 3121 if (tp) { 3122 /* Here the transport's ref counter WILL reach zero. But the 3123 * transport will NOT get destroyed because it should have an 3124 * idle timer. 3125 */ 3126 pjsip_transport_dec_ref(tp); 3127 tp = NULL; 3128 } 3129 3130 if (status != PJ_SUCCESS && !log_written) { 3131 PJ_PERROR(4,(THIS_FILE, status, "Unable to use source local " 3132 "TCP socket address for Contact")); 3133 } 3134 status = PJ_SUCCESS; 3135 } 3019 3136 3020 3137 if (p_tp_type) -
pjproject/trunk/pjsip/src/pjsua-lib/pjsua_core.c
r4887 r4888 290 290 cfg->reg_retry_interval = PJSUA_REG_RETRY_INTERVAL; 291 291 cfg->contact_rewrite_method = PJSUA_CONTACT_REWRITE_METHOD; 292 cfg->contact_rewrite_use_src_port = PJ_TRUE; 292 293 cfg->use_rfc5626 = PJ_TRUE; 293 294 cfg->reg_use_proxy = PJSUA_REG_USE_OUTBOUND_PROXY |
Note: See TracChangeset
for help on using the changeset viewer.