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
28 #include "urlmon_main.h"
30 #include "wine/debug.h"
31 #include "wine/unicode.h"
33 WINE_DEFAULT_DEBUG_CHANNEL(urlmon);
36 const IInternetProtocolVtbl *lpInternetProtocolVtbl;
43 #define PROTOCOL_THIS(iface) DEFINE_THIS(MkProtocol, InternetProtocol, iface)
45 #define PROTOCOL(x) ((IInternetProtocol*) &(x)->lpInternetProtocolVtbl)
47 static HRESULT WINAPI MkProtocol_QueryInterface(IInternetProtocol *iface, REFIID riid, void **ppv)
49 MkProtocol *This = PROTOCOL_THIS(iface);
52 if(IsEqualGUID(&IID_IUnknown, riid)) {
53 TRACE("(%p)->(IID_IUnknown %p)\n", This, ppv);
54 *ppv = PROTOCOL(This);
55 }else if(IsEqualGUID(&IID_IInternetProtocolRoot, riid)) {
56 TRACE("(%p)->(IID_IInternetProtocolRoot %p)\n", This, ppv);
57 *ppv = PROTOCOL(This);
58 }else if(IsEqualGUID(&IID_IInternetProtocol, riid)) {
59 TRACE("(%p)->(IID_IInternetProtocol %p)\n", This, ppv);
60 *ppv = PROTOCOL(This);
64 IInternetProtocol_AddRef(iface);
68 WARN("not supported interface %s\n", debugstr_guid(riid));
72 static ULONG WINAPI MkProtocol_AddRef(IInternetProtocol *iface)
74 MkProtocol *This = PROTOCOL_THIS(iface);
75 LONG ref = InterlockedIncrement(&This->ref);
76 TRACE("(%p) ref=%d\n", This, ref);
80 static ULONG WINAPI MkProtocol_Release(IInternetProtocol *iface)
82 MkProtocol *This = PROTOCOL_THIS(iface);
83 LONG ref = InterlockedDecrement(&This->ref);
85 TRACE("(%p) ref=%d\n", This, ref);
89 IStream_Release(This->stream);
93 URLMON_UnlockModule();
99 static HRESULT report_result(IInternetProtocolSink *sink, HRESULT hres, DWORD dwError)
101 IInternetProtocolSink_ReportResult(sink, hres, dwError, NULL);
105 static HRESULT WINAPI MkProtocol_Start(IInternetProtocol *iface, LPCWSTR szUrl,
106 IInternetProtocolSink *pOIProtSink, IInternetBindInfo *pOIBindInfo,
107 DWORD grfPI, DWORD dwReserved)
109 MkProtocol *This = PROTOCOL_THIS(iface);
110 IParseDisplayName *pdn;
112 LPWSTR mime, progid, display_name;
116 DWORD bindf=0, eaten=0, len;
120 static const WCHAR wszMK[] = {'m','k',':'};
122 TRACE("(%p)->(%s %p %p %08x %d)\n", This, debugstr_w(szUrl), pOIProtSink,
123 pOIBindInfo, grfPI, dwReserved);
125 if(strncmpiW(szUrl, wszMK, sizeof(wszMK)/sizeof(WCHAR)))
126 return INET_E_INVALID_URL;
128 memset(&bindinfo, 0, sizeof(bindinfo));
129 bindinfo.cbSize = sizeof(BINDINFO);
130 hres = IInternetBindInfo_GetBindInfo(pOIBindInfo, &bindf, &bindinfo);
132 WARN("GetBindInfo failed: %08x\n", hres);
136 ReleaseBindInfo(&bindinfo);
138 IInternetProtocolSink_ReportProgress(pOIProtSink, BINDSTATUS_DIRECTBIND, NULL);
139 IInternetProtocolSink_ReportProgress(pOIProtSink, BINDSTATUS_SENDINGREQUEST, NULL);
141 hres = FindMimeFromData(NULL, szUrl, NULL, 0, NULL, 0, &mime, 0);
142 if(SUCCEEDED(hres)) {
143 IInternetProtocolSink_ReportProgress(pOIProtSink, BINDSTATUS_MIMETYPEAVAILABLE, mime);
147 ptr2 = szUrl + sizeof(wszMK)/sizeof(WCHAR);
149 return report_result(pOIProtSink, INET_E_RESOURCE_NOT_FOUND, ERROR_INVALID_PARAMETER);
152 ptr = strchrW(ptr2, ':');
154 return report_result(pOIProtSink, INET_E_RESOURCE_NOT_FOUND, ERROR_INVALID_PARAMETER);
156 progid = urlmon_alloc((ptr-ptr2+1)*sizeof(WCHAR));
157 memcpy(progid, ptr2, (ptr-ptr2)*sizeof(WCHAR));
158 progid[ptr-ptr2] = 0;
159 hres = CLSIDFromProgID(progid, &clsid);
162 return report_result(pOIProtSink, INET_E_RESOURCE_NOT_FOUND, ERROR_INVALID_PARAMETER);
164 hres = CoCreateInstance(&clsid, NULL, CLSCTX_INPROC_SERVER|CLSCTX_INPROC_HANDLER,
165 &IID_IParseDisplayName, (void**)&pdn);
167 WARN("Could not create object %s\n", debugstr_guid(&clsid));
168 return report_result(pOIProtSink, hres, ERROR_INVALID_PARAMETER);
171 len = strlenW(--ptr2);
172 display_name = urlmon_alloc((len+1)*sizeof(WCHAR));
173 memcpy(display_name, ptr2, (len+1)*sizeof(WCHAR));
174 hres = IParseDisplayName_ParseDisplayName(pdn, NULL /* FIXME */, display_name, &eaten, &mon);
175 urlmon_free(display_name);
176 IParseDisplayName_Release(pdn);
178 WARN("ParseDisplayName failed: %08x\n", hres);
179 return report_result(pOIProtSink, hres, ERROR_INVALID_PARAMETER);
183 IStream_Release(This->stream);
187 hres = IMoniker_BindToStorage(mon, NULL /* FIXME */, NULL, &IID_IStream, (void**)&This->stream);
188 IMoniker_Release(mon);
190 WARN("BindToStorage failed: %08x\n", hres);
191 return report_result(pOIProtSink, hres, ERROR_INVALID_PARAMETER);
194 hres = IStream_Stat(This->stream, &statstg, STATFLAG_NONAME);
196 WARN("Stat failed: %08x\n", hres);
197 return report_result(pOIProtSink, hres, ERROR_INVALID_PARAMETER);
200 IInternetProtocolSink_ReportData(pOIProtSink,
201 BSCF_FIRSTDATANOTIFICATION | BSCF_LASTDATANOTIFICATION,
202 statstg.cbSize.u.LowPart, statstg.cbSize.u.LowPart);
204 return report_result(pOIProtSink, S_OK, ERROR_SUCCESS);
207 static HRESULT WINAPI MkProtocol_Continue(IInternetProtocol *iface, PROTOCOLDATA *pProtocolData)
209 MkProtocol *This = PROTOCOL_THIS(iface);
210 FIXME("(%p)->(%p)\n", This, pProtocolData);
214 static HRESULT WINAPI MkProtocol_Abort(IInternetProtocol *iface, HRESULT hrReason,
217 MkProtocol *This = PROTOCOL_THIS(iface);
218 FIXME("(%p)->(%08x %08x)\n", This, hrReason, dwOptions);
222 static HRESULT WINAPI MkProtocol_Terminate(IInternetProtocol *iface, DWORD dwOptions)
224 MkProtocol *This = PROTOCOL_THIS(iface);
226 TRACE("(%p)->(%08x)\n", This, dwOptions);
231 static HRESULT WINAPI MkProtocol_Suspend(IInternetProtocol *iface)
233 MkProtocol *This = PROTOCOL_THIS(iface);
234 FIXME("(%p)\n", This);
238 static HRESULT WINAPI MkProtocol_Resume(IInternetProtocol *iface)
240 MkProtocol *This = PROTOCOL_THIS(iface);
241 FIXME("(%p)\n", This);
245 static HRESULT WINAPI MkProtocol_Read(IInternetProtocol *iface, void *pv,
246 ULONG cb, ULONG *pcbRead)
248 MkProtocol *This = PROTOCOL_THIS(iface);
250 TRACE("(%p)->(%p %u %p)\n", This, pv, cb, pcbRead);
255 return IStream_Read(This->stream, pv, cb, pcbRead);
258 static HRESULT WINAPI MkProtocol_Seek(IInternetProtocol *iface, LARGE_INTEGER dlibMove,
259 DWORD dwOrigin, ULARGE_INTEGER *plibNewPosition)
261 MkProtocol *This = PROTOCOL_THIS(iface);
262 FIXME("(%p)->(%d %d %p)\n", This, dlibMove.u.LowPart, dwOrigin, plibNewPosition);
266 static HRESULT WINAPI MkProtocol_LockRequest(IInternetProtocol *iface, DWORD dwOptions)
268 MkProtocol *This = PROTOCOL_THIS(iface);
270 TRACE("(%p)->(%08x)\n", This, dwOptions);
275 static HRESULT WINAPI MkProtocol_UnlockRequest(IInternetProtocol *iface)
277 MkProtocol *This = PROTOCOL_THIS(iface);
279 TRACE("(%p)\n", This);
286 static const IInternetProtocolVtbl MkProtocolVtbl = {
287 MkProtocol_QueryInterface,
293 MkProtocol_Terminate,
298 MkProtocol_LockRequest,
299 MkProtocol_UnlockRequest
302 HRESULT MkProtocol_Construct(IUnknown *pUnkOuter, LPVOID *ppobj)
306 TRACE("(%p %p)\n", pUnkOuter, ppobj);
310 ret = urlmon_alloc(sizeof(MkProtocol));
312 ret->lpInternetProtocolVtbl = &MkProtocolVtbl;
317 * Native returns NULL ppobj and S_OK in CreateInstance if called with IID_IUnknown riid.
319 *ppobj = PROTOCOL(ret);