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);
449 case ERROR_IO_PENDING:
453 * If sending response ended synchronously, it means that we have the whole data
454 * available locally (most likely in cache).
456 return protocol_syncbinding(&This->base);
458 hres = handle_http_error(This, error);
460 } while(hres == RPC_E_RETRY);
462 WARN("HttpSendRequest failed: %d\n", error);
466 static HRESULT HttpProtocol_end_request(Protocol *protocol)
470 res = HttpEndRequestW(protocol->request, NULL, 0, 0);
471 if(!res && GetLastError() != ERROR_IO_PENDING) {
472 FIXME("HttpEndRequest failed: %u\n", GetLastError());
479 static HRESULT HttpProtocol_start_downloading(Protocol *prot)
481 HttpProtocol *This = impl_from_Protocol(prot);
482 LPWSTR content_type, content_length, ranges;
483 DWORD len = sizeof(DWORD);
488 static const WCHAR wszDefaultContentType[] =
489 {'t','e','x','t','/','h','t','m','l',0};
491 if(!This->http_negotiate) {
492 WARN("Expected IHttpNegotiate pointer to be non-NULL\n");
496 res = HttpQueryInfoW(This->base.request, HTTP_QUERY_STATUS_CODE | HTTP_QUERY_FLAG_NUMBER,
497 &status_code, &len, NULL);
499 LPWSTR response_headers = query_http_info(This, HTTP_QUERY_RAW_HEADERS_CRLF);
500 if(response_headers) {
501 hres = IHttpNegotiate_OnResponse(This->http_negotiate, status_code, response_headers,
503 heap_free(response_headers);
505 WARN("IHttpNegotiate_OnResponse failed: %08x\n", hres);
510 WARN("HttpQueryInfo failed: %d\n", GetLastError());
513 ranges = query_http_info(This, HTTP_QUERY_ACCEPT_RANGES);
515 IInternetProtocolSink_ReportProgress(This->base.protocol_sink, BINDSTATUS_ACCEPTRANGES, NULL);
519 content_type = query_http_info(This, HTTP_QUERY_CONTENT_TYPE);
521 /* remove the charset, if present */
522 LPWSTR p = strchrW(content_type, ';');
525 IInternetProtocolSink_ReportProgress(This->base.protocol_sink,
526 (This->base.bindf & BINDF_FROMURLMON)
527 ? BINDSTATUS_MIMETYPEAVAILABLE : BINDSTATUS_RAWMIMETYPE,
529 heap_free(content_type);
531 WARN("HttpQueryInfo failed: %d\n", GetLastError());
532 IInternetProtocolSink_ReportProgress(This->base.protocol_sink,
533 (This->base.bindf & BINDF_FROMURLMON)
534 ? BINDSTATUS_MIMETYPEAVAILABLE : BINDSTATUS_RAWMIMETYPE,
535 wszDefaultContentType);
538 content_length = query_http_info(This, HTTP_QUERY_CONTENT_LENGTH);
540 This->base.content_length = atoiW(content_length);
541 heap_free(content_length);
547 static void HttpProtocol_close_connection(Protocol *prot)
549 HttpProtocol *This = impl_from_Protocol(prot);
551 if(This->http_negotiate) {
552 IHttpNegotiate_Release(This->http_negotiate);
553 This->http_negotiate = NULL;
556 heap_free(This->full_header);
557 This->full_header = NULL;
560 static void HttpProtocol_on_error(Protocol *prot, DWORD error)
562 HttpProtocol *This = impl_from_Protocol(prot);
565 TRACE("(%p) %d\n", prot, error);
567 if(prot->flags & FLAG_FIRST_CONTINUE_COMPLETE) {
568 FIXME("Not handling error %d\n", error);
572 while((hres = handle_http_error(This, error)) == RPC_E_RETRY) {
573 error = send_http_request(This);
575 if(error == ERROR_IO_PENDING || error == ERROR_SUCCESS)
579 protocol_abort(prot, hres);
580 protocol_close_connection(prot);
584 static const ProtocolVtbl AsyncProtocolVtbl = {
585 HttpProtocol_open_request,
586 HttpProtocol_end_request,
587 HttpProtocol_start_downloading,
588 HttpProtocol_close_connection,
589 HttpProtocol_on_error
592 static HRESULT WINAPI HttpProtocol_QueryInterface(IInternetProtocolEx *iface, REFIID riid, void **ppv)
594 HttpProtocol *This = impl_from_IInternetProtocolEx(iface);
597 if(IsEqualGUID(&IID_IUnknown, riid)) {
598 TRACE("(%p)->(IID_IUnknown %p)\n", This, ppv);
599 *ppv = &This->IInternetProtocolEx_iface;
600 }else if(IsEqualGUID(&IID_IInternetProtocolRoot, riid)) {
601 TRACE("(%p)->(IID_IInternetProtocolRoot %p)\n", This, ppv);
602 *ppv = &This->IInternetProtocolEx_iface;
603 }else if(IsEqualGUID(&IID_IInternetProtocol, riid)) {
604 TRACE("(%p)->(IID_IInternetProtocol %p)\n", This, ppv);
605 *ppv = &This->IInternetProtocolEx_iface;
606 }else if(IsEqualGUID(&IID_IInternetProtocolEx, riid)) {
607 TRACE("(%p)->(IID_IInternetProtocolEx %p)\n", This, ppv);
608 *ppv = &This->IInternetProtocolEx_iface;
609 }else if(IsEqualGUID(&IID_IInternetPriority, riid)) {
610 TRACE("(%p)->(IID_IInternetPriority %p)\n", This, ppv);
611 *ppv = &This->IInternetPriority_iface;
612 }else if(IsEqualGUID(&IID_IWinInetInfo, riid)) {
613 TRACE("(%p)->(IID_IWinInetInfo %p)\n", This, ppv);
614 *ppv = &This->IWinInetHttpInfo_iface;
615 }else if(IsEqualGUID(&IID_IWinInetHttpInfo, riid)) {
616 TRACE("(%p)->(IID_IWinInetHttpInfo %p)\n", This, ppv);
617 *ppv = &This->IWinInetHttpInfo_iface;
621 IInternetProtocolEx_AddRef(iface);
625 WARN("not supported interface %s\n", debugstr_guid(riid));
626 return E_NOINTERFACE;
629 static ULONG WINAPI HttpProtocol_AddRef(IInternetProtocolEx *iface)
631 HttpProtocol *This = impl_from_IInternetProtocolEx(iface);
632 LONG ref = InterlockedIncrement(&This->ref);
633 TRACE("(%p) ref=%d\n", This, ref);
637 static ULONG WINAPI HttpProtocol_Release(IInternetProtocolEx *iface)
639 HttpProtocol *This = impl_from_IInternetProtocolEx(iface);
640 LONG ref = InterlockedDecrement(&This->ref);
642 TRACE("(%p) ref=%d\n", This, ref);
645 protocol_close_connection(&This->base);
648 URLMON_UnlockModule();
654 static HRESULT WINAPI HttpProtocol_Start(IInternetProtocolEx *iface, LPCWSTR szUrl,
655 IInternetProtocolSink *pOIProtSink, IInternetBindInfo *pOIBindInfo,
656 DWORD grfPI, HANDLE_PTR dwReserved)
658 HttpProtocol *This = impl_from_IInternetProtocolEx(iface);
662 TRACE("(%p)->(%s %p %p %08x %lx)\n", This, debugstr_w(szUrl), pOIProtSink,
663 pOIBindInfo, grfPI, dwReserved);
665 hres = CreateUri(szUrl, 0, 0, &uri);
669 hres = IInternetProtocolEx_StartEx(&This->IInternetProtocolEx_iface, uri, pOIProtSink,
670 pOIBindInfo, grfPI, (HANDLE*)dwReserved);
676 static HRESULT WINAPI HttpProtocol_Continue(IInternetProtocolEx *iface, PROTOCOLDATA *pProtocolData)
678 HttpProtocol *This = impl_from_IInternetProtocolEx(iface);
680 TRACE("(%p)->(%p)\n", This, pProtocolData);
682 return protocol_continue(&This->base, pProtocolData);
685 static HRESULT WINAPI HttpProtocol_Abort(IInternetProtocolEx *iface, HRESULT hrReason,
688 HttpProtocol *This = impl_from_IInternetProtocolEx(iface);
690 TRACE("(%p)->(%08x %08x)\n", This, hrReason, dwOptions);
692 return protocol_abort(&This->base, hrReason);
695 static HRESULT WINAPI HttpProtocol_Terminate(IInternetProtocolEx *iface, DWORD dwOptions)
697 HttpProtocol *This = impl_from_IInternetProtocolEx(iface);
699 TRACE("(%p)->(%08x)\n", This, dwOptions);
701 protocol_close_connection(&This->base);
705 static HRESULT WINAPI HttpProtocol_Suspend(IInternetProtocolEx *iface)
707 HttpProtocol *This = impl_from_IInternetProtocolEx(iface);
708 FIXME("(%p)\n", This);
712 static HRESULT WINAPI HttpProtocol_Resume(IInternetProtocolEx *iface)
714 HttpProtocol *This = impl_from_IInternetProtocolEx(iface);
715 FIXME("(%p)\n", This);
719 static HRESULT WINAPI HttpProtocol_Read(IInternetProtocolEx *iface, void *pv,
720 ULONG cb, ULONG *pcbRead)
722 HttpProtocol *This = impl_from_IInternetProtocolEx(iface);
724 TRACE("(%p)->(%p %u %p)\n", This, pv, cb, pcbRead);
726 return protocol_read(&This->base, pv, cb, pcbRead);
729 static HRESULT WINAPI HttpProtocol_Seek(IInternetProtocolEx *iface, LARGE_INTEGER dlibMove,
730 DWORD dwOrigin, ULARGE_INTEGER *plibNewPosition)
732 HttpProtocol *This = impl_from_IInternetProtocolEx(iface);
733 FIXME("(%p)->(%d %d %p)\n", This, dlibMove.u.LowPart, dwOrigin, plibNewPosition);
737 static HRESULT WINAPI HttpProtocol_LockRequest(IInternetProtocolEx *iface, DWORD dwOptions)
739 HttpProtocol *This = impl_from_IInternetProtocolEx(iface);
741 TRACE("(%p)->(%08x)\n", This, dwOptions);
743 return protocol_lock_request(&This->base);
746 static HRESULT WINAPI HttpProtocol_UnlockRequest(IInternetProtocolEx *iface)
748 HttpProtocol *This = impl_from_IInternetProtocolEx(iface);
750 TRACE("(%p)\n", This);
752 return protocol_unlock_request(&This->base);
755 static HRESULT WINAPI HttpProtocol_StartEx(IInternetProtocolEx *iface, IUri *pUri,
756 IInternetProtocolSink *pOIProtSink, IInternetBindInfo *pOIBindInfo,
757 DWORD grfPI, HANDLE *dwReserved)
759 HttpProtocol *This = impl_from_IInternetProtocolEx(iface);
763 TRACE("(%p)->(%p %p %p %08x %p)\n", This, pUri, pOIProtSink,
764 pOIBindInfo, grfPI, dwReserved);
766 hres = IUri_GetScheme(pUri, &scheme);
769 if(scheme != (This->https ? URL_SCHEME_HTTPS : URL_SCHEME_HTTP))
772 return protocol_start(&This->base, (IInternetProtocol*)&This->IInternetProtocolEx_iface, pUri,
773 pOIProtSink, pOIBindInfo);
776 static const IInternetProtocolExVtbl HttpProtocolVtbl = {
777 HttpProtocol_QueryInterface,
779 HttpProtocol_Release,
781 HttpProtocol_Continue,
783 HttpProtocol_Terminate,
784 HttpProtocol_Suspend,
788 HttpProtocol_LockRequest,
789 HttpProtocol_UnlockRequest,
793 static HRESULT WINAPI HttpPriority_QueryInterface(IInternetPriority *iface, REFIID riid, void **ppv)
795 HttpProtocol *This = impl_from_IInternetPriority(iface);
796 return IInternetProtocolEx_QueryInterface(&This->IInternetProtocolEx_iface, riid, ppv);
799 static ULONG WINAPI HttpPriority_AddRef(IInternetPriority *iface)
801 HttpProtocol *This = impl_from_IInternetPriority(iface);
802 return IInternetProtocolEx_AddRef(&This->IInternetProtocolEx_iface);
805 static ULONG WINAPI HttpPriority_Release(IInternetPriority *iface)
807 HttpProtocol *This = impl_from_IInternetPriority(iface);
808 return IInternetProtocolEx_Release(&This->IInternetProtocolEx_iface);
811 static HRESULT WINAPI HttpPriority_SetPriority(IInternetPriority *iface, LONG nPriority)
813 HttpProtocol *This = impl_from_IInternetPriority(iface);
815 TRACE("(%p)->(%d)\n", This, nPriority);
817 This->base.priority = nPriority;
821 static HRESULT WINAPI HttpPriority_GetPriority(IInternetPriority *iface, LONG *pnPriority)
823 HttpProtocol *This = impl_from_IInternetPriority(iface);
825 TRACE("(%p)->(%p)\n", This, pnPriority);
827 *pnPriority = This->base.priority;
831 static const IInternetPriorityVtbl HttpPriorityVtbl = {
832 HttpPriority_QueryInterface,
834 HttpPriority_Release,
835 HttpPriority_SetPriority,
836 HttpPriority_GetPriority
839 static HRESULT WINAPI HttpInfo_QueryInterface(IWinInetHttpInfo *iface, REFIID riid, void **ppv)
841 HttpProtocol *This = impl_from_IWinInetHttpInfo(iface);
842 return IInternetProtocolEx_QueryInterface(&This->IInternetProtocolEx_iface, riid, ppv);
845 static ULONG WINAPI HttpInfo_AddRef(IWinInetHttpInfo *iface)
847 HttpProtocol *This = impl_from_IWinInetHttpInfo(iface);
848 return IInternetProtocolEx_AddRef(&This->IInternetProtocolEx_iface);
851 static ULONG WINAPI HttpInfo_Release(IWinInetHttpInfo *iface)
853 HttpProtocol *This = impl_from_IWinInetHttpInfo(iface);
854 return IInternetProtocolEx_Release(&This->IInternetProtocolEx_iface);
857 static HRESULT WINAPI HttpInfo_QueryOption(IWinInetHttpInfo *iface, DWORD dwOption,
858 void *pBuffer, DWORD *pcbBuffer)
860 HttpProtocol *This = impl_from_IWinInetHttpInfo(iface);
861 TRACE("(%p)->(%x %p %p)\n", This, dwOption, pBuffer, pcbBuffer);
863 if(!This->base.request)
866 if(!InternetQueryOptionW(This->base.request, dwOption, pBuffer, pcbBuffer))
871 static HRESULT WINAPI HttpInfo_QueryInfo(IWinInetHttpInfo *iface, DWORD dwOption,
872 void *pBuffer, DWORD *pcbBuffer, DWORD *pdwFlags, DWORD *pdwReserved)
874 HttpProtocol *This = impl_from_IWinInetHttpInfo(iface);
875 TRACE("(%p)->(%x %p %p %p %p)\n", This, dwOption, pBuffer, pcbBuffer, pdwFlags, pdwReserved);
877 if(!This->base.request)
880 if(!HttpQueryInfoW(This->base.request, dwOption, pBuffer, pcbBuffer, pdwFlags)) {
882 memset(pBuffer, 0, *pcbBuffer);
888 static const IWinInetHttpInfoVtbl WinInetHttpInfoVtbl = {
889 HttpInfo_QueryInterface,
892 HttpInfo_QueryOption,
896 static HRESULT create_http_protocol(BOOL https, void **ppobj)
900 ret = heap_alloc_zero(sizeof(HttpProtocol));
902 return E_OUTOFMEMORY;
904 ret->base.vtbl = &AsyncProtocolVtbl;
905 ret->IInternetProtocolEx_iface.lpVtbl = &HttpProtocolVtbl;
906 ret->IInternetPriority_iface.lpVtbl = &HttpPriorityVtbl;
907 ret->IWinInetHttpInfo_iface.lpVtbl = &WinInetHttpInfoVtbl;
912 *ppobj = &ret->IInternetProtocolEx_iface;
918 HRESULT HttpProtocol_Construct(IUnknown *pUnkOuter, LPVOID *ppobj)
920 TRACE("(%p %p)\n", pUnkOuter, ppobj);
922 return create_http_protocol(FALSE, ppobj);
925 HRESULT HttpSProtocol_Construct(IUnknown *pUnkOuter, LPVOID *ppobj)
927 TRACE("(%p %p)\n", pUnkOuter, ppobj);
929 return create_http_protocol(TRUE, ppobj);