changeset 2123:56c4382f2909

[gaim-migrate @ 2133] now has the ability to notify you beforehand that messages are too long. I haven't tested this yet though. committer: Tailor Script <tailor@pidgin.im>
author Eric Warmenhoven <eric@warmenhoven.org>
date Mon, 06 Aug 2001 17:50:46 +0000
parents c99c781e5931
children a1922ad52304
files src/conversation.c src/gaim.h src/protocols/icq/gaim_icq.c src/protocols/irc/irc.c src/protocols/jabber/jabber.c src/protocols/msn/msn.c src/protocols/napster/napster.c src/protocols/oscar/oscar.c src/protocols/toc/toc.c src/protocols/yahoo/yay.c src/protocols/zephyr/zephyr.c src/prpl.h src/server.c
diffstat 13 files changed, 57 insertions(+), 36 deletions(-) [+]
line wrap: on
line diff
--- a/src/conversation.c	Sat Aug 04 01:37:49 2001 +0000
+++ b/src/conversation.c	Mon Aug 06 17:50:46 2001 +0000
@@ -29,6 +29,7 @@
 #include <unistd.h>
 #include <stdio.h>
 #include <stdlib.h>
+#include <errno.h>
 #include <ctype.h>
 #include <gtk/gtk.h>
 #include "gtkimhtml.h"
@@ -752,21 +753,16 @@
 {
 	char *buf, *buf2;
 	int limit;
+	int err = 0;
 
 	if (!c->gc)
 		return;
 
 	buf2 = gtk_editable_get_chars(GTK_EDITABLE(c->entry), 0, -1);
-	/* uncomment this if you want no limit on outgoing messages.
-	 * if you uncomment this, you'll probably get kicked off if
-	 * you send one that's too big.
-	 limit = strlen(buf2) * 2;
-	 */
-	limit = 7985 << 2;
+	limit = 32 * 1024; /* you shouldn't be sending more than 32k in your messages. that's a book. */
 	buf = g_malloc(limit);
 	g_snprintf(buf, limit, "%s", buf2);
 	g_free(buf2);
-	gtk_editable_delete_text(GTK_EDITABLE(c->entry), 0, -1);
 	if (!strlen(buf)) {
 		g_free(buf);
 		return;
@@ -858,7 +854,7 @@
 		buffy = g_strdup(buf);
 		plugin_event(event_im_displayed_sent, c->gc, c->name, &buffy, 0);
 		if (buffy) {
-			serv_send_im(c->gc, c->name, buffy, 0);
+			err = serv_send_im(c->gc, c->name, buffy, 0);
 			g_free(buffy);
 		}
 
@@ -871,16 +867,25 @@
 		/* no sound because we do that when we receive our message */
 	}
 
-	if (general_options & OPT_GEN_BACK_ON_IM) {
-		if (awaymessage != NULL) {
-			do_im_back();
-		} else if (c->gc->away) {
-			serv_set_away(c->gc, GAIM_AWAY_CUSTOM, NULL);
+	g_free(buf2);
+	g_free(buf);
+
+	if (err < 0) {
+		if (err == -E2BIG)
+			do_error_dialog(_("Unable to send message: too large"), _("Message Error"));
+		else
+			do_error_dialog(_("Unable to send message: Unknown reason"), _("Message Error"));
+	} else {
+		gtk_editable_delete_text(GTK_EDITABLE(c->entry), 0, -1);
+
+		if (general_options & OPT_GEN_BACK_ON_IM) {
+			if (awaymessage != NULL) {
+				do_im_back();
+			} else if (c->gc->away) {
+				serv_set_away(c->gc, GAIM_AWAY_CUSTOM, NULL);
+			}
 		}
 	}
-
-	g_free(buf2);
-	g_free(buf);
 }
 
 int entry_key_pressed(GtkWidget *w, GtkWidget *entry)
--- a/src/gaim.h	Sat Aug 04 01:37:49 2001 +0000
+++ b/src/gaim.h	Mon Aug 06 17:50:46 2001 +0000
@@ -647,7 +647,7 @@
 extern void serv_close(struct gaim_connection *);
 extern void serv_touch_idle(struct gaim_connection *);
 extern void serv_finish_login();
-extern void serv_send_im(struct gaim_connection *, char *, char *, int);
+extern int  serv_send_im(struct gaim_connection *, char *, char *, int);
 extern void serv_get_info(struct gaim_connection *, char *);
 extern void serv_get_away_msg(struct gaim_connection *, char *);
 extern void serv_get_dir(struct gaim_connection *, char *);
--- a/src/protocols/icq/gaim_icq.c	Sat Aug 04 01:37:49 2001 +0000
+++ b/src/protocols/icq/gaim_icq.c	Mon Aug 06 17:50:46 2001 +0000
@@ -347,7 +347,7 @@
 	g_free(id);
 }
 
-static void icq_send_msg(struct gaim_connection *gc, char *who, char *msg, int away) {
+static int icq_send_msg(struct gaim_connection *gc, char *who, char *msg, int away) {
 	if (!away && (strlen(msg) > 0)) {
 		struct icq_data *id = (struct icq_data *)gc->proto_data;
 		GSList *l = id->thru_serv;
@@ -359,6 +359,7 @@
 		}
 		icq_SendMessage(id->link, w, msg, l ? ICQ_SEND_THRUSERVER : ICQ_SEND_BESTWAY);
 	}
+	return 0;
 }
 
 static void icq_keepalive(struct gaim_connection *gc) {
--- a/src/protocols/irc/irc.c	Sat Aug 04 01:37:49 2001 +0000
+++ b/src/protocols/irc/irc.c	Mon Aug 06 17:50:46 2001 +0000
@@ -162,7 +162,7 @@
 }
 
 
-static void irc_send_im(struct gaim_connection *gc, char *who, char *message, int away)
+static int irc_send_im(struct gaim_connection *gc, char *who, char *message, int away)
 {
 
 	struct irc_data *idata = (struct irc_data *)gc->proto_data;
@@ -195,7 +195,7 @@
 			irc_get_info(gc, temp);
 			g_free(temp);
 
-			return;
+			return 0;
 		}
 
 	} else {
@@ -205,6 +205,7 @@
 	write(idata->fd, buf, strlen(buf));
 
 	g_free(buf);
+	return 0;
 }
 
 static int find_id_by_name(struct gaim_connection *gc, char *name)
