Index: plugins/gaim-remote/remote.c
===================================================================
RCS file: /cvsroot/gaim/gaim/plugins/gaim-remote/remote.c,v
retrieving revision 1.10
diff -u -r1.10 remote.c
--- plugins/gaim-remote/remote.c	17 Jul 2003 10:35:43 -0000	1.10
+++ plugins/gaim-remote/remote.c	2 Aug 2003 07:36:35 -0000
@@ -34,6 +34,7 @@
 #include "core.h"
 #include "debug.h"
 #include "prpl.h"
+#include "blist.h"
 
 /* XXX */
 #include "gtkconv.h"
@@ -406,44 +407,13 @@
 	case CUI_MESSAGE_LIST:
 		break;
 	case CUI_MESSAGE_SEND:
-		if (!data)
-			return;
-		{
-			guint id;
-			GaimConnection *gc;
-			guint len;
-			char *who, *msg;
-			gint flags;
-			int pos = 0;
-
-			memcpy(&id, data + pos, sizeof(id));
-			pos += sizeof(id);
-			gc = g_list_nth_data(gaim_connections_get_all(), id);
-			if (!gc)
-				return;
-
-			memcpy(&len, data + pos, sizeof(len));
-			pos += sizeof(len);
-			who = g_strndup(data + pos, len + 1);
-			pos += len;
-
-			memcpy(&len, data + pos, sizeof(len));
-			pos += sizeof(len);
-			msg = g_strndup(data + pos, len + 1);
-			pos += len;
-
-			memcpy(&flags, data + pos, sizeof(flags));
-			serv_send_im(gc, who, msg, -1, flags);
-
-			g_free(who);
-			g_free(msg);
-		}
+		/*See CUI_REMOTE_SEND*/
 		break;
 	case CUI_MESSAGE_RECV:
 		break;
 	default:
 		gaim_debug(GAIM_DEBUG_WARNING, "cui",
-				   "Unhandled message subtype %d\n", subtype);
+				   "Unhandled message subtype %d\n", subtype); 
 		break;
 	}
 }
