Home | Info | Community | Development | myReactOS | Contact Us
ReactOS Development > Doxygensaxreader.c
Go to the documentation of this file.
00001 /* 00002 * SAX Reader implementation 00003 * 00004 * Copyright 2008 Alistair Leslie-Hughes 00005 * Copyright 2008 Piotr Caban 00006 * 00007 * This library is free software; you can redistribute it and/or 00008 * modify it under the terms of the GNU Lesser General Public 00009 * License as published by the Free Software Foundation; either 00010 * version 2.1 of the License, or (at your option) any later version. 00011 * 00012 * This library is distributed in the hope that it will be useful, 00013 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00015 * Lesser General Public License for more details. 00016 * 00017 * You should have received a copy of the GNU Lesser General Public 00018 * License along with this library; if not, write to the Free Software 00019 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA 00020 */ 00021 #define COBJMACROS 00022 00023 #include "config.h" 00024 00025 #include <stdarg.h> 00026 #include <assert.h> 00027 #include "windef.h" 00028 #include "winbase.h" 00029 #include "winuser.h" 00030 #include "winnls.h" 00031 #include "ole2.h" 00032 #include "msxml2.h" 00033 #include "wininet.h" 00034 #include "urlmon.h" 00035 #include "winreg.h" 00036 #include "shlwapi.h" 00037 00038 #include "wine/debug.h" 00039 00040 #include "msxml_private.h" 00041 00042 WINE_DEFAULT_DEBUG_CHANNEL(msxml); 00043 00044 #ifdef HAVE_LIBXML2 00045 00046 #include <libxml/SAX2.h> 00047 #include <libxml/parserInternals.h> 00048 00049 typedef struct _saxreader 00050 { 00051 const struct IVBSAXXMLReaderVtbl *lpVBSAXXMLReaderVtbl; 00052 const struct ISAXXMLReaderVtbl *lpSAXXMLReaderVtbl; 00053 LONG ref; 00054 struct ISAXContentHandler *contentHandler; 00055 struct IVBSAXContentHandler *vbcontentHandler; 00056 struct ISAXErrorHandler *errorHandler; 00057 struct IVBSAXErrorHandler *vberrorHandler; 00058 struct ISAXLexicalHandler *lexicalHandler; 00059 struct IVBSAXLexicalHandler *vblexicalHandler; 00060 struct ISAXDeclHandler *declHandler; 00061 struct IVBSAXDeclHandler *vbdeclHandler; 00062 xmlSAXHandler sax; 00063 BOOL isParsing; 00064 } saxreader; 00065 00066 typedef struct _saxlocator 00067 { 00068 const struct IVBSAXLocatorVtbl *lpVBSAXLocatorVtbl; 00069 const struct ISAXLocatorVtbl *lpSAXLocatorVtbl; 00070 LONG ref; 00071 saxreader *saxreader; 00072 HRESULT ret; 00073 xmlParserCtxtPtr pParserCtxt; 00074 WCHAR *publicId; 00075 WCHAR *systemId; 00076 xmlChar *lastCur; 00077 int line; 00078 int realLine; 00079 int column; 00080 int realColumn; 00081 BOOL vbInterface; 00082 int nsStackSize; 00083 int nsStackLast; 00084 int *nsStack; 00085 } saxlocator; 00086 00087 typedef struct _saxattributes 00088 { 00089 const struct IVBSAXAttributesVtbl *lpVBSAXAttributesVtbl; 00090 const struct ISAXAttributesVtbl *lpSAXAttributesVtbl; 00091 LONG ref; 00092 int nb_attributes; 00093 BSTR *szLocalname; 00094 BSTR *szURI; 00095 BSTR *szValue; 00096 BSTR *szQName; 00097 } saxattributes; 00098 00099 static inline saxreader *impl_from_IVBSAXXMLReader( IVBSAXXMLReader *iface ) 00100 { 00101 return (saxreader *)((char*)iface - FIELD_OFFSET(saxreader, lpVBSAXXMLReaderVtbl)); 00102 } 00103 00104 static inline saxreader *impl_from_ISAXXMLReader( ISAXXMLReader *iface ) 00105 { 00106 return (saxreader *)((char*)iface - FIELD_OFFSET(saxreader, lpSAXXMLReaderVtbl)); 00107 } 00108 00109 static inline saxlocator *impl_from_IVBSAXLocator( IVBSAXLocator *iface ) 00110 { 00111 return (saxlocator *)((char*)iface - FIELD_OFFSET(saxlocator, lpVBSAXLocatorVtbl)); 00112 } 00113 00114 static inline saxlocator *impl_from_ISAXLocator( ISAXLocator *iface ) 00115 { 00116 return (saxlocator *)((char*)iface - FIELD_OFFSET(saxlocator, lpSAXLocatorVtbl)); 00117 } 00118 00119 static inline saxattributes *impl_from_IVBSAXAttributes( IVBSAXAttributes *iface ) 00120 { 00121 return (saxattributes *)((char*)iface - FIELD_OFFSET(saxattributes, lpVBSAXAttributesVtbl)); 00122 } 00123 00124 static inline saxattributes *impl_from_ISAXAttributes( ISAXAttributes *iface ) 00125 { 00126 return (saxattributes *)((char*)iface - FIELD_OFFSET(saxattributes, lpSAXAttributesVtbl)); 00127 } 00128 00129 static inline BOOL has_content_handler(const saxlocator *locator) 00130 { 00131 return (locator->vbInterface && locator->saxreader->vbcontentHandler) || 00132 (!locator->vbInterface && locator->saxreader->contentHandler); 00133 } 00134 00135 static HRESULT namespacePush(saxlocator *locator, int ns) 00136 { 00137 if(locator->nsStackLast>=locator->nsStackSize) 00138 { 00139 int *new_stack; 00140 00141 new_stack = HeapReAlloc(GetProcessHeap(), 0, 00142 locator->nsStack, sizeof(int)*locator->nsStackSize*2); 00143 if(!new_stack) return E_OUTOFMEMORY; 00144 locator->nsStack = new_stack; 00145 locator->nsStackSize *= 2; 00146 } 00147 locator->nsStack[locator->nsStackLast++] = ns; 00148 00149 return S_OK; 00150 } 00151 00152 static int namespacePop(saxlocator *locator) 00153 { 00154 if(locator->nsStackLast == 0) return 0; 00155 return locator->nsStack[--locator->nsStackLast]; 00156 } 00157 00158 static BSTR bstr_from_xmlCharN(const xmlChar *buf, int len) 00159 { 00160 DWORD dLen; 00161 BSTR bstr; 00162 00163 if (!buf) 00164 return NULL; 00165 00166 dLen = MultiByteToWideChar(CP_UTF8, 0, (LPCSTR)buf, len, NULL, 0); 00167 if(len != -1) dLen++; 00168 bstr = SysAllocStringLen(NULL, dLen-1); 00169 if (!bstr) 00170 return NULL; 00171 MultiByteToWideChar(CP_UTF8, 0, (LPCSTR)buf, len, bstr, dLen); 00172 if(len != -1) bstr[dLen-1] = '\0'; 00173 00174 return bstr; 00175 } 00176 00177 static BSTR QName_from_xmlChar(const xmlChar *prefix, const xmlChar *name) 00178 { 00179 DWORD dLen, dLast; 00180 BSTR bstr; 00181 00182 if(!name) return NULL; 00183 00184 if(!prefix || *prefix=='\0') 00185 return bstr_from_xmlChar(name); 00186 00187 dLen = MultiByteToWideChar(CP_UTF8, 0, (LPCSTR)prefix, -1, NULL, 0) 00188 + MultiByteToWideChar(CP_UTF8, 0, (LPCSTR)name, -1, NULL, 0); 00189 bstr = SysAllocStringLen(NULL, dLen-1); 00190 if(!bstr) 00191 return NULL; 00192 00193 dLast = MultiByteToWideChar(CP_UTF8, 0, (LPCSTR)prefix, -1, bstr, dLen); 00194 bstr[dLast-1] = ':'; 00195 MultiByteToWideChar(CP_UTF8, 0, (LPCSTR)name, -1, &bstr[dLast], dLen-dLast); 00196 00197 return bstr; 00198 } 00199 00200 static void format_error_message_from_id(saxlocator *This, HRESULT hr) 00201 { 00202 xmlStopParser(This->pParserCtxt); 00203 This->ret = hr; 00204 00205 if((This->vbInterface && This->saxreader->vberrorHandler) 00206 || (!This->vbInterface && This->saxreader->errorHandler)) 00207 { 00208 WCHAR msg[1024]; 00209 if(!FormatMessageW(FORMAT_MESSAGE_FROM_SYSTEM, 00210 NULL, hr, 0, msg, sizeof(msg), NULL)) 00211 { 00212 FIXME("MSXML errors not yet supported.\n"); 00213 msg[0] = '\0'; 00214 } 00215 00216 if(This->vbInterface) 00217 { 00218 BSTR bstrMsg = SysAllocString(msg); 00219 IVBSAXErrorHandler_fatalError(This->saxreader->vberrorHandler, 00220 (IVBSAXLocator*)&This->lpVBSAXLocatorVtbl, &bstrMsg, hr); 00221 } 00222 else 00223 ISAXErrorHandler_fatalError(This->saxreader->errorHandler, 00224 (ISAXLocator*)&This->lpSAXLocatorVtbl, msg, hr); 00225 } 00226 } 00227 00228 static void update_position(saxlocator *This, xmlChar *end) 00229 { 00230 if(This->lastCur == NULL) 00231 { 00232 This->lastCur = (xmlChar*)This->pParserCtxt->input->base; 00233 This->realLine = 1; 00234 This->realColumn = 1; 00235 } 00236 else if(This->lastCur < This->pParserCtxt->input->base) 00237 { 00238 This->lastCur = (xmlChar*)This->pParserCtxt->input->base; 00239 This->realLine = 1; 00240 This->realColumn = 1; 00241 } 00242 00243 if(This->pParserCtxt->input->cur<This->lastCur) 00244 { 00245 This->lastCur = (xmlChar*)This->pParserCtxt->input->base; 00246 This->realLine -= 1; 00247 This->realColumn = 1; 00248 } 00249 00250 if(!end) end = (xmlChar*)This->pParserCtxt->input->cur; 00251 00252 while(This->lastCur < end) 00253 { 00254 if(*(This->lastCur) == '\n') 00255 { 00256 This->realLine++; 00257 This->realColumn = 1; 00258 } 00259 else if(*(This->lastCur) == '\r' && 00260 (This->lastCur==This->pParserCtxt->input->end || 00261 *(This->lastCur+1)!='\n')) 00262 { 00263 This->realLine++; 00264 This->realColumn = 1; 00265 } 00266 else This->realColumn++; 00267 00268 This->lastCur++; 00269 00270 /* Count multibyte UTF8 encoded characters once */ 00271 while((*(This->lastCur)&0xC0) == 0x80) This->lastCur++; 00272 } 00273 00274 This->line = This->realLine; 00275 This->column = This->realColumn; 00276 } 00277 00278 /*** IVBSAXAttributes interface ***/ 00279 /*** IUnknown methods ***/ 00280 static HRESULT WINAPI ivbsaxattributes_QueryInterface( 00281 IVBSAXAttributes* iface, 00282 REFIID riid, 00283 void **ppvObject) 00284 { 00285 saxattributes *This = impl_from_IVBSAXAttributes(iface); 00286 00287 TRACE("%p %s %p\n", This, debugstr_guid(riid), ppvObject); 00288 00289 *ppvObject = NULL; 00290 00291 if (IsEqualGUID(riid, &IID_IUnknown) || 00292 IsEqualGUID(riid, &IID_IDispatch) || 00293 IsEqualGUID(riid, &IID_IVBSAXAttributes)) 00294 { 00295 *ppvObject = iface; 00296 } 00297 else 00298 { 00299 FIXME("interface %s not implemented\n", debugstr_guid(riid)); 00300 return E_NOINTERFACE; 00301 } 00302 00303 IVBSAXAttributes_AddRef(iface); 00304 00305 return S_OK; 00306 } 00307 00308 static ULONG WINAPI ivbsaxattributes_AddRef(IVBSAXAttributes* iface) 00309 { 00310 saxattributes *This = impl_from_IVBSAXAttributes(iface); 00311 return ISAXAttributes_AddRef((ISAXAttributes*)&This->lpSAXAttributesVtbl); 00312 } 00313 00314 static ULONG WINAPI ivbsaxattributes_Release(IVBSAXAttributes* iface) 00315 { 00316 saxattributes *This = impl_from_IVBSAXAttributes(iface); 00317 return ISAXAttributes_Release((ISAXAttributes*)&This->lpSAXAttributesVtbl); 00318 } 00319 00320 /*** IDispatch methods ***/ 00321 static HRESULT WINAPI ivbsaxattributes_GetTypeInfoCount( IVBSAXAttributes *iface, UINT* pctinfo ) 00322 { 00323 saxattributes *This = impl_from_IVBSAXAttributes( iface ); 00324 00325 TRACE("(%p)->(%p)\n", This, pctinfo); 00326 00327 *pctinfo = 1; 00328 00329 return S_OK; 00330 } 00331 00332 static HRESULT WINAPI ivbsaxattributes_GetTypeInfo( 00333 IVBSAXAttributes *iface, 00334 UINT iTInfo, LCID lcid, ITypeInfo** ppTInfo ) 00335 { 00336 saxattributes *This = impl_from_IVBSAXAttributes( iface ); 00337 HRESULT hr; 00338 00339 TRACE("(%p)->(%u %u %p)\n", This, iTInfo, lcid, ppTInfo); 00340 00341 hr = get_typeinfo(IVBSAXAttributes_tid, ppTInfo); 00342 00343 return hr; 00344 } 00345 00346 static HRESULT WINAPI ivbsaxattributes_GetIDsOfNames( 00347 IVBSAXAttributes *iface, 00348 REFIID riid, 00349 LPOLESTR* rgszNames, 00350 UINT cNames, 00351 LCID lcid, 00352 DISPID* rgDispId) 00353 { 00354 saxattributes *This = impl_from_IVBSAXAttributes( iface ); 00355 ITypeInfo *typeinfo; 00356 HRESULT hr; 00357 00358 TRACE("(%p)->(%s %p %u %u %p)\n", This, debugstr_guid(riid), rgszNames, cNames, 00359 lcid, rgDispId); 00360 00361 if(!rgszNames || cNames == 0 || !rgDispId) 00362 return E_INVALIDARG; 00363 00364 hr = get_typeinfo(IVBSAXAttributes_tid, &typeinfo); 00365 if(SUCCEEDED(hr)) 00366 { 00367 hr = ITypeInfo_GetIDsOfNames(typeinfo, rgszNames, cNames, rgDispId); 00368 ITypeInfo_Release(typeinfo); 00369 } 00370 00371 return hr; 00372 } 00373 00374 static HRESULT WINAPI ivbsaxattributes_Invoke( 00375 IVBSAXAttributes *iface, 00376 DISPID dispIdMember, 00377 REFIID riid, 00378 LCID lcid, 00379 WORD wFlags, 00380 DISPPARAMS* pDispParams, 00381 VARIANT* pVarResult, 00382 EXCEPINFO* pExcepInfo, 00383 UINT* puArgErr) 00384 { 00385 saxattributes *This = impl_from_IVBSAXAttributes( iface ); 00386 ITypeInfo *typeinfo; 00387 HRESULT hr; 00388 00389 TRACE("(%p)->(%d %s %d %d %p %p %p %p)\n", This, dispIdMember, debugstr_guid(riid), 00390 lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr); 00391 00392 hr = get_typeinfo(IVBSAXAttributes_tid, &typeinfo); 00393 if(SUCCEEDED(hr)) 00394 { 00395 hr = ITypeInfo_Invoke(typeinfo, &(This->lpVBSAXAttributesVtbl), dispIdMember, wFlags, pDispParams, 00396 pVarResult, pExcepInfo, puArgErr); 00397 ITypeInfo_Release(typeinfo); 00398 } 00399 00400 return hr; 00401 } 00402 00403 /*** IVBSAXAttributes methods ***/ 00404 static HRESULT WINAPI ivbsaxattributes_get_length( 00405 IVBSAXAttributes* iface, 00406 int *nLength) 00407 { 00408 saxattributes *This = impl_from_IVBSAXAttributes( iface ); 00409 return ISAXAttributes_getLength( 00410 (ISAXAttributes*)&This->lpSAXAttributesVtbl, 00411 nLength); 00412 } 00413 00414 static HRESULT WINAPI ivbsaxattributes_getURI( 00415 IVBSAXAttributes* iface, 00416 int nIndex, 00417 BSTR *uri) 00418 { 00419 int len; 00420 saxattributes *This = impl_from_IVBSAXAttributes( iface ); 00421 return ISAXAttributes_getURI( 00422 (ISAXAttributes*)&This->lpSAXAttributesVtbl, 00423 nIndex, (const WCHAR**)uri, &len); 00424 } 00425 00426 static HRESULT WINAPI ivbsaxattributes_getLocalName( 00427 IVBSAXAttributes* iface, 00428 int nIndex, 00429 BSTR *localName) 00430 { 00431 int len; 00432 saxattributes *This = impl_from_IVBSAXAttributes( iface ); 00433 return ISAXAttributes_getLocalName( 00434 (ISAXAttributes*)&This->lpSAXAttributesVtbl, 00435 nIndex, (const WCHAR**)localName, &len); 00436 } 00437 00438 static HRESULT WINAPI ivbsaxattributes_getQName( 00439 IVBSAXAttributes* iface, 00440 int nIndex, 00441 BSTR *QName) 00442 { 00443 int len; 00444 saxattributes *This = impl_from_IVBSAXAttributes( iface ); 00445 return ISAXAttributes_getQName( 00446 (ISAXAttributes*)&This->lpSAXAttributesVtbl, 00447 nIndex, (const WCHAR**)QName, &len); 00448 } 00449 00450 static HRESULT WINAPI ivbsaxattributes_getIndexFromName( 00451 IVBSAXAttributes* iface, 00452 BSTR uri, 00453 BSTR localName, 00454 int *index) 00455 { 00456 saxattributes *This = impl_from_IVBSAXAttributes( iface ); 00457 return ISAXAttributes_getIndexFromName( 00458 (ISAXAttributes*)&This->lpSAXAttributesVtbl, uri, SysStringLen(uri), 00459 localName, SysStringLen(localName), index); 00460 } 00461 00462 static HRESULT WINAPI ivbsaxattributes_getIndexFromQName( 00463 IVBSAXAttributes* iface, 00464 BSTR QName, 00465 int *index) 00466 { 00467 saxattributes *This = impl_from_IVBSAXAttributes( iface ); 00468 return ISAXAttributes_getIndexFromQName( 00469 (ISAXAttributes*)&This->lpSAXAttributesVtbl, QName, 00470 SysStringLen(QName), index); 00471 } 00472 00473 static HRESULT WINAPI ivbsaxattributes_getType( 00474 IVBSAXAttributes* iface, 00475 int nIndex, 00476 BSTR *type) 00477 { 00478 int len; 00479 saxattributes *This = impl_from_IVBSAXAttributes( iface ); 00480 return ISAXAttributes_getType( 00481 (ISAXAttributes*)&This->lpSAXAttributesVtbl, 00482 nIndex, (const WCHAR**)type, &len); 00483 } 00484 00485 static HRESULT WINAPI ivbsaxattributes_getTypeFromName( 00486 IVBSAXAttributes* iface, 00487 BSTR uri, 00488 BSTR localName, 00489 BSTR *type) 00490 { 00491 int len; 00492 saxattributes *This = impl_from_IVBSAXAttributes( iface ); 00493 return ISAXAttributes_getTypeFromName( 00494 (ISAXAttributes*)&This->lpSAXAttributesVtbl, uri, SysStringLen(uri), 00495 localName, SysStringLen(localName), (const WCHAR**)type, &len); 00496 } 00497 00498 static HRESULT WINAPI ivbsaxattributes_getTypeFromQName( 00499 IVBSAXAttributes* iface, 00500 BSTR QName, 00501 BSTR *type) 00502 { 00503 int len; 00504 saxattributes *This = impl_from_IVBSAXAttributes( iface ); 00505 return ISAXAttributes_getTypeFromQName( 00506 (ISAXAttributes*)&This->lpSAXAttributesVtbl, QName, 00507 SysStringLen(QName), (const WCHAR**)type, &len); 00508 } 00509 00510 static HRESULT WINAPI ivbsaxattributes_getValue( 00511 IVBSAXAttributes* iface, 00512 int nIndex, 00513 BSTR *value) 00514 { 00515 int len; 00516 saxattributes *This = impl_from_IVBSAXAttributes( iface ); 00517 return ISAXAttributes_getValue( 00518 (ISAXAttributes*)&This->lpSAXAttributesVtbl, 00519 nIndex, (const WCHAR**)value, &len); 00520 } 00521 00522 static HRESULT WINAPI ivbsaxattributes_getValueFromName( 00523 IVBSAXAttributes* iface, 00524 BSTR uri, 00525 BSTR localName, 00526 BSTR *value) 00527 { 00528 int len; 00529 saxattributes *This = impl_from_IVBSAXAttributes( iface ); 00530 return ISAXAttributes_getValueFromName( 00531 (ISAXAttributes*)&This->lpSAXAttributesVtbl, uri, SysStringLen(uri), 00532 localName, SysStringLen(localName), (const WCHAR**)value, &len); 00533 } 00534 00535 static HRESULT WINAPI ivbsaxattributes_getValueFromQName( 00536 IVBSAXAttributes* iface, 00537 BSTR QName, 00538 BSTR *value) 00539 { 00540 int len; 00541 saxattributes *This = impl_from_IVBSAXAttributes( iface ); 00542 return ISAXAttributes_getValueFromQName( 00543 (ISAXAttributes*)&This->lpSAXAttributesVtbl, QName, 00544 SysStringLen(QName), (const WCHAR**)value, &len); 00545 } 00546 00547 static const struct IVBSAXAttributesVtbl ivbsaxattributes_vtbl = 00548 { 00549 ivbsaxattributes_QueryInterface, 00550 ivbsaxattributes_AddRef, 00551 ivbsaxattributes_Release, 00552 ivbsaxattributes_GetTypeInfoCount, 00553 ivbsaxattributes_GetTypeInfo, 00554 ivbsaxattributes_GetIDsOfNames, 00555 ivbsaxattributes_Invoke, 00556 ivbsaxattributes_get_length, 00557 ivbsaxattributes_getURI, 00558 ivbsaxattributes_getLocalName, 00559 ivbsaxattributes_getQName, 00560 ivbsaxattributes_getIndexFromName, 00561 ivbsaxattributes_getIndexFromQName, 00562 ivbsaxattributes_getType, 00563 ivbsaxattributes_getTypeFromName, 00564 ivbsaxattributes_getTypeFromQName, 00565 ivbsaxattributes_getValue, 00566 ivbsaxattributes_getValueFromName, 00567 ivbsaxattributes_getValueFromQName 00568 }; 00569 00570 /*** ISAXAttributes interface ***/ 00571 /*** IUnknown methods ***/ 00572 static HRESULT WINAPI isaxattributes_QueryInterface( 00573 ISAXAttributes* iface, 00574 REFIID riid, 00575 void **ppvObject) 00576 { 00577 saxattributes *This = impl_from_ISAXAttributes(iface); 00578 00579 TRACE("%p %s %p\n", This, debugstr_guid(riid), ppvObject); 00580 00581 *ppvObject = NULL; 00582 00583 if (IsEqualGUID(riid, &IID_IUnknown) || 00584 IsEqualGUID(riid, &IID_ISAXAttributes)) 00585 { 00586 *ppvObject = iface; 00587 } 00588 else 00589 { 00590 FIXME("interface %s not implemented\n", debugstr_guid(riid)); 00591 return E_NOINTERFACE; 00592 } 00593 00594 ISAXAttributes_AddRef(iface); 00595 00596 return S_OK; 00597 } 00598 00599 static ULONG WINAPI isaxattributes_AddRef(ISAXAttributes* iface) 00600 { 00601 saxattributes *This = impl_from_ISAXAttributes(iface); 00602 TRACE("%p\n", This); 00603 return InterlockedIncrement(&This->ref); 00604 } 00605 00606 static ULONG WINAPI isaxattributes_Release(ISAXAttributes* iface) 00607 { 00608 saxattributes *This = impl_from_ISAXAttributes(iface); 00609 LONG ref; 00610 00611 TRACE("%p\n", This); 00612 00613 ref = InterlockedDecrement(&This->ref); 00614 if (ref==0) 00615 { 00616 int index; 00617 for(index=0; index<This->nb_attributes; index++) 00618 { 00619 SysFreeString(This->szLocalname[index]); 00620 SysFreeString(This->szURI[index]); 00621 SysFreeString(This->szValue[index]); 00622 SysFreeString(This->szQName[index]); 00623 } 00624 00625 heap_free(This->szLocalname); 00626 heap_free(This->szURI); 00627 heap_free(This->szValue); 00628 heap_free(This->szQName); 00629 00630 heap_free(This); 00631 } 00632 00633 return ref; 00634 } 00635 00636 /*** ISAXAttributes methods ***/ 00637 static HRESULT WINAPI isaxattributes_getLength( 00638 ISAXAttributes* iface, 00639 int *length) 00640 { 00641 saxattributes *This = impl_from_ISAXAttributes( iface ); 00642 00643 *length = This->nb_attributes; 00644 TRACE("Length set to %d\n", *length); 00645 return S_OK; 00646 } 00647 00648 static HRESULT WINAPI isaxattributes_getURI( 00649 ISAXAttributes* iface, 00650 int nIndex, 00651 const WCHAR **pUrl, 00652 int *pUriSize) 00653 { 00654 saxattributes *This = impl_from_ISAXAttributes( iface ); 00655 TRACE("(%p)->(%d)\n", This, nIndex); 00656 00657 if(nIndex>=This->nb_attributes || nIndex<0) return E_INVALIDARG; 00658 if(!pUrl || !pUriSize) return E_POINTER; 00659 00660 *pUriSize = SysStringLen(This->szURI[nIndex]); 00661 *pUrl = This->szURI[nIndex]; 00662 00663 return S_OK; 00664 } 00665 00666 static HRESULT WINAPI isaxattributes_getLocalName( 00667 ISAXAttributes* iface, 00668 int nIndex, 00669 const WCHAR **pLocalName, 00670 int *pLocalNameLength) 00671 { 00672 saxattributes *This = impl_from_ISAXAttributes( iface ); 00673 TRACE("(%p)->(%d)\n", This, nIndex); 00674 00675 if(nIndex>=This->nb_attributes || nIndex<0) return E_INVALIDARG; 00676 if(!pLocalName || !pLocalNameLength) return E_POINTER; 00677 00678 *pLocalNameLength = SysStringLen(This->szLocalname[nIndex]); 00679 *pLocalName = This->szLocalname[nIndex]; 00680 00681 return S_OK; 00682 } 00683 00684 static HRESULT WINAPI isaxattributes_getQName( 00685 ISAXAttributes* iface, 00686 int nIndex, 00687 const WCHAR **pQName, 00688 int *pQNameLength) 00689 { 00690 saxattributes *This = impl_from_ISAXAttributes( iface ); 00691 TRACE("(%p)->(%d)\n", This, nIndex); 00692 00693 if(nIndex>=This->nb_attributes || nIndex<0) return E_INVALIDARG; 00694 if(!pQName || !pQNameLength) return E_POINTER; 00695 00696 *pQNameLength = SysStringLen(This->szQName[nIndex]); 00697 *pQName = This->szQName[nIndex]; 00698 00699 return S_OK; 00700 } 00701 00702 static HRESULT WINAPI isaxattributes_getName( 00703 ISAXAttributes* iface, 00704 int nIndex, 00705 const WCHAR **pUri, 00706 int *pUriLength, 00707 const WCHAR **pLocalName, 00708 int *pLocalNameSize, 00709 const WCHAR **pQName, 00710 int *pQNameLength) 00711 { 00712 saxattributes *This = impl_from_ISAXAttributes( iface ); 00713 TRACE("(%p)->(%d)\n", This, nIndex); 00714 00715 if(nIndex>=This->nb_attributes || nIndex<0) return E_INVALIDARG; 00716 if(!pUri || !pUriLength || !pLocalName || !pLocalNameSize 00717 || !pQName || !pQNameLength) return E_POINTER; 00718 00719 *pUriLength = SysStringLen(This->szURI[nIndex]); 00720 *pUri = This->szURI[nIndex]; 00721 *pLocalNameSize = SysStringLen(This->szLocalname[nIndex]); 00722 *pLocalName = This->szLocalname[nIndex]; 00723 *pQNameLength = SysStringLen(This->szQName[nIndex]); 00724 *pQName = This->szQName[nIndex]; 00725 00726 return S_OK; 00727 } 00728 00729 static HRESULT WINAPI isaxattributes_getIndexFromName( 00730 ISAXAttributes* iface, 00731 const WCHAR *pUri, 00732 int cUriLength, 00733 const WCHAR *pLocalName, 00734 int cocalNameLength, 00735 int *index) 00736 { 00737 saxattributes *This = impl_from_ISAXAttributes( iface ); 00738 int i; 00739 TRACE("(%p)->(%s, %d, %s, %d)\n", This, debugstr_w(pUri), cUriLength, 00740 debugstr_w(pLocalName), cocalNameLength); 00741 00742 if(!pUri || !pLocalName || !index) return E_POINTER; 00743 00744 for(i=0; i<This->nb_attributes; i++) 00745 { 00746 if(cUriLength!=SysStringLen(This->szURI[i]) 00747 || cocalNameLength!=SysStringLen(This->szLocalname[i])) 00748 continue; 00749 if(cUriLength && memcmp(pUri, This->szURI[i], 00750 sizeof(WCHAR)*cUriLength)) 00751 continue; 00752 if(cocalNameLength && memcmp(pLocalName, This->szLocalname[i], 00753 sizeof(WCHAR)*cocalNameLength)) 00754 continue; 00755 00756 *index = i; 00757 return S_OK; 00758 } 00759 00760 return E_INVALIDARG; 00761 } 00762 00763 static HRESULT WINAPI isaxattributes_getIndexFromQName( 00764 ISAXAttributes* iface, 00765 const WCHAR *pQName, 00766 int nQNameLength, 00767 int *index) 00768 { 00769 saxattributes *This = impl_from_ISAXAttributes( iface ); 00770 int i; 00771 TRACE("(%p)->(%s, %d)\n", This, debugstr_w(pQName), nQNameLength); 00772 00773 if(!pQName || !index) return E_POINTER; 00774 if(!nQNameLength) return E_INVALIDARG; 00775 00776 for(i=0; i<This->nb_attributes; i++) 00777 { 00778 if(nQNameLength!=SysStringLen(This->szQName[i])) continue; 00779 if(memcmp(pQName, This->szQName, sizeof(WCHAR)*nQNameLength)) continue; 00780 00781 *index = i; 00782 return S_OK; 00783 } 00784 00785 return E_INVALIDARG; 00786 } 00787 00788 static HRESULT WINAPI isaxattributes_getType( 00789 ISAXAttributes* iface, 00790 int nIndex, 00791 const WCHAR **pType, 00792 int *pTypeLength) 00793 { 00794 saxattributes *This = impl_from_ISAXAttributes( iface ); 00795 00796 FIXME("(%p)->(%d) stub\n", This, nIndex); 00797 return E_NOTIMPL; 00798 } 00799 00800 static HRESULT WINAPI isaxattributes_getTypeFromName( 00801 ISAXAttributes* iface, 00802 const WCHAR *pUri, 00803 int nUri, 00804 const WCHAR *pLocalName, 00805 int nLocalName, 00806 const WCHAR **pType, 00807 int *nType) 00808 { 00809 saxattributes *This = impl_from_ISAXAttributes( iface ); 00810 00811 FIXME("(%p)->(%s, %d, %s, %d) stub\n", This, debugstr_w(pUri), nUri, 00812 debugstr_w(pLocalName), nLocalName); 00813 return E_NOTIMPL; 00814 } 00815 00816 static HRESULT WINAPI isaxattributes_getTypeFromQName( 00817 ISAXAttributes* iface, 00818 const WCHAR *pQName, 00819 int nQName, 00820 const WCHAR **pType, 00821 int *nType) 00822 { 00823 saxattributes *This = impl_from_ISAXAttributes( iface ); 00824 00825 FIXME("(%p)->(%s, %d) stub\n", This, debugstr_w(pQName), nQName); 00826 return E_NOTIMPL; 00827 } 00828 00829 static HRESULT WINAPI isaxattributes_getValue( 00830 ISAXAttributes* iface, 00831 int nIndex, 00832 const WCHAR **pValue, 00833 int *nValue) 00834 { 00835 saxattributes *This = impl_from_ISAXAttributes( iface ); 00836 TRACE("(%p)->(%d)\n", This, nIndex); 00837 00838 if(nIndex>=This->nb_attributes || nIndex<0) return E_INVALIDARG; 00839 if(!pValue || !nValue) return E_POINTER; 00840 00841 *nValue = SysStringLen(This->szValue[nIndex]); 00842 *pValue = This->szValue[nIndex]; 00843 00844 return S_OK; 00845 } 00846 00847 static HRESULT WINAPI isaxattributes_getValueFromName( 00848 ISAXAttributes* iface, 00849 const WCHAR *pUri, 00850 int nUri, 00851 const WCHAR *pLocalName, 00852 int nLocalName, 00853 const WCHAR **pValue, 00854 int *nValue) 00855 { 00856 HRESULT hr; 00857 int index; 00858 saxattributes *This = impl_from_ISAXAttributes( iface ); 00859 TRACE("(%p)->(%s, %d, %s, %d)\n", This, debugstr_w(pUri), nUri, 00860 debugstr_w(pLocalName), nLocalName); 00861 00862 hr = ISAXAttributes_getIndexFromName(iface, 00863 pUri, nUri, pLocalName, nLocalName, &index); 00864 if(hr==S_OK) hr = ISAXAttributes_getValue(iface, index, pValue, nValue); 00865 00866 return hr; 00867 } 00868 00869 static HRESULT WINAPI isaxattributes_getValueFromQName( 00870 ISAXAttributes* iface, 00871 const WCHAR *pQName, 00872 int nQName, 00873 const WCHAR **pValue, 00874 int *nValue) 00875 { 00876 HRESULT hr; 00877 int index; 00878 saxattributes *This = impl_from_ISAXAttributes( iface ); 00879 TRACE("(%p)->(%s, %d)\n", This, debugstr_w(pQName), nQName); 00880 00881 hr = ISAXAttributes_getIndexFromQName(iface, pQName, nQName, &index); 00882 if(hr==S_OK) hr = ISAXAttributes_getValue(iface, index, pValue, nValue); 00883 00884 return hr; 00885 } 00886 00887 static const struct ISAXAttributesVtbl isaxattributes_vtbl = 00888 { 00889 isaxattributes_QueryInterface, 00890 isaxattributes_AddRef, 00891 isaxattributes_Release, 00892 isaxattributes_getLength, 00893 isaxattributes_getURI, 00894 isaxattributes_getLocalName, 00895 isaxattributes_getQName, 00896 isaxattributes_getName, 00897 isaxattributes_getIndexFromName, 00898 isaxattributes_getIndexFromQName, 00899 isaxattributes_getType, 00900 isaxattributes_getTypeFromName, 00901 isaxattributes_getTypeFromQName, 00902 isaxattributes_getValue, 00903 isaxattributes_getValueFromName, 00904 isaxattributes_getValueFromQName 00905 }; 00906 00907 static HRESULT SAXAttributes_create(saxattributes **attr, 00908 int nb_namespaces, const xmlChar **xmlNamespaces, 00909 int nb_attributes, const xmlChar **xmlAttributes) 00910 { 00911 saxattributes *attributes; 00912 int index; 00913 static const xmlChar xmlns[] = "xmlns"; 00914 00915 attributes = heap_alloc(sizeof(*attributes)); 00916 if(!attributes) 00917 return E_OUTOFMEMORY; 00918 00919 attributes->lpVBSAXAttributesVtbl = &ivbsaxattributes_vtbl; 00920 attributes->lpSAXAttributesVtbl = &isaxattributes_vtbl; 00921 attributes->ref = 1; 00922 00923 attributes->nb_attributes = nb_namespaces+nb_attributes; 00924 00925 attributes->szLocalname = heap_alloc(sizeof(BSTR)*attributes->nb_attributes); 00926 attributes->szURI = heap_alloc(sizeof(BSTR)*attributes->nb_attributes); 00927 attributes->szValue = heap_alloc(sizeof(BSTR)*attributes->nb_attributes); 00928 attributes->szQName = heap_alloc(sizeof(BSTR)*attributes->nb_attributes); 00929 00930 if(!attributes->szLocalname || !attributes->szURI 00931 || !attributes->szValue || !attributes->szQName) 00932 { 00933 heap_free(attributes->szLocalname); 00934 heap_free(attributes->szURI); 00935 heap_free(attributes->szValue); 00936 heap_free(attributes->szQName); 00937 heap_free(attributes); 00938 return E_FAIL; 00939 } 00940 00941 for(index=0; index<nb_namespaces; index++) 00942 { 00943 attributes->szLocalname[index] = SysAllocStringLen(NULL, 0); 00944 attributes->szURI[index] = SysAllocStringLen(NULL, 0); 00945 attributes->szValue[index] = bstr_from_xmlChar(xmlNamespaces[2*index+1]); 00946 attributes->szQName[index] = QName_from_xmlChar(xmlns, xmlNamespaces[2*index]); 00947 } 00948 00949 for(index=0; index<nb_attributes; index++) 00950 { 00951 attributes->szLocalname[nb_namespaces+index] = 00952 bstr_from_xmlChar(xmlAttributes[index*5]); 00953 attributes->szURI[nb_namespaces+index] = 00954 bstr_from_xmlChar(xmlAttributes[index*5+2]); 00955 attributes->szValue[nb_namespaces+index] = 00956 bstr_from_xmlCharN(xmlAttributes[index*5+3], 00957 xmlAttributes[index*5+4]-xmlAttributes[index*5+3]); 00958 attributes->szQName[nb_namespaces+index] = 00959 QName_from_xmlChar(xmlAttributes[index*5+1], xmlAttributes[index*5]); 00960 } 00961 00962 *attr = attributes; 00963 00964 TRACE("returning %p\n", *attr); 00965 00966 return S_OK; 00967 } 00968 00969 /*** LibXML callbacks ***/ 00970 static void libxmlStartDocument(void *ctx) 00971 { 00972 saxlocator *This = ctx; 00973 HRESULT hr; 00974 00975 if(has_content_handler(This)) 00976 { 00977 if(This->vbInterface) 00978 hr = IVBSAXContentHandler_startDocument(This->saxreader->vbcontentHandler); 00979 else 00980 hr = ISAXContentHandler_startDocument(This->saxreader->contentHandler); 00981 00982 if(hr != S_OK) 00983 format_error_message_from_id(This, hr); 00984 } 00985 00986 update_position(This, NULL); 00987 } 00988 00989 static void libxmlEndDocument(void *ctx) 00990 { 00991 saxlocator *This = ctx; 00992 HRESULT hr; 00993 00994 This->column = 0; 00995 This->line = 0; 00996 00997 if(This->ret != S_OK) return; 00998 00999 if(has_content_handler(This)) 01000 { 01001 if(This->vbInterface) 01002 hr = IVBSAXContentHandler_endDocument(This->saxreader->vbcontentHandler); 01003 else 01004 hr = ISAXContentHandler_endDocument(This->saxreader->contentHandler); 01005 01006 if(hr != S_OK) 01007 format_error_message_from_id(This, hr); 01008 } 01009 } 01010 01011 static void libxmlStartElementNS( 01012 void *ctx, 01013 const xmlChar *localname, 01014 const xmlChar *prefix, 01015 const xmlChar *URI, 01016 int nb_namespaces, 01017 const xmlChar **namespaces, 01018 int nb_attributes, 01019 int nb_defaulted, 01020 const xmlChar **attributes) 01021 { 01022 BSTR NamespaceUri, LocalName, QName, Prefix, Uri; 01023 saxlocator *This = ctx; 01024 HRESULT hr; 01025 saxattributes *attr; 01026 int index; 01027 01028 if(*(This->pParserCtxt->input->cur) == '/') 01029 update_position(This, (xmlChar*)This->pParserCtxt->input->cur+2); 01030 else 01031 update_position(This, (xmlChar*)This->pParserCtxt->input->cur+1); 01032 01033 hr = namespacePush(This, nb_namespaces); 01034 if(hr==S_OK && has_content_handler(This)) 01035 { 01036 for(index=0; index<nb_namespaces; index++) 01037 { 01038 Prefix = bstr_from_xmlChar(namespaces[2*index]); 01039 Uri = bstr_from_xmlChar(namespaces[2*index+1]); 01040 01041 if(This->vbInterface) 01042 hr = IVBSAXContentHandler_startPrefixMapping( 01043 This->saxreader->vbcontentHandler, 01044 &Prefix, &Uri); 01045 else 01046 hr = ISAXContentHandler_startPrefixMapping( 01047 This->saxreader->contentHandler, 01048 Prefix, SysStringLen(Prefix), 01049 Uri, SysStringLen(Uri)); 01050 01051 SysFreeString(Prefix); 01052 SysFreeString(Uri); 01053 01054 if(hr != S_OK) 01055 { 01056 format_error_message_from_id(This, hr); 01057 return; 01058 } 01059 } 01060 01061 NamespaceUri = bstr_from_xmlChar(URI); 01062 LocalName = bstr_from_xmlChar(localname); 01063 QName = QName_from_xmlChar(prefix, localname); 01064 01065 hr = SAXAttributes_create(&attr, nb_namespaces, namespaces, nb_attributes, attributes); 01066 if(hr == S_OK) 01067 { 01068 if(This->vbInterface) 01069 hr = IVBSAXContentHandler_startElement( 01070 This->saxreader->vbcontentHandler, 01071 &NamespaceUri, &LocalName, &QName, 01072 (IVBSAXAttributes*)&attr->lpVBSAXAttributesVtbl); 01073 else 01074 hr = ISAXContentHandler_startElement( 01075 This->saxreader->contentHandler, 01076 NamespaceUri, SysStringLen(NamespaceUri), 01077 LocalName, SysStringLen(LocalName), 01078 QName, SysStringLen(QName), 01079 (ISAXAttributes*)&attr->lpSAXAttributesVtbl); 01080 01081 ISAXAttributes_Release((ISAXAttributes*)&attr->lpSAXAttributesVtbl); 01082 } 01083 01084 SysFreeString(NamespaceUri); 01085 SysFreeString(LocalName); 01086 SysFreeString(QName); 01087 } 01088 01089 if(hr != S_OK) 01090 format_error_message_from_id(This, hr); 01091 } 01092 01093 static void libxmlEndElementNS( 01094 void *ctx, 01095 const xmlChar *localname, 01096 const xmlChar *prefix, 01097 const xmlChar *URI) 01098 { 01099 BSTR NamespaceUri, LocalName, QName, Prefix; 01100 saxlocator *This = ctx; 01101 HRESULT hr; 01102 xmlChar *end; 01103 int nsNr, index; 01104 01105 end = (xmlChar*)This->pParserCtxt->input->cur; 01106 if(*(end-1) != '>' || *(end-2) != '/') 01107 while(end-2>=This->pParserCtxt->input->base 01108 && *(end-2)!='<' && *(end-1)!='/') end--; 01109 01110 update_position(This, end); 01111 01112 nsNr = namespacePop(This); 01113 01114 if(has_content_handler(This)) 01115 { 01116 NamespaceUri = bstr_from_xmlChar(URI); 01117 LocalName = bstr_from_xmlChar(localname); 01118 QName = QName_from_xmlChar(prefix, localname); 01119 01120 if(This->vbInterface) 01121 hr = IVBSAXContentHandler_endElement( 01122 This->saxreader->vbcontentHandler, 01123 &NamespaceUri, &LocalName, &QName); 01124 else 01125 hr = ISAXContentHandler_endElement( 01126 This->saxreader->contentHandler, 01127 NamespaceUri, SysStringLen(NamespaceUri), 01128 LocalName, SysStringLen(LocalName), 01129 QName, SysStringLen(QName)); 01130 01131 SysFreeString(NamespaceUri); 01132 SysFreeString(LocalName); 01133 SysFreeString(QName); 01134 01135 if(hr != S_OK) 01136 { 01137 format_error_message_from_id(This, hr); 01138 return; 01139 } 01140 01141 for(index=This->pParserCtxt->nsNr-2; 01142 index>=This->pParserCtxt->nsNr-nsNr*2; index-=2) 01143 { 01144 Prefix = bstr_from_xmlChar(This->pParserCtxt->nsTab[index]); 01145 01146 if(This->vbInterface) 01147 hr = IVBSAXContentHandler_endPrefixMapping( 01148 This->saxreader->vbcontentHandler, &Prefix); 01149 else 01150 hr = ISAXContentHandler_endPrefixMapping( 01151 This->saxreader->contentHandler, 01152 Prefix, SysStringLen(Prefix)); 01153 01154 SysFreeString(Prefix); 01155 01156 if(hr != S_OK) 01157 { 01158 format_error_message_from_id(This, hr); 01159 return; 01160 } 01161 01162 } 01163 } 01164 01165 update_position(This, NULL); 01166 } 01167 01168 static void libxmlCharacters( 01169 void *ctx, 01170 const xmlChar *ch, 01171 int len) 01172 { 01173 saxlocator *This = ctx; 01174 BSTR Chars; 01175 HRESULT hr; 01176 xmlChar *cur; 01177 xmlChar *end; 01178 BOOL lastEvent = FALSE; 01179 01180 if(!(has_content_handler(This))) return; 01181 01182 cur = (xmlChar*)ch; 01183 if(*(ch-1)=='\r') cur--; 01184 end = cur; 01185 01186 if(ch<This->pParserCtxt->input->base || ch>This->pParserCtxt->input->end) 01187 This->column++; 01188 01189 while(1) 01190 { 01191 while(end-ch<len && *end!='\r') end++; 01192 if(end-ch==len) 01193 { 01194 end--; 01195 lastEvent = TRUE; 01196 } 01197 01198 if(!lastEvent) *end = '\n'; 01199 01200 Chars = bstr_from_xmlCharN(cur, end-cur+1); 01201 if(This->vbInterface) 01202 hr = IVBSAXContentHandler_characters( 01203 This->saxreader->vbcontentHandler, &Chars); 01204 else 01205 hr = ISAXContentHandler_characters( 01206 This->saxreader->contentHandler, 01207 Chars, SysStringLen(Chars)); 01208 SysFreeString(Chars); 01209 01210 if(hr != S_OK) 01211 { 01212 format_error_message_from_id(This, hr); 01213 return; 01214 } 01215 01216 This->column += end-cur+1; 01217 01218 if(lastEvent) 01219 break; 01220 01221 *end = '\r'; 01222 end++; 01223 if(*end == '\n') 01224 { 01225 end++; 01226 This->column++; 01227 } 01228 cur = end; 01229 01230 if(end-ch == len) break; 01231 } 01232 01233 if(ch<This->pParserCtxt->input->base || ch>This->pParserCtxt->input->end) 01234 This->column = This->realColumn 01235 +This->pParserCtxt->input->cur-This->lastCur; 01236 } 01237 01238 static void libxmlSetDocumentLocator( 01239 void *ctx, 01240 xmlSAXLocatorPtr loc) 01241 { 01242 saxlocator *This = ctx; 01243 HRESULT hr; 01244 01245 if(This->vbInterface) 01246 hr = IVBSAXContentHandler_putref_documentLocator( 01247 This->saxreader->vbcontentHandler, 01248 (IVBSAXLocator*)&This->lpVBSAXLocatorVtbl); 01249 else 01250 hr = ISAXContentHandler_putDocumentLocator( 01251 This->saxreader->contentHandler, 01252 (ISAXLocator*)&This->lpSAXLocatorVtbl); 01253 01254 if(FAILED(hr)) 01255 format_error_message_from_id(This, hr); 01256 } 01257 01258 static void libxmlComment(void *ctx, const xmlChar *value) 01259 { 01260 saxlocator *This = ctx; 01261 BSTR bValue; 01262 HRESULT hr; 01263 xmlChar *beg = (xmlChar*)This->pParserCtxt->input->cur; 01264 01265 while(beg-4>=This->pParserCtxt->input->base 01266 && memcmp(beg-4, "<!--", sizeof(char[4]))) beg--; 01267 update_position(This, beg); 01268 01269 if(!This->vbInterface && !This->saxreader->lexicalHandler) return; 01270 if(This->vbInterface && !This->saxreader->vblexicalHandler) return; 01271 01272 bValue = bstr_from_xmlChar(value); 01273 01274 if(This->vbInterface) 01275 hr = IVBSAXLexicalHandler_comment( 01276 This->saxreader->vblexicalHandler, &bValue); 01277 else 01278 hr = ISAXLexicalHandler_comment( 01279 This->saxreader->lexicalHandler, 01280 bValue, SysStringLen(bValue)); 01281 01282 SysFreeString(bValue); 01283 01284 if(FAILED(hr)) 01285 format_error_message_from_id(This, hr); 01286 01287 update_position(This, NULL); 01288 } 01289 01290 static void libxmlFatalError(void *ctx, const char *msg, ...) 01291 { 01292 saxlocator *This = ctx; 01293 char message[1024]; 01294 WCHAR *wszError; 01295 DWORD len; 01296 va_list args; 01297 01298 if((This->vbInterface && !This->saxreader->vberrorHandler) 01299 || (!This->vbInterface && !This->saxreader->errorHandler)) 01300 { 01301 xmlStopParser(This->pParserCtxt); 01302 This->ret = E_FAIL; 01303 return; 01304 } 01305 01306 FIXME("Error handling is not compatible.\n"); 01307 01308 va_start(args, msg); 01309 vsprintf(message, msg, args); 01310 va_end(args); 01311 01312 len = MultiByteToWideChar(CP_UNIXCP, 0, message, -1, NULL, 0); 01313 wszError = heap_alloc(sizeof(WCHAR)*len); 01314 if(wszError) 01315 MultiByteToWideChar(CP_UNIXCP, 0, message, -1, wszError, len); 01316 01317 if(This->vbInterface) 01318 { 01319 BSTR bstrError = SysAllocString(wszError); 01320 IVBSAXErrorHandler_fatalError(This->saxreader->vberrorHandler, 01321 (IVBSAXLocator*)&This->lpVBSAXLocatorVtbl, &bstrError, E_FAIL); 01322 } 01323 else 01324 ISAXErrorHandler_fatalError(This->saxreader->errorHandler, 01325 (ISAXLocator*)&This->lpSAXLocatorVtbl, wszError, E_FAIL); 01326 01327 heap_free(wszError); 01328 01329 xmlStopParser(This->pParserCtxt); 01330 This->ret = E_FAIL; 01331 } 01332 01333 static void libxmlCDataBlock(void *ctx, const xmlChar *value, int len) 01334 { 01335 saxlocator *This = ctx; 01336 HRESULT hr = S_OK; 01337 xmlChar *beg = (xmlChar*)This->pParserCtxt->input->cur-len; 01338 xmlChar *cur, *end; 01339 int realLen; 01340 BSTR Chars; 01341 BOOL lastEvent = FALSE, change; 01342 01343 while(beg-9>=This->pParserCtxt->input->base 01344 && memcmp(beg-9, "<![CDATA[", sizeof(char[9]))) beg--; 01345 update_position(This, beg); 01346 01347 if(This->vbInterface && This->saxreader->vblexicalHandler) 01348 hr = IVBSAXLexicalHandler_startCDATA(This->saxreader->vblexicalHandler); 01349 if(!This->vbInterface && This->saxreader->lexicalHandler) 01350 hr = ISAXLexicalHandler_startCDATA(This->saxreader->lexicalHandler); 01351 01352 if(FAILED(hr)) 01353 { 01354 format_error_message_from_id(This, hr); 01355 return; 01356 } 01357 01358 realLen = This->pParserCtxt->input->cur-beg-3; 01359 cur = beg; 01360 end = beg; 01361 01362 while(1) 01363 { 01364 while(end-beg<realLen && *end!='\r') end++; 01365 if(end-beg==realLen) 01366 { 01367 end--; 01368 lastEvent = TRUE; 01369 } 01370 else if(end-beg==realLen-1 && *end=='\r' && *(end+1)=='\n') 01371 lastEvent = TRUE; 01372 01373 if(*end == '\r') change = TRUE; 01374 else change = FALSE; 01375 01376 if(change) *end = '\n'; 01377 01378 if(has_content_handler(This)) 01379 { 01380 Chars = bstr_from_xmlCharN(cur, end-cur+1); 01381 if(This->vbInterface) 01382 hr = IVBSAXContentHandler_characters( 01383 This->saxreader->vbcontentHandler, &Chars); 01384 else 01385 hr = ISAXContentHandler_characters( 01386 This->saxreader->contentHandler, 01387 Chars, SysStringLen(Chars)); 01388 SysFreeString(Chars); 01389 } 01390 01391 if(change) *end = '\r'; 01392 01393 if(lastEvent) 01394 break; 01395 01396 This->column += end-cur+2; 01397 end += 2; 01398 cur = end; 01399 } 01400 01401 if(This->vbInterface && This->saxreader->vblexicalHandler) 01402 hr = IVBSAXLexicalHandler_endCDATA(This->saxreader->vblexicalHandler); 01403 if(!This->vbInterface && This->saxreader->lexicalHandler) 01404 hr = ISAXLexicalHandler_endCDATA(This->saxreader->lexicalHandler); 01405 01406 if(FAILED(hr)) 01407 format_error_message_from_id(This, hr); 01408 01409 This->column += 4+end-cur; 01410 } 01411 01412 /*** IVBSAXLocator interface ***/ 01413 /*** IUnknown methods ***/ 01414 static HRESULT WINAPI ivbsaxlocator_QueryInterface(IVBSAXLocator* iface, REFIID riid, void **ppvObject) 01415 { 01416 saxlocator *This = impl_from_IVBSAXLocator( iface ); 01417 01418 TRACE("%p %s %p\n", This, debugstr_guid( riid ), ppvObject); 01419 01420 *ppvObject = NULL; 01421 01422 if ( IsEqualGUID( riid, &IID_IUnknown ) || 01423 IsEqualGUID( riid, &IID_IDispatch) || 01424 IsEqualGUID( riid, &IID_IVBSAXLocator )) 01425 { 01426 *ppvObject = iface; 01427 } 01428 else 01429 { 01430 FIXME("interface %s not implemented\n", debugstr_guid(riid)); 01431 return E_NOINTERFACE; 01432 } 01433 01434 IVBSAXLocator_AddRef( iface ); 01435 01436 return S_OK; 01437 } 01438 01439 static ULONG WINAPI ivbsaxlocator_AddRef(IVBSAXLocator* iface) 01440 { 01441 saxlocator *This = impl_from_IVBSAXLocator( iface ); 01442 TRACE("%p\n", This ); 01443 return InterlockedIncrement( &This->ref ); 01444 } 01445 01446 static ULONG WINAPI ivbsaxlocator_Release( 01447 IVBSAXLocator* iface) 01448 { 01449 saxlocator *This = impl_from_IVBSAXLocator( iface ); 01450 return ISAXLocator_Release((ISAXLocator*)&This->lpVBSAXLocatorVtbl); 01451 } 01452 01453 /*** IDispatch methods ***/ 01454 static HRESULT WINAPI ivbsaxlocator_GetTypeInfoCount( IVBSAXLocator *iface, UINT* pctinfo ) 01455 { 01456 saxlocator *This = impl_from_IVBSAXLocator( iface ); 01457 01458 TRACE("(%p)->(%p)\n", This, pctinfo); 01459 01460 *pctinfo = 1; 01461 01462 return S_OK; 01463 } 01464 01465 static HRESULT WINAPI ivbsaxlocator_GetTypeInfo( 01466 IVBSAXLocator *iface, 01467 UINT iTInfo, LCID lcid, ITypeInfo** ppTInfo ) 01468 { 01469 saxlocator *This = impl_from_IVBSAXLocator( iface ); 01470 HRESULT hr; 01471 01472 TRACE("(%p)->(%u %u %p)\n", This, iTInfo, lcid, ppTInfo); 01473 01474 hr = get_typeinfo(IVBSAXLocator_tid, ppTInfo); 01475 01476 return hr; 01477 } 01478 01479 static HRESULT WINAPI ivbsaxlocator_GetIDsOfNames( 01480 IVBSAXLocator *iface, 01481 REFIID riid, 01482 LPOLESTR* rgszNames, 01483 UINT cNames, 01484 LCID lcid, 01485 DISPID* rgDispId) 01486 { 01487 saxlocator *This = impl_from_IVBSAXLocator( iface ); 01488 ITypeInfo *typeinfo; 01489 HRESULT hr; 01490 01491 TRACE("(%p)->(%s %p %u %u %p)\n", This, debugstr_guid(riid), rgszNames, cNames, 01492 lcid, rgDispId); 01493 01494 if(!rgszNames || cNames == 0 || !rgDispId) 01495 return E_INVALIDARG; 01496 01497 hr = get_typeinfo(IVBSAXLocator_tid, &typeinfo); 01498 if(SUCCEEDED(hr)) 01499 { 01500 hr = ITypeInfo_GetIDsOfNames(typeinfo, rgszNames, cNames, rgDispId); 01501 ITypeInfo_Release(typeinfo); 01502 } 01503 01504 return hr; 01505 } 01506 01507 static HRESULT WINAPI ivbsaxlocator_Invoke( 01508 IVBSAXLocator *iface, 01509 DISPID dispIdMember, 01510 REFIID riid, 01511 LCID lcid, 01512 WORD wFlags, 01513 DISPPARAMS* pDispParams, 01514 VARIANT* pVarResult, 01515 EXCEPINFO* pExcepInfo, 01516 UINT* puArgErr) 01517 { 01518 saxlocator *This = impl_from_IVBSAXLocator( iface ); 01519 ITypeInfo *typeinfo; 01520 HRESULT hr; 01521 01522 TRACE("(%p)->(%d %s %d %d %p %p %p %p)\n", This, dispIdMember, debugstr_guid(riid), 01523 lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr); 01524 01525 hr = get_typeinfo(IVBSAXLocator_tid, &typeinfo); 01526 if(SUCCEEDED(hr)) 01527 { 01528 hr = ITypeInfo_Invoke(typeinfo, &(This->lpVBSAXLocatorVtbl), dispIdMember, wFlags, pDispParams, 01529 pVarResult, pExcepInfo, puArgErr); 01530 ITypeInfo_Release(typeinfo); 01531 } 01532 01533 return hr; 01534 } 01535 01536 /*** IVBSAXLocator methods ***/ 01537 static HRESULT WINAPI ivbsaxlocator_get_columnNumber( 01538 IVBSAXLocator* iface, 01539 int *pnColumn) 01540 { 01541 saxlocator *This = impl_from_IVBSAXLocator( iface ); 01542 return ISAXLocator_getColumnNumber( 01543 (ISAXLocator*)&This->lpVBSAXLocatorVtbl, 01544 pnColumn); 01545 } 01546 01547 static HRESULT WINAPI ivbsaxlocator_get_lineNumber( 01548 IVBSAXLocator* iface, 01549 int *pnLine) 01550 { 01551 saxlocator *This = impl_from_IVBSAXLocator( iface ); 01552 return ISAXLocator_getLineNumber( 01553 (ISAXLocator*)&This->lpVBSAXLocatorVtbl, 01554 pnLine); 01555 } 01556 01557 static HRESULT WINAPI ivbsaxlocator_get_publicId( 01558 IVBSAXLocator* iface, 01559 BSTR* publicId) 01560 { 01561 saxlocator *This = impl_from_IVBSAXLocator( iface ); 01562 return ISAXLocator_getPublicId( 01563 (ISAXLocator*)&This->lpVBSAXLocatorVtbl, 01564 (const WCHAR**)publicId); 01565 } 01566 01567 static HRESULT WINAPI ivbsaxlocator_get_systemId( 01568 IVBSAXLocator* iface, 01569 BSTR* systemId) 01570 { 01571 saxlocator *This = impl_from_IVBSAXLocator( iface ); 01572 return ISAXLocator_getSystemId( 01573 (ISAXLocator*)&This->lpVBSAXLocatorVtbl, 01574 (const WCHAR**)systemId); 01575 } 01576 01577 static const struct IVBSAXLocatorVtbl ivbsaxlocator_vtbl = 01578 { 01579 ivbsaxlocator_QueryInterface, 01580 ivbsaxlocator_AddRef, 01581 ivbsaxlocator_Release, 01582 ivbsaxlocator_GetTypeInfoCount, 01583 ivbsaxlocator_GetTypeInfo, 01584 ivbsaxlocator_GetIDsOfNames, 01585 ivbsaxlocator_Invoke, 01586 ivbsaxlocator_get_columnNumber, 01587 ivbsaxlocator_get_lineNumber, 01588 ivbsaxlocator_get_publicId, 01589 ivbsaxlocator_get_systemId 01590 }; 01591 01592 /*** ISAXLocator interface ***/ 01593 /*** IUnknown methods ***/ 01594 static HRESULT WINAPI isaxlocator_QueryInterface(ISAXLocator* iface, REFIID riid, void **ppvObject) 01595 { 01596 saxlocator *This = impl_from_ISAXLocator( iface ); 01597 01598 TRACE("%p %s %p\n", This, debugstr_guid( riid ), ppvObject ); 01599 01600 *ppvObject = NULL; 01601 01602 if ( IsEqualGUID( riid, &IID_IUnknown ) || 01603 IsEqualGUID( riid, &IID_ISAXLocator )) 01604 { 01605 *ppvObject = iface; 01606 } 01607 else 01608 { 01609 FIXME("interface %s not implemented\n", debugstr_guid(riid)); 01610 return E_NOINTERFACE; 01611 } 01612 01613 ISAXLocator_AddRef( iface ); 01614 01615 return S_OK; 01616 } 01617 01618 static ULONG WINAPI isaxlocator_AddRef(ISAXLocator* iface) 01619 { 01620 saxlocator *This = impl_from_ISAXLocator( iface ); 01621 TRACE("%p\n", This ); 01622 return InterlockedIncrement( &This->ref ); 01623 } 01624 01625 static ULONG WINAPI isaxlocator_Release( 01626 ISAXLocator* iface) 01627 { 01628 saxlocator *This = impl_from_ISAXLocator( iface ); 01629 LONG ref; 01630 01631 TRACE("%p\n", This ); 01632 01633 ref = InterlockedDecrement( &This->ref ); 01634 if ( ref == 0 ) 01635 { 01636 SysFreeString(This->publicId); 01637 SysFreeString(This->systemId); 01638 heap_free(This->nsStack); 01639 01640 ISAXXMLReader_Release((ISAXXMLReader*)&This->saxreader->lpSAXXMLReaderVtbl); 01641 heap_free( This ); 01642 } 01643 01644 return ref; 01645 } 01646 01647 /*** ISAXLocator methods ***/ 01648 static HRESULT WINAPI isaxlocator_getColumnNumber( 01649 ISAXLocator* iface, 01650 int *pnColumn) 01651 { 01652 saxlocator *This = impl_from_ISAXLocator( iface ); 01653 01654 *pnColumn = This->column; 01655 return S_OK; 01656 } 01657 01658 static HRESULT WINAPI isaxlocator_getLineNumber( 01659 ISAXLocator* iface, 01660 int *pnLine) 01661 { 01662 saxlocator *This = impl_from_ISAXLocator( iface ); 01663 01664 *pnLine = This->line; 01665 return S_OK; 01666 } 01667 01668 static HRESULT WINAPI isaxlocator_getPublicId( 01669 ISAXLocator* iface, 01670 const WCHAR ** ppwchPublicId) 01671 { 01672 BSTR publicId; 01673 saxlocator *This = impl_from_ISAXLocator( iface ); 01674 01675 SysFreeString(This->publicId); 01676 01677 publicId = bstr_from_xmlChar(xmlSAX2GetPublicId(This->pParserCtxt)); 01678 if(SysStringLen(publicId)) 01679 This->publicId = (WCHAR*)&publicId; 01680 else 01681 { 01682 SysFreeString(publicId); 01683 This->publicId = NULL; 01684 } 01685 01686 *ppwchPublicId = This->publicId; 01687 return S_OK; 01688 } 01689 01690 static HRESULT WINAPI isaxlocator_getSystemId( 01691 ISAXLocator* iface, 01692 const WCHAR ** ppwchSystemId) 01693 { 01694 BSTR systemId; 01695 saxlocator *This = impl_from_ISAXLocator( iface ); 01696 01697 SysFreeString(This->systemId); 01698 01699 systemId = bstr_from_xmlChar(xmlSAX2GetSystemId(This->pParserCtxt)); 01700 if(SysStringLen(systemId)) 01701 This->systemId = (WCHAR*)&systemId; 01702 else 01703 { 01704 SysFreeString(systemId); 01705 This->systemId = NULL; 01706 } 01707 01708 *ppwchSystemId = This->systemId; 01709 return S_OK; 01710 } 01711 01712 static const struct ISAXLocatorVtbl isaxlocator_vtbl = 01713 { 01714 isaxlocator_QueryInterface, 01715 isaxlocator_AddRef, 01716 isaxlocator_Release, 01717 isaxlocator_getColumnNumber, 01718 isaxlocator_getLineNumber, 01719 isaxlocator_getPublicId, 01720 isaxlocator_getSystemId 01721 }; 01722 01723 static HRESULT SAXLocator_create(saxreader *reader, saxlocator **ppsaxlocator, BOOL vbInterface) 01724 { 01725 saxlocator *locator; 01726 01727 locator = heap_alloc( sizeof (*locator) ); 01728 if( !locator ) 01729 return E_OUTOFMEMORY; 01730 01731 locator->lpVBSAXLocatorVtbl = &ivbsaxlocator_vtbl; 01732 locator->lpSAXLocatorVtbl = &isaxlocator_vtbl; 01733 locator->ref = 1; 01734 locator->vbInterface = vbInterface; 01735 01736 locator->saxreader = reader; 01737 ISAXXMLReader_AddRef((ISAXXMLReader*)&reader->lpSAXXMLReaderVtbl); 01738 01739 locator->pParserCtxt = NULL; 01740 locator->publicId = NULL; 01741 locator->systemId = NULL; 01742 locator->lastCur = NULL; 01743 locator->line = 0; 01744 locator->column = 0; 01745 locator->ret = S_OK; 01746 locator->nsStackSize = 8; 01747 locator->nsStackLast = 0; 01748 locator->nsStack = heap_alloc(sizeof(int)*locator->nsStackSize); 01749 if(!locator->nsStack) 01750 { 01751 ISAXXMLReader_Release((ISAXXMLReader*)&reader->lpSAXXMLReaderVtbl); 01752 heap_free(locator); 01753 return E_OUTOFMEMORY; 01754 } 01755 01756 *ppsaxlocator = locator; 01757 01758 TRACE("returning %p\n", *ppsaxlocator); 01759 01760 return S_OK; 01761 } 01762 01763 /*** SAXXMLReader internal functions ***/ 01764 static HRESULT internal_parseBuffer(saxreader *This, const char *buffer, int size, BOOL vbInterface) 01765 { 01766 saxlocator *locator; 01767 HRESULT hr; 01768 01769 hr = SAXLocator_create(This, &locator, vbInterface); 01770 if(FAILED(hr)) 01771 return hr; 01772 01773 locator->pParserCtxt = xmlCreateMemoryParserCtxt(buffer, size); 01774 if(!locator->pParserCtxt) 01775 { 01776 ISAXLocator_Release((ISAXLocator*)&locator->lpSAXLocatorVtbl); 01777 return E_FAIL; 01778 } 01779 01780 xmlFree(locator->pParserCtxt->sax); 01781 locator->pParserCtxt->sax = &locator->saxreader->sax; 01782 locator->pParserCtxt->userData = locator; 01783 01784 This->isParsing = TRUE; 01785 if(xmlParseDocument(locator->pParserCtxt)) hr = E_FAIL; 01786 else hr = locator->ret; 01787 This->isParsing = FALSE; 01788 01789 if(locator->pParserCtxt) 01790 { 01791 locator->pParserCtxt->sax = NULL; 01792 xmlFreeParserCtxt(locator->pParserCtxt); 01793 locator->pParserCtxt = NULL; 01794 } 01795 01796 ISAXLocator_Release((ISAXLocator*)&locator->lpSAXLocatorVtbl); 01797 return hr; 01798 } 01799 01800 static HRESULT internal_parseStream(saxreader *This, IStream *stream, BOOL vbInterface) 01801 { 01802 saxlocator *locator; 01803 HRESULT hr; 01804 ULONG dataRead; 01805 char data[1024]; 01806 01807 hr = IStream_Read(stream, data, sizeof(data), &dataRead); 01808 if(hr != S_OK) 01809 return hr; 01810 01811 hr = SAXLocator_create(This, &locator, vbInterface); 01812 if(FAILED(hr)) 01813 return hr; 01814 01815 locator->pParserCtxt = xmlCreatePushParserCtxt( 01816 &locator->saxreader->sax, locator, 01817 data, dataRead, NULL); 01818 if(!locator->pParserCtxt) 01819 { 01820 ISAXLocator_Release((ISAXLocator*)&locator->lpSAXLocatorVtbl); 01821 return E_FAIL; 01822 } 01823 01824 This->isParsing = TRUE; 01825 while(1) 01826 { 01827 hr = IStream_Read(stream, data, sizeof(data), &dataRead); 01828 if(hr != S_OK) 01829 break; 01830 01831 if(xmlParseChunk(locator->pParserCtxt, data, dataRead, 0)) hr = E_FAIL; 01832 else hr = locator->ret; 01833 01834 if(hr != S_OK) break; 01835 01836 if(dataRead != sizeof(data)) 01837 { 01838 if(xmlParseChunk(locator->pParserCtxt, data, 0, 1)) hr = E_FAIL; 01839 else hr = locator->ret; 01840 01841 break; 01842 } 01843 } 01844 This->isParsing = FALSE; 01845 01846 xmlFreeParserCtxt(locator->pParserCtxt); 01847 locator->pParserCtxt = NULL; 01848 ISAXLocator_Release((ISAXLocator*)&locator->lpSAXLocatorVtbl); 01849 return hr; 01850 } 01851 01852 static HRESULT internal_getEntityResolver( 01853 saxreader *This, 01854 void *pEntityResolver, 01855 BOOL vbInterface) 01856 { 01857 FIXME("(%p)->(%p) stub\n", This, pEntityResolver); 01858 return E_NOTIMPL; 01859 } 01860 01861 static HRESULT internal_putEntityResolver( 01862 saxreader *This, 01863 void *pEntityResolver, 01864 BOOL vbInterface) 01865 { 01866 FIXME("(%p)->(%p) stub\n", This, pEntityResolver); 01867 return E_NOTIMPL; 01868 } 01869 01870 static HRESULT internal_getContentHandler( 01871 saxreader* This, 01872 void *pContentHandler, 01873 BOOL vbInterface) 01874 { 01875 TRACE("(%p)->(%p)\n", This, pContentHandler); 01876 if(pContentHandler == NULL) 01877 return E_POINTER; 01878 if((vbInterface && This->vbcontentHandler) 01879 || (!vbInterface && This->contentHandler)) 01880 { 01881 if(vbInterface) 01882 IVBSAXContentHandler_AddRef(This->vbcontentHandler); 01883 else 01884 ISAXContentHandler_AddRef(This->contentHandler); 01885 } 01886 if(vbInterface) *(IVBSAXContentHandler**)pContentHandler = 01887 This->vbcontentHandler; 01888 else *(ISAXContentHandler**)pContentHandler = This->contentHandler; 01889 01890 return S_OK; 01891 } 01892 01893 static HRESULT internal_putContentHandler( 01894 saxreader* This, 01895 void *contentHandler, 01896 BOOL vbInterface) 01897 { 01898 TRACE("(%p)->(%p)\n", This, contentHandler); 01899 if(contentHandler) 01900 { 01901 if(vbInterface) 01902 IVBSAXContentHandler_AddRef((IVBSAXContentHandler*)contentHandler); 01903 else 01904 ISAXContentHandler_AddRef((ISAXContentHandler*)contentHandler); 01905 } 01906 if((vbInterface && This->vbcontentHandler) 01907 || (!vbInterface && This->contentHandler)) 01908 { 01909 if(vbInterface) 01910 IVBSAXContentHandler_Release(This->vbcontentHandler); 01911 else 01912 ISAXContentHandler_Release(This->contentHandler); 01913 } 01914 if(vbInterface) 01915 This->vbcontentHandler = contentHandler; 01916 else 01917 This->contentHandler = contentHandler; 01918 01919 return S_OK; 01920 } 01921 01922 static HRESULT internal_getDTDHandler( 01923 saxreader* This, 01924 void *pDTDHandler, 01925 BOOL vbInterface) 01926 { 01927 FIXME("(%p)->(%p) stub\n", This, pDTDHandler); 01928 return E_NOTIMPL; 01929 } 01930 01931 static HRESULT internal_putDTDHandler( 01932 saxreader* This, 01933 void *pDTDHandler, 01934 BOOL vbInterface) 01935 { 01936 FIXME("(%p)->(%p) stub\n", This, pDTDHandler); 01937 return E_NOTIMPL; 01938 } 01939 01940 static HRESULT internal_getErrorHandler( 01941 saxreader* This, 01942 void *pErrorHandler, 01943 BOOL vbInterface) 01944 { 01945 TRACE("(%p)->(%p)\n", This, pErrorHandler); 01946 if(pErrorHandler == NULL) 01947 return E_POINTER; 01948 01949 if(vbInterface && This->vberrorHandler) 01950 IVBSAXErrorHandler_AddRef(This->vberrorHandler); 01951 else if(!vbInterface && This->errorHandler) 01952 ISAXErrorHandler_AddRef(This->errorHandler); 01953 01954 if(vbInterface) 01955 *(IVBSAXErrorHandler**)pErrorHandler = This->vberrorHandler; 01956 else 01957 *(ISAXErrorHandler**)pErrorHandler = This->errorHandler; 01958 01959 return S_OK; 01960 01961 } 01962 01963 static HRESULT internal_putErrorHandler( 01964 saxreader* This, 01965 void *errorHandler, 01966 BOOL vbInterface) 01967 { 01968 TRACE("(%p)->(%p)\n", This, errorHandler); 01969 if(errorHandler) 01970 { 01971 if(vbInterface) 01972 IVBSAXErrorHandler_AddRef((IVBSAXErrorHandler*)errorHandler); 01973 else 01974 ISAXErrorHandler_AddRef((ISAXErrorHandler*)errorHandler); 01975 } 01976 01977 if(vbInterface && This->vberrorHandler) 01978 IVBSAXErrorHandler_Release(This->vberrorHandler); 01979 else if(!vbInterface && This->errorHandler) 01980 ISAXErrorHandler_Release(This->errorHandler); 01981 01982 if(vbInterface) 01983 This->vberrorHandler = errorHandler; 01984 else 01985 This->errorHandler = errorHandler; 01986 01987 return S_OK; 01988 01989 } 01990 01991 static HRESULT internal_parse( 01992 saxreader* This, 01993 VARIANT varInput, 01994 BOOL vbInterface) 01995 { 01996 HRESULT hr; 01997 01998 TRACE("(%p)\n", This); 01999 02000 hr = S_OK; 02001 switch(V_VT(&varInput)) 02002 { 02003 case VT_BSTR: 02004 hr = internal_parseBuffer(This, (const char*)V_BSTR(&varInput), 02005 SysStringByteLen(V_BSTR(&varInput)), vbInterface); 02006 break; 02007 case VT_ARRAY|VT_UI1: { 02008 void *pSAData; 02009 LONG lBound, uBound; 02010 ULONG dataRead; 02011 02012 hr = SafeArrayGetLBound(V_ARRAY(&varInput), 1, &lBound); 02013 if(hr != S_OK) break; 02014 hr = SafeArrayGetUBound(V_ARRAY(&varInput), 1, &uBound); 02015 if(hr != S_OK) break; 02016 dataRead = (uBound-lBound)*SafeArrayGetElemsize(V_ARRAY(&varInput)); 02017 hr = SafeArrayAccessData(V_ARRAY(&varInput), &pSAData); 02018 if(hr != S_OK) break; 02019 hr = internal_parseBuffer(This, pSAData, dataRead, vbInterface); 02020 SafeArrayUnaccessData(V_ARRAY(&varInput)); 02021 break; 02022 } 02023 case VT_UNKNOWN: 02024 case VT_DISPATCH: { 02025 IPersistStream *persistStream; 02026 IStream *stream = NULL; 02027 IXMLDOMDocument *xmlDoc; 02028 02029 if(IUnknown_QueryInterface(V_UNKNOWN(&varInput), 02030 &IID_IXMLDOMDocument, (void**)&xmlDoc) == S_OK) 02031 { 02032 BSTR bstrData; 02033 02034 IXMLDOMDocument_get_xml(xmlDoc, &bstrData); 02035 hr = internal_parseBuffer(This, (const char*)bstrData, 02036 SysStringByteLen(bstrData), vbInterface); 02037 IXMLDOMDocument_Release(xmlDoc); 02038 SysFreeString(bstrData); 02039 break; 02040 } 02041 if(IUnknown_QueryInterface(V_UNKNOWN(&varInput), 02042 &IID_IPersistStream, (void**)&persistStream) == S_OK) 02043 { 02044 hr = IPersistStream_Save(persistStream, stream, TRUE); 02045 IPersistStream_Release(persistStream); 02046 if(hr != S_OK) break; 02047 } 02048 if(stream || IUnknown_QueryInterface(V_UNKNOWN(&varInput), 02049 &IID_IStream, (void**)&stream) == S_OK) 02050 { 02051 hr = internal_parseStream(This, stream, vbInterface); 02052 IStream_Release(stream); 02053 break; 02054 } 02055 } 02056 default: 02057 WARN("vt %d not implemented\n", V_VT(&varInput)); 02058 hr = E_INVALIDARG; 02059 } 02060 02061 return hr; 02062 } 02063 02064 static HRESULT internal_vbonDataAvailable(void *obj, char *ptr, DWORD len) 02065 { 02066 saxreader *This = obj; 02067 02068 return internal_parseBuffer(This, ptr, len, TRUE); 02069 } 02070 02071 static HRESULT internal_onDataAvailable(void *obj, char *ptr, DWORD len) 02072 { 02073 saxreader *This = obj; 02074 02075 return internal_parseBuffer(This, ptr, len, FALSE); 02076 } 02077 02078 static HRESULT internal_parseURL( 02079 saxreader* This, 02080 const WCHAR *url, 02081 BOOL vbInterface) 02082 { 02083 bsc_t *bsc; 02084 HRESULT hr; 02085 02086 TRACE("(%p)->(%s)\n", This, debugstr_w(url)); 02087 02088 if(vbInterface) hr = bind_url(url, internal_vbonDataAvailable, This, &bsc); 02089 else hr = bind_url(url, internal_onDataAvailable, This, &bsc); 02090 02091 if(FAILED(hr)) 02092 return hr; 02093 02094 detach_bsc(bsc); 02095 02096 return S_OK; 02097 } 02098 02099 static HRESULT internal_putProperty( 02100 saxreader* This, 02101 const WCHAR *pProp, 02102 VARIANT value, 02103 BOOL vbInterface) 02104 { 02105 static const WCHAR wszCharset[] = { 02106 'c','h','a','r','s','e','t',0 02107 }; 02108 static const WCHAR wszDeclarationHandler[] = { 02109 'h','t','t','p',':','/','/','x','m','l','.','o','r','g','/', 02110 's','a','x','/','p','r','o','p','e','r','t','i','e','s','/', 02111 'd','e','c','l','a','r','a','t','i','o','n', 02112 '-','h','a','n','d','l','e','r',0 02113 }; 02114 static const WCHAR wszDomNode[] = { 02115 'h','t','t','p',':','/','/','x','m','l','.','o','r','g','/', 02116 's','a','x','/','p','r','o','p','e','r','t','i','e','s','/', 02117 'd','o','m','-','n','o','d','e',0 02118 }; 02119 static const WCHAR wszInputSource[] = { 02120 'i','n','p','u','t','-','s','o','u','r','c','e',0 02121 }; 02122 static const WCHAR wszLexicalHandler[] = { 02123 'h','t','t','p',':','/','/','x','m','l','.','o','r','g','/', 02124 's','a','x','/','p','r','o','p','e','r','t','i','e','s','/', 02125 'l','e','x','i','c','a','l','-','h','a','n','d','l','e','r',0 02126 }; 02127 static const WCHAR wszMaxElementDepth[] = { 02128 'm','a','x','-','e','l','e','m','e','n','t','-','d','e','p','t','h',0 02129 }; 02130 static const WCHAR wszMaxXMLSize[] = { 02131 'm','a','x','-','x','m','l','-','s','i','z','e',0 02132 }; 02133 static const WCHAR wszSchemaDeclarationHandler[] = { 02134 's','c','h','e','m','a','-', 02135 'd','e','c','l','a','r','a','t','i','o','n','-', 02136 'h','a','n','d','l','e','r',0 02137 }; 02138 static const WCHAR wszXMLDeclEncoding[] = { 02139 'x','m','l','d','e','c','l','-','e','n','c','o','d','i','n','g',0 02140 }; 02141 static const WCHAR wszXMLDeclStandalone[] = { 02142 'x','m','l','d','e','c','l', 02143 '-','s','t','a','n','d','a','l','o','n','e',0 02144 }; 02145 static const WCHAR wszXMLDeclVersion[] = { 02146 'x','m','l','d','e','c','l','-','v','e','r','s','i','o','n',0 02147 }; 02148 02149 FIXME("(%p)->(%s): semi-stub\n", This, debugstr_w(pProp)); 02150 02151 if(!memcmp(pProp, wszCharset, sizeof(wszCharset))) 02152 return E_NOTIMPL; 02153 02154 if(!memcmp(pProp, wszDeclarationHandler, sizeof(wszDeclarationHandler))) 02155 { 02156 if(This->isParsing) return E_FAIL; 02157 02158 if(V_UNKNOWN(&value)) 02159 { 02160 if(vbInterface) 02161 IVBSAXDeclHandler_AddRef((IVBSAXDeclHandler*)V_UNKNOWN(&value)); 02162 else 02163 ISAXDeclHandler_AddRef((ISAXDeclHandler*)V_UNKNOWN(&value)); 02164 } 02165 if((vbInterface && This->vbdeclHandler) 02166 || (!vbInterface && This->declHandler)) 02167 { 02168 if(vbInterface) 02169 IVBSAXDeclHandler_Release(This->vbdeclHandler); 02170 else 02171 ISAXDeclHandler_Release(This->declHandler); 02172 } 02173 if(vbInterface) 02174 This->vbdeclHandler = (IVBSAXDeclHandler*)V_UNKNOWN(&value); 02175 else 02176 This->declHandler = (ISAXDeclHandler*)V_UNKNOWN(&value); 02177 return S_OK; 02178 } 02179 02180 if(!memcmp(pProp, wszDomNode, sizeof(wszDomNode))) 02181 return E_FAIL; 02182 02183 if(!memcmp(pProp, wszInputSource, sizeof(wszInputSource))) 02184 return E_NOTIMPL; 02185 02186 if(!memcmp(pProp, wszLexicalHandler, sizeof(wszLexicalHandler))) 02187 { 02188 if(This->isParsing) return E_FAIL; 02189 02190 if(V_UNKNOWN(&value)) 02191 { 02192 if(vbInterface) 02193 IVBSAXLexicalHandler_AddRef( 02194 (IVBSAXLexicalHandler*)V_UNKNOWN(&value)); 02195 else 02196 ISAXLexicalHandler_AddRef( 02197 (ISAXLexicalHandler*)V_UNKNOWN(&value)); 02198 } 02199 if((vbInterface && This->vblexicalHandler) 02200 || (!vbInterface && This->lexicalHandler)) 02201 { 02202 if(vbInterface) 02203 IVBSAXLexicalHandler_Release(This->vblexicalHandler); 02204 else 02205 ISAXLexicalHandler_Release(This->lexicalHandler); 02206 } 02207 if(vbInterface) 02208 This->vblexicalHandler = (IVBSAXLexicalHandler*)V_UNKNOWN(&value); 02209 else 02210 This->lexicalHandler = (ISAXLexicalHandler*)V_UNKNOWN(&value); 02211 return S_OK; 02212 } 02213 02214 if(!memcmp(pProp, wszMaxElementDepth, sizeof(wszMaxElementDepth))) 02215 return E_NOTIMPL; 02216 02217 if(!memcmp(pProp, wszMaxXMLSize, sizeof(wszMaxXMLSize))) 02218 return E_NOTIMPL; 02219 02220 if(!memcmp(pProp, wszSchemaDeclarationHandler, 02221 sizeof(wszSchemaDeclarationHandler))) 02222 return E_NOTIMPL; 02223 02224 if(!memcmp(pProp, wszXMLDeclEncoding, sizeof(wszXMLDeclEncoding))) 02225 return E_FAIL; 02226 02227 if(!memcmp(pProp, wszXMLDeclStandalone, sizeof(wszXMLDeclStandalone))) 02228 return E_FAIL; 02229 02230 if(!memcmp(pProp, wszXMLDeclVersion, sizeof(wszXMLDeclVersion))) 02231 return E_FAIL; 02232 02233 return E_INVALIDARG; 02234 } 02235 02236 /*** IVBSAXXMLReader interface ***/ 02237 /*** IUnknown methods ***/ 02238 static HRESULT WINAPI saxxmlreader_QueryInterface(IVBSAXXMLReader* iface, REFIID riid, void **ppvObject) 02239 { 02240 saxreader *This = impl_from_IVBSAXXMLReader( iface ); 02241 02242 TRACE("%p %s %p\n", This, debugstr_guid( riid ), ppvObject ); 02243 02244 *ppvObject = NULL; 02245 02246 if ( IsEqualGUID( riid, &IID_IUnknown ) || 02247 IsEqualGUID( riid, &IID_IDispatch ) || 02248 IsEqualGUID( riid, &IID_IVBSAXXMLReader )) 02249 { 02250 *ppvObject = iface; 02251 } 02252 else if( IsEqualGUID( riid, &IID_ISAXXMLReader )) 02253 { 02254 *ppvObject = &This->lpSAXXMLReaderVtbl; 02255 } 02256 else 02257 { 02258 FIXME("interface %s not implemented\n", debugstr_guid(riid)); 02259 return E_NOINTERFACE; 02260 } 02261 02262 IVBSAXXMLReader_AddRef( iface ); 02263 02264 return S_OK; 02265 } 02266 02267 static ULONG WINAPI saxxmlreader_AddRef(IVBSAXXMLReader* iface) 02268 { 02269 saxreader *This = impl_from_IVBSAXXMLReader( iface ); 02270 TRACE("%p\n", This ); 02271 return InterlockedIncrement( &This->ref ); 02272 } 02273 02274 static ULONG WINAPI saxxmlreader_Release( 02275 IVBSAXXMLReader* iface) 02276 { 02277 saxreader *This = impl_from_IVBSAXXMLReader( iface ); 02278 LONG ref; 02279 02280 TRACE("%p\n", This ); 02281 02282 ref = InterlockedDecrement( &This->ref ); 02283 if ( ref == 0 ) 02284 { 02285 if(This->contentHandler) 02286 ISAXContentHandler_Release(This->contentHandler); 02287 02288 if(This->vbcontentHandler) 02289 IVBSAXContentHandler_Release(This->vbcontentHandler); 02290 02291 if(This->errorHandler) 02292 ISAXErrorHandler_Release(This->errorHandler); 02293 02294 if(This->vberrorHandler) 02295 IVBSAXErrorHandler_Release(This->vberrorHandler); 02296 02297 if(This->lexicalHandler) 02298 ISAXLexicalHandler_Release(This->lexicalHandler); 02299 02300 if(This->vblexicalHandler) 02301 IVBSAXLexicalHandler_Release(This->vblexicalHandler); 02302 02303 if(This->declHandler) 02304 ISAXDeclHandler_Release(This->declHandler); 02305 02306 if(This->vbdeclHandler) 02307 IVBSAXDeclHandler_Release(This->vbdeclHandler); 02308 02309 heap_free( This ); 02310 } 02311 02312 return ref; 02313 } 02314 /*** IDispatch ***/ 02315 static HRESULT WINAPI saxxmlreader_GetTypeInfoCount( IVBSAXXMLReader *iface, UINT* pctinfo ) 02316 { 02317 saxreader *This = impl_from_IVBSAXXMLReader( iface ); 02318 02319 TRACE("(%p)->(%p)\n", This, pctinfo); 02320 02321 *pctinfo = 1; 02322 02323 return S_OK; 02324 } 02325 02326 static HRESULT WINAPI saxxmlreader_GetTypeInfo( 02327 IVBSAXXMLReader *iface, 02328 UINT iTInfo, LCID lcid, ITypeInfo** ppTInfo ) 02329 { 02330 saxreader *This = impl_from_IVBSAXXMLReader( iface ); 02331 HRESULT hr; 02332 02333 TRACE("(%p)->(%u %u %p)\n", This, iTInfo, lcid, ppTInfo); 02334 02335 hr = get_typeinfo(IVBSAXXMLReader_tid, ppTInfo); 02336 02337 return hr; 02338 } 02339 02340 static HRESULT WINAPI saxxmlreader_GetIDsOfNames( 02341 IVBSAXXMLReader *iface, 02342 REFIID riid, 02343 LPOLESTR* rgszNames, 02344 UINT cNames, 02345 LCID lcid, 02346 DISPID* rgDispId) 02347 { 02348 saxreader *This = impl_from_IVBSAXXMLReader( iface ); 02349 ITypeInfo *typeinfo; 02350 HRESULT hr; 02351 02352 TRACE("(%p)->(%s %p %u %u %p)\n", This, debugstr_guid(riid), rgszNames, cNames, 02353 lcid, rgDispId); 02354 02355 if(!rgszNames || cNames == 0 || !rgDispId) 02356 return E_INVALIDARG; 02357 02358 hr = get_typeinfo(IVBSAXXMLReader_tid, &typeinfo); 02359 if(SUCCEEDED(hr)) 02360 { 02361 hr = ITypeInfo_GetIDsOfNames(typeinfo, rgszNames, cNames, rgDispId); 02362 ITypeInfo_Release(typeinfo); 02363 } 02364 02365 return hr; 02366 } 02367 02368 static HRESULT WINAPI saxxmlreader_Invoke( 02369 IVBSAXXMLReader *iface, 02370 DISPID dispIdMember, 02371 REFIID riid, 02372 LCID lcid, 02373 WORD wFlags, 02374 DISPPARAMS* pDispParams, 02375 VARIANT* pVarResult, 02376 EXCEPINFO* pExcepInfo, 02377 UINT* puArgErr) 02378 { 02379 saxreader *This = impl_from_IVBSAXXMLReader( iface ); 02380 ITypeInfo *typeinfo; 02381 HRESULT hr; 02382 02383 TRACE("(%p)->(%d %s %d %d %p %p %p %p)\n", This, dispIdMember, debugstr_guid(riid), 02384 lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr); 02385 02386 hr = get_typeinfo(IVBSAXXMLReader_tid, &typeinfo); 02387 if(SUCCEEDED(hr)) 02388 { 02389 hr = ITypeInfo_Invoke(typeinfo, &(This->lpVBSAXXMLReaderVtbl), dispIdMember, wFlags, pDispParams, 02390 pVarResult, pExcepInfo, puArgErr); 02391 ITypeInfo_Release(typeinfo); 02392 } 02393 02394 return hr; 02395 } 02396 02397 /*** IVBSAXXMLReader methods ***/ 02398 static HRESULT WINAPI saxxmlreader_getFeature( 02399 IVBSAXXMLReader* iface, 02400 const WCHAR *pFeature, 02401 VARIANT_BOOL *pValue) 02402 { 02403 saxreader *This = impl_from_IVBSAXXMLReader( iface ); 02404 02405 FIXME("(%p)->(%s %p) stub\n", This, debugstr_w(pFeature), pValue); 02406 return E_NOTIMPL; 02407 } 02408 02409 static HRESULT WINAPI saxxmlreader_putFeature( 02410 IVBSAXXMLReader* iface, 02411 const WCHAR *pFeature, 02412 VARIANT_BOOL vfValue) 02413 { 02414 saxreader *This = impl_from_IVBSAXXMLReader( iface ); 02415 02416 FIXME("(%p)->(%s %x) stub\n", This, debugstr_w(pFeature), vfValue); 02417 return E_NOTIMPL; 02418 } 02419 02420 static HRESULT WINAPI saxxmlreader_getProperty( 02421 IVBSAXXMLReader* iface, 02422 const WCHAR *pProp, 02423 VARIANT *pValue) 02424 { 02425 saxreader *This = impl_from_IVBSAXXMLReader( iface ); 02426 02427 FIXME("(%p)->(%s %p) stub\n", This, debugstr_w(pProp), pValue); 02428 return E_NOTIMPL; 02429 } 02430 02431 static HRESULT WINAPI saxxmlreader_putProperty( 02432 IVBSAXXMLReader* iface, 02433 const WCHAR *pProp, 02434 VARIANT value) 02435 { 02436 saxreader *This = impl_from_IVBSAXXMLReader( iface ); 02437 return internal_putProperty(This, pProp, value, TRUE); 02438 } 02439 02440 static HRESULT WINAPI saxxmlreader_get_entityResolver( 02441 IVBSAXXMLReader* iface, 02442 IVBSAXEntityResolver **pEntityResolver) 02443 { 02444 saxreader *This = impl_from_IVBSAXXMLReader( iface ); 02445 return internal_getEntityResolver(This, pEntityResolver, TRUE); 02446 } 02447 02448 static HRESULT WINAPI saxxmlreader_put_entityResolver( 02449 IVBSAXXMLReader* iface, 02450 IVBSAXEntityResolver *pEntityResolver) 02451 { 02452 saxreader *This = impl_from_IVBSAXXMLReader( iface ); 02453 return internal_putEntityResolver(This, pEntityResolver, TRUE); 02454 } 02455 02456 static HRESULT WINAPI saxxmlreader_get_contentHandler( 02457 IVBSAXXMLReader* iface, 02458 IVBSAXContentHandler **ppContentHandler) 02459 { 02460 saxreader *This = impl_from_IVBSAXXMLReader( iface ); 02461 return internal_getContentHandler(This, ppContentHandler, TRUE); 02462 } 02463 02464 static HRESULT WINAPI saxxmlreader_put_contentHandler( 02465 IVBSAXXMLReader* iface, 02466 IVBSAXContentHandler *contentHandler) 02467 { 02468 saxreader *This = impl_from_IVBSAXXMLReader( iface ); 02469 return internal_putContentHandler(This, contentHandler, TRUE); 02470 } 02471 02472 static HRESULT WINAPI saxxmlreader_get_dtdHandler( 02473 IVBSAXXMLReader* iface, 02474 IVBSAXDTDHandler **pDTDHandler) 02475 { 02476 saxreader *This = impl_from_IVBSAXXMLReader( iface ); 02477 return internal_getDTDHandler(This, pDTDHandler, TRUE); 02478 } 02479 02480 static HRESULT WINAPI saxxmlreader_put_dtdHandler( 02481 IVBSAXXMLReader* iface, 02482 IVBSAXDTDHandler *pDTDHandler) 02483 { 02484 saxreader *This = impl_from_IVBSAXXMLReader( iface ); 02485 return internal_putDTDHandler(This, pDTDHandler, TRUE); 02486 } 02487 02488 static HRESULT WINAPI saxxmlreader_get_errorHandler( 02489 IVBSAXXMLReader* iface, 02490 IVBSAXErrorHandler **pErrorHandler) 02491 { 02492 saxreader *This = impl_from_IVBSAXXMLReader( iface ); 02493 return internal_getErrorHandler(This, pErrorHandler, TRUE); 02494 } 02495 02496 static HRESULT WINAPI saxxmlreader_put_errorHandler( 02497 IVBSAXXMLReader* iface, 02498 IVBSAXErrorHandler *errorHandler) 02499 { 02500 saxreader *This = impl_from_IVBSAXXMLReader( iface ); 02501 return internal_putErrorHandler(This, errorHandler, TRUE); 02502 } 02503 02504 static HRESULT WINAPI saxxmlreader_get_baseURL( 02505 IVBSAXXMLReader* iface, 02506 const WCHAR **pBaseUrl) 02507 { 02508 saxreader *This = impl_from_IVBSAXXMLReader( iface ); 02509 02510 FIXME("(%p)->(%p) stub\n", This, pBaseUrl); 02511 return E_NOTIMPL; 02512 } 02513 02514 static HRESULT WINAPI saxxmlreader_put_baseURL( 02515 IVBSAXXMLReader* iface, 02516 const WCHAR *pBaseUrl) 02517 { 02518 saxreader *This = impl_from_IVBSAXXMLReader( iface ); 02519 02520 FIXME("(%p)->(%s) stub\n", This, debugstr_w(pBaseUrl)); 02521 return E_NOTIMPL; 02522 } 02523 02524 static HRESULT WINAPI saxxmlreader_get_secureBaseURL( 02525 IVBSAXXMLReader* iface, 02526 const WCHAR **pSecureBaseUrl) 02527 { 02528 saxreader *This = impl_from_IVBSAXXMLReader( iface ); 02529 02530 FIXME("(%p)->(%p) stub\n", This, pSecureBaseUrl); 02531 return E_NOTIMPL; 02532 } 02533 02534 02535 static HRESULT WINAPI saxxmlreader_put_secureBaseURL( 02536 IVBSAXXMLReader* iface, 02537 const WCHAR *secureBaseUrl) 02538 { 02539 saxreader *This = impl_from_IVBSAXXMLReader( iface ); 02540 02541 FIXME("(%p)->(%s) stub\n", This, debugstr_w(secureBaseUrl)); 02542 return E_NOTIMPL; 02543 } 02544 02545 static HRESULT WINAPI saxxmlreader_parse( 02546 IVBSAXXMLReader* iface, 02547 VARIANT varInput) 02548 { 02549 saxreader *This = impl_from_IVBSAXXMLReader( iface ); 02550 return internal_parse(This, varInput, TRUE); 02551 } 02552 02553 static HRESULT WINAPI saxxmlreader_parseURL( 02554 IVBSAXXMLReader* iface, 02555 const WCHAR *url) 02556 { 02557 saxreader *This = impl_from_IVBSAXXMLReader( iface ); 02558 return internal_parseURL(This, url, TRUE); 02559 } 02560 02561 static const struct IVBSAXXMLReaderVtbl saxreader_vtbl = 02562 { 02563 saxxmlreader_QueryInterface, 02564 saxxmlreader_AddRef, 02565 saxxmlreader_Release, 02566 saxxmlreader_GetTypeInfoCount, 02567 saxxmlreader_GetTypeInfo, 02568 saxxmlreader_GetIDsOfNames, 02569 saxxmlreader_Invoke, 02570 saxxmlreader_getFeature, 02571 saxxmlreader_putFeature, 02572 saxxmlreader_getProperty, 02573 saxxmlreader_putProperty, 02574 saxxmlreader_get_entityResolver, 02575 saxxmlreader_put_entityResolver, 02576 saxxmlreader_get_contentHandler, 02577 saxxmlreader_put_contentHandler, 02578 saxxmlreader_get_dtdHandler, 02579 saxxmlreader_put_dtdHandler, 02580 saxxmlreader_get_errorHandler, 02581 saxxmlreader_put_errorHandler, 02582 saxxmlreader_get_baseURL, 02583 saxxmlreader_put_baseURL, 02584 saxxmlreader_get_secureBaseURL, 02585 saxxmlreader_put_secureBaseURL, 02586 saxxmlreader_parse, 02587 saxxmlreader_parseURL 02588 }; 02589 02590 /*** ISAXXMLReader interface ***/ 02591 /*** IUnknown methods ***/ 02592 static HRESULT WINAPI isaxxmlreader_QueryInterface(ISAXXMLReader* iface, REFIID riid, void **ppvObject) 02593 { 02594 saxreader *This = impl_from_ISAXXMLReader( iface ); 02595 return saxxmlreader_QueryInterface((IVBSAXXMLReader*)&This->lpVBSAXXMLReaderVtbl, riid, ppvObject); 02596 } 02597 02598 static ULONG WINAPI isaxxmlreader_AddRef(ISAXXMLReader* iface) 02599 { 02600 saxreader *This = impl_from_ISAXXMLReader( iface ); 02601 return saxxmlreader_AddRef((IVBSAXXMLReader*)&This->lpVBSAXXMLReaderVtbl); 02602 } 02603 02604 static ULONG WINAPI isaxxmlreader_Release(ISAXXMLReader* iface) 02605 { 02606 saxreader *This = impl_from_ISAXXMLReader( iface ); 02607 return saxxmlreader_Release((IVBSAXXMLReader*)&This->lpVBSAXXMLReaderVtbl); 02608 } 02609 02610 /*** ISAXXMLReader methods ***/ 02611 static HRESULT WINAPI isaxxmlreader_getFeature( 02612 ISAXXMLReader* iface, 02613 const WCHAR *pFeature, 02614 VARIANT_BOOL *pValue) 02615 { 02616 saxreader *This = impl_from_ISAXXMLReader( iface ); 02617 return IVBSAXXMLReader_getFeature( 02618 (IVBSAXXMLReader*)&This->lpVBSAXXMLReaderVtbl, 02619 pFeature, pValue); 02620 } 02621 02622 static HRESULT WINAPI isaxxmlreader_putFeature( 02623 ISAXXMLReader* iface, 02624 const WCHAR *pFeature, 02625 VARIANT_BOOL vfValue) 02626 { 02627 saxreader *This = impl_from_ISAXXMLReader( iface ); 02628 return IVBSAXXMLReader_putFeature( 02629 (IVBSAXXMLReader*)&This->lpVBSAXXMLReaderVtbl, 02630 pFeature, vfValue); 02631 } 02632 02633 static HRESULT WINAPI isaxxmlreader_getProperty( 02634 ISAXXMLReader* iface, 02635 const WCHAR *pProp, 02636 VARIANT *pValue) 02637 { 02638 saxreader *This = impl_from_ISAXXMLReader( iface ); 02639 return IVBSAXXMLReader_getProperty( 02640 (IVBSAXXMLReader*)&This->lpVBSAXXMLReaderVtbl, 02641 pProp, pValue); 02642 } 02643 02644 static HRESULT WINAPI isaxxmlreader_putProperty( 02645 ISAXXMLReader* iface, 02646 const WCHAR *pProp, 02647 VARIANT value) 02648 { 02649 saxreader *This = impl_from_ISAXXMLReader( iface ); 02650 return internal_putProperty(This, pProp, value, FALSE); 02651 } 02652 02653 static HRESULT WINAPI isaxxmlreader_getEntityResolver( 02654 ISAXXMLReader* iface, 02655 ISAXEntityResolver **ppEntityResolver) 02656 { 02657 saxreader *This = impl_from_ISAXXMLReader( iface ); 02658 return internal_getEntityResolver(This, ppEntityResolver, FALSE); 02659 } 02660 02661 static HRESULT WINAPI isaxxmlreader_putEntityResolver( 02662 ISAXXMLReader* iface, 02663 ISAXEntityResolver *pEntityResolver) 02664 { 02665 saxreader *This = impl_from_ISAXXMLReader( iface ); 02666 return internal_putEntityResolver(This, pEntityResolver, FALSE); 02667 } 02668 02669 static HRESULT WINAPI isaxxmlreader_getContentHandler( 02670 ISAXXMLReader* iface, 02671 ISAXContentHandler **pContentHandler) 02672 { 02673 saxreader *This = impl_from_ISAXXMLReader( iface ); 02674 return internal_getContentHandler(This, pContentHandler, FALSE); 02675 } 02676 02677 static HRESULT WINAPI isaxxmlreader_putContentHandler( 02678 ISAXXMLReader* iface, 02679 ISAXContentHandler *contentHandler) 02680 { 02681 saxreader *This = impl_from_ISAXXMLReader( iface ); 02682 return internal_putContentHandler(This, contentHandler, FALSE); 02683 } 02684 02685 static HRESULT WINAPI isaxxmlreader_getDTDHandler( 02686 ISAXXMLReader* iface, 02687 ISAXDTDHandler **pDTDHandler) 02688 { 02689 saxreader *This = impl_from_ISAXXMLReader( iface ); 02690 return internal_getDTDHandler(This, pDTDHandler, FALSE); 02691 } 02692 02693 static HRESULT WINAPI isaxxmlreader_putDTDHandler( 02694 ISAXXMLReader* iface, 02695 ISAXDTDHandler *pDTDHandler) 02696 { 02697 saxreader *This = impl_from_ISAXXMLReader( iface ); 02698 return internal_putDTDHandler(This, pDTDHandler, FALSE); 02699 } 02700 02701 static HRESULT WINAPI isaxxmlreader_getErrorHandler( 02702 ISAXXMLReader* iface, 02703 ISAXErrorHandler **pErrorHandler) 02704 { 02705 saxreader *This = impl_from_ISAXXMLReader( iface ); 02706 return internal_getErrorHandler(This, pErrorHandler, FALSE); 02707 } 02708 02709 static HRESULT WINAPI isaxxmlreader_putErrorHandler( 02710 ISAXXMLReader* iface, 02711 ISAXErrorHandler *errorHandler) 02712 { 02713 saxreader *This = impl_from_ISAXXMLReader( iface ); 02714 return internal_putErrorHandler(This, errorHandler, FALSE); 02715 } 02716 02717 static HRESULT WINAPI isaxxmlreader_getBaseURL( 02718 ISAXXMLReader* iface, 02719 const WCHAR **pBaseUrl) 02720 { 02721 saxreader *This = impl_from_ISAXXMLReader( iface ); 02722 return IVBSAXXMLReader_get_baseURL( 02723 (IVBSAXXMLReader*)&This->lpVBSAXXMLReaderVtbl, 02724 pBaseUrl); 02725 } 02726 02727 static HRESULT WINAPI isaxxmlreader_putBaseURL( 02728 ISAXXMLReader* iface, 02729 const WCHAR *pBaseUrl) 02730 { 02731 saxreader *This = impl_from_ISAXXMLReader( iface ); 02732 return IVBSAXXMLReader_put_baseURL( 02733 (IVBSAXXMLReader*)&This->lpVBSAXXMLReaderVtbl, 02734 pBaseUrl); 02735 } 02736 02737 static HRESULT WINAPI isaxxmlreader_getSecureBaseURL( 02738 ISAXXMLReader* iface, 02739 const WCHAR **pSecureBaseUrl) 02740 { 02741 saxreader *This = impl_from_ISAXXMLReader( iface ); 02742 return IVBSAXXMLReader_get_secureBaseURL( 02743 (IVBSAXXMLReader*)&This->lpVBSAXXMLReaderVtbl, 02744 pSecureBaseUrl); 02745 } 02746 02747 static HRESULT WINAPI isaxxmlreader_putSecureBaseURL( 02748 ISAXXMLReader* iface, 02749 const WCHAR *secureBaseUrl) 02750 { 02751 saxreader *This = impl_from_ISAXXMLReader( iface ); 02752 return IVBSAXXMLReader_put_secureBaseURL( 02753 (IVBSAXXMLReader*)&This->lpVBSAXXMLReaderVtbl, 02754 secureBaseUrl); 02755 } 02756 02757 static HRESULT WINAPI isaxxmlreader_parse( 02758 ISAXXMLReader* iface, 02759 VARIANT varInput) 02760 { 02761 saxreader *This = impl_from_ISAXXMLReader( iface ); 02762 return internal_parse(This, varInput, FALSE); 02763 } 02764 02765 static HRESULT WINAPI isaxxmlreader_parseURL( 02766 ISAXXMLReader* iface, 02767 const WCHAR *url) 02768 { 02769 saxreader *This = impl_from_ISAXXMLReader( iface ); 02770 return internal_parseURL(This, url, FALSE); 02771 } 02772 02773 static const struct ISAXXMLReaderVtbl isaxreader_vtbl = 02774 { 02775 isaxxmlreader_QueryInterface, 02776 isaxxmlreader_AddRef, 02777 isaxxmlreader_Release, 02778 isaxxmlreader_getFeature, 02779 isaxxmlreader_putFeature, 02780 isaxxmlreader_getProperty, 02781 isaxxmlreader_putProperty, 02782 isaxxmlreader_getEntityResolver, 02783 isaxxmlreader_putEntityResolver, 02784 isaxxmlreader_getContentHandler, 02785 isaxxmlreader_putContentHandler, 02786 isaxxmlreader_getDTDHandler, 02787 isaxxmlreader_putDTDHandler, 02788 isaxxmlreader_getErrorHandler, 02789 isaxxmlreader_putErrorHandler, 02790 isaxxmlreader_getBaseURL, 02791 isaxxmlreader_putBaseURL, 02792 isaxxmlreader_getSecureBaseURL, 02793 isaxxmlreader_putSecureBaseURL, 02794 isaxxmlreader_parse, 02795 isaxxmlreader_parseURL 02796 }; 02797 02798 HRESULT SAXXMLReader_create(IUnknown *pUnkOuter, LPVOID *ppObj) 02799 { 02800 saxreader *reader; 02801 02802 TRACE("(%p,%p)\n", pUnkOuter, ppObj); 02803 02804 reader = heap_alloc( sizeof (*reader) ); 02805 if( !reader ) 02806 return E_OUTOFMEMORY; 02807 02808 reader->lpVBSAXXMLReaderVtbl = &saxreader_vtbl; 02809 reader->lpSAXXMLReaderVtbl = &isaxreader_vtbl; 02810 reader->ref = 1; 02811 reader->contentHandler = NULL; 02812 reader->vbcontentHandler = NULL; 02813 reader->errorHandler = NULL; 02814 reader->vberrorHandler = NULL; 02815 reader->lexicalHandler = NULL; 02816 reader->vblexicalHandler = NULL; 02817 reader->declHandler = NULL; 02818 reader->vbdeclHandler = NULL; 02819 reader->isParsing = FALSE; 02820 02821 memset(&reader->sax, 0, sizeof(xmlSAXHandler)); 02822 reader->sax.initialized = XML_SAX2_MAGIC; 02823 reader->sax.startDocument = libxmlStartDocument; 02824 reader->sax.endDocument = libxmlEndDocument; 02825 reader->sax.startElementNs = libxmlStartElementNS; 02826 reader->sax.endElementNs = libxmlEndElementNS; 02827 reader->sax.characters = libxmlCharacters; 02828 reader->sax.setDocumentLocator = libxmlSetDocumentLocator; 02829 reader->sax.comment = libxmlComment; 02830 reader->sax.error = libxmlFatalError; 02831 reader->sax.fatalError = libxmlFatalError; 02832 reader->sax.cdataBlock = libxmlCDataBlock; 02833 02834 *ppObj = &reader->lpVBSAXXMLReaderVtbl; 02835 02836 TRACE("returning iface %p\n", *ppObj); 02837 02838 return S_OK; 02839 } 02840 02841 #else 02842 02843 HRESULT SAXXMLReader_create(IUnknown *pUnkOuter, LPVOID *ppObj) 02844 { 02845 MESSAGE("This program tried to use a SAX XML Reader object, but\n" 02846 "libxml2 support was not present at compile time.\n"); 02847 return E_NOTIMPL; 02848 } 02849 02850 #endif Generated on Sun May 27 2012 04:25:25 for ReactOS by
1.7.6.1
|