--- a/src/protocols/jabber/jabber.c	Sat Aug 04 01:37:49 2001 +0000
+++ b/src/protocols/jabber/jabber.c	Mon Aug 06 17:50:46 2001 +0000
@@ -1215,14 +1215,14 @@
 	gc->proto_data = NULL;
 }
 
-static void jabber_send_im(struct gaim_connection *gc, char *who, char *message, int away)
+static int jabber_send_im(struct gaim_connection *gc, char *who, char *message, int away)
 {
 	xmlnode x, y;
 	char *realwho;
 	gjconn j = ((struct jabber_data *)gc->proto_data)->jc;
 
 	if (!who || !message)
-		return;
+		return 0;
 
 	x = xmlnode_new_tag("message");
 	if (!strchr(who, '@'))
@@ -1243,6 +1243,7 @@
 
 	gjab_send(((struct jabber_data *)gc->proto_data)->jc, x);
 	xmlnode_free(x);
+	return 0;
 }
 
 static void jabber_add_buddy(struct gaim_connection *gc, char *name)
--- a/src/protocols/msn/msn.c	Sat Aug 04 01:37:49 2001 +0000
+++ b/src/protocols/msn/msn.c	Mon Aug 06 17:50:46 2001 +0000
@@ -1142,7 +1142,7 @@
 	g_free(md);
 }
 
