changeset 10003:33431f91e4a8

[gaim-migrate @ 10920] (21:42:10) JBSilvest: see away msg :) (21:42:29) Luke: awesome (21:42:47) JBSilvest: it could probably use a glance at by a second pair of eyes, but it works (21:43:02) JBSilvest: oh, i should do the obligatory thing, shouldn't i? (21:43:15) JBSilvest: [^H] (21:43:31) JBSilvest: Hello World (21:43:53) JBSilvest: [john@tux-laptop gaim]$ gaim-remote send -t lschiere -f JBSilvest -p prpl-oscar -m "Hello World" (21:44:27) JBSilvest: i shain't think there are any memleak risks or other baddies, but i won't profess to being a highly skilled C programmer (21:45:06) Luke: so is it ready? (21:45:16) JBSilvest: more or less (21:45:26) JBSilvest: could use more strings/docs, but it definitely works (21:47:51) JBSilvest: someone will no doubt bitch & moan about 9999-char limit, but until someone can recommend a better way || i redo the whole sys., that'll be it (21:49:13) JBSilvest: *and* thinking about things, there is blessedly no risk of remote buffer overflow or any such crap :-D (21:49:21) JBSilvest: it has to be run by the user :) (21:49:25) Luke: okay, so this patch does what now? it lets you send and not just put text in the input widget and what else? (21:49:40) Luke: or the web browser (21:49:42) JBSilvest: it lets you send...period :) (21:49:52) JBSilvest: from the command line/scripts (21:49:56) Luke: for instance if you made gaim-remote your handler for aim: uris (21:50:02) JBSilvest: no (21:50:06) JBSilvest: that's not what this does (21:50:12) JBSilvest: it doesn't parse aim:uris (21:50:16) Luke: ah (21:50:17) JBSilvest: it's for sending messages themselves committer: Tailor Script <tailor@pidgin.im>
author Luke Schierer <lschiere@pidgin.im>
date Fri, 10 Sep 2004 01:51:02 +0000
parents 8ba9a9048d73
children 690ef036f297
files ChangeLog plugins/gaim-remote/remote.c src/gaim-remote.c
diffstat 3 files changed, 166 insertions(+), 30 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Fri Sep 10 01:43:41 2004 +0000
+++ b/ChangeLog	Fri Sep 10 01:51:02 2004 +0000
@@ -1,4 +1,8 @@
 Gaim: The Pimpin' Penguin IM Client that's good for the soul!
+
+version 2.0.0
+	* gaim-remote can send text (John B. Silvestri)
+
 version 0.83:
 	New Features:
 	* Drag-and-drop buddy support for the Invite dialog (Stu Tomlinson)
--- a/plugins/gaim-remote/remote.c	Fri Sep 10 01:43:41 2004 +0000
+++ b/plugins/gaim-remote/remote.c	Fri Sep 10 01:51:02 2004 +0000
@@ -70,7 +70,7 @@
 	GaimConnection *gc = NULL;
 	GaimAccount *account;
 
-	gaim_debug(GAIM_DEBUG_INFO, "gaim_remote_handle_uri", "Handling URI: %s\n", uri);
+	gaim_debug_info("gaim_remote_handle_uri", "Handling URI: %s\n", uri);
 
 	/* Well, we'd better check to make sure we have at least one
 	   AIM account connected. */
@@ -158,7 +158,7 @@
 			g_string_free(str, TRUE);
 		}
 
-		gaim_debug(GAIM_DEBUG_MISC, "gaim_remote_handle_uri", "who: %s\n", who);
+		gaim_debug_misc("gaim_remote_handle_uri", "who: %s\n", who);
 		gaim_blist_request_add_buddy(gc->account, who, group, NULL);
 		g_free(who);
 		if (group)
@@ -330,8 +330,7 @@
 		gaim_remote_packet_free(p);
 		break;
 	default:
-		gaim_debug(GAIM_DEBUG_WARNING, "cui",
-				   "Unhandled meta subtype %d\n", subtype);
+		gaim_debug_warning("cui", "Unhandled meta subtype %d\n", subtype);
 		break;
 	}
 
@@ -362,8 +361,7 @@
 		}
 		break;
 	default:
