diff src/protocols/bonjour/jabber.c @ 11693:b91a84e7cbcb

[gaim-migrate @ 13979] Don't crash on bonjour when IMing a non-existant user. Also better error reporting, I think. committer: Tailor Script <tailor@pidgin.im>
author Mark Doliner <mark@kingant.net>
date Tue, 18 Oct 2005 04:16:44 +0000
parents 1fd2a974379f
children 27ed05facc71
line wrap: on
line diff
--- a/src/protocols/bonjour/jabber.c	Tue Oct 18 02:54:26 2005 +0000
+++ b/src/protocols/bonjour/jabber.c	Tue Oct 18 04:16:44 2005 +0000
@@ -495,7 +495,7 @@
 	return 0;
 }
 
-void
+int
 bonjour_jabber_send_message(BonjourJabber *data, const gchar *to, const gchar *body)
 {
 	xmlnode *message_node = NULL;
@@ -506,13 +506,20 @@
 	xmlnode *message_html_body_node = NULL;
 	xmlnode *message_html_body_font_node = NULL;
 	xmlnode *message_x_node = NULL;
-	GaimBuddy *gb = gaim_find_buddy(data->account, to);
-	BonjourBuddy *bb = (BonjourBuddy*)gb->proto_data;
+	GaimBuddy *gb = NULL;
+	BonjourBuddy *bb = NULL;
 	char *conv_message = NULL;
 	GaimConversation *conversation = NULL;
 	char *message_from_ui = NULL;
 	char *stripped_message = NULL;
 
+	gb = gaim_find_buddy(data->account, to);
+	if (gb == NULL)
+		/* You can not send a message to an offline buddy */
+		return -10000;
+
+	bb = (BonjourBuddy *)gb->proto_data;
+
 	// Enclose the message from the UI within a "font" node
 	message_body_node = xmlnode_new("body");
 	stripped_message = gaim_markup_strip_html(body);
@@ -572,7 +579,7 @@
 				g_free(bb->conversation->buddy_name);
 				g_free(bb->conversation);
 				bb->conversation = NULL;
-				return;
+				return 0;
 		}
 
 		bb->conversation->stream_started = TRUE;
@@ -580,12 +587,9 @@
 
 	// Send the message
 	if (_send_data(bb->conversation->socket, message) == -1)
-	{
-		gaim_debug_error("bonjour", "Unable to send the message\n");
-		conv_message = g_strdup("Unable to send the message.");
-		conversation = gaim_find_conversation_with_account(GAIM_CONV_TYPE_IM, bb->name, data->account);
-		gaim_conversation_write(conversation, NULL, conv_message, GAIM_MESSAGE_SYSTEM, time(NULL));
-	}
+		return -10000;
+
+	return 1;
 }
 
 void