diff src/gaim-remote.c @ 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 8793c7127c80
children c892b6dbc341
line wrap: on
line diff
--- 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");