changeset 780:c714def9cebb

[gaim-migrate @ 790] You may be a geek if... You've ever used a computer on Friday, Saturday and Sunday of the same weekend. You find yourself interrupting computer store salesman to correct something he said. The first thing you notice when walking in a business is their computer system. ...and offer advice on how you would change it. You've ever mounted a magnetic tape reel. You own any shareware. You know more IP addresses than phone numbers. You've ever accidentally dialed an IP address. Your friends use you as tech support. You've ever named a computer. You have your local computer store on speed dial. You can't carry on a conversation without talking about computers. Co-workers have to E-mail you about the fire alarm to get you out of the building. You've ever found "stray" diskettes when doing laundry. Your computer has it's own phone line - but your teenager doesn't. You check the national weather service web page for current weather conditions (rather than look out the window). You know more URLs than street addresses. Your pet has a web page. You get really excited when Yahoo adds your link. committer: Tailor Script <tailor@pidgin.im>
author Eric Warmenhoven <eric@warmenhoven.org>
date Tue, 29 Aug 2000 03:59:01 +0000
parents 1823a4af82d3
children 95ebfdb31a9b
files plugins/ChangeLog src/aim.c src/away.c src/buddy.c src/buddy_chat.c src/conversation.c src/dialogs.c src/gaim.h src/perl.c src/plugins.c src/server.c
diffstat 11 files changed, 253 insertions(+), 296 deletions(-) [+]
line wrap: on
line diff
--- a/plugins/ChangeLog	Tue Aug 29 02:57:48 2000 +0000
+++ b/plugins/ChangeLog	Tue Aug 29 03:59:01 2000 +0000
@@ -6,6 +6,16 @@
 	This makes things like #ifdef USE_APPLET and #ifdef USE_PERL much more
 	reliable. (#include "config.h" in order to get all the #defines)
 
+	The internals of gaim plugin events got modified slightly. It should
+	have no effect on existing plugins or the way plugins are made. The
+	change was to make my life easier adding perl. It should also make
+	adding new plugin events even easier than before (though I doubt that
+	any more will ever be added).
+
+	event_buddy_away was being triggered every blist_update for every away
+	buddy. This got fixed, but now when you sign on, event_buddy_away may
+	be called before event_buddy_signon. Not that it should matter much.
+
 version 0.9.20:
 	It's 3 am the night before finals, it's obviously a good time to hack
 	gaim.
--- a/src/aim.c	Tue Aug 29 02:57:48 2000 +0000
+++ b/src/aim.c	Tue Aug 29 03:59:01 2000 +0000
@@ -92,22 +92,12 @@
 #else
 #ifdef GAIM_PLUGINS
 	GList *c;
-	struct gaim_callback *g;
 	struct gaim_plugin *p;
-	void (*function)(void *);
 	void (*gaim_plugin_remove)();
 	char *error;
 
 	/* first we tell those who have requested it we're quitting */
-	c = callbacks;
-	while (c) {
-		g = (struct gaim_callback *)c->data;
-		if (g->event == event_quit && g->function != NULL) {
-			function = g->function;
-			(*function)(g->data);
-		}
-		c = c->next;
-	}
+	plugin_event(event_quit, 0, 0, 0);
 
 	/* then we remove everyone in a mass suicide */
 	c = plugins;
@@ -240,21 +230,7 @@
 			NULL);
 #endif /* USE_APPLET */
 
-#ifdef GAIM_PLUGINS
-	 {
-		GList *c = callbacks;
-		struct gaim_callback *g;
-		void (*function)(void *);
-		while (c) {
-			g = (struct gaim_callback *)c->data;
-			if (g->event == event_signon && g->function != NULL) {
-				function = g->function;
-				(*function)(g->data);
-			}
-			c = c->next;
-		}
-	 }
-#endif /* GAIM_PLUGINS */
+	plugin_event(event_signon, 0, 0, 0);
 
 	 running = FALSE;
 	 return;
--- a/src/away.c	Tue Aug 29 02:57:48 2000 +0000
+++ b/src/away.c	Tue Aug 29 03:59:01 2000 +0000
@@ -62,21 +62,7 @@
 
         serv_set_away(NULL);
 	awaymessage = NULL;
