Home | Info | Community | Development | myReactOS | Contact Us
ReactOS Development > Doxygenreader.c
Go to the documentation of this file.
00001 /* 00002 * IXmlReader implementation 00003 * 00004 * Copyright 2010 Nikolay Sivov 00005 * 00006 * This library is free software; you can redistribute it and/or 00007 * modify it under the terms of the GNU Lesser General Public 00008 * License as published by the Free Software Foundation; either 00009 * version 2.1 of the License, or (at your option) any later version. 00010 * 00011 * This library is distributed in the hope that it will be useful, 00012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00014 * Lesser General Public License for more details. 00015 * 00016 * You should have received a copy of the GNU Lesser General Public 00017 * License along with this library; if not, write to the Free Software 00018 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA 00019 */ 00020 00021 #define COBJMACROS 00022 00023 #include <stdarg.h> 00024 #include "windef.h" 00025 #include "winbase.h" 00026 #include "initguid.h" 00027 #include "objbase.h" 00028 #include "xmllite.h" 00029 00030 #include "wine/debug.h" 00031 00032 WINE_DEFAULT_DEBUG_CHANNEL(xmllite); 00033 00034 /* not defined in public headers */ 00035 DEFINE_GUID(IID_IXmlReaderInput, 0x0b3ccc9b, 0x9214, 0x428b, 0xa2, 0xae, 0xef, 0x3a, 0xa8, 0x71, 0xaf, 0xda); 00036 00037 static HRESULT xmlreaderinput_query_for_stream(IXmlReaderInput *iface, void **pObj); 00038 00039 typedef struct _xmlreader 00040 { 00041 IXmlReader IXmlReader_iface; 00042 LONG ref; 00043 IXmlReaderInput *input; 00044 ISequentialStream *stream;/* stored as sequential stream, cause currently 00045 optimizations possible with IStream aren't implemented */ 00046 XmlReadState state; 00047 UINT line, pos; /* reader position in XML stream */ 00048 } xmlreader; 00049 00050 typedef struct _xmlreaderinput 00051 { 00052 IXmlReaderInput IXmlReaderInput_iface; 00053 LONG ref; 00054 IUnknown *input; /* reference passed on IXmlReaderInput creation */ 00055 } xmlreaderinput; 00056 00057 static inline xmlreader *impl_from_IXmlReader(IXmlReader *iface) 00058 { 00059 return CONTAINING_RECORD(iface, xmlreader, IXmlReader_iface); 00060 } 00061 00062 static inline xmlreaderinput *impl_from_IXmlReaderInput(IXmlReaderInput *iface) 00063 { 00064 return CONTAINING_RECORD(iface, xmlreaderinput, IXmlReaderInput_iface); 00065 } 00066 00067 static HRESULT WINAPI xmlreader_QueryInterface(IXmlReader *iface, REFIID riid, void** ppvObject) 00068 { 00069 xmlreader *This = impl_from_IXmlReader(iface); 00070 00071 TRACE("%p %s %p\n", This, debugstr_guid(riid), ppvObject); 00072 00073 if (IsEqualGUID(riid, &IID_IUnknown) || 00074 IsEqualGUID(riid, &IID_IXmlReader)) 00075 { 00076 *ppvObject = iface; 00077 } 00078 else 00079 { 00080 FIXME("interface %s not implemented\n", debugstr_guid(riid)); 00081 return E_NOINTERFACE; 00082 } 00083 00084 IXmlReader_AddRef(iface); 00085 00086 return S_OK; 00087 } 00088 00089 static ULONG WINAPI xmlreader_AddRef(IXmlReader *iface) 00090 { 00091 xmlreader *This = impl_from_IXmlReader(iface); 00092 TRACE("%p\n", This); 00093 return InterlockedIncrement(&This->ref); 00094 } 00095 00096 static ULONG WINAPI xmlreader_Release(IXmlReader *iface) 00097 { 00098 xmlreader *This = impl_from_IXmlReader(iface); 00099 LONG ref; 00100 00101 TRACE("%p\n", This); 00102 00103 ref = InterlockedDecrement(&This->ref); 00104 if (ref == 0) 00105 { 00106 if (This->input) IUnknown_Release(This->input); 00107 if (This->stream) IUnknown_Release(This->stream); 00108 HeapFree(GetProcessHeap(), 0, This); 00109 } 00110 00111 return ref; 00112 } 00113 00114 static HRESULT WINAPI xmlreader_SetInput(IXmlReader* iface, IUnknown *input) 00115 { 00116 xmlreader *This = impl_from_IXmlReader(iface); 00117 HRESULT hr; 00118 00119 TRACE("(%p %p)\n", This, input); 00120 00121 if (This->input) 00122 { 00123 IUnknown_Release(This->input); 00124 This->input = NULL; 00125 } 00126 00127 if (This->stream) 00128 { 00129 IUnknown_Release(This->stream); 00130 This->stream = NULL; 00131 } 00132 00133 This->line = This->pos = 0; 00134 00135 /* just reset current input */ 00136 if (!input) 00137 { 00138 This->state = XmlReadState_Initial; 00139 return S_OK; 00140 } 00141 00142 /* now try IXmlReaderInput, ISequentialStream, IStream */ 00143 hr = IUnknown_QueryInterface(input, &IID_IXmlReaderInput, (void**)&This->input); 00144 if (hr != S_OK) 00145 { 00146 /* create IXmlReaderInput basing on supplied interface */ 00147 hr = CreateXmlReaderInputWithEncodingName(input, 00148 NULL, NULL, FALSE, NULL, &This->input); 00149 if (hr != S_OK) return hr; 00150 } 00151 00152 /* set stream for supplied IXmlReaderInput */ 00153 hr = xmlreaderinput_query_for_stream(This->input, (void**)&This->stream); 00154 if (hr == S_OK) 00155 This->state = XmlReadState_Initial; 00156 00157 return hr; 00158 } 00159 00160 static HRESULT WINAPI xmlreader_GetProperty(IXmlReader* iface, UINT property, LONG_PTR *value) 00161 { 00162 xmlreader *This = impl_from_IXmlReader(iface); 00163 00164 TRACE("(%p %u %p)\n", This, property, value); 00165 00166 if (!value) return E_INVALIDARG; 00167 00168 switch (property) 00169 { 00170 case XmlReaderProperty_ReadState: 00171 *value = This->state; 00172 break; 00173 default: 00174 FIXME("Unimplemented property (%u)\n", property); 00175 return E_NOTIMPL; 00176 } 00177 00178 return S_OK; 00179 } 00180 00181 static HRESULT WINAPI xmlreader_SetProperty(IXmlReader* iface, UINT property, LONG_PTR value) 00182 { 00183 FIXME("(%p %u %lu): stub\n", iface, property, value); 00184 return E_NOTIMPL; 00185 } 00186 00187 static HRESULT WINAPI xmlreader_Read(IXmlReader* iface, XmlNodeType *node_type) 00188 { 00189 FIXME("(%p %p): stub\n", iface, node_type); 00190 return E_NOTIMPL; 00191 } 00192 00193 static HRESULT WINAPI xmlreader_GetNodeType(IXmlReader* iface, XmlNodeType *node_type) 00194 { 00195 FIXME("(%p %p): stub\n", iface, node_type); 00196 return E_NOTIMPL; 00197 } 00198 00199 static HRESULT WINAPI xmlreader_MoveToFirstAttribute(IXmlReader* iface) 00200 { 00201 FIXME("(%p): stub\n", iface); 00202 return E_NOTIMPL; 00203 } 00204 00205 static HRESULT WINAPI xmlreader_MoveToNextAttribute(IXmlReader* iface) 00206 { 00207 FIXME("(%p): stub\n", iface); 00208 return E_NOTIMPL; 00209 } 00210 00211 static HRESULT WINAPI xmlreader_MoveToAttributeByName(IXmlReader* iface, 00212 LPCWSTR local_name, 00213 LPCWSTR namespaceUri) 00214 { 00215 FIXME("(%p %p %p): stub\n", iface, local_name, namespaceUri); 00216 return E_NOTIMPL; 00217 } 00218 00219 static HRESULT WINAPI xmlreader_MoveToElement(IXmlReader* iface) 00220 { 00221 FIXME("(%p): stub\n", iface); 00222 return E_NOTIMPL; 00223 } 00224 00225 static HRESULT WINAPI xmlreader_GetQualifiedName(IXmlReader* iface, LPCWSTR *qualifiedName, 00226 UINT *qualifiedName_length) 00227 { 00228 FIXME("(%p %p %p): stub\n", iface, qualifiedName, qualifiedName_length); 00229 return E_NOTIMPL; 00230 } 00231 00232 static HRESULT WINAPI xmlreader_GetNamespaceUri(IXmlReader* iface, 00233 LPCWSTR *namespaceUri, 00234 UINT *namespaceUri_length) 00235 { 00236 FIXME("(%p %p %p): stub\n", iface, namespaceUri, namespaceUri_length); 00237 return E_NOTIMPL; 00238 } 00239 00240 static HRESULT WINAPI xmlreader_GetLocalName(IXmlReader* iface, 00241 LPCWSTR *local_name, 00242 UINT *local_name_length) 00243 { 00244 FIXME("(%p %p %p): stub\n", iface, local_name, local_name_length); 00245 return E_NOTIMPL; 00246 } 00247 00248 static HRESULT WINAPI xmlreader_GetPrefix(IXmlReader* iface, 00249 LPCWSTR *prefix, 00250 UINT *prefix_length) 00251 { 00252 FIXME("(%p %p %p): stub\n", iface, prefix, prefix_length); 00253 return E_NOTIMPL; 00254 } 00255 00256 static HRESULT WINAPI xmlreader_GetValue(IXmlReader* iface, 00257 LPCWSTR *value, 00258 UINT *value_length) 00259 { 00260 FIXME("(%p %p %p): stub\n", iface, value, value_length); 00261 return E_NOTIMPL; 00262 } 00263 00264 static HRESULT WINAPI xmlreader_ReadValueChunk(IXmlReader* iface, 00265 WCHAR *buffer, 00266 UINT chunk_size, 00267 UINT *read) 00268 { 00269 FIXME("(%p %p %u %p): stub\n", iface, buffer, chunk_size, read); 00270 return E_NOTIMPL; 00271 } 00272 00273 static HRESULT WINAPI xmlreader_GetBaseUri(IXmlReader* iface, 00274 LPCWSTR *baseUri, 00275 UINT *baseUri_length) 00276 { 00277 FIXME("(%p %p %p): stub\n", iface, baseUri, baseUri_length); 00278 return E_NOTIMPL; 00279 } 00280 00281 static BOOL WINAPI xmlreader_IsDefault(IXmlReader* iface) 00282 { 00283 FIXME("(%p): stub\n", iface); 00284 return E_NOTIMPL; 00285 } 00286 00287 static BOOL WINAPI xmlreader_IsEmptyElement(IXmlReader* iface) 00288 { 00289 FIXME("(%p): stub\n", iface); 00290 return E_NOTIMPL; 00291 } 00292 00293 static HRESULT WINAPI xmlreader_GetLineNumber(IXmlReader* iface, UINT *lineNumber) 00294 { 00295 xmlreader *This = impl_from_IXmlReader(iface); 00296 00297 TRACE("(%p %p)\n", This, lineNumber); 00298 00299 if (!lineNumber) return E_INVALIDARG; 00300 00301 *lineNumber = This->line; 00302 00303 return S_OK; 00304 } 00305 00306 static HRESULT WINAPI xmlreader_GetLinePosition(IXmlReader* iface, UINT *linePosition) 00307 { 00308 xmlreader *This = impl_from_IXmlReader(iface); 00309 00310 TRACE("(%p %p)\n", This, linePosition); 00311 00312 if (!linePosition) return E_INVALIDARG; 00313 00314 *linePosition = This->pos; 00315 00316 return S_OK; 00317 } 00318 00319 static HRESULT WINAPI xmlreader_GetAttributeCount(IXmlReader* iface, UINT *attributeCount) 00320 { 00321 FIXME("(%p %p): stub\n", iface, attributeCount); 00322 return E_NOTIMPL; 00323 } 00324 00325 static HRESULT WINAPI xmlreader_GetDepth(IXmlReader* iface, UINT *depth) 00326 { 00327 FIXME("(%p %p): stub\n", iface, depth); 00328 return E_NOTIMPL; 00329 } 00330 00331 static BOOL WINAPI xmlreader_IsEOF(IXmlReader* iface) 00332 { 00333 FIXME("(%p): stub\n", iface); 00334 return E_NOTIMPL; 00335 } 00336 00337 static const struct IXmlReaderVtbl xmlreader_vtbl = 00338 { 00339 xmlreader_QueryInterface, 00340 xmlreader_AddRef, 00341 xmlreader_Release, 00342 xmlreader_SetInput, 00343 xmlreader_GetProperty, 00344 xmlreader_SetProperty, 00345 xmlreader_Read, 00346 xmlreader_GetNodeType, 00347 xmlreader_MoveToFirstAttribute, 00348 xmlreader_MoveToNextAttribute, 00349 xmlreader_MoveToAttributeByName, 00350 xmlreader_MoveToElement, 00351 xmlreader_GetQualifiedName, 00352 xmlreader_GetNamespaceUri, 00353 xmlreader_GetLocalName, 00354 xmlreader_GetPrefix, 00355 xmlreader_GetValue, 00356 xmlreader_ReadValueChunk, 00357 xmlreader_GetBaseUri, 00358 xmlreader_IsDefault, 00359 xmlreader_IsEmptyElement, 00360 xmlreader_GetLineNumber, 00361 xmlreader_GetLinePosition, 00362 xmlreader_GetAttributeCount, 00363 xmlreader_GetDepth, 00364 xmlreader_IsEOF 00365 }; 00366 00369 /* Queries already stored interface for IStream/ISequentialStream. 00370 Interface supplied on creation will be overwritten */ 00371 static HRESULT xmlreaderinput_query_for_stream(IXmlReaderInput *iface, void **pObj) 00372 { 00373 xmlreaderinput *This = impl_from_IXmlReaderInput(iface); 00374 HRESULT hr; 00375 00376 hr = IUnknown_QueryInterface(This->input, &IID_IStream, pObj); 00377 if (hr != S_OK) 00378 hr = IUnknown_QueryInterface(This->input, &IID_ISequentialStream, pObj); 00379 00380 return hr; 00381 } 00382 00383 static HRESULT WINAPI xmlreaderinput_QueryInterface(IXmlReaderInput *iface, REFIID riid, void** ppvObject) 00384 { 00385 xmlreaderinput *This = impl_from_IXmlReaderInput(iface); 00386 00387 TRACE("%p %s %p\n", This, debugstr_guid(riid), ppvObject); 00388 00389 if (IsEqualGUID(riid, &IID_IXmlReaderInput) || 00390 IsEqualGUID(riid, &IID_IUnknown)) 00391 { 00392 *ppvObject = iface; 00393 } 00394 else 00395 { 00396 FIXME("interface %s not implemented\n", debugstr_guid(riid)); 00397 return E_NOINTERFACE; 00398 } 00399 00400 IUnknown_AddRef(iface); 00401 00402 return S_OK; 00403 } 00404 00405 static ULONG WINAPI xmlreaderinput_AddRef(IXmlReaderInput *iface) 00406 { 00407 xmlreaderinput *This = impl_from_IXmlReaderInput(iface); 00408 TRACE("%p\n", This); 00409 return InterlockedIncrement(&This->ref); 00410 } 00411 00412 static ULONG WINAPI xmlreaderinput_Release(IXmlReaderInput *iface) 00413 { 00414 xmlreaderinput *This = impl_from_IXmlReaderInput(iface); 00415 LONG ref; 00416 00417 TRACE("%p\n", This); 00418 00419 ref = InterlockedDecrement(&This->ref); 00420 if (ref == 0) 00421 { 00422 if (This->input) IUnknown_Release(This->input); 00423 HeapFree(GetProcessHeap(), 0, This); 00424 } 00425 00426 return ref; 00427 } 00428 00429 static const struct IUnknownVtbl xmlreaderinput_vtbl = 00430 { 00431 xmlreaderinput_QueryInterface, 00432 xmlreaderinput_AddRef, 00433 xmlreaderinput_Release 00434 }; 00435 00436 HRESULT WINAPI CreateXmlReader(REFIID riid, void **pObject, IMalloc *pMalloc) 00437 { 00438 xmlreader *reader; 00439 00440 TRACE("(%s, %p, %p)\n", wine_dbgstr_guid(riid), pObject, pMalloc); 00441 00442 if (pMalloc) FIXME("custom IMalloc not supported yet\n"); 00443 00444 if (!IsEqualGUID(riid, &IID_IXmlReader)) 00445 { 00446 ERR("Unexpected IID requested -> (%s)\n", wine_dbgstr_guid(riid)); 00447 return E_FAIL; 00448 } 00449 00450 reader = HeapAlloc(GetProcessHeap(), 0, sizeof (*reader)); 00451 if(!reader) return E_OUTOFMEMORY; 00452 00453 reader->IXmlReader_iface.lpVtbl = &xmlreader_vtbl; 00454 reader->ref = 1; 00455 reader->stream = NULL; 00456 reader->input = NULL; 00457 reader->state = XmlReadState_Closed; 00458 reader->line = reader->pos = 0; 00459 00460 *pObject = &reader->IXmlReader_iface; 00461 00462 TRACE("returning iface %p\n", *pObject); 00463 00464 return S_OK; 00465 } 00466 00467 HRESULT WINAPI CreateXmlReaderInputWithEncodingName(IUnknown *stream, 00468 IMalloc *pMalloc, 00469 LPCWSTR encoding, 00470 BOOL hint, 00471 LPCWSTR base_uri, 00472 IXmlReaderInput **ppInput) 00473 { 00474 xmlreaderinput *readerinput; 00475 00476 FIXME("%p %p %s %d %s %p: stub\n", stream, pMalloc, wine_dbgstr_w(encoding), 00477 hint, wine_dbgstr_w(base_uri), ppInput); 00478 00479 if (!stream || !ppInput) return E_INVALIDARG; 00480 00481 readerinput = HeapAlloc(GetProcessHeap(), 0, sizeof (*readerinput)); 00482 if(!readerinput) return E_OUTOFMEMORY; 00483 00484 readerinput->IXmlReaderInput_iface.lpVtbl = &xmlreaderinput_vtbl; 00485 readerinput->ref = 1; 00486 IUnknown_QueryInterface(stream, &IID_IUnknown, (void**)&readerinput->input); 00487 00488 *ppInput = &readerinput->IXmlReaderInput_iface; 00489 00490 TRACE("returning iface %p\n", *ppInput); 00491 00492 return S_OK; 00493 } Generated on Sun May 27 2012 04:25:58 for ReactOS by
1.7.6.1
|