pidgin: 3c6688d4: jabber: Add a bunch of g_return_if_fail ...

darkrain42 at pidgin.im darkrain42 at pidgin.im
Wed Jun 16 21:56:00 EDT 2010


-----------------------------------------------------------------
Revision: 3c6688d49a7d287b24c6518b3e32dd1c742d1451
Ancestor: 8d94b5b7c8b83cf8842ac37678bd680f7ada6638
Author: darkrain42 at pidgin.im
Date: 2010-06-17T01:26:02
Branch: im.pidgin.pidgin
URL: http://d.pidgin.im/viewmtn/revision/info/3c6688d49a7d287b24c6518b3e32dd1c742d1451

Modified files:
        libpurple/protocols/jabber/data.c

ChangeLog: 

jabber: Add a bunch of g_return_if_fail checks to the BoB code

(Entirely untested, but I asked Marcus to double-check them)

-------------- next part --------------
============================================================
--- libpurple/protocols/jabber/data.c	bf7262ae17964ed2b2cf6f94c7f95f8c96a0c8a1
+++ libpurple/protocols/jabber/data.c	664509781d2b33753f70ffb5f3f6f0be7ca534bb
@@ -41,10 +41,17 @@ jabber_data_create_from_data(gconstpoint
 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 at bob.xmpp.org", checksum);
 	g_free(checksum);
 
@@ -62,6 +69,7 @@ jabber_data_delete(gpointer cbdata)
 jabber_data_delete(gpointer cbdata)
 {
 	JabberData *data = cbdata;
+
 	g_free(data->cid);
 	g_free(data->type);
 	g_free(data->data);
@@ -76,6 +84,8 @@ jabber_data_create_from_xml(xmlnode *tag
 	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 @@ jabber_data_destroy(JabberData *data)
 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,27 +144,38 @@ jabber_data_get_type(const JabberData *d
 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);
 	xmlnode_set_attrib(tag, "type", data->type);
@@ -165,9 +190,13 @@ jabber_data_get_xhtml_im(const JabberDat
 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 @@ jabber_data_request_cb(JabberStream *js,
 			"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,10 +310,18 @@ jabber_data_request(JabberStream *js, co
     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;
 	data->ephemeral = ephemeral;
@@ -333,6 +370,9 @@ jabber_data_associate_local(JabberData *
 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(JabberStrea
 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 {


More information about the Commits mailing list