[MSXML3] Sync with Wine Staging 1.9.16. CORE-11866
[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 XML_PARSER_STATE state;
35 } xmlparser;
36
37 static inline xmlparser *impl_from_IXMLParser( IXMLParser *iface )
38 {
39 return CONTAINING_RECORD(iface, xmlparser, IXMLParser_iface);
40 }
41
42 /*** IUnknown methods ***/
43 static HRESULT WINAPI xmlparser_QueryInterface(IXMLParser* iface, REFIID riid, void **ppvObject)
44 {
45 xmlparser *This = impl_from_IXMLParser( iface );
46 TRACE("(%p)->(%s %p)\n", This, debugstr_guid(riid), ppvObject);
47
48 if ( IsEqualGUID( riid, &IID_IXMLParser ) ||
49 IsEqualGUID( riid, &IID_IXMLNodeSource ) ||
50 IsEqualGUID( riid, &IID_IUnknown ) )
51 {
52 *ppvObject = iface;
53 }
54 else
55 {
56 TRACE("Unsupported interface %s\n", debugstr_guid(riid));
57 *ppvObject = NULL;
58 return E_NOINTERFACE;
59 }
60
61 IXMLParser_AddRef(iface);
62 return S_OK;
63 }
64
65 static ULONG WINAPI xmlparser_AddRef(IXMLParser* iface)
66 {
67 xmlparser *This = impl_from_IXMLParser( iface );
68 ULONG ref = InterlockedIncrement( &This->ref );
69 TRACE("(%p)->(%d)\n", This, ref);
70 return ref;
71 }
72
73 static ULONG WINAPI xmlparser_Release(IXMLParser* iface)
74 {
75 xmlparser *This = impl_from_IXMLParser( iface );
76 ULONG ref = InterlockedDecrement( &This->ref );
77
78 TRACE("(%p)->(%d)\n", This, ref);
79 if ( ref == 0 )
80 {
81 if(This->input)
82 IUnknown_Release(This->input);
83
84 if(This->nodefactory)
85 IXMLNodeFactory_Release(This->nodefactory);
86
87 heap_free( This );
88 }
89
90 return ref;
91 }
92
93 /*** IXMLNodeSource methods ***/
94 static HRESULT WINAPI xmlparser_SetFactory(IXMLParser *iface, IXMLNodeFactory *pNodeFactory)
95 {
96 xmlparser *This = impl_from_IXMLParser( iface );
97
98 TRACE("(%p %p)\n", This, pNodeFactory);
99
100 if(This->nodefactory)
101 IXMLNodeFactory_Release(This->nodefactory);
102
103 This->nodefactory = pNodeFactory;
104 if(This->nodefactory)
105 IXMLNodeFactory_AddRef(This->nodefactory);
106
107 return S_OK;
108 }
109
110 static HRESULT WINAPI xmlparser_GetFactory(IXMLParser *iface, IXMLNodeFactory **ppNodeFactory)
111 {
112 xmlparser *This = impl_from_IXMLParser( iface );
113
114 TRACE("(%p, %p)\n", This, ppNodeFactory);
115
116 if(!ppNodeFactory)
117 return E_INVALIDARG;
118
119 *ppNodeFactory = This->nodefactory;
120
121 if(*ppNodeFactory)
122 IXMLNodeFactory_AddRef(*ppNodeFactory);
123
124 return S_OK;
125 }
126
127 static HRESULT WINAPI xmlparser_Abort(IXMLParser *iface, BSTR bstrErrorInfo)
128 {
129 xmlparser *This = impl_from_IXMLParser( iface );
130
131 FIXME("(%p, %s)\n", This, debugstr_w(bstrErrorInfo));
132
133 return E_NOTIMPL;
134 }
135
136 static ULONG WINAPI xmlparser_GetLineNumber(IXMLParser *iface)
137 {
138 xmlparser *This = impl_from_IXMLParser( iface );
139
140 FIXME("(%p)\n", This);
141
142 return 0;
143 }
144
145 static ULONG WINAPI xmlparser_GetLinePosition(IXMLParser *iface)
146 {
147 xmlparser *This = impl_from_IXMLParser( iface );
148
149 FIXME("(%p)\n", This);
150
151 return 0;
152 }
153
154 static ULONG WINAPI xmlparser_GetAbsolutePosition(IXMLParser *iface)
155 {
156 xmlparser *This = impl_from_IXMLParser( iface );
157
158 FIXME("(%p)\n", This);
159
160 return 0;
161 }
162
163 static HRESULT WINAPI xmlparser_GetLineBuffer(IXMLParser *iface, const WCHAR **ppBuf,
164 ULONG *len, ULONG *startPos)
165 {
166 xmlparser *This = impl_from_IXMLParser( iface );
167
168 FIXME("(%p %p %p %p)\n", This, ppBuf, len, startPos);
169
170 return 0;
171 }
172
173 static HRESULT WINAPI xmlparser_GetLastError(IXMLParser *iface)
174 {
175 xmlparser *This = impl_from_IXMLParser( iface );
176
177 FIXME("(%p)\n", This);
178
179 return E_NOTIMPL;
180 }
181
182 static HRESULT WINAPI xmlparser_GetErrorInfo(IXMLParser *iface, BSTR *pErrorInfo)
183 {
184 xmlparser *This = impl_from_IXMLParser( iface );
185
186 FIXME("(%p %p)\n", This, pErrorInfo);
187
188 return E_NOTIMPL;
189 }
190
191 static ULONG WINAPI xmlparser_GetFlags(IXMLParser *iface)
192 {
193 xmlparser *This = impl_from_IXMLParser( iface );
194
195 TRACE("(%p)\n", This);
196
197 return This->flags;
198 }
199
200 static HRESULT WINAPI xmlparser_GetURL(IXMLParser *iface, const WCHAR **ppBuf)
201 {
202 xmlparser *This = impl_from_IXMLParser( iface );
203
204 FIXME("(%p %p)\n", This, ppBuf);
205
206 return E_NOTIMPL;
207 }
208
209 /*** IXMLParser methods ***/
210 static HRESULT WINAPI xmlparser_SetURL(IXMLParser *iface,const WCHAR *pszBaseUrl,
211 const WCHAR *relativeUrl, BOOL async)
212 {
213 xmlparser *This = impl_from_IXMLParser( iface );
214
215 FIXME("(%p %s %s %d)\n", This, debugstr_w(pszBaseUrl), debugstr_w(relativeUrl), async);
216
217 return E_NOTIMPL;
218 }
219
220 static HRESULT WINAPI xmlparser_Load(IXMLParser *iface, BOOL bFullyAvailable,
221 IMoniker *pMon, LPBC pBC, DWORD dwMode)
222 {
223 xmlparser *This = impl_from_IXMLParser( iface );
224
225 FIXME("(%p %d %p %p %d)\n", This, bFullyAvailable, pMon, pBC, dwMode);
226
227 return E_NOTIMPL;
228 }
229
230 static HRESULT WINAPI xmlparser_SetInput(IXMLParser *iface, IUnknown *pStm)
231 {
232 xmlparser *This = impl_from_IXMLParser( iface );
233
234 TRACE("(%p %p)\n", This, pStm);
235
236 if(!pStm)
237 return E_INVALIDARG;
238
239 if(This->input)
240 IUnknown_Release(This->input);
241
242 This->input = pStm;
243 IUnknown_AddRef(This->input);
244
245 return S_OK;
246 }
247
248 static HRESULT WINAPI xmlparser_PushData(IXMLParser *iface, const char *pData,
249 ULONG nChars, BOOL fLastBuffer)
250 {
251 xmlparser *This = impl_from_IXMLParser( iface );
252
253 FIXME("(%p %s %d %d)\n", This, debugstr_a(pData), nChars, fLastBuffer);
254
255 return E_NOTIMPL;
256 }
257
258 static HRESULT WINAPI xmlparser_LoadDTD(IXMLParser *iface, const WCHAR *baseUrl,
259 const WCHAR *relativeUrl)
260 {
261 xmlparser *This = impl_from_IXMLParser( iface );
262
263 FIXME("(%p %s %s)\n", This, debugstr_w(baseUrl), debugstr_w(relativeUrl));
264
265 return E_NOTIMPL;
266 }
267
268 static HRESULT WINAPI xmlparser_LoadEntity(IXMLParser *iface, const WCHAR *baseUrl,
269 const WCHAR *relativeUrl, BOOL fpe)
270 {
271 xmlparser *This = impl_from_IXMLParser( iface );
272
273 FIXME("(%p %s %s %d)\n", This, debugstr_w(baseUrl), debugstr_w(relativeUrl), fpe);
274
275 return E_NOTIMPL;
276 }
277
278 static HRESULT WINAPI xmlparser_ParseEntity(IXMLParser *iface, const WCHAR *text,
279 ULONG len, BOOL fpe)
280 {
281 xmlparser *This = impl_from_IXMLParser( iface );
282
283 FIXME("(%p %s %d %d)\n", This, debugstr_w(text), len, fpe);
284
285 return E_NOTIMPL;
286 }
287
288 static HRESULT WINAPI xmlparser_ExpandEntity(IXMLParser *iface, const WCHAR *text,
289 ULONG len)
290 {
291 xmlparser *This = impl_from_IXMLParser( iface );
292
293 FIXME("(%p %s %d)\n", This, debugstr_w(text), len);
294
295 return E_NOTIMPL;
296 }
297
298 static HRESULT WINAPI xmlparser_SetRoot(IXMLParser *iface, PVOID pRoot)
299 {
300 xmlparser *This = impl_from_IXMLParser( iface );
301
302 FIXME("(%p %p)\n", This, pRoot);
303
304 return E_NOTIMPL;
305 }
306
307 static HRESULT WINAPI xmlparser_GetRoot( IXMLParser *iface, PVOID *ppRoot)
308 {
309 xmlparser *This = impl_from_IXMLParser( iface );
310
311 FIXME("(%p %p)\n", This, ppRoot);
312
313 return E_NOTIMPL;
314 }
315
316 static HRESULT WINAPI xmlparser_Run(IXMLParser *iface, LONG chars)
317 {
318 xmlparser *This = impl_from_IXMLParser( iface );
319
320 FIXME("(%p %d)\n", This, chars);
321
322 return E_NOTIMPL;
323 }
324
325 static HRESULT WINAPI xmlparser_GetParserState(IXMLParser *iface)
326 {
327 xmlparser *This = impl_from_IXMLParser( iface );
328
329 TRACE("(%p)\n", This);
330
331 return This->state;
332 }
333
334 static HRESULT WINAPI xmlparser_Suspend(IXMLParser *iface)
335 {
336 xmlparser *This = impl_from_IXMLParser( iface );
337
338 FIXME("(%p)\n", This);
339
340 return E_NOTIMPL;
341 }
342
343 static HRESULT WINAPI xmlparser_Reset(IXMLParser *iface)
344 {
345 xmlparser *This = impl_from_IXMLParser( iface );
346
347 FIXME("(%p)\n", This);
348
349 return E_NOTIMPL;
350 }
351
352 static HRESULT WINAPI xmlparser_SetFlags(IXMLParser *iface, ULONG flags)
353 {
354 xmlparser *This = impl_from_IXMLParser( iface );
355
356 TRACE("(%p %d)\n", This, flags);
357
358 This->flags = flags;
359
360 return S_OK;
361 }
362
363 static HRESULT WINAPI xmlparser_SetSecureBaseURL(IXMLParser *iface, const WCHAR *baseUrl)
364 {
365 xmlparser *This = impl_from_IXMLParser( iface );
366
367 FIXME("(%p %s)\n", This, debugstr_w(baseUrl));
368
369 return E_NOTIMPL;
370 }
371
372 static HRESULT WINAPI xmlparser_GetSecureBaseURL( IXMLParser *iface, const WCHAR **ppBuf)
373 {
374 xmlparser *This = impl_from_IXMLParser( iface );
375
376 FIXME("(%p %p)\n", This, ppBuf);
377
378 return E_NOTIMPL;
379 }
380
381
382 static const struct IXMLParserVtbl xmlparser_vtbl =
383 {
384 xmlparser_QueryInterface,
385 xmlparser_AddRef,
386 xmlparser_Release,
387 xmlparser_SetFactory,
388 xmlparser_GetFactory,
389 xmlparser_Abort,
390 xmlparser_GetLineNumber,
391 xmlparser_GetLinePosition,
392 xmlparser_GetAbsolutePosition,
393 xmlparser_GetLineBuffer,
394 xmlparser_GetLastError,
395 xmlparser_GetErrorInfo,
396 xmlparser_GetFlags,
397 xmlparser_GetURL,
398 xmlparser_SetURL,
399 xmlparser_Load,
400 xmlparser_SetInput,
401 xmlparser_PushData,
402 xmlparser_LoadDTD,
403 xmlparser_LoadEntity,
404 xmlparser_ParseEntity,
405 xmlparser_ExpandEntity,
406 xmlparser_SetRoot,
407 xmlparser_GetRoot,
408 xmlparser_Run,
409 xmlparser_GetParserState,
410 xmlparser_Suspend,
411 xmlparser_Reset,
412 xmlparser_SetFlags,
413 xmlparser_SetSecureBaseURL,
414 xmlparser_GetSecureBaseURL
415 };
416
417 HRESULT XMLParser_create(void **ppObj)
418 {
419 xmlparser *This;
420
421 TRACE("(%p)\n", ppObj);
422
423 This = heap_alloc( sizeof(xmlparser) );
424 if(!This)
425 return E_OUTOFMEMORY;
426
427 This->IXMLParser_iface.lpVtbl = &xmlparser_vtbl;
428 This->nodefactory = NULL;
429 This->input = NULL;
430 This->flags = 0;
431 This->state = XMLPARSER_IDLE;
432 This->ref = 1;
433
434 *ppObj = &This->IXMLParser_iface;
435
436 TRACE("returning iface %p\n", *ppObj);
437
438 return S_OK;
439 }