wininet: Support the Cache-Control max-age directive for setting url cache entry...
[wine/testsucceed.git] / dlls / mshtml / protocol.c
blobdad93ba2b1c6efa168f4f560c70c66db649d7d6e
1 /*
2 * Copyright 2005 Jacek Caban
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19 #include "config.h"
21 #include <stdarg.h>
22 #include <stdio.h>
24 #define COBJMACROS
26 #include "windef.h"
27 #include "winbase.h"
28 #include "winuser.h"
29 #include "ole2.h"
31 #include "wine/debug.h"
32 #include "wine/unicode.h"
34 #include "mshtml_private.h"
36 WINE_DEFAULT_DEBUG_CHANNEL(mshtml);
38 /********************************************************************
39 * common ProtocolFactory implementation
42 typedef struct {
43 IInternetProtocolInfo IInternetProtocolInfo_iface;
44 IClassFactory IClassFactory_iface;
45 } ProtocolFactory;
47 static inline ProtocolFactory *impl_from_IInternetProtocolInfo(IInternetProtocolInfo *iface)
49 return CONTAINING_RECORD(iface, ProtocolFactory, IInternetProtocolInfo_iface);
52 static HRESULT WINAPI InternetProtocolInfo_QueryInterface(IInternetProtocolInfo *iface, REFIID riid, void **ppv)
54 ProtocolFactory *This = impl_from_IInternetProtocolInfo(iface);
56 *ppv = NULL;
57 if(IsEqualGUID(&IID_IUnknown, riid)) {
58 TRACE("(%p)->(IID_IUnknown %p)\n", This, ppv);
59 *ppv = &This->IInternetProtocolInfo_iface;
60 }else if(IsEqualGUID(&IID_IInternetProtocolInfo, riid)) {
61 TRACE("(%p)->(IID_IInternetProtocolInfo %p)\n", This, ppv);
62 *ppv = &This->IInternetProtocolInfo_iface;
63 }else if(IsEqualGUID(&IID_IClassFactory, riid)) {
64 TRACE("(%p)->(IID_IClassFactory %p)\n", This, ppv);
65 *ppv = &This->IClassFactory_iface;
68 if(!*ppv) {
69 WARN("unknown interface %s\n", debugstr_guid(riid));
70 return E_NOINTERFACE;
73 IInternetProtocolInfo_AddRef(iface);
74 return S_OK;
77 static ULONG WINAPI InternetProtocolInfo_AddRef(IInternetProtocolInfo *iface)
79 TRACE("(%p)\n", iface);
80 return 2;
83 static ULONG WINAPI InternetProtocolInfo_Release(IInternetProtocolInfo *iface)
85 TRACE("(%p)\n", iface);
86 return 1;
89 static HRESULT WINAPI InternetProtocolInfo_CombineUrl(IInternetProtocolInfo *iface,
90 LPCWSTR pwzBaseUrl, LPCWSTR pwzRelativeUrl, DWORD dwCombineFlags, LPWSTR pwzResult,
91 DWORD cchResult, DWORD* pcchResult, DWORD dwReserved)
93 TRACE("%p)->(%s %s %08x %p %d %p %d)\n", iface, debugstr_w(pwzBaseUrl),
94 debugstr_w(pwzRelativeUrl), dwCombineFlags, pwzResult, cchResult,
95 pcchResult, dwReserved);
97 return INET_E_USE_DEFAULT_PROTOCOLHANDLER;
100 static HRESULT WINAPI InternetProtocolInfo_CompareUrl(IInternetProtocolInfo *iface, LPCWSTR pwzUrl1,
101 LPCWSTR pwzUrl2, DWORD dwCompareFlags)
103 TRACE("%p)->(%s %s %08x)\n", iface, debugstr_w(pwzUrl1), debugstr_w(pwzUrl2), dwCompareFlags);
104 return E_NOTIMPL;
107 static inline ProtocolFactory *impl_from_IClassFactory(IClassFactory *iface)
109 return CONTAINING_RECORD(iface, ProtocolFactory, IClassFactory_iface);
112 static HRESULT WINAPI ClassFactory_QueryInterface(IClassFactory *iface, REFIID riid, void **ppv)
114 ProtocolFactory *This = impl_from_IClassFactory(iface);
115 return IInternetProtocolInfo_QueryInterface(&This->IInternetProtocolInfo_iface, riid, ppv);
118 static ULONG WINAPI ClassFactory_AddRef(IClassFactory *iface)
120 ProtocolFactory *This = impl_from_IClassFactory(iface);
121 return IInternetProtocolInfo_AddRef(&This->IInternetProtocolInfo_iface);
124 static ULONG WINAPI ClassFactory_Release(IClassFactory *iface)
126 ProtocolFactory *This = impl_from_IClassFactory(iface);
127 return IInternetProtocolInfo_Release(&This->IInternetProtocolInfo_iface);
130 static HRESULT WINAPI ClassFactory_LockServer(IClassFactory *iface, BOOL dolock)
132 TRACE("(%p)->(%x)\n", iface, dolock);
133 return S_OK;
136 /********************************************************************
137 * AboutProtocol implementation
140 typedef struct {
141 IInternetProtocol IInternetProtocol_iface;
143 LONG ref;
145 BYTE *data;
146 ULONG data_len;
147 ULONG cur;
149 IUnknown *pUnkOuter;
150 } AboutProtocol;
152 static inline AboutProtocol *AboutProtocol_from_IInternetProtocol(IInternetProtocol *iface)
154 return CONTAINING_RECORD(iface, AboutProtocol, IInternetProtocol_iface);
157 static HRESULT WINAPI AboutProtocol_QueryInterface(IInternetProtocol *iface, REFIID riid, void **ppv)
159 AboutProtocol *This = AboutProtocol_from_IInternetProtocol(iface);
161 *ppv = NULL;
163 if(IsEqualGUID(&IID_IUnknown, riid)) {
164 TRACE("(%p)->(IID_IUnknown %p)\n", iface, ppv);
165 if(This->pUnkOuter)
166 return IUnknown_QueryInterface(This->pUnkOuter, riid, ppv);
167 *ppv = &This->IInternetProtocol_iface;
168 }else if(IsEqualGUID(&IID_IInternetProtocolRoot, riid)) {
169 TRACE("(%p)->(IID_IInternetProtocolRoot %p)\n", iface, ppv);
170 *ppv = &This->IInternetProtocol_iface;
171 }else if(IsEqualGUID(&IID_IInternetProtocol, riid)) {
172 TRACE("(%p)->(IID_IInternetProtocol %p)\n", iface, ppv);
173 *ppv = &This->IInternetProtocol_iface;
174 }else if(IsEqualGUID(&IID_IServiceProvider, riid)) {
175 FIXME("IServiceProvider is not implemented\n");
176 return E_NOINTERFACE;
179 if(!*ppv) {
180 TRACE("unknown interface %s\n", debugstr_guid(riid));
181 return E_NOINTERFACE;
184 IInternetProtocol_AddRef(iface);
185 return S_OK;
188 static ULONG WINAPI AboutProtocol_AddRef(IInternetProtocol *iface)
190 AboutProtocol *This = AboutProtocol_from_IInternetProtocol(iface);
191 ULONG ref = InterlockedIncrement(&This->ref);
192 TRACE("(%p) ref=%d\n", iface, ref);
193 return This->pUnkOuter ? IUnknown_AddRef(This->pUnkOuter) : ref;
196 static ULONG WINAPI AboutProtocol_Release(IInternetProtocol *iface)
198 AboutProtocol *This = AboutProtocol_from_IInternetProtocol(iface);
199 IUnknown *pUnkOuter = This->pUnkOuter;
200 ULONG ref = InterlockedDecrement(&This->ref);
202 TRACE("(%p) ref=%x\n", iface, ref);
204 if(!ref) {
205 heap_free(This->data);
206 heap_free(This);
209 return pUnkOuter ? IUnknown_Release(pUnkOuter) : ref;
212 static HRESULT WINAPI AboutProtocol_Start(IInternetProtocol *iface, LPCWSTR szUrl,
213 IInternetProtocolSink* pOIProtSink, IInternetBindInfo* pOIBindInfo,
214 DWORD grfPI, HANDLE_PTR dwReserved)
216 AboutProtocol *This = AboutProtocol_from_IInternetProtocol(iface);
217 BINDINFO bindinfo;
218 DWORD grfBINDF = 0;
219 LPCWSTR text = NULL;
220 DWORD data_len;
221 BYTE *data;
223 static const WCHAR html_begin[] = {0xfeff,'<','H','T','M','L','>',0};
224 static const WCHAR html_end[] = {'<','/','H','T','M','L','>',0};
225 static const WCHAR wszBlank[] = {'b','l','a','n','k',0};
226 static const WCHAR wszAbout[] = {'a','b','o','u','t',':'};
227 static const WCHAR wszTextHtml[] = {'t','e','x','t','/','h','t','m','l',0};
229 /* NOTE:
230 * the about protocol seems not to work as I would expect. It creates html document
231 * for a given url, eg. about:some_text -> <HTML>some_text</HTML> except for the case when
232 * some_text = "blank", when document is blank (<HTML></HMTL>). The same happens
233 * when the url does not have "about:" in the beginning.
236 TRACE("(%p)->(%s %p %p %08x %lx)\n", This, debugstr_w(szUrl), pOIProtSink,
237 pOIBindInfo, grfPI, dwReserved);
239 memset(&bindinfo, 0, sizeof(bindinfo));
240 bindinfo.cbSize = sizeof(BINDINFO);
241 IInternetBindInfo_GetBindInfo(pOIBindInfo, &grfBINDF, &bindinfo);
242 ReleaseBindInfo(&bindinfo);
244 TRACE("bindf %x\n", grfBINDF);
246 if(strlenW(szUrl)>=sizeof(wszAbout)/sizeof(WCHAR) && !memcmp(wszAbout, szUrl, sizeof(wszAbout))) {
247 text = szUrl + sizeof(wszAbout)/sizeof(WCHAR);
248 if(!strcmpW(wszBlank, text))
249 text = NULL;
252 data_len = sizeof(html_begin)+sizeof(html_end)-sizeof(WCHAR)
253 + (text ? strlenW(text)*sizeof(WCHAR) : 0);
254 data = heap_alloc(data_len);
255 if(!data)
256 return E_OUTOFMEMORY;
258 heap_free(This->data);
259 This->data = data;
260 This->data_len = data_len;
262 memcpy(This->data, html_begin, sizeof(html_begin));
263 if(text)
264 strcatW((LPWSTR)This->data, text);
265 strcatW((LPWSTR)This->data, html_end);
267 This->cur = 0;
269 IInternetProtocolSink_ReportProgress(pOIProtSink, BINDSTATUS_MIMETYPEAVAILABLE, wszTextHtml);
271 IInternetProtocolSink_ReportData(pOIProtSink,
272 BSCF_FIRSTDATANOTIFICATION | BSCF_LASTDATANOTIFICATION | BSCF_DATAFULLYAVAILABLE,
273 This->data_len, This->data_len);
275 IInternetProtocolSink_ReportResult(pOIProtSink, S_OK, 0, NULL);
277 return S_OK;
280 static HRESULT WINAPI AboutProtocol_Continue(IInternetProtocol *iface, PROTOCOLDATA* pProtocolData)
282 AboutProtocol *This = AboutProtocol_from_IInternetProtocol(iface);
283 FIXME("(%p)->(%p)\n", This, pProtocolData);
284 return E_NOTIMPL;
287 static HRESULT WINAPI AboutProtocol_Abort(IInternetProtocol *iface, HRESULT hrReason,
288 DWORD dwOptions)
290 AboutProtocol *This = AboutProtocol_from_IInternetProtocol(iface);
291 FIXME("(%p)->(%08x %08x)\n", This, hrReason, dwOptions);
292 return E_NOTIMPL;
295 static HRESULT WINAPI AboutProtocol_Terminate(IInternetProtocol *iface, DWORD dwOptions)
297 AboutProtocol *This = AboutProtocol_from_IInternetProtocol(iface);
298 TRACE("(%p)->(%08x)\n", This, dwOptions);
299 return S_OK;
302 static HRESULT WINAPI AboutProtocol_Suspend(IInternetProtocol *iface)
304 AboutProtocol *This = AboutProtocol_from_IInternetProtocol(iface);
305 FIXME("(%p)\n", This);
306 return E_NOTIMPL;
309 static HRESULT WINAPI AboutProtocol_Resume(IInternetProtocol *iface)
311 AboutProtocol *This = AboutProtocol_from_IInternetProtocol(iface);
312 FIXME("(%p)\n", This);
313 return E_NOTIMPL;
316 static HRESULT WINAPI AboutProtocol_Read(IInternetProtocol *iface, void* pv, ULONG cb, ULONG* pcbRead)
318 AboutProtocol *This = AboutProtocol_from_IInternetProtocol(iface);
320 TRACE("(%p)->(%p %u %p)\n", This, pv, cb, pcbRead);
322 if(!This->data)
323 return E_FAIL;
325 *pcbRead = (cb > This->data_len-This->cur ? This->data_len-This->cur : cb);
327 if(!*pcbRead)
328 return S_FALSE;
330 memcpy(pv, This->data+This->cur, *pcbRead);
331 This->cur += *pcbRead;
333 return S_OK;
336 static HRESULT WINAPI AboutProtocol_Seek(IInternetProtocol *iface, LARGE_INTEGER dlibMove,
337 DWORD dwOrigin, ULARGE_INTEGER* plibNewPosition)
339 AboutProtocol *This = AboutProtocol_from_IInternetProtocol(iface);
340 FIXME("(%p)->(%d %d %p)\n", This, dlibMove.u.LowPart, dwOrigin, plibNewPosition);
341 return E_NOTIMPL;
344 static HRESULT WINAPI AboutProtocol_LockRequest(IInternetProtocol *iface, DWORD dwOptions)
346 AboutProtocol *This = AboutProtocol_from_IInternetProtocol(iface);
348 TRACE("(%p)->(%d)\n", This, dwOptions);
350 return S_OK;
353 static HRESULT WINAPI AboutProtocol_UnlockRequest(IInternetProtocol *iface)
355 AboutProtocol *This = AboutProtocol_from_IInternetProtocol(iface);
357 TRACE("(%p)\n", This);
359 return S_OK;
362 static const IInternetProtocolVtbl AboutProtocolVtbl = {
363 AboutProtocol_QueryInterface,
364 AboutProtocol_AddRef,
365 AboutProtocol_Release,
366 AboutProtocol_Start,
367 AboutProtocol_Continue,
368 AboutProtocol_Abort,
369 AboutProtocol_Terminate,
370 AboutProtocol_Suspend,
371 AboutProtocol_Resume,
372 AboutProtocol_Read,
373 AboutProtocol_Seek,
374 AboutProtocol_LockRequest,
375 AboutProtocol_UnlockRequest
378 static HRESULT WINAPI AboutProtocolFactory_CreateInstance(IClassFactory *iface, IUnknown *pUnkOuter,
379 REFIID riid, void **ppv)
381 AboutProtocol *ret;
382 HRESULT hres = S_OK;
384 TRACE("(%p)->(%p %s %p)\n", iface, pUnkOuter, debugstr_guid(riid), ppv);
386 ret = heap_alloc(sizeof(AboutProtocol));
387 ret->IInternetProtocol_iface.lpVtbl = &AboutProtocolVtbl;
388 ret->ref = 0;
390 ret->data = NULL;
391 ret->data_len = 0;
392 ret->cur = 0;
393 ret->pUnkOuter = pUnkOuter;
395 if(pUnkOuter) {
396 ret->ref = 1;
397 if(IsEqualGUID(&IID_IUnknown, riid))
398 *ppv = &ret->IInternetProtocol_iface;
399 else
400 hres = E_INVALIDARG;
401 }else {
402 hres = IInternetProtocol_QueryInterface(&ret->IInternetProtocol_iface, riid, ppv);
405 if(FAILED(hres))
406 heap_free(ret);
408 return hres;
411 static HRESULT WINAPI AboutProtocolInfo_ParseUrl(IInternetProtocolInfo *iface, LPCWSTR pwzUrl,
412 PARSEACTION ParseAction, DWORD dwParseFlags, LPWSTR pwzResult, DWORD cchResult,
413 DWORD* pcchResult, DWORD dwReserved)
415 TRACE("%p)->(%s %d %08x %p %d %p %d)\n", iface, debugstr_w(pwzUrl), ParseAction,
416 dwParseFlags, pwzResult, cchResult, pcchResult, dwReserved);
418 if(ParseAction == PARSE_SECURITY_URL) {
419 unsigned int len = strlenW(pwzUrl)+1;
421 *pcchResult = len;
422 if(len > cchResult)
423 return S_FALSE;
425 memcpy(pwzResult, pwzUrl, len*sizeof(WCHAR));
426 return S_OK;
429 if(ParseAction == PARSE_DOMAIN) {
430 if(!pcchResult)
431 return E_POINTER;
433 if(pwzUrl)
434 *pcchResult = strlenW(pwzUrl)+1;
435 else
436 *pcchResult = 1;
437 return E_FAIL;
440 return INET_E_DEFAULT_ACTION;
443 static HRESULT WINAPI AboutProtocolInfo_QueryInfo(IInternetProtocolInfo *iface, LPCWSTR pwzUrl,
444 QUERYOPTION QueryOption, DWORD dwQueryFlags, LPVOID pBuffer, DWORD cbBuffer, DWORD* pcbBuf,
445 DWORD dwReserved)
447 TRACE("%p)->(%s %08x %08x %p %d %p %d)\n", iface, debugstr_w(pwzUrl), QueryOption, dwQueryFlags, pBuffer,
448 cbBuffer, pcbBuf, dwReserved);
450 switch(QueryOption) {
451 case QUERY_CAN_NAVIGATE:
452 return INET_E_USE_DEFAULT_PROTOCOLHANDLER;
454 case QUERY_USES_NETWORK:
455 if(!pBuffer || cbBuffer < sizeof(DWORD))
456 return E_FAIL;
458 *(DWORD*)pBuffer = 0;
459 if(pcbBuf)
460 *pcbBuf = sizeof(DWORD);
462 break;
464 case QUERY_IS_CACHED:
465 FIXME("Unsupported option QUERY_IS_CACHED\n");
466 return E_NOTIMPL;
467 case QUERY_IS_INSTALLEDENTRY:
468 FIXME("Unsupported option QUERY_IS_INSTALLEDENTRY\n");
469 return E_NOTIMPL;
470 case QUERY_IS_CACHED_OR_MAPPED:
471 FIXME("Unsupported option QUERY_IS_CACHED_OR_MAPPED\n");
472 return E_NOTIMPL;
473 case QUERY_IS_SECURE:
474 FIXME("Unsupported option QUERY_IS_SECURE\n");
475 return E_NOTIMPL;
476 case QUERY_IS_SAFE:
477 FIXME("Unsupported option QUERY_IS_SAFE\n");
478 return E_NOTIMPL;
479 case QUERY_USES_HISTORYFOLDER:
480 FIXME("Unsupported option QUERY_USES_HISTORYFOLDER\n");
481 return E_FAIL;
482 default:
483 return E_FAIL;
486 return S_OK;
489 static const IInternetProtocolInfoVtbl AboutProtocolInfoVtbl = {
490 InternetProtocolInfo_QueryInterface,
491 InternetProtocolInfo_AddRef,
492 InternetProtocolInfo_Release,
493 AboutProtocolInfo_ParseUrl,
494 InternetProtocolInfo_CombineUrl,
495 InternetProtocolInfo_CompareUrl,
496 AboutProtocolInfo_QueryInfo
499 static const IClassFactoryVtbl AboutProtocolFactoryVtbl = {
500 ClassFactory_QueryInterface,
501 ClassFactory_AddRef,
502 ClassFactory_Release,
503 AboutProtocolFactory_CreateInstance,
504 ClassFactory_LockServer
507 static ProtocolFactory AboutProtocolFactory = {
508 { &AboutProtocolInfoVtbl },
509 { &AboutProtocolFactoryVtbl }
512 /********************************************************************
513 * ResProtocol implementation
516 typedef struct {
517 IInternetProtocol IInternetProtocol_iface;
518 LONG ref;
520 BYTE *data;
521 ULONG data_len;
522 ULONG cur;
524 IUnknown *pUnkOuter;
525 } ResProtocol;
527 static inline ResProtocol *ResProtocol_from_IInternetProtocol(IInternetProtocol *iface)
529 return CONTAINING_RECORD(iface, ResProtocol, IInternetProtocol_iface);
532 static HRESULT WINAPI ResProtocol_QueryInterface(IInternetProtocol *iface, REFIID riid, void **ppv)
534 ResProtocol *This = ResProtocol_from_IInternetProtocol(iface);
536 *ppv = NULL;
538 if(IsEqualGUID(&IID_IUnknown, riid)) {
539 TRACE("(%p)->(IID_IUnknown %p)\n", iface, ppv);
540 if(This->pUnkOuter)
541 return IUnknown_QueryInterface(This->pUnkOuter, &IID_IUnknown, ppv);
542 *ppv = &This->IInternetProtocol_iface;
543 }else if(IsEqualGUID(&IID_IInternetProtocolRoot, riid)) {
544 TRACE("(%p)->(IID_IInternetProtocolRoot %p)\n", iface, ppv);
545 *ppv = &This->IInternetProtocol_iface;
546 }else if(IsEqualGUID(&IID_IInternetProtocol, riid)) {
547 TRACE("(%p)->(IID_IInternetProtocol %p)\n", iface, ppv);
548 *ppv = &This->IInternetProtocol_iface;
549 }else if(IsEqualGUID(&IID_IServiceProvider, riid)) {
550 FIXME("IServiceProvider is not implemented\n");
551 return E_NOINTERFACE;
554 if(!*ppv) {
555 TRACE("unknown interface %s\n", debugstr_guid(riid));
556 return E_NOINTERFACE;
559 IInternetProtocol_AddRef(iface);
560 return S_OK;
563 static ULONG WINAPI ResProtocol_AddRef(IInternetProtocol *iface)
565 ResProtocol *This = ResProtocol_from_IInternetProtocol(iface);
566 ULONG ref = InterlockedIncrement(&This->ref);
567 TRACE("(%p) ref=%d\n", iface, ref);
568 return This->pUnkOuter ? IUnknown_AddRef(This->pUnkOuter) : ref;
571 static ULONG WINAPI ResProtocol_Release(IInternetProtocol *iface)
573 ResProtocol *This = (ResProtocol*)iface;
574 IUnknown *pUnkOuter = This->pUnkOuter;
575 ULONG ref = InterlockedDecrement(&This->ref);
577 TRACE("(%p) ref=%x\n", iface, ref);
579 if(!ref) {
580 heap_free(This->data);
581 heap_free(This);
584 return pUnkOuter ? IUnknown_Release(pUnkOuter) : ref;
587 static HRESULT WINAPI ResProtocol_Start(IInternetProtocol *iface, LPCWSTR szUrl,
588 IInternetProtocolSink* pOIProtSink, IInternetBindInfo* pOIBindInfo,
589 DWORD grfPI, HANDLE_PTR dwReserved)
591 ResProtocol *This = ResProtocol_from_IInternetProtocol(iface);
592 DWORD grfBINDF = 0, len;
593 BINDINFO bindinfo;
594 LPWSTR url_dll, url_file, url, mime, res_type = (LPWSTR)RT_HTML;
595 HMODULE hdll;
596 HRSRC src;
597 HRESULT hres;
599 static const WCHAR wszRes[] = {'r','e','s',':','/','/'};
601 TRACE("(%p)->(%s %p %p %08x %lx)\n", This, debugstr_w(szUrl), pOIProtSink,
602 pOIBindInfo, grfPI, dwReserved);
604 memset(&bindinfo, 0, sizeof(bindinfo));
605 bindinfo.cbSize = sizeof(BINDINFO);
606 IInternetBindInfo_GetBindInfo(pOIBindInfo, &grfBINDF, &bindinfo);
607 ReleaseBindInfo(&bindinfo);
609 len = strlenW(szUrl)+16;
610 url = heap_alloc(len*sizeof(WCHAR));
611 hres = CoInternetParseUrl(szUrl, PARSE_ENCODE, 0, url, len, &len, 0);
612 if(FAILED(hres)) {
613 WARN("CoInternetParseUrl failed: %08x\n", hres);
614 heap_free(url);
615 IInternetProtocolSink_ReportResult(pOIProtSink, hres, 0, NULL);
616 return hres;
619 if(len < sizeof(wszRes)/sizeof(wszRes[0]) || memcmp(url, wszRes, sizeof(wszRes))) {
620 WARN("Wrong protocol of url: %s\n", debugstr_w(url));
621 IInternetProtocolSink_ReportResult(pOIProtSink, E_INVALIDARG, 0, NULL);
622 heap_free(url);
623 return E_INVALIDARG;
626 url_dll = url + sizeof(wszRes)/sizeof(wszRes[0]);
627 if(!(url_file = strrchrW(url_dll, '/'))) {
628 WARN("wrong url: %s\n", debugstr_w(url));
629 IInternetProtocolSink_ReportResult(pOIProtSink, MK_E_SYNTAX, 0, NULL);
630 heap_free(url);
631 return MK_E_SYNTAX;
634 *url_file++ = 0;
635 hdll = LoadLibraryExW(url_dll, NULL, LOAD_LIBRARY_AS_DATAFILE);
636 if(!hdll) {
637 if (!(res_type = strrchrW(url_dll, '/'))) {
638 WARN("Could not open dll: %s\n", debugstr_w(url_dll));
639 IInternetProtocolSink_ReportResult(pOIProtSink, HRESULT_FROM_WIN32(GetLastError()), 0, NULL);
640 heap_free(url);
641 return HRESULT_FROM_WIN32(GetLastError());
643 *res_type++ = 0;
645 hdll = LoadLibraryExW(url_dll, NULL, LOAD_LIBRARY_AS_DATAFILE);
646 if(!hdll) {
647 WARN("Could not open dll: %s\n", debugstr_w(url_dll));
648 IInternetProtocolSink_ReportResult(pOIProtSink, HRESULT_FROM_WIN32(GetLastError()), 0, NULL);
649 heap_free(url);
650 return HRESULT_FROM_WIN32(GetLastError());
654 TRACE("trying to find resource type %s, name %s\n", debugstr_w(res_type), debugstr_w(url_file));
656 src = FindResourceW(hdll, url_file, res_type);
657 if(!src) {
658 LPWSTR endpoint = NULL;
659 DWORD file_id = strtolW(url_file, &endpoint, 10);
660 if(endpoint == url_file+strlenW(url_file))
661 src = FindResourceW(hdll, MAKEINTRESOURCEW(file_id), MAKEINTRESOURCEW(RT_HTML));
663 if(!src) {
664 WARN("Could not find resource\n");
665 IInternetProtocolSink_ReportResult(pOIProtSink,
666 HRESULT_FROM_WIN32(GetLastError()), 0, NULL);
667 heap_free(url);
668 return HRESULT_FROM_WIN32(GetLastError());
672 if(This->data) {
673 WARN("data already loaded\n");
674 heap_free(This->data);
677 This->data_len = SizeofResource(hdll, src);
678 This->data = heap_alloc(This->data_len);
679 memcpy(This->data, LoadResource(hdll, src), This->data_len);
680 This->cur = 0;
682 FreeLibrary(hdll);
684 hres = FindMimeFromData(NULL, url_file, This->data, This->data_len, NULL, 0, &mime, 0);
685 heap_free(url);
686 if(SUCCEEDED(hres)) {
687 IInternetProtocolSink_ReportProgress(pOIProtSink, BINDSTATUS_MIMETYPEAVAILABLE, mime);
688 CoTaskMemFree(mime);
691 IInternetProtocolSink_ReportData(pOIProtSink,
692 BSCF_FIRSTDATANOTIFICATION | BSCF_LASTDATANOTIFICATION | BSCF_DATAFULLYAVAILABLE,
693 This->data_len, This->data_len);
695 IInternetProtocolSink_ReportResult(pOIProtSink, S_OK, 0, NULL);
697 return S_OK;
700 static HRESULT WINAPI ResProtocol_Continue(IInternetProtocol *iface, PROTOCOLDATA* pProtocolData)
702 ResProtocol *This = ResProtocol_from_IInternetProtocol(iface);
703 FIXME("(%p)->(%p)\n", This, pProtocolData);
704 return E_NOTIMPL;
707 static HRESULT WINAPI ResProtocol_Abort(IInternetProtocol *iface, HRESULT hrReason,
708 DWORD dwOptions)
710 ResProtocol *This = ResProtocol_from_IInternetProtocol(iface);
711 FIXME("(%p)->(%08x %08x)\n", This, hrReason, dwOptions);
712 return E_NOTIMPL;
715 static HRESULT WINAPI ResProtocol_Terminate(IInternetProtocol *iface, DWORD dwOptions)
717 ResProtocol *This = ResProtocol_from_IInternetProtocol(iface);
719 TRACE("(%p)->(%08x)\n", This, dwOptions);
721 /* test show that we don't have to do anything here */
722 return S_OK;
725 static HRESULT WINAPI ResProtocol_Suspend(IInternetProtocol *iface)
727 ResProtocol *This = ResProtocol_from_IInternetProtocol(iface);
728 FIXME("(%p)\n", This);
729 return E_NOTIMPL;
732 static HRESULT WINAPI ResProtocol_Resume(IInternetProtocol *iface)
734 ResProtocol *This = ResProtocol_from_IInternetProtocol(iface);
735 FIXME("(%p)\n", This);
736 return E_NOTIMPL;
739 static HRESULT WINAPI ResProtocol_Read(IInternetProtocol *iface, void* pv, ULONG cb, ULONG* pcbRead)
741 ResProtocol *This = ResProtocol_from_IInternetProtocol(iface);
743 TRACE("(%p)->(%p %u %p)\n", This, pv, cb, pcbRead);
745 if(!This->data)
746 return E_FAIL;
748 *pcbRead = (cb > This->data_len-This->cur ? This->data_len-This->cur : cb);
750 if(!*pcbRead)
751 return S_FALSE;
753 memcpy(pv, This->data+This->cur, *pcbRead);
754 This->cur += *pcbRead;
756 return S_OK;
759 static HRESULT WINAPI ResProtocol_Seek(IInternetProtocol *iface, LARGE_INTEGER dlibMove,
760 DWORD dwOrigin, ULARGE_INTEGER* plibNewPosition)
762 ResProtocol *This = ResProtocol_from_IInternetProtocol(iface);
763 FIXME("(%p)->(%d %d %p)\n", This, dlibMove.u.LowPart, dwOrigin, plibNewPosition);
764 return E_NOTIMPL;
767 static HRESULT WINAPI ResProtocol_LockRequest(IInternetProtocol *iface, DWORD dwOptions)
769 ResProtocol *This = ResProtocol_from_IInternetProtocol(iface);
771 TRACE("(%p)->(%d)\n", This, dwOptions);
773 /* test show that we don't have to do anything here */
774 return S_OK;
777 static HRESULT WINAPI ResProtocol_UnlockRequest(IInternetProtocol *iface)
779 ResProtocol *This = ResProtocol_from_IInternetProtocol(iface);
781 TRACE("(%p)\n", This);
783 /* test show that we don't have to do anything here */
784 return S_OK;
787 static const IInternetProtocolVtbl ResProtocolVtbl = {
788 ResProtocol_QueryInterface,
789 ResProtocol_AddRef,
790 ResProtocol_Release,
791 ResProtocol_Start,
792 ResProtocol_Continue,
793 ResProtocol_Abort,
794 ResProtocol_Terminate,
795 ResProtocol_Suspend,
796 ResProtocol_Resume,
797 ResProtocol_Read,
798 ResProtocol_Seek,
799 ResProtocol_LockRequest,
800 ResProtocol_UnlockRequest
803 static HRESULT WINAPI ResProtocolFactory_CreateInstance(IClassFactory *iface, IUnknown *pUnkOuter,
804 REFIID riid, void **ppv)
806 ResProtocol *ret;
807 HRESULT hres = S_OK;
809 TRACE("(%p)->(%p %s %p)\n", iface, pUnkOuter, debugstr_guid(riid), ppv);
811 ret = heap_alloc(sizeof(ResProtocol));
812 ret->IInternetProtocol_iface.lpVtbl = &ResProtocolVtbl;
813 ret->ref = 0;
814 ret->data = NULL;
815 ret->data_len = 0;
816 ret->cur = 0;
817 ret->pUnkOuter = pUnkOuter;
819 if(pUnkOuter) {
820 ret->ref = 1;
821 if(IsEqualGUID(&IID_IUnknown, riid))
822 *ppv = &ret->IInternetProtocol_iface;
823 else
824 hres = E_FAIL;
825 }else {
826 hres = IInternetProtocol_QueryInterface(&ret->IInternetProtocol_iface, riid, ppv);
829 if(FAILED(hres))
830 heap_free(ret);
832 return hres;
835 static HRESULT WINAPI ResProtocolInfo_ParseUrl(IInternetProtocolInfo *iface, LPCWSTR pwzUrl,
836 PARSEACTION ParseAction, DWORD dwParseFlags, LPWSTR pwzResult, DWORD cchResult,
837 DWORD* pcchResult, DWORD dwReserved)
839 TRACE("%p)->(%s %d %x %p %d %p %d)\n", iface, debugstr_w(pwzUrl), ParseAction,
840 dwParseFlags, pwzResult, cchResult, pcchResult, dwReserved);
842 if(ParseAction == PARSE_SECURITY_URL) {
843 WCHAR file_part[MAX_PATH], full_path[MAX_PATH];
844 WCHAR *ptr;
845 DWORD size, len;
847 static const WCHAR wszFile[] = {'f','i','l','e',':','/','/'};
848 static const WCHAR wszRes[] = {'r','e','s',':','/','/'};
850 if(strlenW(pwzUrl) <= sizeof(wszRes)/sizeof(WCHAR) || memcmp(pwzUrl, wszRes, sizeof(wszRes)))
851 return E_INVALIDARG;
853 ptr = strchrW(pwzUrl + sizeof(wszRes)/sizeof(WCHAR), '/');
854 if(!ptr)
855 return E_INVALIDARG;
857 len = ptr - (pwzUrl + sizeof(wszRes)/sizeof(WCHAR));
858 if(len >= sizeof(file_part)/sizeof(WCHAR)) {
859 FIXME("Too long URL\n");
860 return MK_E_SYNTAX;
863 memcpy(file_part, pwzUrl + sizeof(wszRes)/sizeof(WCHAR), len*sizeof(WCHAR));
864 file_part[len] = 0;
866 len = SearchPathW(NULL, file_part, NULL, sizeof(full_path)/sizeof(WCHAR), full_path, NULL);
867 if(!len) {
868 WARN("Could not find file %s\n", debugstr_w(file_part));
869 return MK_E_SYNTAX;
872 size = sizeof(wszFile)/sizeof(WCHAR) + len + 1;
873 if(pcchResult)
874 *pcchResult = size;
875 if(size > cchResult)
876 return S_FALSE;
878 memcpy(pwzResult, wszFile, sizeof(wszFile));
879 memcpy(pwzResult + sizeof(wszFile)/sizeof(WCHAR), full_path, (len+1)*sizeof(WCHAR));
880 return S_OK;
883 if(ParseAction == PARSE_DOMAIN) {
884 if(!pcchResult)
885 return E_POINTER;
887 if(pwzUrl)
888 *pcchResult = strlenW(pwzUrl)+1;
889 else
890 *pcchResult = 1;
891 return E_FAIL;
894 return INET_E_DEFAULT_ACTION;
897 static HRESULT WINAPI ResProtocolInfo_QueryInfo(IInternetProtocolInfo *iface, LPCWSTR pwzUrl,
898 QUERYOPTION QueryOption, DWORD dwQueryFlags, LPVOID pBuffer, DWORD cbBuffer, DWORD* pcbBuf,
899 DWORD dwReserved)
901 TRACE("%p)->(%s %08x %08x %p %d %p %d)\n", iface, debugstr_w(pwzUrl), QueryOption, dwQueryFlags, pBuffer,
902 cbBuffer, pcbBuf, dwReserved);
904 switch(QueryOption) {
905 case QUERY_USES_NETWORK:
906 if(!pBuffer || cbBuffer < sizeof(DWORD))
907 return E_FAIL;
909 *(DWORD*)pBuffer = 0;
910 if(pcbBuf)
911 *pcbBuf = sizeof(DWORD);
912 break;
914 case QUERY_IS_SECURE:
915 FIXME("not supporte QUERY_IS_SECURE\n");
916 return E_NOTIMPL;
917 case QUERY_IS_SAFE:
918 FIXME("not supporte QUERY_IS_SAFE\n");
919 return E_NOTIMPL;
920 default:
921 return INET_E_USE_DEFAULT_PROTOCOLHANDLER;
924 return S_OK;
927 static const IInternetProtocolInfoVtbl ResProtocolInfoVtbl = {
928 InternetProtocolInfo_QueryInterface,
929 InternetProtocolInfo_AddRef,
930 InternetProtocolInfo_Release,
931 ResProtocolInfo_ParseUrl,
932 InternetProtocolInfo_CombineUrl,
933 InternetProtocolInfo_CompareUrl,
934 ResProtocolInfo_QueryInfo
937 static const IClassFactoryVtbl ResProtocolFactoryVtbl = {
938 ClassFactory_QueryInterface,
939 ClassFactory_AddRef,
940 ClassFactory_Release,
941 ResProtocolFactory_CreateInstance,
942 ClassFactory_LockServer
945 static ProtocolFactory ResProtocolFactory = {
946 { &ResProtocolInfoVtbl },
947 { &ResProtocolFactoryVtbl }
950 /********************************************************************
951 * JSProtocol implementation
954 static HRESULT WINAPI JSProtocolFactory_CreateInstance(IClassFactory *iface, IUnknown *pUnkOuter,
955 REFIID riid, void **ppv)
957 FIXME("(%p)->(%p %s %p)\n", iface, pUnkOuter, debugstr_guid(riid), ppv);
958 return E_NOTIMPL;
961 static HRESULT WINAPI JSProtocolInfo_ParseUrl(IInternetProtocolInfo *iface, LPCWSTR pwzUrl,
962 PARSEACTION ParseAction, DWORD dwParseFlags, LPWSTR pwzResult, DWORD cchResult,
963 DWORD* pcchResult, DWORD dwReserved)
965 TRACE("%p)->(%s %d %x %p %d %p %d)\n", iface, debugstr_w(pwzUrl), ParseAction,
966 dwParseFlags, pwzResult, cchResult, pcchResult, dwReserved);
968 switch(ParseAction) {
969 case PARSE_SECURITY_URL:
970 FIXME("PARSE_SECURITY_URL\n");
971 return E_NOTIMPL;
972 case PARSE_DOMAIN:
973 FIXME("PARSE_DOMAIN\n");
974 return E_NOTIMPL;
975 default:
976 return INET_E_DEFAULT_ACTION;
979 return S_OK;
982 static HRESULT WINAPI JSProtocolInfo_QueryInfo(IInternetProtocolInfo *iface, LPCWSTR pwzUrl,
983 QUERYOPTION QueryOption, DWORD dwQueryFlags, LPVOID pBuffer, DWORD cbBuffer, DWORD* pcbBuf,
984 DWORD dwReserved)
986 TRACE("%p)->(%s %08x %08x %p %d %p %d)\n", iface, debugstr_w(pwzUrl), QueryOption, dwQueryFlags, pBuffer,
987 cbBuffer, pcbBuf, dwReserved);
989 switch(QueryOption) {
990 case QUERY_USES_NETWORK:
991 if(!pBuffer || cbBuffer < sizeof(DWORD))
992 return E_FAIL;
994 *(DWORD*)pBuffer = 0;
995 if(pcbBuf)
996 *pcbBuf = sizeof(DWORD);
997 break;
999 case QUERY_IS_SECURE:
1000 FIXME("not supporte QUERY_IS_SECURE\n");
1001 return E_NOTIMPL;
1003 default:
1004 return INET_E_USE_DEFAULT_PROTOCOLHANDLER;
1007 return S_OK;
1010 static const IInternetProtocolInfoVtbl JSProtocolInfoVtbl = {
1011 InternetProtocolInfo_QueryInterface,
1012 InternetProtocolInfo_AddRef,
1013 InternetProtocolInfo_Release,
1014 JSProtocolInfo_ParseUrl,
1015 InternetProtocolInfo_CombineUrl,
1016 InternetProtocolInfo_CompareUrl,
1017 JSProtocolInfo_QueryInfo
1020 static const IClassFactoryVtbl JSProtocolFactoryVtbl = {
1021 ClassFactory_QueryInterface,
1022 ClassFactory_AddRef,
1023 ClassFactory_Release,
1024 JSProtocolFactory_CreateInstance,
1025 ClassFactory_LockServer
1028 static ProtocolFactory JSProtocolFactory = {
1029 { &JSProtocolInfoVtbl },
1030 { &JSProtocolFactoryVtbl }
1033 HRESULT ProtocolFactory_Create(REFCLSID rclsid, REFIID riid, void **ppv)
1035 ProtocolFactory *cf = NULL;
1037 if(IsEqualGUID(&CLSID_AboutProtocol, rclsid))
1038 cf = &AboutProtocolFactory;
1039 else if(IsEqualGUID(&CLSID_ResProtocol, rclsid))
1040 cf = &ResProtocolFactory;
1041 else if(IsEqualGUID(&CLSID_JSProtocol, rclsid))
1042 cf = &JSProtocolFactory;
1044 if(!cf) {
1045 FIXME("not implemented protocol %s\n", debugstr_guid(rclsid));
1046 return CLASS_E_CLASSNOTAVAILABLE;
1049 return IInternetProtocolInfo_QueryInterface(&cf->IInternetProtocolInfo_iface, riid, ppv);