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
*lpIInternetProtocolVtbl
;
32 #define PROTOCOL_THIS(iface) DEFINE_THIS(MkProtocol, IInternetProtocol, iface)
34 static HRESULT WINAPI
MkProtocol_QueryInterface(IInternetProtocol
*iface
, REFIID riid
, void **ppv
)
36 MkProtocol
*This
= PROTOCOL_THIS(iface
);
39 if(IsEqualGUID(&IID_IUnknown
, riid
)) {
40 TRACE("(%p)->(IID_IUnknown %p)\n", This
, ppv
);
41 *ppv
= PROTOCOL(This
);
42 }else if(IsEqualGUID(&IID_IInternetProtocolRoot
, riid
)) {
43 TRACE("(%p)->(IID_IInternetProtocolRoot %p)\n", This
, ppv
);
44 *ppv
= PROTOCOL(This
);
45 }else if(IsEqualGUID(&IID_IInternetProtocol
, riid
)) {
46 TRACE("(%p)->(IID_IInternetProtocol %p)\n", This
, ppv
);
47 *ppv
= PROTOCOL(This
);
51 IInternetProtocol_AddRef(iface
);
55 WARN("not supported interface %s\n", debugstr_guid(riid
));
59 static ULONG WINAPI
MkProtocol_AddRef(IInternetProtocol
*iface
)
61 MkProtocol
*This
= PROTOCOL_THIS(iface
);
62 LONG ref
= InterlockedIncrement(&This
->ref
);
63 TRACE("(%p) ref=%d\n", This
, ref
);
67 static ULONG WINAPI
MkProtocol_Release(IInternetProtocol
*iface
)
69 MkProtocol
*This
= PROTOCOL_THIS(iface
);
70 LONG ref
= InterlockedDecrement(&This
->ref
);
72 TRACE("(%p) ref=%d\n", This
, ref
);
76 IStream_Release(This
->stream
);
80 URLMON_UnlockModule();
86 static HRESULT
report_result(IInternetProtocolSink
*sink
, HRESULT hres
, DWORD dwError
)
88 IInternetProtocolSink_ReportResult(sink
, hres
, dwError
, NULL
);
92 static HRESULT WINAPI
MkProtocol_Start(IInternetProtocol
*iface
, LPCWSTR szUrl
,
93 IInternetProtocolSink
*pOIProtSink
, IInternetBindInfo
*pOIBindInfo
,
94 DWORD grfPI
, HANDLE_PTR dwReserved
)
96 MkProtocol
*This
= PROTOCOL_THIS(iface
);
97 IParseDisplayName
*pdn
;
99 LPWSTR mime
, progid
, display_name
;
103 DWORD bindf
=0, eaten
=0, len
;
107 static const WCHAR wszMK
[] = {'m','k',':','@'};
109 TRACE("(%p)->(%s %p %p %08x %lx)\n", This
, debugstr_w(szUrl
), pOIProtSink
,
110 pOIBindInfo
, grfPI
, dwReserved
);
112 if(strncmpiW(szUrl
, wszMK
, sizeof(wszMK
)/sizeof(WCHAR
)))
113 return INET_E_INVALID_URL
;
115 memset(&bindinfo
, 0, sizeof(bindinfo
));
116 bindinfo
.cbSize
= sizeof(BINDINFO
);
117 hres
= IInternetBindInfo_GetBindInfo(pOIBindInfo
, &bindf
, &bindinfo
);
119 WARN("GetBindInfo failed: %08x\n", hres
);
123 ReleaseBindInfo(&bindinfo
);
125 IInternetProtocolSink_ReportProgress(pOIProtSink
, BINDSTATUS_SENDINGREQUEST
, NULL
);
127 hres
= FindMimeFromData(NULL
, szUrl
, NULL
, 0, NULL
, 0, &mime
, 0);
128 if(SUCCEEDED(hres
)) {
129 IInternetProtocolSink_ReportProgress(pOIProtSink
, BINDSTATUS_MIMETYPEAVAILABLE
, mime
);
133 ptr2
= szUrl
+ sizeof(wszMK
)/sizeof(WCHAR
);
134 ptr
= strchrW(ptr2
, ':');
136 return report_result(pOIProtSink
, INET_E_RESOURCE_NOT_FOUND
, ERROR_INVALID_PARAMETER
);
138 progid
= heap_alloc((ptr
-ptr2
+1)*sizeof(WCHAR
));
139 memcpy(progid
, ptr2
, (ptr
-ptr2
)*sizeof(WCHAR
));
140 progid
[ptr
-ptr2
] = 0;
141 hres
= CLSIDFromProgID(progid
, &clsid
);
144 return report_result(pOIProtSink
, INET_E_RESOURCE_NOT_FOUND
, ERROR_INVALID_PARAMETER
);
146 hres
= CoCreateInstance(&clsid
, NULL
, CLSCTX_INPROC_SERVER
|CLSCTX_INPROC_HANDLER
,
147 &IID_IParseDisplayName
, (void**)&pdn
);
149 WARN("Could not create object %s\n", debugstr_guid(&clsid
));
150 return report_result(pOIProtSink
, hres
, ERROR_INVALID_PARAMETER
);
153 len
= strlenW(--ptr2
);
154 display_name
= heap_alloc((len
+1)*sizeof(WCHAR
));
155 memcpy(display_name
, ptr2
, (len
+1)*sizeof(WCHAR
));
156 hres
= IParseDisplayName_ParseDisplayName(pdn
, NULL
/* FIXME */, display_name
, &eaten
, &mon
);
157 heap_free(display_name
);
158 IParseDisplayName_Release(pdn
);
160 WARN("ParseDisplayName failed: %08x\n", hres
);
161 return report_result(pOIProtSink
, hres
, ERROR_INVALID_PARAMETER
);
165 IStream_Release(This
->stream
);
169 hres
= IMoniker_BindToStorage(mon
, NULL
/* FIXME */, NULL
, &IID_IStream
, (void**)&This
->stream
);
170 IMoniker_Release(mon
);
172 WARN("BindToStorage failed: %08x\n", hres
);
173 return report_result(pOIProtSink
, hres
, ERROR_INVALID_PARAMETER
);
176 hres
= IStream_Stat(This
->stream
, &statstg
, STATFLAG_NONAME
);
178 WARN("Stat failed: %08x\n", hres
);
179 return report_result(pOIProtSink
, hres
, ERROR_INVALID_PARAMETER
);
182 IInternetProtocolSink_ReportData(pOIProtSink
,
183 BSCF_FIRSTDATANOTIFICATION
| BSCF_LASTDATANOTIFICATION
,
184 statstg
.cbSize
.u
.LowPart
, statstg
.cbSize
.u
.LowPart
);
186 return report_result(pOIProtSink
, S_OK
, ERROR_SUCCESS
);
189 static HRESULT WINAPI
MkProtocol_Continue(IInternetProtocol
*iface
, PROTOCOLDATA
*pProtocolData
)
191 MkProtocol
*This
= PROTOCOL_THIS(iface
);
192 FIXME("(%p)->(%p)\n", This
, pProtocolData
);
196 static HRESULT WINAPI
MkProtocol_Abort(IInternetProtocol
*iface
, HRESULT hrReason
,
199 MkProtocol
*This
= PROTOCOL_THIS(iface
);
200 FIXME("(%p)->(%08x %08x)\n", This
, hrReason
, dwOptions
);
204 static HRESULT WINAPI
MkProtocol_Terminate(IInternetProtocol
*iface
, DWORD dwOptions
)
206 MkProtocol
*This
= PROTOCOL_THIS(iface
);
208 TRACE("(%p)->(%08x)\n", This
, dwOptions
);
213 static HRESULT WINAPI
MkProtocol_Suspend(IInternetProtocol
*iface
)
215 MkProtocol
*This
= PROTOCOL_THIS(iface
);
216 FIXME("(%p)\n", This
);
220 static HRESULT WINAPI
MkProtocol_Resume(IInternetProtocol
*iface
)
222 MkProtocol
*This
= PROTOCOL_THIS(iface
);
223 FIXME("(%p)\n", This
);
227 static HRESULT WINAPI
MkProtocol_Read(IInternetProtocol
*iface
, void *pv
,
228 ULONG cb
, ULONG
*pcbRead
)
230 MkProtocol
*This
= PROTOCOL_THIS(iface
);
232 TRACE("(%p)->(%p %u %p)\n", This
, pv
, cb
, pcbRead
);
237 return IStream_Read(This
->stream
, pv
, cb
, pcbRead
);
240 static HRESULT WINAPI
MkProtocol_Seek(IInternetProtocol
*iface
, LARGE_INTEGER dlibMove
,
241 DWORD dwOrigin
, ULARGE_INTEGER
*plibNewPosition
)
243 MkProtocol
*This
= PROTOCOL_THIS(iface
);
244 FIXME("(%p)->(%d %d %p)\n", This
, dlibMove
.u
.LowPart
, dwOrigin
, plibNewPosition
);
248 static HRESULT WINAPI
MkProtocol_LockRequest(IInternetProtocol
*iface
, DWORD dwOptions
)
250 MkProtocol
*This
= PROTOCOL_THIS(iface
);
252 TRACE("(%p)->(%08x)\n", This
, dwOptions
);
257 static HRESULT WINAPI
MkProtocol_UnlockRequest(IInternetProtocol
*iface
)
259 MkProtocol
*This
= PROTOCOL_THIS(iface
);
261 TRACE("(%p)\n", This
);
268 static const IInternetProtocolVtbl MkProtocolVtbl
= {
269 MkProtocol_QueryInterface
,
275 MkProtocol_Terminate
,
280 MkProtocol_LockRequest
,
281 MkProtocol_UnlockRequest
284 HRESULT
MkProtocol_Construct(IUnknown
*pUnkOuter
, LPVOID
*ppobj
)
288 TRACE("(%p %p)\n", pUnkOuter
, ppobj
);
292 ret
= heap_alloc(sizeof(MkProtocol
));
294 ret
->lpIInternetProtocolVtbl
= &MkProtocolVtbl
;
299 * Native returns NULL ppobj and S_OK in CreateInstance if called with IID_IUnknown riid.
301 *ppobj
= PROTOCOL(ret
);