changeset 30197:8cd8c26ea2f9

jabber: Add a bunch of g_return_if_fail checks to the BoB code (Entirely untested, but I asked Marcus to double-check them)
author Paul Aurich <paul@darkrain42.org>
date Thu, 17 Jun 2010 01:26:02 +0000
parents d78a3f06b7a0
children 0c41b5c08cdc
files libpurple/protocols/jabber/data.c
diffstat 1 files changed, 52 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/libpurple/protocols/jabber/data.c	Tue Jun 15 22:42:49 2010 +0000
+++ b/libpurple/protocols/jabber/data.c	Thu Jun 17 01:26:02 2010 +0000
@@ -41,10 +41,17 @@
 jabber_data_create_from_data(gconstpointer rawdata, gsize size, const char *type,
 	gboolean ephemeral, JabberStream *js)
 {
-	JabberData *data = g_new0(JabberData, 1);
-	gchar *checksum = jabber_calculate_data_hash(rawdata, size, "sha1");
+	JabberData *data;
+	gchar *checksum;
 	gchar cid[256];
 
+	g_return_val_if_fail(rawdata != NULL, NULL);
+	g_return_val_if_fail(size > 0, NULL);
+	g_return_val_if_fail(type != NULL, NULL);
+
+	data = g_new0(JabberData, 1);
+	checksum = jabber_calculate_data_hash(rawdata, size, "sha1");
+
 	g_snprintf(cid, sizeof(cid), "sha1+%s@bob.xmpp.org", checksum);
 	g_free(checksum);
 
@@ -62,6 +69,7 @@
 jabber_data_delete(gpointer cbdata)
 {
 	JabberData *data = cbdata;
+
 	g_free(data->cid);
 	g_free(data->type);
 	g_free(data->data);
@@ -76,6 +84,8 @@
 	gchar *raw_data = NULL;
 	const gchar *cid, *type;
 
+	g_return_val_if_fail(tag != NULL, NULL);
+
 	/* check if this is a "data" tag */
 	if (strcmp(tag->name, "data") != 0) {
 		purple_debug_error("jabber", "Invalid data element\n");
@@ -117,12 +127,16 @@
 void
 jabber_data_destroy(JabberData *data)
 {
+	g_return_if_fail(data != NULL);
+
 	jabber_data_delete(data);
 }
 
 const char *
 jabber_data_get_cid(const JabberData *data)
 {
+	g_return_val_if_fail(data != NULL, NULL);
+
 	return data->cid;
 }
 
@@ -130,26 +144,37 @@
 const char *
 jabber_data_get_type(const JabberData *data)
 {
+	g_return_val_if_fail(data != NULL, NULL);
+
 	return data->type;
 }
 
 gsize
 jabber_data_get_size(const JabberData *data)
 {
+	g_return_val_if_fail(data != NULL, 0);
+
 	return data->size;
 }
 
 gpointer
 jabber_data_get_data(const JabberData *data)
 {
+	g_return_val_if_fail(data != NULL, NULL);
+
 	return data->data;
 }
 
 xmlnode *
 jabber_data_get_xml_definition(const JabberData *data)
 {
-	xmlnode *tag = xmlnode_new("data");
-	char *base64data = purple_base64_encode(data->data, data->size);
+	xmlnode *tag;
+	char *base64data;
+
+	g_return_val_if_fail(data != NULL, NULL);
+
+	tag = xmlnode_new("data");
+	base64data = purple_base64_encode(data->data, data->size);
 
 	xmlnode_set_namespace(tag, NS_BOB);
 	xmlnode_set_attrib(tag, "cid", data->cid);
@@ -165,9 +190,13 @@
 xmlnode *
 jabber_data_get_xhtml_im(const JabberData *data, const gchar *alt)
 {
-	xmlnode *img = xmlnode_new("img");
+	xmlnode *img;
 	char src[128];
 
+	g_return_val_if_fail(data != NULL, NULL);
+	g_return_val_if_fail(alt != NULL, NULL);
+
+	img = xmlnode_new("img");
 	xmlnode_set_attrib(img, "alt", alt);
 	g_snprintf(src, sizeof(src), "cid:%s", data->cid);
 	xmlnode_set_attrib(img, "src", src);
@@ -269,7 +298,7 @@
 			"Responder didn't recognize requested data\n");
 		cb(NULL, alt, userdata);
 	} else {
-		purple_debug_error("jabber", "Unknown response to data request\n");
+		purple_debug_warning("jabber", "Unknown response to data request\n");
 		cb(NULL, alt, userdata);
 	}
 
@@ -281,9 +310,17 @@
     gchar *alt, gboolean ephemeral, JabberDataRequestCallback cb,
     gpointer userdata)
 {
-	JabberIq *request = jabber_iq_new(js, JABBER_IQ_GET);
-	xmlnode *data_request = jabber_data_get_xml_request(cid);
-	JabberDataRequestData *data = g_new0(JabberDataRequestData, 1);
+	JabberIq *request;
+	xmlnode *data_request;
+	JabberDataRequestData *data;
+
+	g_return_if_fail(cid != NULL);
+	g_return_if_fail(who != NULL);
+	g_return_if_fail(alt != NULL);
+
+	request = jabber_iq_new(js, JABBER_IQ_GET);
+	data_request = jabber_data_get_xml_request(cid);
+	data = g_new0(JabberDataRequestData, 1);
 
 	data->userdata = userdata;
 	data->alt = alt;
@@ -333,6 +370,9 @@
 void
 jabber_data_associate_local(JabberData *data, const gchar *alt)
 {
+	g_return_if_fail(data != NULL);
+	g_return_if_fail(alt != NULL);
+
 	purple_debug_info("jabber", "associating local data object\n alt = %s, cid = %s\n",
 		alt , jabber_data_get_cid(data));
 	if (alt)
@@ -345,7 +385,9 @@
 jabber_data_associate_remote(JabberStream *js, const gchar *who, JabberData *data)
 {
 	gchar *cid;
-	
+
+	g_return_if_fail(data != NULL);
+
 	if (jabber_data_has_valid_hash(data)) {
 		cid = g_strdup(jabber_data_get_cid(data));
 	} else {