aboutsummaryrefslogtreecommitdiffstats
path: root/protocols/jabber/xmltree.c
diff options
context:
space:
mode:
Diffstat (limited to 'protocols/jabber/xmltree.c')
-rw-r--r--protocols/jabber/xmltree.c24
1 files changed, 20 insertions, 4 deletions
diff --git a/protocols/jabber/xmltree.c b/protocols/jabber/xmltree.c
index d4063476..af0c5832 100644
--- a/protocols/jabber/xmltree.c
+++ b/protocols/jabber/xmltree.c
@@ -527,9 +527,25 @@ void xt_add_attr( struct xt_node *node, char *key, char *value )
{
int i;
- for( i = 0; node->attr[i].key; i ++ );
- node->attr = g_renew( struct xt_attr, node->attr, i + 2 );
- node->attr[i].key = g_strdup( key );
+ /* Now actually it'd be nice if we can also change existing attributes
+ (which actually means this function doesn't have the right name).
+ So let's find out if we have this attribute already... */
+ for( i = 0; node->attr[i].key; i ++ )
+ if( strcmp( node->attr[i].key, key ) == 0 )
+ break;
+
+ if( node->attr[i].key == NULL )
+ {
+ /* If not, allocate space for a new attribute. */
+ node->attr = g_renew( struct xt_attr, node->attr, i + 2 );
+ node->attr[i].key = g_strdup( key );
+ node->attr[i+1].key = NULL;
+ }
+ else
+ {
+ /* Otherwise, free the old value before setting the new one. */
+ g_free( node->attr[i].value );
+ }
+
node->attr[i].value = g_strdup( value );
- node->attr[i+1].key = NULL;
}