Release 1.1.37.
[wine/gsoc-2012-control.git] / dlls / xmllite / reader.c
blob97476d9bbb760cd17e96f141c740ca205d5dd049
1 /*
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
21 #define COBJMACROS
23 #include <stdarg.h>
24 #include "windef.h"
25 #include "winbase.h"
26 #include "initguid.h"
27 #include "objbase.h"
28 #include "xmllite.h"
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;
40 LONG ref;
41 IXmlReaderInput *input;
42 } xmlreader;
44 typedef struct _xmlreaderinput
46 const IUnknownVtbl *lpVtbl;
47 LONG ref;
48 } xmlreaderinput;
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))
69 *ppvObject = iface;
71 else
73 FIXME("interface %s not implemented\n", debugstr_guid(riid));
74 return E_NOINTERFACE;
77 IXmlReader_AddRef(iface);
79 return S_OK;
82 static ULONG WINAPI xmlreader_AddRef(IXmlReader *iface)
84 xmlreader *This = impl_from_IXmlReader(iface);
85 TRACE("%p\n", This);
86 return InterlockedIncrement(&This->ref);
89 static ULONG WINAPI xmlreader_Release(IXmlReader *iface)
91 xmlreader *This = impl_from_IXmlReader(iface);
92 LONG ref;
94 TRACE("%p\n", This);
96 ref = InterlockedDecrement(&This->ref);
97 if (ref == 0)
99 if (This->input) IUnknown_Release(This->input);
100 HeapFree(GetProcessHeap(), 0, This);
103 return ref;
106 static HRESULT WINAPI xmlreader_SetInput(IXmlReader* iface, IUnknown *input)
108 xmlreader *This = impl_from_IXmlReader(iface);
109 HRESULT hr;
111 TRACE("(%p %p)\n", This, input);
113 if (This->input)
115 IUnknown_Release(This->input);
116 This->input = NULL;
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);
124 if (hr != S_OK)
126 IUnknown *stream_input = NULL;
128 hr = IUnknown_QueryInterface(input, &IID_ISequentialStream, (void**)&stream_input);
129 if (hr != S_OK)
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);
141 return S_OK;
144 static HRESULT WINAPI xmlreader_GetProperty(IXmlReader* iface, UINT property, LONG_PTR *value)
146 FIXME("(%p %u %p): stub\n", iface, property, value);
147 return E_NOTIMPL;
150 static HRESULT WINAPI xmlreader_SetProperty(IXmlReader* iface, UINT property, LONG_PTR value)
152 FIXME("(%p %u %lu): stub\n", iface, property, value);
153 return E_NOTIMPL;
156 static HRESULT WINAPI xmlreader_Read(IXmlReader* iface, XmlNodeType *node_type)
158 FIXME("(%p %p): stub\n", iface, node_type);
159 return E_NOTIMPL;
162 static HRESULT WINAPI xmlreader_GetNodeType(IXmlReader* iface, XmlNodeType *node_type)
164 FIXME("(%p %p): stub\n", iface, node_type);
165 return E_NOTIMPL;
168 static HRESULT WINAPI xmlreader_MoveToFirstAttribute(IXmlReader* iface)
170 FIXME("(%p): stub\n", iface);
171 return E_NOTIMPL;
174 static HRESULT WINAPI xmlreader_MoveToNextAttribute(IXmlReader* iface)
176 FIXME("(%p): stub\n", iface);
177 return E_NOTIMPL;
180 static HRESULT WINAPI xmlreader_MoveToAttributeByName(IXmlReader* iface,
181 LPCWSTR local_name,
182 LPCWSTR namespaceUri)
184 FIXME("(%p %p %p): stub\n", iface, local_name, namespaceUri);
185 return E_NOTIMPL;
188 static HRESULT WINAPI xmlreader_MoveToElement(IXmlReader* iface)
190 FIXME("(%p): stub\n", iface);
191 return E_NOTIMPL;
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);
198 return E_NOTIMPL;
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);
206 return E_NOTIMPL;
209 static HRESULT WINAPI xmlreader_GetLocalName(IXmlReader* iface,
210 LPCWSTR *local_name,
211 UINT *local_name_length)
213 FIXME("(%p %p %p): stub\n", iface, local_name, local_name_length);
214 return E_NOTIMPL;
217 static HRESULT WINAPI xmlreader_GetPrefix(IXmlReader* iface,
218 LPCWSTR *prefix,
219 UINT *prefix_length)
221 FIXME("(%p %p %p): stub\n", iface, prefix, prefix_length);
222 return E_NOTIMPL;
225 static HRESULT WINAPI xmlreader_GetValue(IXmlReader* iface,
226 LPCWSTR *value,
227 UINT *value_length)
229 FIXME("(%p %p %p): stub\n", iface, value, value_length);
230 return E_NOTIMPL;
233 static HRESULT WINAPI xmlreader_ReadValueChunk(IXmlReader* iface,
234 WCHAR *buffer,
235 UINT chunk_size,
236 UINT *read)
238 FIXME("(%p %p %u %p): stub\n", iface, buffer, chunk_size, read);
239 return E_NOTIMPL;
242 static HRESULT WINAPI xmlreader_GetBaseUri(IXmlReader* iface,
243 LPCWSTR *baseUri,
244 UINT *baseUri_length)
246 FIXME("(%p %p %p): stub\n", iface, baseUri, baseUri_length);
247 return E_NOTIMPL;
250 static BOOL WINAPI xmlreader_IsDefault(IXmlReader* iface)
252 FIXME("(%p): stub\n", iface);
253 return E_NOTIMPL;
256 static BOOL WINAPI xmlreader_IsEmptyElement(IXmlReader* iface)
258 FIXME("(%p): stub\n", iface);
259 return E_NOTIMPL;
262 static HRESULT WINAPI xmlreader_GetLineNumber(IXmlReader* iface, UINT *lineNumber)
264 FIXME("(%p %p): stub\n", iface, lineNumber);
265 return E_NOTIMPL;
268 static HRESULT WINAPI xmlreader_GetLinePosition(IXmlReader* iface, UINT *linePosition)
270 FIXME("(%p %p): stub\n", iface, linePosition);
271 return E_NOTIMPL;
274 static HRESULT WINAPI xmlreader_GetAttributeCount(IXmlReader* iface, UINT *attributeCount)
276 FIXME("(%p %p): stub\n", iface, attributeCount);
277 return E_NOTIMPL;
280 static HRESULT WINAPI xmlreader_GetDepth(IXmlReader* iface, UINT *depth)
282 FIXME("(%p %p): stub\n", iface, depth);
283 return E_NOTIMPL;
286 static BOOL WINAPI xmlreader_IsEOF(IXmlReader* iface)
288 FIXME("(%p): stub\n", iface);
289 return E_NOTIMPL;
292 static const struct IXmlReaderVtbl xmlreader_vtbl =
294 xmlreader_QueryInterface,
295 xmlreader_AddRef,
296 xmlreader_Release,
297 xmlreader_SetInput,
298 xmlreader_GetProperty,
299 xmlreader_SetProperty,
300 xmlreader_Read,
301 xmlreader_GetNodeType,
302 xmlreader_MoveToFirstAttribute,
303 xmlreader_MoveToNextAttribute,
304 xmlreader_MoveToAttributeByName,
305 xmlreader_MoveToElement,
306 xmlreader_GetQualifiedName,
307 xmlreader_GetNamespaceUri,
308 xmlreader_GetLocalName,
309 xmlreader_GetPrefix,
310 xmlreader_GetValue,
311 xmlreader_ReadValueChunk,
312 xmlreader_GetBaseUri,
313 xmlreader_IsDefault,
314 xmlreader_IsEmptyElement,
315 xmlreader_GetLineNumber,
316 xmlreader_GetLinePosition,
317 xmlreader_GetAttributeCount,
318 xmlreader_GetDepth,
319 xmlreader_IsEOF
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))
332 *ppvObject = iface;
334 else
336 FIXME("interface %s not implemented\n", debugstr_guid(riid));
337 return E_NOINTERFACE;
340 IUnknown_AddRef(iface);
342 return S_OK;
345 static ULONG WINAPI xmlreaderinput_AddRef(IXmlReaderInput *iface)
347 xmlreaderinput *This = impl_from_IXmlReaderInput(iface);
348 TRACE("%p\n", This);
349 return InterlockedIncrement(&This->ref);
352 static ULONG WINAPI xmlreaderinput_Release(IXmlReaderInput *iface)
354 xmlreaderinput *This = impl_from_IXmlReaderInput(iface);
355 LONG ref;
357 TRACE("%p\n", This);
359 ref = InterlockedDecrement(&This->ref);
360 if (ref == 0)
362 HeapFree(GetProcessHeap(), 0, This);
365 return ref;
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)
377 xmlreader *reader;
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));
386 return E_FAIL;
389 reader = HeapAlloc(GetProcessHeap(), 0, sizeof (*reader));
390 if(!reader) return E_OUTOFMEMORY;
392 reader->lpVtbl = &xmlreader_vtbl;
393 reader->ref = 1;
394 reader->input = NULL;
396 *pObject = &reader->lpVtbl;
398 TRACE("returning iface %p\n", *pObject);
400 return S_OK;
403 HRESULT WINAPI CreateXmlReaderInputWithEncodingName(IUnknown *stream,
404 IMalloc *pMalloc,
405 LPCWSTR encoding,
406 BOOL hint,
407 LPCWSTR base_uri,
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);
427 return S_OK;