Changeset 022df46


Ignore:
Timestamp:
2006-09-26T13:30:54Z (18 years ago)
Author:
Wilmer van der Gaast <wilmer@…>
Branches:
master
Children:
6baca2a
Parents:
8e6c732
Message:

Added xt_dup().

Location:
protocols/jabber
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • protocols/jabber/xmltree.c

    r8e6c732 r022df46  
    351351}
    352352
     353struct xt_node *xt_dup( struct xt_node *node )
     354{
     355        struct xt_node *dup = g_new0( struct xt_node, 1 );
     356        struct xt_node *c, *dc = NULL;
     357        int i;
     358       
     359        /* Let's NOT copy the parent element here BTW! Only do it for children. */
     360       
     361        dup->name = g_strdup( node->name );
     362        dup->flags = node->flags;
     363        if( node->text )
     364        {
     365                dup->text = g_memdup( node->text, node->text_len + 1 );
     366                dup->text_len = node->text_len;
     367        }
     368       
     369        /* Count the number of attributes and allocate the new array. */
     370        for( i = 0; node->attr[i].key; i ++ );
     371        dup->attr = g_new0( struct xt_attr, i + 1 );
     372       
     373        /* Copy them all! */
     374        for( i --; i >= 0; i -- )
     375        {
     376                dup->attr[i].key = g_strdup( node->attr[i].key );
     377                dup->attr[i].value = g_strdup( node->attr[i].value );
     378        }
     379       
     380        /* This nice mysterious loop takes care of the children. */
     381        for( c = node->children; c; c = c->next )
     382        {
     383                if( dc == NULL )
     384                        dc = dup->children = xt_dup( c );
     385                else
     386                        dc = ( dc->next = xt_dup( c ) );
     387               
     388                dc->parent = dup;
     389        }
     390       
     391        return dup;
     392}
     393
    353394/* Frees a node. This doesn't clean up references to itself from parents! */
    354395void xt_free_node( struct xt_node *node )
  • protocols/jabber/xmltree.h

    r8e6c732 r022df46  
    8484char *xt_to_string( struct xt_node *node );
    8585void xt_print( struct xt_node *node );
     86struct xt_node *xt_dup( struct xt_node *node );
    8687void xt_free_node( struct xt_node *node );
    8788void xt_free( struct xt_parser *xt );
Note: See TracChangeset for help on using the changeset viewer.