-#ifdef GAIM_PLUGINS
-	{
-		GList *c = callbacks;
-		struct gaim_callback *g;
-		void (*function)(void *);
-		while (c) {
-			g = (struct gaim_callback *)c->data;
-			if (g->event == event_back && g->function != NULL) { 
-				function = g->function;
-				(*function)(g->data);
-			}
-			c = c->next;
-		}
-	}
-#endif
+	plugin_event(event_back, 0, 0, 0);
 }
 
 void do_away_message(GtkWidget *w, struct away_message *a)
@@ -176,21 +162,7 @@
         serv_set_away(buf2);
         g_free(buf2);
 	gtk_widget_show(imaway);
-#ifdef GAIM_PLUGINS
-	{
-		GList *c = callbacks;
-		struct gaim_callback *g;
-		void (*function)(void *);
-		while (c) {
-			g = (struct gaim_callback *)c->data;
-			if (g->event == event_away && g->function != NULL) { 
-				function = g->function;
-				(*function)(g->data);
-			}
-			c = c->next;
-		}
-	}
-#endif
+	plugin_event(event_away, 0, 0, 0);
 }
 
 void rem_away_mess(GtkWidget *w, struct away_message *a)
--- a/src/buddy.c	Tue Aug 29 02:57:48 2000 +0000
+++ b/src/buddy.c	Tue Aug 29 03:59:01 2000 +0000
@@ -281,19 +281,7 @@
 {
 	GList *mem;
 
-#ifdef GAIM_PLUGINS
-	GList *c = callbacks;
-	struct gaim_callback *g;
-	void (*function)(void *);
-	while (c) {
-		g = (struct gaim_callback *)c->data;
-		if (g->event == event_signoff && g->function != NULL) {
-			function = g->function;
-			(*function)(g->data);
-		}
-		c = c->next;
-	}
-#endif
+	plugin_event(event_signoff, 0, 0, 0);
 
         while(groups) {
 		mem = ((struct group *)groups->data)->members;
@@ -958,22 +946,12 @@
 {
 #ifdef GAIM_PLUGINS
 	GList *c;
-	struct gaim_callback *g;
 	struct gaim_plugin *p;
-	void (*function)(void *);
 	void (*gaim_plugin_remove)();
 	char *error;
 
 	/* first we tell those who have requested it we're quitting */
-	c = callbacks;
-	while (c) {
-		g = (struct gaim_callback *)c->data;
-		if (g->event == event_quit && g->function != NULL) {
-			function = g->function;
-			(*function)(g->data);
-		}
-		c = c->next;
-	}
+	plugin_event(event_quit, 0, 0, 0);
 
 	/* then we remove everyone in a mass suicide */
 	c = plugins;
@@ -1403,20 +1381,7 @@
 		/* this check should also depend on whether they left,
 		 * and signed on again before they got erased */
                 if (!GTK_WIDGET_VISIBLE(b->item) || b->present == 1) {
-#ifdef GAIM_PLUGINS
-			GList *c = callbacks;
-			struct gaim_callback *g;
-			void (*function)(char *, void *);
-			while (c) {
-				g = (struct gaim_callback *)c->data;
-				if (g->event == event_buddy_signon &&
-						g->function != NULL) {
-					function = g->function;
-					(*function)(b->name, g->data);
-				}
-				c = c->next;
-			}
-#endif
+			plugin_event(event_buddy_signon, b->name, 0, 0);
 			
 			play_sound(BUDDY_ARRIVE);
 			b->present = 2;
@@ -1474,20 +1439,6 @@
                 if (!b->log_timer) {
                         gtk_widget_hide(b->pix);
                         if (b->uc & UC_UNAVAILABLE) {
-#ifdef GAIM_PLUGINS
-				GList *c = callbacks;
-				struct gaim_callback *g;
-				void (*function)(char *, void *);
-				while (c) {
-					g = (struct gaim_callback *)c->data;
-					if (g->event == event_buddy_away &&
-							g->function != NULL) {
-						function = g->function;
-						(*function)(b->name, g->data);
-					}
-					c = c->next;
-				}
-#endif
                                 pm = gdk_pixmap_create_from_xpm_d(blist->window, &bm,
                                                                   NULL, (gchar **)away_icon_xpm);
                                 gtk_pixmap_set(GTK_PIXMAP(b->pix), pm, bm);
@@ -1568,20 +1519,7 @@
 
 	} else {
 		if (GTK_WIDGET_VISIBLE(b->item)) {
-#ifdef GAIM_PLUGINS
-			GList *c = callbacks;
-			struct gaim_callback *g;
-			void (*function)(char *, void *);
-			while (c) {
-				g = (struct gaim_callback *)c->data;
-				if (g->event == event_buddy_signoff &&
-						g->function != NULL) {
-					function = g->function;
-					(*function)(b->name, g->data);
-				}
-				c = c->next;
-			}
-#endif
+			plugin_event(event_buddy_signoff, b->name, 0, 0);
 			play_sound(BUDDY_LEAVE);
 			pm = gdk_pixmap_create_from_xpm_d(blist->window, &bm,
 				NULL, (gchar **)logout_icon_xpm);
--- a/src/buddy_chat.c	Tue Aug 29 02:57:48 2000 +0000
+++ b/src/buddy_chat.c	Tue Aug 29 03:59:01 2000 +0000
@@ -411,19 +411,7 @@
         char *name = g_strdup(buddy);
 	char tmp[BUF_LONG];
 
-#ifdef GAIM_PLUGINS
-	GList *c = callbacks;
-	struct gaim_callback *g;
-	void (*function)(char *, char *, void *);
-	while (c) {
-		g = (struct gaim_callback *)c->data;
-		if (g->event == event_chat_buddy_join && g->function != NULL) {
-			function = g->function;
-			(*function)(b->name, name, g->data);
-		}
-		c = c->next;
-	}
-#endif
+	plugin_event(event_chat_buddy_join, b->name, name, 0);
         b->in_room = g_list_append(b->in_room, name);
 
         update_chat_list(b);
@@ -445,19 +433,7 @@
         GList *names = b->in_room;
 	char tmp[BUF_LONG];
 
-#ifdef GAIM_PLUGINS
-	GList *c = callbacks;
-	struct gaim_callback *g;
-	void (*function)(char *, char *, void *);
-	while (c) {
-		g = (struct gaim_callback *)c->data;
-		if (g->event == event_chat_buddy_leave && g->function != NULL) {
-			function = g->function;
-			(*function)(b->name, buddy, g->data);
-		}
-		c = c->next;
-	}
-#endif
+	plugin_event(event_chat_buddy_leave, b->name, buddy, 0);
 
         while(names) {
                 if (!strcasecmp((char *)names->data, buddy)) {
--- a/src/conversation.c	Tue Aug 29 02:57:48 2000 +0000
+++ b/src/conversation.c	Tue Aug 29 03:59:01 2000 +0000
@@ -586,21 +586,10 @@
 		strcpy(buf, buf2);
 	}
 
-#ifdef GAIM_PLUGINS
 	{
-		GList *ca = callbacks;
-		struct gaim_callback *g;
-		void (*function)(char *, char **, void *);
 		char *buffy = g_strdup(buf);
 		enum gaim_event evnt = c->is_chat ? event_chat_send : event_im_send;
-		while (ca) {
-			g = (struct gaim_callback *)(ca->data);
-			if (g->event == evnt && g->function != NULL) {
-				function = g->function;
-				(*function)(c->name, &buffy, g->data);
-			}
-			ca = ca->next;
-		}
+		plugin_event(evnt, c->name, &buffy, 0);
 		if (!buffy) {
 			g_free(buf2);
 			return;
@@ -608,7 +597,6 @@
 		g_snprintf(buf, limit, "%s", buffy);
 		g_free(buffy);
 	}
-#endif
         
 	if (!c->is_chat) {
 		buf3 = g_strdup(buf);
--- a/src/dialogs.c	Tue Aug 29 02:57:48 2000 +0000
+++ b/src/dialogs.c	Tue Aug 29 03:59:01 2000 +0000
@@ -512,19 +512,7 @@
 	char buf[256];
 	char buf2[32];
 
-#ifdef GAIM_PLUGINS
-	GList *c = callbacks;
-	struct gaim_callback *g;
-	void (*function)(int, void *);
-	while (c) {
-		g = (struct gaim_callback *)c->data;
-		if (g->event == event_error && g->function != NULL) {
-			function = g->function;
-			(*function)(no, g->data);
-		}
-		c = c->next;
-	}
-#endif
+	plugin_event(event_error, (void *)no, 0, 0);
 
 	if (USE_OSCAR)
 		w = d + 4;
--- a/src/gaim.h	Tue Aug 29 02:57:48 2000 +0000
+++ b/src/gaim.h	Tue Aug 29 03:59:01 2000 +0000
@@ -401,7 +401,7 @@
 #define TYPE_SIGNOFF   4
 #define TYPE_KEEPALIVE 5
 
-#define REVISION "gaim:$Revision: 775 $"
+#define REVISION "gaim:$Revision: 790 $"
 #define FLAPON "FLAPON\r\n\r\n"
 
 #define ROAST "Tic/Toc"
@@ -733,14 +733,15 @@
 extern void play_sound(int);
 
 
+/* Functions in plugins.c */
 #ifdef GAIM_PLUGINS
-/* Functions in plugins.c */
 extern void show_plugins(GtkWidget *, gpointer);
 extern void load_plugin (char *);
 extern void gaim_signal_connect(void *, enum gaim_event, void *, void *);
 extern void gaim_signal_disconnect(void *, enum gaim_event, void *);
 extern void gaim_plugin_unload(void *);
 #endif
+extern void plugin_event(enum gaim_event, void *, void *, void *);
 
 /* Functions in prefs.c */
 extern void debug_print( char * chars );
--- a/src/perl.c	Tue Aug 29 02:57:48 2000 +0000
+++ b/src/perl.c	Tue Aug 29 03:59:01 2000 +0000
@@ -57,6 +57,11 @@
 	char *shutdowncallback; /* bleh */
 };
 
+struct _perl_event_handlers {
+	char *event_type;
+	char *handler_name;
+}
+
 struct _perl_timeout_handlers {
 	char *handler_name;
 	gint iotag;
@@ -64,6 +69,7 @@
 
 static GList *perl_list = NULL; /* should probably extern this at some point */
 static GList *perl_timeout_handlers = NULL;
+static GList *perl_event_handlers = NULL;
 static PerlInterpreter *my_perl = NULL;
 
 /* dealing with gaim */
@@ -83,8 +89,7 @@
 XS(XS_AIM_print_to_chat); /* send message to chat room */
 
 /* handler commands */
-XS(XS_AIM_add_message_handler); /* when people talk */
-XS(XS_AIM_add_command_handler); /* when servers talk */
+XS(XS_AIM_add_event_handler); /* when servers talk */
 XS(XS_AIM_add_timeout_handler); /* figure it out */
 
 void xs_init()
@@ -172,8 +177,7 @@
 	newXS ("AIM::print_to_conv", XS_AIM_print_to_conv, "AIM");
 	newXS ("AIM::print_to_chat", XS_AIM_print_to_chat, "AIM");
 
-	newXS ("AIM::add_message_handler", XS_AIM_add_message_handler, "AIM");
-	newXS ("AIM::add_command_handler", XS_AIM_add_command_handler, "AIM");
+	newXS ("AIM::add_event_handler", XS_AIM_add_event_handler, "AIM");
 	newXS ("AIM::add_timeout_handler", XS_AIM_add_timeout_handler, "AIM");
 }
 
@@ -181,6 +185,7 @@
 {
 	struct perlscript *scp;
 	struct _perl_timeout_handlers *thn;
+	struct _perl_event_handlers *ehn;
 
 	while (perl_list) {
 		scp = perl_list->data;
@@ -201,6 +206,14 @@
 		g_free(thn);
 	}
 
+	while (perl_event_handlers) {
+		ehn = perl_event_handlers->data;
+		perl_event_handlers = g_list_remove(perl_event_handlers, ehn);
+		g_free(ehn->event_type);
+		g_free(ehn->handler_name);
+		g_free(ehn);
+	}
+
 	if (my_perl != NULL) {
 		perl_destruct(my_perl);
 		perl_free(my_perl);
@@ -432,14 +445,105 @@
 	serv_chat_send(c->id, what);
 }
 
-XS (XS_AIM_add_message_handler)
+static char *event_name(enum gaim_event event)
 {
-	/* FIXME */
+	static char buf[128];
+	switch(event) {
+		case event_signon:
+			sprintf(buf, "event_signon");
+			break;
+		case event_signoff:
+			sprintf(buf, "event_signoff");
+			break;
+		case event_away:
+			sprintf(buf, "event_away");
+			break;
+		case event_back:
+			sprintf(buf, "event_back");
+			break;
+		case event_im_recv:
+			sprintf(buf, "event_im_recv");
+			break;
+		case event_im_send:
+			sprintf(buf, "event_im_send");
+			break;
+		case event_buddy_signon:
+			sprintf(buf, "event_buddy_signon");
+			break;
+		case event_buddy_signoff:
+			sprintf(buf, "event_buddy_signoff");
+			break;
+		case event_buddy_away:
+			sprintf(buf, "event_buddy_away");
+			break;
+		case event_buddy_back:
+			sprintf(buf, "event_buddy_back");
+			break;
+		case event_blist_update:
+			sprintf(buf, "event_blist_update");
+			break;
+		case event_chat_invited:
+			sprintf(buf, "event_chat_invited");
+			break;
+		case event_chat_join:
+			sprintf(buf, "event_chat_join");
+			break;
+		case event_chat_leave:
+			sprintf(buf, "event_chat_leave");
+			break;
+		case event_chat_buddy_join:
+			sprintf(buf, "event_chat_buddy_join");
+			break;
+		case event_chat_buddy_leave:
+			sprintf(buf, "event_chat_buddy_leave");
+			break;
+		case event_chat_recv:
+			sprintf(buf, "event_chat_recv");
+			break;
+		case event_chat_send:
+			sprintf(buf, "event_chat_send");
+			break;
+		case event_warned:
+			sprintf(buf, "event_warned");
+			break;
+		case event_error:
+			sprintf(buf, "event_error");
+			break;
+		case event_quit:
+			sprintf(buf, "event_quit");
+			break;
+		default:
+			sprintf(buf, "event_unknown");
+			break;
+	}
 }
 
-XS (XS_AIM_add_command_handler)
+int perl_event(enum gaim_event event, char *args)
 {
-	/* FIXME */
+	GList *handler;
+	struct _perl_event_handlers *data;
+
+	for (handler = perl_event_handlers; handler != NULL; handler = handler->next) {
+		data = handler->data;
+		if (!strcmp(event_name(event), data->event_type))
+			execute_perl(args);
+	}
+
+	return 0;
+}
+
+XS (XS_AIM_add_event_handler)
+{
+	int junk;
+	struct _perl_event_handlers *handler;
+	dXSARGS;
+	items = 0;
+
+	handler = g_new0(struct _perl_event_handlers, 1);
+	handler->event_type = g_strdup(SvPV(ST(0), junk));
+	handler->handler_name = g_strdup(SvPV(ST(1), junk));
+	perl_event_handlers = g_list_append(perl_event_handlers, handler);
+	XSRETURN_EMPTY;
 }
 
 static int perl_timeout(struct _perl_timeout_handlers *handler)
--- a/src/plugins.c	Tue Aug 29 02:57:48 2000 +0000
+++ b/src/plugins.c	Tue Aug 29 03:59:01 2000 +0000
@@ -530,3 +530,107 @@
 }
 
 #endif /* GAIM_PLUGINS */
+
+void plugin_event(enum gaim_event event, void *arg1, void *arg2, void *arg3) {
+#ifdef GAIM_PLUGINS
+	GList *c = callbacks;
+	struct gaim_callback *g;
+
+	sprintf(debug_buff, "callback %d\n", event);
+	debug_print(debug_buff);
+
+	while (c) {
+		g = (struct gaim_callback *)c->data;
+		if (g->event == event && g->function != NULL) {
+			switch(event) {
+
+			/* no args */
+			case event_signon:
+			case event_signoff:
+			case event_away:
+			case event_back:
+			case event_blist_update:
+			case event_quit:
+				{
+					void (*function)(void *) = g->function;
+					(*function)(g->data);
+				}
+				break;
+
+			/* char **, char ** */
+			case event_im_recv:
+				{
+					void (*function)(char **, char **, void *) = g->function;
+					(*function)(arg1, arg2, g->data);
+				}
+				break;
+
+			/* char *, char ** */
+			case event_im_send:
+				{
+					void (*function)(char *, char **, void *) = g->function;
+					(*function)(arg1, arg2, g->data);
+				}
+				break;
+
+			/* char * */
+			case event_buddy_signon:
+			case event_buddy_signoff:
+			case event_buddy_away:
+			case event_buddy_back:
+			case event_chat_join:
+			case event_chat_leave:
+				{
+					void (*function)(char *, void *) = g->function;
+					(*function)(arg1, g->data);
+				}
+				break;
+
+			/* char *, char *, char * */
+			case event_chat_invited:
+			case event_chat_recv:
+			case event_chat_send:
+				{
+					void (*function)(char *, char *, char *, void *) = g->function;
+					(*function)(arg1, arg2, arg3, g->data);
+				}
+				break;
+
+			/* char *, char * */
+			case event_chat_buddy_join:
+			case event_chat_buddy_leave:
+				{
+					void (*function)(char *, char *, void *) = g->function;
+					(*function)(arg1, arg2, g->data);
+				}
+				break;
+
+			/* char *, int */
+			case event_warned:
+				{
+					void (*function)(char *, int, void *) = g->function;
+					(*function)(arg1, (int)arg2, g->data);
+				}
+				break;
+
+			/* int */
+			case event_error:
+				{
+					void (*function)(int, void *) = g->function;
+					(*function)((int)arg1, g->data);
+				}
+				break;
+
+			default:
+				sprintf(debug_buff, "unknown event %d\n", event);
+				debug_print(debug_buff);
+				break;
+			}
+		}
+		c = c->next;
+	}
+#endif /* GAIM_PLUGINS */
+#ifdef USE_PERL
+	/* FIXME : AIM::event_handler */
+#endif
+}
--- a/src/server.c	Tue Aug 29 02:57:48 2000 +0000
+++ b/src/server.c	Tue Aug 29 03:59:01 2000 +0000
@@ -100,22 +100,7 @@
 		is_idle = 1;
         }
 
-#ifdef GAIM_PLUGINS
-	{
-		GList *c = callbacks;
-		struct gaim_callback *g;
-		void (*function)(void *);
-		while (c) {
-			g = (struct gaim_callback *)c->data;
-			if (g->event == event_blist_update &&
-					g->function != NULL) { 
-				function = g->function;
-				(*function)(g->data);
-			}
-			c = c->next;
-		}
-	}
-#endif
+	plugin_event(event_blist_update, 0, 0, 0);
         
 	return TRUE;
 
@@ -636,27 +621,15 @@
 	int is_idle = -1;
 	int new_conv = 0;
 
-#ifdef GAIM_PLUGINS
-	GList *c = callbacks;
-	struct gaim_callback *g;
-	void (*function)(char **, char **, void *);
 	char *buffy = g_strdup(message);
 	char *angel = g_strdup(name);
-	while (c) {
-		g = (struct gaim_callback *)c->data;
-		if (g->event == event_im_recv && g->function != NULL) {
-			function = g->function;
-			(*function)(&angel, &buffy, g->data);
-		}
-		c = c->next;
-	}
+	plugin_event(event_im_recv, &angel, &buffy, 0);
 	if (!buffy || !angel)
 		return;
 	g_snprintf(message, strlen(message) + 1, "%s", buffy);
 	g_free(buffy);
 	g_snprintf(name, strlen(name) + 1, "%s", angel);
 	g_free(angel);
-#endif
 	
 	if ((general_options & OPT_GEN_TIK_HACK) && awaymessage &&
 	    !strcmp(message, ">>>Automated Message: Getting Away Message<<<"))
@@ -798,22 +771,13 @@
 
         b->idle = idle;
         b->evil = evil;
-#ifdef GAIM_PLUGINS
+
 	if ((b->uc & UC_UNAVAILABLE) && !(type & UC_UNAVAILABLE)) {
-		GList *c = callbacks;
-		struct gaim_callback *g;
-		void (*function)(char *, void *);
-		while (c) {
-			g = (struct gaim_callback *)c->data;
-			if (g->event == event_buddy_back &&
-					g->function != NULL) { 
-				function = g->function;
-				(*function)(b->name, g->data);
-			}
-			c = c->next;
-		}
+		plugin_event(event_buddy_back, b->name, 0, 0);
+	} else if (!(b->uc & UC_UNAVAILABLE) && (type & UC_UNAVAILABLE)) {
+		plugin_event(event_buddy_away, b->name, 0, 0);
 	}
-#endif
+
         b->uc = type;
 	if (caps) b->caps = caps;
         
@@ -844,19 +808,7 @@
         GtkWidget *d, *label, *close;
 
 
-#ifdef GAIM_PLUGINS
-	GList *c = callbacks;
-	struct gaim_callback *g;
-	void (*function)(char *, int, void *);
-	while (c) {
-		g = (struct gaim_callback *)c->data;
-		if (g->event == event_warned && g->function != NULL) {
-			function = g->function;
-			(*function)(name, lev, g->data);
-		}
-		c = c->next;
-	}
-#endif
+	plugin_event(event_warned, 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);
@@ -916,19 +868,7 @@
         char buf2[BUF_LONG];
 
 
-#ifdef GAIM_PLUGINS
-	GList *c = callbacks;
-	struct gaim_callback *g;
-	void (*function)(char *, char *, char *, void *);
-	while (c) {
-		g = (struct gaim_callback *)c->data;
-		if (g->event == event_chat_invited && g->function != NULL) {
-			function = g->function;
-			(*function)(who, name, message, g->data);
-		}
-		c = c->next;
-	}
-#endif
+	plugin_event(event_chat_invited, who, name, message);
 
 	if (message)
 		g_snprintf(buf2, sizeof(buf2), "User '%s' invites you to buddy chat room: '%s'\n%s", who, name, message);
@@ -980,19 +920,7 @@
 {
         struct conversation *b;
 
-#ifdef GAIM_PLUGINS
-	GList *c = callbacks;
-	struct gaim_callback *g;
-	void (*function)(char *, void *);
-	while (c) {
-		g = (struct gaim_callback *)c->data;
-		if (g->event == event_chat_join && g->function != NULL) {
-			function = g->function;
-			(*function)(name, g->data);
-		}
-		c = c->next;
-	}
-#endif
+	plugin_event(event_chat_join, name, 0, 0);
 
         b = (struct conversation *)g_new0(struct conversation, 1);
         buddy_chats = g_list_append(buddy_chats, b);
@@ -1023,21 +951,7 @@
         if (!b)
                 return;
 
-#ifdef GAIM_PLUGINS
-	{
-	GList *c = callbacks;
-	struct gaim_callback *g;
-	void (*function)(char *, void *);
-	while (c) {
-		g = (struct gaim_callback *)c->data;
-		if (g->event == event_chat_leave && g->function != NULL) {
-			function = g->function;
-			(*function)(b->name, g->data);
-		}
-		c = c->next;
-	}
-	}
-#endif
+	plugin_event(event_chat_leave, b->name, 0, 0);
 
 	sprintf(debug_buff, "Leaving room %s.\n", b->name);
 	debug_print(debug_buff);
@@ -1064,21 +978,7 @@
         if (!b)
                 return;
         
-#ifdef GAIM_PLUGINS
-	{
-	GList *c = callbacks;
-	struct gaim_callback *g;
-	void (*function)(char *, char *, char *, void *);
-	while (c) {
-		g = (struct gaim_callback *)c->data;
-		if (g->event == event_chat_recv && g->function != NULL) {
-			function = g->function;
-			(*function)(b->name, who, message, g->data);
-		}
-		c = c->next;
-	}
-	}
-#endif
+	plugin_event(event_chat_recv, b->name, who, message);
 
         if (whisper)
                 w = WFLAG_WHISPER;