3480
|
1 /*
|
|
2 * gaim-remote
|
|
3 *
|
|
4 * Copyright (C) 2002, Sean Egan <bj91704@binghamton.edu>
|
|
5 *
|
|
6 * This program is free software; you can redistribute it and/or modify
|
|
7 * it under the terms of the GNU General Public License as published by
|
|
8 * the Free Software Foundation; either version 2 of the License, or
|
|
9 * (at your option) any later version.
|
|
10 *
|
|
11 * This program is distributed in the hope that it will be useful,
|
|
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
14 * GNU General Public License for more details.
|
|
15 *
|
|
16 * You should have received a copy of the GNU General Public License
|
|
17 * along with this program; if not, write to the Free Software
|
|
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
19 *
|
|
20 */
|
|
21
|
|
22 #include "gaim.h"
|
3533
|
23 #include <getopt.h>
|
3480
|
24 #include "gaim-socket.h"
|
|
25
|
|
26 void show_remote_usage(char *name)
|
|
27 {
|
|
28 printf(_("Usage: %s command [OPTIONS] [URI]\n\n"
|
|
29
|
|
30 " COMMANDS:\n"
|
|
31 " uri Handle AIM:// URI\n"
|
|
32 " info Show information about connected accounts\n"
|
|
33 " list Print buddy list\n"
|
|
34 " ison Show presence state of your buddy\n"
|
|
35 " convo Open a new conversation window\n"
|
|
36 " send Send message\n"
|
|
37 " add Add buddy to buddy list\n"
|
3559
|
38 " remove Remove buddy from list\n"
|
|
39 " quit Close running copy of Gaim\n\n"
|
3480
|
40
|
|
41 " OPTIONS:\n"
|
|
42 " -m, --message=MESG Message to send or show in conversation window\n"
|
|
43 " -t, --to=SCREENNAME Select a target for command\n"
|
|
44 " -p, --protocol=PROTO Specify protocol to use\n"
|
|
45 " -f, --from=SCREENNAME Specify screenname to use\n"
|
|
46 " -q, --quiet Send message without showing a conversation\n"
|
|
47 " window\n"
|
|
48 " -h, --help Show help for command\n"), name);
|
|
49 return;
|
|
50 }
|
|
51
|
|
52 static struct option longopts[] = {
|
|
53 {"message", required_argument, NULL, 'm'},
|
|
54 {"to", required_argument, NULL, 't'},
|
|
55 {"protocol",required_argument, NULL, 'p'},
|
|
56 {"from", required_argument, NULL, 'f'},
|
|
57 {"quiet", no_argument, NULL, 'q'},
|
|
58 {"help", no_argument, NULL, 'h'},
|
|
59 {0,0,0,0}
|
|
60 };
|
|
61
|
|
62 struct remoteopts {
|
|
63 char *command;
|
|
64 char *uri;
|
|
65 gboolean help, quiet;
|
|
66 char *message, *to, *from;
|
|
67 int protocol;
|
|
68 };
|
|
69
|
|
70
|
|
71 struct remoteopts opts;
|
|
72 int get_options(int argc, char *argv[])
|
|
73 {
|
|
74 int i;
|
|
75 memset(&opts, 0, sizeof(opts));
|
|
76 opts.protocol = -1;
|
|
77 while ((i=getopt_long(argc, argv, "m:t:p:f:qh", longopts, NULL)) != -1) {
|
|
78 switch (i) {
|
|
79 case 'm':
|
|
80 opts.message = optarg;
|
|
81 break;
|
|
82 case 't':
|
|
83 opts.to = optarg;
|
|
84 break;
|
|
85 case 'p':
|
|
86 /* Do stuff here. */
|
|
87 break;
|
|
88 case 'f':
|
|
89 opts.from = optarg;
|
|
90 break;
|
|
91 case 'q':
|
|
92 opts.quiet = TRUE;
|
|
93 break;
|
|
94 case 'h':
|
|
95 opts.help = TRUE;
|
|
96 break;
|
|
97 }
|
|
98 }
|
|
99
|
|
100 /* We must have non getopt'ed argument-- the command */
|
|
101 if (optind < argc)
|
|
102 opts.command = g_strdup(argv[optind++]);
|
|
103 else
|
|
104 return 1;
|
|
105
|
|
106 /* And we can have another argument--the URI. */
|
|
107 if (optind < argc) {
|
|
108 /* but only if we're using the uri command. */
|
|
109 if (!strcmp(opts.command, "uri"))
|
|
110 opts.uri = g_strdup(argv[optind++]);
|
|
111 else
|
|
112 return 1;
|
|
113
|
|
114 /* and we can't have any others. */
|
|
115 if (optind < argc)
|
|
116 return 1;
|
|
117 }
|
|
118
|
|
119 return 0;
|
|
120 }
|
|
121
|
|
122
|
|
123 int command_uri() {
|
|
124 int fd = 0;
|
|
125 struct gaim_cui_packet *p = NULL;
|
|
126 fd = gaim_connect_to_session(0);
|
|
127 if (!fd) {
|
|
128 fprintf(stderr, "Gaim not running (on session 0)\n");
|
|
129 return 1;
|
|
130 }
|
|
131 p = cui_packet_new(CUI_TYPE_REMOTE, CUI_REMOTE_URI);
|
|
132 cui_packet_append_string(p, opts.uri);
|
|
133 cui_send_packet (fd, p);
|
|
134 close(fd);
|
|
135 cui_packet_free(p);
|
|
136 return 0;
|
|
137 }
|
|
138
|
3559
|
139 int command_quit() {
|
|
140 int fd = 0;
|
|
141 struct gaim_cui_packet *p = NULL;
|
|
142 fd = gaim_connect_to_session(0);
|
|
143 if (!fd) {
|
|
144 fprintf(stderr, "Gaim not running (on session 0)\n");
|
|
145 return 1;
|
|
146 }
|
|
147 p = cui_packet_new(CUI_TYPE_META, CUI_META_QUIT);
|
|
148 cui_send_packet (fd, p);
|
|
149 close(fd);
|
|
150 cui_packet_free(p);
|
|
151 return 0;
|
|
152 }
|
|
153
|
3480
|
154 int command_info(){}
|
|
155
|
3559
|
156 int main (int argc, char *argv[])
|
3480
|
157 {
|
|
158
|
|
159 if (get_options(argc, argv)) {
|
|
160 show_remote_usage(argv[0]);
|
|
161 return 0;
|
|
162 }
|
|
163
|
|
164
|
|
165 if (!strcmp(opts.command, "uri")) {
|
|
166 return command_uri();
|
|
167 } else if (!strcmp(opts.command, "info")) {
|
|
168 return command_info();
|
3559
|
169 } else if (!strcmp(opts.command, "quit")) {
|
|
170 return command_quit();
|
3480
|
171 } else {
|
|
172 show_remote_usage(argv[0]);
|
|
173 return 1;
|
|
174 }
|
|
175
|
|
176 return 0;
|
|
177 }
|