2005-09-14 17:38:26 +02:00
|
|
|
/*
|
|
|
|
* Copyright 2005 Jacek Caban
|
2007-07-10 17:52:03 +02:00
|
|
|
* Copyright 2007 Misha Koshelev
|
2005-09-14 17:38:26 +02:00
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
2006-05-18 14:49:52 +02:00
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
2005-09-14 17:38:26 +02:00
|
|
|
*/
|
|
|
|
|
2015-03-26 15:29:22 +01:00
|
|
|
#define NONAMELESSUNION
|
|
|
|
|
2005-09-14 17:38:26 +02:00
|
|
|
#include "urlmon_main.h"
|
2007-12-13 20:26:51 +01:00
|
|
|
#include "wininet.h"
|
2005-09-14 17:38:26 +02:00
|
|
|
|
2010-10-06 21:37:27 +02:00
|
|
|
#define NO_SHLWAPI_REG
|
|
|
|
#include "shlwapi.h"
|
|
|
|
|
2005-09-14 17:38:26 +02:00
|
|
|
#include "wine/debug.h"
|
|
|
|
|
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(urlmon);
|
|
|
|
|
|
|
|
typedef struct {
|
2009-03-02 03:19:00 +01:00
|
|
|
Protocol base;
|
|
|
|
|
2019-06-03 21:50:16 +02:00
|
|
|
IUnknown IUnknown_inner;
|
2010-12-06 23:34:19 +01:00
|
|
|
IInternetProtocolEx IInternetProtocolEx_iface;
|
|
|
|
IInternetPriority IInternetPriority_iface;
|
|
|
|
IWinInetHttpInfo IWinInetHttpInfo_iface;
|
2005-11-09 11:28:26 +01:00
|
|
|
|
2009-01-11 21:19:46 +01:00
|
|
|
BOOL https;
|
2007-07-10 17:52:03 +02:00
|
|
|
IHttpNegotiate *http_negotiate;
|
2011-05-26 15:08:28 +02:00
|
|
|
WCHAR *full_header;
|
2009-03-02 03:21:07 +01:00
|
|
|
|
|
|
|
LONG ref;
|
2018-05-08 18:18:32 +02:00
|
|
|
IUnknown *outer;
|
2005-09-14 17:38:26 +02:00
|
|
|
} HttpProtocol;
|
|
|
|
|
2018-05-08 18:18:32 +02:00
|
|
|
static inline HttpProtocol *impl_from_IUnknown(IUnknown *iface)
|
|
|
|
{
|
2019-06-03 21:50:16 +02:00
|
|
|
return CONTAINING_RECORD(iface, HttpProtocol, IUnknown_inner);
|
2018-05-08 18:18:32 +02:00
|
|
|
}
|
|
|
|
|
2010-12-06 23:34:19 +01:00
|
|
|
static inline HttpProtocol *impl_from_IInternetProtocolEx(IInternetProtocolEx *iface)
|
|
|
|
{
|
|
|
|
return CONTAINING_RECORD(iface, HttpProtocol, IInternetProtocolEx_iface);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline HttpProtocol *impl_from_IInternetPriority(IInternetPriority *iface)
|
|
|
|
{
|
|
|
|
return CONTAINING_RECORD(iface, HttpProtocol, IInternetPriority_iface);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline HttpProtocol *impl_from_IWinInetHttpInfo(IWinInetHttpInfo *iface)
|
|
|
|
{
|
|
|
|
return CONTAINING_RECORD(iface, HttpProtocol, IWinInetHttpInfo_iface);
|
|
|
|
}
|
2009-02-26 01:47:24 +01:00
|
|
|
|
2020-12-03 00:32:46 +01:00
|
|
|
static const WCHAR default_headersW[] = L"Accept-Encoding: gzip, deflate";
|
2007-07-26 06:58:37 +02:00
|
|
|
|
2009-03-02 03:20:46 +01:00
|
|
|
static LPWSTR query_http_info(HttpProtocol *This, DWORD option)
|
|
|
|
{
|
|
|
|
LPWSTR ret = NULL;
|
|
|
|
DWORD len = 0;
|
|
|
|
BOOL res;
|
|
|
|
|
|
|
|
res = HttpQueryInfoW(This->base.request, option, NULL, &len, NULL);
|
|
|
|
if (!res && GetLastError() == ERROR_INSUFFICIENT_BUFFER) {
|
|
|
|
ret = heap_alloc(len);
|
|
|
|
res = HttpQueryInfoW(This->base.request, option, ret, &len, NULL);
|
|
|
|
}
|
|
|
|
if(!res) {
|
2022-02-18 09:18:16 +01:00
|
|
|
TRACE("HttpQueryInfoW(%ld) failed: %08lx\n", option, GetLastError());
|
2009-03-02 03:20:46 +01:00
|
|
|
heap_free(ret);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2012-06-12 10:35:52 +02:00
|
|
|
static inline BOOL set_security_flag(HttpProtocol *This, DWORD flags)
|
2011-01-09 06:28:54 +01:00
|
|
|
{
|
|
|
|
BOOL res;
|
|
|
|
|
2012-06-12 10:35:52 +02:00
|
|
|
res = InternetSetOptionW(This->base.request, INTERNET_OPTION_SECURITY_FLAGS, &flags, sizeof(flags));
|
2011-01-09 06:28:54 +01:00
|
|
|
if(!res)
|
2022-02-18 09:18:16 +01:00
|
|
|
ERR("Failed to set security flags: %lx\n", flags);
|
2011-01-09 06:28:54 +01:00
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline HRESULT internet_error_to_hres(DWORD error)
|
|
|
|
{
|
|
|
|
switch(error)
|
|
|
|
{
|
|
|
|
case ERROR_INTERNET_SEC_CERT_DATE_INVALID:
|
|
|
|
case ERROR_INTERNET_SEC_CERT_CN_INVALID:
|
|
|
|
case ERROR_INTERNET_INVALID_CA:
|
|
|
|
case ERROR_INTERNET_CLIENT_AUTH_CERT_NEEDED:
|
2012-06-01 16:41:55 +02:00
|
|
|
case ERROR_INTERNET_SEC_INVALID_CERT:
|
|
|
|
case ERROR_INTERNET_SEC_CERT_ERRORS:
|
|
|
|
case ERROR_INTERNET_SEC_CERT_REV_FAILED:
|
|
|
|
case ERROR_INTERNET_SEC_CERT_NO_REV:
|
|
|
|
case ERROR_INTERNET_SEC_CERT_REVOKED:
|
2011-01-09 06:28:54 +01:00
|
|
|
return INET_E_INVALID_CERTIFICATE;
|
|
|
|
case ERROR_INTERNET_HTTP_TO_HTTPS_ON_REDIR:
|
|
|
|
case ERROR_INTERNET_HTTPS_TO_HTTP_ON_REDIR:
|
|
|
|
case ERROR_HTTP_REDIRECT_NEEDS_CONFIRMATION:
|
|
|
|
return INET_E_REDIRECT_FAILED;
|
|
|
|
default:
|
|
|
|
return INET_E_DOWNLOAD_FAILURE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT handle_http_error(HttpProtocol *This, DWORD error)
|
|
|
|
{
|
|
|
|
IServiceProvider *serv_prov;
|
|
|
|
IWindowForBindingUI *wfb_ui;
|
|
|
|
IHttpSecurity *http_security;
|
|
|
|
BOOL security_problem;
|
2012-05-30 16:53:32 +02:00
|
|
|
DWORD dlg_flags;
|
|
|
|
HWND hwnd;
|
|
|
|
DWORD res;
|
2011-01-09 06:28:54 +01:00
|
|
|
HRESULT hres;
|
|
|
|
|
2022-02-18 09:18:16 +01:00
|
|
|
TRACE("(%p %lu)\n", This, error);
|
2012-06-11 16:14:45 +02:00
|
|
|
|
2011-01-09 06:28:54 +01:00
|
|
|
switch(error) {
|
|
|
|
case ERROR_INTERNET_SEC_CERT_DATE_INVALID:
|
|
|
|
case ERROR_INTERNET_SEC_CERT_CN_INVALID:
|
|
|
|
case ERROR_INTERNET_HTTP_TO_HTTPS_ON_REDIR:
|
|
|
|
case ERROR_INTERNET_HTTPS_TO_HTTP_ON_REDIR:
|
|
|
|
case ERROR_INTERNET_INVALID_CA:
|
|
|
|
case ERROR_INTERNET_CLIENT_AUTH_CERT_NEEDED:
|
2012-06-01 16:41:55 +02:00
|
|
|
case ERROR_INTERNET_SEC_INVALID_CERT:
|
|
|
|
case ERROR_INTERNET_SEC_CERT_ERRORS:
|
|
|
|
case ERROR_INTERNET_SEC_CERT_REV_FAILED:
|
|
|
|
case ERROR_INTERNET_SEC_CERT_NO_REV:
|
|
|
|
case ERROR_INTERNET_SEC_CERT_REVOKED:
|
|
|
|
case ERROR_HTTP_REDIRECT_NEEDS_CONFIRMATION:
|
2011-01-09 06:28:54 +01:00
|
|
|
security_problem = TRUE;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
security_problem = FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
hres = IInternetProtocolSink_QueryInterface(This->base.protocol_sink, &IID_IServiceProvider,
|
|
|
|
(void**)&serv_prov);
|
|
|
|
if(FAILED(hres)) {
|
|
|
|
ERR("Failed to get IServiceProvider.\n");
|
|
|
|
return E_ABORT;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(security_problem) {
|
|
|
|
hres = IServiceProvider_QueryService(serv_prov, &IID_IHttpSecurity, &IID_IHttpSecurity,
|
|
|
|
(void**)&http_security);
|
|
|
|
if(SUCCEEDED(hres)) {
|
|
|
|
hres = IHttpSecurity_OnSecurityProblem(http_security, error);
|
|
|
|
IHttpSecurity_Release(http_security);
|
|
|
|
|
2022-02-18 09:18:16 +01:00
|
|
|
TRACE("OnSecurityProblem returned %08lx\n", hres);
|
2012-06-11 16:14:45 +02:00
|
|
|
|
2011-01-09 06:28:54 +01:00
|
|
|
if(hres != S_FALSE)
|
|
|
|
{
|
|
|
|
BOOL res = FALSE;
|
|
|
|
|
|
|
|
IServiceProvider_Release(serv_prov);
|
|
|
|
|
|
|
|
if(hres == S_OK) {
|
|
|
|
if(error == ERROR_INTERNET_SEC_CERT_DATE_INVALID)
|
|
|
|
res = set_security_flag(This, SECURITY_FLAG_IGNORE_CERT_DATE_INVALID);
|
|
|
|
else if(error == ERROR_INTERNET_SEC_CERT_CN_INVALID)
|
|
|
|
res = set_security_flag(This, SECURITY_FLAG_IGNORE_CERT_CN_INVALID);
|
|
|
|
else if(error == ERROR_INTERNET_INVALID_CA)
|
|
|
|
res = set_security_flag(This, SECURITY_FLAG_IGNORE_UNKNOWN_CA);
|
|
|
|
|
|
|
|
if(res)
|
|
|
|
return RPC_E_RETRY;
|
|
|
|
|
2022-02-18 09:18:16 +01:00
|
|
|
FIXME("Don't know how to ignore error %ld\n", error);
|
2011-01-09 06:28:54 +01:00
|
|
|
return E_ABORT;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(hres == E_ABORT)
|
|
|
|
return E_ABORT;
|
|
|
|
if(hres == RPC_E_RETRY)
|
|
|
|
return RPC_E_RETRY;
|
|
|
|
|
|
|
|
return internet_error_to_hres(error);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-06-07 16:32:56 +02:00
|
|
|
switch(error) {
|
|
|
|
case ERROR_INTERNET_SEC_CERT_REV_FAILED:
|
2012-06-11 16:14:45 +02:00
|
|
|
if(hres != S_FALSE) {
|
2012-06-07 16:32:56 +02:00
|
|
|
/* Silently ignore the error. We will get more detailed error from wininet anyway. */
|
|
|
|
set_security_flag(This, SECURITY_FLAG_IGNORE_REVOCATION);
|
|
|
|
hres = RPC_E_RETRY;
|
2012-06-11 16:14:45 +02:00
|
|
|
break;
|
2012-06-07 16:32:56 +02:00
|
|
|
}
|
2012-06-11 16:14:45 +02:00
|
|
|
/* fallthrough */
|
2012-06-07 16:32:56 +02:00
|
|
|
default:
|
|
|
|
hres = IServiceProvider_QueryService(serv_prov, &IID_IWindowForBindingUI, &IID_IWindowForBindingUI, (void**)&wfb_ui);
|
|
|
|
if(SUCCEEDED(hres)) {
|
|
|
|
const IID *iid_reason;
|
|
|
|
|
|
|
|
if(security_problem)
|
|
|
|
iid_reason = &IID_IHttpSecurity;
|
|
|
|
else if(error == ERROR_INTERNET_INCORRECT_PASSWORD)
|
|
|
|
iid_reason = &IID_IAuthenticate;
|
|
|
|
else
|
|
|
|
iid_reason = &IID_IWindowForBindingUI;
|
|
|
|
|
|
|
|
hres = IWindowForBindingUI_GetWindow(wfb_ui, iid_reason, &hwnd);
|
|
|
|
IWindowForBindingUI_Release(wfb_ui);
|
|
|
|
}
|
2011-01-09 06:28:54 +01:00
|
|
|
|
2012-09-18 07:49:50 +02:00
|
|
|
if(FAILED(hres)) hwnd = NULL;
|
2012-05-30 16:53:32 +02:00
|
|
|
|
2012-06-07 16:32:56 +02:00
|
|
|
dlg_flags = FLAGS_ERROR_UI_FLAGS_CHANGE_OPTIONS | FLAGS_ERROR_UI_FLAGS_GENERATE_DATA;
|
|
|
|
if(This->base.bindf & BINDF_NO_UI)
|
|
|
|
dlg_flags |= FLAGS_ERROR_UI_FLAGS_NO_UI;
|
2011-01-09 06:28:54 +01:00
|
|
|
|
2012-06-07 16:32:56 +02:00
|
|
|
res = InternetErrorDlg(hwnd, This->base.request, error, dlg_flags, NULL);
|
|
|
|
hres = res == ERROR_INTERNET_FORCE_RETRY || res == ERROR_SUCCESS ? RPC_E_RETRY : internet_error_to_hres(error);
|
|
|
|
}
|
|
|
|
|
|
|
|
IServiceProvider_Release(serv_prov);
|
|
|
|
return hres;
|
2011-01-09 06:28:54 +01:00
|
|
|
}
|
|
|
|
|
2010-12-22 00:50:24 +01:00
|
|
|
static ULONG send_http_request(HttpProtocol *This)
|
|
|
|
{
|
|
|
|
INTERNET_BUFFERSW send_buffer = {sizeof(INTERNET_BUFFERSW)};
|
|
|
|
BOOL res;
|
|
|
|
|
|
|
|
send_buffer.lpcszHeader = This->full_header;
|
2019-06-24 10:15:45 +02:00
|
|
|
send_buffer.dwHeadersLength = send_buffer.dwHeadersTotal = lstrlenW(This->full_header);
|
2010-12-22 00:50:24 +01:00
|
|
|
|
|
|
|
if(This->base.bind_info.dwBindVerb != BINDVERB_GET) {
|
|
|
|
switch(This->base.bind_info.stgmedData.tymed) {
|
|
|
|
case TYMED_HGLOBAL:
|
|
|
|
/* Native does not use GlobalLock/GlobalUnlock, so we won't either */
|
|
|
|
send_buffer.lpvBuffer = This->base.bind_info.stgmedData.u.hGlobal;
|
|
|
|
send_buffer.dwBufferLength = send_buffer.dwBufferTotal = This->base.bind_info.cbstgmedData;
|
|
|
|
break;
|
|
|
|
case TYMED_ISTREAM: {
|
|
|
|
LARGE_INTEGER offset;
|
|
|
|
|
|
|
|
send_buffer.dwBufferTotal = This->base.bind_info.cbstgmedData;
|
|
|
|
if(!This->base.post_stream) {
|
|
|
|
This->base.post_stream = This->base.bind_info.stgmedData.u.pstm;
|
|
|
|
IStream_AddRef(This->base.post_stream);
|
|
|
|
}
|
|
|
|
|
|
|
|
offset.QuadPart = 0;
|
|
|
|
IStream_Seek(This->base.post_stream, offset, STREAM_SEEK_SET, NULL);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
2022-02-18 09:18:16 +01:00
|
|
|
FIXME("Unsupported This->base.bind_info.stgmedData.tymed %ld\n", This->base.bind_info.stgmedData.tymed);
|
2010-12-22 00:50:24 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(This->base.post_stream)
|
|
|
|
res = HttpSendRequestExW(This->base.request, &send_buffer, NULL, 0, 0);
|
|
|
|
else
|
|
|
|
res = HttpSendRequestW(This->base.request, send_buffer.lpcszHeader, send_buffer.dwHeadersLength,
|
|
|
|
send_buffer.lpvBuffer, send_buffer.dwBufferLength);
|
|
|
|
|
|
|
|
return res ? 0 : GetLastError();
|
|
|
|
}
|
|
|
|
|
2011-01-04 10:59:54 +01:00
|
|
|
static inline HttpProtocol *impl_from_Protocol(Protocol *prot)
|
|
|
|
{
|
|
|
|
return CONTAINING_RECORD(prot, HttpProtocol, base);
|
|
|
|
}
|
2009-03-02 03:20:09 +01:00
|
|
|
|
2010-09-20 20:00:52 +02:00
|
|
|
static HRESULT HttpProtocol_open_request(Protocol *prot, IUri *uri, DWORD request_flags,
|
2009-08-02 00:11:46 +02:00
|
|
|
HINTERNET internet_session, IInternetBindInfo *bind_info)
|
2009-03-02 03:21:07 +01:00
|
|
|
{
|
2011-01-04 10:59:54 +01:00
|
|
|
HttpProtocol *This = impl_from_Protocol(prot);
|
2014-02-26 14:40:48 +01:00
|
|
|
WCHAR *addl_header = NULL, *post_cookie = NULL, *rootdoc_url = NULL;
|
2009-03-02 03:21:07 +01:00
|
|
|
IServiceProvider *service_provider = NULL;
|
|
|
|
IHttpNegotiate2 *http_negotiate2 = NULL;
|
2010-09-20 20:00:52 +02:00
|
|
|
BSTR url, host, user, pass, path;
|
2009-03-02 03:21:07 +01:00
|
|
|
LPOLESTR accept_mimes[257];
|
2010-09-08 14:56:08 +02:00
|
|
|
const WCHAR **accept_types;
|
2009-03-02 03:21:07 +01:00
|
|
|
BYTE security_id[512];
|
2012-05-30 16:53:20 +02:00
|
|
|
DWORD len, port, flags;
|
2010-12-22 00:50:24 +01:00
|
|
|
ULONG num, error;
|
2009-06-04 22:49:56 +02:00
|
|
|
BOOL res, b;
|
2009-03-02 03:21:07 +01:00
|
|
|
HRESULT hres;
|
|
|
|
|
|
|
|
static const WCHAR wszBindVerb[BINDVERB_CUSTOM][5] =
|
2020-11-27 23:24:51 +01:00
|
|
|
{L"GET",
|
|
|
|
L"POST",
|
|
|
|
L"PUT"};
|
2009-03-02 03:21:07 +01:00
|
|
|
|
2010-09-20 20:00:52 +02:00
|
|
|
hres = IUri_GetPort(uri, &port);
|
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
|
|
|
hres = IUri_GetHost(uri, &host);
|
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
2009-03-02 03:21:07 +01:00
|
|
|
|
2010-09-20 20:00:52 +02:00
|
|
|
hres = IUri_GetUserName(uri, &user);
|
|
|
|
if(SUCCEEDED(hres)) {
|
|
|
|
hres = IUri_GetPassword(uri, &pass);
|
|
|
|
|
|
|
|
if(SUCCEEDED(hres)) {
|
|
|
|
This->base.connection = InternetConnectW(internet_session, host, port, user, pass,
|
|
|
|
INTERNET_SERVICE_HTTP, This->https ? INTERNET_FLAG_SECURE : 0, (DWORD_PTR)&This->base);
|
|
|
|
SysFreeString(pass);
|
|
|
|
}
|
|
|
|
SysFreeString(user);
|
|
|
|
}
|
|
|
|
SysFreeString(host);
|
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
2009-03-02 03:21:07 +01:00
|
|
|
if(!This->base.connection) {
|
2022-02-18 09:18:16 +01:00
|
|
|
WARN("InternetConnect failed: %ld\n", GetLastError());
|
2009-03-02 03:21:07 +01:00
|
|
|
return INET_E_CANNOT_CONNECT;
|
|
|
|
}
|
|
|
|
|
2014-02-26 14:40:48 +01:00
|
|
|
num = 0;
|
|
|
|
hres = IInternetBindInfo_GetBindString(bind_info, BINDSTRING_ROOTDOC_URL, &rootdoc_url, 1, &num);
|
|
|
|
if(hres == S_OK && num) {
|
|
|
|
FIXME("Use root doc URL %s\n", debugstr_w(rootdoc_url));
|
|
|
|
CoTaskMemFree(rootdoc_url);
|
|
|
|
}
|
|
|
|
|
2018-07-05 17:22:32 +02:00
|
|
|
num = ARRAY_SIZE(accept_mimes) - 1;
|
2009-03-02 03:21:07 +01:00
|
|
|
hres = IInternetBindInfo_GetBindString(bind_info, BINDSTRING_ACCEPT_MIMES, accept_mimes, num, &num);
|
2010-09-08 14:56:08 +02:00
|
|
|
if(hres == INET_E_USE_DEFAULT_SETTING) {
|
2020-11-27 23:24:51 +01:00
|
|
|
static const WCHAR *default_accept_mimes[] = {L"*/*", NULL};
|
2010-09-08 14:56:08 +02:00
|
|
|
|
|
|
|
accept_types = default_accept_mimes;
|
|
|
|
num = 0;
|
|
|
|
}else if(hres == S_OK) {
|
|
|
|
accept_types = (const WCHAR**)accept_mimes;
|
|
|
|
}else {
|
2022-02-18 09:18:16 +01:00
|
|
|
WARN("GetBindString BINDSTRING_ACCEPT_MIMES failed: %08lx\n", hres);
|
2009-03-02 03:21:07 +01:00
|
|
|
return INET_E_NO_VALID_MEDIA;
|
|
|
|
}
|
|
|
|
accept_mimes[num] = 0;
|
|
|
|
|
|
|
|
if(This->https)
|
|
|
|
request_flags |= INTERNET_FLAG_SECURE;
|
2010-09-20 20:00:52 +02:00
|
|
|
|
|
|
|
hres = IUri_GetPathAndQuery(uri, &path);
|
|
|
|
if(SUCCEEDED(hres)) {
|
|
|
|
This->base.request = HttpOpenRequestW(This->base.connection,
|
|
|
|
This->base.bind_info.dwBindVerb < BINDVERB_CUSTOM
|
|
|
|
? wszBindVerb[This->base.bind_info.dwBindVerb] : This->base.bind_info.szCustomVerb,
|
|
|
|
path, NULL, NULL, accept_types, request_flags, (DWORD_PTR)&This->base);
|
|
|
|
SysFreeString(path);
|
|
|
|
}
|
2010-01-04 19:16:20 +01:00
|
|
|
while(num--)
|
|
|
|
CoTaskMemFree(accept_mimes[num]);
|
2010-09-20 20:00:52 +02:00
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
2009-03-02 03:21:07 +01:00
|
|
|
if (!This->base.request) {
|
2022-02-18 09:18:16 +01:00
|
|
|
WARN("HttpOpenRequest failed: %ld\n", GetLastError());
|
2009-03-02 03:21:07 +01:00
|
|
|
return INET_E_RESOURCE_NOT_FOUND;
|
|
|
|
}
|
|
|
|
|
|
|
|
hres = IInternetProtocolSink_QueryInterface(This->base.protocol_sink, &IID_IServiceProvider,
|
|
|
|
(void **)&service_provider);
|
|
|
|
if (hres != S_OK) {
|
2022-02-18 09:18:16 +01:00
|
|
|
WARN("IInternetProtocolSink_QueryInterface IID_IServiceProvider failed: %08lx\n", hres);
|
2009-03-02 03:21:07 +01:00
|
|
|
return hres;
|
|
|
|
}
|
|
|
|
|
|
|
|
hres = IServiceProvider_QueryService(service_provider, &IID_IHttpNegotiate,
|
|
|
|
&IID_IHttpNegotiate, (void **)&This->http_negotiate);
|
|
|
|
if (hres != S_OK) {
|
2022-02-18 09:18:16 +01:00
|
|
|
WARN("IServiceProvider_QueryService IID_IHttpNegotiate failed: %08lx\n", hres);
|
2010-10-04 14:00:17 +02:00
|
|
|
IServiceProvider_Release(service_provider);
|
2009-03-02 03:21:07 +01:00
|
|
|
return hres;
|
|
|
|
}
|
|
|
|
|
2010-09-20 20:00:52 +02:00
|
|
|
hres = IUri_GetAbsoluteUri(uri, &url);
|
|
|
|
if(FAILED(hres)) {
|
|
|
|
IServiceProvider_Release(service_provider);
|
|
|
|
return hres;
|
|
|
|
}
|
|
|
|
|
2011-05-26 15:08:28 +02:00
|
|
|
hres = IHttpNegotiate_BeginningTransaction(This->http_negotiate, url, default_headersW,
|
2009-03-02 03:21:07 +01:00
|
|
|
0, &addl_header);
|
2010-09-20 20:00:52 +02:00
|
|
|
SysFreeString(url);
|
2009-03-02 03:21:07 +01:00
|
|
|
if(hres != S_OK) {
|
2022-02-18 09:18:16 +01:00
|
|
|
WARN("IHttpNegotiate_BeginningTransaction failed: %08lx\n", hres);
|
2009-03-02 03:21:07 +01:00
|
|
|
IServiceProvider_Release(service_provider);
|
|
|
|
return hres;
|
|
|
|
}
|
|
|
|
|
2019-06-24 10:15:45 +02:00
|
|
|
len = addl_header ? lstrlenW(addl_header) : 0;
|
2009-03-02 03:21:07 +01:00
|
|
|
|
2011-05-26 15:08:28 +02:00
|
|
|
This->full_header = heap_alloc(len*sizeof(WCHAR)+sizeof(default_headersW));
|
|
|
|
if(!This->full_header) {
|
|
|
|
IServiceProvider_Release(service_provider);
|
|
|
|
return E_OUTOFMEMORY;
|
2009-03-02 03:21:07 +01:00
|
|
|
}
|
|
|
|
|
2011-05-26 15:08:28 +02:00
|
|
|
if(len)
|
|
|
|
memcpy(This->full_header, addl_header, len*sizeof(WCHAR));
|
|
|
|
CoTaskMemFree(addl_header);
|
|
|
|
memcpy(This->full_header+len, default_headersW, sizeof(default_headersW));
|
|
|
|
|
2009-03-02 03:21:07 +01:00
|
|
|
hres = IServiceProvider_QueryService(service_provider, &IID_IHttpNegotiate2,
|
|
|
|
&IID_IHttpNegotiate2, (void **)&http_negotiate2);
|
|
|
|
IServiceProvider_Release(service_provider);
|
|
|
|
if(hres != S_OK) {
|
2022-02-18 09:18:16 +01:00
|
|
|
WARN("IServiceProvider_QueryService IID_IHttpNegotiate2 failed: %08lx\n", hres);
|
2009-03-02 03:21:07 +01:00
|
|
|
/* No goto done as per native */
|
|
|
|
}else {
|
2018-07-05 17:22:32 +02:00
|
|
|
len = ARRAY_SIZE(security_id);
|
2009-03-02 03:21:07 +01:00
|
|
|
hres = IHttpNegotiate2_GetRootSecurityId(http_negotiate2, security_id, &len, 0);
|
|
|
|
IHttpNegotiate2_Release(http_negotiate2);
|
|
|
|
if (hres != S_OK)
|
2022-02-18 09:18:16 +01:00
|
|
|
WARN("IHttpNegotiate2_GetRootSecurityId failed: %08lx\n", hres);
|
2009-03-02 03:21:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* FIXME: Handle security_id. Native calls undocumented function IsHostInProxyBypassList. */
|
|
|
|
|
|
|
|
if(This->base.bind_info.dwBindVerb == BINDVERB_POST) {
|
|
|
|
num = 0;
|
|
|
|
hres = IInternetBindInfo_GetBindString(bind_info, BINDSTRING_POST_COOKIE, &post_cookie, 1, &num);
|
|
|
|
if(hres == S_OK && num) {
|
|
|
|
if(!InternetSetOptionW(This->base.request, INTERNET_OPTION_SECONDARY_CACHE_KEY,
|
|
|
|
post_cookie, lstrlenW(post_cookie)))
|
2022-02-18 09:18:16 +01:00
|
|
|
WARN("InternetSetOption INTERNET_OPTION_SECONDARY_CACHE_KEY failed: %ld\n", GetLastError());
|
2009-03-02 03:21:07 +01:00
|
|
|
CoTaskMemFree(post_cookie);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-05-30 16:53:20 +02:00
|
|
|
flags = INTERNET_ERROR_MASK_COMBINED_SEC_CERT;
|
|
|
|
res = InternetSetOptionW(This->base.request, INTERNET_OPTION_ERROR_MASK, &flags, sizeof(flags));
|
|
|
|
if(!res)
|
2022-02-18 09:18:16 +01:00
|
|
|
WARN("InternetSetOption(INTERNET_OPTION_ERROR_MASK) failed: %lu\n", GetLastError());
|
2012-05-30 16:53:20 +02:00
|
|
|
|
2009-06-04 22:49:56 +02:00
|
|
|
b = TRUE;
|
|
|
|
res = InternetSetOptionW(This->base.request, INTERNET_OPTION_HTTP_DECODING, &b, sizeof(b));
|
|
|
|
if(!res)
|
2022-02-18 09:18:16 +01:00
|
|
|
WARN("InternetSetOption(INTERNET_OPTION_HTTP_DECODING) failed: %lu\n", GetLastError());
|
2009-06-04 22:49:56 +02:00
|
|
|
|
2011-01-09 06:28:54 +01:00
|
|
|
do {
|
|
|
|
error = send_http_request(This);
|
2010-12-22 00:50:24 +01:00
|
|
|
|
2013-03-07 16:29:48 +01:00
|
|
|
switch(error) {
|
|
|
|
case ERROR_IO_PENDING:
|
2011-01-09 06:28:54 +01:00
|
|
|
return S_OK;
|
2013-03-07 16:29:48 +01:00
|
|
|
case ERROR_SUCCESS:
|
|
|
|
/*
|
|
|
|
* If sending response ended synchronously, it means that we have the whole data
|
|
|
|
* available locally (most likely in cache).
|
|
|
|
*/
|
|
|
|
return protocol_syncbinding(&This->base);
|
|
|
|
default:
|
|
|
|
hres = handle_http_error(This, error);
|
|
|
|
}
|
2011-01-09 06:28:54 +01:00
|
|
|
} while(hres == RPC_E_RETRY);
|
2009-03-02 03:21:07 +01:00
|
|
|
|
2022-02-18 09:18:16 +01:00
|
|
|
WARN("HttpSendRequest failed: %ld\n", error);
|
2011-01-09 06:28:54 +01:00
|
|
|
return hres;
|
2009-03-02 03:21:07 +01:00
|
|
|
}
|
|
|
|
|
2010-10-06 21:36:44 +02:00
|
|
|
static HRESULT HttpProtocol_end_request(Protocol *protocol)
|
|
|
|
{
|
|
|
|
BOOL res;
|
|
|
|
|
|
|
|
res = HttpEndRequestW(protocol->request, NULL, 0, 0);
|
|
|
|
if(!res && GetLastError() != ERROR_IO_PENDING) {
|
2022-02-18 09:18:16 +01:00
|
|
|
FIXME("HttpEndRequest failed: %lu\n", GetLastError());
|
2010-10-06 21:36:44 +02:00
|
|
|
return E_FAIL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2017-06-06 17:14:49 +02:00
|
|
|
static BOOL is_redirect_response(DWORD status_code)
|
|
|
|
{
|
|
|
|
switch(status_code) {
|
|
|
|
case HTTP_STATUS_REDIRECT:
|
|
|
|
case HTTP_STATUS_MOVED:
|
|
|
|
case HTTP_STATUS_REDIRECT_KEEP_VERB:
|
|
|
|
case HTTP_STATUS_REDIRECT_METHOD:
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2009-03-02 03:20:46 +01:00
|
|
|
static HRESULT HttpProtocol_start_downloading(Protocol *prot)
|
|
|
|
{
|
2011-01-04 10:59:54 +01:00
|
|
|
HttpProtocol *This = impl_from_Protocol(prot);
|
2009-12-15 21:15:45 +01:00
|
|
|
LPWSTR content_type, content_length, ranges;
|
2009-03-02 03:20:46 +01:00
|
|
|
DWORD len = sizeof(DWORD);
|
|
|
|
DWORD status_code;
|
|
|
|
BOOL res;
|
|
|
|
HRESULT hres;
|
|
|
|
|
|
|
|
if(!This->http_negotiate) {
|
|
|
|
WARN("Expected IHttpNegotiate pointer to be non-NULL\n");
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
res = HttpQueryInfoW(This->base.request, HTTP_QUERY_STATUS_CODE | HTTP_QUERY_FLAG_NUMBER,
|
|
|
|
&status_code, &len, NULL);
|
|
|
|
if(res) {
|
2017-06-06 17:14:49 +02:00
|
|
|
WCHAR *response_headers;
|
|
|
|
|
|
|
|
if((This->base.bind_info.dwOptions & BINDINFO_OPTIONS_DISABLEAUTOREDIRECTS) && is_redirect_response(status_code)) {
|
|
|
|
WCHAR *location;
|
|
|
|
|
|
|
|
TRACE("Got redirect with disabled auto redirects\n");
|
|
|
|
|
|
|
|
location = query_http_info(This, HTTP_QUERY_LOCATION);
|
|
|
|
This->base.flags |= FLAG_RESULT_REPORTED | FLAG_LAST_DATA_REPORTED;
|
|
|
|
IInternetProtocolSink_ReportResult(This->base.protocol_sink, INET_E_REDIRECT_FAILED, 0, location);
|
|
|
|
heap_free(location);
|
|
|
|
return INET_E_REDIRECT_FAILED;
|
|
|
|
}
|
|
|
|
|
|
|
|
response_headers = query_http_info(This, HTTP_QUERY_RAW_HEADERS_CRLF);
|
2009-03-02 03:20:46 +01:00
|
|
|
if(response_headers) {
|
|
|
|
hres = IHttpNegotiate_OnResponse(This->http_negotiate, status_code, response_headers,
|
|
|
|
NULL, NULL);
|
|
|
|
heap_free(response_headers);
|
|
|
|
if (hres != S_OK) {
|
2022-02-18 09:18:16 +01:00
|
|
|
WARN("IHttpNegotiate_OnResponse failed: %08lx\n", hres);
|
2009-03-02 03:20:46 +01:00
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}else {
|
2022-02-18 09:18:16 +01:00
|
|
|
WARN("HttpQueryInfo failed: %ld\n", GetLastError());
|
2009-03-02 03:20:46 +01:00
|
|
|
}
|
|
|
|
|
2009-12-15 21:15:45 +01:00
|
|
|
ranges = query_http_info(This, HTTP_QUERY_ACCEPT_RANGES);
|
|
|
|
if(ranges) {
|
2009-03-02 03:20:46 +01:00
|
|
|
IInternetProtocolSink_ReportProgress(This->base.protocol_sink, BINDSTATUS_ACCEPTRANGES, NULL);
|
2009-12-15 21:15:45 +01:00
|
|
|
heap_free(ranges);
|
|
|
|
}
|
2009-03-02 03:20:46 +01:00
|
|
|
|
|
|
|
content_type = query_http_info(This, HTTP_QUERY_CONTENT_TYPE);
|
|
|
|
if(content_type) {
|
|
|
|
/* remove the charset, if present */
|
2019-06-24 10:15:45 +02:00
|
|
|
LPWSTR p = wcschr(content_type, ';');
|
2009-03-02 03:20:46 +01:00
|
|
|
if (p) *p = '\0';
|
|
|
|
|
|
|
|
IInternetProtocolSink_ReportProgress(This->base.protocol_sink,
|
|
|
|
(This->base.bindf & BINDF_FROMURLMON)
|
|
|
|
? BINDSTATUS_MIMETYPEAVAILABLE : BINDSTATUS_RAWMIMETYPE,
|
|
|
|
content_type);
|
|
|
|
heap_free(content_type);
|
|
|
|
}else {
|
2022-02-18 09:18:16 +01:00
|
|
|
WARN("HttpQueryInfo failed: %ld\n", GetLastError());
|
2009-03-02 03:20:46 +01:00
|
|
|
IInternetProtocolSink_ReportProgress(This->base.protocol_sink,
|
|
|
|
(This->base.bindf & BINDF_FROMURLMON)
|
2020-12-03 00:32:46 +01:00
|
|
|
? BINDSTATUS_MIMETYPEAVAILABLE : BINDSTATUS_RAWMIMETYPE, L"text/html");
|
2009-03-02 03:20:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
content_length = query_http_info(This, HTTP_QUERY_CONTENT_LENGTH);
|
|
|
|
if(content_length) {
|
2019-06-24 10:15:45 +02:00
|
|
|
This->base.content_length = wcstol(content_length, NULL, 10);
|
2009-03-02 03:20:46 +01:00
|
|
|
heap_free(content_length);
|
|
|
|
}
|
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2009-03-02 03:20:09 +01:00
|
|
|
static void HttpProtocol_close_connection(Protocol *prot)
|
|
|
|
{
|
2011-01-04 10:59:54 +01:00
|
|
|
HttpProtocol *This = impl_from_Protocol(prot);
|
2009-03-02 03:20:09 +01:00
|
|
|
|
|
|
|
if(This->http_negotiate) {
|
|
|
|
IHttpNegotiate_Release(This->http_negotiate);
|
2011-05-26 15:08:28 +02:00
|
|
|
This->http_negotiate = NULL;
|
2009-03-02 03:20:09 +01:00
|
|
|
}
|
|
|
|
|
2011-10-11 00:03:42 +02:00
|
|
|
heap_free(This->full_header);
|
|
|
|
This->full_header = NULL;
|
2009-03-02 03:20:09 +01:00
|
|
|
}
|
|
|
|
|
2011-01-03 03:47:38 +01:00
|
|
|
static void HttpProtocol_on_error(Protocol *prot, DWORD error)
|
|
|
|
{
|
2011-01-09 06:28:54 +01:00
|
|
|
HttpProtocol *This = impl_from_Protocol(prot);
|
|
|
|
HRESULT hres;
|
|
|
|
|
2022-02-18 09:18:16 +01:00
|
|
|
TRACE("(%p) %ld\n", prot, error);
|
2011-01-09 06:28:54 +01:00
|
|
|
|
|
|
|
if(prot->flags & FLAG_FIRST_CONTINUE_COMPLETE) {
|
2022-02-18 09:18:16 +01:00
|
|
|
FIXME("Not handling error %ld\n", error);
|
2011-01-09 06:28:54 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
while((hres = handle_http_error(This, error)) == RPC_E_RETRY) {
|
|
|
|
error = send_http_request(This);
|
|
|
|
|
|
|
|
if(error == ERROR_IO_PENDING || error == ERROR_SUCCESS)
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
protocol_abort(prot, hres);
|
|
|
|
protocol_close_connection(prot);
|
|
|
|
return;
|
2011-01-03 03:47:38 +01:00
|
|
|
}
|
|
|
|
|
2009-03-02 03:20:09 +01:00
|
|
|
static const ProtocolVtbl AsyncProtocolVtbl = {
|
2009-03-02 03:21:07 +01:00
|
|
|
HttpProtocol_open_request,
|
2010-10-06 21:36:44 +02:00
|
|
|
HttpProtocol_end_request,
|
2009-03-02 03:20:46 +01:00
|
|
|
HttpProtocol_start_downloading,
|
2011-01-03 03:47:38 +01:00
|
|
|
HttpProtocol_close_connection,
|
|
|
|
HttpProtocol_on_error
|
2009-03-02 03:20:09 +01:00
|
|
|
};
|
2007-07-10 17:52:03 +02:00
|
|
|
|
2018-05-08 18:18:32 +02:00
|
|
|
static HRESULT WINAPI HttpProtocolUnk_QueryInterface(IUnknown *iface, REFIID riid, void **ppv)
|
2005-09-14 17:38:26 +02:00
|
|
|
{
|
2018-05-08 18:18:32 +02:00
|
|
|
HttpProtocol *This = impl_from_IUnknown(iface);
|
2005-09-14 17:38:26 +02:00
|
|
|
|
|
|
|
if(IsEqualGUID(&IID_IUnknown, riid)) {
|
|
|
|
TRACE("(%p)->(IID_IUnknown %p)\n", This, ppv);
|
2019-06-03 21:50:16 +02:00
|
|
|
*ppv = &This->IUnknown_inner;
|
2005-09-14 17:38:26 +02:00
|
|
|
}else if(IsEqualGUID(&IID_IInternetProtocolRoot, riid)) {
|
|
|
|
TRACE("(%p)->(IID_IInternetProtocolRoot %p)\n", This, ppv);
|
2010-12-06 23:34:19 +01:00
|
|
|
*ppv = &This->IInternetProtocolEx_iface;
|
2005-09-14 17:38:26 +02:00
|
|
|
}else if(IsEqualGUID(&IID_IInternetProtocol, riid)) {
|
|
|
|
TRACE("(%p)->(IID_IInternetProtocol %p)\n", This, ppv);
|
2010-12-06 23:34:19 +01:00
|
|
|
*ppv = &This->IInternetProtocolEx_iface;
|
2010-10-06 21:37:27 +02:00
|
|
|
}else if(IsEqualGUID(&IID_IInternetProtocolEx, riid)) {
|
|
|
|
TRACE("(%p)->(IID_IInternetProtocolEx %p)\n", This, ppv);
|
2010-12-06 23:34:19 +01:00
|
|
|
*ppv = &This->IInternetProtocolEx_iface;
|
2005-11-09 11:28:26 +01:00
|
|
|
}else if(IsEqualGUID(&IID_IInternetPriority, riid)) {
|
|
|
|
TRACE("(%p)->(IID_IInternetPriority %p)\n", This, ppv);
|
2010-12-06 23:34:19 +01:00
|
|
|
*ppv = &This->IInternetPriority_iface;
|
2009-03-29 21:30:29 +02:00
|
|
|
}else if(IsEqualGUID(&IID_IWinInetInfo, riid)) {
|
|
|
|
TRACE("(%p)->(IID_IWinInetInfo %p)\n", This, ppv);
|
2010-12-06 23:34:19 +01:00
|
|
|
*ppv = &This->IWinInetHttpInfo_iface;
|
2009-03-29 21:30:29 +02:00
|
|
|
}else if(IsEqualGUID(&IID_IWinInetHttpInfo, riid)) {
|
|
|
|
TRACE("(%p)->(IID_IWinInetHttpInfo %p)\n", This, ppv);
|
2010-12-06 23:34:19 +01:00
|
|
|
*ppv = &This->IWinInetHttpInfo_iface;
|
2018-05-08 18:18:32 +02:00
|
|
|
}else {
|
|
|
|
*ppv = NULL;
|
|
|
|
WARN("not supported interface %s\n", debugstr_guid(riid));
|
|
|
|
return E_NOINTERFACE;
|
2005-09-14 17:38:26 +02:00
|
|
|
}
|
|
|
|
|
2018-05-08 18:18:32 +02:00
|
|
|
IUnknown_AddRef((IUnknown*)*ppv);
|
|
|
|
return S_OK;
|
2005-09-14 17:38:26 +02:00
|
|
|
}
|
|
|
|
|
2018-05-08 18:18:32 +02:00
|
|
|
static ULONG WINAPI HttpProtocolUnk_AddRef(IUnknown *iface)
|
2005-09-14 17:38:26 +02:00
|
|
|
{
|
2018-05-08 18:18:32 +02:00
|
|
|
HttpProtocol *This = impl_from_IUnknown(iface);
|
2005-09-14 17:38:26 +02:00
|
|
|
LONG ref = InterlockedIncrement(&This->ref);
|
2022-02-18 09:18:16 +01:00
|
|
|
TRACE("(%p) ref=%ld\n", This, ref);
|
2005-09-14 17:38:26 +02:00
|
|
|
return ref;
|
|
|
|
}
|
|
|
|
|
2018-05-08 18:18:32 +02:00
|
|
|
static ULONG WINAPI HttpProtocolUnk_Release(IUnknown *iface)
|
2005-09-14 17:38:26 +02:00
|
|
|
{
|
2018-05-08 18:18:32 +02:00
|
|
|
HttpProtocol *This = impl_from_IUnknown(iface);
|
2005-09-14 17:38:26 +02:00
|
|
|
LONG ref = InterlockedDecrement(&This->ref);
|
|
|
|
|
2022-02-18 09:18:16 +01:00
|
|
|
TRACE("(%p) ref=%ld\n", This, ref);
|
2005-09-14 17:38:26 +02:00
|
|
|
|
|
|
|
if(!ref) {
|
2009-03-02 03:20:09 +01:00
|
|
|
protocol_close_connection(&This->base);
|
2007-11-29 22:12:34 +01:00
|
|
|
heap_free(This);
|
2005-09-14 17:38:26 +02:00
|
|
|
|
|
|
|
URLMON_UnlockModule();
|
|
|
|
}
|
|
|
|
|
|
|
|
return ref;
|
|
|
|
}
|
|
|
|
|
2018-05-08 18:18:32 +02:00
|
|
|
static const IUnknownVtbl HttpProtocolUnkVtbl = {
|
|
|
|
HttpProtocolUnk_QueryInterface,
|
|
|
|
HttpProtocolUnk_AddRef,
|
|
|
|
HttpProtocolUnk_Release
|
|
|
|
};
|
|
|
|
|
|
|
|
static HRESULT WINAPI HttpProtocol_QueryInterface(IInternetProtocolEx *iface, REFIID riid, void **ppv)
|
|
|
|
{
|
|
|
|
HttpProtocol *This = impl_from_IInternetProtocolEx(iface);
|
|
|
|
TRACE("(%p)->(%s %p)\n", This, debugstr_guid(riid), ppv);
|
|
|
|
return IUnknown_QueryInterface(This->outer, riid, ppv);
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI HttpProtocol_AddRef(IInternetProtocolEx *iface)
|
|
|
|
{
|
|
|
|
HttpProtocol *This = impl_from_IInternetProtocolEx(iface);
|
|
|
|
TRACE("(%p)\n", This);
|
|
|
|
return IUnknown_AddRef(This->outer);
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI HttpProtocol_Release(IInternetProtocolEx *iface)
|
|
|
|
{
|
|
|
|
HttpProtocol *This = impl_from_IInternetProtocolEx(iface);
|
|
|
|
TRACE("(%p)\n", This);
|
|
|
|
return IUnknown_Release(This->outer);
|
|
|
|
}
|
|
|
|
|
2010-10-06 21:37:27 +02:00
|
|
|
static HRESULT WINAPI HttpProtocol_Start(IInternetProtocolEx *iface, LPCWSTR szUrl,
|
2005-09-14 17:38:26 +02:00
|
|
|
IInternetProtocolSink *pOIProtSink, IInternetBindInfo *pOIBindInfo,
|
2009-04-01 03:42:37 +02:00
|
|
|
DWORD grfPI, HANDLE_PTR dwReserved)
|
2005-09-14 17:38:26 +02:00
|
|
|
{
|
2010-12-06 23:34:19 +01:00
|
|
|
HttpProtocol *This = impl_from_IInternetProtocolEx(iface);
|
2010-09-20 20:00:52 +02:00
|
|
|
IUri *uri;
|
|
|
|
HRESULT hres;
|
2007-07-10 17:52:03 +02:00
|
|
|
|
2022-02-18 09:18:16 +01:00
|
|
|
TRACE("(%p)->(%s %p %p %08lx %Ix)\n", This, debugstr_w(szUrl), pOIProtSink,
|
2005-09-14 17:38:26 +02:00
|
|
|
pOIBindInfo, grfPI, dwReserved);
|
2007-07-10 17:52:03 +02:00
|
|
|
|
2010-09-20 20:00:52 +02:00
|
|
|
hres = CreateUri(szUrl, 0, 0, &uri);
|
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
2010-12-06 23:34:19 +01:00
|
|
|
hres = IInternetProtocolEx_StartEx(&This->IInternetProtocolEx_iface, uri, pOIProtSink,
|
|
|
|
pOIBindInfo, grfPI, (HANDLE*)dwReserved);
|
2010-09-20 20:00:52 +02:00
|
|
|
|
|
|
|
IUri_Release(uri);
|
|
|
|
return hres;
|
2005-09-14 17:38:26 +02:00
|
|
|
}
|
|
|
|
|
2010-10-06 21:37:27 +02:00
|
|
|
static HRESULT WINAPI HttpProtocol_Continue(IInternetProtocolEx *iface, PROTOCOLDATA *pProtocolData)
|
2005-09-14 17:38:26 +02:00
|
|
|
{
|
2010-12-06 23:34:19 +01:00
|
|
|
HttpProtocol *This = impl_from_IInternetProtocolEx(iface);
|
2007-07-10 17:52:03 +02:00
|
|
|
|
|
|
|
TRACE("(%p)->(%p)\n", This, pProtocolData);
|
|
|
|
|
2009-03-02 03:20:46 +01:00
|
|
|
return protocol_continue(&This->base, pProtocolData);
|
2005-09-14 17:38:26 +02:00
|
|
|
}
|
|
|
|
|
2010-10-06 21:37:27 +02:00
|
|
|
static HRESULT WINAPI HttpProtocol_Abort(IInternetProtocolEx *iface, HRESULT hrReason,
|
2005-09-14 17:38:26 +02:00
|
|
|
DWORD dwOptions)
|
|
|
|
{
|
2010-12-06 23:34:19 +01:00
|
|
|
HttpProtocol *This = impl_from_IInternetProtocolEx(iface);
|
2010-10-04 14:00:17 +02:00
|
|
|
|
2022-02-18 09:18:16 +01:00
|
|
|
TRACE("(%p)->(%08lx %08lx)\n", This, hrReason, dwOptions);
|
2010-10-04 14:00:17 +02:00
|
|
|
|
|
|
|
return protocol_abort(&This->base, hrReason);
|
2005-09-14 17:38:26 +02:00
|
|
|
}
|
|
|
|
|
2010-10-06 21:37:27 +02:00
|
|
|
static HRESULT WINAPI HttpProtocol_Terminate(IInternetProtocolEx *iface, DWORD dwOptions)
|
2005-09-14 17:38:26 +02:00
|
|
|
{
|
2010-12-06 23:34:19 +01:00
|
|
|
HttpProtocol *This = impl_from_IInternetProtocolEx(iface);
|
2007-07-19 03:00:01 +02:00
|
|
|
|
2022-02-18 09:18:16 +01:00
|
|
|
TRACE("(%p)->(%08lx)\n", This, dwOptions);
|
2007-07-19 03:00:01 +02:00
|
|
|
|
2009-03-02 03:20:09 +01:00
|
|
|
protocol_close_connection(&This->base);
|
2007-07-19 03:00:01 +02:00
|
|
|
return S_OK;
|
2005-09-14 17:38:26 +02:00
|
|
|
}
|
|
|
|
|
2010-10-06 21:37:27 +02:00
|
|
|
static HRESULT WINAPI HttpProtocol_Suspend(IInternetProtocolEx *iface)
|
2005-09-14 17:38:26 +02:00
|
|
|
{
|
2010-12-06 23:34:19 +01:00
|
|
|
HttpProtocol *This = impl_from_IInternetProtocolEx(iface);
|
2005-09-14 17:38:26 +02:00
|
|
|
FIXME("(%p)\n", This);
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
2010-10-06 21:37:27 +02:00
|
|
|
static HRESULT WINAPI HttpProtocol_Resume(IInternetProtocolEx *iface)
|
2005-09-14 17:38:26 +02:00
|
|
|
{
|
2010-12-06 23:34:19 +01:00
|
|
|
HttpProtocol *This = impl_from_IInternetProtocolEx(iface);
|
2005-09-14 17:38:26 +02:00
|
|
|
FIXME("(%p)\n", This);
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
2010-10-06 21:37:27 +02:00
|
|
|
static HRESULT WINAPI HttpProtocol_Read(IInternetProtocolEx *iface, void *pv,
|
2005-09-14 17:38:26 +02:00
|
|
|
ULONG cb, ULONG *pcbRead)
|
|
|
|
{
|
2010-12-06 23:34:19 +01:00
|
|
|
HttpProtocol *This = impl_from_IInternetProtocolEx(iface);
|
2007-07-10 17:52:03 +02:00
|
|
|
|
2022-02-18 09:18:16 +01:00
|
|
|
TRACE("(%p)->(%p %lu %p)\n", This, pv, cb, pcbRead);
|
2007-07-10 17:52:03 +02:00
|
|
|
|
2009-03-02 03:20:26 +01:00
|
|
|
return protocol_read(&This->base, pv, cb, pcbRead);
|
2005-09-14 17:38:26 +02:00
|
|
|
}
|
|
|
|
|
2010-10-06 21:37:27 +02:00
|
|
|
static HRESULT WINAPI HttpProtocol_Seek(IInternetProtocolEx *iface, LARGE_INTEGER dlibMove,
|
2006-10-03 14:11:42 +02:00
|
|
|
DWORD dwOrigin, ULARGE_INTEGER *plibNewPosition)
|
2005-09-14 17:38:26 +02:00
|
|
|
{
|
2010-12-06 23:34:19 +01:00
|
|
|
HttpProtocol *This = impl_from_IInternetProtocolEx(iface);
|
2022-02-18 09:18:16 +01:00
|
|
|
FIXME("(%p)->(%ld %ld %p)\n", This, dlibMove.u.LowPart, dwOrigin, plibNewPosition);
|
2005-09-14 17:38:26 +02:00
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
2010-10-06 21:37:27 +02:00
|
|
|
static HRESULT WINAPI HttpProtocol_LockRequest(IInternetProtocolEx *iface, DWORD dwOptions)
|
2005-09-14 17:38:26 +02:00
|
|
|
{
|
2010-12-06 23:34:19 +01:00
|
|
|
HttpProtocol *This = impl_from_IInternetProtocolEx(iface);
|
2007-07-10 17:52:03 +02:00
|
|
|
|
2022-02-18 09:18:16 +01:00
|
|
|
TRACE("(%p)->(%08lx)\n", This, dwOptions);
|
2007-07-10 17:52:03 +02:00
|
|
|
|
2009-03-02 03:19:44 +01:00
|
|
|
return protocol_lock_request(&This->base);
|
2005-09-14 17:38:26 +02:00
|
|
|
}
|
|
|
|
|
2010-10-06 21:37:27 +02:00
|
|
|
static HRESULT WINAPI HttpProtocol_UnlockRequest(IInternetProtocolEx *iface)
|
2005-09-14 17:38:26 +02:00
|
|
|
{
|
2010-12-06 23:34:19 +01:00
|
|
|
HttpProtocol *This = impl_from_IInternetProtocolEx(iface);
|
2007-07-10 17:52:03 +02:00
|
|
|
|
|
|
|
TRACE("(%p)\n", This);
|
|
|
|
|
2009-03-02 03:19:44 +01:00
|
|
|
return protocol_unlock_request(&This->base);
|
2005-09-14 17:38:26 +02:00
|
|
|
}
|
|
|
|
|
2010-10-06 21:37:27 +02:00
|
|
|
static HRESULT WINAPI HttpProtocol_StartEx(IInternetProtocolEx *iface, IUri *pUri,
|
|
|
|
IInternetProtocolSink *pOIProtSink, IInternetBindInfo *pOIBindInfo,
|
|
|
|
DWORD grfPI, HANDLE *dwReserved)
|
|
|
|
{
|
2010-12-06 23:34:19 +01:00
|
|
|
HttpProtocol *This = impl_from_IInternetProtocolEx(iface);
|
2010-10-06 21:37:27 +02:00
|
|
|
DWORD scheme = 0;
|
|
|
|
HRESULT hres;
|
|
|
|
|
2022-02-18 09:18:16 +01:00
|
|
|
TRACE("(%p)->(%p %p %p %08lx %p)\n", This, pUri, pOIProtSink,
|
2010-10-06 21:37:27 +02:00
|
|
|
pOIBindInfo, grfPI, dwReserved);
|
|
|
|
|
|
|
|
hres = IUri_GetScheme(pUri, &scheme);
|
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
if(scheme != (This->https ? URL_SCHEME_HTTPS : URL_SCHEME_HTTP))
|
|
|
|
return MK_E_SYNTAX;
|
|
|
|
|
2010-12-06 23:34:19 +01:00
|
|
|
return protocol_start(&This->base, (IInternetProtocol*)&This->IInternetProtocolEx_iface, pUri,
|
|
|
|
pOIProtSink, pOIBindInfo);
|
2010-10-06 21:37:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static const IInternetProtocolExVtbl HttpProtocolVtbl = {
|
2009-03-02 03:21:22 +01:00
|
|
|
HttpProtocol_QueryInterface,
|
|
|
|
HttpProtocol_AddRef,
|
|
|
|
HttpProtocol_Release,
|
|
|
|
HttpProtocol_Start,
|
|
|
|
HttpProtocol_Continue,
|
|
|
|
HttpProtocol_Abort,
|
|
|
|
HttpProtocol_Terminate,
|
|
|
|
HttpProtocol_Suspend,
|
|
|
|
HttpProtocol_Resume,
|
|
|
|
HttpProtocol_Read,
|
|
|
|
HttpProtocol_Seek,
|
|
|
|
HttpProtocol_LockRequest,
|
2010-10-06 21:37:27 +02:00
|
|
|
HttpProtocol_UnlockRequest,
|
|
|
|
HttpProtocol_StartEx
|
2009-03-02 03:21:22 +01:00
|
|
|
};
|
|
|
|
|
2005-11-09 11:28:26 +01:00
|
|
|
static HRESULT WINAPI HttpPriority_QueryInterface(IInternetPriority *iface, REFIID riid, void **ppv)
|
|
|
|
{
|
2010-12-06 23:34:19 +01:00
|
|
|
HttpProtocol *This = impl_from_IInternetPriority(iface);
|
|
|
|
return IInternetProtocolEx_QueryInterface(&This->IInternetProtocolEx_iface, riid, ppv);
|
2005-11-09 11:28:26 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI HttpPriority_AddRef(IInternetPriority *iface)
|
|
|
|
{
|
2010-12-06 23:34:19 +01:00
|
|
|
HttpProtocol *This = impl_from_IInternetPriority(iface);
|
|
|
|
return IInternetProtocolEx_AddRef(&This->IInternetProtocolEx_iface);
|
2005-11-09 11:28:26 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI HttpPriority_Release(IInternetPriority *iface)
|
|
|
|
{
|
2010-12-06 23:34:19 +01:00
|
|
|
HttpProtocol *This = impl_from_IInternetPriority(iface);
|
|
|
|
return IInternetProtocolEx_Release(&This->IInternetProtocolEx_iface);
|
2005-11-09 11:28:26 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI HttpPriority_SetPriority(IInternetPriority *iface, LONG nPriority)
|
|
|
|
{
|
2010-12-06 23:34:19 +01:00
|
|
|
HttpProtocol *This = impl_from_IInternetPriority(iface);
|
2005-11-09 11:28:26 +01:00
|
|
|
|
2022-02-18 09:18:16 +01:00
|
|
|
TRACE("(%p)->(%ld)\n", This, nPriority);
|
2005-11-09 11:28:26 +01:00
|
|
|
|
2009-03-02 03:19:00 +01:00
|
|
|
This->base.priority = nPriority;
|
2005-11-09 11:28:26 +01:00
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI HttpPriority_GetPriority(IInternetPriority *iface, LONG *pnPriority)
|
|
|
|
{
|
2010-12-06 23:34:19 +01:00
|
|
|
HttpProtocol *This = impl_from_IInternetPriority(iface);
|
2005-11-09 11:28:26 +01:00
|
|
|
|
|
|
|
TRACE("(%p)->(%p)\n", This, pnPriority);
|
|
|
|
|
2009-03-02 03:19:00 +01:00
|
|
|
*pnPriority = This->base.priority;
|
2005-11-09 11:28:26 +01:00
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const IInternetPriorityVtbl HttpPriorityVtbl = {
|
|
|
|
HttpPriority_QueryInterface,
|
|
|
|
HttpPriority_AddRef,
|
|
|
|
HttpPriority_Release,
|
|
|
|
HttpPriority_SetPriority,
|
|
|
|
HttpPriority_GetPriority
|
|
|
|
};
|
|
|
|
|
2009-03-29 21:30:29 +02:00
|
|
|
static HRESULT WINAPI HttpInfo_QueryInterface(IWinInetHttpInfo *iface, REFIID riid, void **ppv)
|
|
|
|
{
|
2010-12-06 23:34:19 +01:00
|
|
|
HttpProtocol *This = impl_from_IWinInetHttpInfo(iface);
|
|
|
|
return IInternetProtocolEx_QueryInterface(&This->IInternetProtocolEx_iface, riid, ppv);
|
2009-03-29 21:30:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI HttpInfo_AddRef(IWinInetHttpInfo *iface)
|
|
|
|
{
|
2010-12-06 23:34:19 +01:00
|
|
|
HttpProtocol *This = impl_from_IWinInetHttpInfo(iface);
|
|
|
|
return IInternetProtocolEx_AddRef(&This->IInternetProtocolEx_iface);
|
2009-03-29 21:30:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI HttpInfo_Release(IWinInetHttpInfo *iface)
|
|
|
|
{
|
2010-12-06 23:34:19 +01:00
|
|
|
HttpProtocol *This = impl_from_IWinInetHttpInfo(iface);
|
|
|
|
return IInternetProtocolEx_Release(&This->IInternetProtocolEx_iface);
|
2009-03-29 21:30:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI HttpInfo_QueryOption(IWinInetHttpInfo *iface, DWORD dwOption,
|
|
|
|
void *pBuffer, DWORD *pcbBuffer)
|
|
|
|
{
|
2010-12-06 23:34:19 +01:00
|
|
|
HttpProtocol *This = impl_from_IWinInetHttpInfo(iface);
|
2022-02-18 09:18:16 +01:00
|
|
|
TRACE("(%p)->(%lx %p %p)\n", This, dwOption, pBuffer, pcbBuffer);
|
2011-03-28 23:38:16 +02:00
|
|
|
|
|
|
|
if(!This->base.request)
|
|
|
|
return E_FAIL;
|
|
|
|
|
|
|
|
if(!InternetQueryOptionW(This->base.request, dwOption, pBuffer, pcbBuffer))
|
|
|
|
return S_FALSE;
|
|
|
|
return S_OK;
|
2009-03-29 21:30:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI HttpInfo_QueryInfo(IWinInetHttpInfo *iface, DWORD dwOption,
|
|
|
|
void *pBuffer, DWORD *pcbBuffer, DWORD *pdwFlags, DWORD *pdwReserved)
|
|
|
|
{
|
2010-12-06 23:34:19 +01:00
|
|
|
HttpProtocol *This = impl_from_IWinInetHttpInfo(iface);
|
2022-02-18 09:18:16 +01:00
|
|
|
TRACE("(%p)->(%lx %p %p %p %p)\n", This, dwOption, pBuffer, pcbBuffer, pdwFlags, pdwReserved);
|
2011-03-28 23:38:16 +02:00
|
|
|
|
|
|
|
if(!This->base.request)
|
|
|
|
return E_FAIL;
|
|
|
|
|
2018-02-26 18:21:02 +01:00
|
|
|
if(!HttpQueryInfoA(This->base.request, dwOption, pBuffer, pcbBuffer, pdwFlags))
|
|
|
|
return S_FALSE;
|
|
|
|
|
2011-03-28 23:38:16 +02:00
|
|
|
return S_OK;
|
2009-03-29 21:30:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static const IWinInetHttpInfoVtbl WinInetHttpInfoVtbl = {
|
|
|
|
HttpInfo_QueryInterface,
|
|
|
|
HttpInfo_AddRef,
|
|
|
|
HttpInfo_Release,
|
|
|
|
HttpInfo_QueryOption,
|
|
|
|
HttpInfo_QueryInfo
|
|
|
|
};
|
|
|
|
|
2018-05-08 18:18:32 +02:00
|
|
|
static HRESULT create_http_protocol(BOOL https, IUnknown *outer, void **ppobj)
|
2005-09-14 17:38:26 +02:00
|
|
|
{
|
|
|
|
HttpProtocol *ret;
|
|
|
|
|
2009-01-11 21:19:46 +01:00
|
|
|
ret = heap_alloc_zero(sizeof(HttpProtocol));
|
|
|
|
if(!ret)
|
|
|
|
return E_OUTOFMEMORY;
|
2005-09-14 17:38:26 +02:00
|
|
|
|
2009-03-02 03:20:09 +01:00
|
|
|
ret->base.vtbl = &AsyncProtocolVtbl;
|
2019-06-03 21:50:16 +02:00
|
|
|
ret->IUnknown_inner.lpVtbl = &HttpProtocolUnkVtbl;
|
2010-12-06 23:34:19 +01:00
|
|
|
ret->IInternetProtocolEx_iface.lpVtbl = &HttpProtocolVtbl;
|
|
|
|
ret->IInternetPriority_iface.lpVtbl = &HttpPriorityVtbl;
|
|
|
|
ret->IWinInetHttpInfo_iface.lpVtbl = &WinInetHttpInfoVtbl;
|
2009-01-11 21:19:46 +01:00
|
|
|
|
|
|
|
ret->https = https;
|
2007-07-10 17:52:03 +02:00
|
|
|
ret->ref = 1;
|
2019-06-03 21:50:16 +02:00
|
|
|
ret->outer = outer ? outer : &ret->IUnknown_inner;
|
2005-11-09 11:28:26 +01:00
|
|
|
|
2019-06-03 21:50:16 +02:00
|
|
|
*ppobj = &ret->IUnknown_inner;
|
2010-12-06 23:34:19 +01:00
|
|
|
|
2009-01-11 21:19:46 +01:00
|
|
|
URLMON_LockModule();
|
2005-09-14 17:38:26 +02:00
|
|
|
return S_OK;
|
|
|
|
}
|
2007-11-04 17:09:20 +01:00
|
|
|
|
2018-05-08 18:18:32 +02:00
|
|
|
HRESULT HttpProtocol_Construct(IUnknown *outer, void **ppv)
|
2009-01-11 21:19:46 +01:00
|
|
|
{
|
2018-05-08 18:18:32 +02:00
|
|
|
TRACE("(%p %p)\n", outer, ppv);
|
2009-01-11 21:19:46 +01:00
|
|
|
|
2018-05-08 18:18:32 +02:00
|
|
|
return create_http_protocol(FALSE, outer, ppv);
|
2009-01-11 21:19:46 +01:00
|
|
|
}
|
|
|
|
|
2018-05-08 18:18:32 +02:00
|
|
|
HRESULT HttpSProtocol_Construct(IUnknown *outer, void **ppv)
|
2007-11-04 17:09:20 +01:00
|
|
|
{
|
2018-05-08 18:18:32 +02:00
|
|
|
TRACE("(%p %p)\n", outer, ppv);
|
2009-01-11 21:19:46 +01:00
|
|
|
|
2018-05-08 18:18:32 +02:00
|
|
|
return create_http_protocol(TRUE, outer, ppv);
|
2007-11-04 17:09:20 +01:00
|
|
|
}
|