1c2c66affSColin Finck /*
2c2c66affSColin Finck * Copyright 2006-2007 Jacek Caban for CodeWeavers
3c2c66affSColin Finck *
4c2c66affSColin Finck * This library is free software; you can redistribute it and/or
5c2c66affSColin Finck * modify it under the terms of the GNU Lesser General Public
6c2c66affSColin Finck * License as published by the Free Software Foundation; either
7c2c66affSColin Finck * version 2.1 of the License, or (at your option) any later version.
8c2c66affSColin Finck *
9c2c66affSColin Finck * This library is distributed in the hope that it will be useful,
10c2c66affSColin Finck * but WITHOUT ANY WARRANTY; without even the implied warranty of
11c2c66affSColin Finck * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12c2c66affSColin Finck * Lesser General Public License for more details.
13c2c66affSColin Finck *
14c2c66affSColin Finck * You should have received a copy of the GNU Lesser General Public
15c2c66affSColin Finck * License along with this library; if not, write to the Free Software
16c2c66affSColin Finck * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
17c2c66affSColin Finck */
18c2c66affSColin Finck
19919215fdSAmine Khaldi #include <stdarg.h>
20c2c66affSColin Finck
21919215fdSAmine Khaldi #define COBJMACROS
22919215fdSAmine Khaldi
23919215fdSAmine Khaldi #include "windef.h"
24919215fdSAmine Khaldi #include "winbase.h"
25919215fdSAmine Khaldi #include "winuser.h"
26919215fdSAmine Khaldi #include "winreg.h"
27919215fdSAmine Khaldi #include "ole2.h"
28919215fdSAmine Khaldi #include "urlmon.h"
29919215fdSAmine Khaldi #include "shlwapi.h"
30919215fdSAmine Khaldi #include "itsstor.h"
31919215fdSAmine Khaldi #include "chm_lib.h"
32919215fdSAmine Khaldi
33919215fdSAmine Khaldi #include "wine/debug.h"
34919215fdSAmine Khaldi
35919215fdSAmine Khaldi WINE_DEFAULT_DEBUG_CHANNEL(itss);
36c2c66affSColin Finck
37c2c66affSColin Finck typedef struct {
38e64b0329SAmine Khaldi IUnknown IUnknown_inner;
39c2c66affSColin Finck IInternetProtocol IInternetProtocol_iface;
40c2c66affSColin Finck IInternetProtocolInfo IInternetProtocolInfo_iface;
41c2c66affSColin Finck
42c2c66affSColin Finck LONG ref;
43e64b0329SAmine Khaldi IUnknown *outer;
44c2c66affSColin Finck
45c2c66affSColin Finck ULONG offset;
46c2c66affSColin Finck struct chmFile *chm_file;
47c2c66affSColin Finck struct chmUnitInfo chm_object;
48c2c66affSColin Finck } ITSProtocol;
49c2c66affSColin Finck
impl_from_IUnknown(IUnknown * iface)50e64b0329SAmine Khaldi static inline ITSProtocol *impl_from_IUnknown(IUnknown *iface)
51e64b0329SAmine Khaldi {
52e64b0329SAmine Khaldi return CONTAINING_RECORD(iface, ITSProtocol, IUnknown_inner);
53e64b0329SAmine Khaldi }
54e64b0329SAmine Khaldi
impl_from_IInternetProtocol(IInternetProtocol * iface)55c2c66affSColin Finck static inline ITSProtocol *impl_from_IInternetProtocol(IInternetProtocol *iface)
56c2c66affSColin Finck {
57c2c66affSColin Finck return CONTAINING_RECORD(iface, ITSProtocol, IInternetProtocol_iface);
58c2c66affSColin Finck }
59c2c66affSColin Finck
impl_from_IInternetProtocolInfo(IInternetProtocolInfo * iface)60c2c66affSColin Finck static inline ITSProtocol *impl_from_IInternetProtocolInfo(IInternetProtocolInfo *iface)
61c2c66affSColin Finck {
62c2c66affSColin Finck return CONTAINING_RECORD(iface, ITSProtocol, IInternetProtocolInfo_iface);
63c2c66affSColin Finck }
64c2c66affSColin Finck
release_chm(ITSProtocol * This)65c2c66affSColin Finck static void release_chm(ITSProtocol *This)
66c2c66affSColin Finck {
67c2c66affSColin Finck if(This->chm_file) {
68c2c66affSColin Finck chm_close(This->chm_file);
69c2c66affSColin Finck This->chm_file = NULL;
70c2c66affSColin Finck }
71c2c66affSColin Finck This->offset = 0;
72c2c66affSColin Finck }
73c2c66affSColin Finck
ITSProtocol_QueryInterface(IUnknown * iface,REFIID riid,void ** ppv)74e64b0329SAmine Khaldi static HRESULT WINAPI ITSProtocol_QueryInterface(IUnknown *iface, REFIID riid, void **ppv)
75c2c66affSColin Finck {
76e64b0329SAmine Khaldi ITSProtocol *This = impl_from_IUnknown(iface);
77c2c66affSColin Finck
78c2c66affSColin Finck if(IsEqualGUID(&IID_IUnknown, riid)) {
79c2c66affSColin Finck TRACE("(%p)->(IID_IUnknown %p)\n", This, ppv);
80e64b0329SAmine Khaldi *ppv = &This->IUnknown_inner;
81c2c66affSColin Finck }else if(IsEqualGUID(&IID_IInternetProtocolRoot, riid)) {
82c2c66affSColin Finck TRACE("(%p)->(IID_IInternetProtocolRoot %p)\n", This, ppv);
83c2c66affSColin Finck *ppv = &This->IInternetProtocol_iface;
84c2c66affSColin Finck }else if(IsEqualGUID(&IID_IInternetProtocol, riid)) {
85c2c66affSColin Finck TRACE("(%p)->(IID_IInternetProtocol %p)\n", This, ppv);
86c2c66affSColin Finck *ppv = &This->IInternetProtocol_iface;
87c2c66affSColin Finck }else if(IsEqualGUID(&IID_IInternetProtocolInfo, riid)) {
88c2c66affSColin Finck TRACE("(%p)->(IID_IInternetProtocolInfo %p)\n", This, ppv);
89c2c66affSColin Finck *ppv = &This->IInternetProtocolInfo_iface;
90e64b0329SAmine Khaldi }else {
91e64b0329SAmine Khaldi *ppv = NULL;
92c2c66affSColin Finck WARN("not supported interface %s\n", debugstr_guid(riid));
93c2c66affSColin Finck return E_NOINTERFACE;
94c2c66affSColin Finck }
95c2c66affSColin Finck
96e64b0329SAmine Khaldi IUnknown_AddRef((IUnknown*)*ppv);
97e64b0329SAmine Khaldi return S_OK;
98e64b0329SAmine Khaldi }
99e64b0329SAmine Khaldi
ITSProtocol_AddRef(IUnknown * iface)100e64b0329SAmine Khaldi static ULONG WINAPI ITSProtocol_AddRef(IUnknown *iface)
101c2c66affSColin Finck {
102e64b0329SAmine Khaldi ITSProtocol *This = impl_from_IUnknown(iface);
103c2c66affSColin Finck LONG ref = InterlockedIncrement(&This->ref);
104c2c66affSColin Finck TRACE("(%p) ref=%d\n", This, ref);
105c2c66affSColin Finck return ref;
106c2c66affSColin Finck }
107c2c66affSColin Finck
ITSProtocol_Release(IUnknown * iface)108e64b0329SAmine Khaldi static ULONG WINAPI ITSProtocol_Release(IUnknown *iface)
109c2c66affSColin Finck {
110e64b0329SAmine Khaldi ITSProtocol *This = impl_from_IUnknown(iface);
111c2c66affSColin Finck LONG ref = InterlockedDecrement(&This->ref);
112c2c66affSColin Finck
113c2c66affSColin Finck TRACE("(%p) ref=%d\n", This, ref);
114c2c66affSColin Finck
115c2c66affSColin Finck if(!ref) {
116c2c66affSColin Finck release_chm(This);
117c2c66affSColin Finck HeapFree(GetProcessHeap(), 0, This);
118c2c66affSColin Finck
119c2c66affSColin Finck ITSS_UnlockModule();
120c2c66affSColin Finck }
121c2c66affSColin Finck
122c2c66affSColin Finck return ref;
123c2c66affSColin Finck }
124c2c66affSColin Finck
125e64b0329SAmine Khaldi static const IUnknownVtbl ITSProtocolUnkVtbl = {
126e64b0329SAmine Khaldi ITSProtocol_QueryInterface,
127e64b0329SAmine Khaldi ITSProtocol_AddRef,
128e64b0329SAmine Khaldi ITSProtocol_Release
129e64b0329SAmine Khaldi };
130e64b0329SAmine Khaldi
ITSInternetProtocol_QueryInterface(IInternetProtocol * iface,REFIID riid,void ** ppv)131e64b0329SAmine Khaldi static HRESULT WINAPI ITSInternetProtocol_QueryInterface(IInternetProtocol *iface, REFIID riid, void **ppv)
132e64b0329SAmine Khaldi {
133e64b0329SAmine Khaldi ITSProtocol *This = impl_from_IInternetProtocol(iface);
134e64b0329SAmine Khaldi return IUnknown_QueryInterface(This->outer, riid, ppv);
135e64b0329SAmine Khaldi }
136e64b0329SAmine Khaldi
ITSInternetProtocol_AddRef(IInternetProtocol * iface)137e64b0329SAmine Khaldi static ULONG WINAPI ITSInternetProtocol_AddRef(IInternetProtocol *iface)
138e64b0329SAmine Khaldi {
139e64b0329SAmine Khaldi ITSProtocol *This = impl_from_IInternetProtocol(iface);
140e64b0329SAmine Khaldi return IUnknown_AddRef(This->outer);
141e64b0329SAmine Khaldi }
142e64b0329SAmine Khaldi
ITSInternetProtocol_Release(IInternetProtocol * iface)143e64b0329SAmine Khaldi static ULONG WINAPI ITSInternetProtocol_Release(IInternetProtocol *iface)
144e64b0329SAmine Khaldi {
145e64b0329SAmine Khaldi ITSProtocol *This = impl_from_IInternetProtocol(iface);
146e64b0329SAmine Khaldi return IUnknown_Release(This->outer);
147e64b0329SAmine Khaldi }
148e64b0329SAmine Khaldi
skip_schema(LPCWSTR url)149c2c66affSColin Finck static LPCWSTR skip_schema(LPCWSTR url)
150c2c66affSColin Finck {
151c2c66affSColin Finck static const WCHAR its_schema[] = {'i','t','s',':'};
152c2c66affSColin Finck static const WCHAR msits_schema[] = {'m','s','-','i','t','s',':'};
153c2c66affSColin Finck static const WCHAR mk_schema[] = {'m','k',':','@','M','S','I','T','S','t','o','r','e',':'};
154c2c66affSColin Finck
155*da0cd273SAmine Khaldi if(!_wcsnicmp(its_schema, url, ARRAY_SIZE(its_schema)))
1560ccdd32fSAmine Khaldi return url + ARRAY_SIZE(its_schema);
157*da0cd273SAmine Khaldi if(!_wcsnicmp(msits_schema, url, ARRAY_SIZE(msits_schema)))
1580ccdd32fSAmine Khaldi return url + ARRAY_SIZE(msits_schema);
159*da0cd273SAmine Khaldi if(!_wcsnicmp(mk_schema, url, ARRAY_SIZE(mk_schema)))
1600ccdd32fSAmine Khaldi return url + ARRAY_SIZE(mk_schema);
161c2c66affSColin Finck
162c2c66affSColin Finck return NULL;
163c2c66affSColin Finck }
164c2c66affSColin Finck
165c2c66affSColin Finck /* Adopted from urlmon */
remove_dot_segments(WCHAR * path)166c2c66affSColin Finck static void remove_dot_segments(WCHAR *path) {
167c2c66affSColin Finck const WCHAR *in = path;
168c2c66affSColin Finck WCHAR *out = path;
169c2c66affSColin Finck
170c2c66affSColin Finck while(1) {
171c2c66affSColin Finck /* Move the first path segment in the input buffer to the end of
172c2c66affSColin Finck * the output buffer, and any subsequent characters up to, including
173c2c66affSColin Finck * the next "/" character (if any) or the end of the input buffer.
174c2c66affSColin Finck */
175c2c66affSColin Finck while(*in != '/') {
176c2c66affSColin Finck if(!(*out++ = *in++))
177c2c66affSColin Finck return;
178c2c66affSColin Finck }
179c2c66affSColin Finck
180c2c66affSColin Finck *out++ = *in++;
181c2c66affSColin Finck
182c2c66affSColin Finck while(*in) {
183c2c66affSColin Finck if(*in != '.')
184c2c66affSColin Finck break;
185c2c66affSColin Finck
186c2c66affSColin Finck /* Handle ending "/." */
187c2c66affSColin Finck if(!in[1]) {
188c2c66affSColin Finck ++in;
189c2c66affSColin Finck break;
190c2c66affSColin Finck }
191c2c66affSColin Finck
192c2c66affSColin Finck /* Handle "/./" */
193c2c66affSColin Finck if(in[1] == '/') {
194c2c66affSColin Finck in += 2;
195c2c66affSColin Finck continue;
196c2c66affSColin Finck }
197c2c66affSColin Finck
198c2c66affSColin Finck /* If we don't have "/../" or ending "/.." */
199c2c66affSColin Finck if(in[1] != '.' || (in[2] && in[2] != '/'))
200c2c66affSColin Finck break;
201c2c66affSColin Finck
202c2c66affSColin Finck in += *in ? 3 : 2;
203c2c66affSColin Finck
204c2c66affSColin Finck /* Find the slash preceding out pointer and move out pointer to it */
205c2c66affSColin Finck if(out > path+1 && *--out == '/')
206c2c66affSColin Finck --out;
207c2c66affSColin Finck while(out > path && *(--out) != '/');
208c2c66affSColin Finck if(*out == '/')
209c2c66affSColin Finck ++out;
210c2c66affSColin Finck }
211c2c66affSColin Finck }
212c2c66affSColin Finck }
213c2c66affSColin Finck
report_result(IInternetProtocolSink * sink,HRESULT hres)214c2c66affSColin Finck static HRESULT report_result(IInternetProtocolSink *sink, HRESULT hres)
215c2c66affSColin Finck {
216c2c66affSColin Finck IInternetProtocolSink_ReportResult(sink, hres, 0, NULL);
217c2c66affSColin Finck return hres;
218c2c66affSColin Finck }
219c2c66affSColin Finck
ITSProtocol_Start(IInternetProtocol * iface,LPCWSTR szUrl,IInternetProtocolSink * pOIProtSink,IInternetBindInfo * pOIBindInfo,DWORD grfPI,HANDLE_PTR dwReserved)220c2c66affSColin Finck static HRESULT WINAPI ITSProtocol_Start(IInternetProtocol *iface, LPCWSTR szUrl,
221c2c66affSColin Finck IInternetProtocolSink *pOIProtSink, IInternetBindInfo *pOIBindInfo,
222c2c66affSColin Finck DWORD grfPI, HANDLE_PTR dwReserved)
223c2c66affSColin Finck {
224c2c66affSColin Finck ITSProtocol *This = impl_from_IInternetProtocol(iface);
225c2c66affSColin Finck BINDINFO bindinfo;
226c2c66affSColin Finck DWORD bindf = 0, len;
227c2c66affSColin Finck LPWSTR file_name, mime, object_name, p;
228c2c66affSColin Finck LPCWSTR ptr;
229c2c66affSColin Finck struct chmFile *chm_file;
230c2c66affSColin Finck struct chmUnitInfo chm_object;
231c2c66affSColin Finck int res;
232c2c66affSColin Finck HRESULT hres;
233c2c66affSColin Finck
234c2c66affSColin Finck static const WCHAR separator[] = {':',':',0};
235c2c66affSColin Finck
236c2c66affSColin Finck TRACE("(%p)->(%s %p %p %08x %lx)\n", This, debugstr_w(szUrl), pOIProtSink,
237c2c66affSColin Finck pOIBindInfo, grfPI, dwReserved);
238c2c66affSColin Finck
239c2c66affSColin Finck ptr = skip_schema(szUrl);
240c2c66affSColin Finck if(!ptr)
241c2c66affSColin Finck return INET_E_USE_DEFAULT_PROTOCOLHANDLER;
242c2c66affSColin Finck
243c2c66affSColin Finck memset(&bindinfo, 0, sizeof(bindinfo));
244c2c66affSColin Finck bindinfo.cbSize = sizeof(BINDINFO);
245c2c66affSColin Finck hres = IInternetBindInfo_GetBindInfo(pOIBindInfo, &bindf, &bindinfo);
246c2c66affSColin Finck if(FAILED(hres)) {
247c2c66affSColin Finck WARN("GetBindInfo failed: %08x\n", hres);
248c2c66affSColin Finck return hres;
249c2c66affSColin Finck }
250c2c66affSColin Finck
251c2c66affSColin Finck ReleaseBindInfo(&bindinfo);
252c2c66affSColin Finck
253*da0cd273SAmine Khaldi len = lstrlenW(ptr)+3;
254c2c66affSColin Finck file_name = HeapAlloc(GetProcessHeap(), 0, len*sizeof(WCHAR));
255c2c66affSColin Finck memcpy(file_name, ptr, len*sizeof(WCHAR));
256c2c66affSColin Finck hres = UrlUnescapeW(file_name, NULL, &len, URL_UNESCAPE_INPLACE);
257c2c66affSColin Finck if(FAILED(hres)) {
258c2c66affSColin Finck WARN("UrlUnescape failed: %08x\n", hres);
259c2c66affSColin Finck HeapFree(GetProcessHeap(), 0, file_name);
260c2c66affSColin Finck return hres;
261c2c66affSColin Finck }
262c2c66affSColin Finck
263*da0cd273SAmine Khaldi p = wcsstr(file_name, separator);
264c2c66affSColin Finck if(!p) {
265c2c66affSColin Finck WARN("invalid url\n");
266c2c66affSColin Finck HeapFree(GetProcessHeap(), 0, file_name);
267c2c66affSColin Finck return report_result(pOIProtSink, STG_E_FILENOTFOUND);
268c2c66affSColin Finck }
269c2c66affSColin Finck
270c2c66affSColin Finck *p = 0;
271c2c66affSColin Finck chm_file = chm_openW(file_name);
272c2c66affSColin Finck if(!chm_file) {
273c2c66affSColin Finck WARN("Could not open chm file\n");
274c2c66affSColin Finck HeapFree(GetProcessHeap(), 0, file_name);
275c2c66affSColin Finck return report_result(pOIProtSink, STG_E_FILENOTFOUND);
276c2c66affSColin Finck }
277c2c66affSColin Finck
278c2c66affSColin Finck object_name = p+2;
279*da0cd273SAmine Khaldi len = lstrlenW(object_name);
280c2c66affSColin Finck
281c2c66affSColin Finck if(*object_name != '/' && *object_name != '\\') {
282c2c66affSColin Finck memmove(object_name+1, object_name, (len+1)*sizeof(WCHAR));
283c2c66affSColin Finck *object_name = '/';
284c2c66affSColin Finck len++;
285c2c66affSColin Finck }
286c2c66affSColin Finck
287c2c66affSColin Finck if(object_name[len-1] == '/')
288c2c66affSColin Finck object_name[--len] = 0;
289c2c66affSColin Finck
290c2c66affSColin Finck for(p=object_name; *p; p++) {
291c2c66affSColin Finck if(*p == '\\')
292c2c66affSColin Finck *p = '/';
293c2c66affSColin Finck }
294c2c66affSColin Finck
295c2c66affSColin Finck remove_dot_segments(object_name);
296c2c66affSColin Finck
297c2c66affSColin Finck TRACE("Resolving %s\n", debugstr_w(object_name));
298c2c66affSColin Finck
299c2c66affSColin Finck memset(&chm_object, 0, sizeof(chm_object));
300c2c66affSColin Finck res = chm_resolve_object(chm_file, object_name, &chm_object);
301c2c66affSColin Finck if(res != CHM_RESOLVE_SUCCESS) {
302c2c66affSColin Finck WARN("Could not resolve chm object\n");
303c2c66affSColin Finck HeapFree(GetProcessHeap(), 0, file_name);
304c2c66affSColin Finck chm_close(chm_file);
305c2c66affSColin Finck return report_result(pOIProtSink, STG_E_FILENOTFOUND);
306c2c66affSColin Finck }
307c2c66affSColin Finck
308c2c66affSColin Finck IInternetProtocolSink_ReportProgress(pOIProtSink, BINDSTATUS_SENDINGREQUEST,
309*da0cd273SAmine Khaldi wcsrchr(object_name, '/')+1);
310c2c66affSColin Finck
311c2c66affSColin Finck /* FIXME: Native doesn't use FindMimeFromData */
312c2c66affSColin Finck hres = FindMimeFromData(NULL, object_name, NULL, 0, NULL, 0, &mime, 0);
313c2c66affSColin Finck HeapFree(GetProcessHeap(), 0, file_name);
314c2c66affSColin Finck if(SUCCEEDED(hres)) {
315c2c66affSColin Finck IInternetProtocolSink_ReportProgress(pOIProtSink, BINDSTATUS_MIMETYPEAVAILABLE, mime);
316c2c66affSColin Finck CoTaskMemFree(mime);
317c2c66affSColin Finck }
318c2c66affSColin Finck
319c2c66affSColin Finck release_chm(This); /* Native leaks handle here */
320c2c66affSColin Finck This->chm_file = chm_file;
321c2c66affSColin Finck This->chm_object = chm_object;
322c2c66affSColin Finck
323c2c66affSColin Finck hres = IInternetProtocolSink_ReportData(pOIProtSink,
324c2c66affSColin Finck BSCF_FIRSTDATANOTIFICATION|BSCF_DATAFULLYAVAILABLE,
325c2c66affSColin Finck chm_object.length, chm_object.length);
326c2c66affSColin Finck if(FAILED(hres)) {
327c2c66affSColin Finck WARN("ReportData failed: %08x\n", hres);
328c2c66affSColin Finck release_chm(This);
329c2c66affSColin Finck return report_result(pOIProtSink, hres);
330c2c66affSColin Finck }
331c2c66affSColin Finck
332c2c66affSColin Finck hres = IInternetProtocolSink_ReportProgress(pOIProtSink, BINDSTATUS_BEGINDOWNLOADDATA, NULL);
333c2c66affSColin Finck
334c2c66affSColin Finck return report_result(pOIProtSink, hres);
335c2c66affSColin Finck }
336c2c66affSColin Finck
ITSProtocol_Continue(IInternetProtocol * iface,PROTOCOLDATA * pProtocolData)337c2c66affSColin Finck static HRESULT WINAPI ITSProtocol_Continue(IInternetProtocol *iface, PROTOCOLDATA *pProtocolData)
338c2c66affSColin Finck {
339c2c66affSColin Finck ITSProtocol *This = impl_from_IInternetProtocol(iface);
340c2c66affSColin Finck FIXME("(%p)->(%p)\n", This, pProtocolData);
341c2c66affSColin Finck return E_NOTIMPL;
342c2c66affSColin Finck }
343c2c66affSColin Finck
ITSProtocol_Abort(IInternetProtocol * iface,HRESULT hrReason,DWORD dwOptions)344c2c66affSColin Finck static HRESULT WINAPI ITSProtocol_Abort(IInternetProtocol *iface, HRESULT hrReason,
345c2c66affSColin Finck DWORD dwOptions)
346c2c66affSColin Finck {
347c2c66affSColin Finck ITSProtocol *This = impl_from_IInternetProtocol(iface);
348c2c66affSColin Finck FIXME("(%p)->(%08x %08x)\n", This, hrReason, dwOptions);
349c2c66affSColin Finck return E_NOTIMPL;
350c2c66affSColin Finck }
351c2c66affSColin Finck
ITSProtocol_Terminate(IInternetProtocol * iface,DWORD dwOptions)352c2c66affSColin Finck static HRESULT WINAPI ITSProtocol_Terminate(IInternetProtocol *iface, DWORD dwOptions)
353c2c66affSColin Finck {
354c2c66affSColin Finck ITSProtocol *This = impl_from_IInternetProtocol(iface);
355c2c66affSColin Finck
356c2c66affSColin Finck TRACE("(%p)->(%08x)\n", This, dwOptions);
357c2c66affSColin Finck
358c2c66affSColin Finck return S_OK;
359c2c66affSColin Finck }
360c2c66affSColin Finck
ITSProtocol_Suspend(IInternetProtocol * iface)361c2c66affSColin Finck static HRESULT WINAPI ITSProtocol_Suspend(IInternetProtocol *iface)
362c2c66affSColin Finck {
363c2c66affSColin Finck ITSProtocol *This = impl_from_IInternetProtocol(iface);
364c2c66affSColin Finck FIXME("(%p)\n", This);
365c2c66affSColin Finck return E_NOTIMPL;
366c2c66affSColin Finck }
367c2c66affSColin Finck
ITSProtocol_Resume(IInternetProtocol * iface)368c2c66affSColin Finck static HRESULT WINAPI ITSProtocol_Resume(IInternetProtocol *iface)
369c2c66affSColin Finck {
370c2c66affSColin Finck ITSProtocol *This = impl_from_IInternetProtocol(iface);
371c2c66affSColin Finck FIXME("(%p)\n", This);
372c2c66affSColin Finck return E_NOTIMPL;
373c2c66affSColin Finck }
374c2c66affSColin Finck
ITSProtocol_Read(IInternetProtocol * iface,void * pv,ULONG cb,ULONG * pcbRead)375c2c66affSColin Finck static HRESULT WINAPI ITSProtocol_Read(IInternetProtocol *iface, void *pv,
376c2c66affSColin Finck ULONG cb, ULONG *pcbRead)
377c2c66affSColin Finck {
378c2c66affSColin Finck ITSProtocol *This = impl_from_IInternetProtocol(iface);
379c2c66affSColin Finck
380c2c66affSColin Finck TRACE("(%p)->(%p %u %p)\n", This, pv, cb, pcbRead);
381c2c66affSColin Finck
382c2c66affSColin Finck if(!This->chm_file)
383c2c66affSColin Finck return INET_E_DATA_NOT_AVAILABLE;
384c2c66affSColin Finck
385c2c66affSColin Finck *pcbRead = chm_retrieve_object(This->chm_file, &This->chm_object, pv, This->offset, cb);
386c2c66affSColin Finck This->offset += *pcbRead;
387c2c66affSColin Finck
388c2c66affSColin Finck return *pcbRead ? S_OK : S_FALSE;
389c2c66affSColin Finck }
390c2c66affSColin Finck
ITSProtocol_Seek(IInternetProtocol * iface,LARGE_INTEGER dlibMove,DWORD dwOrigin,ULARGE_INTEGER * plibNewPosition)391c2c66affSColin Finck static HRESULT WINAPI ITSProtocol_Seek(IInternetProtocol *iface, LARGE_INTEGER dlibMove,
392c2c66affSColin Finck DWORD dwOrigin, ULARGE_INTEGER *plibNewPosition)
393c2c66affSColin Finck {
394c2c66affSColin Finck ITSProtocol *This = impl_from_IInternetProtocol(iface);
395c2c66affSColin Finck FIXME("(%p)->(%d %d %p)\n", This, dlibMove.u.LowPart, dwOrigin, plibNewPosition);
396c2c66affSColin Finck return E_NOTIMPL;
397c2c66affSColin Finck }
398c2c66affSColin Finck
ITSProtocol_LockRequest(IInternetProtocol * iface,DWORD dwOptions)399c2c66affSColin Finck static HRESULT WINAPI ITSProtocol_LockRequest(IInternetProtocol *iface, DWORD dwOptions)
400c2c66affSColin Finck {
401c2c66affSColin Finck ITSProtocol *This = impl_from_IInternetProtocol(iface);
402c2c66affSColin Finck
403c2c66affSColin Finck TRACE("(%p)->(%08x)\n", This, dwOptions);
404c2c66affSColin Finck
405c2c66affSColin Finck return S_OK;
406c2c66affSColin Finck }
407c2c66affSColin Finck
ITSProtocol_UnlockRequest(IInternetProtocol * iface)408c2c66affSColin Finck static HRESULT WINAPI ITSProtocol_UnlockRequest(IInternetProtocol *iface)
409c2c66affSColin Finck {
410c2c66affSColin Finck ITSProtocol *This = impl_from_IInternetProtocol(iface);
411c2c66affSColin Finck
412c2c66affSColin Finck TRACE("(%p)\n", This);
413c2c66affSColin Finck
414c2c66affSColin Finck return S_OK;
415c2c66affSColin Finck }
416c2c66affSColin Finck
417c2c66affSColin Finck static const IInternetProtocolVtbl ITSProtocolVtbl = {
418e64b0329SAmine Khaldi ITSInternetProtocol_QueryInterface,
419e64b0329SAmine Khaldi ITSInternetProtocol_AddRef,
420e64b0329SAmine Khaldi ITSInternetProtocol_Release,
421c2c66affSColin Finck ITSProtocol_Start,
422c2c66affSColin Finck ITSProtocol_Continue,
423c2c66affSColin Finck ITSProtocol_Abort,
424c2c66affSColin Finck ITSProtocol_Terminate,
425c2c66affSColin Finck ITSProtocol_Suspend,
426c2c66affSColin Finck ITSProtocol_Resume,
427c2c66affSColin Finck ITSProtocol_Read,
428c2c66affSColin Finck ITSProtocol_Seek,
429c2c66affSColin Finck ITSProtocol_LockRequest,
430c2c66affSColin Finck ITSProtocol_UnlockRequest
431c2c66affSColin Finck };
432c2c66affSColin Finck
ITSProtocolInfo_QueryInterface(IInternetProtocolInfo * iface,REFIID riid,void ** ppv)433c2c66affSColin Finck static HRESULT WINAPI ITSProtocolInfo_QueryInterface(IInternetProtocolInfo *iface,
434c2c66affSColin Finck REFIID riid, void **ppv)
435c2c66affSColin Finck {
436c2c66affSColin Finck ITSProtocol *This = impl_from_IInternetProtocolInfo(iface);
437c2c66affSColin Finck return IInternetProtocol_QueryInterface(&This->IInternetProtocol_iface, riid, ppv);
438c2c66affSColin Finck }
439c2c66affSColin Finck
ITSProtocolInfo_AddRef(IInternetProtocolInfo * iface)440c2c66affSColin Finck static ULONG WINAPI ITSProtocolInfo_AddRef(IInternetProtocolInfo *iface)
441c2c66affSColin Finck {
442c2c66affSColin Finck ITSProtocol *This = impl_from_IInternetProtocolInfo(iface);
443c2c66affSColin Finck return IInternetProtocol_AddRef(&This->IInternetProtocol_iface);
444c2c66affSColin Finck }
445c2c66affSColin Finck
ITSProtocolInfo_Release(IInternetProtocolInfo * iface)446c2c66affSColin Finck static ULONG WINAPI ITSProtocolInfo_Release(IInternetProtocolInfo *iface)
447c2c66affSColin Finck {
448c2c66affSColin Finck ITSProtocol *This = impl_from_IInternetProtocolInfo(iface);
449c2c66affSColin Finck return IInternetProtocol_Release(&This->IInternetProtocol_iface);
450c2c66affSColin Finck }
451c2c66affSColin Finck
ITSProtocolInfo_ParseUrl(IInternetProtocolInfo * iface,LPCWSTR pwzUrl,PARSEACTION ParseAction,DWORD dwParseFlags,LPWSTR pwzResult,DWORD cchResult,DWORD * pcchResult,DWORD dwReserved)452c2c66affSColin Finck static HRESULT WINAPI ITSProtocolInfo_ParseUrl(IInternetProtocolInfo *iface, LPCWSTR pwzUrl,
453c2c66affSColin Finck PARSEACTION ParseAction, DWORD dwParseFlags, LPWSTR pwzResult, DWORD cchResult,
454c2c66affSColin Finck DWORD *pcchResult, DWORD dwReserved)
455c2c66affSColin Finck {
456c2c66affSColin Finck ITSProtocol *This = impl_from_IInternetProtocolInfo(iface);
457c2c66affSColin Finck
458c2c66affSColin Finck TRACE("(%p)->(%s %x %08x %p %d %p %d)\n", This, debugstr_w(pwzUrl), ParseAction,
459c2c66affSColin Finck dwParseFlags, pwzResult, cchResult, pcchResult, dwReserved);
460c2c66affSColin Finck
461c2c66affSColin Finck switch(ParseAction) {
462c2c66affSColin Finck case PARSE_CANONICALIZE:
463c2c66affSColin Finck FIXME("PARSE_CANONICALIZE\n");
464c2c66affSColin Finck return E_NOTIMPL;
465c2c66affSColin Finck case PARSE_SECURITY_URL:
466c2c66affSColin Finck FIXME("PARSE_SECURITY_URL\n");
467c2c66affSColin Finck return E_NOTIMPL;
468c2c66affSColin Finck default:
469c2c66affSColin Finck return INET_E_DEFAULT_ACTION;
470c2c66affSColin Finck }
471c2c66affSColin Finck
472c2c66affSColin Finck return S_OK;
473c2c66affSColin Finck }
474c2c66affSColin Finck
ITSProtocolInfo_CombineUrl(IInternetProtocolInfo * iface,LPCWSTR pwzBaseUrl,LPCWSTR pwzRelativeUrl,DWORD dwCombineFlags,LPWSTR pwzResult,DWORD cchResult,DWORD * pcchResult,DWORD dwReserved)475c2c66affSColin Finck static HRESULT WINAPI ITSProtocolInfo_CombineUrl(IInternetProtocolInfo *iface,
476c2c66affSColin Finck LPCWSTR pwzBaseUrl, LPCWSTR pwzRelativeUrl, DWORD dwCombineFlags, LPWSTR pwzResult,
477c2c66affSColin Finck DWORD cchResult, DWORD* pcchResult, DWORD dwReserved)
478c2c66affSColin Finck {
479c2c66affSColin Finck ITSProtocol *This = impl_from_IInternetProtocolInfo(iface);
480c2c66affSColin Finck LPCWSTR base_end, ptr;
481c2c66affSColin Finck DWORD rel_len;
482c2c66affSColin Finck
483c2c66affSColin Finck static const WCHAR separator[] = {':',':',0};
484c2c66affSColin Finck
485c2c66affSColin Finck TRACE("(%p)->(%s %s %08x %p %d %p %d)\n", This, debugstr_w(pwzBaseUrl),
486c2c66affSColin Finck debugstr_w(pwzRelativeUrl), dwCombineFlags, pwzResult, cchResult,
487c2c66affSColin Finck pcchResult, dwReserved);
488c2c66affSColin Finck
489*da0cd273SAmine Khaldi base_end = wcsstr(pwzBaseUrl, separator);
490c2c66affSColin Finck if(!base_end)
491c2c66affSColin Finck return 0x80041001;
492c2c66affSColin Finck base_end += 2;
493c2c66affSColin Finck
494c2c66affSColin Finck if(!skip_schema(pwzBaseUrl))
495c2c66affSColin Finck return INET_E_USE_DEFAULT_PROTOCOLHANDLER;
496c2c66affSColin Finck
497*da0cd273SAmine Khaldi if(wcschr(pwzRelativeUrl, ':'))
498c2c66affSColin Finck return STG_E_INVALIDNAME;
499c2c66affSColin Finck
500c2c66affSColin Finck if(pwzRelativeUrl[0] == '#') {
501*da0cd273SAmine Khaldi base_end += lstrlenW(base_end);
502c2c66affSColin Finck }else if(pwzRelativeUrl[0] != '/') {
503*da0cd273SAmine Khaldi ptr = wcsrchr(base_end, '/');
504c2c66affSColin Finck if(ptr)
505c2c66affSColin Finck base_end = ptr+1;
506c2c66affSColin Finck else
507*da0cd273SAmine Khaldi base_end += lstrlenW(base_end);
508c2c66affSColin Finck }
509c2c66affSColin Finck
510*da0cd273SAmine Khaldi rel_len = lstrlenW(pwzRelativeUrl)+1;
511c2c66affSColin Finck
512c2c66affSColin Finck *pcchResult = rel_len + (base_end-pwzBaseUrl);
513c2c66affSColin Finck
514c2c66affSColin Finck if(*pcchResult > cchResult)
515c2c66affSColin Finck return E_OUTOFMEMORY;
516c2c66affSColin Finck
517c2c66affSColin Finck memcpy(pwzResult, pwzBaseUrl, (base_end-pwzBaseUrl)*sizeof(WCHAR));
518*da0cd273SAmine Khaldi lstrcpyW(pwzResult + (base_end-pwzBaseUrl), pwzRelativeUrl);
519c2c66affSColin Finck
520c2c66affSColin Finck return S_OK;
521c2c66affSColin Finck }
522c2c66affSColin Finck
ITSProtocolInfo_CompareUrl(IInternetProtocolInfo * iface,LPCWSTR pwzUrl1,LPCWSTR pwzUrl2,DWORD dwCompareFlags)523c2c66affSColin Finck static HRESULT WINAPI ITSProtocolInfo_CompareUrl(IInternetProtocolInfo *iface, LPCWSTR pwzUrl1,
524c2c66affSColin Finck LPCWSTR pwzUrl2, DWORD dwCompareFlags)
525c2c66affSColin Finck {
526c2c66affSColin Finck ITSProtocol *This = impl_from_IInternetProtocolInfo(iface);
527c2c66affSColin Finck FIXME("%p)->(%s %s %08x)\n", This, debugstr_w(pwzUrl1), debugstr_w(pwzUrl2), dwCompareFlags);
528c2c66affSColin Finck return E_NOTIMPL;
529c2c66affSColin Finck }
530c2c66affSColin Finck
ITSProtocolInfo_QueryInfo(IInternetProtocolInfo * iface,LPCWSTR pwzUrl,QUERYOPTION QueryOption,DWORD dwQueryFlags,LPVOID pBuffer,DWORD cbBuffer,DWORD * pcbBuf,DWORD dwReserved)531c2c66affSColin Finck static HRESULT WINAPI ITSProtocolInfo_QueryInfo(IInternetProtocolInfo *iface, LPCWSTR pwzUrl,
532c2c66affSColin Finck QUERYOPTION QueryOption, DWORD dwQueryFlags, LPVOID pBuffer, DWORD cbBuffer, DWORD* pcbBuf,
533c2c66affSColin Finck DWORD dwReserved)
534c2c66affSColin Finck {
535c2c66affSColin Finck ITSProtocol *This = impl_from_IInternetProtocolInfo(iface);
536c2c66affSColin Finck FIXME("(%p)->(%s %08x %08x %p %d %p %d)\n", This, debugstr_w(pwzUrl), QueryOption,
537c2c66affSColin Finck dwQueryFlags, pBuffer, cbBuffer, pcbBuf, dwReserved);
538c2c66affSColin Finck return E_NOTIMPL;
539c2c66affSColin Finck }
540c2c66affSColin Finck
541c2c66affSColin Finck static const IInternetProtocolInfoVtbl ITSProtocolInfoVtbl = {
542c2c66affSColin Finck ITSProtocolInfo_QueryInterface,
543c2c66affSColin Finck ITSProtocolInfo_AddRef,
544c2c66affSColin Finck ITSProtocolInfo_Release,
545c2c66affSColin Finck ITSProtocolInfo_ParseUrl,
546c2c66affSColin Finck ITSProtocolInfo_CombineUrl,
547c2c66affSColin Finck ITSProtocolInfo_CompareUrl,
548c2c66affSColin Finck ITSProtocolInfo_QueryInfo
549c2c66affSColin Finck };
550c2c66affSColin Finck
ITSProtocol_create(IUnknown * outer,void ** ppv)551e64b0329SAmine Khaldi HRESULT ITSProtocol_create(IUnknown *outer, void **ppv)
552c2c66affSColin Finck {
553c2c66affSColin Finck ITSProtocol *ret;
554c2c66affSColin Finck
555e64b0329SAmine Khaldi TRACE("(%p %p)\n", outer, ppv);
556c2c66affSColin Finck
557c2c66affSColin Finck ITSS_LockModule();
558c2c66affSColin Finck
559c2c66affSColin Finck ret = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(ITSProtocol));
560e64b0329SAmine Khaldi if(!ret)
561e64b0329SAmine Khaldi return E_OUTOFMEMORY;
562c2c66affSColin Finck
563e64b0329SAmine Khaldi ret->IUnknown_inner.lpVtbl = &ITSProtocolUnkVtbl;
564c2c66affSColin Finck ret->IInternetProtocol_iface.lpVtbl = &ITSProtocolVtbl;
565c2c66affSColin Finck ret->IInternetProtocolInfo_iface.lpVtbl = &ITSProtocolInfoVtbl;
566c2c66affSColin Finck ret->ref = 1;
567e64b0329SAmine Khaldi ret->outer = outer ? outer : &ret->IUnknown_inner;
568c2c66affSColin Finck
569e64b0329SAmine Khaldi *ppv = &ret->IUnknown_inner;
570c2c66affSColin Finck return S_OK;
571c2c66affSColin Finck }
572