Commit d29c0e2b authored by Hans Leidekker's avatar Hans Leidekker Committed by Alexandre Julliard

webservices: Fix the empty text case for a couple of data types.

parent 5a0b3ff3
......@@ -3460,14 +3460,10 @@ static HRESULT str_to_guid( const unsigned char *str, ULONG len, GUID *ret )
static HRESULT str_to_string( const unsigned char *str, ULONG len, WS_HEAP *heap, WS_STRING *ret )
{
const unsigned char *p = str;
int len_utf16;
len_utf16 = MultiByteToWideChar( CP_UTF8, 0, (const char *)p, len, NULL, 0 );
int len_utf16 = MultiByteToWideChar( CP_UTF8, 0, (const char *)str, len, NULL, 0 );
if (!(ret->chars = ws_alloc( heap, len_utf16 * sizeof(WCHAR) ))) return WS_E_QUOTA_EXCEEDED;
MultiByteToWideChar( CP_UTF8, 0, (const char *)p, len, ret->chars, len_utf16 );
MultiByteToWideChar( CP_UTF8, 0, (const char *)str, len, ret->chars, len_utf16 );
ret->length = len_utf16;
return S_OK;
}
......@@ -3558,10 +3554,8 @@ static HRESULT str_to_bytes( const unsigned char *str, ULONG len, WS_HEAP *heap,
static HRESULT str_to_xml_string( const unsigned char *str, ULONG len, WS_HEAP *heap, WS_XML_STRING *ret )
{
const unsigned char *p = str;
if (!(ret->bytes = ws_alloc( heap, len ))) return WS_E_QUOTA_EXCEEDED;
memcpy( ret->bytes, p, len );
memcpy( ret->bytes, str, len );
ret->length = len;
ret->dictionary = NULL;
ret->id = 0;
......@@ -3826,18 +3820,13 @@ HRESULT WINAPI WsFileTimeToDateTime( const FILETIME *ft, WS_DATETIME *dt, WS_ERR
static HRESULT read_get_node_text( struct reader *reader, WS_XML_UTF8_TEXT **ret )
{
WS_XML_TEXT_NODE *text;
if (node_type( reader->current ) != WS_XML_NODE_TYPE_TEXT)
return WS_E_INVALID_FORMAT;
text = (WS_XML_TEXT_NODE *)&reader->current->hdr.node;
if (text->text->textType != WS_XML_TEXT_TYPE_UTF8)
WS_XML_TEXT_NODE *node = (WS_XML_TEXT_NODE *)&reader->current->hdr.node;
if (node->text->textType != WS_XML_TEXT_TYPE_UTF8)
{
FIXME( "text type %u not supported\n", text->text->textType );
FIXME( "text type %u not supported\n", node->text->textType );
return E_NOTIMPL;
}
*ret = (WS_XML_UTF8_TEXT *)text->text;
*ret = (WS_XML_UTF8_TEXT *)node->text;
return S_OK;
}
......@@ -3929,6 +3918,24 @@ HRESULT WINAPI WsFindAttribute( WS_XML_READER *handle, const WS_XML_STRING *loca
return hr;
}
static BOOL match_element( const struct node *node, const WS_XML_STRING *localname, const WS_XML_STRING *ns )
{
const WS_XML_ELEMENT_NODE *elem = (const WS_XML_ELEMENT_NODE *)node;
if (node_type( node ) != WS_XML_NODE_TYPE_ELEMENT) return FALSE;
return WsXmlStringEquals( localname, elem->localName, NULL ) == S_OK &&
WsXmlStringEquals( ns, elem->ns, NULL ) == S_OK;
}
static HRESULT read_next_node( struct reader *reader )
{
if (reader->current == reader->last) return read_node( reader );
if (move_to_child_node( &reader->current )) return S_OK;
if (move_to_next_node( &reader->current )) return S_OK;
if (!move_to_parent_node( &reader->current )) return WS_E_INVALID_FORMAT;
if (move_to_next_node( &reader->current )) return S_OK;
return WS_E_INVALID_FORMAT;
}
static HRESULT read_get_text( struct reader *reader, WS_TYPE_MAPPING mapping,
const WS_XML_STRING *localname, const WS_XML_STRING *ns,
WS_XML_UTF8_TEXT **ret, BOOL *found )
......@@ -3945,19 +3952,27 @@ static HRESULT read_get_text( struct reader *reader, WS_TYPE_MAPPING mapping,
case WS_ELEMENT_CONTENT_TYPE_MAPPING:
case WS_ANY_ELEMENT_TYPE_MAPPING:
{
HRESULT hr;
*found = TRUE;
if (localname)
{
const WS_XML_ELEMENT_NODE *elem = &reader->current->hdr;
if (WsXmlStringEquals( localname, elem->localName, NULL ) != S_OK ||
WsXmlStringEquals( ns, elem->ns, NULL ) != S_OK)
HRESULT hr;
if (!match_element( reader->current, localname, ns ))
{
*found = FALSE;
return S_OK;
}
if ((hr = read_startelement( reader )) != S_OK) return hr;
if ((hr = read_next_node( reader )) != S_OK) return hr;
if (node_type( reader->current ) != WS_XML_NODE_TYPE_TEXT)
{
if (!move_to_parent_element( &reader->current )) return WS_E_INVALID_FORMAT;
*found = FALSE;
return S_OK;
}
}
if (node_type( reader->current ) != WS_XML_NODE_TYPE_TEXT)
{
*found = FALSE;
return S_OK;
}
return read_get_node_text( reader, ret );
}
......@@ -4540,7 +4555,7 @@ static HRESULT read_type_wsz( struct reader *reader, WS_TYPE_MAPPING mapping,
switch (option)
{
case WS_READ_REQUIRED_POINTER:
if (!found) return WS_E_INVALID_FORMAT;
if (!found && !(str = ws_alloc_zero( heap, 1 ))) return WS_E_QUOTA_EXCEEDED;
/* fall through */
case WS_READ_OPTIONAL_POINTER:
......@@ -4794,18 +4809,20 @@ static HRESULT read_type_string( struct reader *reader, WS_TYPE_MAPPING mapping,
switch (option)
{
case WS_READ_REQUIRED_VALUE:
if (!found) return WS_E_INVALID_FORMAT;
/* fall through */
case WS_READ_NILLABLE_VALUE:
if (size != sizeof(val)) return E_INVALIDARG;
*(WS_STRING *)ret = val;
break;
case WS_READ_REQUIRED_POINTER:
if (!found) return WS_E_INVALID_FORMAT;
/* fall through */
{
WS_STRING *heap_val;
if (size != sizeof(heap_val)) return E_INVALIDARG;
if (!(heap_val = ws_alloc( heap, sizeof(*heap_val) ))) return WS_E_QUOTA_EXCEEDED;
*heap_val = val;
*(WS_STRING **)ret = heap_val;
break;
}
case WS_READ_OPTIONAL_POINTER:
case WS_READ_NILLABLE_POINTER:
{
......@@ -4846,18 +4863,20 @@ static HRESULT read_type_bytes( struct reader *reader, WS_TYPE_MAPPING mapping,
switch (option)
{
case WS_READ_REQUIRED_VALUE:
if (!found) return WS_E_INVALID_FORMAT;
/* fall through */
case WS_READ_NILLABLE_VALUE:
if (size != sizeof(val)) return E_INVALIDARG;
*(WS_BYTES *)ret = val;
break;
case WS_READ_REQUIRED_POINTER:
if (!found) return WS_E_INVALID_FORMAT;
/* fall through */
{
WS_BYTES *heap_val;
if (size != sizeof(heap_val)) return E_INVALIDARG;
if (!(heap_val = ws_alloc( heap, sizeof(*heap_val) ))) return WS_E_QUOTA_EXCEEDED;
*heap_val = val;
*(WS_BYTES **)ret = heap_val;
break;
}
case WS_READ_OPTIONAL_POINTER:
case WS_READ_NILLABLE_POINTER:
{
......@@ -4898,18 +4917,20 @@ static HRESULT read_type_xml_string( struct reader *reader, WS_TYPE_MAPPING mapp
switch (option)
{
case WS_READ_REQUIRED_VALUE:
if (!found) return WS_E_INVALID_FORMAT;
/* fall through */
case WS_READ_NILLABLE_VALUE:
if (size != sizeof(val)) return E_INVALIDARG;
*(WS_XML_STRING *)ret = val;
break;
case WS_READ_REQUIRED_POINTER:
if (!found) return WS_E_INVALID_FORMAT;
/* fall through */
{
WS_XML_STRING *heap_val;
if (size != sizeof(heap_val)) return E_INVALIDARG;
if (!(heap_val = ws_alloc( heap, sizeof(*heap_val) ))) return WS_E_QUOTA_EXCEEDED;
*heap_val = val;
*(WS_XML_STRING **)ret = heap_val;
break;
}
case WS_READ_OPTIONAL_POINTER:
case WS_READ_NILLABLE_POINTER:
{
......@@ -5004,16 +5025,6 @@ static BOOL is_empty_text_node( const struct node *node )
return TRUE;
}
static HRESULT read_next_node( struct reader *reader )
{
if (reader->current == reader->last) return read_node( reader );
if (move_to_child_node( &reader->current )) return S_OK;
if (move_to_next_node( &reader->current )) return S_OK;
if (!move_to_parent_node( &reader->current )) return WS_E_INVALID_FORMAT;
if (move_to_next_node( &reader->current )) return S_OK;
return WS_E_INVALID_FORMAT;
}
/* skips comment and empty text nodes */
static HRESULT read_type_next_node( struct reader *reader )
{
......@@ -5030,15 +5041,6 @@ static HRESULT read_type_next_node( struct reader *reader )
}
}
static BOOL match_current_element( struct reader *reader, const WS_XML_STRING *localname,
const WS_XML_STRING *ns )
{
const WS_XML_ELEMENT_NODE *elem = &reader->current->hdr;
if (node_type( reader->current ) != WS_XML_NODE_TYPE_ELEMENT) return FALSE;
return WsXmlStringEquals( localname, elem->localName, NULL ) == S_OK &&
WsXmlStringEquals( ns, elem->ns, NULL ) == S_OK;
}
static HRESULT read_type_next_element_node( struct reader *reader, const WS_XML_STRING *localname,
const WS_XML_STRING *ns )
{
......@@ -5053,13 +5055,13 @@ static HRESULT read_type_next_element_node( struct reader *reader, const WS_XML_
if ((hr = read_to_startelement( reader, &found )) != S_OK) return hr;
if (!found) return WS_E_INVALID_FORMAT;
}
if (match_current_element( reader, localname, ns )) return S_OK;
if (match_element( reader->current, localname, ns )) return S_OK;
node = reader->current;
attr = reader->current_attr;
if ((hr = read_type_next_node( reader )) != S_OK) return hr;
if (match_current_element( reader, localname, ns )) return S_OK;
if (match_element( reader->current, localname, ns )) return S_OK;
reader->current = node;
reader->current_attr = attr;
......
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