changeset 1101:0ef4386edc29

[gaim-migrate @ 1111] wow, perl got updated. committer: Tailor Script <tailor@pidgin.im>
author Eric Warmenhoven <eric@warmenhoven.org>
date Thu, 16 Nov 2000 10:06:12 +0000
parents f168625b63fe
children d7944415b1cc
files plugins/PERL-HOWTO src/perl.c
diffstat 2 files changed, 180 insertions(+), 150 deletions(-) [+]
line wrap: on
line diff
--- a/plugins/PERL-HOWTO	Thu Nov 16 08:48:01 2000 +0000
+++ b/plugins/PERL-HOWTO	Thu Nov 16 10:06:12 2000 +0000
@@ -3,7 +3,7 @@
 
 If you've ever written a perl script for X-Chat then you've basically written
 one for gaim as well. perl.c in gaim's source is basically an exact copy of
-X-Chat's perl.c file, with small modifications to suit AIM rather than IRC.
+X-Chat's perl.c file, with small modifications to suit GAIM rather than IRC.
 
 Basically the reason for including perl is based on the experience with the
 plugins. X-Chat's docs on Perl Scripting sums it up nicely:
@@ -21,51 +21,51 @@
 
 Everything available in normal perl scripts should be available in gaim's
 perl interface, so I'm not going to bother describing that. The important
-things are the functions provided by gaim's internal AIM module, which is
+things are the functions provided by gaim's internal GAIM module, which is
 what most of this document is about. So, onto the functions.
 
-AIM::register(name, version, shutdownroutine, unused)
+GAIM::register(name, version, shutdownroutine, unused)
 	Just like X-Chat. This is the first function your script should call.
 	shutdownroutine is a function that will be called when the script
 	gets unloaded (like when gaim gets closed). This function returns
 	gaim's version number.
 
-AIM::get_info(integer)
+GAIM::get_info(integer, ...)
 	This function returns different information based on the integer passed
 	to it.
 	0 - the version of gaim you're running ("0.10.0" for example).
-	1 - the screenname to last attempt to sign on
-	2 - either "Offline", "TOC", or "Oscar"
+	1 - the list of currently online screennames
+	2 - given a screenname, the protocol(s) it(/they) use(s) (as ints)
 
-AIM::print(title, message)
+GAIM::print(title, message)
 	This displays a nice little dialog window.
 
 
-AIM::buddy_list()
+GAIM::buddy_list(name)
 	This returns the buddy list (no groups, just the names of the buddies)
+	for the specified account
 
-AIM::online_list()
-	This returns the list of online buddies.
-
-AIM::deny_list()
-	This returns the deny list. This is probably going to be modified before
-	0.10.0 is released to return either the deny or the permit list and the
-	current mode.
+GAIM::online_list(name)
+	This returns the list of online buddies for the specified account.
 
 
-AIM::command(command, ...)
+GAIM::command(command, ...)
 	This sends commands to the server, and each command takes various
 	arguments. The command should be self-explanatory:
-	"signon" - no args.
-	"signoff" - no args.
+	"signon" - the second arg is the screenname to sign on
+	"signoff" - the optional second arg is who to sign off. if no args are
+		    given, all names are signed off.
 	"away" - the second arg is the away message
 	"back" - no args.
 	"idle" - the second arg is how long (in seconds) to set the idle time
-	"warn" - the second arg is the name of the person to warn
+		 (this sets the idle time for all connections)
+	"warn" - the second arg is the name of the person to warn. this is
+		 especially evil since it warns the person from every connection.
 
-AIM::user_info(nick)
-	Returns 7 data items:
+GAIM::user_info(nick)
+	Returns 8 data items:
 		the screenname of the buddy
+		the alias of the buddy
 		"Online" or "Offline"
 		their warning level
 		signon time, in seconds since the epoch
@@ -83,19 +83,21 @@
 			CHAT		8
 			GETFILE		16
 			SENDFILE	32
-
-		This is probably going to change before 0.10.0 is released to
-		also return the alias of the buddy.
+	Since buddy lists are per-connection this goes through the connections
+	until it finds a matching buddy name.
 
