[CMAKE]
[reactos.git] / dll / win32 / urlmon / http.c
1 /*
2 * Copyright 2005 Jacek Caban
3 * Copyright 2007 Misha Koshelev
4 *
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.
9 *
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.
14 *
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
18 */
19
20 #include "urlmon_main.h"
21 #include "wininet.h"
22
23 #include "wine/debug.h"
24
25 WINE_DEFAULT_DEBUG_CHANNEL(urlmon);
26
27 typedef struct {
28 Protocol base;
29
30 const IInternetProtocolVtbl *lpIInternetProtocolVtbl;
31 const IInternetPriorityVtbl *lpInternetPriorityVtbl;
32 const IWinInetHttpInfoVtbl *lpWinInetHttpInfoVtbl;
33
34 BOOL https;
35 IHttpNegotiate *http_negotiate;
36 LPWSTR full_header;
37
38 LONG ref;
39 } HttpProtocol;
40
41 #define PRIORITY(x) ((IInternetPriority*) &(x)->lpInternetPriorityVtbl)
42 #define INETHTTPINFO(x) ((IWinInetHttpInfo*) &(x)->lpWinInetHttpInfoVtbl)
43
44 /* Default headers from native */
45 static const WCHAR wszHeaders[] = {'A','c','c','e','p','t','-','E','n','c','o','d','i','n','g',
46 ':',' ','g','z','i','p',',',' ','d','e','f','l','a','t','e',0};
47
48 static LPWSTR query_http_info(HttpProtocol *This, DWORD option)
49 {
50 LPWSTR ret = NULL;
51 DWORD len = 0;
52 BOOL res;
53
54 res = HttpQueryInfoW(This->base.request, option, NULL, &len, NULL);
55 if (!res && GetLastError() == ERROR_INSUFFICIENT_BUFFER) {
56 ret = heap_alloc(len);
57 res = HttpQueryInfoW(This->base.request, option, ret, &len, NULL);
58 }
59 if(!res) {
60 TRACE("HttpQueryInfoW(%d) failed: %08x\n", option, GetLastError());
61 heap_free(ret);
62 return NULL;
63 }
64
65 return ret;
66 }
67
68 #define ASYNCPROTOCOL_THIS(iface) DEFINE_THIS2(HttpProtocol, base, iface)
69
70 static HRESULT HttpProtocol_open_request(Protocol *prot, IUri *uri, DWORD request_flags,
71 HINTERNET internet_session, IInternetBindInfo *bind_info)
72 {
73 HttpProtocol *This = ASYNCPROTOCOL_THIS(prot);
74 LPWSTR addl_header = NULL, post_cookie = NULL, optional = NULL;
75 IServiceProvider *service_provider = NULL;
76 IHttpNegotiate2 *http_negotiate2 = NULL;
77 BSTR url, host, user, pass, path;
78 LPOLESTR accept_mimes[257];
79 const WCHAR **accept_types;
80 BYTE security_id[512];
81 DWORD len = 0, port;
82 ULONG num;
83 BOOL res, b;
84 HRESULT hres;
85
86 static const WCHAR wszBindVerb[BINDVERB_CUSTOM][5] =
87 {{'G','E','T',0},
88 {'P','O','S','T',0},
89 {'P','U','T',0}};
90
91 hres = IUri_GetPort(uri, &port);
92 if(FAILED(hres))
93 return hres;
94
95 hres = IUri_GetHost(uri, &host);
96 if(FAILED(hres))
97 return hres;
98
99 hres = IUri_GetUserName(uri, &user);
100 if(SUCCEEDED(hres)) {
101 hres = IUri_GetPassword(uri, &pass);
102
103 if(SUCCEEDED(hres)) {
104 This->base.connection = InternetConnectW(internet_session, host, port, user, pass,
105 INTERNET_SERVICE_HTTP, This->https ? INTERNET_FLAG_SECURE : 0, (DWORD_PTR)&This->base);
106 SysFreeString(pass);
107 }
108 SysFreeString(user);
109 }
110 SysFreeString(host);
111 if(FAILED(hres))
112 return hres;
113 if(!This->base.connection) {
114 WARN("InternetConnect failed: %d\n", GetLastError());
115 return INET_E_CANNOT_CONNECT;
116 }
117
118 num = sizeof(accept_mimes)/sizeof(accept_mimes[0])-1;
119 hres = IInternetBindInfo_GetBindString(bind_info, BINDSTRING_ACCEPT_MIMES, accept_mimes, num, &num);
120 if(hres == INET_E_USE_DEFAULT_SETTING) {
121 static const WCHAR default_accept_mimeW[] = {'*','/','*',0};
122 static const WCHAR *default_accept_mimes[] = {default_accept_mimeW, NULL};
123
124 accept_types = default_accept_mimes;
125 num = 0;
126 }else if(hres == S_OK) {
127 accept_types = (const WCHAR**)accept_mimes;
128 }else {
129 WARN("GetBindString BINDSTRING_ACCEPT_MIMES failed: %08x\n", hres);
130 return INET_E_NO_VALID_MEDIA;
131 }
132 accept_mimes[num] = 0;
133
134 if(This->https)
135 request_flags |= INTERNET_FLAG_SECURE;
136
137 hres = IUri_GetPathAndQuery(uri, &path);
138 if(SUCCEEDED(hres)) {
139 This->base.request = HttpOpenRequestW(This->base.connection,
140 This->base.bind_info.dwBindVerb < BINDVERB_CUSTOM
141 ? wszBindVerb[This->base.bind_info.dwBindVerb] : This->base.bind_info.szCustomVerb,
142 path, NULL, NULL, accept_types, request_flags, (DWORD_PTR)&This->base);
143 SysFreeString(path);
144 }
145 while(num--)
146 CoTaskMemFree(accept_mimes[num]);
147 if(FAILED(hres))
148 return hres;
149 if (!This->base.request) {
150 WARN("HttpOpenRequest failed: %d\n", GetLastError());
151 return INET_E_RESOURCE_NOT_FOUND;
152 }
153
154 hres = IInternetProtocolSink_QueryInterface(This->base.protocol_sink, &IID_IServiceProvider,
155 (void **)&service_provider);
156 if (hres != S_OK) {
157 WARN("IInternetProtocolSink_QueryInterface IID_IServiceProvider failed: %08x\n", hres);
158 return hres;
159 }
160
161 hres = IServiceProvider_QueryService(service_provider, &IID_IHttpNegotiate,
162 &IID_IHttpNegotiate, (void **)&This->http_negotiate);
163 if (hres != S_OK) {
164 WARN("IServiceProvider_QueryService IID_IHttpNegotiate failed: %08x\n", hres);
165 return hres;
166 }
167
168 hres = IUri_GetAbsoluteUri(uri, &url);
169 if(FAILED(hres)) {
170 IServiceProvider_Release(service_provider);
171 return hres;
172 }
173
174 hres = IHttpNegotiate_BeginningTransaction(This->http_negotiate, url, wszHeaders,
175 0, &addl_header);
176 SysFreeString(url);
177 if(hres != S_OK) {
178 WARN("IHttpNegotiate_BeginningTransaction failed: %08x\n", hres);
179 IServiceProvider_Release(service_provider);
180 return hres;
181 }
182
183 if(addl_header) {
184 int len_addl_header = strlenW(addl_header);
185
186 This->full_header = heap_alloc(len_addl_header*sizeof(WCHAR)+sizeof(wszHeaders));
187
188 lstrcpyW(This->full_header, addl_header);
189 lstrcpyW(&This->full_header[len_addl_header], wszHeaders);
190 CoTaskMemFree(addl_header);
191 }else {
192 This->full_header = (LPWSTR)wszHeaders;
193 }
194
195 hres = IServiceProvider_QueryService(service_provider, &IID_IHttpNegotiate2,
196 &IID_IHttpNegotiate2, (void **)&http_negotiate2);
197 IServiceProvider_Release(service_provider);
198 if(hres != S_OK) {
199 WARN("IServiceProvider_QueryService IID_IHttpNegotiate2 failed: %08x\n", hres);
200 /* No goto done as per native */
201 }else {
202 len = sizeof(security_id)/sizeof(security_id[0]);
203 hres = IHttpNegotiate2_GetRootSecurityId(http_negotiate2, security_id, &len, 0);
204 IHttpNegotiate2_Release(http_negotiate2);
205 if (hres != S_OK)
206 WARN("IHttpNegotiate2_GetRootSecurityId failed: %08x\n", hres);
207 }
208
209 /* FIXME: Handle security_id. Native calls undocumented function IsHostInProxyBypassList. */
210
211 if(This->base.bind_info.dwBindVerb == BINDVERB_POST) {
212 num = 0;
213 hres = IInternetBindInfo_GetBindString(bind_info, BINDSTRING_POST_COOKIE, &post_cookie, 1, &num);
214 if(hres == S_OK && num) {
215 if(!InternetSetOptionW(This->base.request, INTERNET_OPTION_SECONDARY_CACHE_KEY,
216 post_cookie, lstrlenW(post_cookie)))
217 WARN("InternetSetOption INTERNET_OPTION_SECONDARY_CACHE_KEY failed: %d\n", GetLastError());
218 CoTaskMemFree(post_cookie);
219 }
220 }
221
222 if(This->base.bind_info.dwBindVerb != BINDVERB_GET) {
223 /* Native does not use GlobalLock/GlobalUnlock, so we won't either */
224 if (This->base.bind_info.stgmedData.tymed != TYMED_HGLOBAL)
225 WARN("Expected This->base.bind_info.stgmedData.tymed to be TYMED_HGLOBAL, not %d\n",
226 This->base.bind_info.stgmedData.tymed);
227 else
228 optional = (LPWSTR)This->base.bind_info.stgmedData.u.hGlobal;
229 }
230
231 b = TRUE;
232 res = InternetSetOptionW(This->base.request, INTERNET_OPTION_HTTP_DECODING, &b, sizeof(b));
233 if(!res)
234 WARN("InternetSetOption(INTERNET_OPTION_HTTP_DECODING) failed: %08x\n", GetLastError());
235
236 res = HttpSendRequestW(This->base.request, This->full_header, lstrlenW(This->full_header),
237 optional, optional ? This->base.bind_info.cbstgmedData : 0);
238 if(!res && GetLastError() != ERROR_IO_PENDING) {
239 WARN("HttpSendRequest failed: %d\n", GetLastError());
240 return INET_E_DOWNLOAD_FAILURE;
241 }
242
243 return S_OK;
244 }
245
246 static HRESULT HttpProtocol_start_downloading(Protocol *prot)
247 {
248 HttpProtocol *This = ASYNCPROTOCOL_THIS(prot);
249 LPWSTR content_type, content_length, ranges;
250 DWORD len = sizeof(DWORD);
251 DWORD status_code;
252 BOOL res;
253 HRESULT hres;
254
255 static const WCHAR wszDefaultContentType[] =
256 {'t','e','x','t','/','h','t','m','l',0};
257
258 if(!This->http_negotiate) {
259 WARN("Expected IHttpNegotiate pointer to be non-NULL\n");
260 return S_OK;
261 }
262
263 res = HttpQueryInfoW(This->base.request, HTTP_QUERY_STATUS_CODE | HTTP_QUERY_FLAG_NUMBER,
264 &status_code, &len, NULL);
265 if(res) {
266 LPWSTR response_headers = query_http_info(This, HTTP_QUERY_RAW_HEADERS_CRLF);
267 if(response_headers) {
268 hres = IHttpNegotiate_OnResponse(This->http_negotiate, status_code, response_headers,
269 NULL, NULL);
270 heap_free(response_headers);
271 if (hres != S_OK) {
272 WARN("IHttpNegotiate_OnResponse failed: %08x\n", hres);
273 return S_OK;
274 }
275 }
276 }else {
277 WARN("HttpQueryInfo failed: %d\n", GetLastError());
278 }
279
280 ranges = query_http_info(This, HTTP_QUERY_ACCEPT_RANGES);
281 if(ranges) {
282 IInternetProtocolSink_ReportProgress(This->base.protocol_sink, BINDSTATUS_ACCEPTRANGES, NULL);
283 heap_free(ranges);
284 }
285
286 content_type = query_http_info(This, HTTP_QUERY_CONTENT_TYPE);
287 if(content_type) {
288 /* remove the charset, if present */
289 LPWSTR p = strchrW(content_type, ';');
290 if (p) *p = '\0';
291
292 IInternetProtocolSink_ReportProgress(This->base.protocol_sink,
293 (This->base.bindf & BINDF_FROMURLMON)
294 ? BINDSTATUS_MIMETYPEAVAILABLE : BINDSTATUS_RAWMIMETYPE,
295 content_type);
296 heap_free(content_type);
297 }else {
298 WARN("HttpQueryInfo failed: %d\n", GetLastError());
299 IInternetProtocolSink_ReportProgress(This->base.protocol_sink,
300 (This->base.bindf & BINDF_FROMURLMON)
301 ? BINDSTATUS_MIMETYPEAVAILABLE : BINDSTATUS_RAWMIMETYPE,
302 wszDefaultContentType);
303 }
304
305 content_length = query_http_info(This, HTTP_QUERY_CONTENT_LENGTH);
306 if(content_length) {
307 This->base.content_length = atoiW(content_length);
308 heap_free(content_length);
309 }
310
311 return S_OK;
312 }
313
314 static void HttpProtocol_close_connection(Protocol *prot)
315 {
316 HttpProtocol *This = ASYNCPROTOCOL_THIS(prot);
317
318 if(This->http_negotiate) {
319 IHttpNegotiate_Release(This->http_negotiate);
320 This->http_negotiate = 0;
321 }
322
323 if(This->full_header) {
324 if(This->full_header != wszHeaders)
325 heap_free(This->full_header);
326 This->full_header = 0;
327 }
328 }
329
330 #undef ASYNCPROTOCOL_THIS
331
332 static const ProtocolVtbl AsyncProtocolVtbl = {
333 HttpProtocol_open_request,
334 HttpProtocol_start_downloading,
335 HttpProtocol_close_connection
336 };
337
338 #define PROTOCOL_THIS(iface) DEFINE_THIS(HttpProtocol, IInternetProtocol, iface)
339
340 static HRESULT WINAPI HttpProtocol_QueryInterface(IInternetProtocol *iface, REFIID riid, void **ppv)
341 {
342 HttpProtocol *This = PROTOCOL_THIS(iface);
343
344 *ppv = NULL;
345 if(IsEqualGUID(&IID_IUnknown, riid)) {
346 TRACE("(%p)->(IID_IUnknown %p)\n", This, ppv);
347 *ppv = PROTOCOL(This);
348 }else if(IsEqualGUID(&IID_IInternetProtocolRoot, riid)) {
349 TRACE("(%p)->(IID_IInternetProtocolRoot %p)\n", This, ppv);
350 *ppv = PROTOCOL(This);
351 }else if(IsEqualGUID(&IID_IInternetProtocol, riid)) {
352 TRACE("(%p)->(IID_IInternetProtocol %p)\n", This, ppv);
353 *ppv = PROTOCOL(This);
354 }else if(IsEqualGUID(&IID_IInternetPriority, riid)) {
355 TRACE("(%p)->(IID_IInternetPriority %p)\n", This, ppv);
356 *ppv = PRIORITY(This);
357 }else if(IsEqualGUID(&IID_IWinInetInfo, riid)) {
358 TRACE("(%p)->(IID_IWinInetInfo %p)\n", This, ppv);
359 *ppv = INETHTTPINFO(This);
360 }else if(IsEqualGUID(&IID_IWinInetHttpInfo, riid)) {
361 TRACE("(%p)->(IID_IWinInetHttpInfo %p)\n", This, ppv);
362 *ppv = INETHTTPINFO(This);
363 }
364
365 if(*ppv) {
366 IInternetProtocol_AddRef(iface);
367 return S_OK;
368 }
369
370 WARN("not supported interface %s\n", debugstr_guid(riid));
371 return E_NOINTERFACE;
372 }
373
374 static ULONG WINAPI HttpProtocol_AddRef(IInternetProtocol *iface)
375 {
376 HttpProtocol *This = PROTOCOL_THIS(iface);
377 LONG ref = InterlockedIncrement(&This->ref);
378 TRACE("(%p) ref=%d\n", This, ref);
379 return ref;
380 }
381
382 static ULONG WINAPI HttpProtocol_Release(IInternetProtocol *iface)
383 {
384 HttpProtocol *This = PROTOCOL_THIS(iface);
385 LONG ref = InterlockedDecrement(&This->ref);
386
387 TRACE("(%p) ref=%d\n", This, ref);
388
389 if(!ref) {
390 protocol_close_connection(&This->base);
391 heap_free(This);
392
393 URLMON_UnlockModule();
394 }
395
396 return ref;
397 }
398
399 static HRESULT WINAPI HttpProtocol_Start(IInternetProtocol *iface, LPCWSTR szUrl,
400 IInternetProtocolSink *pOIProtSink, IInternetBindInfo *pOIBindInfo,
401 DWORD grfPI, HANDLE_PTR dwReserved)
402 {
403 HttpProtocol *This = PROTOCOL_THIS(iface);
404 IUri *uri;
405 HRESULT hres;
406
407 static const WCHAR httpW[] = {'h','t','t','p',':'};
408 static const WCHAR httpsW[] = {'h','t','t','p','s',':'};
409
410 TRACE("(%p)->(%s %p %p %08x %lx)\n", This, debugstr_w(szUrl), pOIProtSink,
411 pOIBindInfo, grfPI, dwReserved);
412
413 if(This->https
414 ? strncmpW(szUrl, httpsW, sizeof(httpsW)/sizeof(WCHAR))
415 : strncmpW(szUrl, httpW, sizeof(httpW)/sizeof(WCHAR)))
416 return MK_E_SYNTAX;
417
418 hres = CreateUri(szUrl, 0, 0, &uri);
419 if(FAILED(hres))
420 return hres;
421
422 hres = protocol_start(&This->base, PROTOCOL(This), uri, pOIProtSink, pOIBindInfo);
423
424 IUri_Release(uri);
425 return hres;
426 }
427
428 static HRESULT WINAPI HttpProtocol_Continue(IInternetProtocol *iface, PROTOCOLDATA *pProtocolData)
429 {
430 HttpProtocol *This = PROTOCOL_THIS(iface);
431
432 TRACE("(%p)->(%p)\n", This, pProtocolData);
433
434 return protocol_continue(&This->base, pProtocolData);
435 }
436
437 static HRESULT WINAPI HttpProtocol_Abort(IInternetProtocol *iface, HRESULT hrReason,
438 DWORD dwOptions)
439 {
440 HttpProtocol *This = PROTOCOL_THIS(iface);
441 FIXME("(%p)->(%08x %08x)\n", This, hrReason, dwOptions);
442 return E_NOTIMPL;
443 }
444
445 static HRESULT WINAPI HttpProtocol_Terminate(IInternetProtocol *iface, DWORD dwOptions)
446 {
447 HttpProtocol *This = PROTOCOL_THIS(iface);
448
449 TRACE("(%p)->(%08x)\n", This, dwOptions);
450
451 protocol_close_connection(&This->base);
452 return S_OK;
453 }
454
455 static HRESULT WINAPI HttpProtocol_Suspend(IInternetProtocol *iface)
456 {
457 HttpProtocol *This = PROTOCOL_THIS(iface);
458 FIXME("(%p)\n", This);
459 return E_NOTIMPL;
460 }
461
462 static HRESULT WINAPI HttpProtocol_Resume(IInternetProtocol *iface)
463 {
464 HttpProtocol *This = PROTOCOL_THIS(iface);
465 FIXME("(%p)\n", This);
466 return E_NOTIMPL;
467 }
468
469 static HRESULT WINAPI HttpProtocol_Read(IInternetProtocol *iface, void *pv,
470 ULONG cb, ULONG *pcbRead)
471 {
472 HttpProtocol *This = PROTOCOL_THIS(iface);
473
474 TRACE("(%p)->(%p %u %p)\n", This, pv, cb, pcbRead);
475
476 return protocol_read(&This->base, pv, cb, pcbRead);
477 }
478
479 static HRESULT WINAPI HttpProtocol_Seek(IInternetProtocol *iface, LARGE_INTEGER dlibMove,
480 DWORD dwOrigin, ULARGE_INTEGER *plibNewPosition)
481 {
482 HttpProtocol *This = PROTOCOL_THIS(iface);
483 FIXME("(%p)->(%d %d %p)\n", This, dlibMove.u.LowPart, dwOrigin, plibNewPosition);
484 return E_NOTIMPL;
485 }
486
487 static HRESULT WINAPI HttpProtocol_LockRequest(IInternetProtocol *iface, DWORD dwOptions)
488 {
489 HttpProtocol *This = PROTOCOL_THIS(iface);
490
491 TRACE("(%p)->(%08x)\n", This, dwOptions);
492
493 return protocol_lock_request(&This->base);
494 }
495
496 static HRESULT WINAPI HttpProtocol_UnlockRequest(IInternetProtocol *iface)
497 {
498 HttpProtocol *This = PROTOCOL_THIS(iface);
499
500 TRACE("(%p)\n", This);
501
502 return protocol_unlock_request(&This->base);
503 }
504
505 #undef PROTOCOL_THIS
506
507 static const IInternetProtocolVtbl HttpProtocolVtbl = {
508 HttpProtocol_QueryInterface,
509 HttpProtocol_AddRef,
510 HttpProtocol_Release,
511 HttpProtocol_Start,
512 HttpProtocol_Continue,
513 HttpProtocol_Abort,
514 HttpProtocol_Terminate,
515 HttpProtocol_Suspend,
516 HttpProtocol_Resume,
517 HttpProtocol_Read,
518 HttpProtocol_Seek,
519 HttpProtocol_LockRequest,
520 HttpProtocol_UnlockRequest
521 };
522
523 #define PRIORITY_THIS(iface) DEFINE_THIS(HttpProtocol, InternetPriority, iface)
524
525 static HRESULT WINAPI HttpPriority_QueryInterface(IInternetPriority *iface, REFIID riid, void **ppv)
526 {
527 HttpProtocol *This = PRIORITY_THIS(iface);
528 return IInternetProtocol_QueryInterface(PROTOCOL(This), riid, ppv);
529 }
530
531 static ULONG WINAPI HttpPriority_AddRef(IInternetPriority *iface)
532 {
533 HttpProtocol *This = PRIORITY_THIS(iface);
534 return IInternetProtocol_AddRef(PROTOCOL(This));
535 }
536
537 static ULONG WINAPI HttpPriority_Release(IInternetPriority *iface)
538 {
539 HttpProtocol *This = PRIORITY_THIS(iface);
540 return IInternetProtocol_Release(PROTOCOL(This));
541 }
542
543 static HRESULT WINAPI HttpPriority_SetPriority(IInternetPriority *iface, LONG nPriority)
544 {
545 HttpProtocol *This = PRIORITY_THIS(iface);
546
547 TRACE("(%p)->(%d)\n", This, nPriority);
548
549 This->base.priority = nPriority;
550 return S_OK;
551 }
552
553 static HRESULT WINAPI HttpPriority_GetPriority(IInternetPriority *iface, LONG *pnPriority)
554 {
555 HttpProtocol *This = PRIORITY_THIS(iface);
556
557 TRACE("(%p)->(%p)\n", This, pnPriority);
558
559 *pnPriority = This->base.priority;
560 return S_OK;
561 }
562
563 #undef PRIORITY_THIS
564
565 static const IInternetPriorityVtbl HttpPriorityVtbl = {
566 HttpPriority_QueryInterface,
567 HttpPriority_AddRef,
568 HttpPriority_Release,
569 HttpPriority_SetPriority,
570 HttpPriority_GetPriority
571 };
572
573 #define INETINFO_THIS(iface) DEFINE_THIS(HttpProtocol, WinInetHttpInfo, iface)
574
575 static HRESULT WINAPI HttpInfo_QueryInterface(IWinInetHttpInfo *iface, REFIID riid, void **ppv)
576 {
577 HttpProtocol *This = INETINFO_THIS(iface);
578 return IBinding_QueryInterface(PROTOCOL(This), riid, ppv);
579 }
580
581 static ULONG WINAPI HttpInfo_AddRef(IWinInetHttpInfo *iface)
582 {
583 HttpProtocol *This = INETINFO_THIS(iface);
584 return IBinding_AddRef(PROTOCOL(This));
585 }
586
587 static ULONG WINAPI HttpInfo_Release(IWinInetHttpInfo *iface)
588 {
589 HttpProtocol *This = INETINFO_THIS(iface);
590 return IBinding_Release(PROTOCOL(This));
591 }
592
593 static HRESULT WINAPI HttpInfo_QueryOption(IWinInetHttpInfo *iface, DWORD dwOption,
594 void *pBuffer, DWORD *pcbBuffer)
595 {
596 HttpProtocol *This = INETINFO_THIS(iface);
597 FIXME("(%p)->(%x %p %p)\n", This, dwOption, pBuffer, pcbBuffer);
598 return E_NOTIMPL;
599 }
600
601 static HRESULT WINAPI HttpInfo_QueryInfo(IWinInetHttpInfo *iface, DWORD dwOption,
602 void *pBuffer, DWORD *pcbBuffer, DWORD *pdwFlags, DWORD *pdwReserved)
603 {
604 HttpProtocol *This = INETINFO_THIS(iface);
605 FIXME("(%p)->(%x %p %p %p %p)\n", This, dwOption, pBuffer, pcbBuffer, pdwFlags, pdwReserved);
606 return E_NOTIMPL;
607 }
608
609 #undef INETINFO_THIS
610
611 static const IWinInetHttpInfoVtbl WinInetHttpInfoVtbl = {
612 HttpInfo_QueryInterface,
613 HttpInfo_AddRef,
614 HttpInfo_Release,
615 HttpInfo_QueryOption,
616 HttpInfo_QueryInfo
617 };
618
619 static HRESULT create_http_protocol(BOOL https, void **ppobj)
620 {
621 HttpProtocol *ret;
622
623 ret = heap_alloc_zero(sizeof(HttpProtocol));
624 if(!ret)
625 return E_OUTOFMEMORY;
626
627 ret->base.vtbl = &AsyncProtocolVtbl;
628 ret->lpIInternetProtocolVtbl = &HttpProtocolVtbl;
629 ret->lpInternetPriorityVtbl = &HttpPriorityVtbl;
630 ret->lpWinInetHttpInfoVtbl = &WinInetHttpInfoVtbl;
631
632 ret->https = https;
633 ret->ref = 1;
634
635 *ppobj = PROTOCOL(ret);
636
637 URLMON_LockModule();
638 return S_OK;
639 }
640
641 HRESULT HttpProtocol_Construct(IUnknown *pUnkOuter, LPVOID *ppobj)
642 {
643 TRACE("(%p %p)\n", pUnkOuter, ppobj);
644
645 return create_http_protocol(FALSE, ppobj);
646 }
647
648 HRESULT HttpSProtocol_Construct(IUnknown *pUnkOuter, LPVOID *ppobj)
649 {
650 TRACE("(%p %p)\n", pUnkOuter, ppobj);
651
652 return create_http_protocol(TRUE, ppobj);
653 }