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 IInternetProtocolEx IInternetProtocolEx_iface
;
36 IInternetPriority IInternetPriority_iface
;
37 IWinInetHttpInfo IWinInetHttpInfo_iface
;
40 IHttpNegotiate
*http_negotiate
;
46 static inline HttpProtocol
*impl_from_IInternetProtocolEx(IInternetProtocolEx
*iface
)
48 return CONTAINING_RECORD(iface
, HttpProtocol
, IInternetProtocolEx_iface
);
51 static inline HttpProtocol
*impl_from_IInternetPriority(IInternetPriority
*iface
)
53 return CONTAINING_RECORD(iface
, HttpProtocol
, IInternetPriority_iface
);
56 static inline HttpProtocol
*impl_from_IWinInetHttpInfo(IWinInetHttpInfo
*iface
)
58 return CONTAINING_RECORD(iface
, HttpProtocol
, IWinInetHttpInfo_iface
);
61 static const WCHAR default_headersW
[] = {
62 '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};
64 static LPWSTR
query_http_info(HttpProtocol
*This
, DWORD option
)
70 res
= HttpQueryInfoW(This
->base
.request
, option
, NULL
, &len
, NULL
);
71 if (!res
&& GetLastError() == ERROR_INSUFFICIENT_BUFFER
) {
72 ret
= heap_alloc(len
);
73 res
= HttpQueryInfoW(This
->base
.request
, option
, ret
, &len
, NULL
);
76 TRACE("HttpQueryInfoW(%d) failed: %08x\n", option
, GetLastError());
84 static inline BOOL
set_security_flag(HttpProtocol
*This
, DWORD flags
)
88 res
= InternetSetOptionW(This
->base
.request
, INTERNET_OPTION_SECURITY_FLAGS
, &flags
, sizeof(flags
));
90 ERR("Failed to set security flags: %x\n", flags
);
95 static inline HRESULT
internet_error_to_hres(DWORD error
)
99 case ERROR_INTERNET_SEC_CERT_DATE_INVALID
:
100 case ERROR_INTERNET_SEC_CERT_CN_INVALID
:
101 case ERROR_INTERNET_INVALID_CA
:
102 case ERROR_INTERNET_CLIENT_AUTH_CERT_NEEDED
:
103 case ERROR_INTERNET_SEC_INVALID_CERT
:
104 case ERROR_INTERNET_SEC_CERT_ERRORS
:
105 case ERROR_INTERNET_SEC_CERT_REV_FAILED
:
106 case ERROR_INTERNET_SEC_CERT_NO_REV
:
107 case ERROR_INTERNET_SEC_CERT_REVOKED
:
108 return INET_E_INVALID_CERTIFICATE
;
109 case ERROR_INTERNET_HTTP_TO_HTTPS_ON_REDIR
:
110 case ERROR_INTERNET_HTTPS_TO_HTTP_ON_REDIR
:
111 case ERROR_HTTP_REDIRECT_NEEDS_CONFIRMATION
:
112 return INET_E_REDIRECT_FAILED
;
114 return INET_E_DOWNLOAD_FAILURE
;
118 static HRESULT
handle_http_error(HttpProtocol
*This
, DWORD error
)
120 IServiceProvider
*serv_prov
;
121 IWindowForBindingUI
*wfb_ui
;
122 IHttpSecurity
*http_security
;
123 BOOL security_problem
;
129 TRACE("(%p %u)\n", This
, error
);
132 case ERROR_INTERNET_SEC_CERT_DATE_INVALID
:
133 case ERROR_INTERNET_SEC_CERT_CN_INVALID
:
134 case ERROR_INTERNET_HTTP_TO_HTTPS_ON_REDIR
:
135 case ERROR_INTERNET_HTTPS_TO_HTTP_ON_REDIR
:
136 case ERROR_INTERNET_INVALID_CA
:
137 case ERROR_INTERNET_CLIENT_AUTH_CERT_NEEDED
:
138 case ERROR_INTERNET_SEC_INVALID_CERT
:
139 case ERROR_INTERNET_SEC_CERT_ERRORS
:
140 case ERROR_INTERNET_SEC_CERT_REV_FAILED
:
141 case ERROR_INTERNET_SEC_CERT_NO_REV
:
142 case ERROR_INTERNET_SEC_CERT_REVOKED
:
143 case ERROR_HTTP_REDIRECT_NEEDS_CONFIRMATION
:
144 security_problem
= TRUE
;
147 security_problem
= FALSE
;
150 hres
= IInternetProtocolSink_QueryInterface(This
->base
.protocol_sink
, &IID_IServiceProvider
,
153 ERR("Failed to get IServiceProvider.\n");
157 if(security_problem
) {
158 hres
= IServiceProvider_QueryService(serv_prov
, &IID_IHttpSecurity
, &IID_IHttpSecurity
,
159 (void**)&http_security
);
160 if(SUCCEEDED(hres
)) {
161 hres
= IHttpSecurity_OnSecurityProblem(http_security
, error
);
162 IHttpSecurity_Release(http_security
);
164 TRACE("OnSecurityProblem returned %08x\n", hres
);
170 IServiceProvider_Release(serv_prov
);
173 if(error
== ERROR_INTERNET_SEC_CERT_DATE_INVALID
)
174 res
= set_security_flag(This
, SECURITY_FLAG_IGNORE_CERT_DATE_INVALID
);
175 else if(error
== ERROR_INTERNET_SEC_CERT_CN_INVALID
)
176 res
= set_security_flag(This
, SECURITY_FLAG_IGNORE_CERT_CN_INVALID
);
177 else if(error
== ERROR_INTERNET_INVALID_CA
)
178 res
= set_security_flag(This
, SECURITY_FLAG_IGNORE_UNKNOWN_CA
);
183 FIXME("Don't know how to ignore error %d\n", error
);
189 if(hres
== RPC_E_RETRY
)
192 return internet_error_to_hres(error
);
198 case ERROR_INTERNET_SEC_CERT_REV_FAILED
:
199 if(hres
!= S_FALSE
) {
200 /* Silently ignore the error. We will get more detailed error from wininet anyway. */
201 set_security_flag(This
, SECURITY_FLAG_IGNORE_REVOCATION
);
207 hres
= IServiceProvider_QueryService(serv_prov
, &IID_IWindowForBindingUI
, &IID_IWindowForBindingUI
, (void**)&wfb_ui
);
208 if(SUCCEEDED(hres
)) {
209 const IID
*iid_reason
;
212 iid_reason
= &IID_IHttpSecurity
;
213 else if(error
== ERROR_INTERNET_INCORRECT_PASSWORD
)
214 iid_reason
= &IID_IAuthenticate
;
216 iid_reason
= &IID_IWindowForBindingUI
;
218 hres
= IWindowForBindingUI_GetWindow(wfb_ui
, iid_reason
, &hwnd
);
219 IWindowForBindingUI_Release(wfb_ui
);
222 if(FAILED(hres
)) hwnd
= NULL
;
224 dlg_flags
= FLAGS_ERROR_UI_FLAGS_CHANGE_OPTIONS
| FLAGS_ERROR_UI_FLAGS_GENERATE_DATA
;
225 if(This
->base
.bindf
& BINDF_NO_UI
)
226 dlg_flags
|= FLAGS_ERROR_UI_FLAGS_NO_UI
;
228 res
= InternetErrorDlg(hwnd
, This
->base
.request
, error
, dlg_flags
, NULL
);
229 hres
= res
== ERROR_INTERNET_FORCE_RETRY
|| res
== ERROR_SUCCESS
? RPC_E_RETRY
: internet_error_to_hres(error
);
232 IServiceProvider_Release(serv_prov
);
236 static ULONG
send_http_request(HttpProtocol
*This
)
238 INTERNET_BUFFERSW send_buffer
= {sizeof(INTERNET_BUFFERSW
)};
241 send_buffer
.lpcszHeader
= This
->full_header
;
242 send_buffer
.dwHeadersLength
= send_buffer
.dwHeadersTotal
= strlenW(This
->full_header
);
244 if(This
->base
.bind_info
.dwBindVerb
!= BINDVERB_GET
) {
245 switch(This
->base
.bind_info
.stgmedData
.tymed
) {
247 /* Native does not use GlobalLock/GlobalUnlock, so we won't either */
248 send_buffer
.lpvBuffer
= This
->base
.bind_info
.stgmedData
.u
.hGlobal
;
249 send_buffer
.dwBufferLength
= send_buffer
.dwBufferTotal
= This
->base
.bind_info
.cbstgmedData
;
251 case TYMED_ISTREAM
: {
252 LARGE_INTEGER offset
;
254 send_buffer
.dwBufferTotal
= This
->base
.bind_info
.cbstgmedData
;
255 if(!This
->base
.post_stream
) {
256 This
->base
.post_stream
= This
->base
.bind_info
.stgmedData
.u
.pstm
;
257 IStream_AddRef(This
->base
.post_stream
);
261 IStream_Seek(This
->base
.post_stream
, offset
, STREAM_SEEK_SET
, NULL
);
265 FIXME("Unsupported This->base.bind_info.stgmedData.tymed %d\n", This
->base
.bind_info
.stgmedData
.tymed
);
269 if(This
->base
.post_stream
)
270 res
= HttpSendRequestExW(This
->base
.request
, &send_buffer
, NULL
, 0, 0);
272 res
= HttpSendRequestW(This
->base
.request
, send_buffer
.lpcszHeader
, send_buffer
.dwHeadersLength
,
273 send_buffer
.lpvBuffer
, send_buffer
.dwBufferLength
);
275 return res
? 0 : GetLastError();
278 static inline HttpProtocol
*impl_from_Protocol(Protocol
*prot
)
280 return CONTAINING_RECORD(prot
, HttpProtocol
, base
);
283 static HRESULT
HttpProtocol_open_request(Protocol
*prot
, IUri
*uri
, DWORD request_flags
,
284 HINTERNET internet_session
, IInternetBindInfo
*bind_info
)
286 HttpProtocol
*This
= impl_from_Protocol(prot
);
287 WCHAR
*addl_header
= NULL
, *post_cookie
= NULL
, *rootdoc_url
= NULL
;
288 IServiceProvider
*service_provider
= NULL
;
289 IHttpNegotiate2
*http_negotiate2
= NULL
;
290 BSTR url
, host
, user
, pass
, path
;
291 LPOLESTR accept_mimes
[257];
292 const WCHAR
**accept_types
;
293 BYTE security_id
[512];
294 DWORD len
, port
, flags
;
299 static const WCHAR wszBindVerb
[BINDVERB_CUSTOM
][5] =
304 hres
= IUri_GetPort(uri
, &port
);
308 hres
= IUri_GetHost(uri
, &host
);
312 hres
= IUri_GetUserName(uri
, &user
);
313 if(SUCCEEDED(hres
)) {
314 hres
= IUri_GetPassword(uri
, &pass
);
316 if(SUCCEEDED(hres
)) {
317 This
->base
.connection
= InternetConnectW(internet_session
, host
, port
, user
, pass
,
318 INTERNET_SERVICE_HTTP
, This
->https
? INTERNET_FLAG_SECURE
: 0, (DWORD_PTR
)&This
->base
);
326 if(!This
->base
.connection
) {
327 WARN("InternetConnect failed: %d\n", GetLastError());
328 return INET_E_CANNOT_CONNECT
;
332 hres
= IInternetBindInfo_GetBindString(bind_info
, BINDSTRING_ROOTDOC_URL
, &rootdoc_url
, 1, &num
);
333 if(hres
== S_OK
&& num
) {
334 FIXME("Use root doc URL %s\n", debugstr_w(rootdoc_url
));
335 CoTaskMemFree(rootdoc_url
);
338 num
= sizeof(accept_mimes
)/sizeof(accept_mimes
[0])-1;
339 hres
= IInternetBindInfo_GetBindString(bind_info
, BINDSTRING_ACCEPT_MIMES
, accept_mimes
, num
, &num
);
340 if(hres
== INET_E_USE_DEFAULT_SETTING
) {
341 static const WCHAR default_accept_mimeW
[] = {'*','/','*',0};
342 static const WCHAR
*default_accept_mimes
[] = {default_accept_mimeW
, NULL
};
344 accept_types
= default_accept_mimes
;
346 }else if(hres
== S_OK
) {
347 accept_types
= (const WCHAR
**)accept_mimes
;
349 WARN("GetBindString BINDSTRING_ACCEPT_MIMES failed: %08x\n", hres
);
350 return INET_E_NO_VALID_MEDIA
;
352 accept_mimes
[num
] = 0;
355 request_flags
|= INTERNET_FLAG_SECURE
;
357 hres
= IUri_GetPathAndQuery(uri
, &path
);
358 if(SUCCEEDED(hres
)) {
359 This
->base
.request
= HttpOpenRequestW(This
->base
.connection
,
360 This
->base
.bind_info
.dwBindVerb
< BINDVERB_CUSTOM
361 ? wszBindVerb
[This
->base
.bind_info
.dwBindVerb
] : This
->base
.bind_info
.szCustomVerb
,
362 path
, NULL
, NULL
, accept_types
, request_flags
, (DWORD_PTR
)&This
->base
);
366 CoTaskMemFree(accept_mimes
[num
]);
369 if (!This
->base
.request
) {
370 WARN("HttpOpenRequest failed: %d\n", GetLastError());
371 return INET_E_RESOURCE_NOT_FOUND
;
374 hres
= IInternetProtocolSink_QueryInterface(This
->base
.protocol_sink
, &IID_IServiceProvider
,
375 (void **)&service_provider
);
377 WARN("IInternetProtocolSink_QueryInterface IID_IServiceProvider failed: %08x\n", hres
);
381 hres
= IServiceProvider_QueryService(service_provider
, &IID_IHttpNegotiate
,
382 &IID_IHttpNegotiate
, (void **)&This
->http_negotiate
);
384 WARN("IServiceProvider_QueryService IID_IHttpNegotiate failed: %08x\n", hres
);
385 IServiceProvider_Release(service_provider
);
389 hres
= IUri_GetAbsoluteUri(uri
, &url
);
391 IServiceProvider_Release(service_provider
);
395 hres
= IHttpNegotiate_BeginningTransaction(This
->http_negotiate
, url
, default_headersW
,
399 WARN("IHttpNegotiate_BeginningTransaction failed: %08x\n", hres
);
400 IServiceProvider_Release(service_provider
);
404 len
= addl_header
? strlenW(addl_header
) : 0;
406 This
->full_header
= heap_alloc(len
*sizeof(WCHAR
)+sizeof(default_headersW
));
407 if(!This
->full_header
) {
408 IServiceProvider_Release(service_provider
);
409 return E_OUTOFMEMORY
;
413 memcpy(This
->full_header
, addl_header
, len
*sizeof(WCHAR
));
414 CoTaskMemFree(addl_header
);
415 memcpy(This
->full_header
+len
, default_headersW
, sizeof(default_headersW
));
417 hres
= IServiceProvider_QueryService(service_provider
, &IID_IHttpNegotiate2
,
418 &IID_IHttpNegotiate2
, (void **)&http_negotiate2
);
419 IServiceProvider_Release(service_provider
);
421 WARN("IServiceProvider_QueryService IID_IHttpNegotiate2 failed: %08x\n", hres
);
422 /* No goto done as per native */
424 len
= sizeof(security_id
)/sizeof(security_id
[0]);
425 hres
= IHttpNegotiate2_GetRootSecurityId(http_negotiate2
, security_id
, &len
, 0);
426 IHttpNegotiate2_Release(http_negotiate2
);
428 WARN("IHttpNegotiate2_GetRootSecurityId failed: %08x\n", hres
);
431 /* FIXME: Handle security_id. Native calls undocumented function IsHostInProxyBypassList. */
433 if(This
->base
.bind_info
.dwBindVerb
== BINDVERB_POST
) {
435 hres
= IInternetBindInfo_GetBindString(bind_info
, BINDSTRING_POST_COOKIE
, &post_cookie
, 1, &num
);
436 if(hres
== S_OK
&& num
) {
437 if(!InternetSetOptionW(This
->base
.request
, INTERNET_OPTION_SECONDARY_CACHE_KEY
,
438 post_cookie
, lstrlenW(post_cookie
)))
439 WARN("InternetSetOption INTERNET_OPTION_SECONDARY_CACHE_KEY failed: %d\n", GetLastError());
440 CoTaskMemFree(post_cookie
);
444 flags
= INTERNET_ERROR_MASK_COMBINED_SEC_CERT
;
445 res
= InternetSetOptionW(This
->base
.request
, INTERNET_OPTION_ERROR_MASK
, &flags
, sizeof(flags
));
447 WARN("InternetSetOption(INTERNET_OPTION_ERROR_MASK) failed: %u\n", GetLastError());
450 res
= InternetSetOptionW(This
->base
.request
, INTERNET_OPTION_HTTP_DECODING
, &b
, sizeof(b
));
452 WARN("InternetSetOption(INTERNET_OPTION_HTTP_DECODING) failed: %u\n", GetLastError());
455 error
= send_http_request(This
);
458 case ERROR_IO_PENDING
:
462 * If sending response ended synchronously, it means that we have the whole data
463 * available locally (most likely in cache).
465 return protocol_syncbinding(&This
->base
);
467 hres
= handle_http_error(This
, error
);
469 } while(hres
== RPC_E_RETRY
);
471 WARN("HttpSendRequest failed: %d\n", error
);
475 static HRESULT
HttpProtocol_end_request(Protocol
*protocol
)
479 res
= HttpEndRequestW(protocol
->request
, NULL
, 0, 0);
480 if(!res
&& GetLastError() != ERROR_IO_PENDING
) {
481 FIXME("HttpEndRequest failed: %u\n", GetLastError());
488 static BOOL
is_redirect_response(DWORD status_code
)
490 switch(status_code
) {
491 case HTTP_STATUS_REDIRECT
:
492 case HTTP_STATUS_MOVED
:
493 case HTTP_STATUS_REDIRECT_KEEP_VERB
:
494 case HTTP_STATUS_REDIRECT_METHOD
:
500 static HRESULT
HttpProtocol_start_downloading(Protocol
*prot
)
502 HttpProtocol
*This
= impl_from_Protocol(prot
);
503 LPWSTR content_type
, content_length
, ranges
;
504 DWORD len
= sizeof(DWORD
);
509 static const WCHAR wszDefaultContentType
[] =
510 {'t','e','x','t','/','h','t','m','l',0};
512 if(!This
->http_negotiate
) {
513 WARN("Expected IHttpNegotiate pointer to be non-NULL\n");
517 res
= HttpQueryInfoW(This
->base
.request
, HTTP_QUERY_STATUS_CODE
| HTTP_QUERY_FLAG_NUMBER
,
518 &status_code
, &len
, NULL
);
520 WCHAR
*response_headers
;
522 if((This
->base
.bind_info
.dwOptions
& BINDINFO_OPTIONS_DISABLEAUTOREDIRECTS
) && is_redirect_response(status_code
)) {
525 TRACE("Got redirect with disabled auto redirects\n");
527 location
= query_http_info(This
, HTTP_QUERY_LOCATION
);
528 This
->base
.flags
|= FLAG_RESULT_REPORTED
| FLAG_LAST_DATA_REPORTED
;
529 IInternetProtocolSink_ReportResult(This
->base
.protocol_sink
, INET_E_REDIRECT_FAILED
, 0, location
);
531 return INET_E_REDIRECT_FAILED
;
534 response_headers
= query_http_info(This
, HTTP_QUERY_RAW_HEADERS_CRLF
);
535 if(response_headers
) {
536 hres
= IHttpNegotiate_OnResponse(This
->http_negotiate
, status_code
, response_headers
,
538 heap_free(response_headers
);
540 WARN("IHttpNegotiate_OnResponse failed: %08x\n", hres
);
545 WARN("HttpQueryInfo failed: %d\n", GetLastError());
548 ranges
= query_http_info(This
, HTTP_QUERY_ACCEPT_RANGES
);
550 IInternetProtocolSink_ReportProgress(This
->base
.protocol_sink
, BINDSTATUS_ACCEPTRANGES
, NULL
);
554 content_type
= query_http_info(This
, HTTP_QUERY_CONTENT_TYPE
);
556 /* remove the charset, if present */
557 LPWSTR p
= strchrW(content_type
, ';');
560 IInternetProtocolSink_ReportProgress(This
->base
.protocol_sink
,
561 (This
->base
.bindf
& BINDF_FROMURLMON
)
562 ? BINDSTATUS_MIMETYPEAVAILABLE
: BINDSTATUS_RAWMIMETYPE
,
564 heap_free(content_type
);
566 WARN("HttpQueryInfo failed: %d\n", GetLastError());
567 IInternetProtocolSink_ReportProgress(This
->base
.protocol_sink
,
568 (This
->base
.bindf
& BINDF_FROMURLMON
)
569 ? BINDSTATUS_MIMETYPEAVAILABLE
: BINDSTATUS_RAWMIMETYPE
,
570 wszDefaultContentType
);
573 content_length
= query_http_info(This
, HTTP_QUERY_CONTENT_LENGTH
);
575 This
->base
.content_length
= atoiW(content_length
);
576 heap_free(content_length
);
582 static void HttpProtocol_close_connection(Protocol
*prot
)
584 HttpProtocol
*This
= impl_from_Protocol(prot
);
586 if(This
->http_negotiate
) {
587 IHttpNegotiate_Release(This
->http_negotiate
);
588 This
->http_negotiate
= NULL
;
591 heap_free(This
->full_header
);
592 This
->full_header
= NULL
;
595 static void HttpProtocol_on_error(Protocol
*prot
, DWORD error
)
597 HttpProtocol
*This
= impl_from_Protocol(prot
);
600 TRACE("(%p) %d\n", prot
, error
);
602 if(prot
->flags
& FLAG_FIRST_CONTINUE_COMPLETE
) {
603 FIXME("Not handling error %d\n", error
);
607 while((hres
= handle_http_error(This
, error
)) == RPC_E_RETRY
) {
608 error
= send_http_request(This
);
610 if(error
== ERROR_IO_PENDING
|| error
== ERROR_SUCCESS
)
614 protocol_abort(prot
, hres
);
615 protocol_close_connection(prot
);
619 static const ProtocolVtbl AsyncProtocolVtbl
= {
620 HttpProtocol_open_request
,
621 HttpProtocol_end_request
,
622 HttpProtocol_start_downloading
,
623 HttpProtocol_close_connection
,
624 HttpProtocol_on_error
627 static HRESULT WINAPI
HttpProtocol_QueryInterface(IInternetProtocolEx
*iface
, REFIID riid
, void **ppv
)
629 HttpProtocol
*This
= impl_from_IInternetProtocolEx(iface
);
632 if(IsEqualGUID(&IID_IUnknown
, riid
)) {
633 TRACE("(%p)->(IID_IUnknown %p)\n", This
, ppv
);
634 *ppv
= &This
->IInternetProtocolEx_iface
;
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
;
656 IInternetProtocolEx_AddRef(iface
);
660 WARN("not supported interface %s\n", debugstr_guid(riid
));
661 return E_NOINTERFACE
;
664 static ULONG WINAPI
HttpProtocol_AddRef(IInternetProtocolEx
*iface
)
666 HttpProtocol
*This
= impl_from_IInternetProtocolEx(iface
);
667 LONG ref
= InterlockedIncrement(&This
->ref
);
668 TRACE("(%p) ref=%d\n", This
, ref
);
672 static ULONG WINAPI
HttpProtocol_Release(IInternetProtocolEx
*iface
)
674 HttpProtocol
*This
= impl_from_IInternetProtocolEx(iface
);
675 LONG ref
= InterlockedDecrement(&This
->ref
);
677 TRACE("(%p) ref=%d\n", This
, ref
);
680 protocol_close_connection(&This
->base
);
683 URLMON_UnlockModule();
689 static HRESULT WINAPI
HttpProtocol_Start(IInternetProtocolEx
*iface
, LPCWSTR szUrl
,
690 IInternetProtocolSink
*pOIProtSink
, IInternetBindInfo
*pOIBindInfo
,
691 DWORD grfPI
, HANDLE_PTR dwReserved
)
693 HttpProtocol
*This
= impl_from_IInternetProtocolEx(iface
);
697 TRACE("(%p)->(%s %p %p %08x %lx)\n", This
, debugstr_w(szUrl
), pOIProtSink
,
698 pOIBindInfo
, grfPI
, dwReserved
);
700 hres
= CreateUri(szUrl
, 0, 0, &uri
);
704 hres
= IInternetProtocolEx_StartEx(&This
->IInternetProtocolEx_iface
, uri
, pOIProtSink
,
705 pOIBindInfo
, grfPI
, (HANDLE
*)dwReserved
);
711 static HRESULT WINAPI
HttpProtocol_Continue(IInternetProtocolEx
*iface
, PROTOCOLDATA
*pProtocolData
)
713 HttpProtocol
*This
= impl_from_IInternetProtocolEx(iface
);
715 TRACE("(%p)->(%p)\n", This
, pProtocolData
);
717 return protocol_continue(&This
->base
, pProtocolData
);
720 static HRESULT WINAPI
HttpProtocol_Abort(IInternetProtocolEx
*iface
, HRESULT hrReason
,
723 HttpProtocol
*This
= impl_from_IInternetProtocolEx(iface
);
725 TRACE("(%p)->(%08x %08x)\n", This
, hrReason
, dwOptions
);
727 return protocol_abort(&This
->base
, hrReason
);
730 static HRESULT WINAPI
HttpProtocol_Terminate(IInternetProtocolEx
*iface
, DWORD dwOptions
)
732 HttpProtocol
*This
= impl_from_IInternetProtocolEx(iface
);
734 TRACE("(%p)->(%08x)\n", This
, dwOptions
);
736 protocol_close_connection(&This
->base
);
740 static HRESULT WINAPI
HttpProtocol_Suspend(IInternetProtocolEx
*iface
)
742 HttpProtocol
*This
= impl_from_IInternetProtocolEx(iface
);
743 FIXME("(%p)\n", This
);
747 static HRESULT WINAPI
HttpProtocol_Resume(IInternetProtocolEx
*iface
)
749 HttpProtocol
*This
= impl_from_IInternetProtocolEx(iface
);
750 FIXME("(%p)\n", This
);
754 static HRESULT WINAPI
HttpProtocol_Read(IInternetProtocolEx
*iface
, void *pv
,
755 ULONG cb
, ULONG
*pcbRead
)
757 HttpProtocol
*This
= impl_from_IInternetProtocolEx(iface
);
759 TRACE("(%p)->(%p %u %p)\n", This
, pv
, cb
, pcbRead
);
761 return protocol_read(&This
->base
, pv
, cb
, pcbRead
);
764 static HRESULT WINAPI
HttpProtocol_Seek(IInternetProtocolEx
*iface
, LARGE_INTEGER dlibMove
,
765 DWORD dwOrigin
, ULARGE_INTEGER
*plibNewPosition
)
767 HttpProtocol
*This
= impl_from_IInternetProtocolEx(iface
);
768 FIXME("(%p)->(%d %d %p)\n", This
, dlibMove
.u
.LowPart
, dwOrigin
, plibNewPosition
);
772 static HRESULT WINAPI
HttpProtocol_LockRequest(IInternetProtocolEx
*iface
, DWORD dwOptions
)
774 HttpProtocol
*This
= impl_from_IInternetProtocolEx(iface
);
776 TRACE("(%p)->(%08x)\n", This
, dwOptions
);
778 return protocol_lock_request(&This
->base
);
781 static HRESULT WINAPI
HttpProtocol_UnlockRequest(IInternetProtocolEx
*iface
)
783 HttpProtocol
*This
= impl_from_IInternetProtocolEx(iface
);
785 TRACE("(%p)\n", This
);
787 return protocol_unlock_request(&This
->base
);
790 static HRESULT WINAPI
HttpProtocol_StartEx(IInternetProtocolEx
*iface
, IUri
*pUri
,
791 IInternetProtocolSink
*pOIProtSink
, IInternetBindInfo
*pOIBindInfo
,
792 DWORD grfPI
, HANDLE
*dwReserved
)
794 HttpProtocol
*This
= impl_from_IInternetProtocolEx(iface
);
798 TRACE("(%p)->(%p %p %p %08x %p)\n", This
, pUri
, pOIProtSink
,
799 pOIBindInfo
, grfPI
, dwReserved
);
801 hres
= IUri_GetScheme(pUri
, &scheme
);
804 if(scheme
!= (This
->https
? URL_SCHEME_HTTPS
: URL_SCHEME_HTTP
))
807 return protocol_start(&This
->base
, (IInternetProtocol
*)&This
->IInternetProtocolEx_iface
, pUri
,
808 pOIProtSink
, pOIBindInfo
);
811 static const IInternetProtocolExVtbl HttpProtocolVtbl
= {
812 HttpProtocol_QueryInterface
,
814 HttpProtocol_Release
,
816 HttpProtocol_Continue
,
818 HttpProtocol_Terminate
,
819 HttpProtocol_Suspend
,
823 HttpProtocol_LockRequest
,
824 HttpProtocol_UnlockRequest
,
828 static HRESULT WINAPI
HttpPriority_QueryInterface(IInternetPriority
*iface
, REFIID riid
, void **ppv
)
830 HttpProtocol
*This
= impl_from_IInternetPriority(iface
);
831 return IInternetProtocolEx_QueryInterface(&This
->IInternetProtocolEx_iface
, riid
, ppv
);
834 static ULONG WINAPI
HttpPriority_AddRef(IInternetPriority
*iface
)
836 HttpProtocol
*This
= impl_from_IInternetPriority(iface
);
837 return IInternetProtocolEx_AddRef(&This
->IInternetProtocolEx_iface
);
840 static ULONG WINAPI
HttpPriority_Release(IInternetPriority
*iface
)
842 HttpProtocol
*This
= impl_from_IInternetPriority(iface
);
843 return IInternetProtocolEx_Release(&This
->IInternetProtocolEx_iface
);
846 static HRESULT WINAPI
HttpPriority_SetPriority(IInternetPriority
*iface
, LONG nPriority
)
848 HttpProtocol
*This
= impl_from_IInternetPriority(iface
);
850 TRACE("(%p)->(%d)\n", This
, nPriority
);
852 This
->base
.priority
= nPriority
;
856 static HRESULT WINAPI
HttpPriority_GetPriority(IInternetPriority
*iface
, LONG
*pnPriority
)
858 HttpProtocol
*This
= impl_from_IInternetPriority(iface
);
860 TRACE("(%p)->(%p)\n", This
, pnPriority
);
862 *pnPriority
= This
->base
.priority
;
866 static const IInternetPriorityVtbl HttpPriorityVtbl
= {
867 HttpPriority_QueryInterface
,
869 HttpPriority_Release
,
870 HttpPriority_SetPriority
,
871 HttpPriority_GetPriority
874 static HRESULT WINAPI
HttpInfo_QueryInterface(IWinInetHttpInfo
*iface
, REFIID riid
, void **ppv
)
876 HttpProtocol
*This
= impl_from_IWinInetHttpInfo(iface
);
877 return IInternetProtocolEx_QueryInterface(&This
->IInternetProtocolEx_iface
, riid
, ppv
);
880 static ULONG WINAPI
HttpInfo_AddRef(IWinInetHttpInfo
*iface
)
882 HttpProtocol
*This
= impl_from_IWinInetHttpInfo(iface
);
883 return IInternetProtocolEx_AddRef(&This
->IInternetProtocolEx_iface
);
886 static ULONG WINAPI
HttpInfo_Release(IWinInetHttpInfo
*iface
)
888 HttpProtocol
*This
= impl_from_IWinInetHttpInfo(iface
);
889 return IInternetProtocolEx_Release(&This
->IInternetProtocolEx_iface
);
892 static HRESULT WINAPI
HttpInfo_QueryOption(IWinInetHttpInfo
*iface
, DWORD dwOption
,
893 void *pBuffer
, DWORD
*pcbBuffer
)
895 HttpProtocol
*This
= impl_from_IWinInetHttpInfo(iface
);
896 TRACE("(%p)->(%x %p %p)\n", This
, dwOption
, pBuffer
, pcbBuffer
);
898 if(!This
->base
.request
)
901 if(!InternetQueryOptionW(This
->base
.request
, dwOption
, pBuffer
, pcbBuffer
))
906 static HRESULT WINAPI
HttpInfo_QueryInfo(IWinInetHttpInfo
*iface
, DWORD dwOption
,
907 void *pBuffer
, DWORD
*pcbBuffer
, DWORD
*pdwFlags
, DWORD
*pdwReserved
)
909 HttpProtocol
*This
= impl_from_IWinInetHttpInfo(iface
);
910 TRACE("(%p)->(%x %p %p %p %p)\n", This
, dwOption
, pBuffer
, pcbBuffer
, pdwFlags
, pdwReserved
);
912 if(!This
->base
.request
)
915 if(!HttpQueryInfoA(This
->base
.request
, dwOption
, pBuffer
, pcbBuffer
, pdwFlags
))
921 static const IWinInetHttpInfoVtbl WinInetHttpInfoVtbl
= {
922 HttpInfo_QueryInterface
,
925 HttpInfo_QueryOption
,
929 static HRESULT
create_http_protocol(BOOL https
, void **ppobj
)
933 ret
= heap_alloc_zero(sizeof(HttpProtocol
));
935 return E_OUTOFMEMORY
;
937 ret
->base
.vtbl
= &AsyncProtocolVtbl
;
938 ret
->IInternetProtocolEx_iface
.lpVtbl
= &HttpProtocolVtbl
;
939 ret
->IInternetPriority_iface
.lpVtbl
= &HttpPriorityVtbl
;
940 ret
->IWinInetHttpInfo_iface
.lpVtbl
= &WinInetHttpInfoVtbl
;
945 *ppobj
= &ret
->IInternetProtocolEx_iface
;
951 HRESULT
HttpProtocol_Construct(IUnknown
*pUnkOuter
, LPVOID
*ppobj
)
953 TRACE("(%p %p)\n", pUnkOuter
, ppobj
);
955 return create_http_protocol(FALSE
, ppobj
);
958 HRESULT
HttpSProtocol_Construct(IUnknown
*pUnkOuter
, LPVOID
*ppobj
)
960 TRACE("(%p %p)\n", pUnkOuter
, ppobj
);
962 return create_http_protocol(TRUE
, ppobj
);