-AIM::print_to_conv(who, what)
-	This should be obvious. If you can't figure this out on your own, you
-	shouldn't be using a computer.
+GAIM::print_to_conv(who, what)
+	The question is not what does this do, it's who does this do it as. The
+	answer is "whatever the default is". It uses whichever connection is
+	selected in the conversation window's menu. If the conversation window
+	didn't exist beforehand, then it's the default (first) connection.
 
-AIM::print_to_chat(room, what)
-	This should be just as obvious as the last command.
+GAIM::print_to_chat(room, what)
+	This goes through each connection. If it finds a room matching the name,
+	it'll print the message to that room.
 
 
-AIM::add_event_handler(event, function)
+GAIM::add_event_handler(event, function)
 	This is the most important of them all. This is basically exactly like
 	gaim_signal_connect for plugins. You pass which event you want to connect to
 	(a string with the same name as the events for plugins, see SIGNALS), and a
@@ -106,13 +108,18 @@
 	yourself with split. (Sounding exactly like X-Chat yet?) The arguments are
 	the exact same as those passed to the plugins, and are passed after the
 	plugins have had their way with them. Perl scripts cannot modify the values
-	so that gaim knows what the changes are. Unlike X-Chat, perl scripts cannot
-	short-circut gaim (that is, your script will be called in order it was added,
-	despite what other scripts do, and afterwards, execution will continue as
-	normal). Names of buddies and chat rooms will be in quotes, and all other
+	so that gaim knows what the changes are.
+
+	Perl scripts can short-circuit certain events (namely event_im_send,
+	event_im_recv, event_chat_send, and event_chat_recv). To short-circuit an
+	event simply return a non-0 value. This will cause all subsequent scripts
+	and the event itself to never happen (i.e. the user won't see it happen,
+	and _send events won't actually send).
+
+	Names of buddies and chat rooms will be in quotes, and all other
 	values (like text messages) will not be. (Watch the debug window to get a
 	better feel for this, or better yet, look at the bottom of plugins.c.)
 
-AIM::add_timeout_handler(integer, function)
+GAIM::add_timeout_handler(integer, function)
 	This calls function after integer number of seconds. It only calls function
 	once, so if you want to keep calling function, keep readding the handler.
--- a/src/perl.c	Thu Nov 16 08:48:01 2000 +0000
+++ b/src/perl.c	Thu Nov 16 10:06:12 2000 +0000
@@ -78,24 +78,23 @@
 static PerlInterpreter *my_perl = NULL;
 
 /* dealing with gaim */
-XS(XS_AIM_register); /* set up hooks for script */
-XS(XS_AIM_get_info); /* version, last to attempt signon, protocol */
-XS(XS_AIM_print); /* lemme figure this one out... */
+XS(XS_GAIM_register); /* set up hooks for script */
+XS(XS_GAIM_get_info); /* version, last to attempt signon, protocol */
+XS(XS_GAIM_print); /* lemme figure this one out... */
 
 /* list stuff */
-XS(XS_AIM_buddy_list); /* all buddies */
-XS(XS_AIM_online_list); /* online buddies */
-XS(XS_AIM_deny_list); /* also returns permit list */
+XS(XS_GAIM_buddy_list); /* all buddies */
+XS(XS_GAIM_online_list); /* online buddies */
 
 /* server stuff */
-XS(XS_AIM_command); /* send command to server */
-XS(XS_AIM_user_info); /* given name, return struct buddy members */
-XS(XS_AIM_print_to_conv); /* send message to someone */
-XS(XS_AIM_print_to_chat); /* send message to chat room */
+XS(XS_GAIM_command); /* send command to server */
+XS(XS_GAIM_user_info); /* given name, return struct buddy members */
+XS(XS_GAIM_print_to_conv); /* send message to someone */
+XS(XS_GAIM_print_to_chat); /* send message to chat room */
 
 /* handler commands */
-XS(XS_AIM_add_event_handler); /* when servers talk */
-XS(XS_AIM_add_timeout_handler); /* figure it out */
+XS(XS_GAIM_add_event_handler); /* when servers talk */
+XS(XS_GAIM_add_timeout_handler); /* figure it out */
 
 void xs_init()
 {
@@ -207,21 +206,20 @@
 	Perl_eval_pv(load_file, TRUE);
 #endif
 
-	newXS ("AIM::register", XS_AIM_register, "AIM");
-	newXS ("AIM::get_info", XS_AIM_get_info, "AIM");
-	newXS ("AIM::print", XS_AIM_print, "AIM");
+	newXS ("GAIM::register", XS_GAIM_register, "GAIM");
+	newXS ("GAIM::get_info", XS_GAIM_get_info, "GAIM");
+	newXS ("GAIM::print", XS_GAIM_print, "GAIM");
 
-	newXS ("AIM::buddy_list", XS_AIM_buddy_list, "AIM");
-	newXS ("AIM::online_list", XS_AIM_online_list, "AIM");
-	newXS ("AIM::deny_list", XS_AIM_deny_list, "AIM");
+	newXS ("GAIM::buddy_list", XS_GAIM_buddy_list, "GAIM");
+	newXS ("GAIM::online_list", XS_GAIM_online_list, "GAIM");
 
-	newXS ("AIM::command", XS_AIM_command, "AIM");
-	newXS ("AIM::user_info", XS_AIM_user_info, "AIM");
-	newXS ("AIM::print_to_conv", XS_AIM_print_to_conv, "AIM");
-	newXS ("AIM::print_to_chat", XS_AIM_print_to_chat, "AIM");
+	newXS ("GAIM::command", XS_GAIM_command, "GAIM");
+	newXS ("GAIM::user_info", XS_GAIM_user_info, "GAIM");
+	newXS ("GAIM::print_to_conv", XS_GAIM_print_to_conv, "GAIM");
+	newXS ("GAIM::print_to_chat", XS_GAIM_print_to_chat, "GAIM");
 
-	newXS ("AIM::add_event_handler", XS_AIM_add_event_handler, "AIM");
-	newXS ("AIM::add_timeout_handler", XS_AIM_add_timeout_handler, "AIM");
+	newXS ("GAIM::add_event_handler", XS_GAIM_add_event_handler, "GAIM");
+	newXS ("GAIM::add_timeout_handler", XS_GAIM_add_timeout_handler, "GAIM");
 }
 
 void perl_end()
@@ -264,7 +262,7 @@
 	}
 }
 
