Ignore:
Timestamp:
2006-10-05T22:55:54Z (18 years ago)
Author:
Wilmer van der Gaast <wilmer@…>
Branches:
master
Children:
090f1cb
Parents:
cc2cb2d
Message:

Added max. recursion depth arguments to xt_handle()/_cleanup() to make sure
commands that still have to be handled don't get (partially) cleaned up
already.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • protocols/jabber/xmltree.c

    rcc2cb2d r101d84f  
    152152/* Find completed nodes and see if a handler has to be called. Passing
    153153   a node isn't necessary if you want to start at the root, just pass
    154    NULL. This second argument is needed for recursive calls. FIXME: Retval? */
    155 int xt_handle( struct xt_parser *xt, struct xt_node *node )
     154   NULL. This second argument is needed for recursive calls. */
     155int xt_handle( struct xt_parser *xt, struct xt_node *node, int depth )
    156156{
    157157        struct xt_node *c;
     
    159159        int i;
    160160       
    161         /* Let's just hope xt->root isn't NULL! */
     161        /* Just in case someone likes infinite loops... */
     162        if( xt->root == NULL )
     163                return 0;
     164       
    162165        if( node == NULL )
    163                 return xt_handle( xt, xt->root );
    164        
    165         for( c = node->children; c; c = c->next )
    166                 if( !xt_handle( xt, c ) )
    167                         return 0;
     166                return xt_handle( xt, xt->root, depth );
     167       
     168        if( depth != 0 )
     169                for( c = node->children; c; c = c->next )
     170                        if( !xt_handle( xt, c, depth > 0 ? depth - 1 : depth ) )
     171                                return 0;
    168172       
    169173        if( node->flags & XT_COMPLETE && !( node->flags & XT_SEEN ) )
     
    202206   streams because there's no reason to keep a complete packet history
    203207   in memory. */
    204 void xt_cleanup( struct xt_parser *xt, struct xt_node *node )
     208void xt_cleanup( struct xt_parser *xt, struct xt_node *node, int depth )
    205209{
    206210        struct xt_node *c, *prev;
     
    210214       
    211215        if( node == NULL )
    212                 return xt_cleanup( xt, xt->root );
     216                return xt_cleanup( xt, xt->root, depth );
    213217       
    214218        if( node->flags & XT_SEEN && node == xt->root )
     
    246250                        /* This node can't be cleaned up yet, but maybe a
    247251                           subnode can. */
    248                         xt_cleanup( xt, c );
     252                        if( depth != 0 )
     253                                xt_cleanup( xt, c, depth > 0 ? depth - 1 : depth );
    249254                }
    250255        }
Note: See TracChangeset for help on using the changeset viewer.