changeset 10424:108151be77a3

[gaim-migrate @ 11676] Those 2 helper functions in xmlnode made things less readable... Lesson #456: Helper functions, while possible saving time, can hurt you in the long run when they steal your wallet. committer: Tailor Script <tailor@pidgin.im>
author Mark Doliner <mark@kingant.net>
date Sun, 26 Dec 2004 18:58:36 +0000
parents 3232e1a33899
children 9903182f2aac
files src/account.c src/savedstatuses.c src/xmlnode.c src/xmlnode.h
diffstat 4 files changed, 33 insertions(+), 101 deletions(-) [+]
line wrap: on
line diff
--- a/src/account.c	Sun Dec 26 18:38:22 2004 +0000
+++ b/src/account.c	Sun Dec 26 18:58:36 2004 +0000
@@ -1365,7 +1365,7 @@
 	setting = (GaimAccountSetting *)value;
 	node    = (xmlnode *)user_data;
 
-	child = xmlnode_new("setting");
+	child = xmlnode_new_child(node, "setting");
 	xmlnode_set_attrib(child, "name", name);
 
 	if (setting->type == GAIM_PREF_INT) {
@@ -1382,8 +1382,6 @@
 		snprintf(buf, sizeof(buf), "%d", setting->value.bool);
 		xmlnode_insert_data(child, buf, -1);
 	}
-
-	xmlnode_insert_child(node, child);
 }
 
 static void
@@ -1397,11 +1395,9 @@
 	table = (GHashTable *)value;
 	node  = (xmlnode *)user_data;
 
-	child = xmlnode_new("settings");
+	child = xmlnode_new_child(node, "settings");
 	xmlnode_set_attrib(child, "ui", ui);
 	g_hash_table_foreach(table, setting_to_xmlnode, child);
-
-	xmlnode_insert_child(node, child);
 }
 
 static xmlnode *
@@ -1417,7 +1413,8 @@
 
 	node = xmlnode_new("proxy");
 
