Sync with trunk head
[reactos.git] / dll / win32 / urlmon / mimefilter.c
1 /*
2 * Copyright 2009 Jacek Caban for CodeWeavers
3 *
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.
8 *
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.
13 *
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
17 */
18
19 #include "urlmon_main.h"
20 #include "wine/debug.h"
21
22 WINE_DEFAULT_DEBUG_CHANNEL(urlmon);
23
24 typedef struct {
25 const IInternetProtocolVtbl *lpIInternetProtocolVtbl;
26 const IInternetProtocolSinkVtbl *lpIInternetProtocolSinkVtbl;
27
28 LONG ref;
29 } MimeFilter;
30
31 #define PROTOCOL(x) ((IInternetProtocol*) &(x)->lpIInternetProtocolVtbl)
32 #define PROTOCOLSINK(x) ((IInternetProtocolSink*) &(x)->lpIInternetProtocolSinkVtbl)
33
34 #define PROTOCOL_THIS(iface) DEFINE_THIS(MimeFilter, IInternetProtocol, iface)
35
36 static HRESULT WINAPI MimeFilterProtocol_QueryInterface(IInternetProtocol *iface, REFIID riid, void **ppv)
37 {
38 MimeFilter *This = PROTOCOL_THIS(iface);
39
40 *ppv = NULL;
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);
50 }else if(IsEqualGUID(&IID_IInternetProtocolSink, riid)) {
51 TRACE("(%p)->(IID_IInternetProtocolSink %p)\n", This, ppv);
52 *ppv = PROTOCOLSINK(This);
53 }
54
55 if(*ppv) {
56 IInternetProtocol_AddRef(iface);
57 return S_OK;
58 }
59
60 WARN("not supported interface %s\n", debugstr_guid(riid));
61 return E_NOINTERFACE;
62 }
63
64 static ULONG WINAPI MimeFilterProtocol_AddRef(IInternetProtocol *iface)
65 {
66 MimeFilter *This = PROTOCOL_THIS(iface);
67 LONG ref = InterlockedIncrement(&This->ref);
68 TRACE("(%p) ref=%d\n", This, ref);
69 return ref;
70 }
71
72 static ULONG WINAPI MimeFilterProtocol_Release(IInternetProtocol *iface)
73 {
74 MimeFilter *This = PROTOCOL_THIS(iface);
75 LONG ref = InterlockedDecrement(&This->ref);
76
77 TRACE("(%p) ref=%d\n", This, ref);
78
79 if(!ref) {
80 heap_free(This);
81
82 URLMON_UnlockModule();
83 }
84
85 return ref;
86 }
87
88 static HRESULT WINAPI MimeFilterProtocol_Start(IInternetProtocol *iface, LPCWSTR szUrl,
89 IInternetProtocolSink *pOIProtSink, IInternetBindInfo *pOIBindInfo,
90 DWORD grfPI, HANDLE_PTR dwReserved)
91 {
92 MimeFilter *This = PROTOCOL_THIS(iface);
93 FIXME("(%p)->(%s %p %p %08x %lx)\n", This, debugstr_w(szUrl), pOIProtSink,
94 pOIBindInfo, grfPI, dwReserved);
95 return E_NOTIMPL;
96 }
97
98 static HRESULT WINAPI MimeFilterProtocol_Continue(IInternetProtocol *iface, PROTOCOLDATA *pProtocolData)
99 {
100 MimeFilter *This = PROTOCOL_THIS(iface);
101 FIXME("(%p)->(%p)\n", This, pProtocolData);
102 return E_NOTIMPL;
103 }
104
105 static HRESULT WINAPI MimeFilterProtocol_Abort(IInternetProtocol *iface, HRESULT hrReason,
106 DWORD dwOptions)
107 {
108 MimeFilter *This = PROTOCOL_THIS(iface);
109 FIXME("(%p)->(%08x %08x)\n", This, hrReason, dwOptions);
110 return E_NOTIMPL;
111 }
112
113 static HRESULT WINAPI MimeFilterProtocol_Terminate(IInternetProtocol *iface, DWORD dwOptions)
114 {
115 MimeFilter *This = PROTOCOL_THIS(iface);
116 FIXME("(%p)->(%08x)\n", This, dwOptions);
117 return E_NOTIMPL;
118 }
119
120 static HRESULT WINAPI MimeFilterProtocol_Suspend(IInternetProtocol *iface)
121 {
122 MimeFilter *This = PROTOCOL_THIS(iface);
123 FIXME("(%p)\n", This);
124 return E_NOTIMPL;
125 }
126
127 static HRESULT WINAPI MimeFilterProtocol_Resume(IInternetProtocol *iface)
128 {
129 MimeFilter *This = PROTOCOL_THIS(iface);
130 FIXME("(%p)\n", This);
131 return E_NOTIMPL;
132 }
133
134 static HRESULT WINAPI MimeFilterProtocol_Read(IInternetProtocol *iface, void *pv,
135 ULONG cb, ULONG *pcbRead)
136 {
137 MimeFilter *This = PROTOCOL_THIS(iface);
138 FIXME("(%p)->(%p %u %p)\n", This, pv, cb, pcbRead);
139 return E_NOTIMPL;
140 }
141
142 static HRESULT WINAPI MimeFilterProtocol_Seek(IInternetProtocol *iface, LARGE_INTEGER dlibMove,
143 DWORD dwOrigin, ULARGE_INTEGER *plibNewPosition)
144 {
145 MimeFilter *This = PROTOCOL_THIS(iface);
146 FIXME("(%p)->(%d %d %p)\n", This, dlibMove.u.LowPart, dwOrigin, plibNewPosition);
147 return E_NOTIMPL;
148 }
149
150 static HRESULT WINAPI MimeFilterProtocol_LockRequest(IInternetProtocol *iface, DWORD dwOptions)
151 {
152 MimeFilter *This = PROTOCOL_THIS(iface);
153 FIXME("(%p)->(%08x)\n", This, dwOptions);
154 return E_NOTIMPL;
155 }
156
157 static HRESULT WINAPI MimeFilterProtocol_UnlockRequest(IInternetProtocol *iface)
158 {
159 MimeFilter *This = PROTOCOL_THIS(iface);
160 FIXME("(%p)\n", This);
161 return E_NOTIMPL;
162 }
163
164 #undef PROTOCOL_THIS
165
166 static const IInternetProtocolVtbl MimeFilterProtocolVtbl = {
167 MimeFilterProtocol_QueryInterface,
168 MimeFilterProtocol_AddRef,
169 MimeFilterProtocol_Release,
170 MimeFilterProtocol_Start,
171 MimeFilterProtocol_Continue,
172 MimeFilterProtocol_Abort,
173 MimeFilterProtocol_Terminate,
174 MimeFilterProtocol_Suspend,
175 MimeFilterProtocol_Resume,
176 MimeFilterProtocol_Read,
177 MimeFilterProtocol_Seek,
178 MimeFilterProtocol_LockRequest,
179 MimeFilterProtocol_UnlockRequest
180 };
181
182 #define PROTSINK_THIS(iface) DEFINE_THIS(MimeFilter, IInternetProtocolSink, iface)
183
184 static HRESULT WINAPI MimeFilterSink_QueryInterface(IInternetProtocolSink *iface,
185 REFIID riid, void **ppv)
186 {
187 MimeFilter *This = PROTSINK_THIS(iface);
188 return IInternetProtocol_QueryInterface(PROTOCOL(This), riid, ppv);
189 }
190
191 static ULONG WINAPI MimeFilterSink_AddRef(IInternetProtocolSink *iface)
192 {
193 MimeFilter *This = PROTSINK_THIS(iface);
194 return IInternetProtocol_AddRef(PROTOCOL(This));
195 }
196
197 static ULONG WINAPI MimeFilterSink_Release(IInternetProtocolSink *iface)
198 {
199 MimeFilter *This = PROTSINK_THIS(iface);
200 return IInternetProtocol_Release(PROTOCOL(This));
201 }
202
203 static HRESULT WINAPI MimeFilterSink_Switch(IInternetProtocolSink *iface,
204 PROTOCOLDATA *pProtocolData)
205 {
206 MimeFilter *This = PROTSINK_THIS(iface);
207 FIXME("(%p)->(%p)\n", This, pProtocolData);
208 return E_NOTIMPL;
209 }
210
211 static HRESULT WINAPI MimeFilterSink_ReportProgress(IInternetProtocolSink *iface,
212 ULONG ulStatusCode, LPCWSTR szStatusText)
213 {
214 MimeFilter *This = PROTSINK_THIS(iface);
215 FIXME("(%p)->(%u %s)\n", This, ulStatusCode, debugstr_w(szStatusText));
216 return E_NOTIMPL;
217 }
218
219 static HRESULT WINAPI MimeFilterSink_ReportData(IInternetProtocolSink *iface,
220 DWORD grfBSCF, ULONG ulProgress, ULONG ulProgressMax)
221 {
222 MimeFilter *This = PROTSINK_THIS(iface);
223 FIXME("(%p)->(%d %u %u)\n", This, grfBSCF, ulProgress, ulProgressMax);
224 return E_NOTIMPL;
225 }
226
227 static HRESULT WINAPI MimeFilterSink_ReportResult(IInternetProtocolSink *iface,
228 HRESULT hrResult, DWORD dwError, LPCWSTR szResult)
229 {
230 MimeFilter *This = PROTSINK_THIS(iface);
231 FIXME("(%p)->(%08x %d %s)\n", This, hrResult, dwError, debugstr_w(szResult));
232 return E_NOTIMPL;
233 }
234
235 #undef PROTSINK_THIS
236
237 static const IInternetProtocolSinkVtbl InternetProtocolSinkVtbl = {
238 MimeFilterSink_QueryInterface,
239 MimeFilterSink_AddRef,
240 MimeFilterSink_Release,
241 MimeFilterSink_Switch,
242 MimeFilterSink_ReportProgress,
243 MimeFilterSink_ReportData,
244 MimeFilterSink_ReportResult
245 };
246
247 HRESULT MimeFilter_Construct(IUnknown *pUnkOuter, LPVOID *ppobj)
248 {
249 MimeFilter *ret;
250
251 TRACE("(%p %p)\n", pUnkOuter, ppobj);
252
253 URLMON_LockModule();
254
255 ret = heap_alloc_zero(sizeof(MimeFilter));
256
257 ret->lpIInternetProtocolVtbl = &MimeFilterProtocolVtbl;
258 ret->lpIInternetProtocolSinkVtbl = &InternetProtocolSinkVtbl;
259 ret->ref = 1;
260
261 *ppobj = PROTOCOL(ret);
262 return S_OK;
263 }