soc.2009.telepathy: 2c6a8a67: Added parameter checks to telepathy_chan...

sttwister at gmail.com sttwister at gmail.com
Thu Oct 15 15:55:34 EDT 2009


-----------------------------------------------------------------
Revision: 2c6a8a67424c07def9d8ae05d528ef258545e974
Ancestor: f62d3a07e678e00635dfb1b01fa2118cb0591cd0
Author: sttwister at gmail.com
Date: 2009-10-14T18:09:22
Branch: im.pidgin.soc.2009.telepathy
URL: http://d.pidgin.im/viewmtn/revision/info/2c6a8a67424c07def9d8ae05d528ef258545e974

Modified files:
        libpurple/protocols/telepathy/telepathy_channel_text.c

ChangeLog: 

Added parameter checks to telepathy_channel_text.c

-------------- next part --------------
============================================================
--- libpurple/protocols/telepathy/telepathy_channel_text.c	779a1372a0f1401bfce8e32a7b1a25f1429c5c28
+++ libpurple/protocols/telepathy/telepathy_channel_text.c	a559b63a2d2344d38cdcf3d4c7b9c67c840744e9
@@ -33,6 +33,8 @@ destroy_property(PrplTpProperty *tp_prop
 void
 destroy_property(PrplTpProperty *tp_property)
 {
+	g_return_if_fail(tp_property != NULL);
+
 	g_free(tp_property->name);
 	g_free(tp_property->signature);
 
@@ -44,12 +46,16 @@ destroy_room_channel(PrplTpRoomChannel *
 void
 destroy_room_channel(PrplTpRoomChannel *tp_channel)
 {
+	g_return_if_fail(tp_channel != NULL);
+
 	g_free(tp_channel);
 }
 
 void
 destroy_text_channel(PrplTpTextChannel *tp_channel)
 {
+	g_return_if_fail(tp_channel != NULL);
+
 	g_free(tp_channel);
 }
 
@@ -69,6 +75,8 @@ write_message_to_chatroom (int id,
 	gchar *final_message = purple_strdup_withhtml(escaped_message);
 	g_free(escaped_message);
 
+	g_return_if_fail(user_data != NULL);
+
 	purple_debug_info("telepathy", "Received from %s: \"%s\" (escaped: \"%s\")\n",
 			from, msg, final_message);
 
@@ -87,16 +95,20 @@ chat_got_message (PrplTpRoomChannel *tp_
                   guint arg_Flags,
                   const gchar *arg_Text)
 {
-	TpChannel *channel = tp_channel->channel;
+	TpChannel *channel;
+	TpHandle handle;
+	GArray *message_IDs;
+	const gchar *from;
+	TpContact *contact;
 
-	TpHandle handle = tp_channel_get_handle(channel, NULL);
+	g_return_if_fail(tp_channel != NULL);
 
-	GArray *message_IDs;
+	channel = tp_channel->channel;
 
+	handle = tp_channel_get_handle(channel, NULL);
+
 	/* Get information about the contact who sent this message */
-	const gchar *from;
-	TpContact *contact = g_hash_table_lookup(
-			tp_channel->contacts, (gpointer)arg_Sender);
+	contact = g_hash_table_lookup(tp_channel->contacts, (gpointer)arg_Sender);
 
 	if (contact != NULL)
 		from = tp_contact_get_alias(contact);
@@ -144,6 +156,8 @@ get_contacts_for_scrollback_cb (TpConnec
 	{
 		int i;
 
+		g_return_if_fail(user_data != NULL);
+
 		if (n_failed > 0)
 		{
 			purple_debug_info("telepathy", "Failed to fetch %u contacts for scrollback\n",
@@ -198,12 +212,17 @@ chat_got_scrollback_messages (PrplTpConn
 chat_got_scrollback_messages (PrplTpConnection *data,
                               PrplTpScrollbackMessages *tp_messages)
 {
-	GArray *handles = tp_messages->handles;
+	GArray *handles;
 
 	const TpContactFeature features[] = {
 		TP_CONTACT_FEATURE_ALIAS,
 	};
 
+	g_return_if_fail(data != NULL);
+	g_return_if_fail(tp_messages != NULL);
+
+	handles = tp_messages->handles;
+
 	purple_debug_info("telepathy", "Requesting %u contacts for scrollback\n", handles->len);
 
 	if (handles->len > 0)
@@ -235,20 +254,22 @@ chat_list_pending_messages_cb  (TpChanne
 	else
 	{
 		PrplTpConnection *data = user_data;
-
 		int i;
+		const gchar *who;
+		TpHandle handle;
+		PrplTpRoomChannel *tp_channel;
+		PrplTpScrollbackMessages *tp_messages;
+		
+		g_return_if_fail(user_data != NULL);
 
-		const gchar *who = tp_channel_get_identifier(proxy);
-		TpHandle handle = tp_channel_get_handle(proxy, NULL);
+		who = tp_channel_get_identifier(proxy);
+		handle = tp_channel_get_handle(proxy, NULL);
 
 		/* Get the channel struct by channel handle
 		 * (which is the same with the libpurple chat id)
 		 */
-		PrplTpRoomChannel *tp_channel = g_hash_table_lookup(
-				data->room_Channels, (gpointer)handle);
+		tp_channel = g_hash_table_lookup( data->room_Channels, (gpointer)handle);
 
-		PrplTpScrollbackMessages *tp_messages;
-		
 		if (tp_channel == NULL)
 		{
 			purple_debug_warning("telepathy", "Pending message from %s,"
@@ -325,17 +346,26 @@ chat_received_cb (TpChannel *proxy,
                   gpointer user_data,
                   GObject *weak_object)
 {
-	PrplTpConnection *data = user_data;
+	PrplTpConnection *data;
 
-	GHashTable *properties = tp_channel_borrow_immutable_properties(proxy);
-	gchar *who = (gchar *)tp_asv_get_string(properties, TP_IFACE_CHANNEL ".TargetID");
-	TpHandle handle = tp_channel_get_handle(proxy, NULL);
+	GHashTable *properties;
+	gchar *who;
+	TpHandle handle;
 
+	PrplTpRoomChannel *tp_channel;
+
+	g_return_if_fail(user_data != NULL);
+
+	data = user_data;
+
+	properties = tp_channel_borrow_immutable_properties(proxy);
+	who = (gchar *)tp_asv_get_string(properties, TP_IFACE_CHANNEL ".TargetID");
+	handle = tp_channel_get_handle(proxy, NULL);
+
 	/* Get the channel struct by channel handle
 	 * (which is the same with the libpurple chat id)
 	 */
-	PrplTpRoomChannel *tp_channel = g_hash_table_lookup(
-			data->room_Channels, (gpointer)handle);
+	tp_channel = g_hash_table_lookup(data->room_Channels, (gpointer)handle);
 
 	if (tp_channel == NULL)
 	{
@@ -366,12 +396,15 @@ chat_send_error_cb (TpChannel *proxy,
 {
 	PrplTpConnection *data = user_data;
 
-	const gchar *who = tp_channel_get_identifier(proxy);
-
+	const gchar *who;
 	const gchar *error_reason = NULL;
 	gchar *error_message;
 	gchar *error_message2;
 
+	g_return_if_fail(user_data != NULL);
+
+	who = tp_channel_get_identifier(proxy);
+
 	switch (arg_Error)
 	{
 		case TP_CHANNEL_TEXT_SEND_ERROR_UNKNOWN:
@@ -428,6 +461,8 @@ chat_send_cb (TpChannel *proxy,
               gpointer user_data,
               GObject *weak_object)
 {
+	g_return_if_fail(user_data != NULL);
+
 	if (error != NULL)
 	{
 		PrplTpConnection *data = user_data;
@@ -473,6 +508,10 @@ chat_get_contacts_cb (TpConnection *conn
 	PurpleConversation *conv;
 	PrplTpRoomChannel *tp_channel = user_data;
 
+	g_return_if_fail(user_data != NULL);
+
+	tp_channel = user_data;
+
 	if (error != NULL)
 	{
 		purple_debug_error("telepathy", "get_contacts_by_id for chatroom error: %s\n",
@@ -537,6 +576,8 @@ chat_get_all_members_cb (TpChannel *prox
 		return;
 	}
 
+	g_return_if_fail(user_data != NULL);
+
 	purple_debug_info("telepathy", "Got %u members for chatroom\n", out_Members->len);
 
 	for (i = 0; i<out_Members->len; ++i)
@@ -588,9 +629,12 @@ room_channel_invalidated_cb (TpProxy *se
 
 	GHashTableIter iter;
 	gpointer key, value;
+	TpHandle handle;
 
+	g_return_if_fail(user_data != NULL);
+
 	/* remove the cached TpChannel proxy when the channel closes */
-	TpHandle handle = tp_channel_get_handle((TpChannel *)self, NULL);
+	handle = tp_channel_get_handle((TpChannel *)self, NULL);
 
 	purple_debug_info("telepathy", "Chatroom channel with handle %u closed!\n", handle);
 
@@ -622,12 +666,17 @@ chat_members_joined (TpConnection *conne
                      gpointer user_data,
                      GObject *weak_object)
 {
-	PrplTpRoomChannel *tp_channel = user_data;
-	PrplTpConnection *connection_data = tp_channel->connection_data;
+	PrplTpRoomChannel *tp_channel;
+	PrplTpConnection *connection_data;
 	PurpleConversation *conv;
 
 	int i;
 
+	g_return_if_fail(user_data != NULL);
+
+	tp_channel = user_data;
+	connection_data = tp_channel->connection_data;
+
 	if (error != NULL)
 	{
 		purple_debug_error("telepathy", "Error getting TpContact for members joining"
@@ -678,9 +727,14 @@ chat_members_changed_cb (TpChannel *prox
                          gpointer user_data,
                          GObject *weak_object)
 {
-	PrplTpRoomChannel *tp_channel = user_data;
-	PrplTpConnection *connection_data = tp_channel->connection_data;
+	PrplTpRoomChannel *tp_channel;
+	PrplTpConnection *connection_data;
 
+	g_return_if_fail(user_data != NULL);
+
+	tp_channel = user_data;
+	connection_data = tp_channel->connection_data;
+
 	/* Members joined the charoom */
 	if (arg_Added->len > 0)
 	{
@@ -741,8 +795,13 @@ room_property_updated (PrplTpRoomChannel
 room_property_updated (PrplTpRoomChannel *tp_channel,
                        PrplTpProperty *tp_property)
 {
-	PrplTpConnection *connection_data = tp_channel->connection_data;
+	PrplTpConnection *connection_data;
 
+	g_return_if_fail(tp_channel != NULL);
+	g_return_if_fail(tp_property != NULL);
+
+	connection_data = tp_channel->connection_data;
+
 	/* The chat subject or topic has changed */
 	if (g_strcmp0(tp_property->name, "subject") == 0)
 	{
@@ -832,9 +891,9 @@ get_properties_cb (TpProxy *proxy,
                    gpointer user_data,
                    GObject *weak_object)
 {
-	PrplTpRoomChannel *tp_channel = user_data;
-
+	PrplTpRoomChannel *tp_channel;
 	int i;
+	tp_channel = user_data;
 
 	if (error != NULL)
 	{
@@ -843,6 +902,8 @@ get_properties_cb (TpProxy *proxy,
 		return;
 	}
 
+	g_return_if_fail(user_data != NULL);
+
 	purple_debug_info("telepathy", "Got %u properties!\n", out_Values->len);
 
 	for (i = 0; i<out_Values->len; ++i)
@@ -873,10 +934,11 @@ list_properties_cb (TpProxy *proxy,
                     gpointer user_data,
                     GObject *weak_object)
 {
-	PrplTpRoomChannel *tp_channel = user_data;
+	PrplTpRoomChannel *tp_channel;
 
 	int i;
 	GArray *properties;
+	tp_channel = user_data;
 
 	if (error != NULL)
 	{
@@ -885,6 +947,8 @@ list_properties_cb (TpProxy *proxy,
 		return;
 	}
 
+	g_return_if_fail(user_data != NULL);
+
 	tp_channel->properties = g_hash_table_new_full(g_direct_hash, g_direct_equal,
 			NULL, (GDestroyNotify) destroy_property);
 
@@ -942,6 +1006,8 @@ property_flags_changed_cb (TpProxy *prox
 
 	int i;
 
+	g_return_if_fail(user_data != NULL);
+
 	for (i = 0; i<arg_Properties->len; ++i)
 	{
 		GValueArray *arr = g_ptr_array_index(arg_Properties, i);
@@ -971,6 +1037,8 @@ properties_changed_cb (TpProxy *proxy,
 
 	int i;
 
+	g_return_if_fail(user_data != NULL);
+
 	/* We first updated all the properties, and then signal the change in order to 
 	 * take actions. We do this so all properties are updated when taking action.
 	 * For example, we'd also liked to know who changed the subject when it's changed.
@@ -1019,21 +1087,21 @@ handle_room_text_channel (TpChannel *cha
                           gboolean invitation)
 {
 	GError *error = NULL;
+	GHashTable *properties;
+	gchar *who;
+	TpHandle initiator_handle;
+	TpHandle handle;
+	PrplTpRoomChannel *tp_channel;
 
-	GHashTable *properties = tp_channel_borrow_immutable_properties(channel);
+	g_return_if_fail(channel != NULL);
+	g_return_if_fail(data != NULL);
 
-	gchar *who = (gchar *)tp_asv_get_string(properties, TP_IFACE_CHANNEL ".TargetID");
-
-	TpHandle initiator_handle = tp_asv_get_uint32(properties,
-			TP_IFACE_CHANNEL ".InitiatorHandle", NULL);
-
-	TpHandle handle = tp_channel_get_handle(channel, NULL);
-
-	PrplTpRoomChannel *tp_channel;
-
+	properties = tp_channel_borrow_immutable_properties(channel);
+	who = (gchar *)tp_asv_get_string(properties, TP_IFACE_CHANNEL ".TargetID");
+	initiator_handle = tp_asv_get_uint32(properties, TP_IFACE_CHANNEL ".InitiatorHandle", NULL);
+	handle = tp_channel_get_handle(channel, NULL);
 	tp_channel = g_hash_table_lookup(data->room_Channels, (gpointer)handle);
 
-
 	/* Is this an invitation we have not yet handled? */
 	if (initiator_handle != data->self_handle && !invitation)
 	{
@@ -1188,6 +1256,8 @@ write_message_to_conversation (const gch
 	gchar *final_message = purple_strdup_withhtml(escaped_message);
 	g_free(escaped_message);
 
+	g_return_if_fail(user_data != NULL);
+
 	purple_debug_info("telepathy", "Contact %s says \"%s\" (escaped: \"%s\")\n", from, msg, final_message);
 
 	/* transmit the message to the UI */
@@ -1223,14 +1293,18 @@ list_pending_messages_cb  (TpChannel *pr
 	{
 		PrplTpConnection *data = user_data;
 		GArray *message_IDs;
-
 		int i;
+		GHashTable *properties;
+		gchar *who;
+		PrplTpTextChannel *tp_channel;
 
-		GHashTable *properties = tp_channel_borrow_immutable_properties(proxy);
-		gchar *who = (gchar *)tp_asv_get_string(properties, TP_IFACE_CHANNEL ".TargetID");
+		g_return_if_fail(user_data != NULL);
 
-		PrplTpTextChannel *tp_channel = g_hash_table_lookup(data->text_Channels, who);
+		properties = tp_channel_borrow_immutable_properties(proxy);
+		who = (gchar *)tp_asv_get_string(properties, TP_IFACE_CHANNEL ".TargetID");
 
+		tp_channel = g_hash_table_lookup(data->text_Channels, who);
+
 		if (tp_channel == NULL)
 		{
 			purple_debug_warning("telepathy", "Received message from %s, but there's no channel struct for the buddy!\n", who);
@@ -1286,11 +1360,17 @@ received_cb (TpChannel *proxy,
 {
 	PrplTpConnection *data = user_data;
 
-	GHashTable *properties = tp_channel_borrow_immutable_properties(proxy);
-	gchar *who = (gchar *)tp_asv_get_string(properties, TP_IFACE_CHANNEL ".TargetID");
+	GHashTable *properties;
+	gchar *who;
+	PrplTpTextChannel *tp_channel;
 
-	PrplTpTextChannel *tp_channel = g_hash_table_lookup(data->text_Channels, who);
+	g_return_if_fail(user_data != NULL);
 
+	properties = tp_channel_borrow_immutable_properties(proxy);
+	who = (gchar *)tp_asv_get_string(properties, TP_IFACE_CHANNEL ".TargetID");
+
+	tp_channel = g_hash_table_lookup(data->text_Channels, who);
+
 	if (tp_channel == NULL)
 	{
 		purple_debug_warning("telepathy", "Received message from %s, but there's no channel struct for the buddy!\n", who);
@@ -1337,6 +1417,8 @@ send_error_cb (TpChannel *proxy,
 	gchar *error_message;
 	gchar *error_message2;
 
+	g_return_if_fail(user_data != NULL);
+
 	switch (arg_Error)
 	{
 		case TP_CHANNEL_TEXT_SEND_ERROR_UNKNOWN:
@@ -1398,6 +1480,8 @@ send_cb (TpChannel *proxy,
 		gchar *error_message = g_strdup_printf(_("There was an error sending your message to %s"), who);
 		gchar *error_message2 = g_strdup_printf("%s: %s", error_message, error->message);
 
+		g_return_if_fail(user_data != NULL);
+
 		/* display the error in the conversation */
 		if (!purple_conv_present_error(who, data->acct, error_message2))
 		{
@@ -1429,6 +1513,8 @@ text_channel_invalidated_cb (TpProxy *se
 
 	PrplTpTextChannel *tp_channel = NULL;
 	
+	g_return_if_fail(user_data != NULL);
+
 	if (data->text_Channels)
 		tp_channel = g_hash_table_lookup(data->text_Channels, who);
 
@@ -1449,11 +1535,15 @@ chat_state_changed_cb (TpChannel *proxy,
 {
 	PrplTpConnection *data = user_data;
 
-	PrplTpContact *contact_data = g_hash_table_lookup(data->contacts, (gpointer)arg_Contact);
+	PrplTpContact *contact_data;
 
 	PurpleTypingState state;
 	const gchar *name;
 
+	g_return_if_fail(user_data != NULL);
+
+	contact_data = g_hash_table_lookup(data->contacts, (gpointer)arg_Contact);
+
 	if (contact_data == NULL)
 	{
 		purple_debug_warning("telepathy", "Chat state changed for %u who isn't cached!\n", arg_Contact);
@@ -1494,12 +1584,17 @@ handle_im_text_channel (TpChannel *chann
                         PrplTpConnection *data)
 {
 	GError *error = NULL;
+	GHashTable *properties;
+	gchar *who;
 
-	GHashTable *properties = tp_channel_borrow_immutable_properties(channel);
-	gchar *who = (gchar *)tp_asv_get_string(properties, TP_IFACE_CHANNEL ".TargetID");
+	PrplTpTextChannel *tp_channel;
 
-	PrplTpTextChannel *tp_channel;
+	g_return_if_fail(channel != NULL);
+	g_return_if_fail(data != NULL);
 
+	properties = tp_channel_borrow_immutable_properties(channel);
+	who = (gchar *)tp_asv_get_string(properties, TP_IFACE_CHANNEL ".TargetID");
+
 	purple_debug_info("telepathy", "Saving TpChannel proxy for %s\n", who);
 
 	tp_channel = g_hash_table_lookup(data->text_Channels, who);
@@ -1567,6 +1662,9 @@ handle_text_channel (TpChannel *channel,
 	TpHandle handle;
 	TpHandleType handleType;
 
+	g_return_if_fail(channel != NULL);
+	g_return_if_fail(data != NULL);
+
 	handle = tp_channel_get_handle(channel, &handleType);
 
 	switch (handleType)


More information about the Commits mailing list