2 * Copyright 2005 Jacek Caban
3 * Copyright 2007 Misha Koshelev
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
20 #define NONAMELESSUNION
22 #include "urlmon_main.h"
25 #define NO_SHLWAPI_REG
28 #include "wine/debug.h"
30 WINE_DEFAULT_DEBUG_CHANNEL(urlmon
);
35 IUnknown IUnknown_inner
;
36 IInternetProtocolEx IInternetProtocolEx_iface
;
37 IInternetPriority IInternetPriority_iface
;
38 IWinInetHttpInfo IWinInetHttpInfo_iface
;
41 IHttpNegotiate
*http_negotiate
;
48 static inline HttpProtocol
*impl_from_IUnknown(IUnknown
*iface
)
50 return CONTAINING_RECORD(iface
, HttpProtocol
, IUnknown_inner
);
53 static inline HttpProtocol
*impl_from_IInternetProtocolEx(IInternetProtocolEx
*iface
)
55 return CONTAINING_RECORD(iface
, HttpProtocol
, IInternetProtocolEx_iface
);
58 static inline HttpProtocol
*impl_from_IInternetPriority(IInternetPriority
*iface
)
60 return CONTAINING_RECORD(iface
, HttpProtocol
, IInternetPriority_iface
);
63 static inline HttpProtocol
*impl_from_IWinInetHttpInfo(IWinInetHttpInfo
*iface
)
65 return CONTAINING_RECORD(iface
, HttpProtocol
, IWinInetHttpInfo_iface
);
68 static const WCHAR default_headersW
[] = L
"Accept-Encoding: gzip, deflate";
70 static LPWSTR
query_http_info(HttpProtocol
*This
, DWORD option
)
76 res
= HttpQueryInfoW(This
->base
.request
, option
, NULL
, &len
, NULL
);
77 if (!res
&& GetLastError() == ERROR_INSUFFICIENT_BUFFER
) {
78 ret
= heap_alloc(len
);
79 res
= HttpQueryInfoW(This
->base
.request
, option
, ret
, &len
, NULL
);
82 TRACE("HttpQueryInfoW(%ld) failed: %08lx\n", option
, GetLastError());
90 static inline BOOL
set_security_flag(HttpProtocol
*This
, DWORD flags
)
94 res
= InternetSetOptionW(This
->base
.request
, INTERNET_OPTION_SECURITY_FLAGS
, &flags
, sizeof(flags
));
96 ERR("Failed to set security flags: %lx\n", flags
);
101 static inline HRESULT
internet_error_to_hres(DWORD error
)
105 case ERROR_INTERNET_SEC_CERT_DATE_INVALID
:
106 case ERROR_INTERNET_SEC_CERT_CN_INVALID
:
107 case ERROR_INTERNET_INVALID_CA
:
108 case ERROR_INTERNET_CLIENT_AUTH_CERT_NEEDED
:
109 case ERROR_INTERNET_SEC_INVALID_CERT
:
110 case ERROR_INTERNET_SEC_CERT_ERRORS
:
111 case ERROR_INTERNET_SEC_CERT_REV_FAILED
:
112 case ERROR_INTERNET_SEC_CERT_NO_REV
:
113 case ERROR_INTERNET_SEC_CERT_REVOKED
:
114 return INET_E_INVALID_CERTIFICATE
;
115 case ERROR_INTERNET_HTTP_TO_HTTPS_ON_REDIR
:
116 case ERROR_INTERNET_HTTPS_TO_HTTP_ON_REDIR
:
117 case ERROR_HTTP_REDIRECT_NEEDS_CONFIRMATION
:
118 return INET_E_REDIRECT_FAILED
;
120 return INET_E_DOWNLOAD_FAILURE
;
124 static HRESULT
handle_http_error(HttpProtocol
*This
, DWORD error
)
126 IServiceProvider
*serv_prov
;
127 IWindowForBindingUI
*wfb_ui
;
128 IHttpSecurity
*http_security
;
129 BOOL security_problem
;
135 TRACE("(%p %lu)\n", This
, error
);
138 case ERROR_INTERNET_SEC_CERT_DATE_INVALID
:
139 case ERROR_INTERNET_SEC_CERT_CN_INVALID
:
140 case ERROR_INTERNET_HTTP_TO_HTTPS_ON_REDIR
:
141 case ERROR_INTERNET_HTTPS_TO_HTTP_ON_REDIR
:
142 case ERROR_INTERNET_INVALID_CA
:
143 case ERROR_INTERNET_CLIENT_AUTH_CERT_NEEDED
:
144 case ERROR_INTERNET_SEC_INVALID_CERT
:
145 case ERROR_INTERNET_SEC_CERT_ERRORS
:
146 case ERROR_INTERNET_SEC_CERT_REV_FAILED
:
147 case ERROR_INTERNET_SEC_CERT_NO_REV
:
148 case ERROR_INTERNET_SEC_CERT_REVOKED
:
149 case ERROR_HTTP_REDIRECT_NEEDS_CONFIRMATION
:
150 security_problem
= TRUE
;
153 security_problem
= FALSE
;
156 hres
= IInternetProtocolSink_QueryInterface(This
->base
.protocol_sink
, &IID_IServiceProvider
,
159 ERR("Failed to get IServiceProvider.\n");
163 if(security_problem
) {
164 hres
= IServiceProvider_QueryService(serv_prov
, &IID_IHttpSecurity
, &IID_IHttpSecurity
,
165 (void**)&http_security
);
166 if(SUCCEEDED(hres
)) {
167 hres
= IHttpSecurity_OnSecurityProblem(http_security
, error
);
168 IHttpSecurity_Release(http_security
);
170 TRACE("OnSecurityProblem returned %08lx\n", hres
);
176 IServiceProvider_Release(serv_prov
);
179 if(error
== ERROR_INTERNET_SEC_CERT_DATE_INVALID
)
180 res
= set_security_flag(This
, SECURITY_FLAG_IGNORE_CERT_DATE_INVALID
);
181 else if(error
== ERROR_INTERNET_SEC_CERT_CN_INVALID
)
182 res
= set_security_flag(This
, SECURITY_FLAG_IGNORE_CERT_CN_INVALID
);
183 else if(error
== ERROR_INTERNET_INVALID_CA
)
184 res
= set_security_flag(This
, SECURITY_FLAG_IGNORE_UNKNOWN_CA
);
189 FIXME("Don't know how to ignore error %ld\n", error
);
195 if(hres
== RPC_E_RETRY
)
198 return internet_error_to_hres(error
);
204 case ERROR_INTERNET_SEC_CERT_REV_FAILED
:
205 if(hres
!= S_FALSE
) {
206 /* Silently ignore the error. We will get more detailed error from wininet anyway. */
207 set_security_flag(This
, SECURITY_FLAG_IGNORE_REVOCATION
);
213 hres
= IServiceProvider_QueryService(serv_prov
, &IID_IWindowForBindingUI
, &IID_IWindowForBindingUI
, (void**)&wfb_ui
);
214 if(SUCCEEDED(hres
)) {
215 const IID
*iid_reason
;
218 iid_reason
= &IID_IHttpSecurity
;
219 else if(error
== ERROR_INTERNET_INCORRECT_PASSWORD
)
220 iid_reason
= &IID_IAuthenticate
;
222 iid_reason
= &IID_IWindowForBindingUI
;
224 hres
= IWindowForBindingUI_GetWindow(wfb_ui
, iid_reason
, &hwnd
);
225 IWindowForBindingUI_Release(wfb_ui
);
228 if(FAILED(hres
)) hwnd
= NULL
;
230 dlg_flags
= FLAGS_ERROR_UI_FLAGS_CHANGE_OPTIONS
| FLAGS_ERROR_UI_FLAGS_GENERATE_DATA
;
231 if(This
->base
.bindf
& BINDF_NO_UI
)
232 dlg_flags
|= FLAGS_ERROR_UI_FLAGS_NO_UI
;
234 res
= InternetErrorDlg(hwnd
, This
->base
.request
, error
, dlg_flags
, NULL
);
235 hres
= res
== ERROR_INTERNET_FORCE_RETRY
|| res
== ERROR_SUCCESS
? RPC_E_RETRY
: internet_error_to_hres(error
);
238 IServiceProvider_Release(serv_prov
);
242 static ULONG
send_http_request(HttpProtocol
*This
)
244 INTERNET_BUFFERSW send_buffer
= {sizeof(INTERNET_BUFFERSW
)};
247 send_buffer
.lpcszHeader
= This
->full_header
;
248 send_buffer
.dwHeadersLength
= send_buffer
.dwHeadersTotal
= lstrlenW(This
->full_header
);
250 if(This
->base
.bind_info
.dwBindVerb
!= BINDVERB_GET
) {
251 switch(This
->base
.bind_info
.stgmedData
.tymed
) {
253 /* Native does not use GlobalLock/GlobalUnlock, so we won't either */
254 send_buffer
.lpvBuffer
= This
->base
.bind_info
.stgmedData
.u
.hGlobal
;
255 send_buffer
.dwBufferLength
= send_buffer
.dwBufferTotal
= This
->base
.bind_info
.cbstgmedData
;
257 case TYMED_ISTREAM
: {
258 LARGE_INTEGER offset
;
260 send_buffer
.dwBufferTotal
= This
->base
.bind_info
.cbstgmedData
;
261 if(!This
->base
.post_stream
) {
262 This
->base
.post_stream
= This
->base
.bind_info
.stgmedData
.u
.pstm
;
263 IStream_AddRef(This
->base
.post_stream
);
267 IStream_Seek(This
->base
.post_stream
, offset
, STREAM_SEEK_SET
, NULL
);
271 FIXME("Unsupported This->base.bind_info.stgmedData.tymed %ld\n", This
->base
.bind_info
.stgmedData
.tymed
);
275 if(This
->base
.post_stream
)
276 res
= HttpSendRequestExW(This
->base
.request
, &send_buffer
, NULL
, 0, 0);
278 res
= HttpSendRequestW(This
->base
.request
, send_buffer
.lpcszHeader
, send_buffer
.dwHeadersLength
,
279 send_buffer
.lpvBuffer
, send_buffer
.dwBufferLength
);
281 return res
? 0 : GetLastError();
284 static inline HttpProtocol
*impl_from_Protocol(Protocol
*prot
)
286 return CONTAINING_RECORD(prot
, HttpProtocol
, base
);
289 static HRESULT
HttpProtocol_open_request(Protocol
*prot
, IUri
*uri
, DWORD request_flags
,
290 HINTERNET internet_session
, IInternetBindInfo
*bind_info
)
292 HttpProtocol
*This
= impl_from_Protocol(prot
);
293 WCHAR
*addl_header
= NULL
, *post_cookie
= NULL
, *rootdoc_url
= NULL
;
294 IServiceProvider
*service_provider
= NULL
;
295 IHttpNegotiate2
*http_negotiate2
= NULL
;
296 BSTR url
, host
, user
, pass
, path
;
297 LPOLESTR accept_mimes
[257];
298 const WCHAR
**accept_types
;
299 BYTE security_id
[512];
300 DWORD len
, port
, flags
;
305 static const WCHAR wszBindVerb
[BINDVERB_CUSTOM
][5] =
310 hres
= IUri_GetPort(uri
, &port
);
314 hres
= IUri_GetHost(uri
, &host
);
318 hres
= IUri_GetUserName(uri
, &user
);
319 if(SUCCEEDED(hres
)) {
320 hres
= IUri_GetPassword(uri
, &pass
);
322 if(SUCCEEDED(hres
)) {
323 This
->base
.connection
= InternetConnectW(internet_session
, host
, port
, user
, pass
,
324 INTERNET_SERVICE_HTTP
, This
->https
? INTERNET_FLAG_SECURE
: 0, (DWORD_PTR
)&This
->base
);
332 if(!This
->base
.connection
) {
333 WARN("InternetConnect failed: %ld\n", GetLastError());
334 return INET_E_CANNOT_CONNECT
;
338 hres
= IInternetBindInfo_GetBindString(bind_info
, BINDSTRING_ROOTDOC_URL
, &rootdoc_url
, 1, &num
);
339 if(hres
== S_OK
&& num
) {
340 FIXME("Use root doc URL %s\n", debugstr_w(rootdoc_url
));
341 CoTaskMemFree(rootdoc_url
);
344 num
= ARRAY_SIZE(accept_mimes
) - 1;
345 hres
= IInternetBindInfo_GetBindString(bind_info
, BINDSTRING_ACCEPT_MIMES
, accept_mimes
, num
, &num
);
346 if(hres
== INET_E_USE_DEFAULT_SETTING
) {
347 static const WCHAR
*default_accept_mimes
[] = {L
"*/*", NULL
};
349 accept_types
= default_accept_mimes
;
351 }else if(hres
== S_OK
) {
352 accept_types
= (const WCHAR
**)accept_mimes
;
354 WARN("GetBindString BINDSTRING_ACCEPT_MIMES failed: %08lx\n", hres
);
355 return INET_E_NO_VALID_MEDIA
;
357 accept_mimes
[num
] = 0;
360 request_flags
|= INTERNET_FLAG_SECURE
;
362 hres
= IUri_GetPathAndQuery(uri
, &path
);
363 if(SUCCEEDED(hres
)) {
364 This
->base
.request
= HttpOpenRequestW(This
->base
.connection
,
365 This
->base
.bind_info
.dwBindVerb
< BINDVERB_CUSTOM
366 ? wszBindVerb
[This
->base
.bind_info
.dwBindVerb
] : This
->base
.bind_info
.szCustomVerb
,
367 path
, NULL
, NULL
, accept_types
, request_flags
, (DWORD_PTR
)&This
->base
);
371 CoTaskMemFree(accept_mimes
[num
]);
374 if (!This
->base
.request
) {
375 WARN("HttpOpenRequest failed: %ld\n", GetLastError());
376 return INET_E_RESOURCE_NOT_FOUND
;
379 hres
= IInternetProtocolSink_QueryInterface(This
->base
.protocol_sink
, &IID_IServiceProvider
,
380 (void **)&service_provider
);
382 WARN("IInternetProtocolSink_QueryInterface IID_IServiceProvider failed: %08lx\n", hres
);
386 hres
= IServiceProvider_QueryService(service_provider
, &IID_IHttpNegotiate
,
387 &IID_IHttpNegotiate
, (void **)&This
->http_negotiate
);
389 WARN("IServiceProvider_QueryService IID_IHttpNegotiate failed: %08lx\n", hres
);
390 IServiceProvider_Release(service_provider
);
394 hres
= IUri_GetAbsoluteUri(uri
, &url
);
396 IServiceProvider_Release(service_provider
);
400 hres
= IHttpNegotiate_BeginningTransaction(This
->http_negotiate
, url
, default_headersW
,
404 WARN("IHttpNegotiate_BeginningTransaction failed: %08lx\n", hres
);
405 IServiceProvider_Release(service_provider
);
409 len
= addl_header
? lstrlenW(addl_header
) : 0;
411 This
->full_header
= heap_alloc(len
*sizeof(WCHAR
)+sizeof(default_headersW
));
412 if(!This
->full_header
) {
413 IServiceProvider_Release(service_provider
);
414 return E_OUTOFMEMORY
;
418 memcpy(This
->full_header
, addl_header
, len
*sizeof(WCHAR
));
419 CoTaskMemFree(addl_header
);
420 memcpy(This
->full_header
+len
, default_headersW
, sizeof(default_headersW
));
422 hres
= IServiceProvider_QueryService(service_provider
, &IID_IHttpNegotiate2
,
423 &IID_IHttpNegotiate2
, (void **)&http_negotiate2
);
424 IServiceProvider_Release(service_provider
);
426 WARN("IServiceProvider_QueryService IID_IHttpNegotiate2 failed: %08lx\n", hres
);
427 /* No goto done as per native */
429 len
= ARRAY_SIZE(security_id
);
430 hres
= IHttpNegotiate2_GetRootSecurityId(http_negotiate2
, security_id
, &len
, 0);
431 IHttpNegotiate2_Release(http_negotiate2
);
433 WARN("IHttpNegotiate2_GetRootSecurityId failed: %08lx\n", hres
);
436 /* FIXME: Handle security_id. Native calls undocumented function IsHostInProxyBypassList. */
438 if(This
->base
.bind_info
.dwBindVerb
== BINDVERB_POST
) {
440 hres
= IInternetBindInfo_GetBindString(bind_info
, BINDSTRING_POST_COOKIE
, &post_cookie
, 1, &num
);
441 if(hres
== S_OK
&& num
) {
442 if(!InternetSetOptionW(This
->base
.request
, INTERNET_OPTION_SECONDARY_CACHE_KEY
,
443 post_cookie
, lstrlenW(post_cookie
)))
444 WARN("InternetSetOption INTERNET_OPTION_SECONDARY_CACHE_KEY failed: %ld\n", GetLastError());
445 CoTaskMemFree(post_cookie
);
449 flags
= INTERNET_ERROR_MASK_COMBINED_SEC_CERT
;
450 res
= InternetSetOptionW(This
->base
.request
, INTERNET_OPTION_ERROR_MASK
, &flags
, sizeof(flags
));
452 WARN("InternetSetOption(INTERNET_OPTION_ERROR_MASK) failed: %lu\n", GetLastError());
455 res
= InternetSetOptionW(This
->base
.request
, INTERNET_OPTION_HTTP_DECODING
, &b
, sizeof(b
));
457 WARN("InternetSetOption(INTERNET_OPTION_HTTP_DECODING) failed: %lu\n", GetLastError());
460 error
= send_http_request(This
);
463 case ERROR_IO_PENDING
:
467 * If sending response ended synchronously, it means that we have the whole data
468 * available locally (most likely in cache).
470 return protocol_syncbinding(&This
->base
);
472 hres
= handle_http_error(This
, error
);
474 } while(hres
== RPC_E_RETRY
);
476 WARN("HttpSendRequest failed: %ld\n", error
);
480 static HRESULT
HttpProtocol_end_request(Protocol
*protocol
)
484 res
= HttpEndRequestW(protocol
->request
, NULL
, 0, 0);
485 if(!res
&& GetLastError() != ERROR_IO_PENDING
) {
486 FIXME("HttpEndRequest failed: %lu\n", GetLastError());
493 static BOOL
is_redirect_response(DWORD status_code
)
495 switch(status_code
) {
496 case HTTP_STATUS_REDIRECT
:
497 case HTTP_STATUS_MOVED
:
498 case HTTP_STATUS_REDIRECT_KEEP_VERB
:
499 case HTTP_STATUS_REDIRECT_METHOD
:
505 static HRESULT
HttpProtocol_start_downloading(Protocol
*prot
)
507 HttpProtocol
*This
= impl_from_Protocol(prot
);
508 LPWSTR content_type
, content_length
, ranges
;
509 DWORD len
= sizeof(DWORD
);
514 if(!This
->http_negotiate
) {
515 WARN("Expected IHttpNegotiate pointer to be non-NULL\n");
519 res
= HttpQueryInfoW(This
->base
.request
, HTTP_QUERY_STATUS_CODE
| HTTP_QUERY_FLAG_NUMBER
,
520 &status_code
, &len
, NULL
);
522 WCHAR
*response_headers
;
524 if((This
->base
.bind_info
.dwOptions
& BINDINFO_OPTIONS_DISABLEAUTOREDIRECTS
) && is_redirect_response(status_code
)) {
527 TRACE("Got redirect with disabled auto redirects\n");
529 location
= query_http_info(This
, HTTP_QUERY_LOCATION
);
530 This
->base
.flags
|= FLAG_RESULT_REPORTED
| FLAG_LAST_DATA_REPORTED
;
531 IInternetProtocolSink_ReportResult(This
->base
.protocol_sink
, INET_E_REDIRECT_FAILED
, 0, location
);
533 return INET_E_REDIRECT_FAILED
;
536 response_headers
= query_http_info(This
, HTTP_QUERY_RAW_HEADERS_CRLF
);
537 if(response_headers
) {
538 hres
= IHttpNegotiate_OnResponse(This
->http_negotiate
, status_code
, response_headers
,
540 heap_free(response_headers
);
542 WARN("IHttpNegotiate_OnResponse failed: %08lx\n", hres
);
547 WARN("HttpQueryInfo failed: %ld\n", GetLastError());
550 ranges
= query_http_info(This
, HTTP_QUERY_ACCEPT_RANGES
);
552 IInternetProtocolSink_ReportProgress(This
->base
.protocol_sink
, BINDSTATUS_ACCEPTRANGES
, NULL
);
556 content_type
= query_http_info(This
, HTTP_QUERY_CONTENT_TYPE
);
558 /* remove the charset, if present */
559 LPWSTR p
= wcschr(content_type
, ';');
562 IInternetProtocolSink_ReportProgress(This
->base
.protocol_sink
,
563 (This
->base
.bindf
& BINDF_FROMURLMON
)
564 ? BINDSTATUS_MIMETYPEAVAILABLE
: BINDSTATUS_RAWMIMETYPE
,
566 heap_free(content_type
);
568 WARN("HttpQueryInfo failed: %ld\n", GetLastError());
569 IInternetProtocolSink_ReportProgress(This
->base
.protocol_sink
,
570 (This
->base
.bindf
& BINDF_FROMURLMON
)
571 ? BINDSTATUS_MIMETYPEAVAILABLE
: BINDSTATUS_RAWMIMETYPE
, L
"text/html");
574 content_length
= query_http_info(This
, HTTP_QUERY_CONTENT_LENGTH
);
576 This
->base
.content_length
= wcstol(content_length
, NULL
, 10);
577 heap_free(content_length
);
583 static void HttpProtocol_close_connection(Protocol
*prot
)
585 HttpProtocol
*This
= impl_from_Protocol(prot
);
587 if(This
->http_negotiate
) {
588 IHttpNegotiate_Release(This
->http_negotiate
);
589 This
->http_negotiate
= NULL
;
592 heap_free(This
->full_header
);
593 This
->full_header
= NULL
;
596 static void HttpProtocol_on_error(Protocol
*prot
, DWORD error
)
598 HttpProtocol
*This
= impl_from_Protocol(prot
);
601 TRACE("(%p) %ld\n", prot
, error
);
603 if(prot
->flags
& FLAG_FIRST_CONTINUE_COMPLETE
) {
604 FIXME("Not handling error %ld\n", error
);
608 while((hres
= handle_http_error(This
, error
)) == RPC_E_RETRY
) {
609 error
= send_http_request(This
);
611 if(error
== ERROR_IO_PENDING
|| error
== ERROR_SUCCESS
)
615 protocol_abort(prot
, hres
);
616 protocol_close_connection(prot
);
620 static const ProtocolVtbl AsyncProtocolVtbl
= {
621 HttpProtocol_open_request
,
622 HttpProtocol_end_request
,
623 HttpProtocol_start_downloading
,
624 HttpProtocol_close_connection
,
625 HttpProtocol_on_error
628 static HRESULT WINAPI
HttpProtocolUnk_QueryInterface(IUnknown
*iface
, REFIID riid
, void **ppv
)
630 HttpProtocol
*This
= impl_from_IUnknown(iface
);
632 if(IsEqualGUID(&IID_IUnknown
, riid
)) {
633 TRACE("(%p)->(IID_IUnknown %p)\n", This
, ppv
);
634 *ppv
= &This
->IUnknown_inner
;
635 }else if(IsEqualGUID(&IID_IInternetProtocolRoot
, riid
)) {
636 TRACE("(%p)->(IID_IInternetProtocolRoot %p)\n", This
, ppv
);
637 *ppv
= &This
->IInternetProtocolEx_iface
;
638 }else if(IsEqualGUID(&IID_IInternetProtocol
, riid
)) {
639 TRACE("(%p)->(IID_IInternetProtocol %p)\n", This
, ppv
);
640 *ppv
= &This
->IInternetProtocolEx_iface
;
641 }else if(IsEqualGUID(&IID_IInternetProtocolEx
, riid
)) {
642 TRACE("(%p)->(IID_IInternetProtocolEx %p)\n", This
, ppv
);
643 *ppv
= &This
->IInternetProtocolEx_iface
;
644 }else if(IsEqualGUID(&IID_IInternetPriority
, riid
)) {
645 TRACE("(%p)->(IID_IInternetPriority %p)\n", This
, ppv
);
646 *ppv
= &This
->IInternetPriority_iface
;
647 }else if(IsEqualGUID(&IID_IWinInetInfo
, riid
)) {
648 TRACE("(%p)->(IID_IWinInetInfo %p)\n", This
, ppv
);
649 *ppv
= &This
->IWinInetHttpInfo_iface
;
650 }else if(IsEqualGUID(&IID_IWinInetHttpInfo
, riid
)) {
651 TRACE("(%p)->(IID_IWinInetHttpInfo %p)\n", This
, ppv
);
652 *ppv
= &This
->IWinInetHttpInfo_iface
;
655 WARN("not supported interface %s\n", debugstr_guid(riid
));
656 return E_NOINTERFACE
;
659 IUnknown_AddRef((IUnknown
*)*ppv
);
663 static ULONG WINAPI
HttpProtocolUnk_AddRef(IUnknown
*iface
)
665 HttpProtocol
*This
= impl_from_IUnknown(iface
);
666 LONG ref
= InterlockedIncrement(&This
->ref
);
667 TRACE("(%p) ref=%ld\n", This
, ref
);
671 static ULONG WINAPI
HttpProtocolUnk_Release(IUnknown
*iface
)
673 HttpProtocol
*This
= impl_from_IUnknown(iface
);
674 LONG ref
= InterlockedDecrement(&This
->ref
);
676 TRACE("(%p) ref=%ld\n", This
, ref
);
679 protocol_close_connection(&This
->base
);
682 URLMON_UnlockModule();
688 static const IUnknownVtbl HttpProtocolUnkVtbl
= {
689 HttpProtocolUnk_QueryInterface
,
690 HttpProtocolUnk_AddRef
,
691 HttpProtocolUnk_Release
694 static HRESULT WINAPI
HttpProtocol_QueryInterface(IInternetProtocolEx
*iface
, REFIID riid
, void **ppv
)
696 HttpProtocol
*This
= impl_from_IInternetProtocolEx(iface
);
697 TRACE("(%p)->(%s %p)\n", This
, debugstr_guid(riid
), ppv
);
698 return IUnknown_QueryInterface(This
->outer
, riid
, ppv
);
701 static ULONG WINAPI
HttpProtocol_AddRef(IInternetProtocolEx
*iface
)
703 HttpProtocol
*This
= impl_from_IInternetProtocolEx(iface
);
704 TRACE("(%p)\n", This
);
705 return IUnknown_AddRef(This
->outer
);
708 static ULONG WINAPI
HttpProtocol_Release(IInternetProtocolEx
*iface
)
710 HttpProtocol
*This
= impl_from_IInternetProtocolEx(iface
);
711 TRACE("(%p)\n", This
);
712 return IUnknown_Release(This
->outer
);
715 static HRESULT WINAPI
HttpProtocol_Start(IInternetProtocolEx
*iface
, LPCWSTR szUrl
,
716 IInternetProtocolSink
*pOIProtSink
, IInternetBindInfo
*pOIBindInfo
,
717 DWORD grfPI
, HANDLE_PTR dwReserved
)
719 HttpProtocol
*This
= impl_from_IInternetProtocolEx(iface
);
723 TRACE("(%p)->(%s %p %p %08lx %Ix)\n", This
, debugstr_w(szUrl
), pOIProtSink
,
724 pOIBindInfo
, grfPI
, dwReserved
);
726 hres
= CreateUri(szUrl
, 0, 0, &uri
);
730 hres
= IInternetProtocolEx_StartEx(&This
->IInternetProtocolEx_iface
, uri
, pOIProtSink
,
731 pOIBindInfo
, grfPI
, (HANDLE
*)dwReserved
);
737 static HRESULT WINAPI
HttpProtocol_Continue(IInternetProtocolEx
*iface
, PROTOCOLDATA
*pProtocolData
)
739 HttpProtocol
*This
= impl_from_IInternetProtocolEx(iface
);
741 TRACE("(%p)->(%p)\n", This
, pProtocolData
);
743 return protocol_continue(&This
->base
, pProtocolData
);
746 static HRESULT WINAPI
HttpProtocol_Abort(IInternetProtocolEx
*iface
, HRESULT hrReason
,
749 HttpProtocol
*This
= impl_from_IInternetProtocolEx(iface
);
751 TRACE("(%p)->(%08lx %08lx)\n", This
, hrReason
, dwOptions
);
753 return protocol_abort(&This
->base
, hrReason
);
756 static HRESULT WINAPI
HttpProtocol_Terminate(IInternetProtocolEx
*iface
, DWORD dwOptions
)
758 HttpProtocol
*This
= impl_from_IInternetProtocolEx(iface
);
760 TRACE("(%p)->(%08lx)\n", This
, dwOptions
);
762 protocol_close_connection(&This
->base
);
766 static HRESULT WINAPI
HttpProtocol_Suspend(IInternetProtocolEx
*iface
)
768 HttpProtocol
*This
= impl_from_IInternetProtocolEx(iface
);
769 FIXME("(%p)\n", This
);
773 static HRESULT WINAPI
HttpProtocol_Resume(IInternetProtocolEx
*iface
)
775 HttpProtocol
*This
= impl_from_IInternetProtocolEx(iface
);
776 FIXME("(%p)\n", This
);
780 static HRESULT WINAPI
HttpProtocol_Read(IInternetProtocolEx
*iface
, void *pv
,
781 ULONG cb
, ULONG
*pcbRead
)
783 HttpProtocol
*This
= impl_from_IInternetProtocolEx(iface
);
785 TRACE("(%p)->(%p %lu %p)\n", This
, pv
, cb
, pcbRead
);
787 return protocol_read(&This
->base
, pv
, cb
, pcbRead
);
790 static HRESULT WINAPI
HttpProtocol_Seek(IInternetProtocolEx
*iface
, LARGE_INTEGER dlibMove
,
791 DWORD dwOrigin
, ULARGE_INTEGER
*plibNewPosition
)
793 HttpProtocol
*This
= impl_from_IInternetProtocolEx(iface
);
794 FIXME("(%p)->(%ld %ld %p)\n", This
, dlibMove
.u
.LowPart
, dwOrigin
, plibNewPosition
);
798 static HRESULT WINAPI
HttpProtocol_LockRequest(IInternetProtocolEx
*iface
, DWORD dwOptions
)
800 HttpProtocol
*This
= impl_from_IInternetProtocolEx(iface
);
802 TRACE("(%p)->(%08lx)\n", This
, dwOptions
);
804 return protocol_lock_request(&This
->base
);
807 static HRESULT WINAPI
HttpProtocol_UnlockRequest(IInternetProtocolEx
*iface
)
809 HttpProtocol
*This
= impl_from_IInternetProtocolEx(iface
);
811 TRACE("(%p)\n", This
);
813 return protocol_unlock_request(&This
->base
);
816 static HRESULT WINAPI
HttpProtocol_StartEx(IInternetProtocolEx
*iface
, IUri
*pUri
,
817 IInternetProtocolSink
*pOIProtSink
, IInternetBindInfo
*pOIBindInfo
,
818 DWORD grfPI
, HANDLE
*dwReserved
)
820 HttpProtocol
*This
= impl_from_IInternetProtocolEx(iface
);
824 TRACE("(%p)->(%p %p %p %08lx %p)\n", This
, pUri
, pOIProtSink
,
825 pOIBindInfo
, grfPI
, dwReserved
);
827 hres
= IUri_GetScheme(pUri
, &scheme
);
830 if(scheme
!= (This
->https
? URL_SCHEME_HTTPS
: URL_SCHEME_HTTP
))
833 return protocol_start(&This
->base
, (IInternetProtocol
*)&This
->IInternetProtocolEx_iface
, pUri
,
834 pOIProtSink
, pOIBindInfo
);
837 static const IInternetProtocolExVtbl HttpProtocolVtbl
= {
838 HttpProtocol_QueryInterface
,
840 HttpProtocol_Release
,
842 HttpProtocol_Continue
,
844 HttpProtocol_Terminate
,
845 HttpProtocol_Suspend
,
849 HttpProtocol_LockRequest
,
850 HttpProtocol_UnlockRequest
,
854 static HRESULT WINAPI
HttpPriority_QueryInterface(IInternetPriority
*iface
, REFIID riid
, void **ppv
)
856 HttpProtocol
*This
= impl_from_IInternetPriority(iface
);
857 return IInternetProtocolEx_QueryInterface(&This
->IInternetProtocolEx_iface
, riid
, ppv
);
860 static ULONG WINAPI
HttpPriority_AddRef(IInternetPriority
*iface
)
862 HttpProtocol
*This
= impl_from_IInternetPriority(iface
);
863 return IInternetProtocolEx_AddRef(&This
->IInternetProtocolEx_iface
);
866 static ULONG WINAPI
HttpPriority_Release(IInternetPriority
*iface
)
868 HttpProtocol
*This
= impl_from_IInternetPriority(iface
);
869 return IInternetProtocolEx_Release(&This
->IInternetProtocolEx_iface
);
872 static HRESULT WINAPI
HttpPriority_SetPriority(IInternetPriority
*iface
, LONG nPriority
)
874 HttpProtocol
*This
= impl_from_IInternetPriority(iface
);
876 TRACE("(%p)->(%ld)\n", This
, nPriority
);
878 This
->base
.priority
= nPriority
;
882 static HRESULT WINAPI
HttpPriority_GetPriority(IInternetPriority
*iface
, LONG
*pnPriority
)
884 HttpProtocol
*This
= impl_from_IInternetPriority(iface
);
886 TRACE("(%p)->(%p)\n", This
, pnPriority
);
888 *pnPriority
= This
->base
.priority
;
892 static const IInternetPriorityVtbl HttpPriorityVtbl
= {
893 HttpPriority_QueryInterface
,
895 HttpPriority_Release
,
896 HttpPriority_SetPriority
,
897 HttpPriority_GetPriority
900 static HRESULT WINAPI
HttpInfo_QueryInterface(IWinInetHttpInfo
*iface
, REFIID riid
, void **ppv
)
902 HttpProtocol
*This
= impl_from_IWinInetHttpInfo(iface
);
903 return IInternetProtocolEx_QueryInterface(&This
->IInternetProtocolEx_iface
, riid
, ppv
);
906 static ULONG WINAPI
HttpInfo_AddRef(IWinInetHttpInfo
*iface
)
908 HttpProtocol
*This
= impl_from_IWinInetHttpInfo(iface
);
909 return IInternetProtocolEx_AddRef(&This
->IInternetProtocolEx_iface
);
912 static ULONG WINAPI
HttpInfo_Release(IWinInetHttpInfo
*iface
)
914 HttpProtocol
*This
= impl_from_IWinInetHttpInfo(iface
);
915 return IInternetProtocolEx_Release(&This
->IInternetProtocolEx_iface
);
918 static HRESULT WINAPI
HttpInfo_QueryOption(IWinInetHttpInfo
*iface
, DWORD dwOption
,
919 void *pBuffer
, DWORD
*pcbBuffer
)
921 HttpProtocol
*This
= impl_from_IWinInetHttpInfo(iface
);
922 TRACE("(%p)->(%lx %p %p)\n", This
, dwOption
, pBuffer
, pcbBuffer
);
924 if(!This
->base
.request
)
927 if(!InternetQueryOptionW(This
->base
.request
, dwOption
, pBuffer
, pcbBuffer
))
932 static HRESULT WINAPI
HttpInfo_QueryInfo(IWinInetHttpInfo
*iface
, DWORD dwOption
,
933 void *pBuffer
, DWORD
*pcbBuffer
, DWORD
*pdwFlags
, DWORD
*pdwReserved
)
935 HttpProtocol
*This
= impl_from_IWinInetHttpInfo(iface
);
936 TRACE("(%p)->(%lx %p %p %p %p)\n", This
, dwOption
, pBuffer
, pcbBuffer
, pdwFlags
, pdwReserved
);
938 if(!This
->base
.request
)
941 if(!HttpQueryInfoA(This
->base
.request
, dwOption
, pBuffer
, pcbBuffer
, pdwFlags
))
947 static const IWinInetHttpInfoVtbl WinInetHttpInfoVtbl
= {
948 HttpInfo_QueryInterface
,
951 HttpInfo_QueryOption
,
955 static HRESULT
create_http_protocol(BOOL https
, IUnknown
*outer
, void **ppobj
)
959 ret
= heap_alloc_zero(sizeof(HttpProtocol
));
961 return E_OUTOFMEMORY
;
963 ret
->base
.vtbl
= &AsyncProtocolVtbl
;
964 ret
->IUnknown_inner
.lpVtbl
= &HttpProtocolUnkVtbl
;
965 ret
->IInternetProtocolEx_iface
.lpVtbl
= &HttpProtocolVtbl
;
966 ret
->IInternetPriority_iface
.lpVtbl
= &HttpPriorityVtbl
;
967 ret
->IWinInetHttpInfo_iface
.lpVtbl
= &WinInetHttpInfoVtbl
;
971 ret
->outer
= outer
? outer
: &ret
->IUnknown_inner
;
973 *ppobj
= &ret
->IUnknown_inner
;
979 HRESULT
HttpProtocol_Construct(IUnknown
*outer
, void **ppv
)
981 TRACE("(%p %p)\n", outer
, ppv
);
983 return create_http_protocol(FALSE
, outer
, ppv
);
986 HRESULT
HttpSProtocol_Construct(IUnknown
*outer
, void **ppv
)
988 TRACE("(%p %p)\n", outer
, ppv
);
990 return create_http_protocol(TRUE
, outer
, ppv
);