Commit 49bc8b4c authored by Hans Leidekker's avatar Hans Leidekker Committed by Alexandre Julliard

webservices: Add a helper to determine node type.

parent e4a68fd5
...@@ -303,7 +303,7 @@ void free_attribute( WS_XML_ATTRIBUTE *attr ) ...@@ -303,7 +303,7 @@ void free_attribute( WS_XML_ATTRIBUTE *attr )
void free_node( struct node *node ) void free_node( struct node *node )
{ {
if (!node) return; if (!node) return;
switch (node->hdr.node.nodeType) switch (node_type( node ))
{ {
case WS_XML_NODE_TYPE_ELEMENT: case WS_XML_NODE_TYPE_ELEMENT:
{ {
...@@ -337,7 +337,7 @@ void free_node( struct node *node ) ...@@ -337,7 +337,7 @@ void free_node( struct node *node )
break; break;
default: default:
ERR( "unhandled type %u\n", node->hdr.node.nodeType ); ERR( "unhandled type %u\n", node_type( node ) );
break; break;
} }
heap_free( node ); heap_free( node );
...@@ -1117,12 +1117,12 @@ static struct node *read_find_parent( struct reader *reader, const WS_XML_STRING ...@@ -1117,12 +1117,12 @@ static struct node *read_find_parent( struct reader *reader, const WS_XML_STRING
for (parent = reader->current; parent; parent = parent->parent) for (parent = reader->current; parent; parent = parent->parent)
{ {
if (parent->hdr.node.nodeType == WS_XML_NODE_TYPE_BOF) if (node_type( parent ) == WS_XML_NODE_TYPE_BOF)
{ {
if (!localname) return parent; if (!localname) return parent;
return NULL; return NULL;
} }
else if (parent->hdr.node.nodeType == WS_XML_NODE_TYPE_ELEMENT) else if (node_type( parent ) == WS_XML_NODE_TYPE_ELEMENT)
{ {
if (!localname) return parent; if (!localname) return parent;
...@@ -1540,7 +1540,7 @@ static BOOL move_to_root_element( struct reader *reader ) ...@@ -1540,7 +1540,7 @@ static BOOL move_to_root_element( struct reader *reader )
if (!(ptr = list_head( &reader->root->children ))) return FALSE; if (!(ptr = list_head( &reader->root->children ))) return FALSE;
node = LIST_ENTRY( ptr, struct node, entry ); node = LIST_ENTRY( ptr, struct node, entry );
if (node->hdr.node.nodeType == WS_XML_NODE_TYPE_ELEMENT) if (node_type( node ) == WS_XML_NODE_TYPE_ELEMENT)
{ {
reader->current = node; reader->current = node;
return TRUE; return TRUE;
...@@ -1548,7 +1548,7 @@ static BOOL move_to_root_element( struct reader *reader ) ...@@ -1548,7 +1548,7 @@ static BOOL move_to_root_element( struct reader *reader )
while ((ptr = list_next( &reader->root->children, &node->entry ))) while ((ptr = list_next( &reader->root->children, &node->entry )))
{ {
struct node *next = LIST_ENTRY( ptr, struct node, entry ); struct node *next = LIST_ENTRY( ptr, struct node, entry );
if (next->hdr.node.nodeType == WS_XML_NODE_TYPE_ELEMENT) if (node_type( next ) == WS_XML_NODE_TYPE_ELEMENT)
{ {
reader->current = next; reader->current = next;
return TRUE; return TRUE;
...@@ -1566,7 +1566,7 @@ static BOOL move_to_next_element( struct reader *reader ) ...@@ -1566,7 +1566,7 @@ static BOOL move_to_next_element( struct reader *reader )
while ((ptr = list_next( &node->parent->children, &node->entry ))) while ((ptr = list_next( &node->parent->children, &node->entry )))
{ {
struct node *next = LIST_ENTRY( ptr, struct node, entry ); struct node *next = LIST_ENTRY( ptr, struct node, entry );
if (next->hdr.node.nodeType == WS_XML_NODE_TYPE_ELEMENT) if (node_type( next ) == WS_XML_NODE_TYPE_ELEMENT)
{ {
reader->current = next; reader->current = next;
return TRUE; return TRUE;
...@@ -1584,7 +1584,7 @@ static BOOL move_to_prev_element( struct reader *reader ) ...@@ -1584,7 +1584,7 @@ static BOOL move_to_prev_element( struct reader *reader )
while ((ptr = list_prev( &node->parent->children, &node->entry ))) while ((ptr = list_prev( &node->parent->children, &node->entry )))
{ {
struct node *prev = LIST_ENTRY( ptr, struct node, entry ); struct node *prev = LIST_ENTRY( ptr, struct node, entry );
if (prev->hdr.node.nodeType == WS_XML_NODE_TYPE_ELEMENT) if (node_type( prev ) == WS_XML_NODE_TYPE_ELEMENT)
{ {
reader->current = prev; reader->current = prev;
return TRUE; return TRUE;
...@@ -1601,7 +1601,7 @@ static BOOL move_to_child_element( struct reader *reader ) ...@@ -1601,7 +1601,7 @@ static BOOL move_to_child_element( struct reader *reader )
if (!(ptr = list_head( &reader->current->children ))) return FALSE; if (!(ptr = list_head( &reader->current->children ))) return FALSE;
node = LIST_ENTRY( ptr, struct node, entry ); node = LIST_ENTRY( ptr, struct node, entry );
if (node->hdr.node.nodeType == WS_XML_NODE_TYPE_ELEMENT) if (node_type( node ) == WS_XML_NODE_TYPE_ELEMENT)
{ {
reader->current = node; reader->current = node;
return TRUE; return TRUE;
...@@ -1609,7 +1609,7 @@ static BOOL move_to_child_element( struct reader *reader ) ...@@ -1609,7 +1609,7 @@ static BOOL move_to_child_element( struct reader *reader )
while ((ptr = list_next( &reader->current->children, &node->entry ))) while ((ptr = list_next( &reader->current->children, &node->entry )))
{ {
struct node *next = LIST_ENTRY( ptr, struct node, entry ); struct node *next = LIST_ENTRY( ptr, struct node, entry );
if (next->hdr.node.nodeType == WS_XML_NODE_TYPE_ELEMENT) if (node_type( next ) == WS_XML_NODE_TYPE_ELEMENT)
{ {
reader->current = next; reader->current = next;
return TRUE; return TRUE;
...@@ -1624,12 +1624,12 @@ static BOOL move_to_end_element( struct reader *reader ) ...@@ -1624,12 +1624,12 @@ static BOOL move_to_end_element( struct reader *reader )
struct list *ptr; struct list *ptr;
struct node *node = reader->current; struct node *node = reader->current;
if (node->hdr.node.nodeType != WS_XML_NODE_TYPE_ELEMENT) return FALSE; if (node_type( node ) != WS_XML_NODE_TYPE_ELEMENT) return FALSE;
if ((ptr = list_tail( &node->children ))) if ((ptr = list_tail( &node->children )))
{ {
struct node *tail = LIST_ENTRY( ptr, struct node, entry ); struct node *tail = LIST_ENTRY( ptr, struct node, entry );
if (tail->hdr.node.nodeType == WS_XML_NODE_TYPE_END_ELEMENT) if (node_type( tail ) == WS_XML_NODE_TYPE_END_ELEMENT)
{ {
reader->current = tail; reader->current = tail;
return TRUE; return TRUE;
...@@ -1642,8 +1642,8 @@ static BOOL move_to_parent_element( struct reader *reader ) ...@@ -1642,8 +1642,8 @@ static BOOL move_to_parent_element( struct reader *reader )
{ {
struct node *parent = reader->current->parent; struct node *parent = reader->current->parent;
if (parent && (parent->hdr.node.nodeType == WS_XML_NODE_TYPE_ELEMENT || if (parent && (node_type( parent ) == WS_XML_NODE_TYPE_ELEMENT ||
parent->hdr.node.nodeType == WS_XML_NODE_TYPE_BOF)) node_type( parent ) == WS_XML_NODE_TYPE_BOF))
{ {
reader->current = parent; reader->current = parent;
return TRUE; return TRUE;
...@@ -1905,7 +1905,7 @@ static HRESULT read_get_node_text( struct reader *reader, WS_XML_UTF8_TEXT **ret ...@@ -1905,7 +1905,7 @@ static HRESULT read_get_node_text( struct reader *reader, WS_XML_UTF8_TEXT **ret
{ {
WS_XML_TEXT_NODE *text; WS_XML_TEXT_NODE *text;
if (reader->current->hdr.node.nodeType != WS_XML_NODE_TYPE_TEXT) if (node_type( reader->current ) != WS_XML_NODE_TYPE_TEXT)
return WS_E_INVALID_FORMAT; return WS_E_INVALID_FORMAT;
text = (WS_XML_TEXT_NODE *)&reader->current->hdr.node; text = (WS_XML_TEXT_NODE *)&reader->current->hdr.node;
...@@ -1923,7 +1923,7 @@ static HRESULT read_get_attribute_text( struct reader *reader, ULONG index, WS_X ...@@ -1923,7 +1923,7 @@ static HRESULT read_get_attribute_text( struct reader *reader, ULONG index, WS_X
WS_XML_ELEMENT_NODE *elem = &reader->current->hdr; WS_XML_ELEMENT_NODE *elem = &reader->current->hdr;
WS_XML_ATTRIBUTE *attr; WS_XML_ATTRIBUTE *attr;
if (reader->current->hdr.node.nodeType != WS_XML_NODE_TYPE_ELEMENT) if (node_type( reader->current ) != WS_XML_NODE_TYPE_ELEMENT)
return WS_E_INVALID_FORMAT; return WS_E_INVALID_FORMAT;
attr = elem->attributes[index]; attr = elem->attributes[index];
...@@ -1977,7 +1977,7 @@ HRESULT WINAPI WsFindAttribute( WS_XML_READER *handle, const WS_XML_STRING *loca ...@@ -1977,7 +1977,7 @@ HRESULT WINAPI WsFindAttribute( WS_XML_READER *handle, const WS_XML_STRING *loca
if (!reader || !localname || !ns || !index) return E_INVALIDARG; if (!reader || !localname || !ns || !index) return E_INVALIDARG;
if (reader->current->hdr.node.nodeType != WS_XML_NODE_TYPE_ELEMENT) if (node_type( reader->current ) != WS_XML_NODE_TYPE_ELEMENT)
return WS_E_INVALID_OPERATION; return WS_E_INVALID_OPERATION;
if (!find_attribute( reader, localname, ns, index )) if (!find_attribute( reader, localname, ns, index ))
...@@ -2689,7 +2689,7 @@ static BOOL is_empty_text_node( const struct node *node ) ...@@ -2689,7 +2689,7 @@ static BOOL is_empty_text_node( const struct node *node )
const WS_XML_UTF8_TEXT *utf8; const WS_XML_UTF8_TEXT *utf8;
ULONG i; ULONG i;
if (node->hdr.node.nodeType != WS_XML_NODE_TYPE_TEXT) return FALSE; if (node_type( node ) != WS_XML_NODE_TYPE_TEXT) return FALSE;
if (text->text->textType != WS_XML_TEXT_TYPE_UTF8) if (text->text->textType != WS_XML_TEXT_TYPE_UTF8)
{ {
ERR( "unhandled text type %u\n", text->text->textType ); ERR( "unhandled text type %u\n", text->text->textType );
...@@ -2719,7 +2719,7 @@ static HRESULT read_type_next_node( struct reader *reader, const WS_XML_STRING * ...@@ -2719,7 +2719,7 @@ static HRESULT read_type_next_node( struct reader *reader, const WS_XML_STRING *
for (;;) for (;;)
{ {
if ((hr = read_node( reader ) != S_OK)) return hr; if ((hr = read_node( reader ) != S_OK)) return hr;
type = reader->current->hdr.node.nodeType; type = node_type( reader->current );
if (type == WS_XML_NODE_TYPE_COMMENT || if (type == WS_XML_NODE_TYPE_COMMENT ||
(type == WS_XML_NODE_TYPE_TEXT && is_empty_text_node( reader->current ))) continue; (type == WS_XML_NODE_TYPE_TEXT && is_empty_text_node( reader->current ))) continue;
break; break;
......
...@@ -46,6 +46,11 @@ struct node *alloc_node( WS_XML_NODE_TYPE ) DECLSPEC_HIDDEN; ...@@ -46,6 +46,11 @@ struct node *alloc_node( WS_XML_NODE_TYPE ) DECLSPEC_HIDDEN;
void free_node( struct node * ) DECLSPEC_HIDDEN; void free_node( struct node * ) DECLSPEC_HIDDEN;
void destroy_nodes( struct node * ) DECLSPEC_HIDDEN; void destroy_nodes( struct node * ) DECLSPEC_HIDDEN;
static inline WS_XML_NODE_TYPE node_type( const struct node *node )
{
return node->hdr.node.nodeType;
}
static inline void *heap_alloc( SIZE_T size ) static inline void *heap_alloc( SIZE_T size )
{ {
return HeapAlloc( GetProcessHeap(), 0, size ); return HeapAlloc( GetProcessHeap(), 0, size );
......
...@@ -601,8 +601,8 @@ static struct node *write_find_parent_element( struct writer *writer ) ...@@ -601,8 +601,8 @@ static struct node *write_find_parent_element( struct writer *writer )
{ {
struct node *node = writer->current; struct node *node = writer->current;
if (node->hdr.node.nodeType == WS_XML_NODE_TYPE_ELEMENT) return node; if (node_type( node ) == WS_XML_NODE_TYPE_ELEMENT) return node;
if (node->parent->hdr.node.nodeType == WS_XML_NODE_TYPE_ELEMENT) return node->parent; if (node_type( node->parent ) == WS_XML_NODE_TYPE_ELEMENT) return node->parent;
return NULL; return NULL;
} }
...@@ -894,15 +894,15 @@ static HRESULT write_add_element_node( struct writer *writer, const WS_XML_STRIN ...@@ -894,15 +894,15 @@ static HRESULT write_add_element_node( struct writer *writer, const WS_XML_STRIN
const WS_XML_STRING *localname, const WS_XML_STRING *ns ) const WS_XML_STRING *localname, const WS_XML_STRING *ns )
{ {
struct node *node; struct node *node;
WS_XML_ELEMENT_NODE *elem, *current = &writer->current->hdr; WS_XML_ELEMENT_NODE *elem;
HRESULT hr; HRESULT hr;
/* flush current start element if necessary */ /* flush current start element if necessary */
if (writer->state == WRITER_STATE_STARTELEMENT && ((hr = write_endstartelement( writer )) != S_OK)) if (writer->state == WRITER_STATE_STARTELEMENT && ((hr = write_endstartelement( writer )) != S_OK))
return hr; return hr;
if (!prefix && current->node.nodeType == WS_XML_NODE_TYPE_ELEMENT) if (!prefix && node_type( writer->current ) == WS_XML_NODE_TYPE_ELEMENT)
prefix = current->prefix; prefix = writer->current->hdr.prefix;
if (!(node = alloc_node( WS_XML_NODE_TYPE_ELEMENT ))) return E_OUTOFMEMORY; if (!(node = alloc_node( WS_XML_NODE_TYPE_ELEMENT ))) return E_OUTOFMEMORY;
elem = &node->hdr; elem = &node->hdr;
......
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