-XS (XS_AIM_register)
+XS (XS_GAIM_register)
 {
 	char *name, *ver, *callback, *unused; /* exactly like X-Chat, eh? :) */
 	int junk;
@@ -287,8 +285,9 @@
 	XSRETURN (1);
 }
 
-XS (XS_AIM_get_info)
+XS (XS_GAIM_get_info)
 {
+	int i = 0;
 	int junk;
 	dXSARGS;
 	items = 0;
@@ -296,30 +295,44 @@
 	switch(atoi(SvPV(ST(0), junk))) {
 	case 0:
 		XST_mPV(0, VERSION);
+		i = 1;
 		break;
 	case 1:
-		/* FIXME: no more current_user
-		XST_mPV(0, current_user->username);
-		*/
+		{
+			GSList *c = connections;
+			struct gaim_connection *gc;
+
+			while (c) {
+				gc = (struct gaim_connection *)c->data;
+				XST_mPV(i++, gc->username);
+				c = c->next;
+			}
+		}
 		break;
 	case 2:
-		/* FIXME: more per-connection issues
-		if (!blist)
-			XST_mPV(0, "Offline");
-		else if (!USE_OSCAR)
-			XST_mPV(0, "TOC");
-		else
-			XST_mPV(0, "Oscar");
-		*/
+		{
+			GList *u = aim_users;
+			struct aim_user *a;
+			char *name = g_strdup(normalize(SvPV(ST(1), junk)));
+
+			while (u) {
+				a = (struct aim_user *)u->data;
+				if (!strcasecmp(normalize(a->username), name))
+					XST_mIV(i++, a->protocol);
+				u = u->next;
+			}
+			g_free(name);
+		}
 		break;
 	default:
 		XST_mPV(0, "Error2");
+		i = 1;
 	}
 
-	XSRETURN(1);
+	XSRETURN(i);
 }
 
