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