Mercurial > pidgin
annotate src/gaim-remote.c @ 9642:8901ef16f310
[gaim-migrate @ 10490]
Some changes that don't affect anything. Ethan might want to do
something with this function? I'm too lazy to read the gaim-devel
emails in detail.
committer: Tailor Script <tailor@pidgin.im>
| author | Mark Doliner <mark@kingant.net> |
|---|---|
| date | Mon, 02 Aug 2004 03:33:00 +0000 |
| parents | 204f5d66a863 |
| children | a049733e41f3 |
| 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> |
|
5859
022786c7ab53
[gaim-migrate @ 6290]
Christian Hammond <chipx86@chipx86.com>
parents:
5124
diff
changeset
|
27 |
|
022786c7ab53
[gaim-migrate @ 6290]
Christian Hammond <chipx86@chipx86.com>
parents:
5124
diff
changeset
|
28 #include <gaim-remote/remote.h> |
| 3480 | 29 |
| 7724 | 30 /* writes a message 'text' to screen |
| 31 * message tries to convert 'text' from utf-8 to user's locale and | |
| 32 * uses the original message 'text' as a fallback | |
| 33 * | |
| 34 * if channel is 1, the message is printed to stdout | |
| 35 * if channel is 2, the message is printed to stderr | |
| 36 */ | |
| 37 void message(char *text,int channel) | |
| 38 { | |
| 39 char *text_conv=NULL,*text_output; | |
| 40 GError *error=NULL; | |
| 41 | |
| 42 text_conv=g_locale_from_utf8(text,-1,NULL,NULL,&error); | |
| 43 | |
| 44 if(!text_conv) { | |
| 45 g_warning("%s\n", error->message); | |
| 46 g_error_free(error); | |
| 47 } | |
| 48 | |
| 49 text_output=(text_conv ? text_conv : text); | |
| 50 | |
| 51 switch(channel) { | |
| 52 case 1: puts(text_output); break; | |
| 53 case 2: fputs(text_output, stderr); break; | |
| 54 default: break; | |
| 55 } | |
| 56 | |
| 57 if(text_conv) | |
| 58 g_free(text_conv); | |
| 59 } | |
| 60 | |
| 4242 | 61 void show_remote_usage(char *name) |
| 3480 | 62 { |
| 7724 | 63 char *text=NULL; |
| 64 | |
| 65 text=g_strdup_printf(_("Usage: %s command [OPTIONS] [URI]\n\n" | |
| 4242 | 66 |
| 3480 | 67 " COMMANDS:\n" |
| 4242 | 68 " uri Handle AIM: URI\n" |
| 9608 | 69 " away Popup the away dialog with the default message\n" |
| 70 " back Remove the away dialog\n" | |
| 4242 | 71 " quit Close running copy of Gaim\n\n" |
| 72 | |
| 73 " OPTIONS:\n" | |
| 9184 | 74 " -h, --help [command] Show help for command\n"), name); |
| 7724 | 75 |
| 76 message(text,1); | |
| 77 g_free(text); | |
| 78 | |
| 4242 | 79 return; |
| 80 } | |
| 81 | |
| 82 /*To be implemented: | |
| 3480 | 83 " info Show information about connected accounts\n" |
| 84 " list Print buddy list\n" | |
| 85 " ison Show presence state of your buddy\n" | |
| 86 " convo Open a new conversation window\n" | |
| 87 " send Send message\n" | |
| 88 " add Add buddy to buddy list\n" | |
| 3559 | 89 " remove Remove buddy from list\n" |
| 3480 | 90 " -m, --message=MESG Message to send or show in conversation window\n" |
| 91 " -t, --to=SCREENNAME Select a target for command\n" | |
| 92 " -p, --protocol=PROTO Specify protocol to use\n" | |
| 8154 | 93 " -f, --from=SCREENNAME Specify screen name to use\n" |
| 4242 | 94 " -q, --quiet Send message without showing a conversation\n" |
| 3480 | 95 " window\n" |
| 4242 | 96 */ |
| 3480 | 97 |
| 98 static struct option longopts[] = { | |
| 99 {"message", required_argument, NULL, 'm'}, | |
| 100 {"to", required_argument, NULL, 't'}, | |
| 101 {"protocol",required_argument, NULL, 'p'}, | |
| 102 {"from", required_argument, NULL, 'f'}, | |
| 103 {"quiet", no_argument, NULL, 'q'}, | |
| 104 {"help", no_argument, NULL, 'h'}, | |
| 105 {0,0,0,0} | |
| 106 }; | |
| 107 | |
| 108 struct remoteopts { | |
| 109 char *command; | |
| 110 char *uri; | |
| 111 gboolean help, quiet; | |
| 112 char *message, *to, *from; | |
| 113 int protocol; | |
| 114 }; | |
| 115 | |
| 116 | |
| 117 struct remoteopts opts; | |
| 118 int get_options(int argc, char *argv[]) | |
| 119 { | |
| 120 int i; | |
| 121 memset(&opts, 0, sizeof(opts)); | |
| 122 opts.protocol = -1; | |
| 123 while ((i=getopt_long(argc, argv, "m:t:p:f:qh", longopts, NULL)) != -1) { | |
| 124 switch (i) { | |
| 125 case 'm': | |
| 126 opts.message = optarg; | |
| 127 break; | |
| 128 case 't': | |
| 129 opts.to = optarg; | |
| 130 break; | |
| 131 case 'p': | |
| 132 /* Do stuff here. */ | |
| 133 break; | |
| 134 case 'f': | |
| 135 opts.from = optarg; | |
| 136 break; | |
| 137 case 'q': | |
| 138 opts.quiet = TRUE; | |
| 139 break; | |
| 140 case 'h': | |
| 141 opts.help = TRUE; | |
| 142 break; | |
| 143 } | |
| 144 } | |
| 145 | |
| 146 /* We must have non getopt'ed argument-- the command */ | |
| 147 if (optind < argc) | |
| 148 opts.command = g_strdup(argv[optind++]); | |
| 149 else | |
| 150 return 1; | |
| 151 | |
| 6643 | 152 if(opts.help) |
| 153 return 0; | |
| 154 | |
| 3480 | 155 /* And we can have another argument--the URI. */ |
| 6643 | 156 /* but only if we're using the uri command. */ |
| 157 if (!strcmp(opts.command, "uri")) { | |
| 158 if(argc-optind==1) | |
| 3480 | 159 opts.uri = g_strdup(argv[optind++]); |
| 160 else | |
| 161 return 1; | |
| 162 } | |
| 6643 | 163 else if(optind==argc) |
| 164 return 0; | |
| 165 else | |
| 166 return 1; | |
| 167 | |
| 168 return 0; | |
| 3480 | 169 } |
| 170 | |
| 171 int command_uri() { | |
| 172 int fd = 0; | |
|
5859
022786c7ab53
[gaim-migrate @ 6290]
Christian Hammond <chipx86@chipx86.com>
parents:
5124
diff
changeset
|
173 GaimRemotePacket *p = NULL; |
|
022786c7ab53
[gaim-migrate @ 6290]
Christian Hammond <chipx86@chipx86.com>
parents:
5124
diff
changeset
|
174 fd = gaim_remote_session_connect(0); |
| 6643 | 175 if (fd<0) { |
| 7724 | 176 message(_("Gaim not running (on session 0)\n"),2); |
| 3480 | 177 return 1; |
| 178 } | |
|
5859
022786c7ab53
[gaim-migrate @ 6290]
Christian Hammond <chipx86@chipx86.com>
parents:
5124
diff
changeset
|
179 p = gaim_remote_packet_new(CUI_TYPE_REMOTE, CUI_REMOTE_URI); |
|
022786c7ab53
[gaim-migrate @ 6290]
Christian Hammond <chipx86@chipx86.com>
parents:
5124
diff
changeset
|
180 gaim_remote_packet_append_string(p, opts.uri); |
|
022786c7ab53
[gaim-migrate @ 6290]
Christian Hammond <chipx86@chipx86.com>
parents:
5124
diff
changeset
|
181 gaim_remote_session_send_packet(fd, p); |
| 3480 | 182 close(fd); |
|
5859
022786c7ab53
[gaim-migrate @ 6290]
Christian Hammond <chipx86@chipx86.com>
parents:
5124
diff
changeset
|
183 gaim_remote_packet_free(p); |
| 3480 | 184 return 0; |
| 185 } | |
| 186 | |
| 3559 | 187 int command_quit() { |
| 188 int fd = 0; | |
|
5859
022786c7ab53
[gaim-migrate @ 6290]
Christian Hammond <chipx86@chipx86.com>
parents:
5124
diff
changeset
|
189 GaimRemotePacket *p = NULL; |
|
022786c7ab53
[gaim-migrate @ 6290]
Christian Hammond <chipx86@chipx86.com>
parents:
5124
diff
changeset
|
190 fd = gaim_remote_session_connect(0); |
| 6643 | 191 if (fd<0) { |
| 7724 | 192 message(_("Gaim not running (on session 0)\n"),2); |
| 3559 | 193 return 1; |
| 194 } | |
|
5859
022786c7ab53
[gaim-migrate @ 6290]
Christian Hammond <chipx86@chipx86.com>
parents:
5124
diff
changeset
|
195 p = gaim_remote_packet_new(CUI_TYPE_META, CUI_META_QUIT); |
|
022786c7ab53
[gaim-migrate @ 6290]
Christian Hammond <chipx86@chipx86.com>
parents:
5124
diff
changeset
|
196 gaim_remote_session_send_packet(fd, p); |
| 3559 | 197 close(fd); |
|
5859
022786c7ab53
[gaim-migrate @ 6290]
Christian Hammond <chipx86@chipx86.com>
parents:
5124
diff
changeset
|
198 gaim_remote_packet_free(p); |
| 3559 | 199 return 0; |
| 200 } | |
| 201 | |
| 9608 | 202 int command_away() |
| 203 { | |
| 204 int fd = 0; | |
| 205 GaimRemotePacket *p = NULL; | |
| 206 fd = gaim_remote_session_connect(0); | |
| 207 if (fd<0) { | |
| 208 message(_("Gaim not running (on session 0)\n"),2); | |
| 209 return 1; | |
| 210 } | |
| 211 p = gaim_remote_packet_new(CUI_TYPE_USER, CUI_USER_AWAY); | |
| 212 gaim_remote_session_send_packet(fd, p); | |
| 213 close(fd); | |
| 214 gaim_remote_packet_free(p); | |
| 215 return 0; | |
| 216 } | |
| 217 | |
| 218 int command_back() | |
| 219 { | |
| 220 int fd = 0; | |
| 221 GaimRemotePacket *p = NULL; | |
| 222 fd = gaim_remote_session_connect(0); | |
| 223 if (fd<0) { | |
| 224 message(_("Gaim not running (on session 0)\n"),2); | |
| 225 return 1; | |
| 226 } | |
| 227 p = gaim_remote_packet_new(CUI_TYPE_USER, CUI_USER_BACK); | |
| 228 gaim_remote_session_send_packet(fd, p); | |
| 229 close(fd); | |
| 230 gaim_remote_packet_free(p); | |
| 231 return 0; | |
| 232 } | |
| 233 | |
| 234 | |
| 7724 | 235 void show_longhelp_uri( char *name, char *command) |
| 236 { | |
| 5116 | 237 if(!strcmp(command, "uri")) { |
| 7724 | 238 message(_("\n" |
| 239 "Using AIM: URIs:\n" | |
| 8152 | 240 "Sending an IM to a screen name:\n" |
| 7724 | 241 " gaim-remote uri 'aim:goim?screenname=Penguin&message=hello+world'\n" |
| 8152 | 242 "In this case, 'Penguin' is the screen name we wish to IM, and 'hello world'\n" |
| 7724 | 243 "is the message to be sent. '+' must be used in place of spaces.\n" |
| 244 "Please note the quoting used above - if you run this from a shell the '&'\n" | |
| 245 "needs to be escaped, or the command will stop at that point.\n" | |
| 8152 | 246 "Also,the following will just open a conversation window to a screen name,\n" |
| 7724 | 247 "with no message:\n" |
| 248 " gaim-remote uri 'aim:goim?screenname=Penguin'\n\n" | |
| 249 "Joining a chat:\n" | |
| 250 " gaim-remote uri 'aim:gochat?roomname=PenguinLounge'\n" | |
| 251 "...joins the 'PenguinLounge' chat room.\n\n" | |
| 252 "Adding a buddy to your buddy list:\n" | |
| 253 " gaim-remote uri 'aim:addbuddy?screenname=Penguin'\n" | |
| 254 "...prompts you to add 'Penguin' to your buddy list.\n"), 1); | |
| 5116 | 255 } |
| 256 else if(!strcmp(command, "quit")) { | |
| 7724 | 257 message(_("\nClose running copy of Gaim\n"), 1); |
| 5116 | 258 } |
| 259 else { | |
| 260 show_remote_usage(name); | |
| 261 } | |
| 4242 | 262 } |
| 263 | |
| 264 /* Work in progress - JBS | |
| 3867 | 265 int command_info(){ |
| 266 fprintf(stderr, "Info not yet implemented\n"); | |
| 267 return 1; | |
| 4242 | 268 }*/ |
| 3480 | 269 |
| 3559 | 270 int main (int argc, char *argv[]) |
| 3480 | 271 { |
| 272 | |
| 5116 | 273 #ifdef ENABLE_NLS |
| 274 setlocale (LC_ALL, ""); | |
| 275 bindtextdomain(PACKAGE, LOCALEDIR); | |
| 276 bind_textdomain_codeset(PACKAGE, "UTF-8"); | |
| 277 textdomain(PACKAGE); | |
| 278 #endif | |
| 279 | |
| 3480 | 280 if (get_options(argc, argv)) { |
| 281 show_remote_usage(argv[0]); | |
| 282 return 0; | |
| 283 } | |
| 284 | |
| 285 | |
| 286 if (!strcmp(opts.command, "uri")) { | |
| 4242 | 287 if(opts.help){ |
| 5116 | 288 show_longhelp_uri(argv[0], "uri"); |
| 4242 | 289 }else{ |
| 290 return command_uri(); | |
| 291 } | |
| 292 /* } else if (!strcmp(opts.command, "info")) { | |
| 293 return command_info();*/ | |
| 9608 | 294 } else if (!strcmp(opts.command, "away")) { |
| 295 return command_away(); | |
| 296 } else if (!strcmp(opts.command, "back")) { | |
| 297 return command_back(); | |
| 3559 | 298 } else if (!strcmp(opts.command, "quit")) { |
| 5116 | 299 if(opts.help){ |
| 300 show_longhelp_uri(argv[0], "quit"); | |
| 301 }else{ | |
| 302 return command_quit(); | |
| 303 } | |
| 3480 | 304 } else { |
| 305 show_remote_usage(argv[0]); | |
| 306 return 1; | |
| 307 } | |
| 308 | |
| 309 return 0; | |
| 310 } |
