3480
|
1 /*
|
|
2 * gaim-remote
|
|
3 *
|
|
4 * Copyright (C) 2002, Sean Egan <bj91704@binghamton.edu>
|
|
5 *
|
|
6 * This program is free software; you can redistribute it and/or modify
|
|
7 * it under the terms of the GNU General Public License as published by
|
|
8 * the Free Software Foundation; either version 2 of the License, or
|
|
9 * (at your option) any later version.
|
|
10 *
|
|
11 * This program is distributed in the hope that it will be useful,
|
|
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
14 * GNU General Public License for more details.
|
|
15 *
|
|
16 * You should have received a copy of the GNU General Public License
|
|
17 * along with this program; if not, write to the Free Software
|
|
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
19 *
|
|
20 */
|
|
21
|
|
22 #include "gaim.h"
|
3533
|
23 #include <getopt.h>
|
3867
|
24 #include <unistd.h>
|
3480
|
25 #include "gaim-socket.h"
|
|
26
|
|
27 void show_remote_usage(char *name)
|
|
28 {
|
|
29 printf(_("Usage: %s command [OPTIONS] [URI]\n\n"
|
|
30
|
|
31 " COMMANDS:\n"
|
|
32 " uri Handle AIM:// URI\n"
|
|
33 " info Show information about connected accounts\n"
|
|
34 " list Print buddy list\n"
|
|
35 " ison Show presence state of your buddy\n"
|
|
36 " convo Open a new conversation window\n"
|
|
37 " send Send message\n"
|
|
38 " add Add buddy to buddy list\n"
|
3559
|
39 " remove Remove buddy from list\n"
|
|
40 " quit Close running copy of Gaim\n\n"
|
3480
|
41
|
|
42 " OPTIONS:\n"
|
|
43 " -m, --message=MESG Message to send or show in conversation window\n"
|
|
44 " -t, --to=SCREENNAME Select a target for command\n"
|
|
45 " -p, --protocol=PROTO Specify protocol to use\n"
|
|
46 " -f, --from=SCREENNAME Specify screenname to use\n"
|
|
47 " -q, --quiet Send message without showing a conversation\n"
|
|
48 " window\n"
|
|
49 " -h, --help Show help for command\n"), name);
|
|
50 return;
|
|
51 }
|
|
52
|
|
53 static struct option longopts[] = {
|
|
54 {"message", required_argument, NULL, 'm'},
|
|
55 {"to", required_argument, NULL, 't'},
|
|
56 {"protocol",required_argument, NULL, 'p'},
|
|
57 {"from", required_argument, NULL, 'f'},
|
|
58 {"quiet", no_argument, NULL, 'q'},
|
|
59 {"help", no_argument, NULL, 'h'},
|
|
60 {0,0,0,0}
|
|
61 };
|
|
62
|
|
63 struct remoteopts {
|
|
64 char *command;
|
|
65 char *uri;
|
|
66 gboolean help, quiet;
|
|
67 char *message, *to, *from;
|
|
68 int protocol;
|
|
69 };
|
|
70
|
|
71
|
|
72 struct remoteopts opts;
|
|
73 int get_options(int argc, char *argv[])
|
|
74 {
|
|
75 int i;
|
|
76 memset(&opts, 0, sizeof(opts));
|
|
77 opts.protocol = -1;
|
|
78 while ((i=getopt_long(argc, argv, "m:t:p:f:qh", longopts, NULL)) != -1) {
|
|
79 switch (i) {
|
|
80 case 'm':
|
|
81 opts.message = optarg;
|
|
82 break;
|
|
83 case 't':
|
|
84 opts.to = optarg;
|
|
85 break;
|
|
86 case 'p':
|
|
87 /* Do stuff here. */
|
|
88 break;
|
|
89 case 'f':
|
|
90 opts.from = optarg;
|
|
91 break;
|
|
92 case 'q':
|
|
93 opts.quiet = TRUE;
|
|
94 break;
|
|
95 case 'h':
|
|
96 opts.help = TRUE;
|
|
97 break;
|
|
98 }
|
|
99 }
|
|
100
|
|
101 /* We must have non getopt'ed argument-- the command */
|
|
102 if (optind < argc)
|
|
103 opts.command = g_strdup(argv[optind++]);
|
|
104 else
|
|
105 return 1;
|
|
106
|
|
107 /* And we can have another argument--the URI. */
|
|
108 if (optind < argc) {
|
|
109 /* but only if we're using the uri command. */
|
|
110 if (!strcmp(opts.command, "uri"))
|
|
111 opts.uri = g_strdup(argv[optind++]);
|
|
112 else
|
|
113 return 1;
|
|
114
|
|
115 /* and we can't have any others. */
|
|
116 if (optind < argc)
|
|
117 return 1;
|
|
118 }
|
|
119
|
|
120 return 0;
|
|
121 }
|
|
122
|
|
123
|
|
124 int command_uri() {
|
|
125 int fd = 0;
|
|
126 struct gaim_cui_packet *p = NULL;
|
|
127 fd = gaim_connect_to_session(0);
|
|
128 if (!fd) {
|
|
129 fprintf(stderr, "Gaim not running (on session 0)\n");
|
|
130 return 1;
|
|
131 }
|
|
132 p = cui_packet_new(CUI_TYPE_REMOTE, CUI_REMOTE_URI);
|
|
133 cui_packet_append_string(p, opts.uri);
|
|
134 cui_send_packet (fd, p);
|
|
135 close(fd);
|
|
136 cui_packet_free(p);
|
|
137 return 0;
|
|
138 }
|
|
139
|
3559
|
140 int command_quit() {
|
|
141 int fd = 0;
|
|
142 struct gaim_cui_packet *p = NULL;
|
|
143 fd = gaim_connect_to_session(0);
|
|
144 if (!fd) {
|
|
145 fprintf(stderr, "Gaim not running (on session 0)\n");
|
|
146 return 1;
|
|
147 }
|
|
148 p = cui_packet_new(CUI_TYPE_META, CUI_META_QUIT);
|
|
149 cui_send_packet (fd, p);
|
|
150 close(fd);
|
|
151 cui_packet_free(p);
|
|
152 return 0;
|
|
153 }
|
|
154
|
3867
|
155 int command_info(){
|
|
156 fprintf(stderr, "Info not yet implemented\n");
|
|
157 return 1;
|
|
158 }
|
3480
|
159
|
3559
|
160 int main (int argc, char *argv[])
|
3480
|
161 {
|
|
162
|
|
163 if (get_options(argc, argv)) {
|
|
164 show_remote_usage(argv[0]);
|
|
165 return 0;
|
|
166 }
|
|
167
|
|
168
|
|
169 if (!strcmp(opts.command, "uri")) {
|
|
170 return command_uri();
|
|
171 } else if (!strcmp(opts.command, "info")) {
|
|
172 return command_info();
|
3559
|
173 } else if (!strcmp(opts.command, "quit")) {
|
|
174 return command_quit();
|
3480
|
175 } else {
|
|
176 show_remote_usage(argv[0]);
|
|
177 return 1;
|
|
178 }
|
|
179
|
|
180 return 0;
|
|
181 }
|