changeset 1100:f168625b63fe

[gaim-migrate @ 1110] some perl updates, and indication of which account got warned committer: Tailor Script <tailor@pidgin.im>
author Eric Warmenhoven <eric@warmenhoven.org>
date Thu, 16 Nov 2000 08:48:01 +0000
parents 4416ead31db7
children 0ef4386edc29
files src/conversation.c src/gaim.h src/oscar.c src/perl.c src/plugins.c src/server.c src/toc.c src/util.c
diffstat 8 files changed, 91 insertions(+), 33 deletions(-) [+]
line wrap: on
line diff
--- a/src/conversation.c	Thu Nov 16 07:35:58 2000 +0000
+++ b/src/conversation.c	Thu Nov 16 08:48:01 2000 +0000
@@ -580,17 +580,18 @@
 void send_callback(GtkWidget *widget, struct conversation *c)
 {
 	char *buf, *buf2, *buf3;
-	int hdrlen, limit;
+	int limit;
 
 	if (!c->gc) return;
-	/* FIXME! this used to have limits based on protocol limits (oscar chat was 512,
-	 * oscar im was 7985, toc was 4k). we shouldn't be using PROTO_whatever here. it
-	 * should be gotten from the PRPL somehow */
+
+	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;
-
 	buf = g_malloc(limit);
-	
-	buf2 = gtk_editable_get_chars(GTK_EDITABLE(c->entry), 0, -1);
 	g_snprintf(buf, limit, "%s", buf2);
 	g_free(buf2);
 	gtk_editable_delete_text(GTK_EDITABLE(c->entry), 0, -1);
@@ -604,15 +605,6 @@
 
 	buf2 = g_malloc(limit);
 
-        /* Let us determine how long the message CAN be.
-         * toc_send_im is 11 chars long + 2 quotes.
-         * + 2 spaces + 6 for the header + 2 for good
-         * measure = 23 bytes + the length of normalize c->name */
-	/* FIXME: the hdrlen is for how long the header is going to cut off the limit.
-	 * but since we don't know on a protocol basis anymore we can't do this. so we'll
-	 * just assume it's 23 + strlen(normalize(c->name)) for all protocols */
-	hdrlen = 23 + strlen(normalize(c->name));
-
         if (font_options & OPT_FONT_BOLD) {
                 g_snprintf(buf2, limit, "<B>%s</B>", buf);
                 strcpy(buf, buf2);
@@ -651,12 +643,18 @@
 	{
 		char *buffy = g_strdup(buf);
 		enum gaim_event evnt = c->is_chat ? event_chat_send : event_im_send;
-		plugin_event(evnt, c->gc, c->name, &buffy, 0);
+		int plugin_return = plugin_event(evnt, c->gc, c->name, &buffy, 0);
 		if (!buffy) {
 			g_free(buf2);
 			g_free(buf);
 			return;
 		}
+		if (plugin_return) {
+			g_free(buffy);
+			g_free(buf2);
+			g_free(buf);
+			return;
+		}
 		g_snprintf(buf, limit, "%s", buffy);
 		g_free(buffy);
 	}
--- a/src/gaim.h	Thu Nov 16 07:35:58 2000 +0000
+++ b/src/gaim.h	Thu Nov 16 08:48:01 2000 +0000
@@ -661,7 +661,7 @@
 /* output from serv */
 extern void serv_got_update(struct gaim_connection *, char *, int, int, time_t, time_t, int, gushort);
 extern void serv_got_im(struct gaim_connection *, char *, char *, int);
-extern void serv_got_eviled(char *, int);
+extern void serv_got_eviled(struct gaim_connection *, char *, int);
 extern void serv_got_chat_invite(struct gaim_connection *, char *, int, char *, char *);
 extern void serv_got_joined_chat(struct gaim_connection *, int, char *);
 extern void serv_got_chat_left(struct gaim_connection *, int);
@@ -784,7 +784,7 @@
 extern void gaim_plugin_unload(GModule *);
 #endif
 extern char *event_name(enum gaim_event);
-extern void plugin_event(enum gaim_event, void *, void *, void *, void *);
+extern int plugin_event(enum gaim_event, void *, void *, void *, void *);
 
 /* Functions in prefs.c */
 extern void debug_print( char * chars );
--- a/src/oscar.c	Thu Nov 16 07:35:58 2000 +0000
+++ b/src/oscar.c	Thu Nov 16 08:48:01 2000 +0000
@@ -1232,12 +1232,13 @@
 int gaim_parse_evilnotify(struct aim_session_t *sess, struct command_rx_struct *command, ...) {
 	va_list ap;
 	char *sn;
+	struct gaim_connection *gc = find_gaim_conn_by_aim_sess(sess);
 
 	va_start(ap, command);
 	sn = va_arg(ap, char *);
 	va_end(ap);
 
-	serv_got_eviled(sn, 0);
+	serv_got_eviled(gc, sn, 0);
 
 	return 1;
 }
--- a/src/perl.c	Thu Nov 16 07:35:58 2000 +0000
+++ b/src/perl.c	Thu Nov 16 08:48:01 2000 +0000
@@ -515,11 +515,15 @@
 {
 	GList *handler;
 	struct _perl_event_handlers *data;
+	SV *handler_return;
 
 	for (handler = perl_event_handlers; handler != NULL; handler = handler->next) {
 		data = handler->data;
-		if (!strcmp(event, data->event_type))
-			execute_perl(data->handler_name, args);
+		if (!strcmp(event, data->event_type)) {
+			handler_return = execute_perl(data->handler_name, args);
+			if (SvIV(handler_return))
+				return SvIV(handler_return);
+		}
 	}
 
 	return 0;
--- a/src/plugins.c	Thu Nov 16 07:35:58 2000 +0000
+++ b/src/plugins.c	Thu Nov 16 08:48:01 2000 +0000
@@ -619,7 +619,7 @@
 	return buf;
 }
 
-void plugin_event(enum gaim_event event, void *arg1, void *arg2, void *arg3, void *arg4) {
+int plugin_event(enum gaim_event event, void *arg1, void *arg2, void *arg3, void *arg4) {
 #ifdef USE_PERL
 	char buf[BUF_LONG];
 	char *tmp;
@@ -821,6 +821,8 @@
 	tmp = event_name(event);
 	g_snprintf(debug_buff, sizeof debug_buff, "%s: %s\n", tmp, buf);
 	debug_print(debug_buff);
-	perl_event(tmp, buf);
+	return perl_event(tmp, buf);
+#else
+	return 0;
 #endif
 }
--- a/src/server.c	Thu Nov 16 07:35:58 2000 +0000
+++ b/src/server.c	Thu Nov 16 08:48:01 2000 +0000
@@ -307,9 +307,12 @@
 
 	char *buffy = g_strdup(message);
 	char *angel = g_strdup(name);
-	plugin_event(event_im_recv, gc, &angel, &buffy, 0);
-	if (!buffy || !angel)
+	int plugin_return = plugin_event(event_im_recv, gc, &angel, &buffy, 0);
+	if (!buffy || !angel || plugin_return) {
+		if (buffy) g_free(buffy);
+		if (angel) g_free(angel);
 		return;
+	}
 	g_snprintf(message, strlen(message) + 1, "%s", buffy);
 	g_free(buffy);
 	g_snprintf(name, strlen(name) + 1, "%s", angel);
@@ -497,16 +500,16 @@
 
 
 
-void serv_got_eviled(char *name, int lev)
+void serv_got_eviled(struct gaim_connection *gc, char *name, int lev)
 {
         char *buf2 = g_malloc(1024);
         GtkWidget *d, *label, *close;
 
 
-	plugin_event(event_warned, name, (void *)lev, 0, 0);
+	plugin_event(event_warned, gc, name, (void *)lev, 0);
 
-        g_snprintf(buf2, 1023, "You have just been warned by %s.\nYour new warning level is %d%%",
-                   ((name == NULL) ? "an anonymous person" : name) , lev);
+        g_snprintf(buf2, 1023, "%s have just been warned by %s.\nYour new warning level is %d%%",
+                   gc->username, ((name == NULL) ? "an anonymous person" : name) , lev);
 
 
         d = gtk_dialog_new();
@@ -694,7 +697,8 @@
         if (!b)
                 return;
         
-	plugin_event(event_chat_recv, g, b->name, who, message);
+	if (plugin_event(event_chat_recv, g, b->name, who, message))
+		return;
 
         if (whisper)
                 w = WFLAG_WHISPER;
--- a/src/toc.c	Thu Nov 16 07:35:58 2000 +0000
+++ b/src/toc.c	Thu Nov 16 08:48:01 2000 +0000
@@ -47,7 +47,7 @@
 #include "pixmaps/dt_icon.xpm"
 #include "pixmaps/free_icon.xpm"
 
-#define REVISION "gaim:$Revision: 1099 $"
+#define REVISION "gaim:$Revision: 1110 $"
 
 struct toc_data {
 	int toc_fd;
@@ -473,7 +473,7 @@
                 sprintf(debug_buff,"%s | %d\n", name, lev);
 				debug_print(debug_buff);
 
-		serv_got_eviled(name, lev);
+		serv_got_eviled(gc, name, lev);
 		
         } else if (!strcasecmp(c, "CHAT_JOIN")) {
                 char *name;
--- a/src/util.c	Thu Nov 16 07:35:58 2000 +0000
+++ b/src/util.c	Thu Nov 16 08:48:01 2000 +0000
@@ -1258,3 +1258,52 @@
 
 	return 0;
 }
+
+GSList *message_split(char *message, int limit) {
+	static GSList *ret = NULL;
+	int lastgood = 0, curgood = 0, curpos = 0, len = strlen(message);
+	gboolean intag = FALSE;
+
+	if (ret) {
+		GSList *tmp = ret;
+		while (tmp) {
+			g_free(tmp->data);
+			tmp = g_slist_remove(tmp, tmp->data);
+		}
+		ret = NULL;
+	}
+
+	while (TRUE) {
+		if (lastgood >= len)
+			return ret;
+
+		if (len - lastgood < limit) {
+			ret = g_slist_append(ret, g_strdup(&message[lastgood]));
+			return ret;
+		}
+		
+		curgood = curpos = 0;
+		intag = FALSE;
+		while (curpos <= limit) {
+			if (isspace(message[curpos + lastgood]) && !intag)
+				curgood = curpos;
+			if (message[curpos + lastgood] == '<')
+				intag = TRUE;
+			if (message[curpos + lastgood] == '>')
+				intag = FALSE;
+			curpos++;
+		}
+
+		if (curgood) {
+			ret = g_slist_append(ret, g_strndup(&message[lastgood], curgood));
+			if (isspace(message[curgood + lastgood]))
+				lastgood += curgood + 1;
+			else
+				lastgood += curgood;
+		} else {
+			/* whoops, guess we have to fudge it here */
+			ret = g_slist_append(ret, g_strndup(&message[lastgood], limit));
+			lastgood += limit;
+		}
+	}
+}