@@ -475,8 +445,39 @@
 {
 	const char *resp;
 	char *send;
+
+	GList *c = gaim_connections_get_all();
+	GaimConnection *gc;
+	GaimAccount *account;
+	GaimRemotePacket *p;
+	char buf[2048];
+	/*blist stuff*/
+	struct buddy *b;
+	struct group *g;
+	GSList *gr;
+	GSList *m;
+
+	struct gaim_buddy_list *gaimbuddylist=gaim_get_blist();
+	GaimBlistNode *group;
+	GaimBlistNode *buddy;
+
+
 	switch (subtype) {
 	case CUI_REMOTE_CONNECTIONS:
+		p = gaim_remote_packet_new(CUI_TYPE_REMOTE, CUI_REMOTE_CONNECTIONS);
+		gaim_debug(GAIM_DEBUG_INFO, "cui",
+"Got `gaim-remote info` request\n");
+		while (c) {
+			gc = (GaimConnection *)c->data;
+			account=gaim_connection_get_account(gc);
+			g_snprintf(buf, sizeof buf, "%s,%s\n", gaim_account_get_username(account), gaim_account_get_protocol_id(account));
+			gaim_remote_packet_append_string(p, buf);
+
+			c = c->next;
+		}
+		gaim_debug(GAIM_DEBUG_INFO, "cui", "Sending connection list to gaim-remote\n");
+		gaim_remote_session_send_packet(g_io_channel_unix_get_fd(ui->channel), p);
+		gaim_remote_packet_free(p);
 		break;
 	case CUI_REMOTE_URI:
 		send = g_malloc(len + 1);
@@ -485,6 +486,196 @@
 		resp = gaim_remote_handle_uri(send);
 		g_free(send);
 		/* report error */
+		break;
+
+
+	case CUI_REMOTE_BLIST:
+		p = gaim_remote_packet_new(CUI_TYPE_REMOTE, CUI_REMOTE_BLIST);
+		gaim_debug(GAIM_DEBUG_INFO, "cui", "Got `gaim-remote list` request\n");
+	
+		if (!gaimbuddylist)
+			return ;
+		group = gaimbuddylist->root;
+		while (group) {
+			g_snprintf(buf, sizeof buf, "%s\n", ((struct group *)group)->name);
+			gaim_remote_packet_append_string(p, buf);
+			buddy = group->child;
+			while (buddy) {
+				if(GAIM_BLIST_NODE_IS_BUDDY(buddy)){ /*if this works, javabsp does *rock* */
+					b = (struct buddy *)buddy;
+					if (b->present) {
+						g_snprintf(buf, sizeof buf, "\t%s,%d,%s,%s,%s\n", b->name, b->uc & UC_UNAVAILABLE, gaim_get_buddy_alias(b),gaim_account_get_username(b->account), gaim_account_get_protocol_id(b->account));
+	
+						gaim_remote_packet_append_string(p, buf);
+					}
+
+				}
+	
+				buddy = buddy->next;
+			}
+			group = group->next;
+		}
+	
+
+		gaim_debug(GAIM_DEBUG_INFO, "cui", "Sending buddy list to gaim-remote\n");
+		gaim_remote_session_send_packet(g_io_channel_unix_get_fd(ui->channel), p);
+		gaim_remote_packet_free(p);
+	
+		break;
+	case CUI_REMOTE_SEND:
+		if (!data)
+			return;
+		{
+			guint id;
+			GaimConnection *gc;
+   			GaimConversation *conv;
+			guint tlen,len,len2,quiet;
+			char *who, *msg;
+			char *tmp, *from, *proto;
+			gint flags;
+			int pos = 0;
+			GList *c = gaim_connections_get_all();
+
+			gaim_debug(GAIM_DEBUG_INFO, "cui", "Got `gaim-remote send` packet\n",data);
+			gaim_debug(GAIM_DEBUG_INFO, "cui", "g-r>%s;\n",data);
+
+			tmp = g_strndup(data + pos, 4);
+			tlen=atoi(tmp);
+			pos+=4;
+
+			who=g_strndup(data+pos, tlen);
+			pos+=tlen;
+
+			tmp = g_strndup(data + pos, 4);
+			tlen=atoi(tmp); len=tlen; /*length for 'from' compare*/
+			pos+=4;
+
+			from=g_strndup(data+pos, tlen);
+			pos+=tlen;
+
+			tmp = g_strndup(data + pos, 4);
+			tlen=atoi(tmp); len2=tlen; /*length for 'proto' compare*/
+			pos+=4;
+
+			proto=g_strndup(data+pos, tlen);
+			pos+=tlen;
+			
+			tmp = g_strndup(data + pos, 4);
+			tlen=atoi(tmp);
+			pos+=4;
+
+			msg=g_strndup(data+pos, tlen);
+			pos+=tlen;
+
+			tmp = g_strndup(data + pos, 1);
+			quiet=atoi(tmp); /*quiet flag - not in use yet*/
+
+			/*find acct*/
+	   		while (c) {
+				gc = c->data;
+				account=gaim_connection_get_account(gc);
+				if ((!gaim_utf8_strcasecmp(from, gaim_account_get_username(account))) && (!g_ascii_strncasecmp(proto, gaim_account_get_protocol_id(account), len2)) ) 
+					break;
+				c = c->next;
+			}
+			if (!gc)
+				return;
+			/*end acct find*/
+
+			/*gaim_debug(GAIM_DEBUG_INFO, "cui", "g-r>To: %s; From: %s; Protocol: %s; Message: %s; Quiet: %d\n",who,from,proto,msg,quiet);*/
+   			conv = gaim_conversation_new(GAIM_CONV_IM, gaim_connection_get_account(gc), who);
+   			gaim_im_send(GAIM_IM(conv), msg);
+
+			/*likely to be used for quiet:
+			serv_send_im(gc, who, msg, -1, 0);
+			*/
+			
+			g_free(who);
+			g_free(msg);
+			g_free(from);
+			g_free(tmp);
+		}
+		break;
+	case CUI_REMOTE_AWAY:
+		#if 0
+		if (!data)
+			return;
+		{
+			guint id;
+			GaimConnection *gc;
+   			struct gaim_conversation *conv;
+			guint tlen,len,len2,quiet;
+			char *msg;
+			char *tmp, *from, *proto;
+			gint flags;
+			int pos = 0;
+			int all;
+			GList *c = gaim_connections_get_all();
+
+			gaim_debug(GAIM_DEBUG_INFO, "cui", "Got `gaim-remote away` packet\n",data);
+			gaim_debug(GAIM_DEBUG_INFO, "cui", "g-r>%s;\n",data);
+
+			tmp = g_strndup(data + pos, 1);
+			all=atoi(tmp); /*all?*/
+			pos++;
+
+			if(all==0){
+			tmp = g_strndup(data + pos, 4);
+			tlen=atoi(tmp); len=tlen; /*length for 'from' compare*/
+			pos+=4;
+
+			from=g_strndup(data+pos, tlen);
+			pos+=tlen;
+
+			tmp = g_strndup(data + pos, 4);
+			tlen=atoi(tmp); len2=tlen; /*length for 'proto' compare*/
+			pos+=4;
+
+			proto=g_strndup(data+pos, tlen);
+			pos+=tlen;
+			}/*end if all*/
+			
+			tmp = g_strndup(data + pos, 4);
+			tlen=atoi(tmp);
+			pos+=4;
+
+			msg=g_strndup(data+pos, tlen);
+			pos+=tlen;
+
+
+			if(all==0){
+			/*find acct*/
+	   		while (c) {
+				gc = c->data;
+				account=gaim_connection_get_account(gc);
+				if ((!gaim_utf8_strcasecmp(from, gaim_account_get_username(account))) && (!g_ascii_strncasecmp(proto, gaim_account_get_protocol_id(account), len2)) ) 
+					break;
+				c = c->next;
+			}
+			if (!gc)
+				return;
+			/*end acct find*/
+			}/*only if we're not going away for all accts*/
+
+			/*gaim_debug(GAIM_DEBUG_INFO, "cui", "g-r>From: %s; Protocol: %s; Message: %s; Quiet: %d\n",who,from,proto,msg,quiet);*/
+   			/*conv = gaim_conversation_new(GAIM_CONV_IM, gc->account, who);
+   			gaim_im_send(GAIM_IM(conv), msg);*/
+
+			/*likely to be used for quiet:
+			serv_send_im(gc, who, msg, -1, 0);
+			*/
+
+			if (all==1){
+				serv_set_away_all(msg);
+			}else{
+				serv_set_away(gc, GAIM_AWAY_CUSTOM, msg);
+			}
+			
+			g_free(msg);
+			g_free(from);
+			g_free(tmp);
+		}
+		#endif
 		break;
 	default:
 		gaim_debug(GAIM_DEBUG_WARNING, "cui",
Index: plugins/gaim-remote/remote.h
===================================================================
RCS file: /cvsroot/gaim/gaim/plugins/gaim-remote/remote.h,v
retrieving revision 1.3
diff -u -r1.3 remote.h
--- plugins/gaim-remote/remote.h	15 Jun 2003 07:19:59 -0000	1.3
+++ plugins/gaim-remote/remote.h	2 Aug 2003 07:36:35 -0000
@@ -94,6 +94,7 @@
 #define CUI_REMOTE_ADD_BUDDY    8       /* Adds buddy to list */
 #define CUI_REMOTE_REMOVE_BUDDY 9       /* Removes buddy from list */
 #define CUI_REMOTE_JOIN_CHAT    10       /* Joins a chat. */
+#define CUI_REMOTE_AWAY	        11       /* Sets client as away, with message */
                               /* What else?? */
 
 #endif /* _GAIM_REMOTE_H_ */
Index: src/gaim-remote.c
===================================================================
RCS file: /cvsroot/gaim/gaim/src/gaim-remote.c,v
retrieving revision 1.10
diff -u -r1.10 gaim-remote.c
--- src/gaim-remote.c	14 Jun 2003 23:21:00 -0000	1.10
+++ src/gaim-remote.c	2 Aug 2003 07:36:35 -0000
@@ -2,8 +2,9 @@
  * gaim-remote
  *
  * Copyright (C) 2002, Sean Egan <bj91704@binghamton.edu>
- * Features/functionality added (C) 2002, John B. Silvestri <silvestrij@mville.edu>
- *	'quit', long help for URIs
+ * Features/functionality added (C) 2002-2003, John B. Silvestri <silvestrij@mville.edu>
+ *	'quit', long help for (URIs, send, list), 'info', 'send', 'list'
+ * Command/option/argument code redone by Ethan Blanton
  * 
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -28,33 +29,36 @@
 
 #include <gaim-remote/remote.h>
 
-void show_remote_usage(char *name)
-{
-	printf(_("Usage: %s command [OPTIONS] [URI]\n\n"
-
-	     "    COMMANDS:\n"
-	     "       uri                      Handle AIM: URI\n"
-	     "       quit                     Close running copy of Gaim\n\n"
-
-	     "    OPTIONS:\n"
-	     "       -h, --help [commmand]    Show help for command\n"), name);
-	return;
-}
+static int command_uri(int fd);
+static int command_quit(int fd);
+static int command_info(int fd);
+static int command_list(int fd);
+static int command_send(int fd);
+/*static int command_away(int fd);*/
+static void show_longhelp_uri();
+static void show_longhelp_send();
+static void show_longhelp_list();
+
+struct command {
+	char *name;
+	char *description;
+	void (*longhelp)();
+	int (*cmdfunc)(int fd);
+} remote_commands[] = {
+	{ "uri", N_("Handle AIM: URI"), show_longhelp_uri, command_uri },
+	{ "send", N_("Send message"), show_longhelp_send, command_send },
+	{ "info", N_("Show information about connected accounts"), NULL, command_info },
+	{ "list", N_("Print buddy list"), show_longhelp_list, command_list },
+	/*{ "away", N_("Set as Away"), NULL, command_away },*/
+	{ "quit", N_("Close running copy of Gaim"), NULL, command_quit },
+	{ NULL, NULL, NULL, NULL }
+};
 
-/*To be implemented:
-	     "       info                     Show information about connected accounts\n"
-	     "       list                     Print buddy list\n"
-	     "       ison                     Show presence state of your buddy\n"
-	     "       convo                    Open a new conversation window\n"
-	     "       send                     Send message\n"
-	     "       add                      Add buddy to buddy list\n"
-	     "       remove                   Remove buddy from list\n"
-	     "       -m, --message=MESG       Message to send or show in conversation window\n"
-	     "       -t, --to=SCREENNAME      Select a target for command\n"
-	     "       -p, --protocol=PROTO     Specify protocol to use\n"
-	     "       -f, --from=SCREENNAME    Specify screenname to use\n"
-	     "       -q, --quiet              Send message without showing a conversation\n"
-	     "                                window\n"
+/* To be implemented:
+	{ "ison", "Show presence state of your buddy", NULL, NULL },
+	{ "convo", "Open a new conversation window", NULL, NULL },
+	{ "add", "Add buddy to buddy list", NULL, NULL },
+	{ "remove", "Remove buddy from list", NULL, NULL }
 */
 
 static struct option longopts[] = {
@@ -67,21 +71,39 @@
 	{0,0,0,0}
 };
 
+/* To be implemented:
+	     "       -q, --quiet              Send message without showing a conversation\n"
+	     "                                window\n"
+*/
+
 struct remoteopts {
 	char *command;
 	char *uri;
 	gboolean help, quiet;
-	char *message, *to, *from;
-	int protocol;
-};
+	char *message, *to, *from, *protocol;
+} opts;
+
+void show_remote_usage(char *name)
+{
+	int i;
 
+	printf(_("Usage: %s command [OPTIONS] [URI]\n\n    COMMANDS:\n"), name);
+	for (i = 0; remote_commands[i].name; i++) {
+		printf("\t%-25s%s\n", gettext(remote_commands[i].name), remote_commands[i].description);
+	}
+	printf(_("\n    OPTIONS:\n"));
+	printf(_("\t-m, --message=MESG       Message to send or show in conversation window\n"));
+	printf(_("\t-t, --to=SCREENNAME      Select a target for command\n"));
+	printf(_("\t-p, --protocol=PROTO     Specify protocol to use\n"));
+	printf(_("\t-f, --from=SCREENNAME    Specify screenname to use\n"));
+	printf(_("\t-h, --help [command]     Show help for command\n\n"));
+	return;
+}
 
-struct remoteopts opts;
 int get_options(int argc, char *argv[])
 {
 	int i;
 	memset(&opts, 0, sizeof(opts));
-	opts.protocol = -1;
 	while ((i=getopt_long(argc, argv, "m:t:p:f:qh", longopts, NULL)) != -1) {
 		switch (i) {
 		case 'm':
@@ -91,7 +113,7 @@
 			opts.to = optarg;
 			break;
 		case 'p':
-			/* Do stuff here. */
+			opts.protocol = optarg;
 			break;
 		case 'f':
 			opts.from = optarg;
@@ -128,74 +150,204 @@
 }
 
 
-int command_uri() {
-	int fd = 0;
-	GaimRemotePacket *p = NULL;
-	fd = gaim_remote_session_connect(0);
-	if (!fd) {
-		fprintf(stderr, _("Gaim not running (on session 0)\n"));
+int command_uri(int fd) {
+	if(opts.uri){
+		GaimRemotePacket *p = gaim_remote_packet_new(CUI_TYPE_REMOTE, CUI_REMOTE_URI);
+		gaim_remote_packet_append_string(p, opts.uri);
+		gaim_remote_session_send_packet (fd, p);
+		gaim_remote_packet_free(p);
+		return 0;
+	}else{
+		fprintf(stderr, _("URI not specified\n"));
 		return 1;
 	}
-	p = gaim_remote_packet_new(CUI_TYPE_REMOTE, CUI_REMOTE_URI);
-	gaim_remote_packet_append_string(p, opts.uri);
-	gaim_remote_session_send_packet(fd, p);
-	close(fd);
+}
+
+int command_quit(int fd) {
+	GaimRemotePacket *p = gaim_remote_packet_new(CUI_TYPE_META, CUI_META_QUIT);
+	gaim_remote_session_send_packet (fd, p);
 	gaim_remote_packet_free(p);
 	return 0;
 }
 
-int command_quit() {
-	int fd = 0;
-	GaimRemotePacket *p = NULL;
-	fd = gaim_remote_session_connect(0);
-	if (!fd) {
-		fprintf(stderr, _("Gaim not running (on session 0)\n"));
+void show_longhelp_uri(){
+	printf ("\n"
+
+	"Using AIM: URIs:\n"
+	"Sending an IM to a screenname:\n"
+	"	gaim-remote uri 'aim:goim?screenname=Penguin&message=hello+world'\n"
+	"In this case, 'Penguin' is the screenname we wish to IM, and 'hello world'\n"
+	"is the message to be sent.  '+' must be used in place of spaces.\n"
+	"Please note the quoting used above - if you run this from a shell the '&'\n"
+	"needs to be escaped, or the command will stop at that point.\n"
+	"Also,the following will just open a conversation window to a screenname,\n"
+	"with no message:\n"
+	"	gaim-remote uri aim:goim?screenname=Penguin\n\n"
+	"Joining a chat:\n"
+	"	gaim-remote uri aim:gochat?roomname=PenguinLounge\n"
+	"...joins the 'PenguinLounge' chat room.\n\n"
+	"Adding a buddy to your buddy list:\n"
+	"	gaim-remote uri aim:addbuddy?screenname=Penguin\n"
+	"...prompts you to add 'Penguin' to your buddy list.\n"
+	);
+	return;
+}
+
+void show_longhelp_send(){
+	printf ("\n"
+
+	"gaim-remote send:\n"
+	"To send messages with gaim-remote, you must specify the recipient,\n"
+	"sender, protocol, and message.\n"
+	"ex:\n"
+	"\tgaim-remote send --to=penguin --from=the_bucket --proto=prpl-irc\n"
+	"\t--message=\"this is from gaim-remote\"\n"
+	"In this case, 'penguin' is the screenname of the recipient,\n"
+	"'the_bucket' is the screenname of the account we are sending from,\n"
+	"the protocol id is prpl-irc, and the message is obvious.\n"
+	);
+	return;
+}
+
+void show_longhelp_list(){
+	printf ("\n"
+
+	"gaim-remote list:\n"
+	"Returns a copy of your buddy list in the following format:\n"
+	"Group\n"
+	" 	Buddy, Away? [0/1], Alias, (Acct, Proto) that buddy belongs to \n"
+	"\n"
+	"Detailed explanation of values for each buddy who is signed on:\n"
+	"\tBuddy - the screen name of the buddy\n"
+	"\tAway? [0/1] - if the buddy is away, a '1' will be printed\n"
+	"\tAlias - the alias of the buddy\n"
+	"\tAcct - the screenname of the account that the buddy belongs to\n"
+	"\tProto - the protocol of the aforementioned account\n"
+	);
+	return;
+}
+
+int command_info(int fd){
+       int len;
+       GaimRemotePacket *p =gaim_remote_packet_new(CUI_TYPE_REMOTE, CUI_REMOTE_CONNECTIONS);
+       char *info;
+       gaim_remote_session_send_packet (fd, p);
+
+       p = (GaimRemotePacket*)gaim_remote_session_read_packet(fd);
+       len=p->length;
+       info = g_malloc(len + 1);
+       memcpy(info, p->data, len);
+       info[len] = 0;
+       printf("%s",info);
+       g_free(info);
+       gaim_remote_packet_free(p);
+       return 0;
+}
+
+int command_list(int fd){
+       int len;
+       GaimRemotePacket *p =gaim_remote_packet_new(CUI_TYPE_REMOTE, CUI_REMOTE_BLIST);
+       char *info;
+       /*Output format:
+	* Group
+	* 	Buddy, Away? [0/1], Alias, (Acct, Proto) that buddy belongs to 
+	*-JBS
+	*/
+       
+       gaim_remote_session_send_packet (fd, p);
+
+       p = (GaimRemotePacket*)gaim_remote_session_read_packet(fd);
+       len=p->length;
+       info = g_malloc(len + 1);
+       memcpy(info, p->data, len);
+       info[len] = 0;
+       printf("%s",info);
+       g_free(info);
+       gaim_remote_packet_free(p);
+       return 0;
+}
+
+int command_send(int fd) {
+       	int len;
+       	char temp[10003];
+	GaimRemotePacket *p = gaim_remote_packet_new(CUI_TYPE_REMOTE, CUI_REMOTE_SEND); 
+	/*Format is as follows:
+	 *Each string has a 4 character 'header' containing the length of the string
+	 *The strings are: To, From, Protocol name, Message
+	 *Following the message is the quiet flag, expressed in a single int (0/1)
+	 *Because the header is 4 characters long, there is a 9999 char limit on any
+	 *given string, though none of these strings should be exceeding this.
+	 *-JBS 
+	 */
+
+	if(opts.to && *opts.to && opts.from && *opts.from && opts.protocol && *opts.protocol && opts.message && *opts.message  && (strlen(opts.to) <10000) && (strlen(opts.from) <10000) && (strlen(opts.protocol) <20) && (strlen(opts.message) <10000) ){ 
+
+		sprintf(temp, "%04d%s", strlen(opts.to), opts.to);
+		gaim_remote_packet_append_string(p, temp);
+		sprintf(temp, "%04d%s", strlen(opts.from), opts.from);
+		gaim_remote_packet_append_string(p, temp);
+		sprintf(temp, "%04d%s", strlen(opts.protocol), opts.protocol);
+		gaim_remote_packet_append_string(p, temp);
+		sprintf(temp, "%04d%s", strlen(opts.message), opts.message);
+		gaim_remote_packet_append_string(p, temp);
+		sprintf(temp, "%d", 0);/*quiet flag - off for now*/
+		gaim_remote_packet_append_string(p, temp);
+
+		gaim_remote_session_send_packet (fd, p);
+		gaim_remote_packet_free(p);
+		return 0;
+	}else{
+		fprintf(stderr, _("Insufficient arguments (-t, -f, -p, & -m are all required) or arguments greater than 9999 chars\n"));
 		return 1;
 	}
-	p = gaim_remote_packet_new(CUI_TYPE_META, CUI_META_QUIT);
-	gaim_remote_session_send_packet(fd, p);
-	close(fd);
-	gaim_remote_packet_free(p);
-	return 0;
 }
 
-void show_longhelp_uri( char *name, char *command){
-	if(!strcmp(command, "uri")) {
-		printf (_("\n"
-			  "Using AIM: URIs:\n"
-			  "Sending an IM to a screenname:\n"
-			  "	gaim-remote uri 'aim:goim?screenname=Penguin&message=hello+world'\n"
-			  "In this case, 'Penguin' is the screenname we wish to IM, and 'hello world'\n"
-			  "is the message to be sent.  '+' must be used in place of spaces.\n"
-			  "Please note the quoting used above - if you run this from a shell the '&'\n"
-			  "needs to be escaped, or the command will stop at that point.\n"
-			  "Also,the following will just open a conversation window to a screenname,\n"
-			  "with no message:\n"
-			  "	gaim-remote uri aim:goim?screenname=Penguin\n\n"
-			  "Joining a chat:\n"
-			  "	gaim-remote uri aim:gochat?roomname=PenguinLounge\n"
-			  "...joins the 'PenguinLounge' chat room.\n\n"
-			  "Adding a buddy to your buddy list:\n"
-			  "	gaim-remote uri aim:addbuddy?screenname=Penguin\n"
-			  "...prompts you to add 'Penguin' to your buddy list.\n")
-			);
-	}
-	else if(!strcmp(command, "quit")) {
-		printf (_("\nClose running copy of Gaim\n"));
-	}
-	else {
-		show_remote_usage(name);
+#if 0
+int command_away(int fd) {
+       	int len, all;
+       	char temp[10003];
+	GaimRemotePacket *p = gaim_remote_packet_new(CUI_TYPE_REMOTE, CUI_REMOTE_AWAY); 
+	/*Format is as follows:
+	 *Preceding the message is the 'all' flag, expressed in a single int (0/1)
+	 *Each string has a 4 character 'header' containing the length of the string
+	 *The strings are: All?, From, Protocol name, Message
+	 *Because the header is 4 characters long, there is a 9999 char limit on any
+	 *given string, though none of these strings should be exceeding this.
+	 *-JBS 
+	 */
+
+	if(opts.from && *opts.from && opts.protocol && *opts.protocol)
+		all=0;
+	else
+		all=1;
+
+		sprintf(temp, "%d", all);/*All?*/
+		gaim_remote_packet_append_string(p, temp);
+	/*Evil test -- if single acct & valid entry, or all & no entry concerned*/
+	if(   (    ((all==0)&& (opts.from && *opts.from && opts.protocol && *opts.protocol && (strlen(opts.from) <10000) && (strlen(opts.protocol) <20) )) || (all==1) ) && opts.message && *opts.message  &&  (strlen(opts.message) <10000) ){ 
+
+		if(all==0){
+			sprintf(temp, "%04d%s", strlen(opts.from), opts.from);
+			gaim_remote_packet_append_string(p, temp);
+			sprintf(temp, "%04d%s", strlen(opts.protocol), opts.protocol);
+			gaim_remote_packet_append_string(p, temp);
+		}
+		sprintf(temp, "%04d%s", strlen(opts.message), opts.message);
+		gaim_remote_packet_append_string(p, temp);
+
+		gaim_remote_session_send_packet (fd, p);
+		gaim_remote_packet_free(p);
+		return 0;
+	}else{
+		fprintf(stderr, _("Insufficient arguments (-f, -p, & -m are all required) or arguments greater than 9999 chars\n"));
+		return 1;
 	}
 }
-
-/* Work in progress - JBS
-int command_info(){
-	fprintf(stderr, "Info not yet implemented\n");
-    return 1;
-}*/
+#endif
 
 int main (int argc, char *argv[])
 {
+	int i, fd, ret;
 
 #ifdef ENABLE_NLS
 	setlocale (LC_ALL, "");
@@ -203,31 +355,34 @@
 	bind_textdomain_codeset(PACKAGE, "UTF-8");
 	textdomain(PACKAGE);
 #endif
-
+	
 	if (get_options(argc, argv)) {
 		show_remote_usage(argv[0]);
 		return 0;
 	}
-	
-	
-	if (!strcmp(opts.command, "uri")) {
-		if(opts.help){
-			show_longhelp_uri(argv[0], "uri");
-		}else{
-			return command_uri();
-		}
-/*	} else if (!strcmp(opts.command, "info")) {
-		return command_info();*/
-	} else if (!strcmp(opts.command, "quit")) {
-		if(opts.help){
-			show_longhelp_uri(argv[0], "quit");
-		}else{
-			return command_quit();
+
+	for (i = 0; remote_commands[i].name; i++) {
+		if (!strcmp(opts.command, remote_commands[i].name)) {
+			if (opts.help) {
+				if (remote_commands[i].longhelp) {
+					remote_commands[i].longhelp();
+				} else {
+					printf(_("No help available for %s\n"), opts.command);
+				}
+				return 0;
+			}
+			fd = gaim_remote_session_connect(0);
+			if (!fd) {
+				fprintf(stderr, _("Gaim not running (on session 0)\n"));
+				return 1;
+			}
+			ret = remote_commands[i].cmdfunc(fd);
+			close(fd);
+			return ret;
 		}
-	} else {
-		show_remote_usage(argv[0]);
-		return 1;
 	}
-	
-	return 0;
+
+	/* No commands matched */
+	show_remote_usage(argv[0]);
+	return 1;
 }