-static void msn_send_im(struct gaim_connection *gc, char *who, char *message, int away)
+static int msn_send_im(struct gaim_connection *gc, char *who, char *message, int away)
 {
 	struct msn_data *md = gc->proto_data;
 	struct msn_switchboard *ms = msn_find_switch(gc, who);
@@ -1162,7 +1162,7 @@
 		if (msn_write(md->fd, buf, strlen(buf)) < 0) {
 			hide_login_progress(gc, "Write error");
 			signoff(gc);
-			return;
+			return 0;
 		}
 
 		ms = g_new0(struct msn_switchboard, 1);
@@ -1174,6 +1174,7 @@
 	} else
 		/* in msn you can't send messages to yourself, so we'll fake like we received it ;) */
 		serv_got_im(gc, who, message, away, time(NULL));
+	return 0;
 }
 
 static void msn_chat_send(struct gaim_connection *gc, int id, char *message)
--- a/src/protocols/napster/napster.c	Sat Aug 04 01:37:49 2001 +0000
+++ b/src/protocols/napster/napster.c	Mon Aug 06 17:50:46 2001 +0000
@@ -217,12 +217,14 @@
 	return NULL;
 }
 
-static void nap_send_im(struct gaim_connection *gc, char *who, char *message, int away)
+static int nap_send_im(struct gaim_connection *gc, char *who, char *message, int away)
 {
 	gchar buf[NAP_BUF_LEN];
 
 	g_snprintf(buf, NAP_BUF_LEN, "%s %s", who, message);
 	nap_write_packet(gc, 0xCD, buf);
+
+	return 0;
 }
 
 static struct nap_channel *find_channel_by_name(struct gaim_connection *gc, char *name)
--- a/src/protocols/oscar/oscar.c	Sat Aug 04 01:37:49 2001 +0000
+++ b/src/protocols/oscar/oscar.c	Mon Aug 06 17:50:46 2001 +0000
@@ -2443,14 +2443,14 @@
 	return "Oscar";
 }
 
-static void oscar_send_im(struct gaim_connection *gc, char *name, char *message, int away) {
+static int oscar_send_im(struct gaim_connection *gc, char *name, char *message, int away) {
 	struct oscar_data *odata = (struct oscar_data *)gc->proto_data;
 	struct direct_im *dim = find_direct_im(odata, name);
 	if (dim) {
-		aim_send_im_direct(odata->sess, dim->conn, message);
+		return aim_send_im_direct(odata->sess, dim->conn, message);
 	} else {
 		if (away)
-			aim_send_im(odata->sess, odata->conn, name, AIM_IMFLAGS_AWAY, message);
+			return aim_send_im(odata->sess, odata->conn, name, AIM_IMFLAGS_AWAY, message);
 		else {
 			int flags = AIM_IMFLAGS_ACK;
 #if USE_PIXBUF
@@ -2469,7 +2469,7 @@
 				debug_printf("sending buddy icon request with message\n");
 			}
 #endif
-			aim_send_im(odata->sess, odata->conn, name, flags, message);
+			return aim_send_im(odata->sess, odata->conn, name, flags, message);
 		}
 	}
 }
--- a/src/protocols/toc/toc.c	Sat Aug 04 01:37:49 2001 +0000
+++ b/src/protocols/toc/toc.c	Mon Aug 06 17:50:46 2001 +0000
@@ -741,14 +741,18 @@
 	return "TOC";
 }
 
-static void toc_send_im(struct gaim_connection *gc, char *name, char *message, int away)
+static int toc_send_im(struct gaim_connection *gc, char *name, char *message, int away)
 {
 	char buf[BUF_LEN * 2];
 
 	escape_text(message);
+	if (strlen(message) + 52 > MSG_LEN)
+		return -E2BIG;
 	g_snprintf(buf, MSG_LEN - 8, "toc_send_im %s \"%s\"%s", normalize(name),
 		   message, ((away) ? " auto" : ""));
 	sflap_send(gc, buf, -1, TYPE_DATA);
+	
+	return 0;
 }
 
 static void toc_set_config(struct gaim_connection *gc)
