3480
|
1 /*
|
|
2 * gaim-remote
|
|
3 *
|
|
4 * Copyright (C) 2002, Sean Egan <bj91704@binghamton.edu>
|
4242
|
5 * Features/functionality added (C) 2002, John B. Silvestri <silvestrij@mville.edu>
|
|
6 * 'quit', long help for URIs
|
3480
|
7 *
|
|
8 * This program is free software; you can redistribute it and/or modify
|
|
9 * it under the terms of the GNU General Public License as published by
|
|
10 * the Free Software Foundation; either version 2 of the License, or
|
|
11 * (at your option) any later version.
|
|
12 *
|
|
13 * This program is distributed in the hope that it will be useful,
|
|
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
16 * GNU General Public License for more details.
|
|
17 *
|
|
18 * You should have received a copy of the GNU General Public License
|
|
19 * along with this program; if not, write to the Free Software
|
|
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
21 *
|
|
22 */
|
|
23
|
|
24 #include "gaim.h"
|
3533
|
25 #include <getopt.h>
|
3867
|
26 #include <unistd.h>
|
4235
|
27 #include <string.h>
|
5124
|
28 #include <locale.h>
|
3480
|
29 #include "gaim-socket.h"
|
|
30
|
4242
|
31 void show_remote_usage(char *name)
|
3480
|
32 {
|
|
33 printf(_("Usage: %s command [OPTIONS] [URI]\n\n"
|
4242
|
34
|
3480
|
35 " COMMANDS:\n"
|
4242
|
36 " uri Handle AIM: URI\n"
|
|
37 " quit Close running copy of Gaim\n\n"
|
|
38
|
|
39 " OPTIONS:\n"
|
|
40 " -h, --help [commmand] Show help for command\n"), name);
|
|
41 return;
|
|
42 }
|
|
43
|
|
44 /*To be implemented:
|
3480
|
45 " info Show information about connected accounts\n"
|
|
46 " list Print buddy list\n"
|
|
47 " ison Show presence state of your buddy\n"
|
|
48 " convo Open a new conversation window\n"
|
|
49 " send Send message\n"
|
|
50 " add Add buddy to buddy list\n"
|
3559
|
51 " remove Remove buddy from list\n"
|
3480
|
52 " -m, --message=MESG Message to send or show in conversation window\n"
|
|
53 " -t, --to=SCREENNAME Select a target for command\n"
|
|
54 " -p, --protocol=PROTO Specify protocol to use\n"
|
|
55 " -f, --from=SCREENNAME Specify screenname to use\n"
|
4242
|
56 " -q, --quiet Send message without showing a conversation\n"
|
3480
|
57 " window\n"
|
4242
|
58 */
|
3480
|
59
|
|
60 static struct option longopts[] = {
|
|
61 {"message", required_argument, NULL, 'm'},
|
|
62 {"to", required_argument, NULL, 't'},
|
|
63 {"protocol",required_argument, NULL, 'p'},
|
|
64 {"from", required_argument, NULL, 'f'},
|
|
65 {"quiet", no_argument, NULL, 'q'},
|
|
66 {"help", no_argument, NULL, 'h'},
|
|
67 {0,0,0,0}
|
|
68 };
|
|
69
|
|
70 struct remoteopts {
|
|
71 char *command;
|
|
72 char *uri;
|
|
73 gboolean help, quiet;
|
|
74 char *message, *to, *from;
|
|
75 int protocol;
|
|
76 };
|
|
77
|
|
78
|
|
79 struct remoteopts opts;
|
|
80 int get_options(int argc, char *argv[])
|
|
81 {
|
|
82 int i;
|
|
83 memset(&opts, 0, sizeof(opts));
|
|
84 opts.protocol = -1;
|
|
85 while ((i=getopt_long(argc, argv, "m:t:p:f:qh", longopts, NULL)) != -1) {
|
|
86 switch (i) {
|
|
87 case 'm':
|
|
88 opts.message = optarg;
|
|
89 break;
|
|
90 case 't':
|
|
91 opts.to = optarg;
|
|
92 break;
|
|
93 case 'p':
|
|
94 /* Do stuff here. */
|
|
95 break;
|
|
96 case 'f':
|
|
97 opts.from = optarg;
|
|
98 break;
|
|
99 case 'q':
|
|
100 opts.quiet = TRUE;
|
|
101 break;
|
|
102 case 'h':
|
|
103 opts.help = TRUE;
|
|
104 break;
|
|
105 }
|
|
106 }
|
|
107
|
|
108 /* We must have non getopt'ed argument-- the command */
|
|
109 if (optind < argc)
|
|
110 opts.command = g_strdup(argv[optind++]);
|
|
111 else
|
|
112 return 1;
|
|
113
|
|
114 /* And we can have another argument--the URI. */
|
|
115 if (optind < argc) {
|
|
116 /* but only if we're using the uri command. */
|
|
117 if (!strcmp(opts.command, "uri"))
|
|
118 opts.uri = g_strdup(argv[optind++]);
|
|
119 else
|
|
120 return 1;
|
|
121
|
|
122 /* and we can't have any others. */
|
|
123 if (optind < argc)
|
|
124 return 1;
|
|
125 }
|
|
126
|
|
127 return 0;
|
|
128 }
|
|
129
|
|
130
|
|
131 int command_uri() {
|
|
132 int fd = 0;
|
|
133 struct gaim_cui_packet *p = NULL;
|
|
134 fd = gaim_connect_to_session(0);
|
|
135 if (!fd) {
|
5116
|
136 fprintf(stderr, _("Gaim not running (on session 0)\n"));
|
3480
|
137 return 1;
|
|
138 }
|
|
139 p = cui_packet_new(CUI_TYPE_REMOTE, CUI_REMOTE_URI);
|
|
140 cui_packet_append_string(p, opts.uri);
|
|
141 cui_send_packet (fd, p);
|
|
142 close(fd);
|
|
143 cui_packet_free(p);
|
|
144 return 0;
|
|
145 }
|
|
146
|
3559
|
147 int command_quit() {
|
|
148 int fd = 0;
|
|
149 struct gaim_cui_packet *p = NULL;
|
|
150 fd = gaim_connect_to_session(0);
|
|
151 if (!fd) {
|
5116
|
152 fprintf(stderr, _("Gaim not running (on session 0)\n"));
|
3559
|
153 return 1;
|
|
154 }
|
|
155 p = cui_packet_new(CUI_TYPE_META, CUI_META_QUIT);
|
|
156 cui_send_packet (fd, p);
|
|
157 close(fd);
|
|
158 cui_packet_free(p);
|
|
159 return 0;
|
|
160 }
|
|
161
|
5116
|
162 void show_longhelp_uri( char *name, char *command){
|
|
163 if(!strcmp(command, "uri")) {
|
|
164 printf (_("\n"
|
|
165 "Using AIM: URIs:\n"
|
|
166 "Sending an IM to a screenname:\n"
|
|
167 " gaim-remote uri 'aim:goim?screenname=Penguin&message=hello+world'\n"
|
|
168 "In this case, 'Penguin' is the screenname we wish to IM, and 'hello world'\n"
|
|
169 "is the message to be sent. '+' must be used in place of spaces.\n"
|
|
170 "Please note the quoting used above - if you run this from a shell the '&'\n"
|
|
171 "needs to be escaped, or the command will stop at that point.\n"
|
|
172 "Also,the following will just open a conversation window to a screenname,\n"
|
|
173 "with no message:\n"
|
|
174 " gaim-remote uri aim:goim?screenname=Penguin\n\n"
|
|
175 "Joining a chat:\n"
|
|
176 " gaim-remote uri aim:gochat?roomname=PenguinLounge\n"
|
|
177 "...joins the 'PenguinLounge' chat room.\n\n"
|
|
178 "Adding a buddy to your buddy list:\n"
|
|
179 " gaim-remote uri aim:addbuddy?screenname=Penguin\n"
|
|
180 "...prompts you to add 'Penguin' to your buddy list.\n")
|
|
181 );
|
|
182 }
|
|
183 else if(!strcmp(command, "quit")) {
|
|
184 printf (_("\nClose running copy of Gaim\n"));
|
|
185 }
|
|
186 else {
|
|
187 show_remote_usage(name);
|
|
188 }
|
4242
|
189 }
|
|
190
|
|
191 /* Work in progress - JBS
|
3867
|
192 int command_info(){
|
|
193 fprintf(stderr, "Info not yet implemented\n");
|
|
194 return 1;
|
4242
|
195 }*/
|
3480
|
196
|
3559
|
197 int main (int argc, char *argv[])
|
3480
|
198 {
|
|
199
|
5116
|
200 #ifdef ENABLE_NLS
|
|
201 setlocale (LC_ALL, "");
|
|
202 bindtextdomain(PACKAGE, LOCALEDIR);
|
|
203 bind_textdomain_codeset(PACKAGE, "UTF-8");
|
|
204 textdomain(PACKAGE);
|
|
205 #endif
|
|
206
|
3480
|
207 if (get_options(argc, argv)) {
|
|
208 show_remote_usage(argv[0]);
|
|
209 return 0;
|
|
210 }
|
|
211
|
|
212
|
|
213 if (!strcmp(opts.command, "uri")) {
|
4242
|
214 if(opts.help){
|
5116
|
215 show_longhelp_uri(argv[0], "uri");
|
4242
|
216 }else{
|
|
217 return command_uri();
|
|
218 }
|
|
219 /* } else if (!strcmp(opts.command, "info")) {
|
|
220 return command_info();*/
|
3559
|
221 } else if (!strcmp(opts.command, "quit")) {
|
5116
|
222 if(opts.help){
|
|
223 show_longhelp_uri(argv[0], "quit");
|
|
224 }else{
|
|
225 return command_quit();
|
|
226 }
|
3480
|
227 } else {
|
|
228 show_remote_usage(argv[0]);
|
|
229 return 1;
|
|
230 }
|
|
231
|
|
232 return 0;
|
|
233 }
|