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 #include "urlmon_main.h"
23 #define NO_SHLWAPI_REG
26 #include "wine/debug.h"
28 WINE_DEFAULT_DEBUG_CHANNEL(urlmon
);
33 IInternetProtocolEx IInternetProtocolEx_iface
;
34 IInternetPriority IInternetPriority_iface
;
35 IWinInetHttpInfo IWinInetHttpInfo_iface
;
38 IHttpNegotiate
*http_negotiate
;
44 static inline HttpProtocol
*impl_from_IInternetProtocolEx(IInternetProtocolEx
*iface
)
46 return CONTAINING_RECORD(iface
, HttpProtocol
, IInternetProtocolEx_iface
);
49 static inline HttpProtocol
*impl_from_IInternetPriority(IInternetPriority
*iface
)
51 return CONTAINING_RECORD(iface
, HttpProtocol
, IInternetPriority_iface
);
54 static inline HttpProtocol
*impl_from_IWinInetHttpInfo(IWinInetHttpInfo
*iface
)
56 return CONTAINING_RECORD(iface
, HttpProtocol
, IWinInetHttpInfo_iface
);
59 static const WCHAR default_headersW
[] = {
60 '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};
62 static LPWSTR
query_http_info(HttpProtocol
*This
, DWORD option
)
68 res
= HttpQueryInfoW(This
->base
.request
, option
, NULL
, &len
, NULL
);
69 if (!res
&& GetLastError() == ERROR_INSUFFICIENT_BUFFER
) {
70 ret
= heap_alloc(len
);
71 res
= HttpQueryInfoW(This
->base
.request
, option
, ret
, &len
, NULL
);
74 TRACE("HttpQueryInfoW(%d) failed: %08x\n", option
, GetLastError());
82 static inline BOOL
set_security_flag(HttpProtocol
*This
, DWORD flags
)
86 res
= InternetSetOptionW(This
->base
.request
, INTERNET_OPTION_SECURITY_FLAGS
, &flags
, sizeof(flags
));
88 ERR("Failed to set security flags: %x\n", flags
);
93 static inline HRESULT
internet_error_to_hres(DWORD error
)
97 case ERROR_INTERNET_SEC_CERT_DATE_INVALID
:
98 case ERROR_INTERNET_SEC_CERT_CN_INVALID
:
99 case ERROR_INTERNET_INVALID_CA
:
100 case ERROR_INTERNET_CLIENT_AUTH_CERT_NEEDED
:
101 case ERROR_INTERNET_SEC_INVALID_CERT
:
102 case ERROR_INTERNET_SEC_CERT_ERRORS
:
103 case ERROR_INTERNET_SEC_CERT_REV_FAILED
:
104 case ERROR_INTERNET_SEC_CERT_NO_REV
:
105 case ERROR_INTERNET_SEC_CERT_REVOKED
:
106 return INET_E_INVALID_CERTIFICATE
;
107 case ERROR_INTERNET_HTTP_TO_HTTPS_ON_REDIR
:
108 case ERROR_INTERNET_HTTPS_TO_HTTP_ON_REDIR
:
109 case ERROR_HTTP_REDIRECT_NEEDS_CONFIRMATION
:
110 return INET_E_REDIRECT_FAILED
;
112 return INET_E_DOWNLOAD_FAILURE
;
116 static HRESULT
handle_http_error(HttpProtocol
*This
, DWORD error
)
118 IServiceProvider
*serv_prov
;
119 IWindowForBindingUI
*wfb_ui
;
120 IHttpSecurity
*http_security
;
121 BOOL security_problem
;
127 TRACE("(%p %u)\n", This
, error
);
130 case ERROR_INTERNET_SEC_CERT_DATE_INVALID
:
131 case ERROR_INTERNET_SEC_CERT_CN_INVALID
:
132 case ERROR_INTERNET_HTTP_TO_HTTPS_ON_REDIR
:
133 case ERROR_INTERNET_HTTPS_TO_HTTP_ON_REDIR
:
134 case ERROR_INTERNET_INVALID_CA
:
135 case ERROR_INTERNET_CLIENT_AUTH_CERT_NEEDED
:
136 case ERROR_INTERNET_SEC_INVALID_CERT
:
137 case ERROR_INTERNET_SEC_CERT_ERRORS
:
138 case ERROR_INTERNET_SEC_CERT_REV_FAILED
:
139 case ERROR_INTERNET_SEC_CERT_NO_REV
:
140 case ERROR_INTERNET_SEC_CERT_REVOKED
:
141 case ERROR_HTTP_REDIRECT_NEEDS_CONFIRMATION
:
142 security_problem
= TRUE
;
145 security_problem
= FALSE
;
148 hres
= IInternetProtocolSink_QueryInterface(This
->base
.protocol_sink
, &IID_IServiceProvider
,
151 ERR("Failed to get IServiceProvider.\n");
155 if(security_problem
) {
156 hres
= IServiceProvider_QueryService(serv_prov
, &IID_IHttpSecurity
, &IID_IHttpSecurity
,
157 (void**)&http_security
);
158 if(SUCCEEDED(hres
)) {
159 hres
= IHttpSecurity_OnSecurityProblem(http_security
, error
);
160 IHttpSecurity_Release(http_security
);
162 TRACE("OnSecurityProblem returned %08x\n", hres
);
168 IServiceProvider_Release(serv_prov
);
171 if(error
== ERROR_INTERNET_SEC_CERT_DATE_INVALID
)
172 res
= set_security_flag(This
, SECURITY_FLAG_IGNORE_CERT_DATE_INVALID
);
173 else if(error
== ERROR_INTERNET_SEC_CERT_CN_INVALID
)
174 res
= set_security_flag(This
, SECURITY_FLAG_IGNORE_CERT_CN_INVALID
);
175 else if(error
== ERROR_INTERNET_INVALID_CA
)
176 res
= set_security_flag(This
, SECURITY_FLAG_IGNORE_UNKNOWN_CA
);
181 FIXME("Don't know how to ignore error %d\n", error
);
187 if(hres
== RPC_E_RETRY
)
190 return internet_error_to_hres(error
);
196 case ERROR_INTERNET_SEC_CERT_REV_FAILED
:
197 if(hres
!= S_FALSE
) {
198 /* Silently ignore the error. We will get more detailed error from wininet anyway. */
199 set_security_flag(This
, SECURITY_FLAG_IGNORE_REVOCATION
);
205 hres
= IServiceProvider_QueryService(serv_prov
, &IID_IWindowForBindingUI
, &IID_IWindowForBindingUI
, (void**)&wfb_ui
);
206 if(SUCCEEDED(hres
)) {
207 const IID
*iid_reason
;
210 iid_reason
= &IID_IHttpSecurity
;
211 else if(error
== ERROR_INTERNET_INCORRECT_PASSWORD
)
212 iid_reason
= &IID_IAuthenticate
;
214 iid_reason
= &IID_IWindowForBindingUI
;
216 hres
= IWindowForBindingUI_GetWindow(wfb_ui
, iid_reason
, &hwnd
);
217 IWindowForBindingUI_Release(wfb_ui
);
223 dlg_flags
= FLAGS_ERROR_UI_FLAGS_CHANGE_OPTIONS
| FLAGS_ERROR_UI_FLAGS_GENERATE_DATA
;
224 if(This
->base
.bindf
& BINDF_NO_UI
)
225 dlg_flags
|= FLAGS_ERROR_UI_FLAGS_NO_UI
;
227 res
= InternetErrorDlg(hwnd
, This
->base
.request
, error
, dlg_flags
, NULL
);
228 hres
= res
== ERROR_INTERNET_FORCE_RETRY
|| res
== ERROR_SUCCESS
? RPC_E_RETRY
: internet_error_to_hres(error
);
231 IServiceProvider_Release(serv_prov
);
235 static ULONG
send_http_request(HttpProtocol
*This
)
237 INTERNET_BUFFERSW send_buffer
= {sizeof(INTERNET_BUFFERSW
)};
240 send_buffer
.lpcszHeader
= This
->full_header
;
241 send_buffer
.dwHeadersLength
= send_buffer
.dwHeadersTotal
= strlenW(This
->full_header
);
243 if(This
->base
.bind_info
.dwBindVerb
!= BINDVERB_GET
) {
244 switch(This
->base
.bind_info
.stgmedData
.tymed
) {
246 /* Native does not use GlobalLock/GlobalUnlock, so we won't either */
247 send_buffer
.lpvBuffer
= This
->base
.bind_info
.stgmedData
.u
.hGlobal
;
248 send_buffer
.dwBufferLength
= send_buffer
.dwBufferTotal
= This
->base
.bind_info
.cbstgmedData
;
250 case TYMED_ISTREAM
: {
251 LARGE_INTEGER offset
;
253 send_buffer
.dwBufferTotal
= This
->base
.bind_info
.cbstgmedData
;
254 if(!This
->base
.post_stream
) {
255 This
->base
.post_stream
= This
->base
.bind_info
.stgmedData
.u
.pstm
;
256 IStream_AddRef(This
->base
.post_stream
);
260 IStream_Seek(This
->base
.post_stream
, offset
, STREAM_SEEK_SET
, NULL
);
264 FIXME("Unsupported This->base.bind_info.stgmedData.tymed %d\n", This
->base
.bind_info
.stgmedData
.tymed
);
268 if(This
->base
.post_stream
)
269 res
= HttpSendRequestExW(This
->base
.request
, &send_buffer
, NULL
, 0, 0);
271 res
= HttpSendRequestW(This
->base
.request
, send_buffer
.lpcszHeader
, send_buffer
.dwHeadersLength
,
272 send_buffer
.lpvBuffer
, send_buffer
.dwBufferLength
);
274 return res
? 0 : GetLastError();
277 static inline HttpProtocol
*impl_from_Protocol(Protocol
*prot
)
279 return CONTAINING_RECORD(prot
, HttpProtocol
, base
);
282 static HRESULT
HttpProtocol_open_request(Protocol
*prot
, IUri
*uri
, DWORD request_flags
,
283 HINTERNET internet_session
, IInternetBindInfo
*bind_info
)
285 HttpProtocol
*This
= impl_from_Protocol(prot
);
286 LPWSTR addl_header
= NULL
, post_cookie
= NULL
;
287 IServiceProvider
*service_provider
= NULL
;
288 IHttpNegotiate2
*http_negotiate2
= NULL
;
289 BSTR url
, host
, user
, pass
, path
;
290 LPOLESTR accept_mimes
[257];
291 const WCHAR
**accept_types
;
292 BYTE security_id
[512];
293 DWORD len
, port
, flags
;
298 static const WCHAR wszBindVerb
[BINDVERB_CUSTOM
][5] =
303 hres
= IUri_GetPort(uri
, &port
);
307 hres
= IUri_GetHost(uri
, &host
);
311 hres
= IUri_GetUserName(uri
, &user
);
312 if(SUCCEEDED(hres
)) {
313 hres
= IUri_GetPassword(uri
, &pass
);
315 if(SUCCEEDED(hres
)) {
316 This
->base
.connection
= InternetConnectW(internet_session
, host
, port
, user
, pass
,
317 INTERNET_SERVICE_HTTP
, This
->https
? INTERNET_FLAG_SECURE
: 0, (DWORD_PTR
)&This
->base
);
325 if(!This
->base
.connection
) {
326 WARN("InternetConnect failed: %d\n", GetLastError());
327 return INET_E_CANNOT_CONNECT
;
330 num
= sizeof(accept_mimes
)/sizeof(accept_mimes
[0])-1;
331 hres
= IInternetBindInfo_GetBindString(bind_info
, BINDSTRING_ACCEPT_MIMES
, accept_mimes
, num
, &num
);
332 if(hres
== INET_E_USE_DEFAULT_SETTING
) {
333 static const WCHAR default_accept_mimeW
[] = {'*','/','*',0};
334 static const WCHAR
*default_accept_mimes
[] = {default_accept_mimeW
, NULL
};
336 accept_types
= default_accept_mimes
;
338 }else if(hres
== S_OK
) {
339 accept_types
= (const WCHAR
**)accept_mimes
;
341 WARN("GetBindString BINDSTRING_ACCEPT_MIMES failed: %08x\n", hres
);
342 return INET_E_NO_VALID_MEDIA
;
344 accept_mimes
[num
] = 0;
347 request_flags
|= INTERNET_FLAG_SECURE
;
349 hres
= IUri_GetPathAndQuery(uri
, &path
);
350 if(SUCCEEDED(hres
)) {
351 This
->base
.request
= HttpOpenRequestW(This
->base
.connection
,
352 This
->base
.bind_info
.dwBindVerb
< BINDVERB_CUSTOM
353 ? wszBindVerb
[This
->base
.bind_info
.dwBindVerb
] : This
->base
.bind_info
.szCustomVerb
,
354 path
, NULL
, NULL
, accept_types
, request_flags
, (DWORD_PTR
)&This
->base
);
358 CoTaskMemFree(accept_mimes
[num
]);
361 if (!This
->base
.request
) {
362 WARN("HttpOpenRequest failed: %d\n", GetLastError());
363 return INET_E_RESOURCE_NOT_FOUND
;
366 hres
= IInternetProtocolSink_QueryInterface(This
->base
.protocol_sink
, &IID_IServiceProvider
,
367 (void **)&service_provider
);
369 WARN("IInternetProtocolSink_QueryInterface IID_IServiceProvider failed: %08x\n", hres
);
373 hres
= IServiceProvider_QueryService(service_provider
, &IID_IHttpNegotiate
,
374 &IID_IHttpNegotiate
, (void **)&This
->http_negotiate
);
376 WARN("IServiceProvider_QueryService IID_IHttpNegotiate failed: %08x\n", hres
);
377 IServiceProvider_Release(service_provider
);
381 hres
= IUri_GetAbsoluteUri(uri
, &url
);
383 IServiceProvider_Release(service_provider
);
387 hres
= IHttpNegotiate_BeginningTransaction(This
->http_negotiate
, url
, default_headersW
,
391 WARN("IHttpNegotiate_BeginningTransaction failed: %08x\n", hres
);
392 IServiceProvider_Release(service_provider
);
396 len
= addl_header
? strlenW(addl_header
) : 0;
398 This
->full_header
= heap_alloc(len
*sizeof(WCHAR
)+sizeof(default_headersW
));
399 if(!This
->full_header
) {
400 IServiceProvider_Release(service_provider
);
401 return E_OUTOFMEMORY
;
405 memcpy(This
->full_header
, addl_header
, len
*sizeof(WCHAR
));
406 CoTaskMemFree(addl_header
);
407 memcpy(This
->full_header
+len
, default_headersW
, sizeof(default_headersW
));
409 hres
= IServiceProvider_QueryService(service_provider
, &IID_IHttpNegotiate2
,
410 &IID_IHttpNegotiate2
, (void **)&http_negotiate2
);
411 IServiceProvider_Release(service_provider
);
413 WARN("IServiceProvider_QueryService IID_IHttpNegotiate2 failed: %08x\n", hres
);
414 /* No goto done as per native */
416 len
= sizeof(security_id
)/sizeof(security_id
[0]);
417 hres
= IHttpNegotiate2_GetRootSecurityId(http_negotiate2
, security_id
, &len
, 0);
418 IHttpNegotiate2_Release(http_negotiate2
);
420 WARN("IHttpNegotiate2_GetRootSecurityId failed: %08x\n", hres
);
423 /* FIXME: Handle security_id. Native calls undocumented function IsHostInProxyBypassList. */
425 if(This
->base
.bind_info
.dwBindVerb
== BINDVERB_POST
) {
427 hres
= IInternetBindInfo_GetBindString(bind_info
, BINDSTRING_POST_COOKIE
, &post_cookie
, 1, &num
);
428 if(hres
== S_OK
&& num
) {
429 if(!InternetSetOptionW(This
->base
.request
, INTERNET_OPTION_SECONDARY_CACHE_KEY
,
430 post_cookie
, lstrlenW(post_cookie
)))
431 WARN("InternetSetOption INTERNET_OPTION_SECONDARY_CACHE_KEY failed: %d\n", GetLastError());
432 CoTaskMemFree(post_cookie
);
436 flags
= INTERNET_ERROR_MASK_COMBINED_SEC_CERT
;
437 res
= InternetSetOptionW(This
->base
.request
, INTERNET_OPTION_ERROR_MASK
, &flags
, sizeof(flags
));
439 WARN("InternetSetOption(INTERNET_OPTION_ERROR_MASK) failed: %u\n", GetLastError());
442 res
= InternetSetOptionW(This
->base
.request
, INTERNET_OPTION_HTTP_DECODING
, &b
, sizeof(b
));
444 WARN("InternetSetOption(INTERNET_OPTION_HTTP_DECODING) failed: %u\n", GetLastError());
447 error
= send_http_request(This
);
449 if(error
== ERROR_IO_PENDING
|| error
== ERROR_SUCCESS
)
452 hres
= handle_http_error(This
, error
);
454 } while(hres
== RPC_E_RETRY
);
456 WARN("HttpSendRequest failed: %d\n", error
);
460 static HRESULT
HttpProtocol_end_request(Protocol
*protocol
)
464 res
= HttpEndRequestW(protocol
->request
, NULL
, 0, 0);
465 if(!res
&& GetLastError() != ERROR_IO_PENDING
) {
466 FIXME("HttpEndRequest failed: %u\n", GetLastError());
473 static HRESULT
HttpProtocol_start_downloading(Protocol
*prot
)
475 HttpProtocol
*This
= impl_from_Protocol(prot
);
476 LPWSTR content_type
, content_length
, ranges
;
477 DWORD len
= sizeof(DWORD
);
482 static const WCHAR wszDefaultContentType
[] =
483 {'t','e','x','t','/','h','t','m','l',0};
485 if(!This
->http_negotiate
) {
486 WARN("Expected IHttpNegotiate pointer to be non-NULL\n");
490 res
= HttpQueryInfoW(This
->base
.request
, HTTP_QUERY_STATUS_CODE
| HTTP_QUERY_FLAG_NUMBER
,
491 &status_code
, &len
, NULL
);
493 LPWSTR response_headers
= query_http_info(This
, HTTP_QUERY_RAW_HEADERS_CRLF
);
494 if(response_headers
) {
495 hres
= IHttpNegotiate_OnResponse(This
->http_negotiate
, status_code
, response_headers
,
497 heap_free(response_headers
);
499 WARN("IHttpNegotiate_OnResponse failed: %08x\n", hres
);
504 WARN("HttpQueryInfo failed: %d\n", GetLastError());
507 ranges
= query_http_info(This
, HTTP_QUERY_ACCEPT_RANGES
);
509 IInternetProtocolSink_ReportProgress(This
->base
.protocol_sink
, BINDSTATUS_ACCEPTRANGES
, NULL
);
513 content_type
= query_http_info(This
, HTTP_QUERY_CONTENT_TYPE
);
515 /* remove the charset, if present */
516 LPWSTR p
= strchrW(content_type
, ';');
519 IInternetProtocolSink_ReportProgress(This
->base
.protocol_sink
,
520 (This
->base
.bindf
& BINDF_FROMURLMON
)
521 ? BINDSTATUS_MIMETYPEAVAILABLE
: BINDSTATUS_RAWMIMETYPE
,
523 heap_free(content_type
);
525 WARN("HttpQueryInfo failed: %d\n", GetLastError());
526 IInternetProtocolSink_ReportProgress(This
->base
.protocol_sink
,
527 (This
->base
.bindf
& BINDF_FROMURLMON
)
528 ? BINDSTATUS_MIMETYPEAVAILABLE
: BINDSTATUS_RAWMIMETYPE
,
529 wszDefaultContentType
);
532 content_length
= query_http_info(This
, HTTP_QUERY_CONTENT_LENGTH
);
534 This
->base
.content_length
= atoiW(content_length
);
535 heap_free(content_length
);
541 static void HttpProtocol_close_connection(Protocol
*prot
)
543 HttpProtocol
*This
= impl_from_Protocol(prot
);
545 if(This
->http_negotiate
) {
546 IHttpNegotiate_Release(This
->http_negotiate
);
547 This
->http_negotiate
= NULL
;
550 heap_free(This
->full_header
);
551 This
->full_header
= NULL
;
554 static void HttpProtocol_on_error(Protocol
*prot
, DWORD error
)
556 HttpProtocol
*This
= impl_from_Protocol(prot
);
559 TRACE("(%p) %d\n", prot
, error
);
561 if(prot
->flags
& FLAG_FIRST_CONTINUE_COMPLETE
) {
562 FIXME("Not handling error %d\n", error
);
566 while((hres
= handle_http_error(This
, error
)) == RPC_E_RETRY
) {
567 error
= send_http_request(This
);
569 if(error
== ERROR_IO_PENDING
|| error
== ERROR_SUCCESS
)
573 protocol_abort(prot
, hres
);
574 protocol_close_connection(prot
);
578 static const ProtocolVtbl AsyncProtocolVtbl
= {
579 HttpProtocol_open_request
,
580 HttpProtocol_end_request
,
581 HttpProtocol_start_downloading
,
582 HttpProtocol_close_connection
,
583 HttpProtocol_on_error
586 static HRESULT WINAPI
HttpProtocol_QueryInterface(IInternetProtocolEx
*iface
, REFIID riid
, void **ppv
)
588 HttpProtocol
*This
= impl_from_IInternetProtocolEx(iface
);
591 if(IsEqualGUID(&IID_IUnknown
, riid
)) {
592 TRACE("(%p)->(IID_IUnknown %p)\n", This
, ppv
);
593 *ppv
= &This
->IInternetProtocolEx_iface
;
594 }else if(IsEqualGUID(&IID_IInternetProtocolRoot
, riid
)) {
595 TRACE("(%p)->(IID_IInternetProtocolRoot %p)\n", This
, ppv
);
596 *ppv
= &This
->IInternetProtocolEx_iface
;
597 }else if(IsEqualGUID(&IID_IInternetProtocol
, riid
)) {
598 TRACE("(%p)->(IID_IInternetProtocol %p)\n", This
, ppv
);
599 *ppv
= &This
->IInternetProtocolEx_iface
;
600 }else if(IsEqualGUID(&IID_IInternetProtocolEx
, riid
)) {
601 TRACE("(%p)->(IID_IInternetProtocolEx %p)\n", This
, ppv
);
602 *ppv
= &This
->IInternetProtocolEx_iface
;
603 }else if(IsEqualGUID(&IID_IInternetPriority
, riid
)) {
604 TRACE("(%p)->(IID_IInternetPriority %p)\n", This
, ppv
);
605 *ppv
= &This
->IInternetPriority_iface
;
606 }else if(IsEqualGUID(&IID_IWinInetInfo
, riid
)) {
607 TRACE("(%p)->(IID_IWinInetInfo %p)\n", This
, ppv
);
608 *ppv
= &This
->IWinInetHttpInfo_iface
;
609 }else if(IsEqualGUID(&IID_IWinInetHttpInfo
, riid
)) {
610 TRACE("(%p)->(IID_IWinInetHttpInfo %p)\n", This
, ppv
);
611 *ppv
= &This
->IWinInetHttpInfo_iface
;
615 IInternetProtocolEx_AddRef(iface
);
619 WARN("not supported interface %s\n", debugstr_guid(riid
));
620 return E_NOINTERFACE
;
623 static ULONG WINAPI
HttpProtocol_AddRef(IInternetProtocolEx
*iface
)
625 HttpProtocol
*This
= impl_from_IInternetProtocolEx(iface
);
626 LONG ref
= InterlockedIncrement(&This
->ref
);
627 TRACE("(%p) ref=%d\n", This
, ref
);
631 static ULONG WINAPI
HttpProtocol_Release(IInternetProtocolEx
*iface
)
633 HttpProtocol
*This
= impl_from_IInternetProtocolEx(iface
);
634 LONG ref
= InterlockedDecrement(&This
->ref
);
636 TRACE("(%p) ref=%d\n", This
, ref
);
639 protocol_close_connection(&This
->base
);
642 URLMON_UnlockModule();
648 static HRESULT WINAPI
HttpProtocol_Start(IInternetProtocolEx
*iface
, LPCWSTR szUrl
,
649 IInternetProtocolSink
*pOIProtSink
, IInternetBindInfo
*pOIBindInfo
,
650 DWORD grfPI
, HANDLE_PTR dwReserved
)
652 HttpProtocol
*This
= impl_from_IInternetProtocolEx(iface
);
656 TRACE("(%p)->(%s %p %p %08x %lx)\n", This
, debugstr_w(szUrl
), pOIProtSink
,
657 pOIBindInfo
, grfPI
, dwReserved
);
659 hres
= CreateUri(szUrl
, 0, 0, &uri
);
663 hres
= IInternetProtocolEx_StartEx(&This
->IInternetProtocolEx_iface
, uri
, pOIProtSink
,
664 pOIBindInfo
, grfPI
, (HANDLE
*)dwReserved
);
670 static HRESULT WINAPI
HttpProtocol_Continue(IInternetProtocolEx
*iface
, PROTOCOLDATA
*pProtocolData
)
672 HttpProtocol
*This
= impl_from_IInternetProtocolEx(iface
);
674 TRACE("(%p)->(%p)\n", This
, pProtocolData
);
676 return protocol_continue(&This
->base
, pProtocolData
);
679 static HRESULT WINAPI
HttpProtocol_Abort(IInternetProtocolEx
*iface
, HRESULT hrReason
,
682 HttpProtocol
*This
= impl_from_IInternetProtocolEx(iface
);
684 TRACE("(%p)->(%08x %08x)\n", This
, hrReason
, dwOptions
);
686 return protocol_abort(&This
->base
, hrReason
);
689 static HRESULT WINAPI
HttpProtocol_Terminate(IInternetProtocolEx
*iface
, DWORD dwOptions
)
691 HttpProtocol
*This
= impl_from_IInternetProtocolEx(iface
);
693 TRACE("(%p)->(%08x)\n", This
, dwOptions
);
695 protocol_close_connection(&This
->base
);
699 static HRESULT WINAPI
HttpProtocol_Suspend(IInternetProtocolEx
*iface
)
701 HttpProtocol
*This
= impl_from_IInternetProtocolEx(iface
);
702 FIXME("(%p)\n", This
);
706 static HRESULT WINAPI
HttpProtocol_Resume(IInternetProtocolEx
*iface
)
708 HttpProtocol
*This
= impl_from_IInternetProtocolEx(iface
);
709 FIXME("(%p)\n", This
);
713 static HRESULT WINAPI
HttpProtocol_Read(IInternetProtocolEx
*iface
, void *pv
,
714 ULONG cb
, ULONG
*pcbRead
)
716 HttpProtocol
*This
= impl_from_IInternetProtocolEx(iface
);
718 TRACE("(%p)->(%p %u %p)\n", This
, pv
, cb
, pcbRead
);
720 return protocol_read(&This
->base
, pv
, cb
, pcbRead
);
723 static HRESULT WINAPI
HttpProtocol_Seek(IInternetProtocolEx
*iface
, LARGE_INTEGER dlibMove
,
724 DWORD dwOrigin
, ULARGE_INTEGER
*plibNewPosition
)
726 HttpProtocol
*This
= impl_from_IInternetProtocolEx(iface
);
727 FIXME("(%p)->(%d %d %p)\n", This
, dlibMove
.u
.LowPart
, dwOrigin
, plibNewPosition
);
731 static HRESULT WINAPI
HttpProtocol_LockRequest(IInternetProtocolEx
*iface
, DWORD dwOptions
)
733 HttpProtocol
*This
= impl_from_IInternetProtocolEx(iface
);
735 TRACE("(%p)->(%08x)\n", This
, dwOptions
);
737 return protocol_lock_request(&This
->base
);
740 static HRESULT WINAPI
HttpProtocol_UnlockRequest(IInternetProtocolEx
*iface
)
742 HttpProtocol
*This
= impl_from_IInternetProtocolEx(iface
);
744 TRACE("(%p)\n", This
);
746 return protocol_unlock_request(&This
->base
);
749 static HRESULT WINAPI
HttpProtocol_StartEx(IInternetProtocolEx
*iface
, IUri
*pUri
,
750 IInternetProtocolSink
*pOIProtSink
, IInternetBindInfo
*pOIBindInfo
,
751 DWORD grfPI
, HANDLE
*dwReserved
)
753 HttpProtocol
*This
= impl_from_IInternetProtocolEx(iface
);
757 TRACE("(%p)->(%p %p %p %08x %p)\n", This
, pUri
, pOIProtSink
,
758 pOIBindInfo
, grfPI
, dwReserved
);
760 hres
= IUri_GetScheme(pUri
, &scheme
);
763 if(scheme
!= (This
->https
? URL_SCHEME_HTTPS
: URL_SCHEME_HTTP
))
766 return protocol_start(&This
->base
, (IInternetProtocol
*)&This
->IInternetProtocolEx_iface
, pUri
,
767 pOIProtSink
, pOIBindInfo
);
770 static const IInternetProtocolExVtbl HttpProtocolVtbl
= {
771 HttpProtocol_QueryInterface
,
773 HttpProtocol_Release
,
775 HttpProtocol_Continue
,
777 HttpProtocol_Terminate
,
778 HttpProtocol_Suspend
,
782 HttpProtocol_LockRequest
,
783 HttpProtocol_UnlockRequest
,
787 static HRESULT WINAPI
HttpPriority_QueryInterface(IInternetPriority
*iface
, REFIID riid
, void **ppv
)
789 HttpProtocol
*This
= impl_from_IInternetPriority(iface
);
790 return IInternetProtocolEx_QueryInterface(&This
->IInternetProtocolEx_iface
, riid
, ppv
);
793 static ULONG WINAPI
HttpPriority_AddRef(IInternetPriority
*iface
)
795 HttpProtocol
*This
= impl_from_IInternetPriority(iface
);
796 return IInternetProtocolEx_AddRef(&This
->IInternetProtocolEx_iface
);
799 static ULONG WINAPI
HttpPriority_Release(IInternetPriority
*iface
)
801 HttpProtocol
*This
= impl_from_IInternetPriority(iface
);
802 return IInternetProtocolEx_Release(&This
->IInternetProtocolEx_iface
);
805 static HRESULT WINAPI
HttpPriority_SetPriority(IInternetPriority
*iface
, LONG nPriority
)
807 HttpProtocol
*This
= impl_from_IInternetPriority(iface
);
809 TRACE("(%p)->(%d)\n", This
, nPriority
);
811 This
->base
.priority
= nPriority
;
815 static HRESULT WINAPI
HttpPriority_GetPriority(IInternetPriority
*iface
, LONG
*pnPriority
)
817 HttpProtocol
*This
= impl_from_IInternetPriority(iface
);
819 TRACE("(%p)->(%p)\n", This
, pnPriority
);
821 *pnPriority
= This
->base
.priority
;
825 static const IInternetPriorityVtbl HttpPriorityVtbl
= {
826 HttpPriority_QueryInterface
,
828 HttpPriority_Release
,
829 HttpPriority_SetPriority
,
830 HttpPriority_GetPriority
833 static HRESULT WINAPI
HttpInfo_QueryInterface(IWinInetHttpInfo
*iface
, REFIID riid
, void **ppv
)
835 HttpProtocol
*This
= impl_from_IWinInetHttpInfo(iface
);
836 return IInternetProtocolEx_QueryInterface(&This
->IInternetProtocolEx_iface
, riid
, ppv
);
839 static ULONG WINAPI
HttpInfo_AddRef(IWinInetHttpInfo
*iface
)
841 HttpProtocol
*This
= impl_from_IWinInetHttpInfo(iface
);
842 return IInternetProtocolEx_AddRef(&This
->IInternetProtocolEx_iface
);
845 static ULONG WINAPI
HttpInfo_Release(IWinInetHttpInfo
*iface
)
847 HttpProtocol
*This
= impl_from_IWinInetHttpInfo(iface
);
848 return IInternetProtocolEx_Release(&This
->IInternetProtocolEx_iface
);
851 static HRESULT WINAPI
HttpInfo_QueryOption(IWinInetHttpInfo
*iface
, DWORD dwOption
,
852 void *pBuffer
, DWORD
*pcbBuffer
)
854 HttpProtocol
*This
= impl_from_IWinInetHttpInfo(iface
);
855 TRACE("(%p)->(%x %p %p)\n", This
, dwOption
, pBuffer
, pcbBuffer
);
857 if(!This
->base
.request
)
860 if(!InternetQueryOptionW(This
->base
.request
, dwOption
, pBuffer
, pcbBuffer
))
865 static HRESULT WINAPI
HttpInfo_QueryInfo(IWinInetHttpInfo
*iface
, DWORD dwOption
,
866 void *pBuffer
, DWORD
*pcbBuffer
, DWORD
*pdwFlags
, DWORD
*pdwReserved
)
868 HttpProtocol
*This
= impl_from_IWinInetHttpInfo(iface
);
869 TRACE("(%p)->(%x %p %p %p %p)\n", This
, dwOption
, pBuffer
, pcbBuffer
, pdwFlags
, pdwReserved
);
871 if(!This
->base
.request
)
874 if(!HttpQueryInfoW(This
->base
.request
, dwOption
, pBuffer
, pcbBuffer
, pdwFlags
)) {
876 memset(pBuffer
, 0, *pcbBuffer
);
882 static const IWinInetHttpInfoVtbl WinInetHttpInfoVtbl
= {
883 HttpInfo_QueryInterface
,
886 HttpInfo_QueryOption
,
890 static HRESULT
create_http_protocol(BOOL https
, void **ppobj
)
894 ret
= heap_alloc_zero(sizeof(HttpProtocol
));
896 return E_OUTOFMEMORY
;
898 ret
->base
.vtbl
= &AsyncProtocolVtbl
;
899 ret
->IInternetProtocolEx_iface
.lpVtbl
= &HttpProtocolVtbl
;
900 ret
->IInternetPriority_iface
.lpVtbl
= &HttpPriorityVtbl
;
901 ret
->IWinInetHttpInfo_iface
.lpVtbl
= &WinInetHttpInfoVtbl
;
906 *ppobj
= &ret
->IInternetProtocolEx_iface
;
912 HRESULT
HttpProtocol_Construct(IUnknown
*pUnkOuter
, LPVOID
*ppobj
)
914 TRACE("(%p %p)\n", pUnkOuter
, ppobj
);
916 return create_http_protocol(FALSE
, ppobj
);
919 HRESULT
HttpSProtocol_Construct(IUnknown
*pUnkOuter
, LPVOID
*ppobj
)
921 TRACE("(%p %p)\n", pUnkOuter
, ppobj
);
923 return create_http_protocol(TRUE
, ppobj
);