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_SENDINGREQUEST, NULL);
129 hres = FindMimeFromData(NULL, szUrl, NULL, 0, NULL, 0, &mime, 0);
130 if(SUCCEEDED(hres)) {
131 IInternetProtocolSink_ReportProgress(pOIProtSink, BINDSTATUS_MIMETYPEAVAILABLE, mime);
135 ptr2 = szUrl + sizeof(wszMK)/sizeof(WCHAR);
137 return report_result(pOIProtSink, INET_E_RESOURCE_NOT_FOUND, ERROR_INVALID_PARAMETER);
140 ptr = strchrW(ptr2, ':');
142 return report_result(pOIProtSink, INET_E_RESOURCE_NOT_FOUND, ERROR_INVALID_PARAMETER);
144 progid = heap_alloc((ptr-ptr2+1)*sizeof(WCHAR));
145 memcpy(progid, ptr2, (ptr-ptr2)*sizeof(WCHAR));
146 progid[ptr-ptr2] = 0;
147 hres = CLSIDFromProgID(progid, &clsid);
150 return report_result(pOIProtSink, INET_E_RESOURCE_NOT_FOUND, ERROR_INVALID_PARAMETER);
152 hres = CoCreateInstance(&clsid, NULL, CLSCTX_INPROC_SERVER|CLSCTX_INPROC_HANDLER,
153 &IID_IParseDisplayName, (void**)&pdn);
155 WARN("Could not create object %s\n", debugstr_guid(&clsid));
156 return report_result(pOIProtSink, hres, ERROR_INVALID_PARAMETER);
159 len = strlenW(--ptr2);
160 display_name = heap_alloc((len+1)*sizeof(WCHAR));
161 memcpy(display_name, ptr2, (len+1)*sizeof(WCHAR));
162 hres = IParseDisplayName_ParseDisplayName(pdn, NULL /* FIXME */, display_name, &eaten, &mon);
163 heap_free(display_name);
164 IParseDisplayName_Release(pdn);
166 WARN("ParseDisplayName failed: %08x\n", hres);
167 return report_result(pOIProtSink, hres, ERROR_INVALID_PARAMETER);
171 IStream_Release(This->stream);
175 hres = IMoniker_BindToStorage(mon, NULL /* FIXME */, NULL, &IID_IStream, (void**)&This->stream);
176 IMoniker_Release(mon);
178 WARN("BindToStorage failed: %08x\n", hres);
179 return report_result(pOIProtSink, hres, ERROR_INVALID_PARAMETER);
182 hres = IStream_Stat(This->stream, &statstg, STATFLAG_NONAME);
184 WARN("Stat failed: %08x\n", hres);
185 return report_result(pOIProtSink, hres, ERROR_INVALID_PARAMETER);
188 IInternetProtocolSink_ReportData(pOIProtSink,
189 BSCF_FIRSTDATANOTIFICATION | BSCF_LASTDATANOTIFICATION,
190 statstg.cbSize.u.LowPart, statstg.cbSize.u.LowPart);
192 return report_result(pOIProtSink, S_OK, ERROR_SUCCESS);
195 static HRESULT WINAPI MkProtocol_Continue(IInternetProtocol *iface, PROTOCOLDATA *pProtocolData)
197 MkProtocol *This = PROTOCOL_THIS(iface);
198 FIXME("(%p)->(%p)\n", This, pProtocolData);
202 static HRESULT WINAPI MkProtocol_Abort(IInternetProtocol *iface, HRESULT hrReason,
205 MkProtocol *This = PROTOCOL_THIS(iface);
206 FIXME("(%p)->(%08x %08x)\n", This, hrReason, dwOptions);
210 static HRESULT WINAPI MkProtocol_Terminate(IInternetProtocol *iface, DWORD dwOptions)
212 MkProtocol *This = PROTOCOL_THIS(iface);
214 TRACE("(%p)->(%08x)\n", This, dwOptions);
219 static HRESULT WINAPI MkProtocol_Suspend(IInternetProtocol *iface)
221 MkProtocol *This = PROTOCOL_THIS(iface);
222 FIXME("(%p)\n", This);
226 static HRESULT WINAPI MkProtocol_Resume(IInternetProtocol *iface)
228 MkProtocol *This = PROTOCOL_THIS(iface);
229 FIXME("(%p)\n", This);
233 static HRESULT WINAPI MkProtocol_Read(IInternetProtocol *iface, void *pv,
234 ULONG cb, ULONG *pcbRead)
236 MkProtocol *This = PROTOCOL_THIS(iface);
238 TRACE("(%p)->(%p %u %p)\n", This, pv, cb, pcbRead);
243 return IStream_Read(This->stream, pv, cb, pcbRead);
246 static HRESULT WINAPI MkProtocol_Seek(IInternetProtocol *iface, LARGE_INTEGER dlibMove,
247 DWORD dwOrigin, ULARGE_INTEGER *plibNewPosition)
249 MkProtocol *This = PROTOCOL_THIS(iface);
250 FIXME("(%p)->(%d %d %p)\n", This, dlibMove.u.LowPart, dwOrigin, plibNewPosition);
254 static HRESULT WINAPI MkProtocol_LockRequest(IInternetProtocol *iface, DWORD dwOptions)
256 MkProtocol *This = PROTOCOL_THIS(iface);
258 TRACE("(%p)->(%08x)\n", This, dwOptions);
263 static HRESULT WINAPI MkProtocol_UnlockRequest(IInternetProtocol *iface)
265 MkProtocol *This = PROTOCOL_THIS(iface);
267 TRACE("(%p)\n", This);
274 static const IInternetProtocolVtbl MkProtocolVtbl = {
275 MkProtocol_QueryInterface,
281 MkProtocol_Terminate,
286 MkProtocol_LockRequest,
287 MkProtocol_UnlockRequest
290 HRESULT MkProtocol_Construct(IUnknown *pUnkOuter, LPVOID *ppobj)
294 TRACE("(%p %p)\n", pUnkOuter, ppobj);
298 ret = heap_alloc(sizeof(MkProtocol));
300 ret->lpInternetProtocolVtbl = &MkProtocolVtbl;
305 * Native returns NULL ppobj and S_OK in CreateInstance if called with IID_IUnknown riid.
307 *ppobj = PROTOCOL(ret);