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 /* Default headers from native */
60 static const WCHAR wszHeaders
[] = {'A','c','c','e','p','t','-','E','n','c','o','d','i','n','g',
61 ':',' ','g','z','i','p',',',' ','d','e','f','l','a','t','e',0};
63 static LPWSTR
query_http_info(HttpProtocol
*This
, DWORD option
)
69 res
= HttpQueryInfoW(This
->base
.request
, option
, NULL
, &len
, NULL
);
70 if (!res
&& GetLastError() == ERROR_INSUFFICIENT_BUFFER
) {
71 ret
= heap_alloc(len
);
72 res
= HttpQueryInfoW(This
->base
.request
, option
, ret
, &len
, NULL
);
75 TRACE("HttpQueryInfoW(%d) failed: %08x\n", option
, GetLastError());
83 static inline BOOL
set_security_flag(HttpProtocol
*This
, DWORD new_flag
)
85 DWORD flags
, size
= sizeof(flags
);
88 res
= InternetQueryOptionW(This
->base
.request
, INTERNET_OPTION_SECURITY_FLAGS
, &flags
, &size
);
91 res
= InternetSetOptionW(This
->base
.request
, INTERNET_OPTION_SECURITY_FLAGS
, &flags
, size
);
94 ERR("Failed to set security flag(s): %x\n", new_flag
);
99 static inline HRESULT
internet_error_to_hres(DWORD error
)
103 case ERROR_INTERNET_SEC_CERT_DATE_INVALID
:
104 case ERROR_INTERNET_SEC_CERT_CN_INVALID
:
105 case ERROR_INTERNET_INVALID_CA
:
106 case ERROR_INTERNET_CLIENT_AUTH_CERT_NEEDED
:
107 return INET_E_INVALID_CERTIFICATE
;
108 case ERROR_INTERNET_HTTP_TO_HTTPS_ON_REDIR
:
109 case ERROR_INTERNET_HTTPS_TO_HTTP_ON_REDIR
:
110 case ERROR_HTTP_REDIRECT_NEEDS_CONFIRMATION
:
111 return INET_E_REDIRECT_FAILED
;
113 return INET_E_DOWNLOAD_FAILURE
;
117 static HRESULT
handle_http_error(HttpProtocol
*This
, DWORD error
)
119 IServiceProvider
*serv_prov
;
120 IWindowForBindingUI
*wfb_ui
;
121 IHttpSecurity
*http_security
;
122 BOOL security_problem
;
126 case ERROR_INTERNET_SEC_CERT_DATE_INVALID
:
127 case ERROR_INTERNET_SEC_CERT_CN_INVALID
:
128 case ERROR_INTERNET_HTTP_TO_HTTPS_ON_REDIR
:
129 case ERROR_INTERNET_HTTPS_TO_HTTP_ON_REDIR
:
130 case ERROR_HTTP_REDIRECT_NEEDS_CONFIRMATION
:
131 case ERROR_INTERNET_INVALID_CA
:
132 case ERROR_INTERNET_CLIENT_AUTH_CERT_NEEDED
:
133 security_problem
= TRUE
;
136 security_problem
= FALSE
;
139 hres
= IInternetProtocolSink_QueryInterface(This
->base
.protocol_sink
, &IID_IServiceProvider
,
142 ERR("Failed to get IServiceProvider.\n");
146 if(security_problem
) {
147 hres
= IServiceProvider_QueryService(serv_prov
, &IID_IHttpSecurity
, &IID_IHttpSecurity
,
148 (void**)&http_security
);
149 if(SUCCEEDED(hres
)) {
150 hres
= IHttpSecurity_OnSecurityProblem(http_security
, error
);
151 IHttpSecurity_Release(http_security
);
157 IServiceProvider_Release(serv_prov
);
160 if(error
== ERROR_INTERNET_SEC_CERT_DATE_INVALID
)
161 res
= set_security_flag(This
, SECURITY_FLAG_IGNORE_CERT_DATE_INVALID
);
162 else if(error
== ERROR_INTERNET_SEC_CERT_CN_INVALID
)
163 res
= set_security_flag(This
, SECURITY_FLAG_IGNORE_CERT_CN_INVALID
);
164 else if(error
== ERROR_INTERNET_INVALID_CA
)
165 res
= set_security_flag(This
, SECURITY_FLAG_IGNORE_UNKNOWN_CA
);
170 FIXME("Don't know how to ignore error %d\n", error
);
176 if(hres
== RPC_E_RETRY
)
179 return internet_error_to_hres(error
);
184 hres
= IServiceProvider_QueryService(serv_prov
, &IID_IWindowForBindingUI
, &IID_IWindowForBindingUI
,
186 if(SUCCEEDED(hres
)) {
188 const IID
*iid_reason
;
191 iid_reason
= &IID_IHttpSecurity
;
192 else if(error
== ERROR_INTERNET_INCORRECT_PASSWORD
)
193 iid_reason
= &IID_IAuthenticate
;
195 iid_reason
= &IID_IWindowForBindingUI
;
197 hres
= IWindowForBindingUI_GetWindow(wfb_ui
, iid_reason
, &hwnd
);
198 if(SUCCEEDED(hres
) && hwnd
)
202 res
= InternetErrorDlg(hwnd
, This
->base
.request
, error
,
203 FLAGS_ERROR_UI_FLAGS_CHANGE_OPTIONS
| FLAGS_ERROR_UI_FLAGS_GENERATE_DATA
,
206 if(res
== ERROR_INTERNET_FORCE_RETRY
|| res
== ERROR_SUCCESS
)
211 IWindowForBindingUI_Release(wfb_ui
);
214 IServiceProvider_Release(serv_prov
);
216 if(hres
== RPC_E_RETRY
)
219 return internet_error_to_hres(error
);
222 static ULONG
send_http_request(HttpProtocol
*This
)
224 INTERNET_BUFFERSW send_buffer
= {sizeof(INTERNET_BUFFERSW
)};
227 send_buffer
.lpcszHeader
= This
->full_header
;
228 send_buffer
.dwHeadersLength
= send_buffer
.dwHeadersTotal
= strlenW(This
->full_header
);
230 if(This
->base
.bind_info
.dwBindVerb
!= BINDVERB_GET
) {
231 switch(This
->base
.bind_info
.stgmedData
.tymed
) {
233 /* Native does not use GlobalLock/GlobalUnlock, so we won't either */
234 send_buffer
.lpvBuffer
= This
->base
.bind_info
.stgmedData
.u
.hGlobal
;
235 send_buffer
.dwBufferLength
= send_buffer
.dwBufferTotal
= This
->base
.bind_info
.cbstgmedData
;
237 case TYMED_ISTREAM
: {
238 LARGE_INTEGER offset
;
240 send_buffer
.dwBufferTotal
= This
->base
.bind_info
.cbstgmedData
;
241 if(!This
->base
.post_stream
) {
242 This
->base
.post_stream
= This
->base
.bind_info
.stgmedData
.u
.pstm
;
243 IStream_AddRef(This
->base
.post_stream
);
247 IStream_Seek(This
->base
.post_stream
, offset
, STREAM_SEEK_SET
, NULL
);
251 FIXME("Unsupported This->base.bind_info.stgmedData.tymed %d\n", This
->base
.bind_info
.stgmedData
.tymed
);
255 if(This
->base
.post_stream
)
256 res
= HttpSendRequestExW(This
->base
.request
, &send_buffer
, NULL
, 0, 0);
258 res
= HttpSendRequestW(This
->base
.request
, send_buffer
.lpcszHeader
, send_buffer
.dwHeadersLength
,
259 send_buffer
.lpvBuffer
, send_buffer
.dwBufferLength
);
261 return res
? 0 : GetLastError();
264 static inline HttpProtocol
*impl_from_Protocol(Protocol
*prot
)
266 return CONTAINING_RECORD(prot
, HttpProtocol
, base
);
269 static HRESULT
HttpProtocol_open_request(Protocol
*prot
, IUri
*uri
, DWORD request_flags
,
270 HINTERNET internet_session
, IInternetBindInfo
*bind_info
)
272 HttpProtocol
*This
= impl_from_Protocol(prot
);
273 LPWSTR addl_header
= NULL
, post_cookie
= NULL
;
274 IServiceProvider
*service_provider
= NULL
;
275 IHttpNegotiate2
*http_negotiate2
= NULL
;
276 BSTR url
, host
, user
, pass
, path
;
277 LPOLESTR accept_mimes
[257];
278 const WCHAR
**accept_types
;
279 BYTE security_id
[512];
285 static const WCHAR wszBindVerb
[BINDVERB_CUSTOM
][5] =
290 hres
= IUri_GetPort(uri
, &port
);
294 hres
= IUri_GetHost(uri
, &host
);
298 hres
= IUri_GetUserName(uri
, &user
);
299 if(SUCCEEDED(hres
)) {
300 hres
= IUri_GetPassword(uri
, &pass
);
302 if(SUCCEEDED(hres
)) {
303 This
->base
.connection
= InternetConnectW(internet_session
, host
, port
, user
, pass
,
304 INTERNET_SERVICE_HTTP
, This
->https
? INTERNET_FLAG_SECURE
: 0, (DWORD_PTR
)&This
->base
);
312 if(!This
->base
.connection
) {
313 WARN("InternetConnect failed: %d\n", GetLastError());
314 return INET_E_CANNOT_CONNECT
;
317 num
= sizeof(accept_mimes
)/sizeof(accept_mimes
[0])-1;
318 hres
= IInternetBindInfo_GetBindString(bind_info
, BINDSTRING_ACCEPT_MIMES
, accept_mimes
, num
, &num
);
319 if(hres
== INET_E_USE_DEFAULT_SETTING
) {
320 static const WCHAR default_accept_mimeW
[] = {'*','/','*',0};
321 static const WCHAR
*default_accept_mimes
[] = {default_accept_mimeW
, NULL
};
323 accept_types
= default_accept_mimes
;
325 }else if(hres
== S_OK
) {
326 accept_types
= (const WCHAR
**)accept_mimes
;
328 WARN("GetBindString BINDSTRING_ACCEPT_MIMES failed: %08x\n", hres
);
329 return INET_E_NO_VALID_MEDIA
;
331 accept_mimes
[num
] = 0;
334 request_flags
|= INTERNET_FLAG_SECURE
;
336 hres
= IUri_GetPathAndQuery(uri
, &path
);
337 if(SUCCEEDED(hres
)) {
338 This
->base
.request
= HttpOpenRequestW(This
->base
.connection
,
339 This
->base
.bind_info
.dwBindVerb
< BINDVERB_CUSTOM
340 ? wszBindVerb
[This
->base
.bind_info
.dwBindVerb
] : This
->base
.bind_info
.szCustomVerb
,
341 path
, NULL
, NULL
, accept_types
, request_flags
, (DWORD_PTR
)&This
->base
);
345 CoTaskMemFree(accept_mimes
[num
]);
348 if (!This
->base
.request
) {
349 WARN("HttpOpenRequest failed: %d\n", GetLastError());
350 return INET_E_RESOURCE_NOT_FOUND
;
353 hres
= IInternetProtocolSink_QueryInterface(This
->base
.protocol_sink
, &IID_IServiceProvider
,
354 (void **)&service_provider
);
356 WARN("IInternetProtocolSink_QueryInterface IID_IServiceProvider failed: %08x\n", hres
);
360 hres
= IServiceProvider_QueryService(service_provider
, &IID_IHttpNegotiate
,
361 &IID_IHttpNegotiate
, (void **)&This
->http_negotiate
);
363 WARN("IServiceProvider_QueryService IID_IHttpNegotiate failed: %08x\n", hres
);
364 IServiceProvider_Release(service_provider
);
368 hres
= IUri_GetAbsoluteUri(uri
, &url
);
370 IServiceProvider_Release(service_provider
);
374 hres
= IHttpNegotiate_BeginningTransaction(This
->http_negotiate
, url
, wszHeaders
,
378 WARN("IHttpNegotiate_BeginningTransaction failed: %08x\n", hres
);
379 IServiceProvider_Release(service_provider
);
384 int len_addl_header
= strlenW(addl_header
);
386 This
->full_header
= heap_alloc(len_addl_header
*sizeof(WCHAR
)+sizeof(wszHeaders
));
388 lstrcpyW(This
->full_header
, addl_header
);
389 lstrcpyW(&This
->full_header
[len_addl_header
], wszHeaders
);
390 CoTaskMemFree(addl_header
);
392 This
->full_header
= (LPWSTR
)wszHeaders
;
395 hres
= IServiceProvider_QueryService(service_provider
, &IID_IHttpNegotiate2
,
396 &IID_IHttpNegotiate2
, (void **)&http_negotiate2
);
397 IServiceProvider_Release(service_provider
);
399 WARN("IServiceProvider_QueryService IID_IHttpNegotiate2 failed: %08x\n", hres
);
400 /* No goto done as per native */
402 len
= sizeof(security_id
)/sizeof(security_id
[0]);
403 hres
= IHttpNegotiate2_GetRootSecurityId(http_negotiate2
, security_id
, &len
, 0);
404 IHttpNegotiate2_Release(http_negotiate2
);
406 WARN("IHttpNegotiate2_GetRootSecurityId failed: %08x\n", hres
);
409 /* FIXME: Handle security_id. Native calls undocumented function IsHostInProxyBypassList. */
411 if(This
->base
.bind_info
.dwBindVerb
== BINDVERB_POST
) {
413 hres
= IInternetBindInfo_GetBindString(bind_info
, BINDSTRING_POST_COOKIE
, &post_cookie
, 1, &num
);
414 if(hres
== S_OK
&& num
) {
415 if(!InternetSetOptionW(This
->base
.request
, INTERNET_OPTION_SECONDARY_CACHE_KEY
,
416 post_cookie
, lstrlenW(post_cookie
)))
417 WARN("InternetSetOption INTERNET_OPTION_SECONDARY_CACHE_KEY failed: %d\n", GetLastError());
418 CoTaskMemFree(post_cookie
);
423 res
= InternetSetOptionW(This
->base
.request
, INTERNET_OPTION_HTTP_DECODING
, &b
, sizeof(b
));
425 WARN("InternetSetOption(INTERNET_OPTION_HTTP_DECODING) failed: %08x\n", GetLastError());
428 error
= send_http_request(This
);
430 if(error
== ERROR_IO_PENDING
|| error
== ERROR_SUCCESS
)
433 hres
= handle_http_error(This
, error
);
435 } while(hres
== RPC_E_RETRY
);
437 WARN("HttpSendRequest failed: %d\n", error
);
441 static HRESULT
HttpProtocol_end_request(Protocol
*protocol
)
445 res
= HttpEndRequestW(protocol
->request
, NULL
, 0, 0);
446 if(!res
&& GetLastError() != ERROR_IO_PENDING
) {
447 FIXME("HttpEndRequest failed: %u\n", GetLastError());
454 static HRESULT
HttpProtocol_start_downloading(Protocol
*prot
)
456 HttpProtocol
*This
= impl_from_Protocol(prot
);
457 LPWSTR content_type
, content_length
, ranges
;
458 DWORD len
= sizeof(DWORD
);
463 static const WCHAR wszDefaultContentType
[] =
464 {'t','e','x','t','/','h','t','m','l',0};
466 if(!This
->http_negotiate
) {
467 WARN("Expected IHttpNegotiate pointer to be non-NULL\n");
471 res
= HttpQueryInfoW(This
->base
.request
, HTTP_QUERY_STATUS_CODE
| HTTP_QUERY_FLAG_NUMBER
,
472 &status_code
, &len
, NULL
);
474 LPWSTR response_headers
= query_http_info(This
, HTTP_QUERY_RAW_HEADERS_CRLF
);
475 if(response_headers
) {
476 hres
= IHttpNegotiate_OnResponse(This
->http_negotiate
, status_code
, response_headers
,
478 heap_free(response_headers
);
480 WARN("IHttpNegotiate_OnResponse failed: %08x\n", hres
);
485 WARN("HttpQueryInfo failed: %d\n", GetLastError());
488 ranges
= query_http_info(This
, HTTP_QUERY_ACCEPT_RANGES
);
490 IInternetProtocolSink_ReportProgress(This
->base
.protocol_sink
, BINDSTATUS_ACCEPTRANGES
, NULL
);
494 content_type
= query_http_info(This
, HTTP_QUERY_CONTENT_TYPE
);
496 /* remove the charset, if present */
497 LPWSTR p
= strchrW(content_type
, ';');
500 IInternetProtocolSink_ReportProgress(This
->base
.protocol_sink
,
501 (This
->base
.bindf
& BINDF_FROMURLMON
)
502 ? BINDSTATUS_MIMETYPEAVAILABLE
: BINDSTATUS_RAWMIMETYPE
,
504 heap_free(content_type
);
506 WARN("HttpQueryInfo failed: %d\n", GetLastError());
507 IInternetProtocolSink_ReportProgress(This
->base
.protocol_sink
,
508 (This
->base
.bindf
& BINDF_FROMURLMON
)
509 ? BINDSTATUS_MIMETYPEAVAILABLE
: BINDSTATUS_RAWMIMETYPE
,
510 wszDefaultContentType
);
513 content_length
= query_http_info(This
, HTTP_QUERY_CONTENT_LENGTH
);
515 This
->base
.content_length
= atoiW(content_length
);
516 heap_free(content_length
);
522 static void HttpProtocol_close_connection(Protocol
*prot
)
524 HttpProtocol
*This
= impl_from_Protocol(prot
);
526 if(This
->http_negotiate
) {
527 IHttpNegotiate_Release(This
->http_negotiate
);
528 This
->http_negotiate
= 0;
531 if(This
->full_header
) {
532 if(This
->full_header
!= wszHeaders
)
533 heap_free(This
->full_header
);
534 This
->full_header
= 0;
538 static void HttpProtocol_on_error(Protocol
*prot
, DWORD error
)
540 HttpProtocol
*This
= impl_from_Protocol(prot
);
543 TRACE("(%p) %d\n", prot
, error
);
545 if(prot
->flags
& FLAG_FIRST_CONTINUE_COMPLETE
) {
546 FIXME("Not handling error %d\n", error
);
550 while((hres
= handle_http_error(This
, error
)) == RPC_E_RETRY
) {
551 error
= send_http_request(This
);
553 if(error
== ERROR_IO_PENDING
|| error
== ERROR_SUCCESS
)
557 protocol_abort(prot
, hres
);
558 protocol_close_connection(prot
);
562 static const ProtocolVtbl AsyncProtocolVtbl
= {
563 HttpProtocol_open_request
,
564 HttpProtocol_end_request
,
565 HttpProtocol_start_downloading
,
566 HttpProtocol_close_connection
,
567 HttpProtocol_on_error
570 static HRESULT WINAPI
HttpProtocol_QueryInterface(IInternetProtocolEx
*iface
, REFIID riid
, void **ppv
)
572 HttpProtocol
*This
= impl_from_IInternetProtocolEx(iface
);
575 if(IsEqualGUID(&IID_IUnknown
, riid
)) {
576 TRACE("(%p)->(IID_IUnknown %p)\n", This
, ppv
);
577 *ppv
= &This
->IInternetProtocolEx_iface
;
578 }else if(IsEqualGUID(&IID_IInternetProtocolRoot
, riid
)) {
579 TRACE("(%p)->(IID_IInternetProtocolRoot %p)\n", This
, ppv
);
580 *ppv
= &This
->IInternetProtocolEx_iface
;
581 }else if(IsEqualGUID(&IID_IInternetProtocol
, riid
)) {
582 TRACE("(%p)->(IID_IInternetProtocol %p)\n", This
, ppv
);
583 *ppv
= &This
->IInternetProtocolEx_iface
;
584 }else if(IsEqualGUID(&IID_IInternetProtocolEx
, riid
)) {
585 TRACE("(%p)->(IID_IInternetProtocolEx %p)\n", This
, ppv
);
586 *ppv
= &This
->IInternetProtocolEx_iface
;
587 }else if(IsEqualGUID(&IID_IInternetPriority
, riid
)) {
588 TRACE("(%p)->(IID_IInternetPriority %p)\n", This
, ppv
);
589 *ppv
= &This
->IInternetPriority_iface
;
590 }else if(IsEqualGUID(&IID_IWinInetInfo
, riid
)) {
591 TRACE("(%p)->(IID_IWinInetInfo %p)\n", This
, ppv
);
592 *ppv
= &This
->IWinInetHttpInfo_iface
;
593 }else if(IsEqualGUID(&IID_IWinInetHttpInfo
, riid
)) {
594 TRACE("(%p)->(IID_IWinInetHttpInfo %p)\n", This
, ppv
);
595 *ppv
= &This
->IWinInetHttpInfo_iface
;
599 IInternetProtocol_AddRef(iface
);
603 WARN("not supported interface %s\n", debugstr_guid(riid
));
604 return E_NOINTERFACE
;
607 static ULONG WINAPI
HttpProtocol_AddRef(IInternetProtocolEx
*iface
)
609 HttpProtocol
*This
= impl_from_IInternetProtocolEx(iface
);
610 LONG ref
= InterlockedIncrement(&This
->ref
);
611 TRACE("(%p) ref=%d\n", This
, ref
);
615 static ULONG WINAPI
HttpProtocol_Release(IInternetProtocolEx
*iface
)
617 HttpProtocol
*This
= impl_from_IInternetProtocolEx(iface
);
618 LONG ref
= InterlockedDecrement(&This
->ref
);
620 TRACE("(%p) ref=%d\n", This
, ref
);
623 protocol_close_connection(&This
->base
);
626 URLMON_UnlockModule();
632 static HRESULT WINAPI
HttpProtocol_Start(IInternetProtocolEx
*iface
, LPCWSTR szUrl
,
633 IInternetProtocolSink
*pOIProtSink
, IInternetBindInfo
*pOIBindInfo
,
634 DWORD grfPI
, HANDLE_PTR dwReserved
)
636 HttpProtocol
*This
= impl_from_IInternetProtocolEx(iface
);
640 TRACE("(%p)->(%s %p %p %08x %lx)\n", This
, debugstr_w(szUrl
), pOIProtSink
,
641 pOIBindInfo
, grfPI
, dwReserved
);
643 hres
= CreateUri(szUrl
, 0, 0, &uri
);
647 hres
= IInternetProtocolEx_StartEx(&This
->IInternetProtocolEx_iface
, uri
, pOIProtSink
,
648 pOIBindInfo
, grfPI
, (HANDLE
*)dwReserved
);
654 static HRESULT WINAPI
HttpProtocol_Continue(IInternetProtocolEx
*iface
, PROTOCOLDATA
*pProtocolData
)
656 HttpProtocol
*This
= impl_from_IInternetProtocolEx(iface
);
658 TRACE("(%p)->(%p)\n", This
, pProtocolData
);
660 return protocol_continue(&This
->base
, pProtocolData
);
663 static HRESULT WINAPI
HttpProtocol_Abort(IInternetProtocolEx
*iface
, HRESULT hrReason
,
666 HttpProtocol
*This
= impl_from_IInternetProtocolEx(iface
);
668 TRACE("(%p)->(%08x %08x)\n", This
, hrReason
, dwOptions
);
670 return protocol_abort(&This
->base
, hrReason
);
673 static HRESULT WINAPI
HttpProtocol_Terminate(IInternetProtocolEx
*iface
, DWORD dwOptions
)
675 HttpProtocol
*This
= impl_from_IInternetProtocolEx(iface
);
677 TRACE("(%p)->(%08x)\n", This
, dwOptions
);
679 protocol_close_connection(&This
->base
);
683 static HRESULT WINAPI
HttpProtocol_Suspend(IInternetProtocolEx
*iface
)
685 HttpProtocol
*This
= impl_from_IInternetProtocolEx(iface
);
686 FIXME("(%p)\n", This
);
690 static HRESULT WINAPI
HttpProtocol_Resume(IInternetProtocolEx
*iface
)
692 HttpProtocol
*This
= impl_from_IInternetProtocolEx(iface
);
693 FIXME("(%p)\n", This
);
697 static HRESULT WINAPI
HttpProtocol_Read(IInternetProtocolEx
*iface
, void *pv
,
698 ULONG cb
, ULONG
*pcbRead
)
700 HttpProtocol
*This
= impl_from_IInternetProtocolEx(iface
);
702 TRACE("(%p)->(%p %u %p)\n", This
, pv
, cb
, pcbRead
);
704 return protocol_read(&This
->base
, pv
, cb
, pcbRead
);
707 static HRESULT WINAPI
HttpProtocol_Seek(IInternetProtocolEx
*iface
, LARGE_INTEGER dlibMove
,
708 DWORD dwOrigin
, ULARGE_INTEGER
*plibNewPosition
)
710 HttpProtocol
*This
= impl_from_IInternetProtocolEx(iface
);
711 FIXME("(%p)->(%d %d %p)\n", This
, dlibMove
.u
.LowPart
, dwOrigin
, plibNewPosition
);
715 static HRESULT WINAPI
HttpProtocol_LockRequest(IInternetProtocolEx
*iface
, DWORD dwOptions
)
717 HttpProtocol
*This
= impl_from_IInternetProtocolEx(iface
);
719 TRACE("(%p)->(%08x)\n", This
, dwOptions
);
721 return protocol_lock_request(&This
->base
);
724 static HRESULT WINAPI
HttpProtocol_UnlockRequest(IInternetProtocolEx
*iface
)
726 HttpProtocol
*This
= impl_from_IInternetProtocolEx(iface
);
728 TRACE("(%p)\n", This
);
730 return protocol_unlock_request(&This
->base
);
733 static HRESULT WINAPI
HttpProtocol_StartEx(IInternetProtocolEx
*iface
, IUri
*pUri
,
734 IInternetProtocolSink
*pOIProtSink
, IInternetBindInfo
*pOIBindInfo
,
735 DWORD grfPI
, HANDLE
*dwReserved
)
737 HttpProtocol
*This
= impl_from_IInternetProtocolEx(iface
);
741 TRACE("(%p)->(%p %p %p %08x %p)\n", This
, pUri
, pOIProtSink
,
742 pOIBindInfo
, grfPI
, dwReserved
);
744 hres
= IUri_GetScheme(pUri
, &scheme
);
747 if(scheme
!= (This
->https
? URL_SCHEME_HTTPS
: URL_SCHEME_HTTP
))
750 return protocol_start(&This
->base
, (IInternetProtocol
*)&This
->IInternetProtocolEx_iface
, pUri
,
751 pOIProtSink
, pOIBindInfo
);
754 static const IInternetProtocolExVtbl HttpProtocolVtbl
= {
755 HttpProtocol_QueryInterface
,
757 HttpProtocol_Release
,
759 HttpProtocol_Continue
,
761 HttpProtocol_Terminate
,
762 HttpProtocol_Suspend
,
766 HttpProtocol_LockRequest
,
767 HttpProtocol_UnlockRequest
,
771 static HRESULT WINAPI
HttpPriority_QueryInterface(IInternetPriority
*iface
, REFIID riid
, void **ppv
)
773 HttpProtocol
*This
= impl_from_IInternetPriority(iface
);
774 return IInternetProtocolEx_QueryInterface(&This
->IInternetProtocolEx_iface
, riid
, ppv
);
777 static ULONG WINAPI
HttpPriority_AddRef(IInternetPriority
*iface
)
779 HttpProtocol
*This
= impl_from_IInternetPriority(iface
);
780 return IInternetProtocolEx_AddRef(&This
->IInternetProtocolEx_iface
);
783 static ULONG WINAPI
HttpPriority_Release(IInternetPriority
*iface
)
785 HttpProtocol
*This
= impl_from_IInternetPriority(iface
);
786 return IInternetProtocolEx_Release(&This
->IInternetProtocolEx_iface
);
789 static HRESULT WINAPI
HttpPriority_SetPriority(IInternetPriority
*iface
, LONG nPriority
)
791 HttpProtocol
*This
= impl_from_IInternetPriority(iface
);
793 TRACE("(%p)->(%d)\n", This
, nPriority
);
795 This
->base
.priority
= nPriority
;
799 static HRESULT WINAPI
HttpPriority_GetPriority(IInternetPriority
*iface
, LONG
*pnPriority
)
801 HttpProtocol
*This
= impl_from_IInternetPriority(iface
);
803 TRACE("(%p)->(%p)\n", This
, pnPriority
);
805 *pnPriority
= This
->base
.priority
;
809 static const IInternetPriorityVtbl HttpPriorityVtbl
= {
810 HttpPriority_QueryInterface
,
812 HttpPriority_Release
,
813 HttpPriority_SetPriority
,
814 HttpPriority_GetPriority
817 static HRESULT WINAPI
HttpInfo_QueryInterface(IWinInetHttpInfo
*iface
, REFIID riid
, void **ppv
)
819 HttpProtocol
*This
= impl_from_IWinInetHttpInfo(iface
);
820 return IInternetProtocolEx_QueryInterface(&This
->IInternetProtocolEx_iface
, riid
, ppv
);
823 static ULONG WINAPI
HttpInfo_AddRef(IWinInetHttpInfo
*iface
)
825 HttpProtocol
*This
= impl_from_IWinInetHttpInfo(iface
);
826 return IInternetProtocolEx_AddRef(&This
->IInternetProtocolEx_iface
);
829 static ULONG WINAPI
HttpInfo_Release(IWinInetHttpInfo
*iface
)
831 HttpProtocol
*This
= impl_from_IWinInetHttpInfo(iface
);
832 return IInternetProtocolEx_Release(&This
->IInternetProtocolEx_iface
);
835 static HRESULT WINAPI
HttpInfo_QueryOption(IWinInetHttpInfo
*iface
, DWORD dwOption
,
836 void *pBuffer
, DWORD
*pcbBuffer
)
838 HttpProtocol
*This
= impl_from_IWinInetHttpInfo(iface
);
839 TRACE("(%p)->(%x %p %p)\n", This
, dwOption
, pBuffer
, pcbBuffer
);
841 if(!This
->base
.request
)
844 if(!InternetQueryOptionW(This
->base
.request
, dwOption
, pBuffer
, pcbBuffer
))
849 static HRESULT WINAPI
HttpInfo_QueryInfo(IWinInetHttpInfo
*iface
, DWORD dwOption
,
850 void *pBuffer
, DWORD
*pcbBuffer
, DWORD
*pdwFlags
, DWORD
*pdwReserved
)
852 HttpProtocol
*This
= impl_from_IWinInetHttpInfo(iface
);
853 TRACE("(%p)->(%x %p %p %p %p)\n", This
, dwOption
, pBuffer
, pcbBuffer
, pdwFlags
, pdwReserved
);
855 if(!This
->base
.request
)
858 if(!HttpQueryInfoW(This
->base
.request
, dwOption
, pBuffer
, pcbBuffer
, pdwFlags
)) {
860 memset(pBuffer
, 0, *pcbBuffer
);
866 static const IWinInetHttpInfoVtbl WinInetHttpInfoVtbl
= {
867 HttpInfo_QueryInterface
,
870 HttpInfo_QueryOption
,
874 static HRESULT
create_http_protocol(BOOL https
, void **ppobj
)
878 ret
= heap_alloc_zero(sizeof(HttpProtocol
));
880 return E_OUTOFMEMORY
;
882 ret
->base
.vtbl
= &AsyncProtocolVtbl
;
883 ret
->IInternetProtocolEx_iface
.lpVtbl
= &HttpProtocolVtbl
;
884 ret
->IInternetPriority_iface
.lpVtbl
= &HttpPriorityVtbl
;
885 ret
->IWinInetHttpInfo_iface
.lpVtbl
= &WinInetHttpInfoVtbl
;
890 *ppobj
= &ret
->IInternetProtocolEx_iface
;
896 HRESULT
HttpProtocol_Construct(IUnknown
*pUnkOuter
, LPVOID
*ppobj
)
898 TRACE("(%p %p)\n", pUnkOuter
, ppobj
);
900 return create_http_protocol(FALSE
, ppobj
);
903 HRESULT
HttpSProtocol_Construct(IUnknown
*pUnkOuter
, LPVOID
*ppobj
)
905 TRACE("(%p %p)\n", pUnkOuter
, ppobj
);
907 return create_http_protocol(TRUE
, ppobj
);