ReactOS  0.4.15-dev-2947-g59e1b78
xmlparser.c
Go to the documentation of this file.
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 
45 
46 typedef struct _xmlparser
47 {
48  IXMLParser IXMLParser_iface;
49  IXMLNodeFactory *nodefactory;
52 
53  int flags;
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 {
66  TRACE("(%p)->(%s %p)\n", This, debugstr_guid(riid), ppvObject);
67 
68  if ( IsEqualGUID( riid, &IID_IXMLParser ) ||
69  IsEqualGUID( riid, &IID_IXMLNodeSource ) ||
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 {
89  TRACE("(%p)->(%d)\n", This, ref);
90  return ref;
91 }
92 
93 static ULONG WINAPI xmlparser_Release(IXMLParser* iface)
94 {
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 {
435 };
436 
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 }
static HRESULT WINAPI xmlparser_GetURL(IXMLParser *iface, const WCHAR **ppBuf)
Definition: xmlparser.c:220
static HRESULT WINAPI xmlparser_Suspend(IXMLParser *iface)
Definition: xmlparser.c:354
XML_PARSER_STATE state
Definition: xmlparser.c:54
#define REFIID
Definition: guiddef.h:118
#define E_NOINTERFACE
Definition: winerror.h:2364
LONG ref
Definition: xmlparser.c:51
static HRESULT WINAPI xmlparser_GetLastError(IXMLParser *iface)
Definition: xmlparser.c:193
struct _xmlparser xmlparser
interface IBindCtx * LPBC
Definition: objfwd.h:18
static HRESULT WINAPI xmlparser_LoadDTD(IXMLParser *iface, const WCHAR *baseUrl, const WCHAR *relativeUrl)
Definition: xmlparser.c:278
static HRESULT WINAPI xmlparser_Reset(IXMLParser *iface)
Definition: xmlparser.c:363
static HRESULT WINAPI xmlparser_Run(IXMLParser *iface, LONG chars)
Definition: xmlparser.c:336
REFIID riid
Definition: precomp.h:44
IUnknown * input
Definition: xmlparser.c:50
const WCHAR * text
Definition: package.c:1827
static HRESULT WINAPI xmlparser_SetSecureBaseURL(IXMLParser *iface, const WCHAR *baseUrl)
Definition: xmlparser.c:383
static HRESULT WINAPI xmlparser_PushData(IXMLParser *iface, const char *pData, ULONG nChars, BOOL fLastBuffer)
Definition: xmlparser.c:268
static HRESULT WINAPI xmlparser_GetParserState(IXMLParser *iface)
Definition: xmlparser.c:345
OLECHAR * BSTR
Definition: compat.h:2152
static HRESULT WINAPI xmlparser_GetErrorInfo(IXMLParser *iface, BSTR *pErrorInfo)
Definition: xmlparser.c:202
static HRESULT WINAPI xmlparser_ParseEntity(IXMLParser *iface, const WCHAR *text, ULONG len, BOOL fpe)
Definition: xmlparser.c:298
Definition: send.c:48
static void * heap_alloc(size_t len)
Definition: appwiz.h:65
HRESULT XMLParser_create(void **ppObj)
Definition: xmlparser.c:437
static HRESULT WINAPI xmlparser_Load(IXMLParser *iface, BOOL bFullyAvailable, IMoniker *pMon, LPBC pBC, DWORD dwMode)
Definition: xmlparser.c:240
#define E_OUTOFMEMORY
Definition: ddrawi.h:100
unsigned int BOOL
Definition: ntddk_ex.h:94
long LONG
Definition: pedump.c:60
#define debugstr_w
Definition: kernel32.h:32
GLenum GLint ref
Definition: glext.h:6028
#define FIXME(fmt,...)
Definition: debug.h:111
static ULONG WINAPI xmlparser_AddRef(IXMLParser *iface)
Definition: xmlparser.c:85
static HRESULT WINAPI xmlparser_SetInput(IXMLParser *iface, IUnknown *pStm)
Definition: xmlparser.c:250
#define E_INVALIDARG
Definition: ddrawi.h:101
static HRESULT WINAPI xmlparser_QueryInterface(IXMLParser *iface, REFIID riid, void **ppvObject)
Definition: xmlparser.c:63
static HRESULT WINAPI xmlparser_GetSecureBaseURL(IXMLParser *iface, const WCHAR **ppBuf)
Definition: xmlparser.c:392
WINE_DEFAULT_DEBUG_CHANNEL(msxml)
static xmlparser * impl_from_IXMLParser(IXMLParser *iface)
Definition: xmlparser.c:57
static HRESULT WINAPI xmlparser_SetFactory(IXMLParser *iface, IXMLNodeFactory *pNodeFactory)
Definition: xmlparser.c:114
static HRESULT WINAPI xmlparser_GetLineBuffer(IXMLParser *iface, const WCHAR **ppBuf, ULONG *len, ULONG *startPos)
Definition: xmlparser.c:183
#define debugstr_guid
Definition: kernel32.h:35
PFLT_MESSAGE_WAITER_QUEUE CONTAINING_RECORD(Csq, DEVICE_EXTENSION, IrpQueue)) -> WaiterQ.mLock) _IRQL_raises_(DISPATCH_LEVEL) VOID NTAPI FltpAcquireMessageWaiterLock(_In_ PIO_CSQ Csq, _Out_ PKIRQL Irql)
Definition: Messaging.c:560
static ULONG WINAPI xmlparser_GetLinePosition(IXMLParser *iface)
Definition: xmlparser.c:165
static ULONG WINAPI xmlparser_GetLineNumber(IXMLParser *iface)
Definition: xmlparser.c:156
static ULONG WINAPI xmlparser_Release(IXMLParser *iface)
Definition: xmlparser.c:93
#define TRACE(s)
Definition: solgame.cpp:4
__wchar_t WCHAR
Definition: xmlstorage.h:180
IXMLParser IXMLParser_iface
Definition: xmlparser.c:48
#define debugstr_a
Definition: kernel32.h:31
LONG HRESULT
Definition: typedefs.h:79
const GUID IID_IUnknown
static HRESULT WINAPI xmlparser_LoadEntity(IXMLParser *iface, const WCHAR *baseUrl, const WCHAR *relativeUrl, BOOL fpe)
Definition: xmlparser.c:288
#define WINAPI
Definition: msvc.h:6
static HRESULT WINAPI xmlparser_GetFactory(IXMLParser *iface, IXMLNodeFactory **ppNodeFactory)
Definition: xmlparser.c:130
unsigned long DWORD
Definition: ntddk_ex.h:95
GLbitfield flags
Definition: glext.h:7161
static HRESULT WINAPI xmlparser_ExpandEntity(IXMLParser *iface, const WCHAR *text, ULONG len)
Definition: xmlparser.c:308
#define InterlockedDecrement
Definition: armddk.h:52
GLenum GLsizei len
Definition: glext.h:6722
REFIID LPVOID * ppvObject
Definition: precomp.h:44
#define S_OK
Definition: intsafe.h:51
static HRESULT WINAPI xmlparser_SetRoot(IXMLParser *iface, PVOID pRoot)
Definition: xmlparser.c:318
static HRESULT WINAPI xmlparser_Abort(IXMLParser *iface, BSTR bstrErrorInfo)
Definition: xmlparser.c:147
#define InterlockedIncrement
Definition: armddk.h:53
static const struct IXMLParserVtbl xmlparser_vtbl
Definition: xmlparser.c:402
#define E_NOTIMPL
Definition: ddrawi.h:99
#define NULL
Definition: types.h:112
BOOL WINAPI IsEqualGUID(REFGUID rguid1, REFGUID rguid2)
Definition: compobj.c:4112
unsigned int ULONG
Definition: retypes.h:1
static HRESULT WINAPI xmlparser_GetRoot(IXMLParser *iface, PVOID *ppRoot)
Definition: xmlparser.c:327
IXMLNodeFactory * nodefactory
Definition: xmlparser.c:49
static HRESULT WINAPI xmlparser_SetFlags(IXMLParser *iface, ULONG flags)
Definition: xmlparser.c:372
XML_PARSER_STATE
Definition: xmlparser.idl:193
TW_UINT32 TW_UINT16 TW_UINT16 TW_MEMREF pData
Definition: twain.h:1827
int flags
Definition: xmlparser.c:53
static ULONG WINAPI xmlparser_GetAbsolutePosition(IXMLParser *iface)
Definition: xmlparser.c:174
static HRESULT WINAPI xmlparser_SetURL(IXMLParser *iface, const WCHAR *pszBaseUrl, const WCHAR *relativeUrl, BOOL async)
Definition: xmlparser.c:230
static BOOL heap_free(void *mem)
Definition: appwiz.h:75
static ULONG WINAPI xmlparser_GetFlags(IXMLParser *iface)
Definition: xmlparser.c:211