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"
|
|
23 #include "getopt.h"
|
|
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"
|
|
38 " remove Remove buddy from list\n\n"
|
|
39
|
|
40 " OPTIONS:\n"
|
|
41 " -m, --message=MESG Message to send or show in conversation window\n"
|
|
42 " -t, --to=SCREENNAME Select a target for command\n"
|
|
43 " -p, --protocol=PROTO Specify protocol to use\n"
|
|
44 " -f, --from=SCREENNAME Specify screenname to use\n"
|
|
45 " -q, --quiet Send message without showing a conversation\n"
|
|
46 " window\n"
|
|
47 " -h, --help Show help for command\n"), name);
|
|
48 return;
|
|
49 }
|
|
50
|
|
51 static struct option longopts[] = {
|
|
52 {"message", required_argument, NULL, 'm'},
|
|
53 {"to", required_argument, NULL, 't'},
|
|
54 {"protocol",required_argument, NULL, 'p'},
|
|
55 {"from", required_argument, NULL, 'f'},
|
|
56 {"quiet", no_argument, NULL, 'q'},
|
|
57 {"help", no_argument, NULL, 'h'},
|
|
58 {0,0,0,0}
|
|
59 };
|
|
60
|
|
61 struct remoteopts {
|
|
62 char *command;
|
|
63 char *uri;
|
|
64 gboolean help, quiet;
|
|
65 char *message, *to, *from;
|
|
66 int protocol;
|
|
67 };
|
|
68
|
|
69
|
|
70 struct remoteopts opts;
|
|
71 int get_options(int argc, char *argv[])
|
|
72 {
|
|
73 int i;
|
|
74 memset(&opts, 0, sizeof(opts));
|
|
75 opts.protocol = -1;
|
|
76 while ((i=getopt_long(argc, argv, "m:t:p:f:qh", longopts, NULL)) != -1) {
|
|
77 switch (i) {
|
|
78 case 'm':
|
|
79 opts.message = optarg;
|
|
80 break;
|
|
81 case 't':
|
|
82 opts.to = optarg;
|
|
83 break;
|
|
84 case 'p':
|
|
85 /* Do stuff here. */
|
|
86 break;
|
|
87 case 'f':
|
|
88 opts.from = optarg;
|
|
89 break;
|
|
90 case 'q':
|
|
91 opts.quiet = TRUE;
|
|
92 break;
|
|
93 case 'h':
|
|
94 opts.help = TRUE;
|
|
95 break;
|
|
96 }
|
|
97 }
|
|
98
|
|
99 /* We must have non getopt'ed argument-- the command */
|
|
100 if (optind < argc)
|
|
101 opts.command = g_strdup(argv[optind++]);
|
|
102 else
|
|
103 return 1;
|
|
104
|
|
105 /* And we can have another argument--the URI. */
|
|
106 if (optind < argc) {
|
|
107 /* but only if we're using the uri command. */
|
|
108 if (!strcmp(opts.command, "uri"))
|
|
109 opts.uri = g_strdup(argv[optind++]);
|
|
110 else
|
|
111 return 1;
|
|
112
|
|
113 /* and we can't have any others. */
|
|
114 if (optind < argc)
|
|
115 return 1;
|
|
116 }
|
|
117
|
|
118 return 0;
|
|
119 }
|
|
120
|
|
121
|
|
122 int command_uri() {
|
|
123 int fd = 0;
|
|
124 struct gaim_cui_packet *p = NULL;
|
|
125 fd = gaim_connect_to_session(0);
|
|
126 if (!fd) {
|
|
127 fprintf(stderr, "Gaim not running (on session 0)\n");
|
|
128 return 1;
|
|
129 }
|
|
130 p = cui_packet_new(CUI_TYPE_REMOTE, CUI_REMOTE_URI);
|
|
131 cui_packet_append_string(p, opts.uri);
|
|
132 cui_send_packet (fd, p);
|
|
133 close(fd);
|
|
134 cui_packet_free(p);
|
|
135 return 0;
|
|
136 }
|
|
137
|
|
138 int command_info(){}
|
|
139
|
|
140 int main (int argc, char *argv[])
|
|
141 {
|
|
142
|
|
143 if (get_options(argc, argv)) {
|
|
144 show_remote_usage(argv[0]);
|
|
145 return 0;
|
|
146 }
|
|
147
|
|
148
|
|
149 if (!strcmp(opts.command, "uri")) {
|
|
150 return command_uri();
|
|
151 } else if (!strcmp(opts.command, "info")) {
|
|
152 return command_info();
|
|
153 } else {
|
|
154 show_remote_usage(argv[0]);
|
|
155 return 1;
|
|
156 }
|
|
157
|
|
158 return 0;
|
|
159 }
|