Mercurial > pidgin
annotate src/gaim-remote.c @ 7369:be94c4be25b4
[gaim-migrate @ 7964]
gtksourceiter.c added
committer: Tailor Script <tailor@pidgin.im>
author | Herman Bloggs <hermanator12002@yahoo.com> |
---|---|
date | Wed, 29 Oct 2003 17:03:20 +0000 |
parents | 0dfe02111e20 |
children | 613b20c69d2c |
rev | line source |
---|---|
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 | |
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 |
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 | |
6643 | 114 if(opts.help) |
115 return 0; | |
116 | |
3480 | 117 /* And we can have another argument--the URI. */ |
6643 | 118 /* but only if we're using the uri command. */ |
119 if (!strcmp(opts.command, "uri")) { | |
120 if(argc-optind==1) | |
3480 | 121 opts.uri = g_strdup(argv[optind++]); |
122 else | |
123 return 1; | |
124 } | |
6643 | 125 else if(optind==argc) |
126 return 0; | |
127 else | |
128 return 1; | |
129 | |
130 return 0; | |
3480 | 131 } |
132 | |
133 | |
134 int command_uri() { | |
135 int fd = 0; | |
5859
022786c7ab53
[gaim-migrate @ 6290]
Christian Hammond <chipx86@chipx86.com>
parents:
5124
diff
changeset
|
136 GaimRemotePacket *p = NULL; |
022786c7ab53
[gaim-migrate @ 6290]
Christian Hammond <chipx86@chipx86.com>
parents:
5124
diff
changeset
|
137 fd = gaim_remote_session_connect(0); |
6643 | 138 if (fd<0) { |
5116 | 139 fprintf(stderr, _("Gaim not running (on session 0)\n")); |
3480 | 140 return 1; |
141 } | |
5859
022786c7ab53
[gaim-migrate @ 6290]
Christian Hammond <chipx86@chipx86.com>
parents:
5124
diff
changeset
|
142 p = gaim_remote_packet_new(CUI_TYPE_REMOTE, CUI_REMOTE_URI); |
022786c7ab53
[gaim-migrate @ 6290]
Christian Hammond <chipx86@chipx86.com>
parents:
5124
diff
changeset
|
143 gaim_remote_packet_append_string(p, opts.uri); |
022786c7ab53
[gaim-migrate @ 6290]
Christian Hammond <chipx86@chipx86.com>
parents:
5124
diff
changeset
|
144 gaim_remote_session_send_packet(fd, p); |
3480 | 145 close(fd); |
5859
022786c7ab53
[gaim-migrate @ 6290]
Christian Hammond <chipx86@chipx86.com>
parents:
5124
diff
changeset
|
146 gaim_remote_packet_free(p); |
3480 | 147 return 0; |
148 } | |
149 | |
3559 | 150 int command_quit() { |
151 int fd = 0; | |
5859
022786c7ab53
[gaim-migrate @ 6290]
Christian Hammond <chipx86@chipx86.com>
parents:
5124
diff
changeset
|
152 GaimRemotePacket *p = NULL; |
022786c7ab53
[gaim-migrate @ 6290]
Christian Hammond <chipx86@chipx86.com>
parents:
5124
diff
changeset
|
153 fd = gaim_remote_session_connect(0); |
6643 | 154 if (fd<0) { |
5116 | 155 fprintf(stderr, _("Gaim not running (on session 0)\n")); |
3559 | 156 return 1; |
157 } | |
5859
022786c7ab53
[gaim-migrate @ 6290]
Christian Hammond <chipx86@chipx86.com>
parents:
5124
diff
changeset
|
158 p = gaim_remote_packet_new(CUI_TYPE_META, CUI_META_QUIT); |
022786c7ab53
[gaim-migrate @ 6290]
Christian Hammond <chipx86@chipx86.com>
parents:
5124
diff
changeset
|
159 gaim_remote_session_send_packet(fd, p); |
3559 | 160 close(fd); |
5859
022786c7ab53
[gaim-migrate @ 6290]
Christian Hammond <chipx86@chipx86.com>
parents:
5124
diff
changeset
|
161 gaim_remote_packet_free(p); |
3559 | 162 return 0; |
163 } | |
164 | |
5116 | 165 void show_longhelp_uri( char *name, char *command){ |
166 if(!strcmp(command, "uri")) { | |
167 printf (_("\n" | |
168 "Using AIM: URIs:\n" | |
169 "Sending an IM to a screenname:\n" | |
170 " gaim-remote uri 'aim:goim?screenname=Penguin&message=hello+world'\n" | |
171 "In this case, 'Penguin' is the screenname we wish to IM, and 'hello world'\n" | |
172 "is the message to be sent. '+' must be used in place of spaces.\n" | |
173 "Please note the quoting used above - if you run this from a shell the '&'\n" | |
174 "needs to be escaped, or the command will stop at that point.\n" | |
175 "Also,the following will just open a conversation window to a screenname,\n" | |
176 "with no message:\n" | |
177 " gaim-remote uri aim:goim?screenname=Penguin\n\n" | |
178 "Joining a chat:\n" | |
179 " gaim-remote uri aim:gochat?roomname=PenguinLounge\n" | |
180 "...joins the 'PenguinLounge' chat room.\n\n" | |
181 "Adding a buddy to your buddy list:\n" | |
182 " gaim-remote uri aim:addbuddy?screenname=Penguin\n" | |
183 "...prompts you to add 'Penguin' to your buddy list.\n") | |
184 ); | |
185 } | |
186 else if(!strcmp(command, "quit")) { | |
187 printf (_("\nClose running copy of Gaim\n")); | |
188 } | |
189 else { | |
190 show_remote_usage(name); | |
191 } | |
4242 | 192 } |
193 | |
194 /* Work in progress - JBS | |
3867 | 195 int command_info(){ |
196 fprintf(stderr, "Info not yet implemented\n"); | |
197 return 1; | |
4242 | 198 }*/ |
3480 | 199 |
3559 | 200 int main (int argc, char *argv[]) |
3480 | 201 { |
202 | |
5116 | 203 #ifdef ENABLE_NLS |
204 setlocale (LC_ALL, ""); | |
205 bindtextdomain(PACKAGE, LOCALEDIR); | |
206 bind_textdomain_codeset(PACKAGE, "UTF-8"); | |
207 textdomain(PACKAGE); | |
208 #endif | |
209 | |
3480 | 210 if (get_options(argc, argv)) { |
211 show_remote_usage(argv[0]); | |
212 return 0; | |
213 } | |
214 | |
215 | |
216 if (!strcmp(opts.command, "uri")) { | |
4242 | 217 if(opts.help){ |
5116 | 218 show_longhelp_uri(argv[0], "uri"); |
4242 | 219 }else{ |
220 return command_uri(); | |
221 } | |
222 /* } else if (!strcmp(opts.command, "info")) { | |
223 return command_info();*/ | |
3559 | 224 } else if (!strcmp(opts.command, "quit")) { |
5116 | 225 if(opts.help){ |
226 show_longhelp_uri(argv[0], "quit"); | |
227 }else{ | |
228 return command_quit(); | |
229 } | |
3480 | 230 } else { |
231 show_remote_usage(argv[0]); | |
232 return 1; | |
233 } | |
234 | |
235 return 0; | |
236 } |