[MSXML3]
[reactos.git] / reactos / dll / win32 / msxml3 / xmlparser.c
1 /*
2 * XML Parser implementation
3 *
4 * Copyright 2011 Alistair Leslie-Hughes
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19 */
20
21 #include "precomp.h"
22
23 #include <initguid.h>
24 #include "xmlparser.h"
25
26 typedef struct _xmlparser
27 {
28 IXMLParser IXMLParser_iface;
29 IXMLNodeFactory *nodefactory;
30 IUnknown *input;
31 LONG ref;
32
33 int flags;
34 } xmlparser;
35
36 static inline xmlparser *impl_from_IXMLParser( IXMLParser *iface )
37 {
38 return CONTAINING_RECORD(iface, xmlparser, IXMLParser_iface);
39 }
40
41 /*** IUnknown methods ***/
42 static HRESULT WINAPI xmlparser_QueryInterface(IXMLParser* iface, REFIID riid, void **ppvObject)
43 {
44 xmlparser *This = impl_from_IXMLParser( iface );
45 TRACE("(%p)->(%s %p)\n", This, debugstr_guid(riid), ppvObject);
46
47 if ( IsEqualGUID( riid, &IID_IXMLParser ) ||
48 IsEqualGUID( riid, &IID_IXMLNodeSource ) ||
49 IsEqualGUID( riid, &IID_IUnknown ) )
50 {
51 *ppvObject = iface;
52 }
53 else
54 {
55 TRACE("Unsupported interface %s\n", debugstr_guid(riid));
56 *ppvObject = NULL;
57 return E_NOINTERFACE;
58 }
59
60 IXMLParser_AddRef(iface);
61 return S_OK;
62 }
63
64 static ULONG WINAPI xmlparser_AddRef(IXMLParser* iface)
65 {
66 xmlparser *This = impl_from_IXMLParser( iface );
67 ULONG ref = InterlockedIncrement( &This->ref );
68 TRACE("(%p)->(%d)\n", This, ref);
69 return ref;
70 }
71
72 static ULONG WINAPI xmlparser_Release(IXMLParser* iface)
73 {
74 xmlparser *This = impl_from_IXMLParser( iface );
75 ULONG ref = InterlockedDecrement( &This->ref );
76
77 TRACE("(%p)->(%d)\n", This, ref);
78 if ( ref == 0 )
79 {
80 if(This->input)
81 IUnknown_Release(This->input);
82
83 if(This->nodefactory)
84 IXMLNodeFactory_Release(This->nodefactory);
85
86 heap_free( This );
87 }
88
89 return ref;
90 }
91
92 /*** IXMLNodeSource methods ***/
93 static HRESULT WINAPI xmlparser_SetFactory(IXMLParser *iface, IXMLNodeFactory *pNodeFactory)
94 {
95 xmlparser *This = impl_from_IXMLParser( iface );
96
97 TRACE("(%p %p)\n", This, pNodeFactory);
98
99 if(This->nodefactory)
100 IXMLNodeFactory_Release(This->nodefactory);
101
102 This->nodefactory = pNodeFactory;
103 if(This->nodefactory)
104 IXMLNodeFactory_AddRef(This->nodefactory);
105
106 return S_OK;
107 }
108
109 static HRESULT WINAPI xmlparser_GetFactory(IXMLParser *iface, IXMLNodeFactory **ppNodeFactory)
110 {
111 xmlparser *This = impl_from_IXMLParser( iface );
112
113 TRACE("(%p, %p)\n", This, ppNodeFactory);
114
115 if(!ppNodeFactory)
116 return E_INVALIDARG;
117
118 *ppNodeFactory = This->nodefactory;
119
120 if(*ppNodeFactory)
121 IXMLNodeFactory_AddRef(*ppNodeFactory);
122
123 return S_OK;
124 }
125
126 static HRESULT WINAPI xmlparser_Abort(IXMLParser *iface, BSTR bstrErrorInfo)
127 {
128 xmlparser *This = impl_from_IXMLParser( iface );
129
130 FIXME("(%p, %s)\n", This, debugstr_w(bstrErrorInfo));
131
132 return E_NOTIMPL;
133 }
134
135 static ULONG WINAPI xmlparser_GetLineNumber(IXMLParser *iface)
136 {
137 xmlparser *This = impl_from_IXMLParser( iface );
138
139 FIXME("(%p)\n", This);
140
141 return 0;
142 }
143
144 static ULONG WINAPI xmlparser_GetLinePosition(IXMLParser *iface)
145 {
146 xmlparser *This = impl_from_IXMLParser( iface );
147
148 FIXME("(%p)\n", This);
149
150 return 0;
151 }
152
153 static ULONG WINAPI xmlparser_GetAbsolutePosition(IXMLParser *iface)
154 {
155 xmlparser *This = impl_from_IXMLParser( iface );
156
157 FIXME("(%p)\n", This);
158
159 return 0;
160 }
161
162 static HRESULT WINAPI xmlparser_GetLineBuffer(IXMLParser *iface, const WCHAR **ppBuf,
163 ULONG *len, ULONG *startPos)
164 {
165 xmlparser *This = impl_from_IXMLParser( iface );
166
167 FIXME("(%p %p %p %p)\n", This, ppBuf, len, startPos);
168
169 return 0;
170 }
171
172 static HRESULT WINAPI xmlparser_GetLastError(IXMLParser *iface)
173 {
174 xmlparser *This = impl_from_IXMLParser( iface );
175
176 FIXME("(%p)\n", This);
177
178 return E_NOTIMPL;
179 }
180
181 static HRESULT WINAPI xmlparser_GetErrorInfo(IXMLParser *iface, BSTR *pErrorInfo)
182 {
183 xmlparser *This = impl_from_IXMLParser( iface );
184
185 FIXME("(%p %p)\n", This, pErrorInfo);
186
187 return E_NOTIMPL;
188 }
189
190 static ULONG WINAPI xmlparser_GetFlags(IXMLParser *iface)
191 {
192 xmlparser *This = impl_from_IXMLParser( iface );
193
194 TRACE("(%p)\n", This);
195
196 return This->flags;
197 }
198
199 static HRESULT WINAPI xmlparser_GetURL(IXMLParser *iface, const WCHAR **ppBuf)
200 {
201 xmlparser *This = impl_from_IXMLParser( iface );
202
203 FIXME("(%p %p)\n", This, ppBuf);
204
205 return E_NOTIMPL;
206 }
207
208 /*** IXMLParser methods ***/
209 static HRESULT WINAPI xmlparser_SetURL(IXMLParser *iface,const WCHAR *pszBaseUrl,
210 const WCHAR *relativeUrl, BOOL async)
211 {
212 xmlparser *This = impl_from_IXMLParser( iface );
213
214 FIXME("(%p %s %s %d)\n", This, debugstr_w(pszBaseUrl), debugstr_w(relativeUrl), async);
215
216 return E_NOTIMPL;
217 }
218
219 static HRESULT WINAPI xmlparser_Load(IXMLParser *iface, BOOL bFullyAvailable,
220 IMoniker *pMon, LPBC pBC, DWORD dwMode)
221 {
222 xmlparser *This = impl_from_IXMLParser( iface );
223
224 FIXME("(%p %d %p %p %d)\n", This, bFullyAvailable, pMon, pBC, dwMode);
225
226 return E_NOTIMPL;
227 }
228
229 static HRESULT WINAPI xmlparser_SetInput(IXMLParser *iface, IUnknown *pStm)
230 {
231 xmlparser *This = impl_from_IXMLParser( iface );
232
233 TRACE("(%p %p)\n", This, pStm);
234
235 if(!pStm)
236 return E_INVALIDARG;
237
238 if(This->input)
239 IUnknown_Release(This->input);
240
241 This->input = pStm;
242 IUnknown_AddRef(This->input);
243
244 return S_OK;
245 }
246
247 static HRESULT WINAPI xmlparser_PushData(IXMLParser *iface, const char *pData,
248 ULONG nChars, BOOL fLastBuffer)
249 {
250 xmlparser *This = impl_from_IXMLParser( iface );
251
252 FIXME("(%p %s %d %d)\n", This, debugstr_a(pData), nChars, fLastBuffer);
253
254 return E_NOTIMPL;
255 }
256
257 static HRESULT WINAPI xmlparser_LoadDTD(IXMLParser *iface, const WCHAR *baseUrl,
258 const WCHAR *relativeUrl)
259 {
260 xmlparser *This = impl_from_IXMLParser( iface );
261
262 FIXME("(%p %s %s)\n", This, debugstr_w(baseUrl), debugstr_w(relativeUrl));
263
264 return E_NOTIMPL;
265 }
266
267 static HRESULT WINAPI xmlparser_LoadEntity(IXMLParser *iface, const WCHAR *baseUrl,
268 const WCHAR *relativeUrl, BOOL fpe)
269 {
270 xmlparser *This = impl_from_IXMLParser( iface );
271
272 FIXME("(%p %s %s %d)\n", This, debugstr_w(baseUrl), debugstr_w(relativeUrl), fpe);
273
274 return E_NOTIMPL;
275 }
276
277 static HRESULT WINAPI xmlparser_ParseEntity(IXMLParser *iface, const WCHAR *text,
278 ULONG len, BOOL fpe)
279 {
280 xmlparser *This = impl_from_IXMLParser( iface );
281
282 FIXME("(%p %s %d %d)\n", This, debugstr_w(text), len, fpe);
283
284 return E_NOTIMPL;
285 }
286
287 static HRESULT WINAPI xmlparser_ExpandEntity(IXMLParser *iface, const WCHAR *text,
288 ULONG len)
289 {
290 xmlparser *This = impl_from_IXMLParser( iface );
291
292 FIXME("(%p %s %d)\n", This, debugstr_w(text), len);
293
294 return E_NOTIMPL;
295 }
296
297 static HRESULT WINAPI xmlparser_SetRoot(IXMLParser *iface, PVOID pRoot)
298 {
299 xmlparser *This = impl_from_IXMLParser( iface );
300
301 FIXME("(%p %p)\n", This, pRoot);
302
303 return E_NOTIMPL;
304 }
305
306 static HRESULT WINAPI xmlparser_GetRoot( IXMLParser *iface, PVOID *ppRoot)
307 {
308 xmlparser *This = impl_from_IXMLParser( iface );
309
310 FIXME("(%p %p)\n", This, ppRoot);
311
312 return E_NOTIMPL;
313 }
314
315 static HRESULT WINAPI xmlparser_Run(IXMLParser *iface, LONG chars)
316 {
317 xmlparser *This = impl_from_IXMLParser( iface );
318
319 FIXME("(%p %d)\n", This, chars);
320
321 return E_NOTIMPL;
322 }
323
324 static HRESULT WINAPI xmlparser_GetParserState(IXMLParser *iface)
325 {
326 xmlparser *This = impl_from_IXMLParser( iface );
327
328 FIXME("(%p)\n", This);
329
330 return E_NOTIMPL;
331 }
332
333 static HRESULT WINAPI xmlparser_Suspend(IXMLParser *iface)
334 {
335 xmlparser *This = impl_from_IXMLParser( iface );
336
337 FIXME("(%p)\n", This);
338
339 return E_NOTIMPL;
340 }
341
342 static HRESULT WINAPI xmlparser_Reset(IXMLParser *iface)
343 {
344 xmlparser *This = impl_from_IXMLParser( iface );
345
346 FIXME("(%p)\n", This);
347
348 return E_NOTIMPL;
349 }
350
351 static HRESULT WINAPI xmlparser_SetFlags(IXMLParser *iface, ULONG flags)
352 {
353 xmlparser *This = impl_from_IXMLParser( iface );
354
355 TRACE("(%p %d)\n", This, flags);
356
357 This->flags = flags;
358
359 return S_OK;
360 }
361
362 static HRESULT WINAPI xmlparser_SetSecureBaseURL(IXMLParser *iface, const WCHAR *baseUrl)
363 {
364 xmlparser *This = impl_from_IXMLParser( iface );
365
366 FIXME("(%p %s)\n", This, debugstr_w(baseUrl));
367
368 return E_NOTIMPL;
369 }
370
371 static HRESULT WINAPI xmlparser_GetSecureBaseURL( IXMLParser *iface, const WCHAR **ppBuf)
372 {
373 xmlparser *This = impl_from_IXMLParser( iface );
374
375 FIXME("(%p %p)\n", This, ppBuf);
376
377 return E_NOTIMPL;
378 }
379
380
381 static const struct IXMLParserVtbl xmlparser_vtbl =
382 {
383 xmlparser_QueryInterface,
384 xmlparser_AddRef,
385 xmlparser_Release,
386 xmlparser_SetFactory,
387 xmlparser_GetFactory,
388 xmlparser_Abort,
389 xmlparser_GetLineNumber,
390 xmlparser_GetLinePosition,
391 xmlparser_GetAbsolutePosition,
392 xmlparser_GetLineBuffer,
393 xmlparser_GetLastError,
394 xmlparser_GetErrorInfo,
395 xmlparser_GetFlags,
396 xmlparser_GetURL,
397 xmlparser_SetURL,
398 xmlparser_Load,
399 xmlparser_SetInput,
400 xmlparser_PushData,
401 xmlparser_LoadDTD,
402 xmlparser_LoadEntity,
403 xmlparser_ParseEntity,
404 xmlparser_ExpandEntity,
405 xmlparser_SetRoot,
406 xmlparser_GetRoot,
407 xmlparser_Run,
408 xmlparser_GetParserState,
409 xmlparser_Suspend,
410 xmlparser_Reset,
411 xmlparser_SetFlags,
412 xmlparser_SetSecureBaseURL,
413 xmlparser_GetSecureBaseURL
414 };
415
416 HRESULT XMLParser_create(IUnknown* pUnkOuter, void**ppObj)
417 {
418 xmlparser *This;
419
420 TRACE("(%p,%p)\n", pUnkOuter, ppObj);
421
422 if (pUnkOuter)
423 FIXME("support aggregation, outer\n");
424
425 This = heap_alloc( sizeof(xmlparser) );
426 if(!This)
427 return E_OUTOFMEMORY;
428
429 This->IXMLParser_iface.lpVtbl = &xmlparser_vtbl;
430 This->nodefactory = NULL;
431 This->input = NULL;
432 This->flags = 0;
433 This->ref = 1;
434
435 *ppObj = &This->IXMLParser_iface;
436
437 TRACE("returning iface %p\n", *ppObj);
438
439 return S_OK;
440 }