--- a/src/protocols/yahoo/yay.c	Sat Aug 04 01:37:49 2001 +0000
+++ b/src/protocols/yahoo/yay.c	Mon Aug 06 17:50:46 2001 +0000
@@ -442,11 +442,11 @@
 	g_free(yd);
 }
 
-static void yahoo_send_im(struct gaim_connection *gc, char *who, char *message, int away) {
+static int yahoo_send_im(struct gaim_connection *gc, char *who, char *message, int away) {
 	struct yahoo_data *yd = (struct yahoo_data *)gc->proto_data;
 	GSList *l = yd->offline;
 
-	if (away || !strlen(message)) return;
+	if (away || !strlen(message)) return 0;
 
 	while (l) {
 		if (!strcmp(who, l->data))
@@ -458,6 +458,7 @@
 		yahoo_send_message(yd->sess, yd->active_id, who, message);
 	else
 		yahoo_send_message_offline(yd->sess, yd->active_id, who, message);
+	return 0;
 }
 
 static void yahoo_set_away(struct gaim_connection *gc, char *state, char *msg) {
--- a/src/protocols/zephyr/zephyr.c	Sat Aug 04 01:37:49 2001 +0000
+++ b/src/protocols/zephyr/zephyr.c	Mon Aug 06 17:50:46 2001 +0000
@@ -722,7 +722,7 @@
 	g_free(buf);
 }
 
-static void zephyr_send_im(struct gaim_connection *gc, char *who, char *im, int away) {
+static int zephyr_send_im(struct gaim_connection *gc, char *who, char *im, int away) {
 	ZNotice_t notice;
 	char *buf;
 	const char *sig;
@@ -753,6 +753,7 @@
 	notice.z_message = buf;
 	ZSendNotice(&notice, ZAUTH);
 	g_free(buf);
+	return 0;
 }
 
 static char *zephyr_normalize(const char *orig)
--- a/src/prpl.h	Sat Aug 04 01:37:49 2001 +0000
+++ b/src/prpl.h	Mon Aug 06 17:50:46 2001 +0000
@@ -87,7 +87,7 @@
 	/* all the server-related functions */
 	void (* login)		(struct aim_user *);
 	void (* close)		(struct gaim_connection *);
-	void (* send_im)	(struct gaim_connection *, char *who, char *message, int away);
+	int  (* send_im)	(struct gaim_connection *, char *who, char *message, int away);
 	void (* set_info)	(struct gaim_connection *, char *info);
 	void (* get_info)	(struct gaim_connection *, char *who);
 	void (* set_away)	(struct gaim_connection *, char *state, char *message);
--- a/src/server.c	Sat Aug 04 01:37:49 2001 +0000
+++ b/src/server.c	Mon Aug 06 17:50:46 2001 +0000
@@ -30,6 +30,7 @@
 #include <sys/stat.h>
 #include <sys/time.h>
 #include <unistd.h>
+#include <errno.h>
 #include <gtk/gtk.h>
 #ifdef USE_SCREENSAVER
 #include <X11/Xlib.h>
@@ -119,13 +120,16 @@
 
 
 
-void serv_send_im(struct gaim_connection *gc, char *name, char *message, int away)
+int serv_send_im(struct gaim_connection *gc, char *name, char *message, int away)
 {
+	int val = -EINVAL;
 	if (gc->prpl && gc->prpl->send_im)
-		(*gc->prpl->send_im)(gc, name, message, away);
+		val = (*gc->prpl->send_im)(gc, name, message, away);
 
 	if (!away)
 		serv_touch_idle(gc);
+
+	return val;
 }
 
 void serv_get_info(struct gaim_connection *g, char *name)