Пример #1
0
void
log_request(struct url *url)
{
	int	custom_port = 0;

	switch (url->scheme) {
	case HTTP:
		custom_port = strcmp(url->port, "80") ? 1 : 0;
		break;
	case HTTPS:
		custom_port = strcmp(url->port, "443") ? 1 : 0;
		break;
	case FTP:
		custom_port = strcmp(url->port, "21") ? 1 : 0;
		break;
	}

	if (proxy)
		log_info("Requesting %s://%s%s%s%s\n"
		    " (via %s://%s%s%s)",
		    scheme_str(url->scheme),
		    url->host,
		    custom_port ? ":" : "",
		    custom_port ? url->port : "",
		    url->path ? url->path : "",

		    /* via proxy part */
		    (proxy->scheme == HTTP) ? "http" : "https",
		    proxy->host,
		    proxy->port[0] ? ":" : "",
		    proxy->port[0] ? proxy->port : "");
	else
		log_info("Requesting %s://%s%s%s%s\n",
		    scheme_str(url->scheme),
		    url->host,
		    custom_port ? ":" : "",
		    custom_port ? url->port : "",
		    url->path ? url->path : "");
}
Пример #2
0
Файл: url.c Проект: AndreRH/wine
/**************************************************************************
 *          WsEncodeUrl		[webservices.@]
 */
HRESULT WINAPI WsEncodeUrl( const WS_URL *base, ULONG flags, WS_HEAP *heap, WS_STRING *ret,
                            WS_ERROR *error )
{
    static const WCHAR fmtW[] = {':','%','u',0};
    ULONG len = 0, len_scheme, len_enc, ret_size;
    const WS_HTTP_URL *url = (const WS_HTTP_URL *)base;
    const WCHAR *scheme;
    WCHAR *str, *p, *q;
    ULONG port = 0;
    HRESULT hr;

    TRACE( "%p %08x %p %p %p\n", base, flags, heap, ret, error );
    if (error) FIXME( "ignoring error parameter\n" );

    if (!url || !heap || !ret) return E_INVALIDARG;
    if (flags)
    {
        FIXME( "unimplemented flags %08x\n", flags );
        return E_NOTIMPL;
    }
    if (!(scheme = scheme_str( url->url.scheme, &len_scheme ))) return WS_E_INVALID_FORMAT;
    len = len_scheme + 3; /* '://' */
    len += 6; /* ':65535' */

    if ((hr = url_encode_size( url->host.chars, url->host.length, "", &len_enc )) != S_OK)
        return hr;
    len += len_enc;

    if ((hr = url_encode_size( url->path.chars, url->path.length, "/", &len_enc )) != S_OK)
        return hr;
    len += len_enc;

    if ((hr = url_encode_size( url->query.chars, url->query.length, "/?", &len_enc )) != S_OK)
        return hr;
    len += len_enc + 1; /* '?' */

    if ((hr = url_encode_size( url->fragment.chars, url->fragment.length, "/?", &len_enc )) != S_OK)
        return hr;
    len += len_enc + 1; /* '#' */

    ret_size = len * sizeof(WCHAR);
    if (!(str = ws_alloc( heap, ret_size ))) return WS_E_QUOTA_EXCEEDED;

    memcpy( str, scheme, len_scheme * sizeof(WCHAR) );
    p = str + len_scheme;
    p[0] = ':';
    p[1] = p[2] = '/';
    p += 3;

    if ((hr = url_encode( url->host.chars, url->host.length, p, "", &len_enc )) != S_OK)
        goto error;
    p += len_enc;

    if (url->portAsString.length)
    {
        q = url->portAsString.chars;
        len = url->portAsString.length;
        while (len && isdigitW( *q ))
        {
            if ((port = port * 10 + *q - '0') > 65535)
            {
                hr = WS_E_INVALID_FORMAT;
                goto error;
            }
            q++; len--;
        }
        if (url->port && port != url->port)
        {
            hr = E_INVALIDARG;
            goto error;
        }
    } else port = url->port;

    if (port == default_port( url->url.scheme )) port = 0;
    if (port)
    {
        WCHAR buf[7];
        len = sprintfW( buf, fmtW, port );
        memcpy( p, buf, len * sizeof(WCHAR) );
        p += len;
    }

    if ((hr = url_encode( url->path.chars, url->path.length, p, "/", &len_enc )) != S_OK)
        goto error;
    p += len_enc;

    if (url->query.length)
    {
        *p++ = '?';
        if ((hr = url_encode( url->query.chars, url->query.length, p, "/?", &len_enc )) != S_OK)
            goto error;
        p += len_enc;
    }

    if (url->fragment.length)
    {
        *p++ = '#';
        if ((hr = url_encode( url->fragment.chars, url->fragment.length, p, "/?", &len_enc )) != S_OK)
            goto error;
        p += len_enc;
    }

    ret->length = p - str;
    ret->chars  = str;
    return S_OK;

error:
    ws_free( heap, str, ret_size );
    return hr;
}