2 * Copyright 2007 Jacek Caban for CodeWeavers
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 "urlmon_main.h"
20 #include "wine/debug.h"
22 WINE_DEFAULT_DEBUG_CHANNEL(urlmon);
25 const IInternetProtocolVtbl *lpInternetProtocolVtbl;
32 #define PROTOCOL_THIS(iface) DEFINE_THIS(MkProtocol, InternetProtocol, iface)
34 #define PROTOCOL(x) ((IInternetProtocol*) &(x)->lpInternetProtocolVtbl)
36 static HRESULT WINAPI MkProtocol_QueryInterface(IInternetProtocol *iface, REFIID riid, void **ppv)
38 MkProtocol *This = PROTOCOL_THIS(iface);
41 if(IsEqualGUID(&IID_IUnknown, riid)) {
42 TRACE("(%p)->(IID_IUnknown %p)\n", This, ppv);
43 *ppv = PROTOCOL(This);
44 }else if(IsEqualGUID(&IID_IInternetProtocolRoot, riid)) {
45 TRACE("(%p)->(IID_IInternetProtocolRoot %p)\n", This, ppv);
46 *ppv = PROTOCOL(This);
47 }else if(IsEqualGUID(&IID_IInternetProtocol, riid)) {
48 TRACE("(%p)->(IID_IInternetProtocol %p)\n", This, ppv);
49 *ppv = PROTOCOL(This);
53 IInternetProtocol_AddRef(iface);
57 WARN("not supported interface %s\n", debugstr_guid(riid));
61 static ULONG WINAPI MkProtocol_AddRef(IInternetProtocol *iface)
63 MkProtocol *This = PROTOCOL_THIS(iface);
64 LONG ref = InterlockedIncrement(&This->ref);
65 TRACE("(%p) ref=%d\n", This, ref);
69 static ULONG WINAPI MkProtocol_Release(IInternetProtocol *iface)
71 MkProtocol *This = PROTOCOL_THIS(iface);
72 LONG ref = InterlockedDecrement(&This->ref);
74 TRACE("(%p) ref=%d\n", This, ref);
78 IStream_Release(This->stream);
82 URLMON_UnlockModule();
88 static HRESULT report_result(IInternetProtocolSink *sink, HRESULT hres, DWORD dwError)
90 IInternetProtocolSink_ReportResult(sink, hres, dwError, NULL);
94 static HRESULT WINAPI MkProtocol_Start(IInternetProtocol *iface, LPCWSTR szUrl,
95 IInternetProtocolSink *pOIProtSink, IInternetBindInfo *pOIBindInfo,
96 DWORD grfPI, DWORD dwReserved)
98 MkProtocol *This = PROTOCOL_THIS(iface);
99 IParseDisplayName *pdn;
101 LPWSTR mime, progid, display_name;
105 DWORD bindf=0, eaten=0, len;
109 static const WCHAR wszMK[] = {'m','k',':'};
111 TRACE("(%p)->(%s %p %p %08x %d)\n", This, debugstr_w(szUrl), pOIProtSink,
112 pOIBindInfo, grfPI, dwReserved);
114 if(strncmpiW(szUrl, wszMK, sizeof(wszMK)/sizeof(WCHAR)))
115 return INET_E_INVALID_URL;
117 memset(&bindinfo, 0, sizeof(bindinfo));
118 bindinfo.cbSize = sizeof(BINDINFO);
119 hres = IInternetBindInfo_GetBindInfo(pOIBindInfo, &bindf, &bindinfo);
121 WARN("GetBindInfo failed: %08x\n", hres);
125 ReleaseBindInfo(&bindinfo);
127 IInternetProtocolSink_ReportProgress(pOIProtSink, BINDSTATUS_DIRECTBIND, NULL);
128 IInternetProtocolSink_ReportProgress(pOIProtSink, BINDSTATUS_SENDINGREQUEST, NULL);
130 hres = FindMimeFromData(NULL, szUrl, NULL, 0, NULL, 0, &mime, 0);
131 if(SUCCEEDED(hres)) {
132 IInternetProtocolSink_ReportProgress(pOIProtSink, BINDSTATUS_MIMETYPEAVAILABLE, mime);
136 ptr2 = szUrl + sizeof(wszMK)/sizeof(WCHAR);
138 return report_result(pOIProtSink, INET_E_RESOURCE_NOT_FOUND, ERROR_INVALID_PARAMETER);
141 ptr = strchrW(ptr2, ':');
143 return report_result(pOIProtSink, INET_E_RESOURCE_NOT_FOUND, ERROR_INVALID_PARAMETER);
145 progid = heap_alloc((ptr-ptr2+1)*sizeof(WCHAR));
146 memcpy(progid, ptr2, (ptr-ptr2)*sizeof(WCHAR));
147 progid[ptr-ptr2] = 0;
148 hres = CLSIDFromProgID(progid, &clsid);
151 return report_result(pOIProtSink, INET_E_RESOURCE_NOT_FOUND, ERROR_INVALID_PARAMETER);
153 hres = CoCreateInstance(&clsid, NULL, CLSCTX_INPROC_SERVER|CLSCTX_INPROC_HANDLER,
154 &IID_IParseDisplayName, (void**)&pdn);
156 WARN("Could not create object %s\n", debugstr_guid(&clsid));
157 return report_result(pOIProtSink, hres, ERROR_INVALID_PARAMETER);
160 len = strlenW(--ptr2);
161 display_name = heap_alloc((len+1)*sizeof(WCHAR));
162 memcpy(display_name, ptr2, (len+1)*sizeof(WCHAR));
163 hres = IParseDisplayName_ParseDisplayName(pdn, NULL /* FIXME */, display_name, &eaten, &mon);
164 heap_free(display_name);
165 IParseDisplayName_Release(pdn);
167 WARN("ParseDisplayName failed: %08x\n", hres);
168 return report_result(pOIProtSink, hres, ERROR_INVALID_PARAMETER);
172 IStream_Release(This->stream);
176 hres = IMoniker_BindToStorage(mon, NULL /* FIXME */, NULL, &IID_IStream, (void**)&This->stream);
177 IMoniker_Release(mon);
179 WARN("BindToStorage failed: %08x\n", hres);
180 return report_result(pOIProtSink, hres, ERROR_INVALID_PARAMETER);
183 hres = IStream_Stat(This->stream, &statstg, STATFLAG_NONAME);
185 WARN("Stat failed: %08x\n", hres);
186 return report_result(pOIProtSink, hres, ERROR_INVALID_PARAMETER);
189 IInternetProtocolSink_ReportData(pOIProtSink,
190 BSCF_FIRSTDATANOTIFICATION | BSCF_LASTDATANOTIFICATION,
191 statstg.cbSize.u.LowPart, statstg.cbSize.u.LowPart);
193 return report_result(pOIProtSink, S_OK, ERROR_SUCCESS);
196 static HRESULT WINAPI MkProtocol_Continue(IInternetProtocol *iface, PROTOCOLDATA *pProtocolData)
198 MkProtocol *This = PROTOCOL_THIS(iface);
199 FIXME("(%p)->(%p)\n", This, pProtocolData);
203 static HRESULT WINAPI MkProtocol_Abort(IInternetProtocol *iface, HRESULT hrReason,
206 MkProtocol *This = PROTOCOL_THIS(iface);
207 FIXME("(%p)->(%08x %08x)\n", This, hrReason, dwOptions);
211 static HRESULT WINAPI MkProtocol_Terminate(IInternetProtocol *iface, DWORD dwOptions)
213 MkProtocol *This = PROTOCOL_THIS(iface);
215 TRACE("(%p)->(%08x)\n", This, dwOptions);
220 static HRESULT WINAPI MkProtocol_Suspend(IInternetProtocol *iface)
222 MkProtocol *This = PROTOCOL_THIS(iface);
223 FIXME("(%p)\n", This);
227 static HRESULT WINAPI MkProtocol_Resume(IInternetProtocol *iface)
229 MkProtocol *This = PROTOCOL_THIS(iface);
230 FIXME("(%p)\n", This);
234 static HRESULT WINAPI MkProtocol_Read(IInternetProtocol *iface, void *pv,
235 ULONG cb, ULONG *pcbRead)
237 MkProtocol *This = PROTOCOL_THIS(iface);
239 TRACE("(%p)->(%p %u %p)\n", This, pv, cb, pcbRead);
244 return IStream_Read(This->stream, pv, cb, pcbRead);
247 static HRESULT WINAPI MkProtocol_Seek(IInternetProtocol *iface, LARGE_INTEGER dlibMove,
248 DWORD dwOrigin, ULARGE_INTEGER *plibNewPosition)
250 MkProtocol *This = PROTOCOL_THIS(iface);
251 FIXME("(%p)->(%d %d %p)\n", This, dlibMove.u.LowPart, dwOrigin, plibNewPosition);
255 static HRESULT WINAPI MkProtocol_LockRequest(IInternetProtocol *iface, DWORD dwOptions)
257 MkProtocol *This = PROTOCOL_THIS(iface);
259 TRACE("(%p)->(%08x)\n", This, dwOptions);
264 static HRESULT WINAPI MkProtocol_UnlockRequest(IInternetProtocol *iface)
266 MkProtocol *This = PROTOCOL_THIS(iface);
268 TRACE("(%p)\n", This);
275 static const IInternetProtocolVtbl MkProtocolVtbl = {
276 MkProtocol_QueryInterface,
282 MkProtocol_Terminate,
287 MkProtocol_LockRequest,
288 MkProtocol_UnlockRequest
291 HRESULT MkProtocol_Construct(IUnknown *pUnkOuter, LPVOID *ppobj)
295 TRACE("(%p %p)\n", pUnkOuter, ppobj);
299 ret = heap_alloc(sizeof(MkProtocol));
301 ret->lpInternetProtocolVtbl = &MkProtocolVtbl;
306 * Native returns NULL ppobj and S_OK in CreateInstance if called with IID_IUnknown riid.
308 *ppobj = PROTOCOL(ret);