From 5ad00660685068eb5adf3e721f997be57b59610e Mon Sep 17 00:00:00 2001 From: Hans Leidekker Date: Mon, 4 Jul 2016 11:35:38 +0200 Subject: [PATCH] webservices: Implement WsGetReaderPosition. Signed-off-by: Hans Leidekker Signed-off-by: Alexandre Julliard --- dlls/webservices/reader.c | 28 ++++++++++++++++-- dlls/webservices/tests/reader.c | 47 +++++++++++++++++++++++++++++++ dlls/webservices/webservices.spec | 2 +- 3 files changed, 73 insertions(+), 4 deletions(-) diff --git a/dlls/webservices/reader.c b/dlls/webservices/reader.c index b8dfed4f34b..b326bd81904 100644 --- a/dlls/webservices/reader.c +++ b/dlls/webservices/reader.c @@ -432,6 +432,7 @@ struct reader ULONG nb_prefixes; ULONG nb_prefixes_allocated; WS_XML_READER_INPUT_TYPE input_type; + struct xmlbuf *input_buf; const unsigned char *input_data; ULONG input_size; ULONG prop_count; @@ -570,6 +571,7 @@ static HRESULT read_init_state( struct reader *reader ) destroy_nodes( reader->root ); reader->root = NULL; + reader->input_buf = NULL; clear_prefixes( reader->prefixes, reader->nb_prefixes ); reader->nb_prefixes = 1; if (!(node = alloc_node( WS_XML_NODE_TYPE_EOF ))) return E_OUTOFMEMORY; @@ -3823,9 +3825,10 @@ static WS_CHARSET detect_charset( const unsigned char *data, ULONG size, ULONG * return ret; } -static void set_input_buffer( struct reader *reader, const unsigned char *data, ULONG size ) +static void set_input_buffer( struct reader *reader, struct xmlbuf *buf, const unsigned char *data, ULONG size ) { reader->input_type = WS_XML_READER_INPUT_TYPE_BUFFER; + reader->input_buf = buf; reader->input_data = data; reader->input_size = size; @@ -3891,7 +3894,8 @@ HRESULT WINAPI WsSetInput( WS_XML_READER *handle, const WS_XML_READER_ENCODING * case WS_XML_READER_INPUT_TYPE_BUFFER: { WS_XML_READER_BUFFER_INPUT *buf = (WS_XML_READER_BUFFER_INPUT *)input; - set_input_buffer( reader, (const unsigned char *)buf->encodedData + offset, buf->encodedDataSize - offset ); + set_input_buffer( reader, NULL, (const unsigned char *)buf->encodedData + offset, + buf->encodedDataSize - offset ); break; } default: @@ -3937,7 +3941,7 @@ HRESULT WINAPI WsSetInputToBuffer( WS_XML_READER *handle, WS_XML_BUFFER *buffer, &charset, sizeof(charset) ); if (hr != S_OK) return hr; - set_input_buffer( reader, (const unsigned char *)xmlbuf->ptr + offset, xmlbuf->size - offset ); + set_input_buffer( reader, xmlbuf, (const unsigned char *)xmlbuf->ptr + offset, xmlbuf->size - offset ); if (!(node = alloc_node( WS_XML_NODE_TYPE_BOF ))) return E_OUTOFMEMORY; read_insert_bof( reader, node ); return S_OK; @@ -3957,3 +3961,21 @@ HRESULT WINAPI WsXmlStringEquals( const WS_XML_STRING *str1, const WS_XML_STRING if (!memcmp( str1->bytes, str2->bytes, str1->length )) return S_OK; return S_FALSE; } + +/************************************************************************** + * WsGetReaderPosition [webservices.@] + */ +HRESULT WINAPI WsGetReaderPosition( WS_XML_READER *handle, WS_XML_NODE_POSITION *pos, WS_ERROR *error ) +{ + struct reader *reader = (struct reader *)handle; + + TRACE( "%p %p %p\n", handle, pos, error ); + if (error) FIXME( "ignoring error parameter\n" ); + + if (!reader || !pos) return E_INVALIDARG; + if (!reader->input_buf) return WS_E_INVALID_OPERATION; + + pos->buffer = (WS_XML_BUFFER *)reader->input_buf; + pos->node = reader->current; + return S_OK; +} diff --git a/dlls/webservices/tests/reader.c b/dlls/webservices/tests/reader.c index 4997f7a01b2..a613fa20443 100644 --- a/dlls/webservices/tests/reader.c +++ b/dlls/webservices/tests/reader.c @@ -3449,6 +3449,52 @@ static void test_WsResetError(void) WsFreeError( error ); } +static void test_WsGetReaderPosition(void) +{ + WS_HEAP *heap; + WS_XML_READER *reader; + WS_XML_BUFFER *buffer; + WS_XML_NODE_POSITION pos; + HRESULT hr; + + hr = WsGetReaderPosition( NULL, NULL, NULL ); + ok( hr == E_INVALIDARG, "got %08x\n", hr ); + + hr = WsCreateHeap( 1 << 16, 0, NULL, 0, &heap, NULL ); + ok( hr == S_OK, "got %08x\n", hr ); + + hr = WsCreateReader( NULL, 0, &reader, NULL ) ; + ok( hr == S_OK, "got %08x\n", hr ); + + /* reader must be set to an XML buffer */ + hr = WsGetReaderPosition( reader, &pos, NULL ); + ok( hr == WS_E_INVALID_OPERATION, "got %08x\n", hr ); + + hr = set_input( reader, "", sizeof("") - 1 ); + ok( hr == S_OK, "got %08x\n", hr ); + + hr = WsGetReaderPosition( reader, &pos, NULL ); + ok( hr == WS_E_INVALID_OPERATION, "got %08x\n", hr ); + + hr = WsCreateXmlBuffer( heap, NULL, 0, &buffer, NULL ); + ok( hr == S_OK, "got %08x\n", hr ); + + hr = WsSetInputToBuffer( reader, buffer, NULL, 0, NULL ); + ok( hr == S_OK, "got %08x\n", hr ); + + hr = WsGetReaderPosition( reader, NULL, NULL ); + ok( hr == E_INVALIDARG, "got %08x\n", hr ); + + pos.buffer = pos.node = NULL; + hr = WsGetReaderPosition( reader, &pos, NULL ); + ok( hr == S_OK, "got %08x\n", hr ); + ok( pos.buffer != NULL, "buffer not set\n" ); + ok( pos.node != NULL, "node not set\n" ); + + WsFreeReader( reader ); + WsFreeHeap( heap ); +} + START_TEST(reader) { test_WsCreateError(); @@ -3481,4 +3527,5 @@ START_TEST(reader) test_WsReadElement(); test_WsReadValue(); test_WsResetError(); + test_WsGetReaderPosition(); } diff --git a/dlls/webservices/webservices.spec b/dlls/webservices/webservices.spec index 3a69302f1fa..814788f83c4 100644 --- a/dlls/webservices/webservices.spec +++ b/dlls/webservices/webservices.spec @@ -81,7 +81,7 @@ @ stub WsGetPolicyProperty @ stdcall WsGetPrefixFromNamespace(ptr ptr long ptr ptr) @ stdcall WsGetReaderNode(ptr ptr ptr) -@ stub WsGetReaderPosition +@ stdcall WsGetReaderPosition(ptr ptr ptr) @ stdcall WsGetReaderProperty(ptr long ptr long ptr) @ stub WsGetSecurityContextProperty @ stub WsGetSecurityTokenProperty