2 * IXmlReader implementation
4 * Copyright 2010 Nikolay Sivov
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.
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.
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
30 #include "wine/debug.h"
32 WINE_DEFAULT_DEBUG_CHANNEL(xmllite);
34 /* not defined in public headers */
35 DEFINE_GUID(IID_IXmlReaderInput, 0x0b3ccc9b, 0x9214, 0x428b, 0xa2, 0xae, 0xef, 0x3a, 0xa8, 0x71, 0xaf, 0xda);
37 static HRESULT xmlreaderinput_query_for_stream(IXmlReaderInput *iface, void **pObj);
39 typedef struct _xmlreader
41 const IXmlReaderVtbl *lpVtbl;
43 IXmlReaderInput *input;
44 ISequentialStream *stream;/* stored as sequential stream, cause currently
45 optimizations possible with IStream aren't implemented */
47 UINT line, pos; /* reader position in XML stream */
50 typedef struct _xmlreaderinput
52 const IUnknownVtbl *lpVtbl;
54 IUnknown *input; /* reference passed on IXmlReaderInput creation */
57 static inline xmlreader *impl_from_IXmlReader(IXmlReader *iface)
59 return (xmlreader *)((char*)iface - FIELD_OFFSET(xmlreader, lpVtbl));
62 static inline xmlreaderinput *impl_from_IXmlReaderInput(IXmlReaderInput *iface)
64 return (xmlreaderinput *)((char*)iface - FIELD_OFFSET(xmlreaderinput, lpVtbl));
67 static HRESULT WINAPI xmlreader_QueryInterface(IXmlReader *iface, REFIID riid, void** ppvObject)
69 xmlreader *This = impl_from_IXmlReader(iface);
71 TRACE("%p %s %p\n", This, debugstr_guid(riid), ppvObject);
73 if (IsEqualGUID(riid, &IID_IUnknown) ||
74 IsEqualGUID(riid, &IID_IXmlReader))
80 FIXME("interface %s not implemented\n", debugstr_guid(riid));
84 IXmlReader_AddRef(iface);
89 static ULONG WINAPI xmlreader_AddRef(IXmlReader *iface)
91 xmlreader *This = impl_from_IXmlReader(iface);
93 return InterlockedIncrement(&This->ref);
96 static ULONG WINAPI xmlreader_Release(IXmlReader *iface)
98 xmlreader *This = impl_from_IXmlReader(iface);
103 ref = InterlockedDecrement(&This->ref);
106 if (This->input) IUnknown_Release(This->input);
107 if (This->stream) IUnknown_Release(This->stream);
108 HeapFree(GetProcessHeap(), 0, This);
114 static HRESULT WINAPI xmlreader_SetInput(IXmlReader* iface, IUnknown *input)
116 xmlreader *This = impl_from_IXmlReader(iface);
119 TRACE("(%p %p)\n", This, input);
123 IUnknown_Release(This->input);
129 IUnknown_Release(This->stream);
133 This->line = This->pos = 0;
135 /* just reset current input */
138 This->state = XmlReadState_Initial;
142 /* now try IXmlReaderInput, ISequentialStream, IStream */
143 hr = IUnknown_QueryInterface(input, &IID_IXmlReaderInput, (void**)&This->input);
146 /* create IXmlReaderInput basing on supplied interface */
147 hr = CreateXmlReaderInputWithEncodingName(input,
148 NULL, NULL, FALSE, NULL, &This->input);
149 if (hr != S_OK) return hr;
152 /* set stream for supplied IXmlReaderInput */
153 hr = xmlreaderinput_query_for_stream(This->input, (void**)&This->stream);
155 This->state = XmlReadState_Initial;
160 static HRESULT WINAPI xmlreader_GetProperty(IXmlReader* iface, UINT property, LONG_PTR *value)
162 xmlreader *This = impl_from_IXmlReader(iface);
164 TRACE("(%p %u %p)\n", This, property, value);
166 if (!value) return E_INVALIDARG;
170 case XmlReaderProperty_ReadState:
171 *value = This->state;
174 FIXME("Unimplemented property (%u)\n", property);
181 static HRESULT WINAPI xmlreader_SetProperty(IXmlReader* iface, UINT property, LONG_PTR value)
183 FIXME("(%p %u %lu): stub\n", iface, property, value);
187 static HRESULT WINAPI xmlreader_Read(IXmlReader* iface, XmlNodeType *node_type)
189 FIXME("(%p %p): stub\n", iface, node_type);
193 static HRESULT WINAPI xmlreader_GetNodeType(IXmlReader* iface, XmlNodeType *node_type)
195 FIXME("(%p %p): stub\n", iface, node_type);
199 static HRESULT WINAPI xmlreader_MoveToFirstAttribute(IXmlReader* iface)
201 FIXME("(%p): stub\n", iface);
205 static HRESULT WINAPI xmlreader_MoveToNextAttribute(IXmlReader* iface)
207 FIXME("(%p): stub\n", iface);
211 static HRESULT WINAPI xmlreader_MoveToAttributeByName(IXmlReader* iface,
213 LPCWSTR namespaceUri)
215 FIXME("(%p %p %p): stub\n", iface, local_name, namespaceUri);
219 static HRESULT WINAPI xmlreader_MoveToElement(IXmlReader* iface)
221 FIXME("(%p): stub\n", iface);
225 static HRESULT WINAPI xmlreader_GetQualifiedName(IXmlReader* iface, LPCWSTR *qualifiedName,
226 UINT *qualifiedName_length)
228 FIXME("(%p %p %p): stub\n", iface, qualifiedName, qualifiedName_length);
232 static HRESULT WINAPI xmlreader_GetNamespaceUri(IXmlReader* iface,
233 LPCWSTR *namespaceUri,
234 UINT *namespaceUri_length)
236 FIXME("(%p %p %p): stub\n", iface, namespaceUri, namespaceUri_length);
240 static HRESULT WINAPI xmlreader_GetLocalName(IXmlReader* iface,
242 UINT *local_name_length)
244 FIXME("(%p %p %p): stub\n", iface, local_name, local_name_length);
248 static HRESULT WINAPI xmlreader_GetPrefix(IXmlReader* iface,
252 FIXME("(%p %p %p): stub\n", iface, prefix, prefix_length);
256 static HRESULT WINAPI xmlreader_GetValue(IXmlReader* iface,
260 FIXME("(%p %p %p): stub\n", iface, value, value_length);
264 static HRESULT WINAPI xmlreader_ReadValueChunk(IXmlReader* iface,
269 FIXME("(%p %p %u %p): stub\n", iface, buffer, chunk_size, read);
273 static HRESULT WINAPI xmlreader_GetBaseUri(IXmlReader* iface,
275 UINT *baseUri_length)
277 FIXME("(%p %p %p): stub\n", iface, baseUri, baseUri_length);
281 static BOOL WINAPI xmlreader_IsDefault(IXmlReader* iface)
283 FIXME("(%p): stub\n", iface);
287 static BOOL WINAPI xmlreader_IsEmptyElement(IXmlReader* iface)
289 FIXME("(%p): stub\n", iface);
293 static HRESULT WINAPI xmlreader_GetLineNumber(IXmlReader* iface, UINT *lineNumber)
295 xmlreader *This = impl_from_IXmlReader(iface);
297 TRACE("(%p %p)\n", This, lineNumber);
299 if (!lineNumber) return E_INVALIDARG;
301 *lineNumber = This->line;
306 static HRESULT WINAPI xmlreader_GetLinePosition(IXmlReader* iface, UINT *linePosition)
308 xmlreader *This = impl_from_IXmlReader(iface);
310 TRACE("(%p %p)\n", This, linePosition);
312 if (!linePosition) return E_INVALIDARG;
314 *linePosition = This->pos;
319 static HRESULT WINAPI xmlreader_GetAttributeCount(IXmlReader* iface, UINT *attributeCount)
321 FIXME("(%p %p): stub\n", iface, attributeCount);
325 static HRESULT WINAPI xmlreader_GetDepth(IXmlReader* iface, UINT *depth)
327 FIXME("(%p %p): stub\n", iface, depth);
331 static BOOL WINAPI xmlreader_IsEOF(IXmlReader* iface)
333 FIXME("(%p): stub\n", iface);
337 static const struct IXmlReaderVtbl xmlreader_vtbl =
339 xmlreader_QueryInterface,
343 xmlreader_GetProperty,
344 xmlreader_SetProperty,
346 xmlreader_GetNodeType,
347 xmlreader_MoveToFirstAttribute,
348 xmlreader_MoveToNextAttribute,
349 xmlreader_MoveToAttributeByName,
350 xmlreader_MoveToElement,
351 xmlreader_GetQualifiedName,
352 xmlreader_GetNamespaceUri,
353 xmlreader_GetLocalName,
356 xmlreader_ReadValueChunk,
357 xmlreader_GetBaseUri,
359 xmlreader_IsEmptyElement,
360 xmlreader_GetLineNumber,
361 xmlreader_GetLinePosition,
362 xmlreader_GetAttributeCount,
367 /** IXmlReaderInput **/
369 /* Queries already stored interface for IStream/ISequentialStream.
370 Interface supplied on creation will be overwritten */
371 static HRESULT xmlreaderinput_query_for_stream(IXmlReaderInput *iface, void **pObj)
373 xmlreaderinput *This = impl_from_IXmlReaderInput(iface);
376 hr = IUnknown_QueryInterface(This->input, &IID_IStream, pObj);
378 hr = IUnknown_QueryInterface(This->input, &IID_ISequentialStream, pObj);
383 static HRESULT WINAPI xmlreaderinput_QueryInterface(IXmlReaderInput *iface, REFIID riid, void** ppvObject)
385 xmlreaderinput *This = impl_from_IXmlReaderInput(iface);
387 TRACE("%p %s %p\n", This, debugstr_guid(riid), ppvObject);
389 if (IsEqualGUID(riid, &IID_IXmlReaderInput) ||
390 IsEqualGUID(riid, &IID_IUnknown))
396 FIXME("interface %s not implemented\n", debugstr_guid(riid));
397 return E_NOINTERFACE;
400 IUnknown_AddRef(iface);
405 static ULONG WINAPI xmlreaderinput_AddRef(IXmlReaderInput *iface)
407 xmlreaderinput *This = impl_from_IXmlReaderInput(iface);
409 return InterlockedIncrement(&This->ref);
412 static ULONG WINAPI xmlreaderinput_Release(IXmlReaderInput *iface)
414 xmlreaderinput *This = impl_from_IXmlReaderInput(iface);
419 ref = InterlockedDecrement(&This->ref);
422 if (This->input) IUnknown_Release(This->input);
423 HeapFree(GetProcessHeap(), 0, This);
429 static const struct IUnknownVtbl xmlreaderinput_vtbl =
431 xmlreaderinput_QueryInterface,
432 xmlreaderinput_AddRef,
433 xmlreaderinput_Release
436 HRESULT WINAPI CreateXmlReader(REFIID riid, void **pObject, IMalloc *pMalloc)
440 TRACE("(%s, %p, %p)\n", wine_dbgstr_guid(riid), pObject, pMalloc);
442 if (pMalloc) FIXME("custom IMalloc not supported yet\n");
444 if (!IsEqualGUID(riid, &IID_IXmlReader))
446 ERR("Unexpected IID requested -> (%s)\n", wine_dbgstr_guid(riid));
450 reader = HeapAlloc(GetProcessHeap(), 0, sizeof (*reader));
451 if(!reader) return E_OUTOFMEMORY;
453 reader->lpVtbl = &xmlreader_vtbl;
455 reader->stream = NULL;
456 reader->input = NULL;
457 reader->state = XmlReadState_Closed;
458 reader->line = reader->pos = 0;
460 *pObject = &reader->lpVtbl;
462 TRACE("returning iface %p\n", *pObject);
467 HRESULT WINAPI CreateXmlReaderInputWithEncodingName(IUnknown *stream,
472 IXmlReaderInput **ppInput)
474 xmlreaderinput *readerinput;
476 FIXME("%p %p %s %d %s %p: stub\n", stream, pMalloc, wine_dbgstr_w(encoding),
477 hint, wine_dbgstr_w(base_uri), ppInput);
479 if (!stream || !ppInput) return E_INVALIDARG;
481 readerinput = HeapAlloc(GetProcessHeap(), 0, sizeof (*readerinput));
482 if(!readerinput) return E_OUTOFMEMORY;
484 readerinput->lpVtbl = &xmlreaderinput_vtbl;
485 readerinput->ref = 1;
486 IUnknown_QueryInterface(stream, &IID_IUnknown, (void**)&readerinput->input);
488 *ppInput = (IXmlReaderInput*)&readerinput->lpVtbl;
490 TRACE("returning iface %p\n", *ppInput);