Home | Info | Community | Development | myReactOS | Contact Us
ReactOS Development > Doxygennodemap.c
Go to the documentation of this file.
00001 /* 00002 * Node map implementation 00003 * 00004 * Copyright 2005 Mike McCormack 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 #include "config.h" 00022 00023 #define COBJMACROS 00024 00025 #include <stdarg.h> 00026 #include "windef.h" 00027 #include "winbase.h" 00028 #include "winuser.h" 00029 #include "winnls.h" 00030 #include "ole2.h" 00031 #include "msxml2.h" 00032 00033 #include "msxml_private.h" 00034 00035 #include "wine/debug.h" 00036 00037 WINE_DEFAULT_DEBUG_CHANNEL(msxml); 00038 00039 #ifdef HAVE_LIBXML2 00040 00041 typedef struct _xmlnodemap 00042 { 00043 const struct IXMLDOMNamedNodeMapVtbl *lpVtbl; 00044 const struct ISupportErrorInfoVtbl *lpSEIVtbl; 00045 LONG ref; 00046 IXMLDOMNode *node; 00047 LONG iterator; 00048 } xmlnodemap; 00049 00050 static inline xmlnodemap *impl_from_IXMLDOMNamedNodeMap( IXMLDOMNamedNodeMap *iface ) 00051 { 00052 return (xmlnodemap *)((char*)iface - FIELD_OFFSET(xmlnodemap, lpVtbl)); 00053 } 00054 00055 static inline xmlnodemap *impl_from_ISupportErrorInfo( ISupportErrorInfo *iface ) 00056 { 00057 return (xmlnodemap *)((char*)iface - FIELD_OFFSET(xmlnodemap, lpSEIVtbl)); 00058 } 00059 00060 static HRESULT WINAPI xmlnodemap_QueryInterface( 00061 IXMLDOMNamedNodeMap *iface, 00062 REFIID riid, void** ppvObject ) 00063 { 00064 xmlnodemap *This = impl_from_IXMLDOMNamedNodeMap( iface ); 00065 TRACE("(%p)->(%s %p)\n", iface, debugstr_guid(riid), ppvObject); 00066 00067 if( IsEqualGUID( riid, &IID_IUnknown ) || 00068 IsEqualGUID( riid, &IID_IDispatch ) || 00069 IsEqualGUID( riid, &IID_IXMLDOMNamedNodeMap ) ) 00070 { 00071 *ppvObject = iface; 00072 } 00073 else if( IsEqualGUID( riid, &IID_ISupportErrorInfo )) 00074 { 00075 *ppvObject = &This->lpSEIVtbl; 00076 } 00077 else 00078 { 00079 FIXME("interface %s not implemented\n", debugstr_guid(riid)); 00080 return E_NOINTERFACE; 00081 } 00082 00083 IXMLDOMElement_AddRef( iface ); 00084 00085 return S_OK; 00086 } 00087 00088 static ULONG WINAPI xmlnodemap_AddRef( 00089 IXMLDOMNamedNodeMap *iface ) 00090 { 00091 xmlnodemap *This = impl_from_IXMLDOMNamedNodeMap( iface ); 00092 return InterlockedIncrement( &This->ref ); 00093 } 00094 00095 static ULONG WINAPI xmlnodemap_Release( 00096 IXMLDOMNamedNodeMap *iface ) 00097 { 00098 xmlnodemap *This = impl_from_IXMLDOMNamedNodeMap( iface ); 00099 ULONG ref; 00100 00101 ref = InterlockedDecrement( &This->ref ); 00102 if ( ref == 0 ) 00103 { 00104 IXMLDOMNode_Release( This->node ); 00105 heap_free( This ); 00106 } 00107 00108 return ref; 00109 } 00110 00111 static HRESULT WINAPI xmlnodemap_GetTypeInfoCount( 00112 IXMLDOMNamedNodeMap *iface, 00113 UINT* pctinfo ) 00114 { 00115 xmlnodemap *This = impl_from_IXMLDOMNamedNodeMap( iface ); 00116 00117 TRACE("(%p)->(%p)\n", This, pctinfo); 00118 00119 *pctinfo = 1; 00120 00121 return S_OK; 00122 } 00123 00124 static HRESULT WINAPI xmlnodemap_GetTypeInfo( 00125 IXMLDOMNamedNodeMap *iface, 00126 UINT iTInfo, LCID lcid, 00127 ITypeInfo** ppTInfo ) 00128 { 00129 xmlnodemap *This = impl_from_IXMLDOMNamedNodeMap( iface ); 00130 HRESULT hr; 00131 00132 TRACE("(%p)->(%u %u %p)\n", This, iTInfo, lcid, ppTInfo); 00133 00134 hr = get_typeinfo(IXMLDOMNamedNodeMap_tid, ppTInfo); 00135 00136 return hr; 00137 } 00138 00139 static HRESULT WINAPI xmlnodemap_GetIDsOfNames( 00140 IXMLDOMNamedNodeMap *iface, 00141 REFIID riid, LPOLESTR* rgszNames, 00142 UINT cNames, LCID lcid, DISPID* rgDispId ) 00143 { 00144 xmlnodemap *This = impl_from_IXMLDOMNamedNodeMap( iface ); 00145 ITypeInfo *typeinfo; 00146 HRESULT hr; 00147 00148 TRACE("(%p)->(%s %p %u %u %p)\n", This, debugstr_guid(riid), rgszNames, cNames, 00149 lcid, rgDispId); 00150 00151 if(!rgszNames || cNames == 0 || !rgDispId) 00152 return E_INVALIDARG; 00153 00154 hr = get_typeinfo(IXMLDOMNamedNodeMap_tid, &typeinfo); 00155 if(SUCCEEDED(hr)) 00156 { 00157 hr = ITypeInfo_GetIDsOfNames(typeinfo, rgszNames, cNames, rgDispId); 00158 ITypeInfo_Release(typeinfo); 00159 } 00160 00161 return hr; 00162 } 00163 00164 static HRESULT WINAPI xmlnodemap_Invoke( 00165 IXMLDOMNamedNodeMap *iface, 00166 DISPID dispIdMember, REFIID riid, LCID lcid, 00167 WORD wFlags, DISPPARAMS* pDispParams, VARIANT* pVarResult, 00168 EXCEPINFO* pExcepInfo, UINT* puArgErr ) 00169 { 00170 xmlnodemap *This = impl_from_IXMLDOMNamedNodeMap( iface ); 00171 ITypeInfo *typeinfo; 00172 HRESULT hr; 00173 00174 TRACE("(%p)->(%d %s %d %d %p %p %p %p)\n", This, dispIdMember, debugstr_guid(riid), 00175 lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr); 00176 00177 hr = get_typeinfo(IXMLDOMNamedNodeMap_tid, &typeinfo); 00178 if(SUCCEEDED(hr)) 00179 { 00180 hr = ITypeInfo_Invoke(typeinfo, &(This->lpVtbl), dispIdMember, wFlags, pDispParams, 00181 pVarResult, pExcepInfo, puArgErr); 00182 ITypeInfo_Release(typeinfo); 00183 } 00184 00185 return hr; 00186 } 00187 00188 xmlChar *xmlChar_from_wchar( LPWSTR str ) 00189 { 00190 DWORD len; 00191 xmlChar *xmlstr; 00192 00193 len = WideCharToMultiByte( CP_UTF8, 0, str, -1, NULL, 0, NULL, NULL ); 00194 xmlstr = heap_alloc( len ); 00195 if ( xmlstr ) 00196 WideCharToMultiByte( CP_UTF8, 0, str, -1, (LPSTR) xmlstr, len, NULL, NULL ); 00197 return xmlstr; 00198 } 00199 00200 static HRESULT WINAPI xmlnodemap_getNamedItem( 00201 IXMLDOMNamedNodeMap *iface, 00202 BSTR name, 00203 IXMLDOMNode** namedItem) 00204 { 00205 xmlnodemap *This = impl_from_IXMLDOMNamedNodeMap( iface ); 00206 xmlChar *element_name; 00207 xmlAttrPtr attr; 00208 xmlNodePtr node; 00209 00210 TRACE("(%p)->(%s %p)\n", This, debugstr_w(name), namedItem ); 00211 00212 if ( !namedItem ) 00213 return E_INVALIDARG; 00214 00215 node = xmlNodePtr_from_domnode( This->node, 0 ); 00216 if ( !node ) 00217 return E_FAIL; 00218 00219 element_name = xmlChar_from_wchar( name ); 00220 attr = xmlHasNsProp( node, element_name, NULL ); 00221 heap_free( element_name ); 00222 00223 if ( !attr ) 00224 { 00225 *namedItem = NULL; 00226 return S_FALSE; 00227 } 00228 00229 *namedItem = create_node( (xmlNodePtr) attr ); 00230 00231 return S_OK; 00232 } 00233 00234 static HRESULT WINAPI xmlnodemap_setNamedItem( 00235 IXMLDOMNamedNodeMap *iface, 00236 IXMLDOMNode* newItem, 00237 IXMLDOMNode** namedItem) 00238 { 00239 xmlnodemap *This = impl_from_IXMLDOMNamedNodeMap( iface ); 00240 xmlnode *ThisNew = NULL; 00241 xmlNodePtr nodeNew; 00242 IXMLDOMNode *pAttr = NULL; 00243 xmlNodePtr node; 00244 00245 TRACE("(%p)->(%p %p)\n", This, newItem, namedItem ); 00246 00247 if(!newItem) 00248 return E_INVALIDARG; 00249 00250 if(namedItem) *namedItem = NULL; 00251 00252 node = xmlNodePtr_from_domnode( This->node, 0 ); 00253 if ( !node ) 00254 return E_FAIL; 00255 00256 /* Must be an Attribute */ 00257 IUnknown_QueryInterface(newItem, &IID_IXMLDOMNode, (LPVOID*)&pAttr); 00258 if(pAttr) 00259 { 00260 ThisNew = impl_from_IXMLDOMNode( pAttr ); 00261 00262 if(ThisNew->node->type != XML_ATTRIBUTE_NODE) 00263 { 00264 IUnknown_Release(pAttr); 00265 return E_FAIL; 00266 } 00267 00268 if(!ThisNew->node->parent) 00269 if(xmldoc_remove_orphan(ThisNew->node->doc, ThisNew->node) != S_OK) 00270 WARN("%p is not an orphan of %p\n", ThisNew->node, ThisNew->node->doc); 00271 00272 nodeNew = xmlAddChild(node, ThisNew->node); 00273 00274 if(namedItem) 00275 *namedItem = create_node( nodeNew ); 00276 00277 IUnknown_Release(pAttr); 00278 00279 return S_OK; 00280 } 00281 00282 return E_INVALIDARG; 00283 } 00284 00285 static HRESULT WINAPI xmlnodemap_removeNamedItem( 00286 IXMLDOMNamedNodeMap *iface, 00287 BSTR name, 00288 IXMLDOMNode** namedItem) 00289 { 00290 xmlnodemap *This = impl_from_IXMLDOMNamedNodeMap( iface ); 00291 xmlChar *element_name; 00292 xmlAttrPtr attr; 00293 xmlNodePtr node; 00294 00295 TRACE("(%p)->(%s %p)\n", This, debugstr_w(name), namedItem ); 00296 00297 if ( !name) 00298 return E_INVALIDARG; 00299 00300 node = xmlNodePtr_from_domnode( This->node, 0 ); 00301 if ( !node ) 00302 return E_FAIL; 00303 00304 element_name = xmlChar_from_wchar( name ); 00305 attr = xmlHasNsProp( node, element_name, NULL ); 00306 heap_free( element_name ); 00307 00308 if ( !attr ) 00309 { 00310 if( namedItem ) 00311 *namedItem = NULL; 00312 return S_FALSE; 00313 } 00314 00315 if ( namedItem ) 00316 { 00317 xmlUnlinkNode( (xmlNodePtr) attr ); 00318 xmldoc_add_orphan( attr->doc, (xmlNodePtr) attr ); 00319 *namedItem = create_node( (xmlNodePtr) attr ); 00320 } 00321 else 00322 { 00323 if( xmlRemoveProp( attr ) == -1 ) 00324 ERR("xmlRemoveProp failed\n"); 00325 } 00326 00327 return S_OK; 00328 } 00329 00330 static HRESULT WINAPI xmlnodemap_get_item( 00331 IXMLDOMNamedNodeMap *iface, 00332 LONG index, 00333 IXMLDOMNode** listItem) 00334 { 00335 xmlnodemap *This = impl_from_IXMLDOMNamedNodeMap( iface ); 00336 xmlNodePtr node; 00337 xmlAttrPtr curr; 00338 LONG attrIndex; 00339 00340 TRACE("(%p)->(%d %p)\n", This, index, listItem); 00341 00342 *listItem = NULL; 00343 00344 if (index < 0) 00345 return S_FALSE; 00346 00347 node = xmlNodePtr_from_domnode( This->node, 0 ); 00348 curr = node->properties; 00349 00350 for (attrIndex = 0; attrIndex < index; attrIndex++) { 00351 if (curr->next == NULL) 00352 return S_FALSE; 00353 else 00354 curr = curr->next; 00355 } 00356 00357 *listItem = create_node( (xmlNodePtr) curr ); 00358 00359 return S_OK; 00360 } 00361 00362 static HRESULT WINAPI xmlnodemap_get_length( 00363 IXMLDOMNamedNodeMap *iface, 00364 LONG *listLength) 00365 { 00366 xmlNodePtr node; 00367 xmlAttrPtr first; 00368 xmlAttrPtr curr; 00369 LONG attrCount; 00370 00371 xmlnodemap *This = impl_from_IXMLDOMNamedNodeMap( iface ); 00372 00373 TRACE("(%p)->(%p)\n", This, listLength); 00374 00375 if( !listLength ) 00376 return E_INVALIDARG; 00377 00378 node = xmlNodePtr_from_domnode( This->node, 0 ); 00379 if ( !node ) 00380 return E_FAIL; 00381 00382 first = node->properties; 00383 if (first == NULL) { 00384 *listLength = 0; 00385 return S_OK; 00386 } 00387 00388 curr = first; 00389 attrCount = 1; 00390 while (curr->next != NULL) { 00391 attrCount++; 00392 curr = curr->next; 00393 } 00394 *listLength = attrCount; 00395 00396 return S_OK; 00397 } 00398 00399 static HRESULT WINAPI xmlnodemap_getQualifiedItem( 00400 IXMLDOMNamedNodeMap *iface, 00401 BSTR baseName, 00402 BSTR namespaceURI, 00403 IXMLDOMNode** qualifiedItem) 00404 { 00405 xmlnodemap *This = impl_from_IXMLDOMNamedNodeMap( iface ); 00406 FIXME("(%p)->(%s %s %p)\n", This, debugstr_w(baseName), debugstr_w(namespaceURI), qualifiedItem); 00407 return E_NOTIMPL; 00408 } 00409 00410 static HRESULT WINAPI xmlnodemap_removeQualifiedItem( 00411 IXMLDOMNamedNodeMap *iface, 00412 BSTR baseName, 00413 BSTR namespaceURI, 00414 IXMLDOMNode** qualifiedItem) 00415 { 00416 xmlnodemap *This = impl_from_IXMLDOMNamedNodeMap( iface ); 00417 FIXME("(%p)->(%s %s %p)\n", This, debugstr_w(baseName), debugstr_w(namespaceURI), qualifiedItem); 00418 return E_NOTIMPL; 00419 } 00420 00421 static HRESULT WINAPI xmlnodemap_nextNode( 00422 IXMLDOMNamedNodeMap *iface, 00423 IXMLDOMNode** nextItem) 00424 { 00425 xmlnodemap *This = impl_from_IXMLDOMNamedNodeMap( iface ); 00426 xmlNodePtr node; 00427 xmlAttrPtr curr; 00428 LONG attrIndex; 00429 00430 TRACE("(%p)->(%p: %d)\n", This, nextItem, This->iterator); 00431 00432 *nextItem = NULL; 00433 00434 node = xmlNodePtr_from_domnode( This->node, 0 ); 00435 curr = node->properties; 00436 00437 for (attrIndex = 0; attrIndex < This->iterator; attrIndex++) { 00438 if (curr->next == NULL) 00439 return S_FALSE; 00440 else 00441 curr = curr->next; 00442 } 00443 00444 This->iterator++; 00445 00446 *nextItem = create_node( (xmlNodePtr) curr ); 00447 00448 return S_OK; 00449 } 00450 00451 static HRESULT WINAPI xmlnodemap_reset( 00452 IXMLDOMNamedNodeMap *iface ) 00453 { 00454 xmlnodemap *This = impl_from_IXMLDOMNamedNodeMap( iface ); 00455 00456 TRACE("(%p: %d)\n", This, This->iterator); 00457 00458 This->iterator = 0; 00459 00460 return S_OK; 00461 } 00462 00463 static HRESULT WINAPI xmlnodemap__newEnum( 00464 IXMLDOMNamedNodeMap *iface, 00465 IUnknown** ppUnk) 00466 { 00467 xmlnodemap *This = impl_from_IXMLDOMNamedNodeMap( iface ); 00468 FIXME("(%p)->(%p)\n", This, ppUnk); 00469 return E_NOTIMPL; 00470 } 00471 00472 static const struct IXMLDOMNamedNodeMapVtbl xmlnodemap_vtbl = 00473 { 00474 xmlnodemap_QueryInterface, 00475 xmlnodemap_AddRef, 00476 xmlnodemap_Release, 00477 xmlnodemap_GetTypeInfoCount, 00478 xmlnodemap_GetTypeInfo, 00479 xmlnodemap_GetIDsOfNames, 00480 xmlnodemap_Invoke, 00481 xmlnodemap_getNamedItem, 00482 xmlnodemap_setNamedItem, 00483 xmlnodemap_removeNamedItem, 00484 xmlnodemap_get_item, 00485 xmlnodemap_get_length, 00486 xmlnodemap_getQualifiedItem, 00487 xmlnodemap_removeQualifiedItem, 00488 xmlnodemap_nextNode, 00489 xmlnodemap_reset, 00490 xmlnodemap__newEnum, 00491 }; 00492 00493 static HRESULT WINAPI support_error_QueryInterface( 00494 ISupportErrorInfo *iface, 00495 REFIID riid, void** ppvObject ) 00496 { 00497 xmlnodemap *This = impl_from_ISupportErrorInfo( iface ); 00498 TRACE("%p %s %p\n", iface, debugstr_guid(riid), ppvObject); 00499 00500 return IXMLDOMNamedNodeMap_QueryInterface((IXMLDOMNamedNodeMap*)&This->lpVtbl, riid, ppvObject); 00501 } 00502 00503 static ULONG WINAPI support_error_AddRef( 00504 ISupportErrorInfo *iface ) 00505 { 00506 xmlnodemap *This = impl_from_ISupportErrorInfo( iface ); 00507 return IXMLDOMNamedNodeMap_AddRef((IXMLDOMNamedNodeMap*)&This->lpVtbl); 00508 } 00509 00510 static ULONG WINAPI support_error_Release( 00511 ISupportErrorInfo *iface ) 00512 { 00513 xmlnodemap *This = impl_from_ISupportErrorInfo( iface ); 00514 return IXMLDOMNamedNodeMap_Release((IXMLDOMNamedNodeMap*)&This->lpVtbl); 00515 } 00516 00517 static HRESULT WINAPI support_error_InterfaceSupportsErrorInfo( 00518 ISupportErrorInfo *iface, 00519 REFIID riid ) 00520 { 00521 FIXME("(%p)->(%s)\n", iface, debugstr_guid(riid)); 00522 return S_FALSE; 00523 } 00524 00525 static const struct ISupportErrorInfoVtbl support_error_vtbl = 00526 { 00527 support_error_QueryInterface, 00528 support_error_AddRef, 00529 support_error_Release, 00530 support_error_InterfaceSupportsErrorInfo 00531 }; 00532 00533 IXMLDOMNamedNodeMap *create_nodemap( IXMLDOMNode *node ) 00534 { 00535 xmlnodemap *nodemap; 00536 00537 nodemap = heap_alloc( sizeof *nodemap ); 00538 if ( !nodemap ) 00539 return NULL; 00540 00541 nodemap->lpVtbl = &xmlnodemap_vtbl; 00542 nodemap->lpSEIVtbl = &support_error_vtbl; 00543 nodemap->node = node; 00544 nodemap->ref = 1; 00545 nodemap->iterator = 0; 00546 00547 IXMLDOMNode_AddRef( node ); 00548 /* Since we AddRef a node here, we don't need to call xmldoc_add_ref() */ 00549 00550 return (IXMLDOMNamedNodeMap*) &nodemap->lpVtbl; 00551 } 00552 00553 #endif Generated on Sat May 26 2012 04:23:56 for ReactOS by
1.7.6.1
|