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