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
|
|
|
*/
|
|
|
|
|
|
|
|
#include "urlmon_main.h"
|
2007-12-13 20:26:51 +01:00
|
|
|
#include "wininet.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;
|
|
|
|
|
2009-05-18 18:31:03 +02:00
|
|
|
const IInternetProtocolVtbl *lpIInternetProtocolVtbl;
|
2005-11-09 11:28:26 +01:00
|
|
|
const IInternetPriorityVtbl *lpInternetPriorityVtbl;
|
2009-03-29 21:30:29 +02:00
|
|
|
const IWinInetHttpInfoVtbl *lpWinInetHttpInfoVtbl;
|
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;
|
2007-07-26 06:58:37 +02:00
|
|
|
LPWSTR full_header;
|
2009-03-02 03:21:07 +01:00
|
|
|
|
|
|
|
LONG ref;
|
2005-09-14 17:38:26 +02:00
|
|
|
} HttpProtocol;
|
|
|
|
|
2009-03-29 21:30:29 +02:00
|
|
|
#define PRIORITY(x) ((IInternetPriority*) &(x)->lpInternetPriorityVtbl)
|
|
|
|
#define INETHTTPINFO(x) ((IWinInetHttpInfo*) &(x)->lpWinInetHttpInfoVtbl)
|
2009-02-26 01:47:24 +01:00
|
|
|
|
2007-07-26 06:58:37 +02:00
|
|
|
/* Default headers from native */
|
|
|
|
static const WCHAR wszHeaders[] = {'A','c','c','e','p','t','-','E','n','c','o','d','i','n','g',
|
|
|
|
':',' ','g','z','i','p',',',' ','d','e','f','l','a','t','e',0};
|
|
|
|
|
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) {
|
|
|
|
TRACE("HttpQueryInfoW(%d) failed: %08x\n", option, GetLastError());
|
|
|
|
heap_free(ret);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2009-03-02 03:20:09 +01:00
|
|
|
#define ASYNCPROTOCOL_THIS(iface) DEFINE_THIS2(HttpProtocol, base, iface)
|
|
|
|
|
2009-03-02 03:21:07 +01:00
|
|
|
static HRESULT HttpProtocol_open_request(Protocol *prot, LPCWSTR url, 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
|
|
|
{
|
|
|
|
HttpProtocol *This = ASYNCPROTOCOL_THIS(prot);
|
|
|
|
LPWSTR addl_header = NULL, post_cookie = NULL, optional = NULL;
|
|
|
|
IServiceProvider *service_provider = NULL;
|
|
|
|
IHttpNegotiate2 *http_negotiate2 = NULL;
|
|
|
|
LPWSTR host, user, pass, path;
|
|
|
|
LPOLESTR accept_mimes[257];
|
2010-09-08 14:56:08 +02:00
|
|
|
const WCHAR **accept_types;
|
2009-03-02 03:21:07 +01:00
|
|
|
URL_COMPONENTSW url_comp;
|
|
|
|
BYTE security_id[512];
|
|
|
|
DWORD len = 0;
|
2010-01-04 19:16:20 +01:00
|
|
|
ULONG num;
|
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] =
|
|
|
|
{{'G','E','T',0},
|
|
|
|
{'P','O','S','T',0},
|
|
|
|
{'P','U','T',0}};
|
|
|
|
|
|
|
|
memset(&url_comp, 0, sizeof(url_comp));
|
|
|
|
url_comp.dwStructSize = sizeof(url_comp);
|
2009-12-09 22:09:22 +01:00
|
|
|
url_comp.dwSchemeLength = url_comp.dwHostNameLength = url_comp.dwUrlPathLength = url_comp.dwExtraInfoLength =
|
2009-03-02 03:21:07 +01:00
|
|
|
url_comp.dwUserNameLength = url_comp.dwPasswordLength = 1;
|
|
|
|
if (!InternetCrackUrlW(url, 0, 0, &url_comp))
|
|
|
|
return MK_E_SYNTAX;
|
|
|
|
|
|
|
|
if(!url_comp.nPort)
|
|
|
|
url_comp.nPort = This->https ? INTERNET_DEFAULT_HTTPS_PORT : INTERNET_DEFAULT_HTTP_PORT;
|
|
|
|
|
|
|
|
host = heap_strndupW(url_comp.lpszHostName, url_comp.dwHostNameLength);
|
|
|
|
user = heap_strndupW(url_comp.lpszUserName, url_comp.dwUserNameLength);
|
|
|
|
pass = heap_strndupW(url_comp.lpszPassword, url_comp.dwPasswordLength);
|
2009-08-02 00:11:46 +02:00
|
|
|
This->base.connection = InternetConnectW(internet_session, host, url_comp.nPort, user, pass,
|
2009-03-02 03:21:07 +01:00
|
|
|
INTERNET_SERVICE_HTTP, This->https ? INTERNET_FLAG_SECURE : 0, (DWORD_PTR)&This->base);
|
|
|
|
heap_free(pass);
|
|
|
|
heap_free(user);
|
|
|
|
heap_free(host);
|
|
|
|
if(!This->base.connection) {
|
|
|
|
WARN("InternetConnect failed: %d\n", GetLastError());
|
|
|
|
return INET_E_CANNOT_CONNECT;
|
|
|
|
}
|
|
|
|
|
|
|
|
num = sizeof(accept_mimes)/sizeof(accept_mimes[0])-1;
|
|
|
|
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) {
|
|
|
|
static const WCHAR default_accept_mimeW[] = {'*','/','*',0};
|
|
|
|
static const WCHAR *default_accept_mimes[] = {default_accept_mimeW, NULL};
|
|
|
|
|
|
|
|
accept_types = default_accept_mimes;
|
|
|
|
num = 0;
|
|
|
|
}else if(hres == S_OK) {
|
|
|
|
accept_types = (const WCHAR**)accept_mimes;
|
|
|
|
}else {
|
2009-03-02 03:21:07 +01:00
|
|
|
WARN("GetBindString BINDSTRING_ACCEPT_MIMES failed: %08x\n", hres);
|
|
|
|
return INET_E_NO_VALID_MEDIA;
|
|
|
|
}
|
|
|
|
accept_mimes[num] = 0;
|
|
|
|
|
2009-12-09 22:09:22 +01:00
|
|
|
path = heap_alloc((url_comp.dwUrlPathLength+url_comp.dwExtraInfoLength+1)*sizeof(WCHAR));
|
|
|
|
if(url_comp.dwUrlPathLength)
|
|
|
|
memcpy(path, url_comp.lpszUrlPath, url_comp.dwUrlPathLength*sizeof(WCHAR));
|
|
|
|
if(url_comp.dwExtraInfoLength)
|
|
|
|
memcpy(path+url_comp.dwUrlPathLength, url_comp.lpszExtraInfo, url_comp.dwExtraInfoLength*sizeof(WCHAR));
|
|
|
|
path[url_comp.dwUrlPathLength+url_comp.dwExtraInfoLength] = 0;
|
2009-03-02 03:21:07 +01:00
|
|
|
if(This->https)
|
|
|
|
request_flags |= INTERNET_FLAG_SECURE;
|
|
|
|
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,
|
2010-09-08 14:56:08 +02:00
|
|
|
path, NULL, NULL, accept_types, request_flags, (DWORD_PTR)&This->base);
|
2009-03-02 03:21:07 +01:00
|
|
|
heap_free(path);
|
2010-01-04 19:16:20 +01:00
|
|
|
while(num--)
|
|
|
|
CoTaskMemFree(accept_mimes[num]);
|
2009-03-02 03:21:07 +01:00
|
|
|
if (!This->base.request) {
|
|
|
|
WARN("HttpOpenRequest failed: %d\n", GetLastError());
|
|
|
|
return INET_E_RESOURCE_NOT_FOUND;
|
|
|
|
}
|
|
|
|
|
|
|
|
hres = IInternetProtocolSink_QueryInterface(This->base.protocol_sink, &IID_IServiceProvider,
|
|
|
|
(void **)&service_provider);
|
|
|
|
if (hres != S_OK) {
|
|
|
|
WARN("IInternetProtocolSink_QueryInterface IID_IServiceProvider failed: %08x\n", hres);
|
|
|
|
return hres;
|
|
|
|
}
|
|
|
|
|
|
|
|
hres = IServiceProvider_QueryService(service_provider, &IID_IHttpNegotiate,
|
|
|
|
&IID_IHttpNegotiate, (void **)&This->http_negotiate);
|
|
|
|
if (hres != S_OK) {
|
|
|
|
WARN("IServiceProvider_QueryService IID_IHttpNegotiate failed: %08x\n", hres);
|
|
|
|
return hres;
|
|
|
|
}
|
|
|
|
|
|
|
|
hres = IHttpNegotiate_BeginningTransaction(This->http_negotiate, url, wszHeaders,
|
|
|
|
0, &addl_header);
|
|
|
|
if(hres != S_OK) {
|
|
|
|
WARN("IHttpNegotiate_BeginningTransaction failed: %08x\n", hres);
|
|
|
|
IServiceProvider_Release(service_provider);
|
|
|
|
return hres;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(addl_header) {
|
|
|
|
int len_addl_header = strlenW(addl_header);
|
|
|
|
|
|
|
|
This->full_header = heap_alloc(len_addl_header*sizeof(WCHAR)+sizeof(wszHeaders));
|
|
|
|
|
|
|
|
lstrcpyW(This->full_header, addl_header);
|
|
|
|
lstrcpyW(&This->full_header[len_addl_header], wszHeaders);
|
|
|
|
CoTaskMemFree(addl_header);
|
|
|
|
}else {
|
|
|
|
This->full_header = (LPWSTR)wszHeaders;
|
|
|
|
}
|
|
|
|
|
|
|
|
hres = IServiceProvider_QueryService(service_provider, &IID_IHttpNegotiate2,
|
|
|
|
&IID_IHttpNegotiate2, (void **)&http_negotiate2);
|
|
|
|
IServiceProvider_Release(service_provider);
|
|
|
|
if(hres != S_OK) {
|
|
|
|
WARN("IServiceProvider_QueryService IID_IHttpNegotiate2 failed: %08x\n", hres);
|
|
|
|
/* No goto done as per native */
|
|
|
|
}else {
|
|
|
|
len = sizeof(security_id)/sizeof(security_id[0]);
|
|
|
|
hres = IHttpNegotiate2_GetRootSecurityId(http_negotiate2, security_id, &len, 0);
|
|
|
|
IHttpNegotiate2_Release(http_negotiate2);
|
|
|
|
if (hres != S_OK)
|
|
|
|
WARN("IHttpNegotiate2_GetRootSecurityId failed: %08x\n", hres);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* 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)))
|
|
|
|
WARN("InternetSetOption INTERNET_OPTION_SECONDARY_CACHE_KEY failed: %d\n", GetLastError());
|
|
|
|
CoTaskMemFree(post_cookie);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(This->base.bind_info.dwBindVerb != BINDVERB_GET) {
|
|
|
|
/* Native does not use GlobalLock/GlobalUnlock, so we won't either */
|
|
|
|
if (This->base.bind_info.stgmedData.tymed != TYMED_HGLOBAL)
|
|
|
|
WARN("Expected This->base.bind_info.stgmedData.tymed to be TYMED_HGLOBAL, not %d\n",
|
|
|
|
This->base.bind_info.stgmedData.tymed);
|
|
|
|
else
|
|
|
|
optional = (LPWSTR)This->base.bind_info.stgmedData.u.hGlobal;
|
|
|
|
}
|
|
|
|
|
2009-06-04 22:49:56 +02:00
|
|
|
b = TRUE;
|
|
|
|
res = InternetSetOptionW(This->base.request, INTERNET_OPTION_HTTP_DECODING, &b, sizeof(b));
|
|
|
|
if(!res)
|
|
|
|
WARN("InternetSetOption(INTERNET_OPTION_HTTP_DECODING) failed: %08x\n", GetLastError());
|
|
|
|
|
2009-03-02 03:21:07 +01:00
|
|
|
res = HttpSendRequestW(This->base.request, This->full_header, lstrlenW(This->full_header),
|
|
|
|
optional, optional ? This->base.bind_info.cbstgmedData : 0);
|
|
|
|
if(!res && GetLastError() != ERROR_IO_PENDING) {
|
|
|
|
WARN("HttpSendRequest failed: %d\n", GetLastError());
|
|
|
|
return INET_E_DOWNLOAD_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2009-03-02 03:20:46 +01:00
|
|
|
static HRESULT HttpProtocol_start_downloading(Protocol *prot)
|
|
|
|
{
|
|
|
|
HttpProtocol *This = ASYNCPROTOCOL_THIS(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;
|
|
|
|
|
|
|
|
static const WCHAR wszDefaultContentType[] =
|
|
|
|
{'t','e','x','t','/','h','t','m','l',0};
|
|
|
|
|
|
|
|
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) {
|
|
|
|
LPWSTR response_headers = query_http_info(This, HTTP_QUERY_RAW_HEADERS_CRLF);
|
|
|
|
if(response_headers) {
|
|
|
|
hres = IHttpNegotiate_OnResponse(This->http_negotiate, status_code, response_headers,
|
|
|
|
NULL, NULL);
|
|
|
|
heap_free(response_headers);
|
|
|
|
if (hres != S_OK) {
|
|
|
|
WARN("IHttpNegotiate_OnResponse failed: %08x\n", hres);
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}else {
|
|
|
|
WARN("HttpQueryInfo failed: %d\n", GetLastError());
|
|
|
|
}
|
|
|
|
|
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 */
|
|
|
|
LPWSTR p = strchrW(content_type, ';');
|
|
|
|
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 {
|
|
|
|
WARN("HttpQueryInfo failed: %d\n", GetLastError());
|
|
|
|
IInternetProtocolSink_ReportProgress(This->base.protocol_sink,
|
|
|
|
(This->base.bindf & BINDF_FROMURLMON)
|
|
|
|
? BINDSTATUS_MIMETYPEAVAILABLE : BINDSTATUS_RAWMIMETYPE,
|
|
|
|
wszDefaultContentType);
|
|
|
|
}
|
|
|
|
|
|
|
|
content_length = query_http_info(This, HTTP_QUERY_CONTENT_LENGTH);
|
|
|
|
if(content_length) {
|
|
|
|
This->base.content_length = atoiW(content_length);
|
|
|
|
heap_free(content_length);
|
|
|
|
}
|
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2009-03-02 03:20:09 +01:00
|
|
|
static void HttpProtocol_close_connection(Protocol *prot)
|
|
|
|
{
|
|
|
|
HttpProtocol *This = ASYNCPROTOCOL_THIS(prot);
|
|
|
|
|
|
|
|
if(This->http_negotiate) {
|
|
|
|
IHttpNegotiate_Release(This->http_negotiate);
|
|
|
|
This->http_negotiate = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(This->full_header) {
|
|
|
|
if(This->full_header != wszHeaders)
|
|
|
|
heap_free(This->full_header);
|
|
|
|
This->full_header = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#undef ASYNCPROTOCOL_THIS
|
|
|
|
|
|
|
|
static const ProtocolVtbl AsyncProtocolVtbl = {
|
2009-03-02 03:21:07 +01:00
|
|
|
HttpProtocol_open_request,
|
2009-03-02 03:20:46 +01:00
|
|
|
HttpProtocol_start_downloading,
|
2009-03-02 03:20:09 +01:00
|
|
|
HttpProtocol_close_connection
|
|
|
|
};
|
2007-07-10 17:52:03 +02:00
|
|
|
|
2009-05-18 18:31:03 +02:00
|
|
|
#define PROTOCOL_THIS(iface) DEFINE_THIS(HttpProtocol, IInternetProtocol, iface)
|
2005-09-14 17:38:26 +02:00
|
|
|
|
|
|
|
static HRESULT WINAPI HttpProtocol_QueryInterface(IInternetProtocol *iface, REFIID riid, void **ppv)
|
|
|
|
{
|
|
|
|
HttpProtocol *This = PROTOCOL_THIS(iface);
|
|
|
|
|
|
|
|
*ppv = NULL;
|
|
|
|
if(IsEqualGUID(&IID_IUnknown, riid)) {
|
|
|
|
TRACE("(%p)->(IID_IUnknown %p)\n", This, ppv);
|
|
|
|
*ppv = PROTOCOL(This);
|
|
|
|
}else if(IsEqualGUID(&IID_IInternetProtocolRoot, riid)) {
|
|
|
|
TRACE("(%p)->(IID_IInternetProtocolRoot %p)\n", This, ppv);
|
|
|
|
*ppv = PROTOCOL(This);
|
|
|
|
}else if(IsEqualGUID(&IID_IInternetProtocol, riid)) {
|
|
|
|
TRACE("(%p)->(IID_IInternetProtocol %p)\n", This, ppv);
|
|
|
|
*ppv = PROTOCOL(This);
|
2005-11-09 11:28:26 +01:00
|
|
|
}else if(IsEqualGUID(&IID_IInternetPriority, riid)) {
|
|
|
|
TRACE("(%p)->(IID_IInternetPriority %p)\n", This, ppv);
|
|
|
|
*ppv = PRIORITY(This);
|
2009-03-29 21:30:29 +02:00
|
|
|
}else if(IsEqualGUID(&IID_IWinInetInfo, riid)) {
|
|
|
|
TRACE("(%p)->(IID_IWinInetInfo %p)\n", This, ppv);
|
|
|
|
*ppv = INETHTTPINFO(This);
|
|
|
|
}else if(IsEqualGUID(&IID_IWinInetHttpInfo, riid)) {
|
|
|
|
TRACE("(%p)->(IID_IWinInetHttpInfo %p)\n", This, ppv);
|
|
|
|
*ppv = INETHTTPINFO(This);
|
2005-09-14 17:38:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if(*ppv) {
|
|
|
|
IInternetProtocol_AddRef(iface);
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
WARN("not supported interface %s\n", debugstr_guid(riid));
|
|
|
|
return E_NOINTERFACE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI HttpProtocol_AddRef(IInternetProtocol *iface)
|
|
|
|
{
|
|
|
|
HttpProtocol *This = PROTOCOL_THIS(iface);
|
|
|
|
LONG ref = InterlockedIncrement(&This->ref);
|
2006-10-05 23:49:11 +02:00
|
|
|
TRACE("(%p) ref=%d\n", This, ref);
|
2005-09-14 17:38:26 +02:00
|
|
|
return ref;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI HttpProtocol_Release(IInternetProtocol *iface)
|
|
|
|
{
|
|
|
|
HttpProtocol *This = PROTOCOL_THIS(iface);
|
|
|
|
LONG ref = InterlockedDecrement(&This->ref);
|
|
|
|
|
2006-10-05 23:49:11 +02:00
|
|
|
TRACE("(%p) ref=%d\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;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI HttpProtocol_Start(IInternetProtocol *iface, LPCWSTR szUrl,
|
|
|
|
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
|
|
|
{
|
|
|
|
HttpProtocol *This = PROTOCOL_THIS(iface);
|
2007-07-10 17:52:03 +02:00
|
|
|
|
2009-01-11 21:19:46 +01:00
|
|
|
static const WCHAR httpW[] = {'h','t','t','p',':'};
|
|
|
|
static const WCHAR httpsW[] = {'h','t','t','p','s',':'};
|
2007-07-10 17:52:03 +02:00
|
|
|
|
2009-04-01 03:42:37 +02:00
|
|
|
TRACE("(%p)->(%s %p %p %08x %lx)\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
|
|
|
|
2009-01-11 21:19:46 +01:00
|
|
|
if(This->https
|
|
|
|
? strncmpW(szUrl, httpsW, sizeof(httpsW)/sizeof(WCHAR))
|
|
|
|
: strncmpW(szUrl, httpW, sizeof(httpW)/sizeof(WCHAR)))
|
2009-03-02 03:21:07 +01:00
|
|
|
return MK_E_SYNTAX;
|
2007-07-10 17:52:03 +02:00
|
|
|
|
2009-03-02 03:21:07 +01:00
|
|
|
return protocol_start(&This->base, PROTOCOL(This), szUrl, pOIProtSink, pOIBindInfo);
|
2005-09-14 17:38:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI HttpProtocol_Continue(IInternetProtocol *iface, PROTOCOLDATA *pProtocolData)
|
|
|
|
{
|
|
|
|
HttpProtocol *This = PROTOCOL_THIS(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
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI HttpProtocol_Abort(IInternetProtocol *iface, HRESULT hrReason,
|
|
|
|
DWORD dwOptions)
|
|
|
|
{
|
|
|
|
HttpProtocol *This = PROTOCOL_THIS(iface);
|
2006-10-05 23:49:11 +02:00
|
|
|
FIXME("(%p)->(%08x %08x)\n", This, hrReason, dwOptions);
|
2005-09-14 17:38:26 +02:00
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI HttpProtocol_Terminate(IInternetProtocol *iface, DWORD dwOptions)
|
|
|
|
{
|
|
|
|
HttpProtocol *This = PROTOCOL_THIS(iface);
|
2007-07-19 03:00:01 +02:00
|
|
|
|
|
|
|
TRACE("(%p)->(%08x)\n", This, dwOptions);
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI HttpProtocol_Suspend(IInternetProtocol *iface)
|
|
|
|
{
|
|
|
|
HttpProtocol *This = PROTOCOL_THIS(iface);
|
|
|
|
FIXME("(%p)\n", This);
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI HttpProtocol_Resume(IInternetProtocol *iface)
|
|
|
|
{
|
|
|
|
HttpProtocol *This = PROTOCOL_THIS(iface);
|
|
|
|
FIXME("(%p)\n", This);
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI HttpProtocol_Read(IInternetProtocol *iface, void *pv,
|
|
|
|
ULONG cb, ULONG *pcbRead)
|
|
|
|
{
|
|
|
|
HttpProtocol *This = PROTOCOL_THIS(iface);
|
2007-07-10 17:52:03 +02:00
|
|
|
|
|
|
|
TRACE("(%p)->(%p %u %p)\n", This, pv, cb, pcbRead);
|
|
|
|
|
2009-03-02 03:20:26 +01:00
|
|
|
return protocol_read(&This->base, pv, cb, pcbRead);
|
2005-09-14 17:38:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI HttpProtocol_Seek(IInternetProtocol *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
|
|
|
{
|
|
|
|
HttpProtocol *This = PROTOCOL_THIS(iface);
|
2006-10-05 23:49:11 +02:00
|
|
|
FIXME("(%p)->(%d %d %p)\n", This, dlibMove.u.LowPart, dwOrigin, plibNewPosition);
|
2005-09-14 17:38:26 +02:00
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI HttpProtocol_LockRequest(IInternetProtocol *iface, DWORD dwOptions)
|
|
|
|
{
|
|
|
|
HttpProtocol *This = PROTOCOL_THIS(iface);
|
2007-07-10 17:52:03 +02:00
|
|
|
|
|
|
|
TRACE("(%p)->(%08x)\n", This, dwOptions);
|
|
|
|
|
2009-03-02 03:19:44 +01:00
|
|
|
return protocol_lock_request(&This->base);
|
2005-09-14 17:38:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI HttpProtocol_UnlockRequest(IInternetProtocol *iface)
|
|
|
|
{
|
|
|
|
HttpProtocol *This = PROTOCOL_THIS(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
|
|
|
}
|
|
|
|
|
|
|
|
#undef PROTOCOL_THIS
|
|
|
|
|
2009-03-02 03:21:22 +01:00
|
|
|
static const IInternetProtocolVtbl HttpProtocolVtbl = {
|
|
|
|
HttpProtocol_QueryInterface,
|
|
|
|
HttpProtocol_AddRef,
|
|
|
|
HttpProtocol_Release,
|
|
|
|
HttpProtocol_Start,
|
|
|
|
HttpProtocol_Continue,
|
|
|
|
HttpProtocol_Abort,
|
|
|
|
HttpProtocol_Terminate,
|
|
|
|
HttpProtocol_Suspend,
|
|
|
|
HttpProtocol_Resume,
|
|
|
|
HttpProtocol_Read,
|
|
|
|
HttpProtocol_Seek,
|
|
|
|
HttpProtocol_LockRequest,
|
|
|
|
HttpProtocol_UnlockRequest
|
|
|
|
};
|
|
|
|
|
2005-11-09 11:28:26 +01:00
|
|
|
#define PRIORITY_THIS(iface) DEFINE_THIS(HttpProtocol, InternetPriority, iface)
|
|
|
|
|
|
|
|
static HRESULT WINAPI HttpPriority_QueryInterface(IInternetPriority *iface, REFIID riid, void **ppv)
|
|
|
|
{
|
|
|
|
HttpProtocol *This = PRIORITY_THIS(iface);
|
|
|
|
return IInternetProtocol_QueryInterface(PROTOCOL(This), riid, ppv);
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI HttpPriority_AddRef(IInternetPriority *iface)
|
|
|
|
{
|
|
|
|
HttpProtocol *This = PRIORITY_THIS(iface);
|
|
|
|
return IInternetProtocol_AddRef(PROTOCOL(This));
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI HttpPriority_Release(IInternetPriority *iface)
|
|
|
|
{
|
|
|
|
HttpProtocol *This = PRIORITY_THIS(iface);
|
|
|
|
return IInternetProtocol_Release(PROTOCOL(This));
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI HttpPriority_SetPriority(IInternetPriority *iface, LONG nPriority)
|
|
|
|
{
|
|
|
|
HttpProtocol *This = PRIORITY_THIS(iface);
|
|
|
|
|
2006-10-05 23:49:11 +02:00
|
|
|
TRACE("(%p)->(%d)\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)
|
|
|
|
{
|
|
|
|
HttpProtocol *This = PRIORITY_THIS(iface);
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
#undef PRIORITY_THIS
|
|
|
|
|
|
|
|
static const IInternetPriorityVtbl HttpPriorityVtbl = {
|
|
|
|
HttpPriority_QueryInterface,
|
|
|
|
HttpPriority_AddRef,
|
|
|
|
HttpPriority_Release,
|
|
|
|
HttpPriority_SetPriority,
|
|
|
|
HttpPriority_GetPriority
|
|
|
|
};
|
|
|
|
|
2009-03-29 21:30:29 +02:00
|
|
|
#define INETINFO_THIS(iface) DEFINE_THIS(HttpProtocol, WinInetHttpInfo, iface)
|
|
|
|
|
|
|
|
static HRESULT WINAPI HttpInfo_QueryInterface(IWinInetHttpInfo *iface, REFIID riid, void **ppv)
|
|
|
|
{
|
|
|
|
HttpProtocol *This = INETINFO_THIS(iface);
|
|
|
|
return IBinding_QueryInterface(PROTOCOL(This), riid, ppv);
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI HttpInfo_AddRef(IWinInetHttpInfo *iface)
|
|
|
|
{
|
|
|
|
HttpProtocol *This = INETINFO_THIS(iface);
|
|
|
|
return IBinding_AddRef(PROTOCOL(This));
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI HttpInfo_Release(IWinInetHttpInfo *iface)
|
|
|
|
{
|
|
|
|
HttpProtocol *This = INETINFO_THIS(iface);
|
|
|
|
return IBinding_Release(PROTOCOL(This));
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI HttpInfo_QueryOption(IWinInetHttpInfo *iface, DWORD dwOption,
|
|
|
|
void *pBuffer, DWORD *pcbBuffer)
|
|
|
|
{
|
|
|
|
HttpProtocol *This = INETINFO_THIS(iface);
|
|
|
|
FIXME("(%p)->(%x %p %p)\n", This, dwOption, pBuffer, pcbBuffer);
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI HttpInfo_QueryInfo(IWinInetHttpInfo *iface, DWORD dwOption,
|
|
|
|
void *pBuffer, DWORD *pcbBuffer, DWORD *pdwFlags, DWORD *pdwReserved)
|
|
|
|
{
|
|
|
|
HttpProtocol *This = INETINFO_THIS(iface);
|
|
|
|
FIXME("(%p)->(%x %p %p %p %p)\n", This, dwOption, pBuffer, pcbBuffer, pdwFlags, pdwReserved);
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
#undef INETINFO_THIS
|
|
|
|
|
|
|
|
static const IWinInetHttpInfoVtbl WinInetHttpInfoVtbl = {
|
|
|
|
HttpInfo_QueryInterface,
|
|
|
|
HttpInfo_AddRef,
|
|
|
|
HttpInfo_Release,
|
|
|
|
HttpInfo_QueryOption,
|
|
|
|
HttpInfo_QueryInfo
|
|
|
|
};
|
|
|
|
|
2009-02-07 16:06:11 +01:00
|
|
|
static HRESULT create_http_protocol(BOOL https, 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;
|
2009-05-18 18:31:03 +02:00
|
|
|
ret->lpIInternetProtocolVtbl = &HttpProtocolVtbl;
|
|
|
|
ret->lpInternetPriorityVtbl = &HttpPriorityVtbl;
|
|
|
|
ret->lpWinInetHttpInfoVtbl = &WinInetHttpInfoVtbl;
|
2009-01-11 21:19:46 +01:00
|
|
|
|
|
|
|
ret->https = https;
|
2007-07-10 17:52:03 +02:00
|
|
|
ret->ref = 1;
|
2005-11-09 11:28:26 +01:00
|
|
|
|
2005-09-14 17:38:26 +02:00
|
|
|
*ppobj = PROTOCOL(ret);
|
|
|
|
|
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
|
|
|
|
2009-01-11 21:19:46 +01:00
|
|
|
HRESULT HttpProtocol_Construct(IUnknown *pUnkOuter, LPVOID *ppobj)
|
|
|
|
{
|
|
|
|
TRACE("(%p %p)\n", pUnkOuter, ppobj);
|
|
|
|
|
|
|
|
return create_http_protocol(FALSE, ppobj);
|
|
|
|
}
|
|
|
|
|
2007-11-04 17:09:20 +01:00
|
|
|
HRESULT HttpSProtocol_Construct(IUnknown *pUnkOuter, LPVOID *ppobj)
|
|
|
|
{
|
2009-01-11 21:19:46 +01:00
|
|
|
TRACE("(%p %p)\n", pUnkOuter, ppobj);
|
|
|
|
|
|
|
|
return create_http_protocol(TRUE, ppobj);
|
2007-11-04 17:09:20 +01:00
|
|
|
}
|