-XS (XS_AIM_print)
+XS (XS_GAIM_print)
 {
 	char *title;
 	char *message;
@@ -333,17 +346,23 @@
 	XSRETURN(0);
 }
 
-XS (XS_AIM_buddy_list)
+XS (XS_GAIM_buddy_list)
 {
-	/* FIXME
+	char *acct;
+	struct gaim_connection *gc;
 	struct buddy *buddy;
 	struct group *g;
-	GSList *list = groups;
-	GList *mem;
+	GSList *list = NULL;
+	GSList *mem;
 	int i = 0;
+	int junk;
 	dXSARGS;
 	items = 0;
 
+	acct = SvPV(ST(0), junk);
+	gc = find_gaim_conn_by_name(acct);
+	if (gc) list = gc->groups;
+
 	while (list) {
 		g = (struct group *)list->data;
 		mem = g->members;
@@ -355,20 +374,25 @@
 		list = g_slist_next(list);
 	}
 	XSRETURN(i);
-	*/
 }
 
-XS (XS_AIM_online_list)
+XS (XS_GAIM_online_list)
 {
-	/* FIXME
+	char *acct;
+	struct gaim_connection *gc;
 	struct buddy *b;
 	struct group *g;
-	GSList *list = groups;
-	GList *mem;
+	GSList *list = NULL;
+	GSList *mem;
 	int i = 0;
+	int junk;
 	dXSARGS;
 	items = 0;
 
+	acct = SvPV(ST(0), junk);
+	gc = find_gaim_conn_by_name(acct);
+	if (gc) list = gc->groups;
+
 	while (list) {
 		g = (struct group *)list->data;
 		mem = g->members;
@@ -380,28 +404,9 @@
 		list = g_slist_next(list);
 	}
 	XSRETURN(i);
-	*/
 }
 
-XS (XS_AIM_deny_list)
-{
-	/* FIXME, yet again. perl is so fucked
-	char *name;
-	GList *list = deny;
-	int i = 0;
-	dXSARGS;
-	items = 0;
-
-	while (list) {
-		name = (char *)list->data;
-		XST_mPV(i++, name);
-		list = list->next;
-	}
-	XSRETURN(i);
-	*/
-}
-
-XS (XS_AIM_command)
+XS (XS_GAIM_command)
 {
 	int junk;
 	char *command = NULL;
@@ -411,15 +416,14 @@
 	command = SvPV(ST(0), junk);
 	if (!command) XSRETURN(0);
 	if        (!strncasecmp(command, "signon", 6)) {
-		/* FIXME
-		if (!blist) {
-			show_login();
-			dologin(0, 0);
-		}
-		*/
+		char *who = SvPV(ST(1), junk);
+		struct aim_user *u = find_user(who, -1);
+		if (u) serv_login(u);
 	} else if (!strncasecmp(command, "signoff", 7)) {
-		/* FIXME: we need to figure out how this works for multiple connections
-		 * signoff(); */
+		char *who = SvPV(ST(1), junk);
+		struct gaim_connection *gc = find_gaim_conn_by_name(who);
+		if (gc) signoff(gc);
+		else signoff_all(NULL, NULL);
 	} else if (!strncasecmp(command, "away", 4)) {
 		char *message = SvPV(ST(1), junk);
 		struct away_message a;
@@ -428,22 +432,33 @@
 	} else if (!strncasecmp(command, "back", 4)) {
 		do_im_back();
 	} else if (!strncasecmp(command, "idle", 4)) {
-		/* FIXME
-		serv_set_idle(atoi(SvPV(ST(1), junk)));
-		*/
+		GSList *c = connections;
+		struct gaim_connection *gc;
+
+		while (c) {
+			gc = (struct gaim_connection *)c->data;
+			serv_set_idle(gc, atoi(SvPV(ST(1), junk)));
+			gc->is_idle = 1;
+			c = c->next;
+		}
 	} else if (!strncasecmp(command, "warn", 4)) {
-		/* yet another perl FIXME
-		char *name = SvPV(ST(1), junk);
-		serv_warn(name, 0);
-		*/
+		GSList *c = connections;
+		struct gaim_connection *gc;
+
+		while (c) {
+			gc = (struct gaim_connection *)c->data;
+			serv_warn(gc, SvPV(ST(1), junk), 0);
+			c = c->next;
+		}
 	}
 
 	XSRETURN(0);
 }
 
