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);
220 if(FAILED(hres)) hwnd = NULL;
222 dlg_flags = FLAGS_ERROR_UI_FLAGS_CHANGE_OPTIONS | FLAGS_ERROR_UI_FLAGS_GENERATE_DATA;
223 if(This->base.bindf & BINDF_NO_UI)
224 dlg_flags |= FLAGS_ERROR_UI_FLAGS_NO_UI;
226 res = InternetErrorDlg(hwnd, This->base.request, error, dlg_flags, NULL);
227 hres = res == ERROR_INTERNET_FORCE_RETRY || res == ERROR_SUCCESS ? RPC_E_RETRY : internet_error_to_hres(error);
230 IServiceProvider_Release(serv_prov);
234 static ULONG send_http_request(HttpProtocol *This)
236 INTERNET_BUFFERSW send_buffer = {sizeof(INTERNET_BUFFERSW)};
239 send_buffer.lpcszHeader = This->full_header;
240 send_buffer.dwHeadersLength = send_buffer.dwHeadersTotal = strlenW(This->full_header);
242 if(This->base.bind_info.dwBindVerb != BINDVERB_GET) {
243 switch(This->base.bind_info.stgmedData.tymed) {
245 /* Native does not use GlobalLock/GlobalUnlock, so we won't either */
246 send_buffer.lpvBuffer = This->base.bind_info.stgmedData.u.hGlobal;
247 send_buffer.dwBufferLength = send_buffer.dwBufferTotal = This->base.bind_info.cbstgmedData;
249 case TYMED_ISTREAM: {
250 LARGE_INTEGER offset;
252 send_buffer.dwBufferTotal = This->base.bind_info.cbstgmedData;
253 if(!This->base.post_stream) {
254 This->base.post_stream = This->base.bind_info.stgmedData.u.pstm;
255 IStream_AddRef(This->base.post_stream);
259 IStream_Seek(This->base.post_stream, offset, STREAM_SEEK_SET, NULL);
263 FIXME("Unsupported This->base.bind_info.stgmedData.tymed %d\n", This->base.bind_info.stgmedData.tymed);
267 if(This->base.post_stream)
268 res = HttpSendRequestExW(This->base.request, &send_buffer, NULL, 0, 0);
270 res = HttpSendRequestW(This->base.request, send_buffer.lpcszHeader, send_buffer.dwHeadersLength,
271 send_buffer.lpvBuffer, send_buffer.dwBufferLength);
273 return res ? 0 : GetLastError();
276 static inline HttpProtocol *impl_from_Protocol(Protocol *prot)
278 return CONTAINING_RECORD(prot, HttpProtocol, base);
281 static HRESULT HttpProtocol_open_request(Protocol *prot, IUri *uri, DWORD request_flags,
282 HINTERNET internet_session, IInternetBindInfo *bind_info)
284 HttpProtocol *This = impl_from_Protocol(prot);
285 LPWSTR addl_header = NULL, post_cookie = NULL;
286 IServiceProvider *service_provider = NULL;
287 IHttpNegotiate2 *http_negotiate2 = NULL;
288 BSTR url, host, user, pass, path;
289 LPOLESTR accept_mimes[257];
290 const WCHAR **accept_types;
291 BYTE security_id[512];
292 DWORD len, port, flags;
297 static const WCHAR wszBindVerb[BINDVERB_CUSTOM][5] =
302 hres = IUri_GetPort(uri, &port);
306 hres = IUri_GetHost(uri, &host);
310 hres = IUri_GetUserName(uri, &user);
311 if(SUCCEEDED(hres)) {
312 hres = IUri_GetPassword(uri, &pass);
314 if(SUCCEEDED(hres)) {
315 This->base.connection = InternetConnectW(internet_session, host, port, user, pass,
316 INTERNET_SERVICE_HTTP, This->https ? INTERNET_FLAG_SECURE : 0, (DWORD_PTR)&This->base);
324 if(!This->base.connection) {
325 WARN("InternetConnect failed: %d\n", GetLastError());
326 return INET_E_CANNOT_CONNECT;
329 num = sizeof(accept_mimes)/sizeof(accept_mimes[0])-1;
330 hres = IInternetBindInfo_GetBindString(bind_info, BINDSTRING_ACCEPT_MIMES, accept_mimes, num, &num);
331 if(hres == INET_E_USE_DEFAULT_SETTING) {
332 static const WCHAR default_accept_mimeW[] = {'*','/','*',0};
333 static const WCHAR *default_accept_mimes[] = {default_accept_mimeW, NULL};
335 accept_types = default_accept_mimes;
337 }else if(hres == S_OK) {
338 accept_types = (const WCHAR**)accept_mimes;
340 WARN("GetBindString BINDSTRING_ACCEPT_MIMES failed: %08x\n", hres);
341 return INET_E_NO_VALID_MEDIA;
343 accept_mimes[num] = 0;
346 request_flags |= INTERNET_FLAG_SECURE;
348 hres = IUri_GetPathAndQuery(uri, &path);
349 if(SUCCEEDED(hres)) {
350 This->base.request = HttpOpenRequestW(This->base.connection,
351 This->base.bind_info.dwBindVerb < BINDVERB_CUSTOM
352 ? wszBindVerb[This->base.bind_info.dwBindVerb] : This->base.bind_info.szCustomVerb,
353 path, NULL, NULL, accept_types, request_flags, (DWORD_PTR)&This->base);
357 CoTaskMemFree(accept_mimes[num]);
360 if (!This->base.request) {
361 WARN("HttpOpenRequest failed: %d\n", GetLastError());
362 return INET_E_RESOURCE_NOT_FOUND;
365 hres = IInternetProtocolSink_QueryInterface(This->base.protocol_sink, &IID_IServiceProvider,
366 (void **)&service_provider);
368 WARN("IInternetProtocolSink_QueryInterface IID_IServiceProvider failed: %08x\n", hres);
372 hres = IServiceProvider_QueryService(service_provider, &IID_IHttpNegotiate,
373 &IID_IHttpNegotiate, (void **)&This->http_negotiate);
375 WARN("IServiceProvider_QueryService IID_IHttpNegotiate failed: %08x\n", hres);
376 IServiceProvider_Release(service_provider);
380 hres = IUri_GetAbsoluteUri(uri, &url);
382 IServiceProvider_Release(service_provider);
386 hres = IHttpNegotiate_BeginningTransaction(This->http_negotiate, url, default_headersW,
390 WARN("IHttpNegotiate_BeginningTransaction failed: %08x\n", hres);
391 IServiceProvider_Release(service_provider);
395 len = addl_header ? strlenW(addl_header) : 0;
397 This->full_header = heap_alloc(len*sizeof(WCHAR)+sizeof(default_headersW));
398 if(!This->full_header) {
399 IServiceProvider_Release(service_provider);
400 return E_OUTOFMEMORY;
404 memcpy(This->full_header, addl_header, len*sizeof(WCHAR));
405 CoTaskMemFree(addl_header);
406 memcpy(This->full_header+len, default_headersW, sizeof(default_headersW));
408 hres = IServiceProvider_QueryService(service_provider, &IID_IHttpNegotiate2,
409 &IID_IHttpNegotiate2, (void **)&http_negotiate2);
410 IServiceProvider_Release(service_provider);
412 WARN("IServiceProvider_QueryService IID_IHttpNegotiate2 failed: %08x\n", hres);
413 /* No goto done as per native */
415 len = sizeof(security_id)/sizeof(security_id[0]);
416 hres = IHttpNegotiate2_GetRootSecurityId(http_negotiate2, security_id, &len, 0);
417 IHttpNegotiate2_Release(http_negotiate2);
419 WARN("IHttpNegotiate2_GetRootSecurityId failed: %08x\n", hres);
422 /* FIXME: Handle security_id. Native calls undocumented function IsHostInProxyBypassList. */
424 if(This->base.bind_info.dwBindVerb == BINDVERB_POST) {
426 hres = IInternetBindInfo_GetBindString(bind_info, BINDSTRING_POST_COOKIE, &post_cookie, 1, &num);
427 if(hres == S_OK && num) {
428 if(!InternetSetOptionW(This->base.request, INTERNET_OPTION_SECONDARY_CACHE_KEY,
429 post_cookie, lstrlenW(post_cookie)))
430 WARN("InternetSetOption INTERNET_OPTION_SECONDARY_CACHE_KEY failed: %d\n", GetLastError());
431 CoTaskMemFree(post_cookie);
435 flags = INTERNET_ERROR_MASK_COMBINED_SEC_CERT;
436 res = InternetSetOptionW(This->base.request, INTERNET_OPTION_ERROR_MASK, &flags, sizeof(flags));
438 WARN("InternetSetOption(INTERNET_OPTION_ERROR_MASK) failed: %u\n", GetLastError());
441 res = InternetSetOptionW(This->base.request, INTERNET_OPTION_HTTP_DECODING, &b, sizeof(b));
443 WARN("InternetSetOption(INTERNET_OPTION_HTTP_DECODING) failed: %u\n", GetLastError());
446 error = send_http_request(This);
448 if(error == ERROR_IO_PENDING || error == ERROR_SUCCESS)
451 hres = handle_http_error(This, error);
453 } while(hres == RPC_E_RETRY);
455 WARN("HttpSendRequest failed: %d\n", error);
459 static HRESULT HttpProtocol_end_request(Protocol *protocol)
463 res = HttpEndRequestW(protocol->request, NULL, 0, 0);
464 if(!res && GetLastError() != ERROR_IO_PENDING) {
465 FIXME("HttpEndRequest failed: %u\n", GetLastError());
472 static HRESULT HttpProtocol_start_downloading(Protocol *prot)
474 HttpProtocol *This = impl_from_Protocol(prot);
475 LPWSTR content_type, content_length, ranges;
476 DWORD len = sizeof(DWORD);
481 static const WCHAR wszDefaultContentType[] =
482 {'t','e','x','t','/','h','t','m','l',0};
484 if(!This->http_negotiate) {
485 WARN("Expected IHttpNegotiate pointer to be non-NULL\n");
489 res = HttpQueryInfoW(This->base.request, HTTP_QUERY_STATUS_CODE | HTTP_QUERY_FLAG_NUMBER,
490 &status_code, &len, NULL);
492 LPWSTR response_headers = query_http_info(This, HTTP_QUERY_RAW_HEADERS_CRLF);
493 if(response_headers) {
494 hres = IHttpNegotiate_OnResponse(This->http_negotiate, status_code, response_headers,
496 heap_free(response_headers);
498 WARN("IHttpNegotiate_OnResponse failed: %08x\n", hres);
503 WARN("HttpQueryInfo failed: %d\n", GetLastError());
506 ranges = query_http_info(This, HTTP_QUERY_ACCEPT_RANGES);
508 IInternetProtocolSink_ReportProgress(This->base.protocol_sink, BINDSTATUS_ACCEPTRANGES, NULL);
512 content_type = query_http_info(This, HTTP_QUERY_CONTENT_TYPE);
514 /* remove the charset, if present */
515 LPWSTR p = strchrW(content_type, ';');
518 IInternetProtocolSink_ReportProgress(This->base.protocol_sink,
519 (This->base.bindf & BINDF_FROMURLMON)
520 ? BINDSTATUS_MIMETYPEAVAILABLE : BINDSTATUS_RAWMIMETYPE,
522 heap_free(content_type);
524 WARN("HttpQueryInfo failed: %d\n", GetLastError());
525 IInternetProtocolSink_ReportProgress(This->base.protocol_sink,
526 (This->base.bindf & BINDF_FROMURLMON)
527 ? BINDSTATUS_MIMETYPEAVAILABLE : BINDSTATUS_RAWMIMETYPE,
528 wszDefaultContentType);
531 content_length = query_http_info(This, HTTP_QUERY_CONTENT_LENGTH);
533 This->base.content_length = atoiW(content_length);
534 heap_free(content_length);
540 static void HttpProtocol_close_connection(Protocol *prot)
542 HttpProtocol *This = impl_from_Protocol(prot);
544 if(This->http_negotiate) {
545 IHttpNegotiate_Release(This->http_negotiate);
546 This->http_negotiate = NULL;
549 heap_free(This->full_header);
550 This->full_header = NULL;
553 static void HttpProtocol_on_error(Protocol *prot, DWORD error)
555 HttpProtocol *This = impl_from_Protocol(prot);
558 TRACE("(%p) %d\n", prot, error);
560 if(prot->flags & FLAG_FIRST_CONTINUE_COMPLETE) {
561 FIXME("Not handling error %d\n", error);
565 while((hres = handle_http_error(This, error)) == RPC_E_RETRY) {
566 error = send_http_request(This);
568 if(error == ERROR_IO_PENDING || error == ERROR_SUCCESS)
572 protocol_abort(prot, hres);
573 protocol_close_connection(prot);
577 static const ProtocolVtbl AsyncProtocolVtbl = {
578 HttpProtocol_open_request,
579 HttpProtocol_end_request,
580 HttpProtocol_start_downloading,
581 HttpProtocol_close_connection,
582 HttpProtocol_on_error
585 static HRESULT WINAPI HttpProtocol_QueryInterface(IInternetProtocolEx *iface, REFIID riid, void **ppv)
587 HttpProtocol *This = impl_from_IInternetProtocolEx(iface);
590 if(IsEqualGUID(&IID_IUnknown, riid)) {
591 TRACE("(%p)->(IID_IUnknown %p)\n", This, ppv);
592 *ppv = &This->IInternetProtocolEx_iface;
593 }else if(IsEqualGUID(&IID_IInternetProtocolRoot, riid)) {
594 TRACE("(%p)->(IID_IInternetProtocolRoot %p)\n", This, ppv);
595 *ppv = &This->IInternetProtocolEx_iface;
596 }else if(IsEqualGUID(&IID_IInternetProtocol, riid)) {
597 TRACE("(%p)->(IID_IInternetProtocol %p)\n", This, ppv);
598 *ppv = &This->IInternetProtocolEx_iface;
599 }else if(IsEqualGUID(&IID_IInternetProtocolEx, riid)) {
600 TRACE("(%p)->(IID_IInternetProtocolEx %p)\n", This, ppv);
601 *ppv = &This->IInternetProtocolEx_iface;
602 }else if(IsEqualGUID(&IID_IInternetPriority, riid)) {
603 TRACE("(%p)->(IID_IInternetPriority %p)\n", This, ppv);
604 *ppv = &This->IInternetPriority_iface;
605 }else if(IsEqualGUID(&IID_IWinInetInfo, riid)) {
606 TRACE("(%p)->(IID_IWinInetInfo %p)\n", This, ppv);
607 *ppv = &This->IWinInetHttpInfo_iface;
608 }else if(IsEqualGUID(&IID_IWinInetHttpInfo, riid)) {
609 TRACE("(%p)->(IID_IWinInetHttpInfo %p)\n", This, ppv);
610 *ppv = &This->IWinInetHttpInfo_iface;
614 IInternetProtocolEx_AddRef(iface);
618 WARN("not supported interface %s\n", debugstr_guid(riid));
619 return E_NOINTERFACE;
622 static ULONG WINAPI HttpProtocol_AddRef(IInternetProtocolEx *iface)
624 HttpProtocol *This = impl_from_IInternetProtocolEx(iface);
625 LONG ref = InterlockedIncrement(&This->ref);
626 TRACE("(%p) ref=%d\n", This, ref);
630 static ULONG WINAPI HttpProtocol_Release(IInternetProtocolEx *iface)
632 HttpProtocol *This = impl_from_IInternetProtocolEx(iface);
633 LONG ref = InterlockedDecrement(&This->ref);
635 TRACE("(%p) ref=%d\n", This, ref);
638 protocol_close_connection(&This->base);
641 URLMON_UnlockModule();
647 static HRESULT WINAPI HttpProtocol_Start(IInternetProtocolEx *iface, LPCWSTR szUrl,
648 IInternetProtocolSink *pOIProtSink, IInternetBindInfo *pOIBindInfo,
649 DWORD grfPI, HANDLE_PTR dwReserved)
651 HttpProtocol *This = impl_from_IInternetProtocolEx(iface);
655 TRACE("(%p)->(%s %p %p %08x %lx)\n", This, debugstr_w(szUrl), pOIProtSink,
656 pOIBindInfo, grfPI, dwReserved);
658 hres = CreateUri(szUrl, 0, 0, &uri);
662 hres = IInternetProtocolEx_StartEx(&This->IInternetProtocolEx_iface, uri, pOIProtSink,
663 pOIBindInfo, grfPI, (HANDLE*)dwReserved);
669 static HRESULT WINAPI HttpProtocol_Continue(IInternetProtocolEx *iface, PROTOCOLDATA *pProtocolData)
671 HttpProtocol *This = impl_from_IInternetProtocolEx(iface);
673 TRACE("(%p)->(%p)\n", This, pProtocolData);
675 return protocol_continue(&This->base, pProtocolData);
678 static HRESULT WINAPI HttpProtocol_Abort(IInternetProtocolEx *iface, HRESULT hrReason,
681 HttpProtocol *This = impl_from_IInternetProtocolEx(iface);
683 TRACE("(%p)->(%08x %08x)\n", This, hrReason, dwOptions);
685 return protocol_abort(&This->base, hrReason);
688 static HRESULT WINAPI HttpProtocol_Terminate(IInternetProtocolEx *iface, DWORD dwOptions)
690 HttpProtocol *This = impl_from_IInternetProtocolEx(iface);
692 TRACE("(%p)->(%08x)\n", This, dwOptions);
694 protocol_close_connection(&This->base);
698 static HRESULT WINAPI HttpProtocol_Suspend(IInternetProtocolEx *iface)
700 HttpProtocol *This = impl_from_IInternetProtocolEx(iface);
701 FIXME("(%p)\n", This);
705 static HRESULT WINAPI HttpProtocol_Resume(IInternetProtocolEx *iface)
707 HttpProtocol *This = impl_from_IInternetProtocolEx(iface);
708 FIXME("(%p)\n", This);
712 static HRESULT WINAPI HttpProtocol_Read(IInternetProtocolEx *iface, void *pv,
713 ULONG cb, ULONG *pcbRead)
715 HttpProtocol *This = impl_from_IInternetProtocolEx(iface);
717 TRACE("(%p)->(%p %u %p)\n", This, pv, cb, pcbRead);
719 return protocol_read(&This->base, pv, cb, pcbRead);
722 static HRESULT WINAPI HttpProtocol_Seek(IInternetProtocolEx *iface, LARGE_INTEGER dlibMove,
723 DWORD dwOrigin, ULARGE_INTEGER *plibNewPosition)
725 HttpProtocol *This = impl_from_IInternetProtocolEx(iface);
726 FIXME("(%p)->(%d %d %p)\n", This, dlibMove.u.LowPart, dwOrigin, plibNewPosition);
730 static HRESULT WINAPI HttpProtocol_LockRequest(IInternetProtocolEx *iface, DWORD dwOptions)
732 HttpProtocol *This = impl_from_IInternetProtocolEx(iface);
734 TRACE("(%p)->(%08x)\n", This, dwOptions);
736 return protocol_lock_request(&This->base);
739 static HRESULT WINAPI HttpProtocol_UnlockRequest(IInternetProtocolEx *iface)
741 HttpProtocol *This = impl_from_IInternetProtocolEx(iface);
743 TRACE("(%p)\n", This);
745 return protocol_unlock_request(&This->base);
748 static HRESULT WINAPI HttpProtocol_StartEx(IInternetProtocolEx *iface, IUri *pUri,
749 IInternetProtocolSink *pOIProtSink, IInternetBindInfo *pOIBindInfo,
750 DWORD grfPI, HANDLE *dwReserved)
752 HttpProtocol *This = impl_from_IInternetProtocolEx(iface);
756 TRACE("(%p)->(%p %p %p %08x %p)\n", This, pUri, pOIProtSink,
757 pOIBindInfo, grfPI, dwReserved);
759 hres = IUri_GetScheme(pUri, &scheme);
762 if(scheme != (This->https ? URL_SCHEME_HTTPS : URL_SCHEME_HTTP))
765 return protocol_start(&This->base, (IInternetProtocol*)&This->IInternetProtocolEx_iface, pUri,
766 pOIProtSink, pOIBindInfo);
769 static const IInternetProtocolExVtbl HttpProtocolVtbl = {
770 HttpProtocol_QueryInterface,
772 HttpProtocol_Release,
774 HttpProtocol_Continue,
776 HttpProtocol_Terminate,
777 HttpProtocol_Suspend,
781 HttpProtocol_LockRequest,
782 HttpProtocol_UnlockRequest,
786 static HRESULT WINAPI HttpPriority_QueryInterface(IInternetPriority *iface, REFIID riid, void **ppv)
788 HttpProtocol *This = impl_from_IInternetPriority(iface);
789 return IInternetProtocolEx_QueryInterface(&This->IInternetProtocolEx_iface, riid, ppv);
792 static ULONG WINAPI HttpPriority_AddRef(IInternetPriority *iface)
794 HttpProtocol *This = impl_from_IInternetPriority(iface);
795 return IInternetProtocolEx_AddRef(&This->IInternetProtocolEx_iface);
798 static ULONG WINAPI HttpPriority_Release(IInternetPriority *iface)
800 HttpProtocol *This = impl_from_IInternetPriority(iface);
801 return IInternetProtocolEx_Release(&This->IInternetProtocolEx_iface);
804 static HRESULT WINAPI HttpPriority_SetPriority(IInternetPriority *iface, LONG nPriority)
806 HttpProtocol *This = impl_from_IInternetPriority(iface);
808 TRACE("(%p)->(%d)\n", This, nPriority);
810 This->base.priority = nPriority;
814 static HRESULT WINAPI HttpPriority_GetPriority(IInternetPriority *iface, LONG *pnPriority)
816 HttpProtocol *This = impl_from_IInternetPriority(iface);
818 TRACE("(%p)->(%p)\n", This, pnPriority);
820 *pnPriority = This->base.priority;
824 static const IInternetPriorityVtbl HttpPriorityVtbl = {
825 HttpPriority_QueryInterface,
827 HttpPriority_Release,
828 HttpPriority_SetPriority,
829 HttpPriority_GetPriority
832 static HRESULT WINAPI HttpInfo_QueryInterface(IWinInetHttpInfo *iface, REFIID riid, void **ppv)
834 HttpProtocol *This = impl_from_IWinInetHttpInfo(iface);
835 return IInternetProtocolEx_QueryInterface(&This->IInternetProtocolEx_iface, riid, ppv);
838 static ULONG WINAPI HttpInfo_AddRef(IWinInetHttpInfo *iface)
840 HttpProtocol *This = impl_from_IWinInetHttpInfo(iface);
841 return IInternetProtocolEx_AddRef(&This->IInternetProtocolEx_iface);
844 static ULONG WINAPI HttpInfo_Release(IWinInetHttpInfo *iface)
846 HttpProtocol *This = impl_from_IWinInetHttpInfo(iface);
847 return IInternetProtocolEx_Release(&This->IInternetProtocolEx_iface);
850 static HRESULT WINAPI HttpInfo_QueryOption(IWinInetHttpInfo *iface, DWORD dwOption,
851 void *pBuffer, DWORD *pcbBuffer)
853 HttpProtocol *This = impl_from_IWinInetHttpInfo(iface);
854 TRACE("(%p)->(%x %p %p)\n", This, dwOption, pBuffer, pcbBuffer);
856 if(!This->base.request)
859 if(!InternetQueryOptionW(This->base.request, dwOption, pBuffer, pcbBuffer))
864 static HRESULT WINAPI HttpInfo_QueryInfo(IWinInetHttpInfo *iface, DWORD dwOption,
865 void *pBuffer, DWORD *pcbBuffer, DWORD *pdwFlags, DWORD *pdwReserved)
867 HttpProtocol *This = impl_from_IWinInetHttpInfo(iface);
868 TRACE("(%p)->(%x %p %p %p %p)\n", This, dwOption, pBuffer, pcbBuffer, pdwFlags, pdwReserved);
870 if(!This->base.request)
873 if(!HttpQueryInfoW(This->base.request, dwOption, pBuffer, pcbBuffer, pdwFlags)) {
875 memset(pBuffer, 0, *pcbBuffer);
881 static const IWinInetHttpInfoVtbl WinInetHttpInfoVtbl = {
882 HttpInfo_QueryInterface,
885 HttpInfo_QueryOption,
889 static HRESULT create_http_protocol(BOOL https, void **ppobj)
893 ret = heap_alloc_zero(sizeof(HttpProtocol));
895 return E_OUTOFMEMORY;
897 ret->base.vtbl = &AsyncProtocolVtbl;
898 ret->IInternetProtocolEx_iface.lpVtbl = &HttpProtocolVtbl;
899 ret->IInternetPriority_iface.lpVtbl = &HttpPriorityVtbl;
900 ret->IWinInetHttpInfo_iface.lpVtbl = &WinInetHttpInfoVtbl;
905 *ppobj = &ret->IInternetProtocolEx_iface;
911 HRESULT HttpProtocol_Construct(IUnknown *pUnkOuter, LPVOID *ppobj)
913 TRACE("(%p %p)\n", pUnkOuter, ppobj);
915 return create_http_protocol(FALSE, ppobj);
918 HRESULT HttpSProtocol_Construct(IUnknown *pUnkOuter, LPVOID *ppobj)
920 TRACE("(%p %p)\n", pUnkOuter, ppobj);
922 return create_http_protocol(TRUE, ppobj);