PJ_DEF(pj_status_t) pjsip_get_dest_info(const pjsip_uri *target_uri,
				 	const pjsip_uri *request_uri,
				 	pj_pool_t *pool,
				 	pjsip_host_info *dest_info)
{
    /* The target URI must be a SIP/SIPS URL so we can resolve it's address.
     * Otherwise we're in trouble (i.e. there's no host part in tel: URL).
     */
    pj_bzero(dest_info, sizeof(*dest_info));

    /* When request URI uses sips scheme, TLS must always be used regardless
     * of the target scheme or transport type (see ticket #1740).
     */
    if (PJSIP_URI_SCHEME_IS_SIPS(target_uri) || 
	(pjsip_cfg()->endpt.disable_tls_switch == 0 && request_uri &&
	 PJSIP_URI_SCHEME_IS_SIPS(request_uri)))
    {
	pjsip_uri *uri = (pjsip_uri*) target_uri;
	const pjsip_sip_uri *url=(const pjsip_sip_uri*)pjsip_uri_get_uri(uri);
	unsigned flag;

	if (!PJSIP_URI_SCHEME_IS_SIPS(target_uri)) {
	    PJ_LOG(4,(THIS_FILE, "Automatic switch to TLS transport as "
				 "request-URI uses ""sips"" scheme."));
	}

	dest_info->flag |= (PJSIP_TRANSPORT_SECURE | PJSIP_TRANSPORT_RELIABLE);
	if (url->maddr_param.slen)
	    pj_strdup(pool, &dest_info->addr.host, &url->maddr_param);
	else
	    pj_strdup(pool, &dest_info->addr.host, &url->host);
        dest_info->addr.port = url->port;
	dest_info->type = 
            pjsip_transport_get_type_from_name(&url->transport_param);
	/* Double-check that the transport parameter match.
	 * Sample case:     sips:host;transport=tcp
	 * See https://trac.pjsip.org/repos/ticket/1319
	 */
	flag = pjsip_transport_get_flag_from_type(dest_info->type);
	if ((flag & dest_info->flag) != dest_info->flag) {
	    pjsip_transport_type_e t;

	    t = pjsip_transport_get_type_from_flag(dest_info->flag);
	    if (t != PJSIP_TRANSPORT_UNSPECIFIED)
		dest_info->type = t;
	}

    } else if (PJSIP_URI_SCHEME_IS_SIP(target_uri)) {
	pjsip_uri *uri = (pjsip_uri*) target_uri;
	const pjsip_sip_uri *url=(const pjsip_sip_uri*)pjsip_uri_get_uri(uri);
	if (url->maddr_param.slen)
	    pj_strdup(pool, &dest_info->addr.host, &url->maddr_param);
	else
	    pj_strdup(pool, &dest_info->addr.host, &url->host);
	dest_info->addr.port = url->port;
	dest_info->type = 
            pjsip_transport_get_type_from_name(&url->transport_param);
	dest_info->flag = 
	    pjsip_transport_get_flag_from_type(dest_info->type);
    } else {
	/* Should have never reached here; app should have configured route
	 * set when sending to tel: URI
        pj_assert(!"Unsupported URI scheme!");
	 */
	PJ_TODO(SUPPORT_REQUEST_ADDR_RESOLUTION_FOR_TEL_URI);
	return PJSIP_ENOROUTESET;
    }

    /* Handle IPv6 (http://trac.pjsip.org/repos/ticket/861) */
    if (dest_info->type != PJSIP_TRANSPORT_UNSPECIFIED && 
	pj_strchr(&dest_info->addr.host, ':'))
    {
	dest_info->type = (pjsip_transport_type_e)
			  ((int)dest_info->type | PJSIP_TRANSPORT_IPV6);
    }

    return PJ_SUCCESS;
}
PJ_DEF(pj_status_t) pjsip_get_dest_info(const pjsip_uri *target_uri,
				 	const pjsip_uri *request_uri,
				 	pj_pool_t *pool,
				 	pjsip_host_info *dest_info)
{
     
    pj_bzero(dest_info, sizeof(*dest_info));

     
    if (PJSIP_URI_SCHEME_IS_SIPS(target_uri) || 
	(pjsip_cfg()->endpt.disable_tls_switch == 0 && request_uri &&
	 PJSIP_URI_SCHEME_IS_SIPS(request_uri)))
    {
	pjsip_uri *uri = (pjsip_uri*) target_uri;
	const pjsip_sip_uri *url=(const pjsip_sip_uri*)pjsip_uri_get_uri(uri);
	unsigned flag;

	if (!PJSIP_URI_SCHEME_IS_SIPS(target_uri)) {
	    PJ_LOG(4,(THIS_FILE, "Automatic switch to TLS transport as "
				 "request-URI uses ""sips"" scheme."));
	}

	dest_info->flag |= (PJSIP_TRANSPORT_SECURE | PJSIP_TRANSPORT_RELIABLE);
	if (url->maddr_param.slen)
	    pj_strdup(pool, &dest_info->addr.host, &url->maddr_param);
	else
	    pj_strdup(pool, &dest_info->addr.host, &url->host);
        dest_info->addr.port = url->port;
	dest_info->type = 
            pjsip_transport_get_type_from_name(&url->transport_param);
	 
	flag = pjsip_transport_get_flag_from_type(dest_info->type);
	if ((flag & dest_info->flag) != dest_info->flag) {
	    pjsip_transport_type_e t;

	    t = pjsip_transport_get_type_from_flag(dest_info->flag);
	    if (t != PJSIP_TRANSPORT_UNSPECIFIED)
		dest_info->type = t;
	}

    } else if (PJSIP_URI_SCHEME_IS_SIP(target_uri)) {
	pjsip_uri *uri = (pjsip_uri*) target_uri;
	const pjsip_sip_uri *url=(const pjsip_sip_uri*)pjsip_uri_get_uri(uri);
	if (url->maddr_param.slen)
	    pj_strdup(pool, &dest_info->addr.host, &url->maddr_param);
	else
	    pj_strdup(pool, &dest_info->addr.host, &url->host);
	dest_info->addr.port = url->port;
	dest_info->type = 
            pjsip_transport_get_type_from_name(&url->transport_param);
	dest_info->flag = 
	    pjsip_transport_get_flag_from_type(dest_info->type);
    } else {
	 
	PJ_TODO(SUPPORT_REQUEST_ADDR_RESOLUTION_FOR_TEL_URI);
	return PJSIP_ENOROUTESET;
    }

     
    if (dest_info->type != PJSIP_TRANSPORT_UNSPECIFIED && 
	pj_strchr(&dest_info->addr.host, ':'))
    {
	dest_info->type = (pjsip_transport_type_e)
			  ((int)dest_info->type | PJSIP_TRANSPORT_IPV6);
    }

    return PJ_SUCCESS;
}