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
);
136 ptr
= strchrW(ptr2
, ':');
138 return report_result(pOIProtSink
, INET_E_RESOURCE_NOT_FOUND
, ERROR_INVALID_PARAMETER
);
140 progid
= heap_alloc((ptr
-ptr2
+1)*sizeof(WCHAR
));
141 memcpy(progid
, ptr2
, (ptr
-ptr2
)*sizeof(WCHAR
));
142 progid
[ptr
-ptr2
] = 0;
143 hres
= CLSIDFromProgID(progid
, &clsid
);
146 return report_result(pOIProtSink
, INET_E_RESOURCE_NOT_FOUND
, ERROR_INVALID_PARAMETER
);
148 hres
= CoCreateInstance(&clsid
, NULL
, CLSCTX_INPROC_SERVER
|CLSCTX_INPROC_HANDLER
,
149 &IID_IParseDisplayName
, (void**)&pdn
);
151 WARN("Could not create object %s\n", debugstr_guid(&clsid
));
152 return report_result(pOIProtSink
, hres
, ERROR_INVALID_PARAMETER
);
155 len
= strlenW(--ptr2
);
156 display_name
= heap_alloc((len
+1)*sizeof(WCHAR
));
157 memcpy(display_name
, ptr2
, (len
+1)*sizeof(WCHAR
));
158 hres
= IParseDisplayName_ParseDisplayName(pdn
, NULL
/* FIXME */, display_name
, &eaten
, &mon
);
159 heap_free(display_name
);
160 IParseDisplayName_Release(pdn
);
162 WARN("ParseDisplayName failed: %08x\n", hres
);
163 return report_result(pOIProtSink
, hres
, ERROR_INVALID_PARAMETER
);
167 IStream_Release(This
->stream
);
171 hres
= IMoniker_BindToStorage(mon
, NULL
/* FIXME */, NULL
, &IID_IStream
, (void**)&This
->stream
);
172 IMoniker_Release(mon
);
174 WARN("BindToStorage failed: %08x\n", hres
);
175 return report_result(pOIProtSink
, hres
, ERROR_INVALID_PARAMETER
);
178 hres
= IStream_Stat(This
->stream
, &statstg
, STATFLAG_NONAME
);
180 WARN("Stat failed: %08x\n", hres
);
181 return report_result(pOIProtSink
, hres
, ERROR_INVALID_PARAMETER
);
184 IInternetProtocolSink_ReportData(pOIProtSink
,
185 BSCF_FIRSTDATANOTIFICATION
| BSCF_LASTDATANOTIFICATION
,
186 statstg
.cbSize
.u
.LowPart
, statstg
.cbSize
.u
.LowPart
);
188 return report_result(pOIProtSink
, S_OK
, ERROR_SUCCESS
);
191 static HRESULT WINAPI
MkProtocol_Continue(IInternetProtocol
*iface
, PROTOCOLDATA
*pProtocolData
)
193 MkProtocol
*This
= PROTOCOL_THIS(iface
);
194 FIXME("(%p)->(%p)\n", This
, pProtocolData
);
198 static HRESULT WINAPI
MkProtocol_Abort(IInternetProtocol
*iface
, HRESULT hrReason
,
201 MkProtocol
*This
= PROTOCOL_THIS(iface
);
202 FIXME("(%p)->(%08x %08x)\n", This
, hrReason
, dwOptions
);
206 static HRESULT WINAPI
MkProtocol_Terminate(IInternetProtocol
*iface
, DWORD dwOptions
)
208 MkProtocol
*This
= PROTOCOL_THIS(iface
);
210 TRACE("(%p)->(%08x)\n", This
, dwOptions
);
215 static HRESULT WINAPI
MkProtocol_Suspend(IInternetProtocol
*iface
)
217 MkProtocol
*This
= PROTOCOL_THIS(iface
);
218 FIXME("(%p)\n", This
);
222 static HRESULT WINAPI
MkProtocol_Resume(IInternetProtocol
*iface
)
224 MkProtocol
*This
= PROTOCOL_THIS(iface
);
225 FIXME("(%p)\n", This
);
229 static HRESULT WINAPI
MkProtocol_Read(IInternetProtocol
*iface
, void *pv
,
230 ULONG cb
, ULONG
*pcbRead
)
232 MkProtocol
*This
= PROTOCOL_THIS(iface
);
234 TRACE("(%p)->(%p %u %p)\n", This
, pv
, cb
, pcbRead
);
239 return IStream_Read(This
->stream
, pv
, cb
, pcbRead
);
242 static HRESULT WINAPI
MkProtocol_Seek(IInternetProtocol
*iface
, LARGE_INTEGER dlibMove
,
243 DWORD dwOrigin
, ULARGE_INTEGER
*plibNewPosition
)
245 MkProtocol
*This
= PROTOCOL_THIS(iface
);
246 FIXME("(%p)->(%d %d %p)\n", This
, dlibMove
.u
.LowPart
, dwOrigin
, plibNewPosition
);
250 static HRESULT WINAPI
MkProtocol_LockRequest(IInternetProtocol
*iface
, DWORD dwOptions
)
252 MkProtocol
*This
= PROTOCOL_THIS(iface
);
254 TRACE("(%p)->(%08x)\n", This
, dwOptions
);
259 static HRESULT WINAPI
MkProtocol_UnlockRequest(IInternetProtocol
*iface
)
261 MkProtocol
*This
= PROTOCOL_THIS(iface
);
263 TRACE("(%p)\n", This
);
270 static const IInternetProtocolVtbl MkProtocolVtbl
= {
271 MkProtocol_QueryInterface
,
277 MkProtocol_Terminate
,
282 MkProtocol_LockRequest
,
283 MkProtocol_UnlockRequest
286 HRESULT
MkProtocol_Construct(IUnknown
*pUnkOuter
, LPVOID
*ppobj
)
290 TRACE("(%p %p)\n", pUnkOuter
, ppobj
);
294 ret
= heap_alloc(sizeof(MkProtocol
));
296 ret
->lpInternetProtocolVtbl
= &MkProtocolVtbl
;
301 * Native returns NULL ppobj and S_OK in CreateInstance if called with IID_IUnknown riid.
303 *ppobj
= PROTOCOL(ret
);