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 new_flag)
84 DWORD flags, size = sizeof(flags);
87 res = InternetQueryOptionW(This->base.request, INTERNET_OPTION_SECURITY_FLAGS, &flags, &size);
90 res = InternetSetOptionW(This->base.request, INTERNET_OPTION_SECURITY_FLAGS, &flags, size);
93 ERR("Failed to set security flag(s): %x\n", new_flag);
98 static inline HRESULT internet_error_to_hres(DWORD error)
102 case ERROR_INTERNET_SEC_CERT_DATE_INVALID:
103 case ERROR_INTERNET_SEC_CERT_CN_INVALID:
104 case ERROR_INTERNET_INVALID_CA:
105 case ERROR_INTERNET_CLIENT_AUTH_CERT_NEEDED:
106 case ERROR_INTERNET_SEC_INVALID_CERT:
107 case ERROR_INTERNET_SEC_CERT_ERRORS:
108 case ERROR_INTERNET_SEC_CERT_REV_FAILED:
109 case ERROR_INTERNET_SEC_CERT_NO_REV:
110 case ERROR_INTERNET_SEC_CERT_REVOKED:
111 return INET_E_INVALID_CERTIFICATE;
112 case ERROR_INTERNET_HTTP_TO_HTTPS_ON_REDIR:
113 case ERROR_INTERNET_HTTPS_TO_HTTP_ON_REDIR:
114 case ERROR_HTTP_REDIRECT_NEEDS_CONFIRMATION:
115 return INET_E_REDIRECT_FAILED;
117 return INET_E_DOWNLOAD_FAILURE;
121 static HRESULT handle_http_error(HttpProtocol *This, DWORD error)
123 IServiceProvider *serv_prov;
124 IWindowForBindingUI *wfb_ui;
125 IHttpSecurity *http_security;
126 BOOL security_problem;
133 case ERROR_INTERNET_SEC_CERT_DATE_INVALID:
134 case ERROR_INTERNET_SEC_CERT_CN_INVALID:
135 case ERROR_INTERNET_HTTP_TO_HTTPS_ON_REDIR:
136 case ERROR_INTERNET_HTTPS_TO_HTTP_ON_REDIR:
137 case ERROR_INTERNET_INVALID_CA:
138 case ERROR_INTERNET_CLIENT_AUTH_CERT_NEEDED:
139 case ERROR_INTERNET_SEC_INVALID_CERT:
140 case ERROR_INTERNET_SEC_CERT_ERRORS:
141 case ERROR_INTERNET_SEC_CERT_REV_FAILED:
142 case ERROR_INTERNET_SEC_CERT_NO_REV:
143 case ERROR_INTERNET_SEC_CERT_REVOKED:
144 case ERROR_HTTP_REDIRECT_NEEDS_CONFIRMATION:
145 security_problem = TRUE;
148 security_problem = FALSE;
151 hres = IInternetProtocolSink_QueryInterface(This->base.protocol_sink, &IID_IServiceProvider,
154 ERR("Failed to get IServiceProvider.\n");
158 if(security_problem) {
159 hres = IServiceProvider_QueryService(serv_prov, &IID_IHttpSecurity, &IID_IHttpSecurity,
160 (void**)&http_security);
161 if(SUCCEEDED(hres)) {
162 hres = IHttpSecurity_OnSecurityProblem(http_security, error);
163 IHttpSecurity_Release(http_security);
169 IServiceProvider_Release(serv_prov);
172 if(error == ERROR_INTERNET_SEC_CERT_DATE_INVALID)
173 res = set_security_flag(This, SECURITY_FLAG_IGNORE_CERT_DATE_INVALID);
174 else if(error == ERROR_INTERNET_SEC_CERT_CN_INVALID)
175 res = set_security_flag(This, SECURITY_FLAG_IGNORE_CERT_CN_INVALID);
176 else if(error == ERROR_INTERNET_INVALID_CA)
177 res = set_security_flag(This, SECURITY_FLAG_IGNORE_UNKNOWN_CA);
182 FIXME("Don't know how to ignore error %d\n", error);
188 if(hres == RPC_E_RETRY)
191 return internet_error_to_hres(error);
196 hres = IServiceProvider_QueryService(serv_prov, &IID_IWindowForBindingUI, &IID_IWindowForBindingUI,
198 if(SUCCEEDED(hres)) {
199 const IID *iid_reason;
202 iid_reason = &IID_IHttpSecurity;
203 else if(error == ERROR_INTERNET_INCORRECT_PASSWORD)
204 iid_reason = &IID_IAuthenticate;
206 iid_reason = &IID_IWindowForBindingUI;
208 hres = IWindowForBindingUI_GetWindow(wfb_ui, iid_reason, &hwnd);
209 IWindowForBindingUI_Release(wfb_ui);
214 IServiceProvider_Release(serv_prov);
216 dlg_flags = FLAGS_ERROR_UI_FLAGS_CHANGE_OPTIONS | FLAGS_ERROR_UI_FLAGS_GENERATE_DATA;
217 if(This->base.bindf & BINDF_NO_UI)
218 dlg_flags |= FLAGS_ERROR_UI_FLAGS_NO_UI;
220 res = InternetErrorDlg(hwnd, This->base.request, error, dlg_flags, NULL);
221 if(res == ERROR_INTERNET_FORCE_RETRY || res == ERROR_SUCCESS)
224 return internet_error_to_hres(error);
227 static ULONG send_http_request(HttpProtocol *This)
229 INTERNET_BUFFERSW send_buffer = {sizeof(INTERNET_BUFFERSW)};
232 send_buffer.lpcszHeader = This->full_header;
233 send_buffer.dwHeadersLength = send_buffer.dwHeadersTotal = strlenW(This->full_header);
235 if(This->base.bind_info.dwBindVerb != BINDVERB_GET) {
236 switch(This->base.bind_info.stgmedData.tymed) {
238 /* Native does not use GlobalLock/GlobalUnlock, so we won't either */
239 send_buffer.lpvBuffer = This->base.bind_info.stgmedData.u.hGlobal;
240 send_buffer.dwBufferLength = send_buffer.dwBufferTotal = This->base.bind_info.cbstgmedData;
242 case TYMED_ISTREAM: {
243 LARGE_INTEGER offset;
245 send_buffer.dwBufferTotal = This->base.bind_info.cbstgmedData;
246 if(!This->base.post_stream) {
247 This->base.post_stream = This->base.bind_info.stgmedData.u.pstm;
248 IStream_AddRef(This->base.post_stream);
252 IStream_Seek(This->base.post_stream, offset, STREAM_SEEK_SET, NULL);
256 FIXME("Unsupported This->base.bind_info.stgmedData.tymed %d\n", This->base.bind_info.stgmedData.tymed);
260 if(This->base.post_stream)
261 res = HttpSendRequestExW(This->base.request, &send_buffer, NULL, 0, 0);
263 res = HttpSendRequestW(This->base.request, send_buffer.lpcszHeader, send_buffer.dwHeadersLength,
264 send_buffer.lpvBuffer, send_buffer.dwBufferLength);
266 return res ? 0 : GetLastError();
269 static inline HttpProtocol *impl_from_Protocol(Protocol *prot)
271 return CONTAINING_RECORD(prot, HttpProtocol, base);
274 static HRESULT HttpProtocol_open_request(Protocol *prot, IUri *uri, DWORD request_flags,
275 HINTERNET internet_session, IInternetBindInfo *bind_info)
277 HttpProtocol *This = impl_from_Protocol(prot);
278 LPWSTR addl_header = NULL, post_cookie = NULL;
279 IServiceProvider *service_provider = NULL;
280 IHttpNegotiate2 *http_negotiate2 = NULL;
281 BSTR url, host, user, pass, path;
282 LPOLESTR accept_mimes[257];
283 const WCHAR **accept_types;
284 BYTE security_id[512];
285 DWORD len, port, flags;
290 static const WCHAR wszBindVerb[BINDVERB_CUSTOM][5] =
295 hres = IUri_GetPort(uri, &port);
299 hres = IUri_GetHost(uri, &host);
303 hres = IUri_GetUserName(uri, &user);
304 if(SUCCEEDED(hres)) {
305 hres = IUri_GetPassword(uri, &pass);
307 if(SUCCEEDED(hres)) {
308 This->base.connection = InternetConnectW(internet_session, host, port, user, pass,
309 INTERNET_SERVICE_HTTP, This->https ? INTERNET_FLAG_SECURE : 0, (DWORD_PTR)&This->base);
317 if(!This->base.connection) {
318 WARN("InternetConnect failed: %d\n", GetLastError());
319 return INET_E_CANNOT_CONNECT;
322 num = sizeof(accept_mimes)/sizeof(accept_mimes[0])-1;
323 hres = IInternetBindInfo_GetBindString(bind_info, BINDSTRING_ACCEPT_MIMES, accept_mimes, num, &num);
324 if(hres == INET_E_USE_DEFAULT_SETTING) {
325 static const WCHAR default_accept_mimeW[] = {'*','/','*',0};
326 static const WCHAR *default_accept_mimes[] = {default_accept_mimeW, NULL};
328 accept_types = default_accept_mimes;
330 }else if(hres == S_OK) {
331 accept_types = (const WCHAR**)accept_mimes;
333 WARN("GetBindString BINDSTRING_ACCEPT_MIMES failed: %08x\n", hres);
334 return INET_E_NO_VALID_MEDIA;
336 accept_mimes[num] = 0;
339 request_flags |= INTERNET_FLAG_SECURE;
341 hres = IUri_GetPathAndQuery(uri, &path);
342 if(SUCCEEDED(hres)) {
343 This->base.request = HttpOpenRequestW(This->base.connection,
344 This->base.bind_info.dwBindVerb < BINDVERB_CUSTOM
345 ? wszBindVerb[This->base.bind_info.dwBindVerb] : This->base.bind_info.szCustomVerb,
346 path, NULL, NULL, accept_types, request_flags, (DWORD_PTR)&This->base);
350 CoTaskMemFree(accept_mimes[num]);
353 if (!This->base.request) {
354 WARN("HttpOpenRequest failed: %d\n", GetLastError());
355 return INET_E_RESOURCE_NOT_FOUND;
358 hres = IInternetProtocolSink_QueryInterface(This->base.protocol_sink, &IID_IServiceProvider,
359 (void **)&service_provider);
361 WARN("IInternetProtocolSink_QueryInterface IID_IServiceProvider failed: %08x\n", hres);
365 hres = IServiceProvider_QueryService(service_provider, &IID_IHttpNegotiate,
366 &IID_IHttpNegotiate, (void **)&This->http_negotiate);
368 WARN("IServiceProvider_QueryService IID_IHttpNegotiate failed: %08x\n", hres);
369 IServiceProvider_Release(service_provider);
373 hres = IUri_GetAbsoluteUri(uri, &url);
375 IServiceProvider_Release(service_provider);
379 hres = IHttpNegotiate_BeginningTransaction(This->http_negotiate, url, default_headersW,
383 WARN("IHttpNegotiate_BeginningTransaction failed: %08x\n", hres);
384 IServiceProvider_Release(service_provider);
388 len = addl_header ? strlenW(addl_header) : 0;
390 This->full_header = heap_alloc(len*sizeof(WCHAR)+sizeof(default_headersW));
391 if(!This->full_header) {
392 IServiceProvider_Release(service_provider);
393 return E_OUTOFMEMORY;
397 memcpy(This->full_header, addl_header, len*sizeof(WCHAR));
398 CoTaskMemFree(addl_header);
399 memcpy(This->full_header+len, default_headersW, sizeof(default_headersW));
401 hres = IServiceProvider_QueryService(service_provider, &IID_IHttpNegotiate2,
402 &IID_IHttpNegotiate2, (void **)&http_negotiate2);
403 IServiceProvider_Release(service_provider);
405 WARN("IServiceProvider_QueryService IID_IHttpNegotiate2 failed: %08x\n", hres);
406 /* No goto done as per native */
408 len = sizeof(security_id)/sizeof(security_id[0]);
409 hres = IHttpNegotiate2_GetRootSecurityId(http_negotiate2, security_id, &len, 0);
410 IHttpNegotiate2_Release(http_negotiate2);
412 WARN("IHttpNegotiate2_GetRootSecurityId failed: %08x\n", hres);
415 /* FIXME: Handle security_id. Native calls undocumented function IsHostInProxyBypassList. */
417 if(This->base.bind_info.dwBindVerb == BINDVERB_POST) {
419 hres = IInternetBindInfo_GetBindString(bind_info, BINDSTRING_POST_COOKIE, &post_cookie, 1, &num);
420 if(hres == S_OK && num) {
421 if(!InternetSetOptionW(This->base.request, INTERNET_OPTION_SECONDARY_CACHE_KEY,
422 post_cookie, lstrlenW(post_cookie)))
423 WARN("InternetSetOption INTERNET_OPTION_SECONDARY_CACHE_KEY failed: %d\n", GetLastError());
424 CoTaskMemFree(post_cookie);
428 flags = INTERNET_ERROR_MASK_COMBINED_SEC_CERT;
429 res = InternetSetOptionW(This->base.request, INTERNET_OPTION_ERROR_MASK, &flags, sizeof(flags));
431 WARN("InternetSetOption(INTERNET_OPTION_ERROR_MASK) failed: %u\n", GetLastError());
434 res = InternetSetOptionW(This->base.request, INTERNET_OPTION_HTTP_DECODING, &b, sizeof(b));
436 WARN("InternetSetOption(INTERNET_OPTION_HTTP_DECODING) failed: %u\n", GetLastError());
439 error = send_http_request(This);
441 if(error == ERROR_IO_PENDING || error == ERROR_SUCCESS)
444 hres = handle_http_error(This, error);
446 } while(hres == RPC_E_RETRY);
448 WARN("HttpSendRequest failed: %d\n", error);
452 static HRESULT HttpProtocol_end_request(Protocol *protocol)
456 res = HttpEndRequestW(protocol->request, NULL, 0, 0);
457 if(!res && GetLastError() != ERROR_IO_PENDING) {
458 FIXME("HttpEndRequest failed: %u\n", GetLastError());
465 static HRESULT HttpProtocol_start_downloading(Protocol *prot)
467 HttpProtocol *This = impl_from_Protocol(prot);
468 LPWSTR content_type, content_length, ranges;
469 DWORD len = sizeof(DWORD);
474 static const WCHAR wszDefaultContentType[] =
475 {'t','e','x','t','/','h','t','m','l',0};
477 if(!This->http_negotiate) {
478 WARN("Expected IHttpNegotiate pointer to be non-NULL\n");
482 res = HttpQueryInfoW(This->base.request, HTTP_QUERY_STATUS_CODE | HTTP_QUERY_FLAG_NUMBER,
483 &status_code, &len, NULL);
485 LPWSTR response_headers = query_http_info(This, HTTP_QUERY_RAW_HEADERS_CRLF);
486 if(response_headers) {
487 hres = IHttpNegotiate_OnResponse(This->http_negotiate, status_code, response_headers,
489 heap_free(response_headers);
491 WARN("IHttpNegotiate_OnResponse failed: %08x\n", hres);
496 WARN("HttpQueryInfo failed: %d\n", GetLastError());
499 ranges = query_http_info(This, HTTP_QUERY_ACCEPT_RANGES);
501 IInternetProtocolSink_ReportProgress(This->base.protocol_sink, BINDSTATUS_ACCEPTRANGES, NULL);
505 content_type = query_http_info(This, HTTP_QUERY_CONTENT_TYPE);
507 /* remove the charset, if present */
508 LPWSTR p = strchrW(content_type, ';');
511 IInternetProtocolSink_ReportProgress(This->base.protocol_sink,
512 (This->base.bindf & BINDF_FROMURLMON)
513 ? BINDSTATUS_MIMETYPEAVAILABLE : BINDSTATUS_RAWMIMETYPE,
515 heap_free(content_type);
517 WARN("HttpQueryInfo failed: %d\n", GetLastError());
518 IInternetProtocolSink_ReportProgress(This->base.protocol_sink,
519 (This->base.bindf & BINDF_FROMURLMON)
520 ? BINDSTATUS_MIMETYPEAVAILABLE : BINDSTATUS_RAWMIMETYPE,
521 wszDefaultContentType);
524 content_length = query_http_info(This, HTTP_QUERY_CONTENT_LENGTH);
526 This->base.content_length = atoiW(content_length);
527 heap_free(content_length);
533 static void HttpProtocol_close_connection(Protocol *prot)
535 HttpProtocol *This = impl_from_Protocol(prot);
537 if(This->http_negotiate) {
538 IHttpNegotiate_Release(This->http_negotiate);
539 This->http_negotiate = NULL;
542 heap_free(This->full_header);
543 This->full_header = NULL;
546 static void HttpProtocol_on_error(Protocol *prot, DWORD error)
548 HttpProtocol *This = impl_from_Protocol(prot);
551 TRACE("(%p) %d\n", prot, error);
553 if(prot->flags & FLAG_FIRST_CONTINUE_COMPLETE) {
554 FIXME("Not handling error %d\n", error);
558 while((hres = handle_http_error(This, error)) == RPC_E_RETRY) {
559 error = send_http_request(This);
561 if(error == ERROR_IO_PENDING || error == ERROR_SUCCESS)
565 protocol_abort(prot, hres);
566 protocol_close_connection(prot);
570 static const ProtocolVtbl AsyncProtocolVtbl = {
571 HttpProtocol_open_request,
572 HttpProtocol_end_request,
573 HttpProtocol_start_downloading,
574 HttpProtocol_close_connection,
575 HttpProtocol_on_error
578 static HRESULT WINAPI HttpProtocol_QueryInterface(IInternetProtocolEx *iface, REFIID riid, void **ppv)
580 HttpProtocol *This = impl_from_IInternetProtocolEx(iface);
583 if(IsEqualGUID(&IID_IUnknown, riid)) {
584 TRACE("(%p)->(IID_IUnknown %p)\n", This, ppv);
585 *ppv = &This->IInternetProtocolEx_iface;
586 }else if(IsEqualGUID(&IID_IInternetProtocolRoot, riid)) {
587 TRACE("(%p)->(IID_IInternetProtocolRoot %p)\n", This, ppv);
588 *ppv = &This->IInternetProtocolEx_iface;
589 }else if(IsEqualGUID(&IID_IInternetProtocol, riid)) {
590 TRACE("(%p)->(IID_IInternetProtocol %p)\n", This, ppv);
591 *ppv = &This->IInternetProtocolEx_iface;
592 }else if(IsEqualGUID(&IID_IInternetProtocolEx, riid)) {
593 TRACE("(%p)->(IID_IInternetProtocolEx %p)\n", This, ppv);
594 *ppv = &This->IInternetProtocolEx_iface;
595 }else if(IsEqualGUID(&IID_IInternetPriority, riid)) {
596 TRACE("(%p)->(IID_IInternetPriority %p)\n", This, ppv);
597 *ppv = &This->IInternetPriority_iface;
598 }else if(IsEqualGUID(&IID_IWinInetInfo, riid)) {
599 TRACE("(%p)->(IID_IWinInetInfo %p)\n", This, ppv);
600 *ppv = &This->IWinInetHttpInfo_iface;
601 }else if(IsEqualGUID(&IID_IWinInetHttpInfo, riid)) {
602 TRACE("(%p)->(IID_IWinInetHttpInfo %p)\n", This, ppv);
603 *ppv = &This->IWinInetHttpInfo_iface;
607 IInternetProtocol_AddRef(iface);
611 WARN("not supported interface %s\n", debugstr_guid(riid));
612 return E_NOINTERFACE;
615 static ULONG WINAPI HttpProtocol_AddRef(IInternetProtocolEx *iface)
617 HttpProtocol *This = impl_from_IInternetProtocolEx(iface);
618 LONG ref = InterlockedIncrement(&This->ref);
619 TRACE("(%p) ref=%d\n", This, ref);
623 static ULONG WINAPI HttpProtocol_Release(IInternetProtocolEx *iface)
625 HttpProtocol *This = impl_from_IInternetProtocolEx(iface);
626 LONG ref = InterlockedDecrement(&This->ref);
628 TRACE("(%p) ref=%d\n", This, ref);
631 protocol_close_connection(&This->base);
634 URLMON_UnlockModule();
640 static HRESULT WINAPI HttpProtocol_Start(IInternetProtocolEx *iface, LPCWSTR szUrl,
641 IInternetProtocolSink *pOIProtSink, IInternetBindInfo *pOIBindInfo,
642 DWORD grfPI, HANDLE_PTR dwReserved)
644 HttpProtocol *This = impl_from_IInternetProtocolEx(iface);
648 TRACE("(%p)->(%s %p %p %08x %lx)\n", This, debugstr_w(szUrl), pOIProtSink,
649 pOIBindInfo, grfPI, dwReserved);
651 hres = CreateUri(szUrl, 0, 0, &uri);
655 hres = IInternetProtocolEx_StartEx(&This->IInternetProtocolEx_iface, uri, pOIProtSink,
656 pOIBindInfo, grfPI, (HANDLE*)dwReserved);
662 static HRESULT WINAPI HttpProtocol_Continue(IInternetProtocolEx *iface, PROTOCOLDATA *pProtocolData)
664 HttpProtocol *This = impl_from_IInternetProtocolEx(iface);
666 TRACE("(%p)->(%p)\n", This, pProtocolData);
668 return protocol_continue(&This->base, pProtocolData);
671 static HRESULT WINAPI HttpProtocol_Abort(IInternetProtocolEx *iface, HRESULT hrReason,
674 HttpProtocol *This = impl_from_IInternetProtocolEx(iface);
676 TRACE("(%p)->(%08x %08x)\n", This, hrReason, dwOptions);
678 return protocol_abort(&This->base, hrReason);
681 static HRESULT WINAPI HttpProtocol_Terminate(IInternetProtocolEx *iface, DWORD dwOptions)
683 HttpProtocol *This = impl_from_IInternetProtocolEx(iface);
685 TRACE("(%p)->(%08x)\n", This, dwOptions);
687 protocol_close_connection(&This->base);
691 static HRESULT WINAPI HttpProtocol_Suspend(IInternetProtocolEx *iface)
693 HttpProtocol *This = impl_from_IInternetProtocolEx(iface);
694 FIXME("(%p)\n", This);
698 static HRESULT WINAPI HttpProtocol_Resume(IInternetProtocolEx *iface)
700 HttpProtocol *This = impl_from_IInternetProtocolEx(iface);
701 FIXME("(%p)\n", This);
705 static HRESULT WINAPI HttpProtocol_Read(IInternetProtocolEx *iface, void *pv,
706 ULONG cb, ULONG *pcbRead)
708 HttpProtocol *This = impl_from_IInternetProtocolEx(iface);
710 TRACE("(%p)->(%p %u %p)\n", This, pv, cb, pcbRead);
712 return protocol_read(&This->base, pv, cb, pcbRead);
715 static HRESULT WINAPI HttpProtocol_Seek(IInternetProtocolEx *iface, LARGE_INTEGER dlibMove,
716 DWORD dwOrigin, ULARGE_INTEGER *plibNewPosition)
718 HttpProtocol *This = impl_from_IInternetProtocolEx(iface);
719 FIXME("(%p)->(%d %d %p)\n", This, dlibMove.u.LowPart, dwOrigin, plibNewPosition);
723 static HRESULT WINAPI HttpProtocol_LockRequest(IInternetProtocolEx *iface, DWORD dwOptions)
725 HttpProtocol *This = impl_from_IInternetProtocolEx(iface);
727 TRACE("(%p)->(%08x)\n", This, dwOptions);
729 return protocol_lock_request(&This->base);
732 static HRESULT WINAPI HttpProtocol_UnlockRequest(IInternetProtocolEx *iface)
734 HttpProtocol *This = impl_from_IInternetProtocolEx(iface);
736 TRACE("(%p)\n", This);
738 return protocol_unlock_request(&This->base);
741 static HRESULT WINAPI HttpProtocol_StartEx(IInternetProtocolEx *iface, IUri *pUri,
742 IInternetProtocolSink *pOIProtSink, IInternetBindInfo *pOIBindInfo,
743 DWORD grfPI, HANDLE *dwReserved)
745 HttpProtocol *This = impl_from_IInternetProtocolEx(iface);
749 TRACE("(%p)->(%p %p %p %08x %p)\n", This, pUri, pOIProtSink,
750 pOIBindInfo, grfPI, dwReserved);
752 hres = IUri_GetScheme(pUri, &scheme);
755 if(scheme != (This->https ? URL_SCHEME_HTTPS : URL_SCHEME_HTTP))
758 return protocol_start(&This->base, (IInternetProtocol*)&This->IInternetProtocolEx_iface, pUri,
759 pOIProtSink, pOIBindInfo);
762 static const IInternetProtocolExVtbl HttpProtocolVtbl = {
763 HttpProtocol_QueryInterface,
765 HttpProtocol_Release,
767 HttpProtocol_Continue,
769 HttpProtocol_Terminate,
770 HttpProtocol_Suspend,
774 HttpProtocol_LockRequest,
775 HttpProtocol_UnlockRequest,
779 static HRESULT WINAPI HttpPriority_QueryInterface(IInternetPriority *iface, REFIID riid, void **ppv)
781 HttpProtocol *This = impl_from_IInternetPriority(iface);
782 return IInternetProtocolEx_QueryInterface(&This->IInternetProtocolEx_iface, riid, ppv);
785 static ULONG WINAPI HttpPriority_AddRef(IInternetPriority *iface)
787 HttpProtocol *This = impl_from_IInternetPriority(iface);
788 return IInternetProtocolEx_AddRef(&This->IInternetProtocolEx_iface);
791 static ULONG WINAPI HttpPriority_Release(IInternetPriority *iface)
793 HttpProtocol *This = impl_from_IInternetPriority(iface);
794 return IInternetProtocolEx_Release(&This->IInternetProtocolEx_iface);
797 static HRESULT WINAPI HttpPriority_SetPriority(IInternetPriority *iface, LONG nPriority)
799 HttpProtocol *This = impl_from_IInternetPriority(iface);
801 TRACE("(%p)->(%d)\n", This, nPriority);
803 This->base.priority = nPriority;
807 static HRESULT WINAPI HttpPriority_GetPriority(IInternetPriority *iface, LONG *pnPriority)
809 HttpProtocol *This = impl_from_IInternetPriority(iface);
811 TRACE("(%p)->(%p)\n", This, pnPriority);
813 *pnPriority = This->base.priority;
817 static const IInternetPriorityVtbl HttpPriorityVtbl = {
818 HttpPriority_QueryInterface,
820 HttpPriority_Release,
821 HttpPriority_SetPriority,
822 HttpPriority_GetPriority
825 static HRESULT WINAPI HttpInfo_QueryInterface(IWinInetHttpInfo *iface, REFIID riid, void **ppv)
827 HttpProtocol *This = impl_from_IWinInetHttpInfo(iface);
828 return IInternetProtocolEx_QueryInterface(&This->IInternetProtocolEx_iface, riid, ppv);
831 static ULONG WINAPI HttpInfo_AddRef(IWinInetHttpInfo *iface)
833 HttpProtocol *This = impl_from_IWinInetHttpInfo(iface);
834 return IInternetProtocolEx_AddRef(&This->IInternetProtocolEx_iface);
837 static ULONG WINAPI HttpInfo_Release(IWinInetHttpInfo *iface)
839 HttpProtocol *This = impl_from_IWinInetHttpInfo(iface);
840 return IInternetProtocolEx_Release(&This->IInternetProtocolEx_iface);
843 static HRESULT WINAPI HttpInfo_QueryOption(IWinInetHttpInfo *iface, DWORD dwOption,
844 void *pBuffer, DWORD *pcbBuffer)
846 HttpProtocol *This = impl_from_IWinInetHttpInfo(iface);
847 TRACE("(%p)->(%x %p %p)\n", This, dwOption, pBuffer, pcbBuffer);
849 if(!This->base.request)
852 if(!InternetQueryOptionW(This->base.request, dwOption, pBuffer, pcbBuffer))
857 static HRESULT WINAPI HttpInfo_QueryInfo(IWinInetHttpInfo *iface, DWORD dwOption,
858 void *pBuffer, DWORD *pcbBuffer, DWORD *pdwFlags, DWORD *pdwReserved)
860 HttpProtocol *This = impl_from_IWinInetHttpInfo(iface);
861 TRACE("(%p)->(%x %p %p %p %p)\n", This, dwOption, pBuffer, pcbBuffer, pdwFlags, pdwReserved);
863 if(!This->base.request)
866 if(!HttpQueryInfoW(This->base.request, dwOption, pBuffer, pcbBuffer, pdwFlags)) {
868 memset(pBuffer, 0, *pcbBuffer);
874 static const IWinInetHttpInfoVtbl WinInetHttpInfoVtbl = {
875 HttpInfo_QueryInterface,
878 HttpInfo_QueryOption,
882 static HRESULT create_http_protocol(BOOL https, void **ppobj)
886 ret = heap_alloc_zero(sizeof(HttpProtocol));
888 return E_OUTOFMEMORY;
890 ret->base.vtbl = &AsyncProtocolVtbl;
891 ret->IInternetProtocolEx_iface.lpVtbl = &HttpProtocolVtbl;
892 ret->IInternetPriority_iface.lpVtbl = &HttpPriorityVtbl;
893 ret->IWinInetHttpInfo_iface.lpVtbl = &WinInetHttpInfoVtbl;
898 *ppobj = &ret->IInternetProtocolEx_iface;
904 HRESULT HttpProtocol_Construct(IUnknown *pUnkOuter, LPVOID *ppobj)
906 TRACE("(%p %p)\n", pUnkOuter, ppobj);
908 return create_http_protocol(FALSE, ppobj);
911 HRESULT HttpSProtocol_Construct(IUnknown *pUnkOuter, LPVOID *ppobj)
913 TRACE("(%p %p)\n", pUnkOuter, ppobj);
915 return create_http_protocol(TRUE, ppobj);