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>
|
3480
|
28 #include "gaim-socket.h"
|
|
29
|
4242
|
30 void show_remote_usage(char *name)
|
3480
|
31 {
|
|
32 printf(_("Usage: %s command [OPTIONS] [URI]\n\n"
|
4242
|
33
|
3480
|
34 " COMMANDS:\n"
|
4242
|
35 " uri Handle AIM: URI\n"
|
|
36 " quit Close running copy of Gaim\n\n"
|
|
37
|
|
38 " OPTIONS:\n"
|
|
39 " -h, --help [commmand] Show help for command\n"), name);
|
|
40 return;
|
|
41 }
|
|
42
|
|
43 /*To be implemented:
|
3480
|
44 " info Show information about connected accounts\n"
|
|
45 " list Print buddy list\n"
|
|
46 " ison Show presence state of your buddy\n"
|
|
47 " convo Open a new conversation window\n"
|
|
48 " send Send message\n"
|
|
49 " add Add buddy to buddy list\n"
|
3559
|
50 " remove Remove buddy from list\n"
|
3480
|
51 " -m, --message=MESG Message to send or show in conversation window\n"
|
|
52 " -t, --to=SCREENNAME Select a target for command\n"
|
|
53 " -p, --protocol=PROTO Specify protocol to use\n"
|
|
54 " -f, --from=SCREENNAME Specify screenname to use\n"
|
4242
|
55 " -q, --quiet Send message without showing a conversation\n"
|
3480
|
56 " window\n"
|
4242
|
57 */
|
3480
|
58
|
|
59 static struct option longopts[] = {
|
|
60 {"message", required_argument, NULL, 'm'},
|
|
61 {"to", required_argument, NULL, 't'},
|
|
62 {"protocol",required_argument, NULL, 'p'},
|
|
63 {"from", required_argument, NULL, 'f'},
|
|
64 {"quiet", no_argument, NULL, 'q'},
|
|
65 {"help", no_argument, NULL, 'h'},
|
|
66 {0,0,0,0}
|
|
67 };
|
|
68
|
|
69 struct remoteopts {
|
|
70 char *command;
|
|
71 char *uri;
|
|
72 gboolean help, quiet;
|
|
73 char *message, *to, *from;
|
|
74 int protocol;
|
|
75 };
|
|
76
|
|
77
|
|
78 struct remoteopts opts;
|
|
79 int get_options(int argc, char *argv[])
|
|
80 {
|
|
81 int i;
|
|
82 memset(&opts, 0, sizeof(opts));
|
|
83 opts.protocol = -1;
|
|
84 while ((i=getopt_long(argc, argv, "m:t:p:f:qh", longopts, NULL)) != -1) {
|
|
85 switch (i) {
|
|
86 case 'm':
|
|
87 opts.message = optarg;
|
|
88 break;
|
|
89 case 't':
|
|
90 opts.to = optarg;
|
|
91 break;
|
|
92 case 'p':
|
|
93 /* Do stuff here. */
|
|
94 break;
|
|
95 case 'f':
|
|
96 opts.from = optarg;
|
|
97 break;
|
|
98 case 'q':
|
|
99 opts.quiet = TRUE;
|
|
100 break;
|
|
101 case 'h':
|
|
102 opts.help = TRUE;
|
|
103 break;
|
|
104 }
|
|
105 }
|
|
106
|
|
107 /* We must have non getopt'ed argument-- the command */
|
|
108 if (optind < argc)
|
|
109 opts.command = g_strdup(argv[optind++]);
|
|
110 else
|
|
111 return 1;
|
|
112
|
|
113 /* And we can have another argument--the URI. */
|
|
114 if (optind < argc) {
|
|
115 /* but only if we're using the uri command. */
|
|
116 if (!strcmp(opts.command, "uri"))
|
|
117 opts.uri = g_strdup(argv[optind++]);
|
|
118 else
|
|
119 return 1;
|
|
120
|
|
121 /* and we can't have any others. */
|
|
122 if (optind < argc)
|
|
123 return 1;
|
|
124 }
|
|
125
|
|
126 return 0;
|
|
127 }
|
|
128
|
|
129
|
|
130 int command_uri() {
|
|
131 int fd = 0;
|
|
132 struct gaim_cui_packet *p = NULL;
|
|
133 fd = gaim_connect_to_session(0);
|
|
134 if (!fd) {
|
|
135 fprintf(stderr, "Gaim not running (on session 0)\n");
|
|
136 return 1;
|
|
137 }
|
|
138 p = cui_packet_new(CUI_TYPE_REMOTE, CUI_REMOTE_URI);
|
|
139 cui_packet_append_string(p, opts.uri);
|
|
140 cui_send_packet (fd, p);
|
|
141 close(fd);
|
|
142 cui_packet_free(p);
|
|
143 return 0;
|
|
144 }
|
|
145
|
3559
|
146 int command_quit() {
|
|
147 int fd = 0;
|
|
148 struct gaim_cui_packet *p = NULL;
|
|
149 fd = gaim_connect_to_session(0);
|
|
150 if (!fd) {
|
|
151 fprintf(stderr, "Gaim not running (on session 0)\n");
|
|
152 return 1;
|
|
153 }
|
|
154 p = cui_packet_new(CUI_TYPE_META, CUI_META_QUIT);
|
|
155 cui_send_packet (fd, p);
|
|
156 close(fd);
|
|
157 cui_packet_free(p);
|
|
158 return 0;
|
|
159 }
|
|
160
|
4242
|
161 void show_longhelp_uri(){
|
|
162 printf ("\n"
|
|
163
|
|
164 "Using AIM: URIs:\n"
|
|
165 "Sending an IM to a screenname:\n"
|
|
166 " gaim-remote uri 'aim:goim?screenname=Penguin&message=hello+world'\n"
|
|
167 "In this case, 'Penguin' is the screenname we wish to IM, and 'hello world'\n"
|
|
168 "is the message to be sent. '+' must be used in place of spaces.\n"
|
|
169 "Please note the quoting used above - if you run this from a shell the '&'\n"
|
|
170 "needs to be escaped, or the command will stop at that point.\n"
|
|
171 "Also,the following will just open a conversation window to a screenname,\n"
|
|
172 "with no message:\n"
|
|
173 " gaim-remote uri aim:goim?screenname=Penguin\n\n"
|
|
174 "Joining a chat:\n"
|
|
175 " gaim-remote uri aim:gochat?roomname=PenguinLounge\n"
|
|
176 "...joins the 'PenguinLounge' chat room.\n\n"
|
|
177 "Adding a buddy to your buddy list:\n"
|
|
178 " gaim-remote uri aim:addbuddy?screenname=Penguin\n"
|
|
179 "...prompts you to add 'Penguin' to your buddy list.\n"
|
|
180 );
|
|
181 return;
|
|
182 }
|
|
183
|
|
184 /* Work in progress - JBS
|
3867
|
185 int command_info(){
|
|
186 fprintf(stderr, "Info not yet implemented\n");
|
|
187 return 1;
|
4242
|
188 }*/
|
3480
|
189
|
3559
|
190 int main (int argc, char *argv[])
|
3480
|
191 {
|
|
192
|
|
193 if (get_options(argc, argv)) {
|
|
194 show_remote_usage(argv[0]);
|
|
195 return 0;
|
|
196 }
|
|
197
|
|
198
|
|
199 if (!strcmp(opts.command, "uri")) {
|
4242
|
200 if(opts.help){
|
|
201 show_longhelp_uri();
|
|
202 }else{
|
|
203 return command_uri();
|
|
204 }
|
|
205 /* } else if (!strcmp(opts.command, "info")) {
|
|
206 return command_info();*/
|
3559
|
207 } else if (!strcmp(opts.command, "quit")) {
|
|
208 return command_quit();
|
3480
|
209 } else {
|
|
210 show_remote_usage(argv[0]);
|
|
211 return 1;
|
|
212 }
|
|
213
|
|
214 return 0;
|
|
215 }
|