webservices: Fix node insertion in the reader when the current node is an end element.

Signed-off-by: Hans Leidekker <hans@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Hans Leidekker 2016-10-12 15:30:24 +02:00 committed by Alexandre Julliard
parent ad57c7c72a
commit 829b225546
3 changed files with 29 additions and 18 deletions

View File

@ -1400,16 +1400,15 @@ error:
return hr;
}
static inline BOOL is_valid_parent( const struct node *node )
static struct node *find_parent( struct reader *reader )
{
if (!node) return FALSE;
return node_type( node ) == WS_XML_NODE_TYPE_ELEMENT || node_type( node ) == WS_XML_NODE_TYPE_BOF;
if (node_type( reader->current ) == WS_XML_NODE_TYPE_END_ELEMENT)
{
if (is_valid_parent( reader->current->parent->parent )) return reader->current->parent->parent;
return NULL;
}
struct node *find_parent( struct node *node )
{
if (is_valid_parent( node )) return node;
if (is_valid_parent( node->parent )) return node->parent;
else if (is_valid_parent( reader->current )) return reader->current;
else if (is_valid_parent( reader->current->parent )) return reader->current->parent;
return NULL;
}
@ -1468,7 +1467,7 @@ static HRESULT read_element( struct reader *reader )
}
if (!len) goto error;
if (!(parent = find_parent( reader->current ))) goto error;
if (!(parent = find_parent( reader ))) goto error;
hr = E_OUTOFMEMORY;
if (!(node = alloc_node( WS_XML_NODE_TYPE_ELEMENT ))) goto error;
@ -1522,7 +1521,7 @@ static HRESULT read_text( struct reader *reader )
len += skip;
}
if (!(parent = find_parent( reader->current ))) return WS_E_INVALID_FORMAT;
if (!(parent = find_parent( reader ))) return WS_E_INVALID_FORMAT;
if (!(node = alloc_node( WS_XML_NODE_TYPE_TEXT ))) return E_OUTOFMEMORY;
text = (WS_XML_TEXT_NODE *)node;
@ -1693,7 +1692,7 @@ static HRESULT read_comment( struct reader *reader )
len += skip;
}
if (!(parent = find_parent( reader->current ))) return WS_E_INVALID_FORMAT;
if (!(parent = find_parent( reader ))) return WS_E_INVALID_FORMAT;
if (!(node = alloc_node( WS_XML_NODE_TYPE_COMMENT ))) return E_OUTOFMEMORY;
comment = (WS_XML_COMMENT_NODE *)node;
@ -1717,7 +1716,7 @@ static HRESULT read_startcdata( struct reader *reader )
if (read_cmp( reader, "<![CDATA[", 9 )) return WS_E_INVALID_FORMAT;
read_skip( reader, 9 );
if (!(parent = find_parent( reader->current ))) return WS_E_INVALID_FORMAT;
if (!(parent = find_parent( reader ))) return WS_E_INVALID_FORMAT;
if (!(node = alloc_node( WS_XML_NODE_TYPE_CDATA ))) return E_OUTOFMEMORY;
if (!(endnode = alloc_node( WS_XML_NODE_TYPE_END_CDATA )))

View File

@ -52,7 +52,6 @@ struct node
struct node *alloc_node( WS_XML_NODE_TYPE ) DECLSPEC_HIDDEN;
void free_node( struct node * ) DECLSPEC_HIDDEN;
void destroy_nodes( struct node * ) DECLSPEC_HIDDEN;
struct node *find_parent( struct node * ) DECLSPEC_HIDDEN;
HRESULT copy_node( WS_XML_READER *, struct node ** ) DECLSPEC_HIDDEN;
static inline WS_XML_NODE_TYPE node_type( const struct node *node )
@ -125,6 +124,12 @@ static inline BOOL is_nil_value( const char *value, ULONG size )
return TRUE;
}
static inline BOOL is_valid_parent( const struct node *node )
{
if (!node) return FALSE;
return (node_type( node ) == WS_XML_NODE_TYPE_ELEMENT || node_type( node ) == WS_XML_NODE_TYPE_BOF);
}
static inline void *heap_alloc( SIZE_T size )
{
return HeapAlloc( GetProcessHeap(), 0, size );

View File

@ -130,6 +130,13 @@ static void write_insert_node( struct writer *writer, struct node *parent, struc
writer->current = node;
}
static struct node *find_parent( struct writer *writer )
{
if (is_valid_parent( writer->current )) return writer->current;
if (is_valid_parent( writer->current->parent )) return writer->current->parent;
return NULL;
}
static HRESULT write_init_state( struct writer *writer )
{
struct node *node;
@ -890,7 +897,7 @@ static HRESULT write_flush( struct writer *writer )
static HRESULT write_add_cdata_node( struct writer *writer )
{
struct node *node, *parent;
if (!(parent = find_parent( writer->current ))) return WS_E_INVALID_FORMAT;
if (!(parent = find_parent( writer ))) return WS_E_INVALID_FORMAT;
if (!(node = alloc_node( WS_XML_NODE_TYPE_CDATA ))) return E_OUTOFMEMORY;
write_insert_node( writer, parent, node );
return S_OK;
@ -977,7 +984,7 @@ static HRESULT write_add_element_node( struct writer *writer, const WS_XML_STRIN
struct node *node, *parent;
WS_XML_ELEMENT_NODE *elem;
if (!(parent = find_parent( writer->current ))) return WS_E_INVALID_FORMAT;
if (!(parent = find_parent( writer ))) return WS_E_INVALID_FORMAT;
if (!prefix && node_type( parent ) == WS_XML_NODE_TYPE_ELEMENT)
{
@ -2563,7 +2570,7 @@ static HRESULT write_add_comment_node( struct writer *writer, const WS_XML_STRIN
struct node *node, *parent;
WS_XML_COMMENT_NODE *comment;
if (!(parent = find_parent( writer->current ))) return WS_E_INVALID_FORMAT;
if (!(parent = find_parent( writer ))) return WS_E_INVALID_FORMAT;
if (!(node = alloc_node( WS_XML_NODE_TYPE_COMMENT ))) return E_OUTOFMEMORY;
comment = (WS_XML_COMMENT_NODE *)node;
@ -2774,7 +2781,7 @@ HRESULT WINAPI WsCopyNode( WS_XML_WRITER *handle, WS_XML_READER *reader, WS_ERRO
if (error) FIXME( "ignoring error parameter\n" );
if (!writer) return E_INVALIDARG;
if (!(parent = find_parent( writer->current ))) return WS_E_INVALID_FORMAT;
if (!(parent = find_parent( writer ))) return WS_E_INVALID_FORMAT;
if ((hr = copy_node( reader, &node )) != S_OK) return hr;
write_insert_node( writer, parent, node );