-XS (XS_AIM_user_info)
+XS (XS_GAIM_user_info)
 {
-	/* FIXME
+	GSList *c = connections;
+	struct gaim_connection *gc;
 	int junk;
 	struct buddy *buddy;
 	char *nick;
@@ -453,23 +468,27 @@
 	nick = SvPV(ST(0), junk);
 	if (!nick[0])
 		XSRETURN(0);
-	buddy = find_buddy(nick);
+	while (c) {
+		gc = (struct gaim_connection *)c->data;
+		buddy = find_buddy(gc, nick);
+		if (buddy) c = NULL;
+		else c = c->next;
+	}
 	if (!buddy)
 		XSRETURN(0);
 	XST_mPV(0, buddy->name);
-	XST_mPV(1, buddy->present ? "Online" : "Offline");
-	XST_mIV(2, buddy->evil);
-	XST_mIV(3, buddy->signon);
-	XST_mIV(4, buddy->idle);
-	XST_mIV(5, buddy->uc);
-	XST_mIV(6, buddy->caps);
-	XSRETURN(7);
-	*/
+	XST_mPV(1, buddy->show);
+	XST_mPV(2, buddy->present ? "Online" : "Offline");
+	XST_mIV(3, buddy->evil);
+	XST_mIV(4, buddy->signon);
+	XST_mIV(5, buddy->idle);
+	XST_mIV(6, buddy->uc);
+	XST_mIV(7, buddy->caps);
+	XSRETURN(8);
 }
 
-XS (XS_AIM_print_to_conv)
+XS (XS_GAIM_print_to_conv)
 {
-	/* FIXME
 	char *nick, *what;
 	struct conversation *c;
 	int junk;
@@ -482,33 +501,37 @@
 	if (!c)
 		c = new_conversation(nick);
 	write_to_conv(c, what, WFLAG_SEND, NULL);
-	serv_send_im(nick, what, 0);
-	*/
+	serv_send_im(c->gc, nick, what, 0);
 }
 
-XS (XS_AIM_print_to_chat)
+XS (XS_GAIM_print_to_chat)
 {
-	/* FIXME: need to make this multi-connection based
-	char *nick, *what;
-	struct conversation *c = NULL;
-	GList *bcs = buddy_chats;
+	char *nick, *what, *tmp;
+	GSList *c = connections;
+	struct gaim_connection *gc;
+	struct conversation *b = NULL;
+	GSList *bcs;
 	int junk;
 	dXSARGS;
 	items = 0;
 
 	nick = SvPV(ST(0), junk);
 	what = SvPV(ST(1), junk);
-	while (bcs) {
-		c = (struct conversation *)bcs->data;
-		if (!strcmp(c->name, nick))
-			break;
-		bcs = bcs->next;
-		c = NULL;
+	tmp = g_strdup(normalize(nick));
+	while (c) {
+		gc = (struct gaim_connection *)c->data;
+		bcs = gc->buddy_chats;
+		while (bcs) {
+			b = (struct conversation *)bcs->data;
+			if (!strcmp(normalize(b->name), tmp))
+				break;
+			bcs = bcs->next;
+			b = NULL;
+		}
+		serv_chat_send(b->gc, b->id, what);
+		c = c->next;
 	}
-	if (!c)
-		XSRETURN(0);
-	serv_chat_send(c->id, what);
-	*/
+	XSRETURN(0);
 }
 
 int perl_event(char *event, char *args)
@@ -529,7 +552,7 @@
 	return 0;
 }
 
-XS (XS_AIM_add_event_handler)
+XS (XS_GAIM_add_event_handler)
 {
 	int junk;
 	struct _perl_event_handlers *handler;
@@ -555,7 +578,7 @@
 	return 0; /* returning zero removes the timeout handler */
 }
 
-XS (XS_AIM_add_timeout_handler)
+XS (XS_GAIM_add_timeout_handler)
 {
 	int junk;
 	long timeout;