changeset 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 969fb599cc1b
children ffc7d932178a
files src/protocols/bonjour/bonjour.c src/protocols/bonjour/jabber.c src/protocols/bonjour/jabber.h src/prpl.h
diffstat 4 files changed, 27 insertions(+), 14 deletions(-) [+]
line wrap: on
line diff
--- a/src/protocols/bonjour/bonjour.c	Tue Oct 18 02:54:26 2005 +0000
+++ b/src/protocols/bonjour/bonjour.c	Tue Oct 18 04:16:44 2005 +0000
@@ -159,9 +159,7 @@
 	if(!to || !msg)
 		return 0;
 
-	bonjour_jabber_send_message(((BonjourData*)(connection->proto_data))->jabber_data, to, msg);
-
-	return 1;
+	return bonjour_jabber_send_message(((BonjourData*)(connection->proto_data))->jabber_data, to, msg);
 }
 
 void
--- 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
--- a/src/protocols/bonjour/jabber.h	Tue Oct 18 02:54:26 2005 +0000
+++ b/src/protocols/bonjour/jabber.h	Tue Oct 18 04:16:44 2005 +0000
@@ -60,7 +60,7 @@
  */
 gint bonjour_jabber_start(BonjourJabber *data);
 
-void bonjour_jabber_send_message(BonjourJabber *data, const gchar *to, const gchar *body);
+int bonjour_jabber_send_message(BonjourJabber *data, const gchar *to, const gchar *body);
 
 void bonjour_jabber_close_conversation(BonjourJabber *data, GaimBuddy *gb);
 
--- a/src/prpl.h	Tue Oct 18 02:54:26 2005 +0000
+++ b/src/prpl.h	Tue Oct 18 04:16:44 2005 +0000
@@ -223,9 +223,20 @@
 
 	/** This must be implemented. */
 	void (*close)(GaimConnection *);
+
+	/**
+	 * This PRPL function should return a positive value on success.
+	 * If the message is too big to be sent, return -E2BIG.  If
+	 * the account is not connected, return -ENOTCONN.  If the
+	 * PRPL is unable to send the message for another reason, return
+	 * some other negative value.  You can use one of the valid
+	 * errno values, or just big something.  If the message should
+	 * not be echoed to the conversation window, return 0.
+	 */
 	int  (*send_im)(GaimConnection *, const char *who,
 					const char *message,
 					GaimConvImFlags flags);
+
 	void (*set_info)(GaimConnection *, const char *info);
 	int  (*send_typing)(GaimConnection *, const char *name, int typing);
 	void (*get_info)(GaimConnection *, const char *who);