Mercurial > pidgin
annotate src/gaim-remote.c @ 8150:20262ccefdd8
[gaim-migrate @ 8862]
Nope, it's humor. Trust me, I know--I define it.
Oh, also, this should make oscar ssi lists take precedence over
local lists. So if you sign on while you're in Rome and delete
someone, the next time you sign in with Gaim the dude will be
deleted from your local list as well.
committer: Tailor Script <tailor@pidgin.im>
author | Mark Doliner <mark@kingant.net> |
---|---|
date | Tue, 20 Jan 2004 15:27:33 +0000 |
parents | fa6395637e2c |
children | 82aeed3c90f0 |
rev | line source |
---|---|
3480 | 1 /* |
2 * gaim-remote | |
3 * | |
8046 | 4 * Gaim is the legal property of its developers, whose names are too numerous |
5 * to list here. Please refer to the COPYRIGHT file distributed with this | |
6 * source distribution. | |
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 | |
5872
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5859
diff
changeset
|
24 #include "internal.h" |
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5859
diff
changeset
|
25 |
3533 | 26 #include <getopt.h> |
5124 | 27 #include <locale.h> |
5859
022786c7ab53
[gaim-migrate @ 6290]
Christian Hammond <chipx86@chipx86.com>
parents:
5124
diff
changeset
|
28 |
022786c7ab53
[gaim-migrate @ 6290]
Christian Hammond <chipx86@chipx86.com>
parents:
5124
diff
changeset
|
29 #include <gaim-remote/remote.h> |
3480 | 30 |
7724 | 31 /* writes a message 'text' to screen |
32 * message tries to convert 'text' from utf-8 to user's locale and | |
33 * uses the original message 'text' as a fallback | |
34 * | |
35 * if channel is 1, the message is printed to stdout | |
36 * if channel is 2, the message is printed to stderr | |
37 */ | |
38 void message(char *text,int channel) | |
39 { | |
40 char *text_conv=NULL,*text_output; | |
41 GError *error=NULL; | |
42 | |
43 text_conv=g_locale_from_utf8(text,-1,NULL,NULL,&error); | |
44 | |
45 if(!text_conv) { | |
46 g_warning("%s\n", error->message); | |
47 g_error_free(error); | |
48 } | |
49 | |
50 text_output=(text_conv ? text_conv : text); | |
51 | |
52 switch(channel) { | |
53 case 1: puts(text_output); break; | |
54 case 2: fputs(text_output, stderr); break; | |
55 default: break; | |
56 } | |
57 | |
58 if(text_conv) | |
59 g_free(text_conv); | |
60 } | |
61 | |
4242 | 62 void show_remote_usage(char *name) |
3480 | 63 { |
7724 | 64 char *text=NULL; |
65 | |
66 text=g_strdup_printf(_("Usage: %s command [OPTIONS] [URI]\n\n" | |
4242 | 67 |
3480 | 68 " COMMANDS:\n" |
4242 | 69 " uri Handle AIM: URI\n" |
70 " quit Close running copy of Gaim\n\n" | |
71 | |
72 " OPTIONS:\n" | |
73 " -h, --help [commmand] Show help for command\n"), name); | |
7724 | 74 |
75 message(text,1); | |
76 g_free(text); | |
77 | |
4242 | 78 return; |
79 } | |
80 | |
81 /*To be implemented: | |
3480 | 82 " info Show information about connected accounts\n" |
83 " list Print buddy list\n" | |
84 " ison Show presence state of your buddy\n" | |
85 " convo Open a new conversation window\n" | |
86 " send Send message\n" | |
87 " add Add buddy to buddy list\n" | |
3559 | 88 " remove Remove buddy from list\n" |
3480 | 89 " -m, --message=MESG Message to send or show in conversation window\n" |
90 " -t, --to=SCREENNAME Select a target for command\n" | |
91 " -p, --protocol=PROTO Specify protocol to use\n" | |
92 " -f, --from=SCREENNAME Specify screenname to use\n" | |
4242 | 93 " -q, --quiet Send message without showing a conversation\n" |
3480 | 94 " window\n" |
4242 | 95 */ |
3480 | 96 |
97 static struct option longopts[] = { | |
98 {"message", required_argument, NULL, 'm'}, | |
99 {"to", required_argument, NULL, 't'}, | |
100 {"protocol",required_argument, NULL, 'p'}, | |
101 {"from", required_argument, NULL, 'f'}, | |
102 {"quiet", no_argument, NULL, 'q'}, | |
103 {"help", no_argument, NULL, 'h'}, | |
104 {0,0,0,0} | |
105 }; | |
106 | |
107 struct remoteopts { | |
108 char *command; | |
109 char *uri; | |
110 gboolean help, quiet; | |
111 char *message, *to, *from; | |
112 int protocol; | |
113 }; | |
114 | |
115 | |
116 struct remoteopts opts; | |
117 int get_options(int argc, char *argv[]) | |
118 { | |
119 int i; | |
120 memset(&opts, 0, sizeof(opts)); | |
121 opts.protocol = -1; | |
122 while ((i=getopt_long(argc, argv, "m:t:p:f:qh", longopts, NULL)) != -1) { | |
123 switch (i) { | |
124 case 'm': | |
125 opts.message = optarg; | |
126 break; | |
127 case 't': | |
128 opts.to = optarg; | |
129 break; | |
130 case 'p': | |
131 /* Do stuff here. */ | |
132 break; | |
133 case 'f': | |
134 opts.from = optarg; | |
135 break; | |
136 case 'q': | |
137 opts.quiet = TRUE; | |
138 break; | |
139 case 'h': | |
140 opts.help = TRUE; | |
141 break; | |
142 } | |
143 } | |
144 | |
145 /* We must have non getopt'ed argument-- the command */ | |
146 if (optind < argc) | |
147 opts.command = g_strdup(argv[optind++]); | |
148 else | |
149 return 1; | |
150 | |
6643 | 151 if(opts.help) |
152 return 0; | |
153 | |
3480 | 154 /* And we can have another argument--the URI. */ |
6643 | 155 /* but only if we're using the uri command. */ |
156 if (!strcmp(opts.command, "uri")) { | |
157 if(argc-optind==1) | |
3480 | 158 opts.uri = g_strdup(argv[optind++]); |
159 else | |
160 return 1; | |
161 } | |
6643 | 162 else if(optind==argc) |
163 return 0; | |
164 else | |
165 return 1; | |
166 | |
167 return 0; | |
3480 | 168 } |
169 | |
170 int command_uri() { | |
171 int fd = 0; | |
5859
022786c7ab53
[gaim-migrate @ 6290]
Christian Hammond <chipx86@chipx86.com>
parents:
5124
diff
changeset
|
172 GaimRemotePacket *p = NULL; |
022786c7ab53
[gaim-migrate @ 6290]
Christian Hammond <chipx86@chipx86.com>
parents:
5124
diff
changeset
|
173 fd = gaim_remote_session_connect(0); |
6643 | 174 if (fd<0) { |
7724 | 175 message(_("Gaim not running (on session 0)\n"),2); |
3480 | 176 return 1; |
177 } | |
5859
022786c7ab53
[gaim-migrate @ 6290]
Christian Hammond <chipx86@chipx86.com>
parents:
5124
diff
changeset
|
178 p = gaim_remote_packet_new(CUI_TYPE_REMOTE, CUI_REMOTE_URI); |
022786c7ab53
[gaim-migrate @ 6290]
Christian Hammond <chipx86@chipx86.com>
parents:
5124
diff
changeset
|
179 gaim_remote_packet_append_string(p, opts.uri); |
022786c7ab53
[gaim-migrate @ 6290]
Christian Hammond <chipx86@chipx86.com>
parents:
5124
diff
changeset
|
180 gaim_remote_session_send_packet(fd, p); |
3480 | 181 close(fd); |
5859
022786c7ab53
[gaim-migrate @ 6290]
Christian Hammond <chipx86@chipx86.com>
parents:
5124
diff
changeset
|
182 gaim_remote_packet_free(p); |
3480 | 183 return 0; |
184 } | |
185 | |
3559 | 186 int command_quit() { |
187 int fd = 0; | |
5859
022786c7ab53
[gaim-migrate @ 6290]
Christian Hammond <chipx86@chipx86.com>
parents:
5124
diff
changeset
|
188 GaimRemotePacket *p = NULL; |
022786c7ab53
[gaim-migrate @ 6290]
Christian Hammond <chipx86@chipx86.com>
parents:
5124
diff
changeset
|
189 fd = gaim_remote_session_connect(0); |
6643 | 190 if (fd<0) { |
7724 | 191 message(_("Gaim not running (on session 0)\n"),2); |
3559 | 192 return 1; |
193 } | |
5859
022786c7ab53
[gaim-migrate @ 6290]
Christian Hammond <chipx86@chipx86.com>
parents:
5124
diff
changeset
|
194 p = gaim_remote_packet_new(CUI_TYPE_META, CUI_META_QUIT); |
022786c7ab53
[gaim-migrate @ 6290]
Christian Hammond <chipx86@chipx86.com>
parents:
5124
diff
changeset
|
195 gaim_remote_session_send_packet(fd, p); |
3559 | 196 close(fd); |
5859
022786c7ab53
[gaim-migrate @ 6290]
Christian Hammond <chipx86@chipx86.com>
parents:
5124
diff
changeset
|
197 gaim_remote_packet_free(p); |
3559 | 198 return 0; |
199 } | |
200 | |
7724 | 201 void show_longhelp_uri( char *name, char *command) |
202 { | |
5116 | 203 if(!strcmp(command, "uri")) { |
7724 | 204 message(_("\n" |
205 "Using AIM: URIs:\n" | |
206 "Sending an IM to a screenname:\n" | |
207 " gaim-remote uri 'aim:goim?screenname=Penguin&message=hello+world'\n" | |
208 "In this case, 'Penguin' is the screenname we wish to IM, and 'hello world'\n" | |
209 "is the message to be sent. '+' must be used in place of spaces.\n" | |
210 "Please note the quoting used above - if you run this from a shell the '&'\n" | |
211 "needs to be escaped, or the command will stop at that point.\n" | |
212 "Also,the following will just open a conversation window to a screenname,\n" | |
213 "with no message:\n" | |
214 " gaim-remote uri 'aim:goim?screenname=Penguin'\n\n" | |
215 "Joining a chat:\n" | |
216 " gaim-remote uri 'aim:gochat?roomname=PenguinLounge'\n" | |
217 "...joins the 'PenguinLounge' chat room.\n\n" | |
218 "Adding a buddy to your buddy list:\n" | |
219 " gaim-remote uri 'aim:addbuddy?screenname=Penguin'\n" | |
220 "...prompts you to add 'Penguin' to your buddy list.\n"), 1); | |
5116 | 221 } |
222 else if(!strcmp(command, "quit")) { | |
7724 | 223 message(_("\nClose running copy of Gaim\n"), 1); |
5116 | 224 } |
225 else { | |
226 show_remote_usage(name); | |
227 } | |
4242 | 228 } |
229 | |
230 /* Work in progress - JBS | |
3867 | 231 int command_info(){ |
232 fprintf(stderr, "Info not yet implemented\n"); | |
233 return 1; | |
4242 | 234 }*/ |
3480 | 235 |
3559 | 236 int main (int argc, char *argv[]) |
3480 | 237 { |
238 | |
5116 | 239 #ifdef ENABLE_NLS |
240 setlocale (LC_ALL, ""); | |
241 bindtextdomain(PACKAGE, LOCALEDIR); | |
242 bind_textdomain_codeset(PACKAGE, "UTF-8"); | |
243 textdomain(PACKAGE); | |
244 #endif | |
245 | |
3480 | 246 if (get_options(argc, argv)) { |
247 show_remote_usage(argv[0]); | |
248 return 0; | |
249 } | |
250 | |
251 | |
252 if (!strcmp(opts.command, "uri")) { | |
4242 | 253 if(opts.help){ |
5116 | 254 show_longhelp_uri(argv[0], "uri"); |
4242 | 255 }else{ |
256 return command_uri(); | |
257 } | |
258 /* } else if (!strcmp(opts.command, "info")) { | |
259 return command_info();*/ | |
3559 | 260 } else if (!strcmp(opts.command, "quit")) { |
5116 | 261 if(opts.help){ |
262 show_longhelp_uri(argv[0], "quit"); | |
263 }else{ | |
264 return command_quit(); | |
265 } | |
3480 | 266 } else { |
267 show_remote_usage(argv[0]); | |
268 return 1; | |
269 } | |
270 | |
271 return 0; | |
272 } |