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 typedef struct _xmlreader
39 const IXmlReaderVtbl
*lpVtbl
;
41 IXmlReaderInput
*input
;
44 typedef struct _xmlreaderinput
46 const IUnknownVtbl
*lpVtbl
;
50 static inline xmlreader
*impl_from_IXmlReader(IXmlReader
*iface
)
52 return (xmlreader
*)((char*)iface
- FIELD_OFFSET(xmlreader
, lpVtbl
));
55 static inline xmlreaderinput
*impl_from_IXmlReaderInput(IXmlReaderInput
*iface
)
57 return (xmlreaderinput
*)((char*)iface
- FIELD_OFFSET(xmlreaderinput
, lpVtbl
));
60 static HRESULT WINAPI
xmlreader_QueryInterface(IXmlReader
*iface
, REFIID riid
, void** ppvObject
)
62 xmlreader
*This
= impl_from_IXmlReader(iface
);
64 TRACE("%p %s %p\n", This
, debugstr_guid(riid
), ppvObject
);
66 if (IsEqualGUID(riid
, &IID_IUnknown
) ||
67 IsEqualGUID(riid
, &IID_IXmlReader
))
73 FIXME("interface %s not implemented\n", debugstr_guid(riid
));
77 IXmlReader_AddRef(iface
);
82 static ULONG WINAPI
xmlreader_AddRef(IXmlReader
*iface
)
84 xmlreader
*This
= impl_from_IXmlReader(iface
);
86 return InterlockedIncrement(&This
->ref
);
89 static ULONG WINAPI
xmlreader_Release(IXmlReader
*iface
)
91 xmlreader
*This
= impl_from_IXmlReader(iface
);
96 ref
= InterlockedDecrement(&This
->ref
);
99 if (This
->input
) IUnknown_Release(This
->input
);
100 HeapFree(GetProcessHeap(), 0, This
);
106 static HRESULT WINAPI
xmlreader_SetInput(IXmlReader
* iface
, IUnknown
*input
)
108 xmlreader
*This
= impl_from_IXmlReader(iface
);
111 TRACE("(%p %p)\n", This
, input
);
115 IUnknown_Release(This
->input
);
119 /* just reset current input */
120 if (!input
) return S_OK
;
122 /* now try IXmlReaderInput, ISequentialStream, IStream */
123 hr
= IUnknown_QueryInterface(input
, &IID_IXmlReaderInput
, (void**)&This
->input
);
126 IUnknown
*stream_input
= NULL
;
128 hr
= IUnknown_QueryInterface(input
, &IID_ISequentialStream
, (void**)&stream_input
);
131 hr
= IUnknown_QueryInterface(input
, &IID_IStream
, (void**)&stream_input
);
132 if (hr
!= S_OK
) return hr
;
135 /* create IXmlReaderInput basing on supplied interface */
136 IUnknown_Release(stream_input
);
137 return CreateXmlReaderInputWithEncodingName(stream_input
,
138 NULL
, NULL
, FALSE
, NULL
, &This
->input
);
144 static HRESULT WINAPI
xmlreader_GetProperty(IXmlReader
* iface
, UINT property
, LONG_PTR
*value
)
146 FIXME("(%p %u %p): stub\n", iface
, property
, value
);
150 static HRESULT WINAPI
xmlreader_SetProperty(IXmlReader
* iface
, UINT property
, LONG_PTR value
)
152 FIXME("(%p %u %lu): stub\n", iface
, property
, value
);
156 static HRESULT WINAPI
xmlreader_Read(IXmlReader
* iface
, XmlNodeType
*node_type
)
158 FIXME("(%p %p): stub\n", iface
, node_type
);
162 static HRESULT WINAPI
xmlreader_GetNodeType(IXmlReader
* iface
, XmlNodeType
*node_type
)
164 FIXME("(%p %p): stub\n", iface
, node_type
);
168 static HRESULT WINAPI
xmlreader_MoveToFirstAttribute(IXmlReader
* iface
)
170 FIXME("(%p): stub\n", iface
);
174 static HRESULT WINAPI
xmlreader_MoveToNextAttribute(IXmlReader
* iface
)
176 FIXME("(%p): stub\n", iface
);
180 static HRESULT WINAPI
xmlreader_MoveToAttributeByName(IXmlReader
* iface
,
182 LPCWSTR namespaceUri
)
184 FIXME("(%p %p %p): stub\n", iface
, local_name
, namespaceUri
);
188 static HRESULT WINAPI
xmlreader_MoveToElement(IXmlReader
* iface
)
190 FIXME("(%p): stub\n", iface
);
194 static HRESULT WINAPI
xmlreader_GetQualifiedName(IXmlReader
* iface
, LPCWSTR
*qualifiedName
,
195 UINT
*qualifiedName_length
)
197 FIXME("(%p %p %p): stub\n", iface
, qualifiedName
, qualifiedName_length
);
201 static HRESULT WINAPI
xmlreader_GetNamespaceUri(IXmlReader
* iface
,
202 LPCWSTR
*namespaceUri
,
203 UINT
*namespaceUri_length
)
205 FIXME("(%p %p %p): stub\n", iface
, namespaceUri
, namespaceUri_length
);
209 static HRESULT WINAPI
xmlreader_GetLocalName(IXmlReader
* iface
,
211 UINT
*local_name_length
)
213 FIXME("(%p %p %p): stub\n", iface
, local_name
, local_name_length
);
217 static HRESULT WINAPI
xmlreader_GetPrefix(IXmlReader
* iface
,
221 FIXME("(%p %p %p): stub\n", iface
, prefix
, prefix_length
);
225 static HRESULT WINAPI
xmlreader_GetValue(IXmlReader
* iface
,
229 FIXME("(%p %p %p): stub\n", iface
, value
, value_length
);
233 static HRESULT WINAPI
xmlreader_ReadValueChunk(IXmlReader
* iface
,
238 FIXME("(%p %p %u %p): stub\n", iface
, buffer
, chunk_size
, read
);
242 static HRESULT WINAPI
xmlreader_GetBaseUri(IXmlReader
* iface
,
244 UINT
*baseUri_length
)
246 FIXME("(%p %p %p): stub\n", iface
, baseUri
, baseUri_length
);
250 static BOOL WINAPI
xmlreader_IsDefault(IXmlReader
* iface
)
252 FIXME("(%p): stub\n", iface
);
256 static BOOL WINAPI
xmlreader_IsEmptyElement(IXmlReader
* iface
)
258 FIXME("(%p): stub\n", iface
);
262 static HRESULT WINAPI
xmlreader_GetLineNumber(IXmlReader
* iface
, UINT
*lineNumber
)
264 FIXME("(%p %p): stub\n", iface
, lineNumber
);
268 static HRESULT WINAPI
xmlreader_GetLinePosition(IXmlReader
* iface
, UINT
*linePosition
)
270 FIXME("(%p %p): stub\n", iface
, linePosition
);
274 static HRESULT WINAPI
xmlreader_GetAttributeCount(IXmlReader
* iface
, UINT
*attributeCount
)
276 FIXME("(%p %p): stub\n", iface
, attributeCount
);
280 static HRESULT WINAPI
xmlreader_GetDepth(IXmlReader
* iface
, UINT
*depth
)
282 FIXME("(%p %p): stub\n", iface
, depth
);
286 static BOOL WINAPI
xmlreader_IsEOF(IXmlReader
* iface
)
288 FIXME("(%p): stub\n", iface
);
292 static const struct IXmlReaderVtbl xmlreader_vtbl
=
294 xmlreader_QueryInterface
,
298 xmlreader_GetProperty
,
299 xmlreader_SetProperty
,
301 xmlreader_GetNodeType
,
302 xmlreader_MoveToFirstAttribute
,
303 xmlreader_MoveToNextAttribute
,
304 xmlreader_MoveToAttributeByName
,
305 xmlreader_MoveToElement
,
306 xmlreader_GetQualifiedName
,
307 xmlreader_GetNamespaceUri
,
308 xmlreader_GetLocalName
,
311 xmlreader_ReadValueChunk
,
312 xmlreader_GetBaseUri
,
314 xmlreader_IsEmptyElement
,
315 xmlreader_GetLineNumber
,
316 xmlreader_GetLinePosition
,
317 xmlreader_GetAttributeCount
,
322 /* IXmlReaderInput */
323 static HRESULT WINAPI
xmlreaderinput_QueryInterface(IXmlReaderInput
*iface
, REFIID riid
, void** ppvObject
)
325 xmlreaderinput
*This
= impl_from_IXmlReaderInput(iface
);
327 TRACE("%p %s %p\n", This
, debugstr_guid(riid
), ppvObject
);
329 if (IsEqualGUID(riid
, &IID_IXmlReaderInput
) ||
330 IsEqualGUID(riid
, &IID_IUnknown
))
336 FIXME("interface %s not implemented\n", debugstr_guid(riid
));
337 return E_NOINTERFACE
;
340 IUnknown_AddRef(iface
);
345 static ULONG WINAPI
xmlreaderinput_AddRef(IXmlReaderInput
*iface
)
347 xmlreaderinput
*This
= impl_from_IXmlReaderInput(iface
);
349 return InterlockedIncrement(&This
->ref
);
352 static ULONG WINAPI
xmlreaderinput_Release(IXmlReaderInput
*iface
)
354 xmlreaderinput
*This
= impl_from_IXmlReaderInput(iface
);
359 ref
= InterlockedDecrement(&This
->ref
);
362 HeapFree(GetProcessHeap(), 0, This
);
368 static const struct IUnknownVtbl xmlreaderinput_vtbl
=
370 xmlreaderinput_QueryInterface
,
371 xmlreaderinput_AddRef
,
372 xmlreaderinput_Release
375 HRESULT WINAPI
CreateXmlReader(REFIID riid
, void **pObject
, IMalloc
*pMalloc
)
379 TRACE("(%s, %p, %p)\n", wine_dbgstr_guid(riid
), pObject
, pMalloc
);
381 if (pMalloc
) FIXME("custom IMalloc not supported yet\n");
383 if (!IsEqualGUID(riid
, &IID_IXmlReader
))
385 ERR("Unexpected IID requested -> (%s)\n", wine_dbgstr_guid(riid
));
389 reader
= HeapAlloc(GetProcessHeap(), 0, sizeof (*reader
));
390 if(!reader
) return E_OUTOFMEMORY
;
392 reader
->lpVtbl
= &xmlreader_vtbl
;
394 reader
->input
= NULL
;
396 *pObject
= &reader
->lpVtbl
;
398 TRACE("returning iface %p\n", *pObject
);
403 HRESULT WINAPI
CreateXmlReaderInputWithEncodingName(IUnknown
*stream
,
408 IXmlReaderInput
**ppInput
)
410 xmlreaderinput
*readerinput
;
412 FIXME("%p %p %s %d %s %p: stub\n", stream
, pMalloc
, wine_dbgstr_w(encoding
),
413 hint
, wine_dbgstr_w(base_uri
), ppInput
);
415 if (!stream
|| !ppInput
) return E_INVALIDARG
;
417 readerinput
= HeapAlloc(GetProcessHeap(), 0, sizeof (*readerinput
));
418 if(!readerinput
) return E_OUTOFMEMORY
;
420 readerinput
->lpVtbl
= &xmlreaderinput_vtbl
;
421 readerinput
->ref
= 1;
423 *ppInput
= (IXmlReaderInput
*)&readerinput
->lpVtbl
;
425 TRACE("returning iface %p\n", *ppInput
);