cmd: Add the Romanian translation.
[wine/hacks.git] / dlls / xmllite / reader.c
blob00a48fc693d5ae98443ddbb202c93c8aa8e2d608
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 static HRESULT xmlreaderinput_query_for_stream(IXmlReaderInput *iface, void **pObj);
39 typedef struct _xmlreader
41 const IXmlReaderVtbl *lpVtbl;
42 LONG ref;
43 IXmlReaderInput *input;
44 ISequentialStream *stream;/* stored as sequential stream, cause currently
45 optimizations possible with IStream aren't implemented */
46 XmlReadState state;
47 UINT line, pos; /* reader position in XML stream */
48 } xmlreader;
50 typedef struct _xmlreaderinput
52 const IUnknownVtbl *lpVtbl;
53 LONG ref;
54 IUnknown *input; /* reference passed on IXmlReaderInput creation */
55 } xmlreaderinput;
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))
76 *ppvObject = iface;
78 else
80 FIXME("interface %s not implemented\n", debugstr_guid(riid));
81 return E_NOINTERFACE;
84 IXmlReader_AddRef(iface);
86 return S_OK;
89 static ULONG WINAPI xmlreader_AddRef(IXmlReader *iface)
91 xmlreader *This = impl_from_IXmlReader(iface);
92 TRACE("%p\n", This);
93 return InterlockedIncrement(&This->ref);
96 static ULONG WINAPI xmlreader_Release(IXmlReader *iface)
98 xmlreader *This = impl_from_IXmlReader(iface);
99 LONG ref;
101 TRACE("%p\n", This);
103 ref = InterlockedDecrement(&This->ref);
104 if (ref == 0)
106 if (This->input) IUnknown_Release(This->input);
107 if (This->stream) IUnknown_Release(This->stream);
108 HeapFree(GetProcessHeap(), 0, This);
111 return ref;
114 static HRESULT WINAPI xmlreader_SetInput(IXmlReader* iface, IUnknown *input)
116 xmlreader *This = impl_from_IXmlReader(iface);
117 HRESULT hr;
119 TRACE("(%p %p)\n", This, input);
121 if (This->input)
123 IUnknown_Release(This->input);
124 This->input = NULL;
127 if (This->stream)
129 IUnknown_Release(This->stream);
130 This->stream = NULL;
133 This->line = This->pos = 0;
135 /* just reset current input */
136 if (!input)
138 This->state = XmlReadState_Initial;
139 return S_OK;
142 /* now try IXmlReaderInput, ISequentialStream, IStream */
143 hr = IUnknown_QueryInterface(input, &IID_IXmlReaderInput, (void**)&This->input);
144 if (hr != S_OK)
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);
154 if (hr == S_OK)
155 This->state = XmlReadState_Initial;
157 return hr;
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;
168 switch (property)
170 case XmlReaderProperty_ReadState:
171 *value = This->state;
172 break;
173 default:
174 FIXME("Unimplemented property (%u)\n", property);
175 return E_NOTIMPL;
178 return S_OK;
181 static HRESULT WINAPI xmlreader_SetProperty(IXmlReader* iface, UINT property, LONG_PTR value)
183 FIXME("(%p %u %lu): stub\n", iface, property, value);
184 return E_NOTIMPL;
187 static HRESULT WINAPI xmlreader_Read(IXmlReader* iface, XmlNodeType *node_type)
189 FIXME("(%p %p): stub\n", iface, node_type);
190 return E_NOTIMPL;
193 static HRESULT WINAPI xmlreader_GetNodeType(IXmlReader* iface, XmlNodeType *node_type)
195 FIXME("(%p %p): stub\n", iface, node_type);
196 return E_NOTIMPL;
199 static HRESULT WINAPI xmlreader_MoveToFirstAttribute(IXmlReader* iface)
201 FIXME("(%p): stub\n", iface);
202 return E_NOTIMPL;
205 static HRESULT WINAPI xmlreader_MoveToNextAttribute(IXmlReader* iface)
207 FIXME("(%p): stub\n", iface);
208 return E_NOTIMPL;
211 static HRESULT WINAPI xmlreader_MoveToAttributeByName(IXmlReader* iface,
212 LPCWSTR local_name,
213 LPCWSTR namespaceUri)
215 FIXME("(%p %p %p): stub\n", iface, local_name, namespaceUri);
216 return E_NOTIMPL;
219 static HRESULT WINAPI xmlreader_MoveToElement(IXmlReader* iface)
221 FIXME("(%p): stub\n", iface);
222 return E_NOTIMPL;
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);
229 return E_NOTIMPL;
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);
237 return E_NOTIMPL;
240 static HRESULT WINAPI xmlreader_GetLocalName(IXmlReader* iface,
241 LPCWSTR *local_name,
242 UINT *local_name_length)
244 FIXME("(%p %p %p): stub\n", iface, local_name, local_name_length);
245 return E_NOTIMPL;
248 static HRESULT WINAPI xmlreader_GetPrefix(IXmlReader* iface,
249 LPCWSTR *prefix,
250 UINT *prefix_length)
252 FIXME("(%p %p %p): stub\n", iface, prefix, prefix_length);
253 return E_NOTIMPL;
256 static HRESULT WINAPI xmlreader_GetValue(IXmlReader* iface,
257 LPCWSTR *value,
258 UINT *value_length)
260 FIXME("(%p %p %p): stub\n", iface, value, value_length);
261 return E_NOTIMPL;
264 static HRESULT WINAPI xmlreader_ReadValueChunk(IXmlReader* iface,
265 WCHAR *buffer,
266 UINT chunk_size,
267 UINT *read)
269 FIXME("(%p %p %u %p): stub\n", iface, buffer, chunk_size, read);
270 return E_NOTIMPL;
273 static HRESULT WINAPI xmlreader_GetBaseUri(IXmlReader* iface,
274 LPCWSTR *baseUri,
275 UINT *baseUri_length)
277 FIXME("(%p %p %p): stub\n", iface, baseUri, baseUri_length);
278 return E_NOTIMPL;
281 static BOOL WINAPI xmlreader_IsDefault(IXmlReader* iface)
283 FIXME("(%p): stub\n", iface);
284 return E_NOTIMPL;
287 static BOOL WINAPI xmlreader_IsEmptyElement(IXmlReader* iface)
289 FIXME("(%p): stub\n", iface);
290 return E_NOTIMPL;
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;
303 return S_OK;
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;
316 return S_OK;
319 static HRESULT WINAPI xmlreader_GetAttributeCount(IXmlReader* iface, UINT *attributeCount)
321 FIXME("(%p %p): stub\n", iface, attributeCount);
322 return E_NOTIMPL;
325 static HRESULT WINAPI xmlreader_GetDepth(IXmlReader* iface, UINT *depth)
327 FIXME("(%p %p): stub\n", iface, depth);
328 return E_NOTIMPL;
331 static BOOL WINAPI xmlreader_IsEOF(IXmlReader* iface)
333 FIXME("(%p): stub\n", iface);
334 return E_NOTIMPL;
337 static const struct IXmlReaderVtbl xmlreader_vtbl =
339 xmlreader_QueryInterface,
340 xmlreader_AddRef,
341 xmlreader_Release,
342 xmlreader_SetInput,
343 xmlreader_GetProperty,
344 xmlreader_SetProperty,
345 xmlreader_Read,
346 xmlreader_GetNodeType,
347 xmlreader_MoveToFirstAttribute,
348 xmlreader_MoveToNextAttribute,
349 xmlreader_MoveToAttributeByName,
350 xmlreader_MoveToElement,
351 xmlreader_GetQualifiedName,
352 xmlreader_GetNamespaceUri,
353 xmlreader_GetLocalName,
354 xmlreader_GetPrefix,
355 xmlreader_GetValue,
356 xmlreader_ReadValueChunk,
357 xmlreader_GetBaseUri,
358 xmlreader_IsDefault,
359 xmlreader_IsEmptyElement,
360 xmlreader_GetLineNumber,
361 xmlreader_GetLinePosition,
362 xmlreader_GetAttributeCount,
363 xmlreader_GetDepth,
364 xmlreader_IsEOF
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);
374 HRESULT hr;
376 hr = IUnknown_QueryInterface(This->input, &IID_IStream, pObj);
377 if (hr != S_OK)
378 hr = IUnknown_QueryInterface(This->input, &IID_ISequentialStream, pObj);
380 return hr;
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))
392 *ppvObject = iface;
394 else
396 FIXME("interface %s not implemented\n", debugstr_guid(riid));
397 return E_NOINTERFACE;
400 IUnknown_AddRef(iface);
402 return S_OK;
405 static ULONG WINAPI xmlreaderinput_AddRef(IXmlReaderInput *iface)
407 xmlreaderinput *This = impl_from_IXmlReaderInput(iface);
408 TRACE("%p\n", This);
409 return InterlockedIncrement(&This->ref);
412 static ULONG WINAPI xmlreaderinput_Release(IXmlReaderInput *iface)
414 xmlreaderinput *This = impl_from_IXmlReaderInput(iface);
415 LONG ref;
417 TRACE("%p\n", This);
419 ref = InterlockedDecrement(&This->ref);
420 if (ref == 0)
422 if (This->input) IUnknown_Release(This->input);
423 HeapFree(GetProcessHeap(), 0, This);
426 return ref;
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)
438 xmlreader *reader;
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));
447 return E_FAIL;
450 reader = HeapAlloc(GetProcessHeap(), 0, sizeof (*reader));
451 if(!reader) return E_OUTOFMEMORY;
453 reader->lpVtbl = &xmlreader_vtbl;
454 reader->ref = 1;
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);
464 return S_OK;
467 HRESULT WINAPI CreateXmlReaderInputWithEncodingName(IUnknown *stream,
468 IMalloc *pMalloc,
469 LPCWSTR encoding,
470 BOOL hint,
471 LPCWSTR base_uri,
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);
492 return S_OK;