xmllite/tests: Test query for supported interface sequence while creating IXmlReaderI...
[wine] / dlls / xmllite / reader.c
1 /*
2  * IXmlReader implementation
3  *
4  * Copyright 2010 Nikolay Sivov
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
21 #define COBJMACROS
22
23 #include <stdarg.h>
24 #include "windef.h"
25 #include "winbase.h"
26 #include "initguid.h"
27 #include "objbase.h"
28 #include "xmllite.h"
29
30 #include "wine/debug.h"
31
32 WINE_DEFAULT_DEBUG_CHANNEL(xmllite);
33
34 typedef struct _xmlreader
35 {
36     const IXmlReaderVtbl *lpVtbl;
37     LONG ref;
38 } xmlreader;
39
40 static inline xmlreader *impl_from_IXmlReader(IXmlReader *iface)
41 {
42     return (xmlreader *)((char*)iface - FIELD_OFFSET(xmlreader, lpVtbl));
43 }
44
45 static HRESULT WINAPI xmlreader_QueryInterface(IXmlReader *iface, REFIID riid, void** ppvObject)
46 {
47     xmlreader *This = impl_from_IXmlReader(iface);
48
49     TRACE("%p %s %p\n", This, debugstr_guid(riid), ppvObject);
50
51     if (IsEqualGUID(riid, &IID_IUnknown) ||
52         IsEqualGUID(riid, &IID_IXmlReader))
53     {
54         *ppvObject = iface;
55     }
56     else
57     {
58         FIXME("interface %s not implemented\n", debugstr_guid(riid));
59         return E_NOINTERFACE;
60     }
61
62     IXmlReader_AddRef(iface);
63
64     return S_OK;
65 }
66
67 static ULONG WINAPI xmlreader_AddRef(IXmlReader *iface)
68 {
69     xmlreader *This = impl_from_IXmlReader(iface);
70     TRACE("%p\n", This);
71     return InterlockedIncrement(&This->ref);
72 }
73
74 static ULONG WINAPI xmlreader_Release(IXmlReader *iface)
75 {
76     xmlreader *This = impl_from_IXmlReader(iface);
77     LONG ref;
78
79     TRACE("%p\n", This);
80
81     ref = InterlockedDecrement(&This->ref);
82     if (ref == 0)
83     {
84         HeapFree(GetProcessHeap(), 0, This);
85     }
86
87     return ref;
88 }
89
90 static HRESULT WINAPI xmlreader_SetInput(IXmlReader* iface, IUnknown *input)
91 {
92     FIXME("(%p %p): stub\n", iface, input);
93     return E_NOTIMPL;
94 }
95
96 static HRESULT WINAPI xmlreader_GetProperty(IXmlReader* iface, UINT property, LONG_PTR *value)
97 {
98     FIXME("(%p %u %p): stub\n", iface, property, value);
99     return E_NOTIMPL;
100 }
101
102 static HRESULT WINAPI xmlreader_SetProperty(IXmlReader* iface, UINT property, LONG_PTR value)
103 {
104     FIXME("(%p %u %lu): stub\n", iface, property, value);
105     return E_NOTIMPL;
106 }
107
108 static HRESULT WINAPI xmlreader_Read(IXmlReader* iface, XmlNodeType *node_type)
109 {
110     FIXME("(%p %p): stub\n", iface, node_type);
111     return E_NOTIMPL;
112 }
113
114 static HRESULT WINAPI xmlreader_GetNodeType(IXmlReader* iface, XmlNodeType *node_type)
115 {
116     FIXME("(%p %p): stub\n", iface, node_type);
117     return E_NOTIMPL;
118 }
119
120 static HRESULT WINAPI xmlreader_MoveToFirstAttribute(IXmlReader* iface)
121 {
122     FIXME("(%p): stub\n", iface);
123     return E_NOTIMPL;
124 }
125
126 static HRESULT WINAPI xmlreader_MoveToNextAttribute(IXmlReader* iface)
127 {
128     FIXME("(%p): stub\n", iface);
129     return E_NOTIMPL;
130 }
131
132 static HRESULT WINAPI xmlreader_MoveToAttributeByName(IXmlReader* iface,
133                                                       LPCWSTR local_name,
134                                                       LPCWSTR namespaceUri)
135 {
136     FIXME("(%p %p %p): stub\n", iface, local_name, namespaceUri);
137     return E_NOTIMPL;
138 }
139
140 static HRESULT WINAPI xmlreader_MoveToElement(IXmlReader* iface)
141 {
142     FIXME("(%p): stub\n", iface);
143     return E_NOTIMPL;
144 }
145
146 static HRESULT WINAPI xmlreader_GetQualifiedName(IXmlReader* iface, LPCWSTR *qualifiedName,
147                                                  UINT *qualifiedName_length)
148 {
149     FIXME("(%p %p %p): stub\n", iface, qualifiedName, qualifiedName_length);
150     return E_NOTIMPL;
151 }
152
153 static HRESULT WINAPI xmlreader_GetNamespaceUri(IXmlReader* iface,
154                                                 LPCWSTR *namespaceUri,
155                                                 UINT *namespaceUri_length)
156 {
157     FIXME("(%p %p %p): stub\n", iface, namespaceUri, namespaceUri_length);
158     return E_NOTIMPL;
159 }
160
161 static HRESULT WINAPI xmlreader_GetLocalName(IXmlReader* iface,
162                                              LPCWSTR *local_name,
163                                              UINT *local_name_length)
164 {
165     FIXME("(%p %p %p): stub\n", iface, local_name, local_name_length);
166     return E_NOTIMPL;
167 }
168
169 static HRESULT WINAPI xmlreader_GetPrefix(IXmlReader* iface,
170                                           LPCWSTR *prefix,
171                                           UINT *prefix_length)
172 {
173     FIXME("(%p %p %p): stub\n", iface, prefix, prefix_length);
174     return E_NOTIMPL;
175 }
176
177 static HRESULT WINAPI xmlreader_GetValue(IXmlReader* iface,
178                                          LPCWSTR *value,
179                                          UINT *value_length)
180 {
181     FIXME("(%p %p %p): stub\n", iface, value, value_length);
182     return E_NOTIMPL;
183 }
184
185 static HRESULT WINAPI xmlreader_ReadValueChunk(IXmlReader* iface,
186                                                WCHAR *buffer,
187                                                UINT   chunk_size,
188                                                UINT  *read)
189 {
190     FIXME("(%p %p %u %p): stub\n", iface, buffer, chunk_size, read);
191     return E_NOTIMPL;
192 }
193
194 static HRESULT WINAPI xmlreader_GetBaseUri(IXmlReader* iface,
195                                            LPCWSTR *baseUri,
196                                            UINT *baseUri_length)
197 {
198     FIXME("(%p %p %p): stub\n", iface, baseUri, baseUri_length);
199     return E_NOTIMPL;
200 }
201
202 static BOOL WINAPI xmlreader_IsDefault(IXmlReader* iface)
203 {
204     FIXME("(%p): stub\n", iface);
205     return E_NOTIMPL;
206 }
207
208 static BOOL WINAPI xmlreader_IsEmptyElement(IXmlReader* iface)
209 {
210     FIXME("(%p): stub\n", iface);
211     return E_NOTIMPL;
212 }
213
214 static HRESULT WINAPI xmlreader_GetLineNumber(IXmlReader* iface, UINT *lineNumber)
215 {
216     FIXME("(%p %p): stub\n", iface, lineNumber);
217     return E_NOTIMPL;
218 }
219
220 static HRESULT WINAPI xmlreader_GetLinePosition(IXmlReader* iface, UINT *linePosition)
221 {
222     FIXME("(%p %p): stub\n", iface, linePosition);
223     return E_NOTIMPL;
224 }
225
226 static HRESULT WINAPI xmlreader_GetAttributeCount(IXmlReader* iface, UINT *attributeCount)
227 {
228     FIXME("(%p %p): stub\n", iface, attributeCount);
229     return E_NOTIMPL;
230 }
231
232 static HRESULT WINAPI xmlreader_GetDepth(IXmlReader* iface, UINT *depth)
233 {
234     FIXME("(%p %p): stub\n", iface, depth);
235     return E_NOTIMPL;
236 }
237
238 static BOOL WINAPI xmlreader_IsEOF(IXmlReader* iface)
239 {
240     FIXME("(%p): stub\n", iface);
241     return E_NOTIMPL;
242 }
243
244 static const struct IXmlReaderVtbl xmlreader_vtbl =
245 {
246     xmlreader_QueryInterface,
247     xmlreader_AddRef,
248     xmlreader_Release,
249     xmlreader_SetInput,
250     xmlreader_GetProperty,
251     xmlreader_SetProperty,
252     xmlreader_Read,
253     xmlreader_GetNodeType,
254     xmlreader_MoveToFirstAttribute,
255     xmlreader_MoveToNextAttribute,
256     xmlreader_MoveToAttributeByName,
257     xmlreader_MoveToElement,
258     xmlreader_GetQualifiedName,
259     xmlreader_GetNamespaceUri,
260     xmlreader_GetLocalName,
261     xmlreader_GetPrefix,
262     xmlreader_GetValue,
263     xmlreader_ReadValueChunk,
264     xmlreader_GetBaseUri,
265     xmlreader_IsDefault,
266     xmlreader_IsEmptyElement,
267     xmlreader_GetLineNumber,
268     xmlreader_GetLinePosition,
269     xmlreader_GetAttributeCount,
270     xmlreader_GetDepth,
271     xmlreader_IsEOF
272 };
273
274 HRESULT WINAPI CreateXmlReader(REFIID riid, void **pObject, IMalloc *pMalloc)
275 {
276     xmlreader *reader;
277
278     TRACE("(%s, %p, %p)\n", wine_dbgstr_guid(riid), pObject, pMalloc);
279
280     if (pMalloc) FIXME("custom IMalloc not supported yet\n");
281
282     if (!IsEqualGUID(riid, &IID_IXmlReader))
283     {
284         ERR("Unexpected IID requested -> (%s)\n", wine_dbgstr_guid(riid));
285         return E_FAIL;
286     }
287
288     reader = HeapAlloc(GetProcessHeap(), 0, sizeof (*reader));
289     if(!reader) return E_OUTOFMEMORY;
290
291     reader->lpVtbl = &xmlreader_vtbl;
292     reader->ref = 1;
293
294     *pObject = &reader->lpVtbl;
295
296     TRACE("returning iface %p\n", *pObject);
297
298     return S_OK;
299 }
300
301 HRESULT WINAPI CreateXmlReaderInputWithEncodingName(IUnknown *stream,
302                                                     IMalloc *pMalloc,
303                                                     LPCWSTR encoding,
304                                                     BOOL hint,
305                                                     LPCWSTR base_uri,
306                                                     IXmlReaderInput **ppInput)
307 {
308     FIXME("%p %p %s %d %s %p\n", stream, pMalloc, wine_dbgstr_w(encoding),
309                                  hint, wine_dbgstr_w(base_uri), ppInput);
310     return E_NOTIMPL;
311 }