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 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;
125 case ERROR_INTERNET_SEC_CERT_DATE_INVALID:
126 case ERROR_INTERNET_SEC_CERT_CN_INVALID:
127 case ERROR_INTERNET_HTTP_TO_HTTPS_ON_REDIR:
128 case ERROR_INTERNET_HTTPS_TO_HTTP_ON_REDIR:
129 case ERROR_HTTP_REDIRECT_NEEDS_CONFIRMATION:
130 case ERROR_INTERNET_INVALID_CA:
131 case ERROR_INTERNET_CLIENT_AUTH_CERT_NEEDED:
132 security_problem = TRUE;
135 security_problem = FALSE;
138 hres = IInternetProtocolSink_QueryInterface(This->base.protocol_sink, &IID_IServiceProvider,
141 ERR("Failed to get IServiceProvider.\n");
145 if(security_problem) {
146 hres = IServiceProvider_QueryService(serv_prov, &IID_IHttpSecurity, &IID_IHttpSecurity,
147 (void**)&http_security);
148 if(SUCCEEDED(hres)) {
149 hres = IHttpSecurity_OnSecurityProblem(http_security, error);
150 IHttpSecurity_Release(http_security);
156 IServiceProvider_Release(serv_prov);
159 if(error == ERROR_INTERNET_SEC_CERT_DATE_INVALID)
160 res = set_security_flag(This, SECURITY_FLAG_IGNORE_CERT_DATE_INVALID);
161 else if(error == ERROR_INTERNET_SEC_CERT_CN_INVALID)
162 res = set_security_flag(This, SECURITY_FLAG_IGNORE_CERT_CN_INVALID);
163 else if(error == ERROR_INTERNET_INVALID_CA)
164 res = set_security_flag(This, SECURITY_FLAG_IGNORE_UNKNOWN_CA);
169 FIXME("Don't know how to ignore error %d\n", error);
175 if(hres == RPC_E_RETRY)
178 return internet_error_to_hres(error);
183 hres = IServiceProvider_QueryService(serv_prov, &IID_IWindowForBindingUI, &IID_IWindowForBindingUI,
185 if(SUCCEEDED(hres)) {
187 const IID *iid_reason;
190 iid_reason = &IID_IHttpSecurity;
191 else if(error == ERROR_INTERNET_INCORRECT_PASSWORD)
192 iid_reason = &IID_IAuthenticate;
194 iid_reason = &IID_IWindowForBindingUI;
196 hres = IWindowForBindingUI_GetWindow(wfb_ui, iid_reason, &hwnd);
197 if(SUCCEEDED(hres) && hwnd)
201 res = InternetErrorDlg(hwnd, This->base.request, error,
202 FLAGS_ERROR_UI_FLAGS_CHANGE_OPTIONS | FLAGS_ERROR_UI_FLAGS_GENERATE_DATA,
205 if(res == ERROR_INTERNET_FORCE_RETRY || res == ERROR_SUCCESS)
210 IWindowForBindingUI_Release(wfb_ui);
213 IServiceProvider_Release(serv_prov);
215 if(hres == RPC_E_RETRY)
218 return internet_error_to_hres(error);
221 static ULONG send_http_request(HttpProtocol *This)
223 INTERNET_BUFFERSW send_buffer = {sizeof(INTERNET_BUFFERSW)};
226 send_buffer.lpcszHeader = This->full_header;
227 send_buffer.dwHeadersLength = send_buffer.dwHeadersTotal = strlenW(This->full_header);
229 if(This->base.bind_info.dwBindVerb != BINDVERB_GET) {
230 switch(This->base.bind_info.stgmedData.tymed) {
232 /* Native does not use GlobalLock/GlobalUnlock, so we won't either */
233 send_buffer.lpvBuffer = This->base.bind_info.stgmedData.u.hGlobal;
234 send_buffer.dwBufferLength = send_buffer.dwBufferTotal = This->base.bind_info.cbstgmedData;
236 case TYMED_ISTREAM: {
237 LARGE_INTEGER offset;
239 send_buffer.dwBufferTotal = This->base.bind_info.cbstgmedData;
240 if(!This->base.post_stream) {
241 This->base.post_stream = This->base.bind_info.stgmedData.u.pstm;
242 IStream_AddRef(This->base.post_stream);
246 IStream_Seek(This->base.post_stream, offset, STREAM_SEEK_SET, NULL);
250 FIXME("Unsupported This->base.bind_info.stgmedData.tymed %d\n", This->base.bind_info.stgmedData.tymed);
254 if(This->base.post_stream)
255 res = HttpSendRequestExW(This->base.request, &send_buffer, NULL, 0, 0);
257 res = HttpSendRequestW(This->base.request, send_buffer.lpcszHeader, send_buffer.dwHeadersLength,
258 send_buffer.lpvBuffer, send_buffer.dwBufferLength);
260 return res ? 0 : GetLastError();
263 static inline HttpProtocol *impl_from_Protocol(Protocol *prot)
265 return CONTAINING_RECORD(prot, HttpProtocol, base);
268 static HRESULT HttpProtocol_open_request(Protocol *prot, IUri *uri, DWORD request_flags,
269 HINTERNET internet_session, IInternetBindInfo *bind_info)
271 HttpProtocol *This = impl_from_Protocol(prot);
272 LPWSTR addl_header = NULL, post_cookie = NULL;
273 IServiceProvider *service_provider = NULL;
274 IHttpNegotiate2 *http_negotiate2 = NULL;
275 BSTR url, host, user, pass, path;
276 LPOLESTR accept_mimes[257];
277 const WCHAR **accept_types;
278 BYTE security_id[512];
284 static const WCHAR wszBindVerb[BINDVERB_CUSTOM][5] =
289 hres = IUri_GetPort(uri, &port);
293 hres = IUri_GetHost(uri, &host);
297 hres = IUri_GetUserName(uri, &user);
298 if(SUCCEEDED(hres)) {
299 hres = IUri_GetPassword(uri, &pass);
301 if(SUCCEEDED(hres)) {
302 This->base.connection = InternetConnectW(internet_session, host, port, user, pass,
303 INTERNET_SERVICE_HTTP, This->https ? INTERNET_FLAG_SECURE : 0, (DWORD_PTR)&This->base);
311 if(!This->base.connection) {
312 WARN("InternetConnect failed: %d\n", GetLastError());
313 return INET_E_CANNOT_CONNECT;
316 num = sizeof(accept_mimes)/sizeof(accept_mimes[0])-1;
317 hres = IInternetBindInfo_GetBindString(bind_info, BINDSTRING_ACCEPT_MIMES, accept_mimes, num, &num);
318 if(hres == INET_E_USE_DEFAULT_SETTING) {
319 static const WCHAR default_accept_mimeW[] = {'*','/','*',0};
320 static const WCHAR *default_accept_mimes[] = {default_accept_mimeW, NULL};
322 accept_types = default_accept_mimes;
324 }else if(hres == S_OK) {
325 accept_types = (const WCHAR**)accept_mimes;
327 WARN("GetBindString BINDSTRING_ACCEPT_MIMES failed: %08x\n", hres);
328 return INET_E_NO_VALID_MEDIA;
330 accept_mimes[num] = 0;
333 request_flags |= INTERNET_FLAG_SECURE;
335 hres = IUri_GetPathAndQuery(uri, &path);
336 if(SUCCEEDED(hres)) {
337 This->base.request = HttpOpenRequestW(This->base.connection,
338 This->base.bind_info.dwBindVerb < BINDVERB_CUSTOM
339 ? wszBindVerb[This->base.bind_info.dwBindVerb] : This->base.bind_info.szCustomVerb,
340 path, NULL, NULL, accept_types, request_flags, (DWORD_PTR)&This->base);
344 CoTaskMemFree(accept_mimes[num]);
347 if (!This->base.request) {
348 WARN("HttpOpenRequest failed: %d\n", GetLastError());
349 return INET_E_RESOURCE_NOT_FOUND;
352 hres = IInternetProtocolSink_QueryInterface(This->base.protocol_sink, &IID_IServiceProvider,
353 (void **)&service_provider);
355 WARN("IInternetProtocolSink_QueryInterface IID_IServiceProvider failed: %08x\n", hres);
359 hres = IServiceProvider_QueryService(service_provider, &IID_IHttpNegotiate,
360 &IID_IHttpNegotiate, (void **)&This->http_negotiate);
362 WARN("IServiceProvider_QueryService IID_IHttpNegotiate failed: %08x\n", hres);
363 IServiceProvider_Release(service_provider);
367 hres = IUri_GetAbsoluteUri(uri, &url);
369 IServiceProvider_Release(service_provider);
373 hres = IHttpNegotiate_BeginningTransaction(This->http_negotiate, url, default_headersW,
377 WARN("IHttpNegotiate_BeginningTransaction failed: %08x\n", hres);
378 IServiceProvider_Release(service_provider);
382 len = addl_header ? strlenW(addl_header) : 0;
384 This->full_header = heap_alloc(len*sizeof(WCHAR)+sizeof(default_headersW));
385 if(!This->full_header) {
386 IServiceProvider_Release(service_provider);
387 return E_OUTOFMEMORY;
391 memcpy(This->full_header, addl_header, len*sizeof(WCHAR));
392 CoTaskMemFree(addl_header);
393 memcpy(This->full_header+len, default_headersW, sizeof(default_headersW));
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 = NULL;
531 if(This->full_header) {
532 heap_free(This->full_header);
533 This->full_header = NULL;
537 static void HttpProtocol_on_error(Protocol *prot, DWORD error)
539 HttpProtocol *This = impl_from_Protocol(prot);
542 TRACE("(%p) %d\n", prot, error);
544 if(prot->flags & FLAG_FIRST_CONTINUE_COMPLETE) {
545 FIXME("Not handling error %d\n", error);
549 while((hres = handle_http_error(This, error)) == RPC_E_RETRY) {
550 error = send_http_request(This);
552 if(error == ERROR_IO_PENDING || error == ERROR_SUCCESS)
556 protocol_abort(prot, hres);
557 protocol_close_connection(prot);
561 static const ProtocolVtbl AsyncProtocolVtbl = {
562 HttpProtocol_open_request,
563 HttpProtocol_end_request,
564 HttpProtocol_start_downloading,
565 HttpProtocol_close_connection,
566 HttpProtocol_on_error
569 static HRESULT WINAPI HttpProtocol_QueryInterface(IInternetProtocolEx *iface, REFIID riid, void **ppv)
571 HttpProtocol *This = impl_from_IInternetProtocolEx(iface);
574 if(IsEqualGUID(&IID_IUnknown, riid)) {
575 TRACE("(%p)->(IID_IUnknown %p)\n", This, ppv);
576 *ppv = &This->IInternetProtocolEx_iface;
577 }else if(IsEqualGUID(&IID_IInternetProtocolRoot, riid)) {
578 TRACE("(%p)->(IID_IInternetProtocolRoot %p)\n", This, ppv);
579 *ppv = &This->IInternetProtocolEx_iface;
580 }else if(IsEqualGUID(&IID_IInternetProtocol, riid)) {
581 TRACE("(%p)->(IID_IInternetProtocol %p)\n", This, ppv);
582 *ppv = &This->IInternetProtocolEx_iface;
583 }else if(IsEqualGUID(&IID_IInternetProtocolEx, riid)) {
584 TRACE("(%p)->(IID_IInternetProtocolEx %p)\n", This, ppv);
585 *ppv = &This->IInternetProtocolEx_iface;
586 }else if(IsEqualGUID(&IID_IInternetPriority, riid)) {
587 TRACE("(%p)->(IID_IInternetPriority %p)\n", This, ppv);
588 *ppv = &This->IInternetPriority_iface;
589 }else if(IsEqualGUID(&IID_IWinInetInfo, riid)) {
590 TRACE("(%p)->(IID_IWinInetInfo %p)\n", This, ppv);
591 *ppv = &This->IWinInetHttpInfo_iface;
592 }else if(IsEqualGUID(&IID_IWinInetHttpInfo, riid)) {
593 TRACE("(%p)->(IID_IWinInetHttpInfo %p)\n", This, ppv);
594 *ppv = &This->IWinInetHttpInfo_iface;
598 IInternetProtocol_AddRef(iface);
602 WARN("not supported interface %s\n", debugstr_guid(riid));
603 return E_NOINTERFACE;
606 static ULONG WINAPI HttpProtocol_AddRef(IInternetProtocolEx *iface)
608 HttpProtocol *This = impl_from_IInternetProtocolEx(iface);
609 LONG ref = InterlockedIncrement(&This->ref);
610 TRACE("(%p) ref=%d\n", This, ref);
614 static ULONG WINAPI HttpProtocol_Release(IInternetProtocolEx *iface)
616 HttpProtocol *This = impl_from_IInternetProtocolEx(iface);
617 LONG ref = InterlockedDecrement(&This->ref);
619 TRACE("(%p) ref=%d\n", This, ref);
622 protocol_close_connection(&This->base);
625 URLMON_UnlockModule();
631 static HRESULT WINAPI HttpProtocol_Start(IInternetProtocolEx *iface, LPCWSTR szUrl,
632 IInternetProtocolSink *pOIProtSink, IInternetBindInfo *pOIBindInfo,
633 DWORD grfPI, HANDLE_PTR dwReserved)
635 HttpProtocol *This = impl_from_IInternetProtocolEx(iface);
639 TRACE("(%p)->(%s %p %p %08x %lx)\n", This, debugstr_w(szUrl), pOIProtSink,
640 pOIBindInfo, grfPI, dwReserved);
642 hres = CreateUri(szUrl, 0, 0, &uri);
646 hres = IInternetProtocolEx_StartEx(&This->IInternetProtocolEx_iface, uri, pOIProtSink,
647 pOIBindInfo, grfPI, (HANDLE*)dwReserved);
653 static HRESULT WINAPI HttpProtocol_Continue(IInternetProtocolEx *iface, PROTOCOLDATA *pProtocolData)
655 HttpProtocol *This = impl_from_IInternetProtocolEx(iface);
657 TRACE("(%p)->(%p)\n", This, pProtocolData);
659 return protocol_continue(&This->base, pProtocolData);
662 static HRESULT WINAPI HttpProtocol_Abort(IInternetProtocolEx *iface, HRESULT hrReason,
665 HttpProtocol *This = impl_from_IInternetProtocolEx(iface);
667 TRACE("(%p)->(%08x %08x)\n", This, hrReason, dwOptions);
669 return protocol_abort(&This->base, hrReason);
672 static HRESULT WINAPI HttpProtocol_Terminate(IInternetProtocolEx *iface, DWORD dwOptions)
674 HttpProtocol *This = impl_from_IInternetProtocolEx(iface);
676 TRACE("(%p)->(%08x)\n", This, dwOptions);
678 protocol_close_connection(&This->base);
682 static HRESULT WINAPI HttpProtocol_Suspend(IInternetProtocolEx *iface)
684 HttpProtocol *This = impl_from_IInternetProtocolEx(iface);
685 FIXME("(%p)\n", This);
689 static HRESULT WINAPI HttpProtocol_Resume(IInternetProtocolEx *iface)
691 HttpProtocol *This = impl_from_IInternetProtocolEx(iface);
692 FIXME("(%p)\n", This);
696 static HRESULT WINAPI HttpProtocol_Read(IInternetProtocolEx *iface, void *pv,
697 ULONG cb, ULONG *pcbRead)
699 HttpProtocol *This = impl_from_IInternetProtocolEx(iface);
701 TRACE("(%p)->(%p %u %p)\n", This, pv, cb, pcbRead);
703 return protocol_read(&This->base, pv, cb, pcbRead);
706 static HRESULT WINAPI HttpProtocol_Seek(IInternetProtocolEx *iface, LARGE_INTEGER dlibMove,
707 DWORD dwOrigin, ULARGE_INTEGER *plibNewPosition)
709 HttpProtocol *This = impl_from_IInternetProtocolEx(iface);
710 FIXME("(%p)->(%d %d %p)\n", This, dlibMove.u.LowPart, dwOrigin, plibNewPosition);
714 static HRESULT WINAPI HttpProtocol_LockRequest(IInternetProtocolEx *iface, DWORD dwOptions)
716 HttpProtocol *This = impl_from_IInternetProtocolEx(iface);
718 TRACE("(%p)->(%08x)\n", This, dwOptions);
720 return protocol_lock_request(&This->base);
723 static HRESULT WINAPI HttpProtocol_UnlockRequest(IInternetProtocolEx *iface)
725 HttpProtocol *This = impl_from_IInternetProtocolEx(iface);
727 TRACE("(%p)\n", This);
729 return protocol_unlock_request(&This->base);
732 static HRESULT WINAPI HttpProtocol_StartEx(IInternetProtocolEx *iface, IUri *pUri,
733 IInternetProtocolSink *pOIProtSink, IInternetBindInfo *pOIBindInfo,
734 DWORD grfPI, HANDLE *dwReserved)
736 HttpProtocol *This = impl_from_IInternetProtocolEx(iface);
740 TRACE("(%p)->(%p %p %p %08x %p)\n", This, pUri, pOIProtSink,
741 pOIBindInfo, grfPI, dwReserved);
743 hres = IUri_GetScheme(pUri, &scheme);
746 if(scheme != (This->https ? URL_SCHEME_HTTPS : URL_SCHEME_HTTP))
749 return protocol_start(&This->base, (IInternetProtocol*)&This->IInternetProtocolEx_iface, pUri,
750 pOIProtSink, pOIBindInfo);
753 static const IInternetProtocolExVtbl HttpProtocolVtbl = {
754 HttpProtocol_QueryInterface,
756 HttpProtocol_Release,
758 HttpProtocol_Continue,
760 HttpProtocol_Terminate,
761 HttpProtocol_Suspend,
765 HttpProtocol_LockRequest,
766 HttpProtocol_UnlockRequest,
770 static HRESULT WINAPI HttpPriority_QueryInterface(IInternetPriority *iface, REFIID riid, void **ppv)
772 HttpProtocol *This = impl_from_IInternetPriority(iface);
773 return IInternetProtocolEx_QueryInterface(&This->IInternetProtocolEx_iface, riid, ppv);
776 static ULONG WINAPI HttpPriority_AddRef(IInternetPriority *iface)
778 HttpProtocol *This = impl_from_IInternetPriority(iface);
779 return IInternetProtocolEx_AddRef(&This->IInternetProtocolEx_iface);
782 static ULONG WINAPI HttpPriority_Release(IInternetPriority *iface)
784 HttpProtocol *This = impl_from_IInternetPriority(iface);
785 return IInternetProtocolEx_Release(&This->IInternetProtocolEx_iface);
788 static HRESULT WINAPI HttpPriority_SetPriority(IInternetPriority *iface, LONG nPriority)
790 HttpProtocol *This = impl_from_IInternetPriority(iface);
792 TRACE("(%p)->(%d)\n", This, nPriority);
794 This->base.priority = nPriority;
798 static HRESULT WINAPI HttpPriority_GetPriority(IInternetPriority *iface, LONG *pnPriority)
800 HttpProtocol *This = impl_from_IInternetPriority(iface);
802 TRACE("(%p)->(%p)\n", This, pnPriority);
804 *pnPriority = This->base.priority;
808 static const IInternetPriorityVtbl HttpPriorityVtbl = {
809 HttpPriority_QueryInterface,
811 HttpPriority_Release,
812 HttpPriority_SetPriority,
813 HttpPriority_GetPriority
816 static HRESULT WINAPI HttpInfo_QueryInterface(IWinInetHttpInfo *iface, REFIID riid, void **ppv)
818 HttpProtocol *This = impl_from_IWinInetHttpInfo(iface);
819 return IInternetProtocolEx_QueryInterface(&This->IInternetProtocolEx_iface, riid, ppv);
822 static ULONG WINAPI HttpInfo_AddRef(IWinInetHttpInfo *iface)
824 HttpProtocol *This = impl_from_IWinInetHttpInfo(iface);
825 return IInternetProtocolEx_AddRef(&This->IInternetProtocolEx_iface);
828 static ULONG WINAPI HttpInfo_Release(IWinInetHttpInfo *iface)
830 HttpProtocol *This = impl_from_IWinInetHttpInfo(iface);
831 return IInternetProtocolEx_Release(&This->IInternetProtocolEx_iface);
834 static HRESULT WINAPI HttpInfo_QueryOption(IWinInetHttpInfo *iface, DWORD dwOption,
835 void *pBuffer, DWORD *pcbBuffer)
837 HttpProtocol *This = impl_from_IWinInetHttpInfo(iface);
838 TRACE("(%p)->(%x %p %p)\n", This, dwOption, pBuffer, pcbBuffer);
840 if(!This->base.request)
843 if(!InternetQueryOptionW(This->base.request, dwOption, pBuffer, pcbBuffer))
848 static HRESULT WINAPI HttpInfo_QueryInfo(IWinInetHttpInfo *iface, DWORD dwOption,
849 void *pBuffer, DWORD *pcbBuffer, DWORD *pdwFlags, DWORD *pdwReserved)
851 HttpProtocol *This = impl_from_IWinInetHttpInfo(iface);
852 TRACE("(%p)->(%x %p %p %p %p)\n", This, dwOption, pBuffer, pcbBuffer, pdwFlags, pdwReserved);
854 if(!This->base.request)
857 if(!HttpQueryInfoW(This->base.request, dwOption, pBuffer, pcbBuffer, pdwFlags)) {
859 memset(pBuffer, 0, *pcbBuffer);
865 static const IWinInetHttpInfoVtbl WinInetHttpInfoVtbl = {
866 HttpInfo_QueryInterface,
869 HttpInfo_QueryOption,
873 static HRESULT create_http_protocol(BOOL https, void **ppobj)
877 ret = heap_alloc_zero(sizeof(HttpProtocol));
879 return E_OUTOFMEMORY;
881 ret->base.vtbl = &AsyncProtocolVtbl;
882 ret->IInternetProtocolEx_iface.lpVtbl = &HttpProtocolVtbl;
883 ret->IInternetPriority_iface.lpVtbl = &HttpPriorityVtbl;
884 ret->IWinInetHttpInfo_iface.lpVtbl = &WinInetHttpInfoVtbl;
889 *ppobj = &ret->IInternetProtocolEx_iface;
895 HRESULT HttpProtocol_Construct(IUnknown *pUnkOuter, LPVOID *ppobj)
897 TRACE("(%p %p)\n", pUnkOuter, ppobj);
899 return create_http_protocol(FALSE, ppobj);
902 HRESULT HttpSProtocol_Construct(IUnknown *pUnkOuter, LPVOID *ppobj)
904 TRACE("(%p %p)\n", pUnkOuter, ppobj);
906 return create_http_protocol(TRUE, ppobj);