-		gaim_debug(GAIM_DEBUG_WARNING, "cui",
-				   "Unhandled plugin subtype %d\n", subtype);
+		gaim_debug_warning("cui", "Unhandled plugin subtype %d\n", subtype);
 		break;
 	}
 #endif
@@ -414,8 +412,7 @@
                 break;
 #endif /* STATUS */
 	default:
-		gaim_debug(GAIM_DEBUG_WARNING, "cui",
-				   "Unhandled user subtype %d\n", subtype);
+		gaim_debug_warning("cui", "Unhandled user subtype %d\n", subtype);
 		break;
 	}
 }
@@ -463,8 +460,7 @@
 	case CUI_MESSAGE_RECV:
 		break;
 	default:
-		gaim_debug(GAIM_DEBUG_WARNING, "cui",
-				   "Unhandled message subtype %d\n", subtype);
+		gaim_debug_warning("cui", "Unhandled message subtype %d\n", subtype);
 		break;
 	}
 }
@@ -496,9 +492,89 @@
 {
 	const char *resp;
 	char *send;
+
+	GList *c = gaim_connections_get_all();
+	GaimConnection *gc;
+	GaimAccount *account;
+
 	switch (subtype) {
 	case CUI_REMOTE_CONNECTIONS:
 		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_info("cui", "Got `gaim-remote send` packet\n",data);
+			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_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_conv_im_send(GAIM_CONV_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_URI:
 		send = g_malloc(len + 1);
 		memcpy(send, data, len);
@@ -508,8 +584,7 @@
 		/* report error */
 		break;
 	default:
-		gaim_debug(GAIM_DEBUG_WARNING, "cui",
-				   "Unhandled remote subtype %d\n", subtype);
+		gaim_debug_warning("cui", "Unhandled remote subtype %d\n", subtype);
 		break;
 	}
 }
@@ -529,7 +604,7 @@
 
 	/* no byte order worries! this'll change if we go to TCP */
 	if (gaim_recv(source, &type, sizeof(type)) != sizeof(type)) {
-		gaim_debug(GAIM_DEBUG_ERROR, "cui", "UI has abandoned us!\n");
+		gaim_debug_error("cui", "UI has abandoned us!\n");
 		uis = g_slist_remove(uis, ui);
 		g_io_channel_shutdown(ui->channel, TRUE, &error);
 		if(error) {
@@ -542,7 +617,7 @@
 	}
 
 	if (gaim_recv(source, &subtype, sizeof(subtype)) != sizeof(subtype)) {
-		gaim_debug(GAIM_DEBUG_ERROR, "cui", "UI has abandoned us!\n");
+		gaim_debug_error("cui", "UI has abandoned us!\n");
 		uis = g_slist_remove(uis, ui);
 		g_io_channel_shutdown(ui->channel, TRUE, &error);
 		if(error) {
@@ -555,7 +630,7 @@
 	}
 
 	if (gaim_recv(source, (gchar *)&len, sizeof(len)) != sizeof(len)) {
-		gaim_debug(GAIM_DEBUG_ERROR, "cui", "UI has abandoned us!\n");
+		gaim_debug_error("cui", "UI has abandoned us!\n");
 		uis = g_slist_remove(uis, ui);
 		g_io_channel_shutdown(ui->channel, TRUE, &error);
 		if(error) {
@@ -570,7 +645,7 @@
 	if (len) {
 		in = g_new0(gchar, len);
 		if (gaim_recv(source, in, len) != len) {
-			gaim_debug(GAIM_DEBUG_ERROR, "cui", "UI has abandoned us!\n");
+			gaim_debug_error("cui", "UI has abandoned us!\n");
 			uis = g_slist_remove(uis, ui);
 			g_io_channel_shutdown(ui->channel, TRUE, &error);
 			if(error) {
@@ -614,8 +689,7 @@
 			remote_handler(ui, subtype, in, len);
 			break; 
         default:
-			gaim_debug(GAIM_DEBUG_WARNING, "cui",
-					   "Unhandled type %d\n", type);
+			gaim_debug_warning("cui", "Unhandled type %d\n", type);
 			break;
 	}
 
@@ -643,7 +717,7 @@
 	ui->inpa = g_io_add_watch(ui->channel, G_IO_IN | G_IO_HUP | G_IO_ERR, UI_readable, ui);
 	g_io_channel_unref(ui->channel);
 
-	gaim_debug(GAIM_DEBUG_MISC, "cui", "Got one\n");
+	gaim_debug_misc("cui", "Got one\n");
 	return TRUE;
 }
 
@@ -656,7 +730,7 @@
 	while (gaim_remote_session_exists(gaim_session))
 		gaim_session++;
 	
-	gaim_debug(GAIM_DEBUG_MISC, "cui", "Session: %d\n", gaim_session);
+	gaim_debug_misc("cui", "Session: %d\n", gaim_session);
 	
 	if ((fd = socket(AF_UNIX, SOCK_STREAM, 0)) != -1) {
 		mode_t m = umask(0177);
@@ -720,7 +794,7 @@
 
 	unlink(buf);
 
-	gaim_debug(GAIM_DEBUG_MISC, "core", "Removed core\n");
+	gaim_debug_misc("core", "Removed core\n");
 
 	return TRUE;
 #else
--- a/src/gaim-remote.c	Fri Sep 10 01:43:41 2004 +0000
+++ b/src/gaim-remote.c	Fri Sep 10 01:51:02 2004 +0000
@@ -32,13 +32,8 @@
 	     "       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 screen name to use\n"
 	     "       -q, --quiet              Send message without showing a conversation\n"
 	     "                                window\n"
 */
@@ -57,8 +52,8 @@
 	char *command;
 	char *uri;
 	gboolean help, quiet;
-	char *message, *to, *from;
-	int protocol;
+	char *message, *to, *from, *protocol;
+	/*int protocol;*/
 };
 struct remoteopts opts;
 
@@ -110,8 +105,13 @@
 		"       uri                      Handle AIM: URI\n"
 		"       away                     Popup the away dialog with the default message\n"
 		"       back                     Remove the away dialog\n"
+		"       send                     Send message\n"
 		"       quit                     Close running copy of Gaim\n\n"
 		"    OPTIONS:\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 screen name to use\n"
 		"       -h, --help [command]     Show help for command\n"), name);
 
 	message(text, 1);
@@ -126,7 +126,7 @@
 	int i;
 
 	memset(&opts, 0, sizeof(opts));
-	opts.protocol = -1;
+	/*opts.protocol = -1;*/
 
 	while ((i=getopt_long(argc, argv, "m:t:p:f:qh", longopts, NULL)) != -1) {
 		switch (i) {
@@ -137,7 +137,7 @@
 			opts.to = optarg;
 			break;
 		case 'p':
-			/* Do stuff here. */
+			opts.protocol = optarg;
 			break;
 		case 'f':
 			opts.from = optarg;
@@ -212,6 +212,53 @@
 	return 0;
 }
 
+static int
+send_command_send() {
+	int fd = 0;
+	GaimRemotePacket *p = NULL;
+	char temp[10003]; /*TODO: Future implementation should send packets instead */
+
+	fd = gaim_remote_session_connect(0);
+	if (fd < 0) {
+		message(_("Gaim not running (on session 0)\nIs the \"Remote Control\" plugin loaded?\n"), 2);
+		return 1;
+	}
+	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);
+		close(fd);
+		gaim_remote_packet_free(p);
+		return 0;
+	}else{
+		message(_("Insufficient arguments (-t, -f, -p, & -m are all required) or arguments greater than 9999 chars\n"), 2);
+		close(fd);
+		gaim_remote_packet_free(p);
+ 		return 1;
+ 	}
+
+}
+
 static void
 show_longhelp( char *name, char *command)
 {
@@ -247,6 +294,10 @@
 		message(_("\nSet all accounts as not away.\n"), 1);
 	}
 
+	else if (!strcmp(command, "send")) {
+		message(_("\nSend instant message\n"), 1);
+	}
+
 	else {
 		show_remote_usage(name);
 	}
@@ -273,6 +324,13 @@
 			return send_command_uri();
 	}
 
+	else if (!strcmp(opts.command, "send")) {
+		if (opts.help)
+			show_longhelp(argv[0], "send");
+		else
+			return send_command_send();
+	}
+
 	else if (!strcmp(opts.command, "away")) {
 		if (opts.help)
 			show_longhelp(argv[0], "away");