Commit 1ba18219 authored by Hans Leidekker's avatar Hans Leidekker Committed by Alexandre Julliard

webservices: Store buffer encoding and character set.

parent 83bdbc1e
...@@ -315,7 +315,7 @@ HRESULT WINAPI WsGetHeapProperty( WS_HEAP *handle, WS_HEAP_PROPERTY_ID id, void ...@@ -315,7 +315,7 @@ HRESULT WINAPI WsGetHeapProperty( WS_HEAP *handle, WS_HEAP_PROPERTY_ID id, void
} }
#define XML_BUFFER_INITIAL_ALLOCATED_SIZE 256 #define XML_BUFFER_INITIAL_ALLOCATED_SIZE 256
struct xmlbuf *alloc_xmlbuf( WS_HEAP *heap ) struct xmlbuf *alloc_xmlbuf( WS_HEAP *heap, WS_XML_WRITER_ENCODING_TYPE encoding, WS_CHARSET charset )
{ {
struct xmlbuf *ret; struct xmlbuf *ret;
...@@ -328,6 +328,8 @@ struct xmlbuf *alloc_xmlbuf( WS_HEAP *heap ) ...@@ -328,6 +328,8 @@ struct xmlbuf *alloc_xmlbuf( WS_HEAP *heap )
ret->heap = heap; ret->heap = heap;
ret->size = XML_BUFFER_INITIAL_ALLOCATED_SIZE; ret->size = XML_BUFFER_INITIAL_ALLOCATED_SIZE;
ret->bytes.length = 0; ret->bytes.length = 0;
ret->encoding = encoding;
ret->charset = charset;
return ret; return ret;
} }
...@@ -349,7 +351,10 @@ HRESULT WINAPI WsCreateXmlBuffer( WS_HEAP *heap, const WS_XML_BUFFER_PROPERTY *p ...@@ -349,7 +351,10 @@ HRESULT WINAPI WsCreateXmlBuffer( WS_HEAP *heap, const WS_XML_BUFFER_PROPERTY *p
if (!heap || !handle) return E_INVALIDARG; if (!heap || !handle) return E_INVALIDARG;
if (count) FIXME( "properties not implemented\n" ); if (count) FIXME( "properties not implemented\n" );
if (!(xmlbuf = alloc_xmlbuf( heap ))) return WS_E_QUOTA_EXCEEDED; if (!(xmlbuf = alloc_xmlbuf( heap, WS_XML_WRITER_ENCODING_TYPE_TEXT, WS_CHARSET_UTF8 )))
{
return WS_E_QUOTA_EXCEEDED;
}
*handle = (WS_XML_BUFFER *)xmlbuf; *handle = (WS_XML_BUFFER *)xmlbuf;
return S_OK; return S_OK;
......
...@@ -365,6 +365,7 @@ struct reader ...@@ -365,6 +365,7 @@ struct reader
ULONG nb_prefixes; ULONG nb_prefixes;
ULONG nb_prefixes_allocated; ULONG nb_prefixes_allocated;
WS_XML_READER_ENCODING_TYPE input_enc; WS_XML_READER_ENCODING_TYPE input_enc;
WS_CHARSET input_charset;
WS_XML_READER_INPUT_TYPE input_type; WS_XML_READER_INPUT_TYPE input_type;
struct xmlbuf *input_buf; struct xmlbuf *input_buf;
const unsigned char *input_data; const unsigned char *input_data;
...@@ -511,6 +512,7 @@ static HRESULT init_reader( struct reader *reader ) ...@@ -511,6 +512,7 @@ static HRESULT init_reader( struct reader *reader )
if (!(node = alloc_node( WS_XML_NODE_TYPE_EOF ))) return E_OUTOFMEMORY; if (!(node = alloc_node( WS_XML_NODE_TYPE_EOF ))) return E_OUTOFMEMORY;
read_insert_eof( reader, node ); read_insert_eof( reader, node );
reader->input_enc = WS_XML_READER_ENCODING_TYPE_TEXT; reader->input_enc = WS_XML_READER_ENCODING_TYPE_TEXT;
reader->input_charset = WS_CHARSET_UTF8;
reader->dict_static = NULL; reader->dict_static = NULL;
reader->dict = NULL; reader->dict = NULL;
return S_OK; return S_OK;
...@@ -524,7 +526,6 @@ HRESULT WINAPI WsCreateReader( const WS_XML_READER_PROPERTY *properties, ULONG c ...@@ -524,7 +526,6 @@ HRESULT WINAPI WsCreateReader( const WS_XML_READER_PROPERTY *properties, ULONG c
{ {
struct reader *reader; struct reader *reader;
ULONG i, max_depth = 32, max_attrs = 128, max_ns = 32; ULONG i, max_depth = 32, max_attrs = 128, max_ns = 32;
WS_CHARSET charset = WS_CHARSET_UTF8;
BOOL read_decl = TRUE; BOOL read_decl = TRUE;
HRESULT hr; HRESULT hr;
...@@ -537,7 +538,6 @@ HRESULT WINAPI WsCreateReader( const WS_XML_READER_PROPERTY *properties, ULONG c ...@@ -537,7 +538,6 @@ HRESULT WINAPI WsCreateReader( const WS_XML_READER_PROPERTY *properties, ULONG c
prop_set( reader->prop, reader->prop_count, WS_XML_READER_PROPERTY_MAX_DEPTH, &max_depth, sizeof(max_depth) ); prop_set( reader->prop, reader->prop_count, WS_XML_READER_PROPERTY_MAX_DEPTH, &max_depth, sizeof(max_depth) );
prop_set( reader->prop, reader->prop_count, WS_XML_READER_PROPERTY_MAX_ATTRIBUTES, &max_attrs, sizeof(max_attrs) ); prop_set( reader->prop, reader->prop_count, WS_XML_READER_PROPERTY_MAX_ATTRIBUTES, &max_attrs, sizeof(max_attrs) );
prop_set( reader->prop, reader->prop_count, WS_XML_READER_PROPERTY_READ_DECLARATION, &read_decl, sizeof(read_decl) ); prop_set( reader->prop, reader->prop_count, WS_XML_READER_PROPERTY_READ_DECLARATION, &read_decl, sizeof(read_decl) );
prop_set( reader->prop, reader->prop_count, WS_XML_READER_PROPERTY_CHARSET, &charset, sizeof(charset) );
prop_set( reader->prop, reader->prop_count, WS_XML_READER_PROPERTY_MAX_NAMESPACES, &max_ns, sizeof(max_ns) ); prop_set( reader->prop, reader->prop_count, WS_XML_READER_PROPERTY_MAX_NAMESPACES, &max_ns, sizeof(max_ns) );
for (i = 0; i < count; i++) for (i = 0; i < count; i++)
...@@ -719,6 +719,14 @@ HRESULT WINAPI WsGetReaderNode( WS_XML_READER *handle, const WS_XML_NODE **node, ...@@ -719,6 +719,14 @@ HRESULT WINAPI WsGetReaderNode( WS_XML_READER *handle, const WS_XML_NODE **node,
return S_OK; return S_OK;
} }
static HRESULT get_charset( struct reader *reader, void *buf, ULONG size )
{
if (!buf || size != sizeof(reader->input_charset)) return E_INVALIDARG;
if (!reader->input_charset) return WS_E_INVALID_FORMAT;
*(WS_CHARSET *)buf = reader->input_charset;
return S_OK;
}
/************************************************************************** /**************************************************************************
* WsGetReaderProperty [webservices.@] * WsGetReaderProperty [webservices.@]
*/ */
...@@ -747,21 +755,9 @@ HRESULT WINAPI WsGetReaderProperty( WS_XML_READER *handle, WS_XML_READER_PROPERT ...@@ -747,21 +755,9 @@ HRESULT WINAPI WsGetReaderProperty( WS_XML_READER *handle, WS_XML_READER_PROPERT
return WS_E_INVALID_OPERATION; return WS_E_INVALID_OPERATION;
} }
if (id == WS_XML_READER_PROPERTY_CHARSET) if (id == WS_XML_READER_PROPERTY_CHARSET) hr = get_charset( reader, buf, size );
{
WS_CHARSET charset;
if ((hr = prop_get( reader->prop, reader->prop_count, id, &charset, size )) != S_OK) goto done;
if (!charset)
{
hr = WS_E_INVALID_FORMAT;
goto done;
}
*(WS_CHARSET *)buf = charset;
hr = S_OK;
}
else hr = prop_get( reader->prop, reader->prop_count, id, buf, size ); else hr = prop_get( reader->prop, reader->prop_count, id, buf, size );
done:
LeaveCriticalSection( &reader->cs ); LeaveCriticalSection( &reader->cs );
return hr; return hr;
} }
...@@ -5604,7 +5600,6 @@ HRESULT WINAPI WsSetInput( WS_XML_READER *handle, const WS_XML_READER_ENCODING * ...@@ -5604,7 +5600,6 @@ HRESULT WINAPI WsSetInput( WS_XML_READER *handle, const WS_XML_READER_ENCODING *
{ {
WS_XML_READER_TEXT_ENCODING *text = (WS_XML_READER_TEXT_ENCODING *)encoding; WS_XML_READER_TEXT_ENCODING *text = (WS_XML_READER_TEXT_ENCODING *)encoding;
WS_XML_READER_BUFFER_INPUT *buf = (WS_XML_READER_BUFFER_INPUT *)input; WS_XML_READER_BUFFER_INPUT *buf = (WS_XML_READER_BUFFER_INPUT *)input;
WS_CHARSET charset = text->charSet;
if (input->inputType != WS_XML_READER_INPUT_TYPE_BUFFER) if (input->inputType != WS_XML_READER_INPUT_TYPE_BUFFER)
{ {
...@@ -5613,12 +5608,8 @@ HRESULT WINAPI WsSetInput( WS_XML_READER *handle, const WS_XML_READER_ENCODING * ...@@ -5613,12 +5608,8 @@ HRESULT WINAPI WsSetInput( WS_XML_READER *handle, const WS_XML_READER_ENCODING *
goto done; goto done;
} }
if (charset == WS_CHARSET_AUTO) if (text->charSet != WS_CHARSET_AUTO) reader->input_charset = text->charSet;
charset = detect_charset( buf->encodedData, buf->encodedDataSize, &offset ); else reader->input_charset = detect_charset( buf->encodedData, buf->encodedDataSize, &offset );
hr = prop_set( reader->prop, reader->prop_count, WS_XML_READER_PROPERTY_CHARSET,
&charset, sizeof(charset) );
if (hr != S_OK) goto done;
reader->input_enc = WS_XML_READER_ENCODING_TYPE_TEXT; reader->input_enc = WS_XML_READER_ENCODING_TYPE_TEXT;
break; break;
...@@ -5627,6 +5618,7 @@ HRESULT WINAPI WsSetInput( WS_XML_READER *handle, const WS_XML_READER_ENCODING * ...@@ -5627,6 +5618,7 @@ HRESULT WINAPI WsSetInput( WS_XML_READER *handle, const WS_XML_READER_ENCODING *
{ {
WS_XML_READER_BINARY_ENCODING *bin = (WS_XML_READER_BINARY_ENCODING *)encoding; WS_XML_READER_BINARY_ENCODING *bin = (WS_XML_READER_BINARY_ENCODING *)encoding;
reader->input_enc = WS_XML_READER_ENCODING_TYPE_BINARY; reader->input_enc = WS_XML_READER_ENCODING_TYPE_BINARY;
reader->input_charset = 0;
reader->dict_static = bin->staticDictionary ? bin->staticDictionary : &dict_builtin_static; reader->dict_static = bin->staticDictionary ? bin->staticDictionary : &dict_builtin_static;
reader->dict = bin->dynamicDictionary ? bin->dynamicDictionary : &dict_builtin; reader->dict = bin->dynamicDictionary ? bin->dynamicDictionary : &dict_builtin;
break; break;
...@@ -5669,10 +5661,9 @@ HRESULT WINAPI WsSetInputToBuffer( WS_XML_READER *handle, WS_XML_BUFFER *buffer, ...@@ -5669,10 +5661,9 @@ HRESULT WINAPI WsSetInputToBuffer( WS_XML_READER *handle, WS_XML_BUFFER *buffer,
{ {
struct reader *reader = (struct reader *)handle; struct reader *reader = (struct reader *)handle;
struct xmlbuf *xmlbuf = (struct xmlbuf *)buffer; struct xmlbuf *xmlbuf = (struct xmlbuf *)buffer;
WS_CHARSET charset;
struct node *node; struct node *node;
ULONG i, offset = 0;
HRESULT hr; HRESULT hr;
ULONG i;
TRACE( "%p %p %p %u %p\n", handle, buffer, properties, count, error ); TRACE( "%p %p %p %u %p\n", handle, buffer, properties, count, error );
if (error) FIXME( "ignoring error parameter\n" ); if (error) FIXME( "ignoring error parameter\n" );
...@@ -5696,12 +5687,10 @@ HRESULT WINAPI WsSetInputToBuffer( WS_XML_READER *handle, WS_XML_BUFFER *buffer, ...@@ -5696,12 +5687,10 @@ HRESULT WINAPI WsSetInputToBuffer( WS_XML_READER *handle, WS_XML_BUFFER *buffer,
if ((hr = init_reader( reader )) != S_OK) goto done; if ((hr = init_reader( reader )) != S_OK) goto done;
charset = detect_charset( xmlbuf->bytes.bytes, xmlbuf->bytes.length, &offset ); reader->input_enc = xmlbuf->encoding;
hr = prop_set( reader->prop, reader->prop_count, WS_XML_READER_PROPERTY_CHARSET, &charset, reader->input_charset = xmlbuf->charset;
sizeof(charset) ); set_input_buffer( reader, xmlbuf, xmlbuf->bytes.bytes, xmlbuf->bytes.length );
if (hr != S_OK) goto done;
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; if (!(node = alloc_node( WS_XML_NODE_TYPE_BOF ))) hr = E_OUTOFMEMORY;
else read_insert_bof( reader, node ); else read_insert_bof( reader, node );
......
...@@ -23,6 +23,8 @@ struct xmlbuf ...@@ -23,6 +23,8 @@ struct xmlbuf
WS_HEAP *heap; WS_HEAP *heap;
WS_BYTES bytes; WS_BYTES bytes;
SIZE_T size; SIZE_T size;
WS_XML_WRITER_ENCODING_TYPE encoding;
WS_CHARSET charset;
}; };
void *ws_alloc( WS_HEAP *, SIZE_T ) DECLSPEC_HIDDEN; void *ws_alloc( WS_HEAP *, SIZE_T ) DECLSPEC_HIDDEN;
...@@ -30,7 +32,7 @@ void *ws_alloc_zero( WS_HEAP *, SIZE_T ) DECLSPEC_HIDDEN; ...@@ -30,7 +32,7 @@ void *ws_alloc_zero( WS_HEAP *, SIZE_T ) DECLSPEC_HIDDEN;
void *ws_realloc( WS_HEAP *, void *, SIZE_T, SIZE_T ) DECLSPEC_HIDDEN; void *ws_realloc( WS_HEAP *, void *, SIZE_T, SIZE_T ) DECLSPEC_HIDDEN;
void *ws_realloc_zero( WS_HEAP *, void *, SIZE_T, SIZE_T ) DECLSPEC_HIDDEN; void *ws_realloc_zero( WS_HEAP *, void *, SIZE_T, SIZE_T ) DECLSPEC_HIDDEN;
void ws_free( WS_HEAP *, void *, SIZE_T ) DECLSPEC_HIDDEN; void ws_free( WS_HEAP *, void *, SIZE_T ) DECLSPEC_HIDDEN;
struct xmlbuf *alloc_xmlbuf( WS_HEAP * ) DECLSPEC_HIDDEN; struct xmlbuf *alloc_xmlbuf( WS_HEAP *, WS_XML_WRITER_ENCODING_TYPE, WS_CHARSET ) DECLSPEC_HIDDEN;
void free_xmlbuf( struct xmlbuf * ) DECLSPEC_HIDDEN; void free_xmlbuf( struct xmlbuf * ) DECLSPEC_HIDDEN;
WS_XML_DICTIONARY dict_builtin DECLSPEC_HIDDEN; WS_XML_DICTIONARY dict_builtin DECLSPEC_HIDDEN;
......
...@@ -80,6 +80,7 @@ struct writer ...@@ -80,6 +80,7 @@ struct writer
struct node *current; struct node *current;
WS_XML_STRING *current_ns; WS_XML_STRING *current_ns;
WS_XML_WRITER_ENCODING_TYPE output_enc; WS_XML_WRITER_ENCODING_TYPE output_enc;
WS_CHARSET output_charset;
WS_XML_WRITER_OUTPUT_TYPE output_type; WS_XML_WRITER_OUTPUT_TYPE output_type;
struct xmlbuf *output_buf; struct xmlbuf *output_buf;
WS_HEAP *output_heap; WS_HEAP *output_heap;
...@@ -165,6 +166,7 @@ static HRESULT init_writer( struct writer *writer ) ...@@ -165,6 +166,7 @@ static HRESULT init_writer( struct writer *writer )
write_insert_eof( writer, node ); write_insert_eof( writer, node );
writer->state = WRITER_STATE_INITIAL; writer->state = WRITER_STATE_INITIAL;
writer->output_enc = WS_XML_WRITER_ENCODING_TYPE_TEXT; writer->output_enc = WS_XML_WRITER_ENCODING_TYPE_TEXT;
writer->output_charset = WS_CHARSET_UTF8;
writer->dict = NULL; writer->dict = NULL;
return S_OK; return S_OK;
} }
...@@ -377,12 +379,14 @@ HRESULT WINAPI WsSetOutput( WS_XML_WRITER *handle, const WS_XML_WRITER_ENCODING ...@@ -377,12 +379,14 @@ HRESULT WINAPI WsSetOutput( WS_XML_WRITER *handle, const WS_XML_WRITER_ENCODING
goto done; goto done;
} }
writer->output_enc = WS_XML_WRITER_ENCODING_TYPE_TEXT; writer->output_enc = WS_XML_WRITER_ENCODING_TYPE_TEXT;
writer->output_charset = WS_CHARSET_UTF8;
break; break;
} }
case WS_XML_WRITER_ENCODING_TYPE_BINARY: case WS_XML_WRITER_ENCODING_TYPE_BINARY:
{ {
WS_XML_WRITER_BINARY_ENCODING *bin = (WS_XML_WRITER_BINARY_ENCODING *)encoding; WS_XML_WRITER_BINARY_ENCODING *bin = (WS_XML_WRITER_BINARY_ENCODING *)encoding;
writer->output_enc = WS_XML_WRITER_ENCODING_TYPE_BINARY; writer->output_enc = WS_XML_WRITER_ENCODING_TYPE_BINARY;
writer->output_charset = 0;
writer->dict = bin->staticDictionary; writer->dict = bin->staticDictionary;
break; break;
} }
...@@ -397,9 +401,12 @@ HRESULT WINAPI WsSetOutput( WS_XML_WRITER *handle, const WS_XML_WRITER_ENCODING ...@@ -397,9 +401,12 @@ HRESULT WINAPI WsSetOutput( WS_XML_WRITER *handle, const WS_XML_WRITER_ENCODING
case WS_XML_WRITER_OUTPUT_TYPE_BUFFER: case WS_XML_WRITER_OUTPUT_TYPE_BUFFER:
{ {
struct xmlbuf *xmlbuf; struct xmlbuf *xmlbuf;
if (!(xmlbuf = alloc_xmlbuf( writer->output_heap, writer->output_enc, writer->output_charset )))
if (!(xmlbuf = alloc_xmlbuf( writer->output_heap ))) hr = WS_E_QUOTA_EXCEEDED; {
else set_output_buffer( writer, xmlbuf ); hr = WS_E_QUOTA_EXCEEDED;
goto done;
}
set_output_buffer( writer, xmlbuf );
break; break;
} }
default: default:
...@@ -450,6 +457,8 @@ HRESULT WINAPI WsSetOutputToBuffer( WS_XML_WRITER *handle, WS_XML_BUFFER *buffer ...@@ -450,6 +457,8 @@ HRESULT WINAPI WsSetOutputToBuffer( WS_XML_WRITER *handle, WS_XML_BUFFER *buffer
} }
if ((hr = init_writer( writer )) != S_OK) goto done; if ((hr = init_writer( writer )) != S_OK) goto done;
writer->output_enc = xmlbuf->encoding;
writer->output_charset = xmlbuf->charset;
set_output_buffer( writer, xmlbuf ); set_output_buffer( writer, xmlbuf );
if (!(node = alloc_node( WS_XML_NODE_TYPE_BOF ))) hr = E_OUTOFMEMORY; if (!(node = alloc_node( WS_XML_NODE_TYPE_BOF ))) hr = E_OUTOFMEMORY;
...@@ -3247,6 +3256,13 @@ HRESULT WINAPI WsWriteXmlBuffer( WS_XML_WRITER *handle, WS_XML_BUFFER *buffer, W ...@@ -3247,6 +3256,13 @@ HRESULT WINAPI WsWriteXmlBuffer( WS_XML_WRITER *handle, WS_XML_BUFFER *buffer, W
return E_INVALIDARG; return E_INVALIDARG;
} }
if (xmlbuf->encoding != writer->output_enc || xmlbuf->charset != writer->output_charset)
{
FIXME( "no support for different encoding and/or charset\n" );
hr = E_NOTIMPL;
goto done;
}
if ((hr = write_flush( writer )) != S_OK) goto done; if ((hr = write_flush( writer )) != S_OK) goto done;
if ((hr = write_grow_buffer( writer, xmlbuf->bytes.length )) != S_OK) goto done; if ((hr = write_grow_buffer( writer, xmlbuf->bytes.length )) != S_OK) goto done;
write_bytes( writer, xmlbuf->bytes.bytes, xmlbuf->bytes.length ); write_bytes( writer, xmlbuf->bytes.bytes, xmlbuf->bytes.length );
......
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