-	child = xmlnode_new_child_with_data(node, "type",
+	child = xmlnode_new_child(node, "type");
+	xmlnode_insert_data(child,
 			(proxy_type == GAIM_PROXY_USE_GLOBAL ? "global" :
 			 proxy_type == GAIM_PROXY_NONE       ? "none"   :
 			 proxy_type == GAIM_PROXY_HTTP       ? "http"   :
@@ -1430,19 +1427,29 @@
 		proxy_type != GAIM_PROXY_USE_ENVVAR)
 	{
 		if ((value = gaim_proxy_info_get_host(proxy_info)) != NULL)
-			child = xmlnode_new_child_with_data(node, "host", value, -1);
+		{
+			child = xmlnode_new_child(node, "host");
+			xmlnode_insert_data(child, value, -1);
+		}
 
 		if ((int_value = gaim_proxy_info_get_port(proxy_info)) != 0)
 		{
 			snprintf(buf, sizeof(buf), "%d", int_value);
-			child = xmlnode_new_child_with_data(node, "port", buf, -1);
+			child = xmlnode_new_child(node, "port");
+			xmlnode_insert_data(child, buf, -1);
 		}
 
 		if ((value = gaim_proxy_info_get_username(proxy_info)) != NULL)
-			child = xmlnode_new_child_with_data(node, "username", value, -1);
+		{
+			child = xmlnode_new_child(node, "username");
+			xmlnode_insert_data(child, value, -1);
+		}
 
 		if ((value = gaim_proxy_info_get_password(proxy_info)) != NULL)
-			child = xmlnode_new_child_with_data(node, "password", value, -1);
+		{
+			child = xmlnode_new_child(node, "password");
+			xmlnode_insert_data(child, value, -1);
+		}
 	}
 
 	return node;
@@ -1457,47 +1464,40 @@
 
 	node = xmlnode_new("account");
 
-	child = xmlnode_new("protocol");
+	child = xmlnode_new_child(node, "protocol");
 	xmlnode_insert_data(child, gaim_account_get_protocol_id(account), -1);
-	xmlnode_insert_child(node, child);
 
-	child = xmlnode_new("name");
+	child = xmlnode_new_child(node, "name");
 	xmlnode_insert_data(child, gaim_account_get_username(account), -1);
-	xmlnode_insert_child(node, child);
 
 	if (gaim_account_get_remember_password(account) &&
 		((tmp = gaim_account_get_password(account)) != NULL))
 	{
-		child = xmlnode_new("password");
+		child = xmlnode_new_child(node, "password");
 		xmlnode_insert_data(child, tmp, -1);
-		xmlnode_insert_child(node, child);
 	}
 
 	if ((tmp = gaim_account_get_alias(account)) != NULL)
 	{
-		child = xmlnode_new("alias");
+		child = xmlnode_new_child(node, "alias");
 		xmlnode_insert_data(child, tmp, -1);
-		xmlnode_insert_child(node, child);
 	}
 
 	if ((tmp = gaim_account_get_user_info(account)) != NULL)
 	{
 		/* TODO: Do we need to call gaim_str_strip_cr(tmp) here? */
-		child = xmlnode_new("userinfo");
+		child = xmlnode_new_child(node, "userinfo");
 		xmlnode_insert_data(child, tmp, -1);
-		xmlnode_insert_child(node, child);
 	}
 
 	if ((tmp = gaim_account_get_buddy_icon(account)) != NULL)
 	{
-		child = xmlnode_new("buddyicon");
+		child = xmlnode_new_child(node, "buddyicon");
 		xmlnode_insert_data(child, tmp, -1);
-		xmlnode_insert_child(node, child);
 	}
 
-	child = xmlnode_new("settings");
+	child = xmlnode_new_child(node, "settings");
 	g_hash_table_foreach(account->settings, setting_to_xmlnode, child);
-	xmlnode_insert_child(node, child);
 
 	g_hash_table_foreach(account->ui_settings, ui_setting_to_xmlnode, node);
 
--- a/src/savedstatuses.c	Sun Dec 26 18:38:22 2004 +0000
+++ b/src/savedstatuses.c	Sun Dec 26 18:58:36 2004 +0000
@@ -111,22 +111,17 @@
 
 	node = xmlnode_new("substatus");
 
-	child = xmlnode_new("account");
-	xmlnode_set_attrib(node, "protocol",
-					   gaim_account_get_protocol_id(substatus->account));
-	xmlnode_insert_data(child,
-						gaim_account_get_username(substatus->account), -1);
-	xmlnode_insert_child(node, child);
+	child = xmlnode_new_child(node, "account");
+	xmlnode_set_attrib(child, "protocol", gaim_account_get_protocol_id(substatus->account));
+	xmlnode_insert_data(child, gaim_account_get_username(substatus->account), -1);
 
-	child = xmlnode_new("state");
+	child = xmlnode_new_child(node, "state");
 	xmlnode_insert_data(child, gaim_status_type_get_id(substatus->type), -1);
-	xmlnode_insert_child(node, child);
 
 	if (substatus->message != NULL)
 	{
-		child = xmlnode_new("message");
+		child = xmlnode_new_child(node, "message");
 		xmlnode_insert_data(child, substatus->message, -1);
-		xmlnode_insert_child(node, child);
 	}
 
 	return node;
@@ -141,13 +136,11 @@
 	node = xmlnode_new("status");
 	xmlnode_set_attrib(node, "name", status->title);
 
-	child = xmlnode_new("state");
-	xmlnode_insert_data(child, strdup(gaim_primitive_get_id_from_type(status->type)), -1);
-	xmlnode_insert_child(node, child);
+	child = xmlnode_new_child(node, "state");
+	xmlnode_insert_data(child, gaim_primitive_get_id_from_type(status->type), -1);
 
-	child = xmlnode_new("message");
+	child = xmlnode_new_child(node, "message");
 	xmlnode_insert_data(child, status->message, -1);
-	xmlnode_insert_child(node, child);
 
 	for (cur = status->substatuses; cur != NULL; cur = cur->next)
 	{
--- a/src/xmlnode.c	Sun Dec 26 18:38:22 2004 +0000
+++ b/src/xmlnode.c	Sun Dec 26 18:58:36 2004 +0000
@@ -54,21 +54,6 @@
 	return new_node(name, XMLNODE_TYPE_TAG);
 }
 
-xmlnode*
-xmlnode_new_with_data(const char *name, const char *data, size_t size)
-{
-	xmlnode *node;
-
-	g_return_val_if_fail(name != NULL, NULL);
-	g_return_val_if_fail(data != NULL, NULL);
-	g_return_val_if_fail(size != 0, NULL);
-
-	node = new_node(name, XMLNODE_TYPE_TAG);
-	xmlnode_insert_data(node, data, size);
-
-	return node;
-}
-
 xmlnode *
 xmlnode_new_child(xmlnode *parent, const char *name)
 {
@@ -84,25 +69,6 @@
 	return node;
 }
 
-xmlnode *
-xmlnode_new_child_with_data(xmlnode *parent, const char *name,
-							const char *data, size_t size)
-{
-	xmlnode *node;
-
-	g_return_val_if_fail(parent != NULL, NULL);
-	g_return_val_if_fail(name != NULL, NULL);
-	g_return_val_if_fail(data != NULL, NULL);
-	g_return_val_if_fail(size != 0, NULL);
-
-	node = new_node(name, XMLNODE_TYPE_TAG);
-	xmlnode_insert_data(node, data, size);
-
-	xmlnode_insert_child(parent, node);
-
-	return node;
-}
-
 void
 xmlnode_insert_child(xmlnode *parent, xmlnode *child)
 {
--- a/src/xmlnode.h	Sun Dec 26 18:38:22 2004 +0000
+++ b/src/xmlnode.h	Sun Dec 26 18:58:36 2004 +0000
@@ -59,19 +59,6 @@
 xmlnode *xmlnode_new(const char *name);
 
 /**
- * Creates a new xmlnode and inserts data into it.
- *
- * @param name The name of the node.
- * @param data The data to insert.
- * @param size The size of the data to insert.  If data is
- *             null-terminated you can pass in -1.
- *
- * @return The new node.
- */
-xmlnode *xmlnode_new_with_data(const char *name,
-							   const char *data, size_t size);
-
-/**
  * Creates a new xmlnode child.
  *
  * @param parent The parent node.
@@ -82,20 +69,6 @@
 xmlnode *xmlnode_new_child(xmlnode *parent, const char *name);
 
 /**
- * Creates a new xmlnode child and inserts data into it.
- *
- * @param parent The parent node.
- * @param name   The name of the child node.
- * @param data   The data to insert.
- * @param size   The size of the data to insert.  If data is
- *               null-terminated you can pass in -1.
- *
- * @return The new child node.
- */
-xmlnode *xmlnode_new_child_with_data(xmlnode *parent, const char *name,
-									 const char *data, size_t size);
-
-/**
  * Inserts a node into a node as a child.
  *
  * @param parent The parent node to insert child into.