Commit df5e40ec authored by Piotr Caban's avatar Piotr Caban Committed by Alexandre Julliard

msxml3: Reorganize parse_buffer function (make use of libxml2 parserInternals.h).

parent 7abfbd08
...@@ -44,6 +44,7 @@ WINE_DEFAULT_DEBUG_CHANNEL(msxml); ...@@ -44,6 +44,7 @@ WINE_DEFAULT_DEBUG_CHANNEL(msxml);
#ifdef HAVE_LIBXML2 #ifdef HAVE_LIBXML2
#include <libxml/SAX2.h> #include <libxml/SAX2.h>
#include <libxml/parserInternals.h>
typedef struct _saxreader typedef struct _saxreader
{ {
...@@ -151,6 +152,12 @@ static void update_position(saxlocator *This, xmlChar *end) ...@@ -151,6 +152,12 @@ static void update_position(saxlocator *This, xmlChar *end)
This->line = 1; This->line = 1;
This->column = 1; This->column = 1;
} }
else if(This->lastCur < This->pParserCtxt->input->base)
{
This->lastCur = (xmlChar*)This->pParserCtxt->input->base;
This->line = 1;
This->column = 1;
}
if(!end) end = (xmlChar*)This->pParserCtxt->input->cur; if(!end) end = (xmlChar*)This->pParserCtxt->input->cur;
...@@ -1468,7 +1475,7 @@ static HRESULT WINAPI isaxxmlreader_putSecureBaseURL( ...@@ -1468,7 +1475,7 @@ static HRESULT WINAPI isaxxmlreader_putSecureBaseURL(
return E_NOTIMPL; return E_NOTIMPL;
} }
static HRESULT parse_buffer(saxreader *This, xmlChar *buffer) static HRESULT parse_buffer(saxreader *This, const char *buffer, int size)
{ {
saxlocator *locator; saxlocator *locator;
HRESULT hr; HRESULT hr;
...@@ -1477,7 +1484,7 @@ static HRESULT parse_buffer(saxreader *This, xmlChar *buffer) ...@@ -1477,7 +1484,7 @@ static HRESULT parse_buffer(saxreader *This, xmlChar *buffer)
if(FAILED(hr)) if(FAILED(hr))
return E_FAIL; return E_FAIL;
locator->pParserCtxt = xmlNewParserCtxt(); locator->pParserCtxt = xmlCreateMemoryParserCtxt(buffer, size);
if(!locator->pParserCtxt) if(!locator->pParserCtxt)
{ {
ISAXLocator_Release((ISAXLocator*)&locator->lpSAXLocatorVtbl); ISAXLocator_Release((ISAXLocator*)&locator->lpSAXLocatorVtbl);
...@@ -1487,8 +1494,6 @@ static HRESULT parse_buffer(saxreader *This, xmlChar *buffer) ...@@ -1487,8 +1494,6 @@ static HRESULT parse_buffer(saxreader *This, xmlChar *buffer)
locator->pParserCtxt->sax = &locator->saxreader->sax; locator->pParserCtxt->sax = &locator->saxreader->sax;
locator->pParserCtxt->userData = locator; locator->pParserCtxt->userData = locator;
xmlSetupParserForBuffer(locator->pParserCtxt, buffer, NULL);
if(xmlParseDocument(locator->pParserCtxt)) hr = E_FAIL; if(xmlParseDocument(locator->pParserCtxt)) hr = E_FAIL;
else hr = locator->ret; else hr = locator->ret;
...@@ -1508,7 +1513,6 @@ static HRESULT WINAPI isaxxmlreader_parse( ...@@ -1508,7 +1513,6 @@ static HRESULT WINAPI isaxxmlreader_parse(
VARIANT varInput) VARIANT varInput)
{ {
saxreader *This = impl_from_ISAXXMLReader( iface ); saxreader *This = impl_from_ISAXXMLReader( iface );
xmlChar *data = NULL;
HRESULT hr; HRESULT hr;
TRACE("(%p)\n", This); TRACE("(%p)\n", This);
...@@ -1517,8 +1521,8 @@ static HRESULT WINAPI isaxxmlreader_parse( ...@@ -1517,8 +1521,8 @@ static HRESULT WINAPI isaxxmlreader_parse(
switch(V_VT(&varInput)) switch(V_VT(&varInput))
{ {
case VT_BSTR: case VT_BSTR:
data = xmlChar_from_wchar(V_BSTR(&varInput)); hr = parse_buffer(This, (const char*)V_BSTR(&varInput),
hr = parse_buffer(This, data); SysStringByteLen(V_BSTR(&varInput)));
break; break;
case VT_ARRAY|VT_UI1: { case VT_ARRAY|VT_UI1: {
void *pSAData; void *pSAData;
...@@ -1530,13 +1534,9 @@ static HRESULT WINAPI isaxxmlreader_parse( ...@@ -1530,13 +1534,9 @@ static HRESULT WINAPI isaxxmlreader_parse(
hr = SafeArrayGetUBound(V_ARRAY(&varInput), 1, &uBound); hr = SafeArrayGetUBound(V_ARRAY(&varInput), 1, &uBound);
if(hr != S_OK) break; if(hr != S_OK) break;
dataRead = (uBound-lBound)*SafeArrayGetElemsize(V_ARRAY(&varInput)); dataRead = (uBound-lBound)*SafeArrayGetElemsize(V_ARRAY(&varInput));
data = HeapAlloc(GetProcessHeap(), 0, dataRead+1);
if(!data) break;
hr = SafeArrayAccessData(V_ARRAY(&varInput), (void**)&pSAData); hr = SafeArrayAccessData(V_ARRAY(&varInput), (void**)&pSAData);
if(hr != S_OK) break; if(hr != S_OK) break;
memcpy(data, pSAData, dataRead); hr = parse_buffer(This, pSAData, dataRead);
data[dataRead] = '\0';
hr = parse_buffer(This, data);
SafeArrayUnaccessData(V_ARRAY(&varInput)); SafeArrayUnaccessData(V_ARRAY(&varInput));
break; break;
} }
...@@ -1558,6 +1558,7 @@ static HRESULT WINAPI isaxxmlreader_parse( ...@@ -1558,6 +1558,7 @@ static HRESULT WINAPI isaxxmlreader_parse(
{ {
STATSTG dataInfo; STATSTG dataInfo;
ULONG dataRead; ULONG dataRead;
char *data;
while(1) while(1)
{ {
...@@ -1566,7 +1567,7 @@ static HRESULT WINAPI isaxxmlreader_parse( ...@@ -1566,7 +1567,7 @@ static HRESULT WINAPI isaxxmlreader_parse(
break; break;
} }
data = HeapAlloc(GetProcessHeap(), 0, data = HeapAlloc(GetProcessHeap(), 0,
dataInfo.cbSize.QuadPart+1); dataInfo.cbSize.QuadPart);
while(1) while(1)
{ {
hr = IStream_Read(stream, data, hr = IStream_Read(stream, data,
...@@ -1574,8 +1575,8 @@ static HRESULT WINAPI isaxxmlreader_parse( ...@@ -1574,8 +1575,8 @@ static HRESULT WINAPI isaxxmlreader_parse(
if(hr == E_PENDING) continue; if(hr == E_PENDING) continue;
break; break;
} }
data[dataInfo.cbSize.QuadPart] = '\0'; hr = parse_buffer(This, data, dataInfo.cbSize.QuadPart);
hr = parse_buffer(This, data); HeapFree(GetProcessHeap(), 0, data);
IStream_Release(stream); IStream_Release(stream);
break; break;
} }
...@@ -1585,8 +1586,7 @@ static HRESULT WINAPI isaxxmlreader_parse( ...@@ -1585,8 +1586,7 @@ static HRESULT WINAPI isaxxmlreader_parse(
BSTR bstrData; BSTR bstrData;
IXMLDOMDocument_get_xml(xmlDoc, &bstrData); IXMLDOMDocument_get_xml(xmlDoc, &bstrData);
data = xmlChar_from_wchar(bstrData); hr = parse_buffer(This, (const char*)bstrData, SysStringByteLen(bstrData));
hr = parse_buffer(This, data);
IXMLDOMDocument_Release(xmlDoc); IXMLDOMDocument_Release(xmlDoc);
hr = E_NOTIMPL; hr = E_NOTIMPL;
break; break;
...@@ -1597,23 +1597,16 @@ static HRESULT WINAPI isaxxmlreader_parse( ...@@ -1597,23 +1597,16 @@ static HRESULT WINAPI isaxxmlreader_parse(
hr = E_INVALIDARG; hr = E_INVALIDARG;
} }
HeapFree(GetProcessHeap(), 0, data);
return hr; return hr;
} }
static HRESULT saxreader_onDataAvailable(void *obj, char *ptr, DWORD len) static HRESULT saxreader_onDataAvailable(void *obj, char *ptr, DWORD len)
{ {
saxreader *This = obj; saxreader *This = obj;
xmlChar *data;
HRESULT hr; HRESULT hr;
data = HeapAlloc(GetProcessHeap(), 0, len+1); hr = parse_buffer(This, ptr, len);
memcpy(data, ptr, len);
data[len] = 0;
hr = parse_buffer(This, data);
HeapFree(GetProcessHeap(), 0, data);
return hr; return hr;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment