Piotr Caban : msxml3: Initialize ISAXAttribute structure.
Alexandre Julliard
julliard at winehq.org
Thu Jul 31 07:17:52 CDT 2008
Module: wine
Branch: master
Commit: 6df49d5707fccbf480be88441fdb83c5af1575ce
URL: http://source.winehq.org/git/wine.git/?a=commit;h=6df49d5707fccbf480be88441fdb83c5af1575ce
Author: Piotr Caban <piotr.caban at gmail.com>
Date: Wed Jul 30 20:24:12 2008 +0200
msxml3: Initialize ISAXAttribute structure.
---
dlls/msxml3/saxreader.c | 111 +++++++++++++++++++++++++++++++++++++++++------
1 files changed, 97 insertions(+), 14 deletions(-)
diff --git a/dlls/msxml3/saxreader.c b/dlls/msxml3/saxreader.c
index 8ec1e46..62bfd9b 100644
--- a/dlls/msxml3/saxreader.c
+++ b/dlls/msxml3/saxreader.c
@@ -73,6 +73,11 @@ typedef struct _saxattributes
{
const struct ISAXAttributesVtbl *lpSAXAttributesVtbl;
LONG ref;
+ int nb_attributes;
+ BSTR *szLocalname;
+ BSTR *szPrefix;
+ BSTR *szURI;
+ BSTR *szValue;
} saxattributes;
static inline saxreader *impl_from_IVBSAXXMLReader( IVBSAXXMLReader *iface )
@@ -96,6 +101,28 @@ static inline saxattributes *impl_from_ISAXAttributes( ISAXAttributes *iface )
}
+BSTR bstr_from_xmlCharN(const xmlChar *buf, int len)
+{
+ DWORD dLen;
+ LPWSTR str;
+ BSTR bstr;
+
+ if (!buf)
+ return NULL;
+
+ dLen = MultiByteToWideChar(CP_UTF8, 0, (LPCSTR)buf, len, NULL, 0);
+ if(len != -1) dLen++;
+ str = (LPWSTR)HeapAlloc(GetProcessHeap(), 0, dLen * sizeof (WCHAR));
+ if (!str)
+ return NULL;
+ MultiByteToWideChar(CP_UTF8, 0, (LPCSTR)buf, len, str, dLen);
+ if(len != -1) str[dLen-1] = '\0';
+ bstr = SysAllocString(str);
+ HeapFree(GetProcessHeap(), 0, str);
+
+ return bstr;
+}
+
static void format_error_message_from_id(saxlocator *This, HRESULT hr)
{
xmlStopParser(This->pParserCtxt);
@@ -191,6 +218,20 @@ static ULONG WINAPI isaxattributes_Release(ISAXAttributes* iface)
ref = InterlockedDecrement(&This->ref);
if (ref==0)
{
+ int index;
+ for(index=0; index<This->nb_attributes; index++)
+ {
+ SysFreeString(This->szLocalname[index]);
+ SysFreeString(This->szPrefix[index]);
+ SysFreeString(This->szURI[index]);
+ SysFreeString(This->szValue[index]);
+ }
+
+ HeapFree(GetProcessHeap(), 0, This->szLocalname);
+ HeapFree(GetProcessHeap(), 0, This->szPrefix);
+ HeapFree(GetProcessHeap(), 0, This->szURI);
+ HeapFree(GetProcessHeap(), 0, This->szValue);
+
HeapFree(GetProcessHeap(), 0, This);
}
@@ -389,9 +430,11 @@ static const struct ISAXAttributesVtbl isaxattributes_vtbl =
isaxattributes_getValueFromQName
};
-static HRESULT SAXAttributes_create(IUnknown *pUnkOuter, LPVOID *ppObj)
+static HRESULT SAXAttributes_create(saxattributes **attr,
+ int nb_attributes, const xmlChar **xmlAttributes)
{
saxattributes *attributes;
+ int index;
attributes = HeapAlloc(GetProcessHeap(), 0, sizeof(*attributes));
if(!attributes)
@@ -400,9 +443,47 @@ static HRESULT SAXAttributes_create(IUnknown *pUnkOuter, LPVOID *ppObj)
attributes->lpSAXAttributesVtbl = &isaxattributes_vtbl;
attributes->ref = 1;
- *ppObj = attributes;
+ attributes->nb_attributes = nb_attributes;
+
+ attributes->szLocalname =
+ HeapAlloc(GetProcessHeap(), 0, sizeof(BSTR)*nb_attributes);
+ attributes->szPrefix =
+ HeapAlloc(GetProcessHeap(), 0, sizeof(BSTR)*nb_attributes);
+ attributes->szURI =
+ HeapAlloc(GetProcessHeap(), 0, sizeof(BSTR)*nb_attributes);
+ attributes->szValue =
+ HeapAlloc(GetProcessHeap(), 0, sizeof(BSTR)*nb_attributes);
+
+ if(!attributes->szLocalname || !attributes->szPrefix
+ || !attributes->szURI || !attributes->szValue)
+ {
+ if(attributes->szLocalname)
+ HeapFree(GetProcessHeap(), 0, attributes->szLocalname);
+ if(attributes->szPrefix)
+ HeapFree(GetProcessHeap(), 0, attributes->szPrefix);
+ if(attributes->szURI)
+ HeapFree(GetProcessHeap(), 0, attributes->szURI);
+ if(attributes->szValue)
+ HeapFree(GetProcessHeap(), 0, attributes->szValue);
+ return E_FAIL;
+ }
+
+ for(index=0; index<nb_attributes; index++)
+ {
+ attributes->szLocalname[index] =
+ bstr_from_xmlChar(xmlAttributes[index*5]);
+ attributes->szPrefix[index] =
+ bstr_from_xmlChar(xmlAttributes[index*5+1]);
+ attributes->szURI[index] =
+ bstr_from_xmlChar(xmlAttributes[index*5+2]);
+ attributes->szValue[index] =
+ bstr_from_xmlCharN(xmlAttributes[index*5+3],
+ xmlAttributes[index*5+4]-xmlAttributes[index*5+3]);
+ }
+
+ *attr = attributes;
- TRACE("returning %p\n", *ppObj);
+ TRACE("returning %p\n", *attr);
return S_OK;
}
@@ -455,7 +536,7 @@ static void libxmlStartElementNS(
BSTR NamespaceUri, LocalName, QName;
saxlocator *This = ctx;
HRESULT hr;
- ISAXAttributes *attr;
+ saxattributes *attr;
FIXME("Arguments processing not yet implemented.\n");
@@ -467,21 +548,23 @@ static void libxmlStartElementNS(
LocalName = bstr_from_xmlChar(localname);
QName = bstr_from_xmlChar(localname);
- SAXAttributes_create(NULL, (void*)&attr);
-
- hr = ISAXContentHandler_startElement(
- This->saxreader->contentHandler,
- NamespaceUri, SysStringLen(NamespaceUri),
- LocalName, SysStringLen(LocalName),
- QName, SysStringLen(QName),
- attr);
+ hr = SAXAttributes_create(&attr, nb_attributes, attributes);
+ if(hr == S_OK)
+ {
+ hr = ISAXContentHandler_startElement(
+ This->saxreader->contentHandler,
+ NamespaceUri, SysStringLen(NamespaceUri),
+ LocalName, SysStringLen(LocalName),
+ QName, SysStringLen(QName),
+ (ISAXAttributes*)&attr->lpSAXAttributesVtbl);
+
+ ISAXAttributes_Release((ISAXAttributes*)&attr->lpSAXAttributesVtbl);
+ }
SysFreeString(NamespaceUri);
SysFreeString(LocalName);
SysFreeString(QName);
- ISAXAttributes_Release(attr);
-
if(hr != S_OK)
format_error_message_from_id(This, hr);
}
More information about the wine-cvs
mailing list