push b79aff4f9e064e6702329573e5ebb8548e254b61
[wine/hacks.git] / dlls / mshtml / protocol.c
blobc87f42e61f6828781b1adf1961b4b071ab94d363
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 #define PROTOCOLINFO(x) ((IInternetProtocolInfo*) &(x)->lpInternetProtocolInfoVtbl)
43 #define CLASSFACTORY(x) ((IClassFactory*) &(x)->lpClassFactoryVtbl)
44 #define PROTOCOL(x) ((IInternetProtocol*) &(x)->lpInternetProtocolVtbl)
46 typedef struct {
47 const IInternetProtocolInfoVtbl *lpInternetProtocolInfoVtbl;
48 const IClassFactoryVtbl *lpClassFactoryVtbl;
49 } ProtocolFactory;
51 #define PROTOCOLINFO_THIS(iface) DEFINE_THIS(ProtocolFactory, InternetProtocolInfo, iface)
53 static HRESULT WINAPI InternetProtocolInfo_QueryInterface(IInternetProtocolInfo *iface, REFIID riid, void **ppv)
55 ProtocolFactory *This = PROTOCOLINFO_THIS(iface);
57 *ppv = NULL;
58 if(IsEqualGUID(&IID_IUnknown, riid)) {
59 TRACE("(%p)->(IID_IUnknown %p)\n", This, ppv);
60 *ppv = PROTOCOLINFO(This);
61 }else if(IsEqualGUID(&IID_IInternetProtocolInfo, riid)) {
62 TRACE("(%p)->(IID_IInternetProtocolInfo %p)\n", This, ppv);
63 *ppv = PROTOCOLINFO(This);
64 }else if(IsEqualGUID(&IID_IClassFactory, riid)) {
65 TRACE("(%p)->(IID_IClassFactory %p)\n", This, ppv);
66 *ppv = CLASSFACTORY(This);
69 if(!*ppv) {
70 WARN("unknown interface %s\n", debugstr_guid(riid));
71 return E_NOINTERFACE;
74 IInternetProtocolInfo_AddRef(iface);
75 return S_OK;
78 static ULONG WINAPI InternetProtocolInfo_AddRef(IInternetProtocolInfo *iface)
80 ProtocolFactory *This = PROTOCOLINFO_THIS(iface);
81 TRACE("(%p)\n", This);
82 LOCK_MODULE();
83 return 2;
86 static ULONG WINAPI InternetProtocolInfo_Release(IInternetProtocolInfo *iface)
88 ProtocolFactory *This = PROTOCOLINFO_THIS(iface);
89 TRACE("(%p)\n", This);
90 UNLOCK_MODULE();
91 return 1;
94 static HRESULT WINAPI InternetProtocolInfo_CombineUrl(IInternetProtocolInfo *iface,
95 LPCWSTR pwzBaseUrl, LPCWSTR pwzRelativeUrl, DWORD dwCombineFlags, LPWSTR pwzResult,
96 DWORD cchResult, DWORD* pcchResult, DWORD dwReserved)
98 TRACE("%p)->(%s %s %08x %p %d %p %d)\n", iface, debugstr_w(pwzBaseUrl),
99 debugstr_w(pwzRelativeUrl), dwCombineFlags, pwzResult, cchResult,
100 pcchResult, dwReserved);
102 return INET_E_USE_DEFAULT_PROTOCOLHANDLER;
105 static HRESULT WINAPI InternetProtocolInfo_CompareUrl(IInternetProtocolInfo *iface, LPCWSTR pwzUrl1,
106 LPCWSTR pwzUrl2, DWORD dwCompareFlags)
108 TRACE("%p)->(%s %s %08x)\n", iface, debugstr_w(pwzUrl1), debugstr_w(pwzUrl2), dwCompareFlags);
109 return E_NOTIMPL;
112 #undef PROTOCOLINFO_THIS
114 #define CLASSFACTORY_THIS(iface) DEFINE_THIS(ProtocolFactory, ClassFactory, iface)
116 static HRESULT WINAPI ClassFactory_QueryInterface(IClassFactory *iface, REFIID riid, void **ppv)
118 ProtocolFactory *This = CLASSFACTORY_THIS(iface);
119 return IInternetProtocolInfo_QueryInterface(PROTOCOLINFO(This), riid, ppv);
122 static ULONG WINAPI ClassFactory_AddRef(IClassFactory *iface)
124 ProtocolFactory *This = CLASSFACTORY_THIS(iface);
125 return IInternetProtocolInfo_AddRef(PROTOCOLINFO(This));
128 static ULONG WINAPI ClassFactory_Release(IClassFactory *iface)
130 ProtocolFactory *This = CLASSFACTORY_THIS(iface);
131 return IInternetProtocolInfo_Release(PROTOCOLINFO(This));
134 static HRESULT WINAPI ClassFactory_LockServer(IClassFactory *iface, BOOL dolock)
136 ProtocolFactory *This = CLASSFACTORY_THIS(iface);
138 TRACE("(%p)->(%x)\n", This, dolock);
140 if(dolock)
141 LOCK_MODULE();
142 else
143 UNLOCK_MODULE();
145 return S_OK;
148 #undef CLASSFACTORY_THIS
150 /********************************************************************
151 * AboutProtocol implementation
154 typedef struct {
155 const IInternetProtocolVtbl *lpInternetProtocolVtbl;
157 LONG ref;
159 BYTE *data;
160 ULONG data_len;
161 ULONG cur;
163 IUnknown *pUnkOuter;
164 } AboutProtocol;
166 #define PROTOCOL_THIS(iface) DEFINE_THIS(AboutProtocol, InternetProtocol, iface)
168 static HRESULT WINAPI AboutProtocol_QueryInterface(IInternetProtocol *iface, REFIID riid, void **ppv)
170 AboutProtocol *This = PROTOCOL_THIS(iface);
172 *ppv = NULL;
174 if(IsEqualGUID(&IID_IUnknown, riid)) {
175 TRACE("(%p)->(IID_IUnknown %p)\n", iface, ppv);
176 if(This->pUnkOuter)
177 return IUnknown_QueryInterface(This->pUnkOuter, riid, ppv);
178 *ppv = PROTOCOL(This);
179 }else if(IsEqualGUID(&IID_IInternetProtocolRoot, riid)) {
180 TRACE("(%p)->(IID_IInternetProtocolRoot %p)\n", iface, ppv);
181 *ppv = PROTOCOL(This);
182 }else if(IsEqualGUID(&IID_IInternetProtocol, riid)) {
183 TRACE("(%p)->(IID_IInternetProtocol %p)\n", iface, ppv);
184 *ppv = PROTOCOL(This);
185 }else if(IsEqualGUID(&IID_IServiceProvider, riid)) {
186 FIXME("IServiceProvider is not implemented\n");
187 return E_NOINTERFACE;
190 if(!*ppv) {
191 TRACE("unknown interface %s\n", debugstr_guid(riid));
192 return E_NOINTERFACE;
195 IInternetProtocol_AddRef(iface);
196 return S_OK;
199 static ULONG WINAPI AboutProtocol_AddRef(IInternetProtocol *iface)
201 AboutProtocol *This = PROTOCOL_THIS(iface);
202 ULONG ref = InterlockedIncrement(&This->ref);
203 TRACE("(%p) ref=%d\n", iface, ref);
204 return This->pUnkOuter ? IUnknown_AddRef(This->pUnkOuter) : ref;
207 static ULONG WINAPI AboutProtocol_Release(IInternetProtocol *iface)
209 AboutProtocol *This = PROTOCOL_THIS(iface);
210 IUnknown *pUnkOuter = This->pUnkOuter;
211 ULONG ref = InterlockedDecrement(&This->ref);
213 TRACE("(%p) ref=%x\n", iface, ref);
215 if(!ref) {
216 mshtml_free(This->data);
217 mshtml_free(This);
218 UNLOCK_MODULE();
221 return pUnkOuter ? IUnknown_Release(pUnkOuter) : ref;
224 static HRESULT WINAPI AboutProtocol_Start(IInternetProtocol *iface, LPCWSTR szUrl,
225 IInternetProtocolSink* pOIProtSink, IInternetBindInfo* pOIBindInfo,
226 DWORD grfPI, DWORD dwReserved)
228 AboutProtocol *This = PROTOCOL_THIS(iface);
229 BINDINFO bindinfo;
230 DWORD grfBINDF = 0;
231 LPCWSTR text = NULL;
233 static const WCHAR html_begin[] = {0xfeff,'<','H','T','M','L','>',0};
234 static const WCHAR html_end[] = {'<','/','H','T','M','L','>',0};
235 static const WCHAR wszBlank[] = {'b','l','a','n','k',0};
236 static const WCHAR wszAbout[] = {'a','b','o','u','t',':'};
237 static const WCHAR wszTextHtml[] = {'t','e','x','t','/','h','t','m','l',0};
239 /* NOTE:
240 * the about protocol seems not to work as I would expect. It creates html document
241 * for a given url, eg. about:some_text -> <HTML>some_text</HTML> except for the case when
242 * some_text = "blank", when document is blank (<HTML></HMTL>). The same happens
243 * when the url does not have "about:" in the beginning.
246 TRACE("(%p)->(%s %p %p %08x %d)\n", This, debugstr_w(szUrl), pOIProtSink,
247 pOIBindInfo, grfPI, dwReserved);
249 memset(&bindinfo, 0, sizeof(bindinfo));
250 bindinfo.cbSize = sizeof(BINDINFO);
251 IInternetBindInfo_GetBindInfo(pOIBindInfo, &grfBINDF, &bindinfo);
252 ReleaseBindInfo(&bindinfo);
254 if(strlenW(szUrl)>=sizeof(wszAbout)/sizeof(WCHAR) && !memcmp(wszAbout, szUrl, sizeof(wszAbout))) {
255 text = szUrl + sizeof(wszAbout)/sizeof(WCHAR);
256 if(!strcmpW(wszBlank, text))
257 text = NULL;
260 This->data_len = sizeof(html_begin)+sizeof(html_end)-sizeof(WCHAR)
261 + (text ? strlenW(text)*sizeof(WCHAR) : 0);
262 This->data = mshtml_alloc(This->data_len);
264 memcpy(This->data, html_begin, sizeof(html_begin));
265 if(text)
266 strcatW((LPWSTR)This->data, text);
267 strcatW((LPWSTR)This->data, html_end);
269 This->cur = 0;
271 IInternetProtocolSink_ReportProgress(pOIProtSink, BINDSTATUS_MIMETYPEAVAILABLE, wszTextHtml);
273 IInternetProtocolSink_ReportData(pOIProtSink,
274 BSCF_FIRSTDATANOTIFICATION | BSCF_LASTDATANOTIFICATION | BSCF_DATAFULLYAVAILABLE,
275 This->data_len, This->data_len);
277 IInternetProtocolSink_ReportResult(pOIProtSink, S_OK, 0, NULL);
279 return S_OK;
282 static HRESULT WINAPI AboutProtocol_Continue(IInternetProtocol *iface, PROTOCOLDATA* pProtocolData)
284 AboutProtocol *This = PROTOCOL_THIS(iface);
285 FIXME("(%p)->(%p)\n", This, pProtocolData);
286 return E_NOTIMPL;
289 static HRESULT WINAPI AboutProtocol_Abort(IInternetProtocol *iface, HRESULT hrReason,
290 DWORD dwOptions)
292 AboutProtocol *This = PROTOCOL_THIS(iface);
293 FIXME("(%p)->(%08x %08x)\n", This, hrReason, dwOptions);
294 return E_NOTIMPL;
297 static HRESULT WINAPI AboutProtocol_Terminate(IInternetProtocol *iface, DWORD dwOptions)
299 AboutProtocol *This = PROTOCOL_THIS(iface);
300 TRACE("(%p)->(%08x)\n", This, dwOptions);
301 return S_OK;
304 static HRESULT WINAPI AboutProtocol_Suspend(IInternetProtocol *iface)
306 AboutProtocol *This = PROTOCOL_THIS(iface);
307 FIXME("(%p)\n", This);
308 return E_NOTIMPL;
311 static HRESULT WINAPI AboutProtocol_Resume(IInternetProtocol *iface)
313 AboutProtocol *This = PROTOCOL_THIS(iface);
314 FIXME("(%p)\n", This);
315 return E_NOTIMPL;
318 static HRESULT WINAPI AboutProtocol_Read(IInternetProtocol *iface, void* pv, ULONG cb, ULONG* pcbRead)
320 AboutProtocol *This = PROTOCOL_THIS(iface);
322 TRACE("(%p)->(%p %u %p)\n", This, pv, cb, pcbRead);
324 if(!This->data)
325 return E_FAIL;
327 *pcbRead = (cb > This->data_len-This->cur ? This->data_len-This->cur : cb);
329 if(!*pcbRead)
330 return S_FALSE;
332 memcpy(pv, This->data, *pcbRead);
333 This->cur += *pcbRead;
335 return S_OK;
338 static HRESULT WINAPI AboutProtocol_Seek(IInternetProtocol *iface, LARGE_INTEGER dlibMove,
339 DWORD dwOrigin, ULARGE_INTEGER* plibNewPosition)
341 AboutProtocol *This = PROTOCOL_THIS(iface);
342 FIXME("(%p)->(%d %d %p)\n", This, dlibMove.u.LowPart, dwOrigin, plibNewPosition);
343 return E_NOTIMPL;
346 static HRESULT WINAPI AboutProtocol_LockRequest(IInternetProtocol *iface, DWORD dwOptions)
348 AboutProtocol *This = PROTOCOL_THIS(iface);
350 TRACE("(%p)->(%d)\n", This, dwOptions);
352 return S_OK;
355 static HRESULT WINAPI AboutProtocol_UnlockRequest(IInternetProtocol *iface)
357 AboutProtocol *This = PROTOCOL_THIS(iface);
359 TRACE("(%p)\n", This);
361 return S_OK;
364 #undef PROTOCOL_THIS
366 static const IInternetProtocolVtbl AboutProtocolVtbl = {
367 AboutProtocol_QueryInterface,
368 AboutProtocol_AddRef,
369 AboutProtocol_Release,
370 AboutProtocol_Start,
371 AboutProtocol_Continue,
372 AboutProtocol_Abort,
373 AboutProtocol_Terminate,
374 AboutProtocol_Suspend,
375 AboutProtocol_Resume,
376 AboutProtocol_Read,
377 AboutProtocol_Seek,
378 AboutProtocol_LockRequest,
379 AboutProtocol_UnlockRequest
382 static HRESULT WINAPI AboutProtocolFactory_CreateInstance(IClassFactory *iface, IUnknown *pUnkOuter,
383 REFIID riid, void **ppv)
385 AboutProtocol *ret;
386 HRESULT hres = S_OK;
388 TRACE("(%p)->(%p %s %p)\n", iface, pUnkOuter, debugstr_guid(riid), ppv);
390 ret = mshtml_alloc(sizeof(AboutProtocol));
391 ret->lpInternetProtocolVtbl = &AboutProtocolVtbl;
392 ret->ref = 0;
394 ret->data = NULL;
395 ret->data_len = 0;
396 ret->cur = 0;
397 ret->pUnkOuter = pUnkOuter;
399 if(pUnkOuter) {
400 ret->ref = 1;
401 if(IsEqualGUID(&IID_IUnknown, riid))
402 *ppv = PROTOCOL(ret);
403 else
404 hres = E_INVALIDARG;
405 }else {
406 hres = IInternetProtocol_QueryInterface(PROTOCOL(ret), riid, ppv);
409 if(SUCCEEDED(hres))
410 LOCK_MODULE();
411 else
412 mshtml_free(ret);
414 return hres;
417 static HRESULT WINAPI AboutProtocolInfo_ParseUrl(IInternetProtocolInfo *iface, LPCWSTR pwzUrl,
418 PARSEACTION ParseAction, DWORD dwParseFlags, LPWSTR pwzResult, DWORD cchResult,
419 DWORD* pcchResult, DWORD dwReserved)
421 TRACE("%p)->(%s %08x %08x %p %d %p %d)\n", iface, debugstr_w(pwzUrl), ParseAction,
422 dwParseFlags, pwzResult, cchResult, pcchResult, dwReserved);
424 if(ParseAction == PARSE_SECURITY_URL) {
425 int len = lstrlenW(pwzUrl);
427 if(len >= cchResult)
428 return S_FALSE;
430 memcpy(pwzResult, pwzUrl, (len+1)*sizeof(WCHAR));
431 return S_OK;
434 if(ParseAction == PARSE_DOMAIN) {
435 if(!pcchResult)
436 return E_POINTER;
438 if(pwzUrl)
439 *pcchResult = strlenW(pwzUrl)+1;
440 else
441 *pcchResult = 1;
442 return E_FAIL;
445 return INET_E_DEFAULT_ACTION;
448 static HRESULT WINAPI AboutProtocolInfo_QueryInfo(IInternetProtocolInfo *iface, LPCWSTR pwzUrl,
449 QUERYOPTION QueryOption, DWORD dwQueryFlags, LPVOID pBuffer, DWORD cbBuffer, DWORD* pcbBuf,
450 DWORD dwReserved)
452 FIXME("%p)->(%s %08x %08x %p %d %p %d)\n", iface, debugstr_w(pwzUrl), QueryOption, dwQueryFlags, pBuffer,
453 cbBuffer, pcbBuf, dwReserved);
454 return E_NOTIMPL;
457 static const IInternetProtocolInfoVtbl AboutProtocolInfoVtbl = {
458 InternetProtocolInfo_QueryInterface,
459 InternetProtocolInfo_AddRef,
460 InternetProtocolInfo_Release,
461 AboutProtocolInfo_ParseUrl,
462 InternetProtocolInfo_CombineUrl,
463 InternetProtocolInfo_CompareUrl,
464 AboutProtocolInfo_QueryInfo
467 static const IClassFactoryVtbl AboutProtocolFactoryVtbl = {
468 ClassFactory_QueryInterface,
469 ClassFactory_AddRef,
470 ClassFactory_Release,
471 AboutProtocolFactory_CreateInstance,
472 ClassFactory_LockServer
475 static ProtocolFactory AboutProtocolFactory = {
476 &AboutProtocolInfoVtbl,
477 &AboutProtocolFactoryVtbl
480 /********************************************************************
481 * ResProtocol implementation
484 typedef struct {
485 const IInternetProtocolVtbl *lpInternetProtocolVtbl;
486 LONG ref;
488 BYTE *data;
489 ULONG data_len;
490 ULONG cur;
492 IUnknown *pUnkOuter;
493 } ResProtocol;
495 #define PROTOCOL_THIS(iface) DEFINE_THIS(ResProtocol, InternetProtocol, iface)
497 static HRESULT WINAPI ResProtocol_QueryInterface(IInternetProtocol *iface, REFIID riid, void **ppv)
499 ResProtocol *This = PROTOCOL_THIS(iface);
501 *ppv = NULL;
503 if(IsEqualGUID(&IID_IUnknown, riid)) {
504 TRACE("(%p)->(IID_IUnknown %p)\n", iface, ppv);
505 if(This->pUnkOuter)
506 return IUnknown_QueryInterface(This->pUnkOuter, &IID_IUnknown, ppv);
507 *ppv = PROTOCOL(This);
508 }else if(IsEqualGUID(&IID_IInternetProtocolRoot, riid)) {
509 TRACE("(%p)->(IID_IInternetProtocolRoot %p)\n", iface, ppv);
510 *ppv = PROTOCOL(This);
511 }else if(IsEqualGUID(&IID_IInternetProtocol, riid)) {
512 TRACE("(%p)->(IID_IInternetProtocol %p)\n", iface, ppv);
513 *ppv = PROTOCOL(This);
514 }else if(IsEqualGUID(&IID_IServiceProvider, riid)) {
515 FIXME("IServiceProvider is not implemented\n");
516 return E_NOINTERFACE;
519 if(!*ppv) {
520 TRACE("unknown interface %s\n", debugstr_guid(riid));
521 return E_NOINTERFACE;
524 IInternetProtocol_AddRef(iface);
525 return S_OK;
528 static ULONG WINAPI ResProtocol_AddRef(IInternetProtocol *iface)
530 ResProtocol *This = PROTOCOL_THIS(iface);
531 ULONG ref = InterlockedIncrement(&This->ref);
532 TRACE("(%p) ref=%d\n", iface, ref);
533 return This->pUnkOuter ? IUnknown_AddRef(This->pUnkOuter) : ref;
536 static ULONG WINAPI ResProtocol_Release(IInternetProtocol *iface)
538 ResProtocol *This = (ResProtocol*)iface;
539 IUnknown *pUnkOuter = This->pUnkOuter;
540 ULONG ref = InterlockedDecrement(&This->ref);
542 TRACE("(%p) ref=%x\n", iface, ref);
544 if(!ref) {
545 mshtml_free(This->data);
546 mshtml_free(This);
547 UNLOCK_MODULE();
550 return pUnkOuter ? IUnknown_Release(pUnkOuter) : ref;
553 static HRESULT WINAPI ResProtocol_Start(IInternetProtocol *iface, LPCWSTR szUrl,
554 IInternetProtocolSink* pOIProtSink, IInternetBindInfo* pOIBindInfo,
555 DWORD grfPI, DWORD dwReserved)
557 ResProtocol *This = PROTOCOL_THIS(iface);
558 DWORD grfBINDF = 0, len;
559 BINDINFO bindinfo;
560 LPWSTR url_dll, url_file, url, mime;
561 HMODULE hdll;
562 HRSRC src;
563 HRESULT hres;
565 static const WCHAR wszRes[] = {'r','e','s',':','/','/'};
567 TRACE("(%p)->(%s %p %p %08x %d)\n", This, debugstr_w(szUrl), pOIProtSink,
568 pOIBindInfo, grfPI, dwReserved);
570 memset(&bindinfo, 0, sizeof(bindinfo));
571 bindinfo.cbSize = sizeof(BINDINFO);
572 IInternetBindInfo_GetBindInfo(pOIBindInfo, &grfBINDF, &bindinfo);
573 ReleaseBindInfo(&bindinfo);
575 len = strlenW(szUrl)+16;
576 url = mshtml_alloc(len*sizeof(WCHAR));
577 hres = CoInternetParseUrl(szUrl, PARSE_ENCODE, 0, url, len, &len, 0);
578 if(FAILED(hres)) {
579 WARN("CoInternetParseUrl failed: %08x\n", hres);
580 mshtml_free(url);
581 IInternetProtocolSink_ReportResult(pOIProtSink, hres, 0, NULL);
582 return hres;
585 if(len < sizeof(wszRes)/sizeof(wszRes[0]) || memcmp(url, wszRes, sizeof(wszRes))) {
586 WARN("Wrong protocol of url: %s\n", debugstr_w(url));
587 IInternetProtocolSink_ReportResult(pOIProtSink, E_INVALIDARG, 0, NULL);
588 mshtml_free(url);
589 return E_INVALIDARG;
592 url_dll = url + sizeof(wszRes)/sizeof(wszRes[0]);
593 if(!(url_file = strrchrW(url_dll, '/'))) {
594 WARN("wrong url: %s\n", debugstr_w(url));
595 IInternetProtocolSink_ReportResult(pOIProtSink, MK_E_SYNTAX, 0, NULL);
596 mshtml_free(url);
597 return MK_E_SYNTAX;
600 *url_file++ = 0;
601 hdll = LoadLibraryExW(url_dll, NULL, LOAD_LIBRARY_AS_DATAFILE);
602 if(!hdll) {
603 WARN("Could not open dll: %s\n", debugstr_w(url_dll));
604 IInternetProtocolSink_ReportResult(pOIProtSink, HRESULT_FROM_WIN32(GetLastError()), 0, NULL);
605 mshtml_free(url);
606 return HRESULT_FROM_WIN32(GetLastError());
609 src = FindResourceW(hdll, url_file, (LPCWSTR)RT_HTML);
610 if(!src) {
611 LPWSTR endpoint = NULL;
612 DWORD file_id = strtolW(url_file, &endpoint, 10);
613 if(endpoint == url_file+strlenW(url_file))
614 src = FindResourceW(hdll, (LPCWSTR)file_id, (LPCWSTR)RT_HTML);
616 if(!src) {
617 WARN("Could not find resource\n");
618 IInternetProtocolSink_ReportResult(pOIProtSink,
619 HRESULT_FROM_WIN32(GetLastError()), 0, NULL);
620 mshtml_free(url);
621 return HRESULT_FROM_WIN32(GetLastError());
625 if(This->data) {
626 WARN("data already loaded\n");
627 mshtml_free(This->data);
630 This->data_len = SizeofResource(hdll, src);
631 This->data = mshtml_alloc(This->data_len);
632 memcpy(This->data, LoadResource(hdll, src), This->data_len);
633 This->cur = 0;
635 FreeLibrary(hdll);
637 hres = FindMimeFromData(NULL, url_file, NULL, 0, NULL, 0, &mime, 0);
638 mshtml_free(url);
639 if(SUCCEEDED(hres)) {
640 IInternetProtocolSink_ReportProgress(pOIProtSink, BINDSTATUS_MIMETYPEAVAILABLE, mime);
641 CoTaskMemFree(mime);
644 IInternetProtocolSink_ReportData(pOIProtSink,
645 BSCF_FIRSTDATANOTIFICATION | BSCF_LASTDATANOTIFICATION | BSCF_DATAFULLYAVAILABLE,
646 This->data_len, This->data_len);
648 IInternetProtocolSink_ReportResult(pOIProtSink, S_OK, 0, NULL);
650 return S_OK;
653 static HRESULT WINAPI ResProtocol_Continue(IInternetProtocol *iface, PROTOCOLDATA* pProtocolData)
655 ResProtocol *This = PROTOCOL_THIS(iface);
656 FIXME("(%p)->(%p)\n", This, pProtocolData);
657 return E_NOTIMPL;
660 static HRESULT WINAPI ResProtocol_Abort(IInternetProtocol *iface, HRESULT hrReason,
661 DWORD dwOptions)
663 ResProtocol *This = PROTOCOL_THIS(iface);
664 FIXME("(%p)->(%08x %08x)\n", This, hrReason, dwOptions);
665 return E_NOTIMPL;
668 static HRESULT WINAPI ResProtocol_Terminate(IInternetProtocol *iface, DWORD dwOptions)
670 ResProtocol *This = PROTOCOL_THIS(iface);
672 TRACE("(%p)->(%08x)\n", This, dwOptions);
674 /* test show that we don't have to do anything here */
675 return S_OK;
678 static HRESULT WINAPI ResProtocol_Suspend(IInternetProtocol *iface)
680 ResProtocol *This = PROTOCOL_THIS(iface);
681 FIXME("(%p)\n", This);
682 return E_NOTIMPL;
685 static HRESULT WINAPI ResProtocol_Resume(IInternetProtocol *iface)
687 ResProtocol *This = PROTOCOL_THIS(iface);
688 FIXME("(%p)\n", This);
689 return E_NOTIMPL;
692 static HRESULT WINAPI ResProtocol_Read(IInternetProtocol *iface, void* pv, ULONG cb, ULONG* pcbRead)
694 ResProtocol *This = PROTOCOL_THIS(iface);
696 TRACE("(%p)->(%p %u %p)\n", This, pv, cb, pcbRead);
698 if(!This->data)
699 return E_FAIL;
701 *pcbRead = (cb > This->data_len-This->cur ? This->data_len-This->cur : cb);
703 if(!*pcbRead)
704 return S_FALSE;
706 memcpy(pv, This->data, *pcbRead);
707 This->cur += *pcbRead;
709 return S_OK;
712 static HRESULT WINAPI ResProtocol_Seek(IInternetProtocol *iface, LARGE_INTEGER dlibMove,
713 DWORD dwOrigin, ULARGE_INTEGER* plibNewPosition)
715 ResProtocol *This = PROTOCOL_THIS(iface);
716 FIXME("(%p)->(%d %d %p)\n", This, dlibMove.u.LowPart, dwOrigin, plibNewPosition);
717 return E_NOTIMPL;
720 static HRESULT WINAPI ResProtocol_LockRequest(IInternetProtocol *iface, DWORD dwOptions)
722 ResProtocol *This = PROTOCOL_THIS(iface);
724 TRACE("(%p)->(%d)\n", This, dwOptions);
726 /* test show that we don't have to do anything here */
727 return S_OK;
730 static HRESULT WINAPI ResProtocol_UnlockRequest(IInternetProtocol *iface)
732 ResProtocol *This = PROTOCOL_THIS(iface);
734 TRACE("(%p)\n", This);
736 /* test show that we don't have to do anything here */
737 return S_OK;
740 #undef PROTOCOL_THIS
742 static const IInternetProtocolVtbl ResProtocolVtbl = {
743 ResProtocol_QueryInterface,
744 ResProtocol_AddRef,
745 ResProtocol_Release,
746 ResProtocol_Start,
747 ResProtocol_Continue,
748 ResProtocol_Abort,
749 ResProtocol_Terminate,
750 ResProtocol_Suspend,
751 ResProtocol_Resume,
752 ResProtocol_Read,
753 ResProtocol_Seek,
754 ResProtocol_LockRequest,
755 ResProtocol_UnlockRequest
758 static HRESULT WINAPI ResProtocolFactory_CreateInstance(IClassFactory *iface, IUnknown *pUnkOuter,
759 REFIID riid, void **ppv)
761 ResProtocol *ret;
762 HRESULT hres = S_OK;
764 TRACE("(%p)->(%p %s %p)\n", iface, pUnkOuter, debugstr_guid(riid), ppv);
766 ret = mshtml_alloc(sizeof(ResProtocol));
767 ret->lpInternetProtocolVtbl = &ResProtocolVtbl;
768 ret->ref = 0;
769 ret->data = NULL;
770 ret->data_len = 0;
771 ret->cur = 0;
772 ret->pUnkOuter = pUnkOuter;
774 if(pUnkOuter) {
775 ret->ref = 1;
776 if(IsEqualGUID(&IID_IUnknown, riid))
777 *ppv = PROTOCOL(ret);
778 else
779 hres = E_FAIL;
780 }else {
781 hres = IInternetProtocol_QueryInterface(PROTOCOL(ret), riid, ppv);
784 if(SUCCEEDED(hres))
785 LOCK_MODULE();
786 else
787 mshtml_free(ret);
789 return hres;
792 static HRESULT WINAPI ResProtocolInfo_ParseUrl(IInternetProtocolInfo *iface, LPCWSTR pwzUrl,
793 PARSEACTION ParseAction, DWORD dwParseFlags, LPWSTR pwzResult, DWORD cchResult,
794 DWORD* pcchResult, DWORD dwReserved)
796 TRACE("%p)->(%s %d %x %p %d %p %d)\n", iface, debugstr_w(pwzUrl), ParseAction,
797 dwParseFlags, pwzResult, cchResult, pcchResult, dwReserved);
799 if(ParseAction == PARSE_SECURITY_URL) {
800 WCHAR *ptr;
801 DWORD size;
803 static const WCHAR wszFile[] = {'f','i','l','e',':','/','/'};
804 static const WCHAR wszRes[] = {'r','e','s',':','/','/'};
806 if(strlenW(pwzUrl) <= sizeof(wszRes)/sizeof(WCHAR) || memcmp(pwzUrl, wszRes, sizeof(wszRes)))
807 return E_INVALIDARG;
809 ptr = strchrW(pwzUrl + sizeof(wszRes)/sizeof(WCHAR), '/');
810 if(!ptr)
811 return E_INVALIDARG;
813 size = ptr-pwzUrl + sizeof(wszFile)/sizeof(WCHAR) - sizeof(wszRes)/sizeof(WCHAR);
814 if(size >= cchResult)
815 return S_FALSE;
817 /* FIXME: return full path */
818 memcpy(pwzResult, wszFile, sizeof(wszFile));
819 memcpy(pwzResult + sizeof(wszFile)/sizeof(WCHAR),
820 pwzUrl + sizeof(wszRes)/sizeof(WCHAR),
821 size*sizeof(WCHAR) - sizeof(wszFile));
822 pwzResult[size] = 0;
824 if(pcchResult)
825 *pcchResult = size;
826 return S_OK;
829 if(ParseAction == PARSE_DOMAIN) {
830 if(!pcchResult)
831 return E_POINTER;
833 if(pwzUrl)
834 *pcchResult = strlenW(pwzUrl)+1;
835 else
836 *pcchResult = 1;
837 return E_FAIL;
840 return INET_E_DEFAULT_ACTION;
843 static HRESULT WINAPI ResProtocolInfo_QueryInfo(IInternetProtocolInfo *iface, LPCWSTR pwzUrl,
844 QUERYOPTION QueryOption, DWORD dwQueryFlags, LPVOID pBuffer, DWORD cbBuffer, DWORD* pcbBuf,
845 DWORD dwReserved)
847 FIXME("%p)->(%s %08x %08x %p %d %p %d)\n", iface, debugstr_w(pwzUrl), QueryOption, dwQueryFlags, pBuffer,
848 cbBuffer, pcbBuf, dwReserved);
849 return E_NOTIMPL;
852 static const IInternetProtocolInfoVtbl ResProtocolInfoVtbl = {
853 InternetProtocolInfo_QueryInterface,
854 InternetProtocolInfo_AddRef,
855 InternetProtocolInfo_Release,
856 ResProtocolInfo_ParseUrl,
857 InternetProtocolInfo_CombineUrl,
858 InternetProtocolInfo_CompareUrl,
859 ResProtocolInfo_QueryInfo
862 static const IClassFactoryVtbl ResProtocolFactoryVtbl = {
863 ClassFactory_QueryInterface,
864 ClassFactory_AddRef,
865 ClassFactory_Release,
866 ResProtocolFactory_CreateInstance,
867 ClassFactory_LockServer
870 static ProtocolFactory ResProtocolFactory = {
871 &ResProtocolInfoVtbl,
872 &ResProtocolFactoryVtbl
875 HRESULT ProtocolFactory_Create(REFCLSID rclsid, REFIID riid, void **ppv)
877 ProtocolFactory *cf = NULL;
879 if(IsEqualGUID(&CLSID_AboutProtocol, rclsid))
880 cf = &AboutProtocolFactory;
881 else if(IsEqualGUID(&CLSID_ResProtocol, rclsid))
882 cf = &ResProtocolFactory;
884 if(!cf) {
885 FIXME("not implemented protocol %s\n", debugstr_guid(rclsid));
886 return CLASS_E_CLASSNOTAVAILABLE;
889 return IUnknown_QueryInterface((IUnknown*)cf, riid, ppv);