webservices: Use a WS_BYTES structure to store XML buffer data.
Signed-off-by: Hans Leidekker <hans@codeweavers.com> Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
parent
eaf2cd11ae
commit
3f20b66a54
|
@ -320,21 +320,21 @@ struct xmlbuf *alloc_xmlbuf( WS_HEAP *heap )
|
|||
struct xmlbuf *ret;
|
||||
|
||||
if (!(ret = ws_alloc( heap, sizeof(*ret) ))) return NULL;
|
||||
if (!(ret->ptr = ws_alloc( heap, XML_BUFFER_INITIAL_ALLOCATED_SIZE )))
|
||||
if (!(ret->bytes.bytes = ws_alloc( heap, XML_BUFFER_INITIAL_ALLOCATED_SIZE )))
|
||||
{
|
||||
ws_free( heap, ret, sizeof(*ret) );
|
||||
return NULL;
|
||||
}
|
||||
ret->heap = heap;
|
||||
ret->size_allocated = XML_BUFFER_INITIAL_ALLOCATED_SIZE;
|
||||
ret->size = 0;
|
||||
ret->heap = heap;
|
||||
ret->size = XML_BUFFER_INITIAL_ALLOCATED_SIZE;
|
||||
ret->bytes.length = 0;
|
||||
return ret;
|
||||
}
|
||||
|
||||
void free_xmlbuf( struct xmlbuf *xmlbuf )
|
||||
{
|
||||
if (!xmlbuf) return;
|
||||
ws_free( xmlbuf->heap, xmlbuf->ptr, xmlbuf->size_allocated );
|
||||
ws_free( xmlbuf->heap, xmlbuf->bytes.bytes, xmlbuf->size );
|
||||
ws_free( xmlbuf->heap, xmlbuf, sizeof(*xmlbuf) );
|
||||
}
|
||||
|
||||
|
|
|
@ -4662,12 +4662,12 @@ HRESULT WINAPI WsSetInputToBuffer( WS_XML_READER *handle, WS_XML_BUFFER *buffer,
|
|||
|
||||
if ((hr = init_reader( reader )) != S_OK) goto done;
|
||||
|
||||
charset = detect_charset( xmlbuf->ptr, xmlbuf->size, &offset );
|
||||
charset = detect_charset( xmlbuf->bytes.bytes, xmlbuf->bytes.length, &offset );
|
||||
hr = prop_set( reader->prop, reader->prop_count, WS_XML_READER_PROPERTY_CHARSET, &charset,
|
||||
sizeof(charset) );
|
||||
if (hr != S_OK) goto done;
|
||||
|
||||
set_input_buffer( reader, xmlbuf, (const unsigned char *)xmlbuf->ptr + offset, xmlbuf->size - offset );
|
||||
set_input_buffer( reader, xmlbuf, xmlbuf->bytes.bytes + offset, xmlbuf->bytes.length - offset );
|
||||
if (!(node = alloc_node( WS_XML_NODE_TYPE_BOF ))) hr = E_OUTOFMEMORY;
|
||||
else read_insert_bof( reader, node );
|
||||
|
||||
|
|
|
@ -21,8 +21,7 @@
|
|||
struct xmlbuf
|
||||
{
|
||||
WS_HEAP *heap;
|
||||
void *ptr;
|
||||
SIZE_T size_allocated;
|
||||
WS_BYTES bytes;
|
||||
SIZE_T size;
|
||||
};
|
||||
|
||||
|
|
|
@ -288,8 +288,8 @@ HRESULT WINAPI WsGetWriterProperty( WS_XML_WRITER *handle, WS_XML_WRITER_PROPERT
|
|||
if (size != sizeof(*bytes)) hr = E_INVALIDARG;
|
||||
else
|
||||
{
|
||||
bytes->bytes = writer->output_buf->ptr;
|
||||
bytes->length = writer->output_buf->size;
|
||||
bytes->bytes = writer->output_buf->bytes.bytes;
|
||||
bytes->length = writer->output_buf->bytes.length;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
@ -310,7 +310,7 @@ static void set_output_buffer( struct writer *writer, struct xmlbuf *xmlbuf )
|
|||
}
|
||||
writer->output_buf = xmlbuf;
|
||||
writer->output_type = WS_XML_WRITER_OUTPUT_TYPE_BUFFER;
|
||||
writer->write_bufptr = xmlbuf->ptr;
|
||||
writer->write_bufptr = xmlbuf->bytes.bytes;
|
||||
writer->write_pos = 0;
|
||||
}
|
||||
|
||||
|
@ -441,16 +441,16 @@ static HRESULT write_grow_buffer( struct writer *writer, ULONG size )
|
|||
SIZE_T new_size;
|
||||
void *tmp;
|
||||
|
||||
if (buf->size_allocated >= writer->write_pos + size)
|
||||
if (buf->size >= writer->write_pos + size)
|
||||
{
|
||||
buf->size = writer->write_pos + size;
|
||||
buf->bytes.length = writer->write_pos + size;
|
||||
return S_OK;
|
||||
}
|
||||
new_size = max( buf->size_allocated * 2, writer->write_pos + size );
|
||||
if (!(tmp = ws_realloc( buf->heap, buf->ptr, buf->size_allocated, new_size ))) return WS_E_QUOTA_EXCEEDED;
|
||||
writer->write_bufptr = buf->ptr = tmp;
|
||||
buf->size_allocated = new_size;
|
||||
buf->size = writer->write_pos + size;
|
||||
new_size = max( buf->size * 2, writer->write_pos + size );
|
||||
if (!(tmp = ws_realloc( buf->heap, buf->bytes.bytes, buf->size, new_size ))) return WS_E_QUOTA_EXCEEDED;
|
||||
writer->write_bufptr = buf->bytes.bytes = tmp;
|
||||
buf->size = new_size;
|
||||
buf->bytes.length = writer->write_pos + size;
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
|
@ -2820,8 +2820,8 @@ HRESULT WINAPI WsWriteXmlBuffer( WS_XML_WRITER *handle, WS_XML_BUFFER *buffer, W
|
|||
}
|
||||
|
||||
if ((hr = write_flush( writer )) != S_OK) goto done;
|
||||
if ((hr = write_grow_buffer( writer, xmlbuf->size )) != S_OK) goto done;
|
||||
write_bytes( writer, xmlbuf->ptr, xmlbuf->size );
|
||||
if ((hr = write_grow_buffer( writer, xmlbuf->bytes.length )) != S_OK) goto done;
|
||||
write_bytes( writer, xmlbuf->bytes.bytes, xmlbuf->bytes.length );
|
||||
|
||||
done:
|
||||
LeaveCriticalSection( &writer->cs );
|
||||
|
@ -2869,12 +2869,12 @@ HRESULT WINAPI WsWriteXmlBufferToBytes( WS_XML_WRITER *handle, WS_XML_BUFFER *bu
|
|||
if (hr != S_OK) goto done;
|
||||
}
|
||||
|
||||
if (!(buf = ws_alloc( heap, xmlbuf->size ))) hr = WS_E_QUOTA_EXCEEDED;
|
||||
if (!(buf = ws_alloc( heap, xmlbuf->bytes.length ))) hr = WS_E_QUOTA_EXCEEDED;
|
||||
else
|
||||
{
|
||||
memcpy( buf, xmlbuf->ptr, xmlbuf->size );
|
||||
memcpy( buf, xmlbuf->bytes.bytes, xmlbuf->bytes.length );
|
||||
*bytes = buf;
|
||||
*size = xmlbuf->size;
|
||||
*size = xmlbuf->bytes.length;
|
||||
}
|
||||
|
||||
done:
|
||||
|
|
Loading…
Reference in New Issue