Mercurial > pidgin
annotate src/protocols/toc/toc.c @ 2518:e7478176e760
[gaim-migrate @ 2531]
don't delete buddy list
committer: Tailor Script <tailor@pidgin.im>
author | Eric Warmenhoven <eric@warmenhoven.org> |
---|---|
date | Tue, 16 Oct 2001 23:24:35 +0000 |
parents | 227cc42ffa6e |
children | 413a81136e3a |
rev | line source |
---|---|
2086 | 1 /* |
2 * gaim | |
3 * | |
4 * Copyright (C) 1998-1999, Mark Spencer <markster@marko.net> | |
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 | |
23 | |
24 #ifdef HAVE_CONFIG_H | |
2090
b66aca8e8dce
[gaim-migrate @ 2100]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
25 #include <config.h> |
2086 | 26 #endif |
27 #include <netdb.h> | |
28 #include <gtk/gtk.h> | |
29 #include <unistd.h> | |
30 #include <errno.h> | |
31 #include <netinet/in.h> | |
32 #include <arpa/inet.h> | |
33 #include <string.h> | |
34 #include <stdlib.h> | |
35 #include <stdio.h> | |
36 #include <time.h> | |
37 #include <sys/socket.h> | |
38 #include <sys/types.h> | |
39 #include <sys/stat.h> | |
40 #include "prpl.h" | |
41 #include "multi.h" | |
42 #include "gaim.h" | |
43 #include "proxy.h" | |
44 | |
45 #include "pixmaps/admin_icon.xpm" | |
46 #include "pixmaps/aol_icon.xpm" | |
47 #include "pixmaps/away_icon.xpm" | |
48 #include "pixmaps/dt_icon.xpm" | |
49 #include "pixmaps/free_icon.xpm" | |
50 | |
51 #define REVISION "penguin" | |
52 | |
53 #define TYPE_SIGNON 1 | |
54 #define TYPE_DATA 2 | |
55 #define TYPE_ERROR 3 | |
56 #define TYPE_SIGNOFF 4 | |
57 #define TYPE_KEEPALIVE 5 | |
58 | |
59 #define FLAPON "FLAPON\r\n\r\n" | |
60 #define ROAST "Tic/Toc" | |
61 | |
62 #define TOC_HOST "toc.oscar.aol.com" | |
63 #define TOC_PORT 9898 | |
64 #define AUTH_HOST "login.oscar.aol.com" | |
65 #define AUTH_PORT 5190 | |
66 #define LANGUAGE "english" | |
67 | |
68 #define STATE_OFFLINE 0 | |
69 #define STATE_FLAPON 1 | |
70 #define STATE_SIGNON_REQUEST 2 | |
71 #define STATE_ONLINE 3 | |
72 #define STATE_PAUSE 4 | |
73 | |
74 #define VOICE_UID "09461341-4C7F-11D1-8222-444553540000" | |
75 #define FILE_SEND_UID "09461343-4C7F-11D1-8222-444553540000" | |
76 #define IMAGE_UID "09461345-4C7F-11D1-8222-444553540000" | |
77 #define B_ICON_UID "09461346-4C7F-11D1-8222-444553540000" | |
78 #define STOCKS_UID "09461347-4C7F-11D1-8222-444553540000" | |
79 #define FILE_GET_UID "09461348-4C7F-11D1-8222-444553540000" | |
80 #define GAMES_UID "0946134a-4C7F-11D1-8222-444553540000" | |
81 | |
2501
227cc42ffa6e
[gaim-migrate @ 2514]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2453
diff
changeset
|
82 #define UC_AOL 0x02 |
227cc42ffa6e
[gaim-migrate @ 2514]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2453
diff
changeset
|
83 #define UC_ADMIN 0x04 |
227cc42ffa6e
[gaim-migrate @ 2514]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2453
diff
changeset
|
84 #define UC_UNCONFIRMED 0x08 |
227cc42ffa6e
[gaim-migrate @ 2514]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2453
diff
changeset
|
85 #define UC_NORMAL 0x10 |
227cc42ffa6e
[gaim-migrate @ 2514]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2453
diff
changeset
|
86 |
2086 | 87 struct ft_request { |
88 struct gaim_connection *gc; | |
89 char *user; | |
90 char UID[2048]; | |
91 char *cookie; | |
92 char *ip; | |
93 int port; | |
94 char *message; | |
95 char *filename; | |
96 int files; | |
97 int size; | |
98 }; | |
99 | |
100 struct buddy_icon { | |
101 guint32 hash; | |
102 guint32 len; | |
103 time_t time; | |
104 void *data; | |
105 }; | |
106 | |
107 struct toc_data { | |
108 int toc_fd; | |
109 int seqno; | |
110 int state; | |
111 }; | |
112 | |
113 struct sflap_hdr { | |
114 unsigned char ast; | |
115 unsigned char type; | |
116 unsigned short seqno; | |
117 unsigned short len; | |
118 }; | |
119 | |
120 struct signon { | |
121 unsigned int ver; | |
122 unsigned short tag; | |
123 unsigned short namelen; | |
124 char username[80]; | |
125 }; | |
126 | |
127 /* constants to identify proto_opts */ | |
128 #define USEROPT_AUTH 0 | |
129 #define USEROPT_AUTHPORT 1 | |
130 | |
2090
b66aca8e8dce
[gaim-migrate @ 2100]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
131 static void toc_login_callback(gpointer, gint, GaimInputCondition); |
b66aca8e8dce
[gaim-migrate @ 2100]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
132 static void toc_callback(gpointer, gint, GaimInputCondition); |
2086 | 133 static unsigned char *roast_password(char *); |
134 static void accept_file_dialog(struct ft_request *); | |
135 | |
136 /* ok. this function used to take username/password, and return 0 on success. | |
137 * now, it takes username/password, and returns NULL on error or a new gaim_connection | |
138 * on success. */ | |
139 static void toc_login(struct aim_user *user) | |
140 { | |
141 struct gaim_connection *gc; | |
142 struct toc_data *tdt; | |
143 char buf[80]; | |
144 | |
145 gc = new_gaim_conn(user); | |
146 gc->proto_data = tdt = g_new0(struct toc_data, 1); | |
147 | |
148 g_snprintf(buf, sizeof buf, "Looking up %s", | |
149 user->proto_opt[USEROPT_AUTH][0] ? user->proto_opt[USEROPT_AUTH] : TOC_HOST); | |
150 set_login_progress(gc, 1, buf); | |
151 | |
152 debug_printf("* Client connects to TOC\n"); | |
153 tdt->toc_fd = | |
154 proxy_connect(user->proto_opt[USEROPT_AUTH][0] ? user->proto_opt[USEROPT_AUTH] : TOC_HOST, | |
155 user->proto_opt[USEROPT_AUTHPORT][0] ? | |
156 atoi(user->proto_opt[USEROPT_AUTHPORT]) : TOC_PORT, | |
157 toc_login_callback, gc); | |
158 | |
159 if (!user->gc || (tdt->toc_fd < 0)) { | |
160 g_snprintf(buf, sizeof(buf), "Connect to %s failed", user->proto_opt[USEROPT_AUTH]); | |
161 hide_login_progress(gc, buf); | |
162 signoff(gc); | |
163 return; | |
164 } | |
165 } | |
166 | |
2090
b66aca8e8dce
[gaim-migrate @ 2100]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
167 static void toc_login_callback(gpointer data, gint source, GaimInputCondition cond) |
2086 | 168 { |
169 struct gaim_connection *gc = data; | |
170 struct toc_data *tdt; | |
171 char buf[80]; | |
172 | |
173 if (!g_slist_find(connections, data)) { | |
174 close(source); | |
175 return; | |
176 } | |
177 | |
178 tdt = gc->proto_data; | |
179 | |
180 if (source == -1) { | |
181 /* we didn't successfully connect. tdt->toc_fd is valid here */ | |
182 hide_login_progress(gc, "Unable to connect."); | |
183 signoff(gc); | |
184 return; | |
185 } | |
186 | |
187 if (tdt->toc_fd == 0) | |
188 tdt->toc_fd = source; | |
189 | |
190 debug_printf("* Client sends \"FLAPON\\r\\n\\r\\n\"\n"); | |
191 if (write(tdt->toc_fd, FLAPON, strlen(FLAPON)) < 0) { | |
192 hide_login_progress(gc, "Disconnected."); | |
193 signoff(gc); | |
194 return; | |
195 } | |
196 tdt->state = STATE_FLAPON; | |
197 | |
198 /* i know a lot of people like to look at gaim to see how TOC works. so i'll comment | |
199 * on what this does. it's really simple. when there's data ready to be read from the | |
200 * toc_fd file descriptor, toc_callback is called, with gc passed as its data arg. */ | |
2090
b66aca8e8dce
[gaim-migrate @ 2100]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
201 gc->inpa = gaim_input_add(tdt->toc_fd, GAIM_INPUT_READ, toc_callback, gc); |
2086 | 202 |
203 g_snprintf(buf, sizeof(buf), "Signon: %s", gc->username); | |
204 set_login_progress(gc, 2, buf); | |
205 } | |
206 | |
207 static void toc_close(struct gaim_connection *gc) | |
208 { | |
209 if (gc->inpa > 0) | |
2090
b66aca8e8dce
[gaim-migrate @ 2100]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
210 gaim_input_remove(gc->inpa); |
2086 | 211 gc->inpa = 0; |
212 close(((struct toc_data *)gc->proto_data)->toc_fd); | |
213 g_free(gc->proto_data); | |
214 } | |
215 | |
2371
db02399a9ad7
[gaim-migrate @ 2384]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2343
diff
changeset
|
216 static int escape_message(char *msg) |
db02399a9ad7
[gaim-migrate @ 2384]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2343
diff
changeset
|
217 { |
db02399a9ad7
[gaim-migrate @ 2384]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2343
diff
changeset
|
218 char *c, *cpy; |
db02399a9ad7
[gaim-migrate @ 2384]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2343
diff
changeset
|
219 int cnt = 0; |
db02399a9ad7
[gaim-migrate @ 2384]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2343
diff
changeset
|
220 /* Assumes you have a buffer able to cary at least BUF_LEN * 2 bytes */ |
db02399a9ad7
[gaim-migrate @ 2384]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2343
diff
changeset
|
221 if (strlen(msg) > BUF_LEN) { |
db02399a9ad7
[gaim-migrate @ 2384]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2343
diff
changeset
|
222 debug_printf("Warning: truncating message to 2048 bytes\n"); |
db02399a9ad7
[gaim-migrate @ 2384]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2343
diff
changeset
|
223 msg[2047] = '\0'; |
db02399a9ad7
[gaim-migrate @ 2384]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2343
diff
changeset
|
224 } |
db02399a9ad7
[gaim-migrate @ 2384]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2343
diff
changeset
|
225 |
db02399a9ad7
[gaim-migrate @ 2384]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2343
diff
changeset
|
226 cpy = g_strdup(msg); |
db02399a9ad7
[gaim-migrate @ 2384]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2343
diff
changeset
|
227 c = cpy; |
db02399a9ad7
[gaim-migrate @ 2384]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2343
diff
changeset
|
228 while (*c) { |
db02399a9ad7
[gaim-migrate @ 2384]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2343
diff
changeset
|
229 switch (*c) { |
db02399a9ad7
[gaim-migrate @ 2384]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2343
diff
changeset
|
230 case '$': |
db02399a9ad7
[gaim-migrate @ 2384]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2343
diff
changeset
|
231 case '[': |
db02399a9ad7
[gaim-migrate @ 2384]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2343
diff
changeset
|
232 case ']': |
db02399a9ad7
[gaim-migrate @ 2384]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2343
diff
changeset
|
233 case '(': |
db02399a9ad7
[gaim-migrate @ 2384]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2343
diff
changeset
|
234 case ')': |
db02399a9ad7
[gaim-migrate @ 2384]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2343
diff
changeset
|
235 case '#': |
db02399a9ad7
[gaim-migrate @ 2384]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2343
diff
changeset
|
236 msg[cnt++] = '\\'; |
db02399a9ad7
[gaim-migrate @ 2384]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2343
diff
changeset
|
237 /* Fall through */ |
db02399a9ad7
[gaim-migrate @ 2384]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2343
diff
changeset
|
238 default: |
db02399a9ad7
[gaim-migrate @ 2384]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2343
diff
changeset
|
239 msg[cnt++] = *c; |
db02399a9ad7
[gaim-migrate @ 2384]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2343
diff
changeset
|
240 } |
db02399a9ad7
[gaim-migrate @ 2384]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2343
diff
changeset
|
241 c++; |
db02399a9ad7
[gaim-migrate @ 2384]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2343
diff
changeset
|
242 } |
db02399a9ad7
[gaim-migrate @ 2384]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2343
diff
changeset
|
243 msg[cnt] = '\0'; |
db02399a9ad7
[gaim-migrate @ 2384]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2343
diff
changeset
|
244 g_free(cpy); |
db02399a9ad7
[gaim-migrate @ 2384]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2343
diff
changeset
|
245 return cnt; |
db02399a9ad7
[gaim-migrate @ 2384]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2343
diff
changeset
|
246 } |
db02399a9ad7
[gaim-migrate @ 2384]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2343
diff
changeset
|
247 |
db02399a9ad7
[gaim-migrate @ 2384]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2343
diff
changeset
|
248 static int escape_text(char *msg) |
db02399a9ad7
[gaim-migrate @ 2384]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2343
diff
changeset
|
249 { |
db02399a9ad7
[gaim-migrate @ 2384]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2343
diff
changeset
|
250 char *c, *cpy; |
db02399a9ad7
[gaim-migrate @ 2384]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2343
diff
changeset
|
251 int cnt = 0; |
db02399a9ad7
[gaim-migrate @ 2384]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2343
diff
changeset
|
252 /* Assumes you have a buffer able to cary at least BUF_LEN * 4 bytes */ |
db02399a9ad7
[gaim-migrate @ 2384]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2343
diff
changeset
|
253 if (strlen(msg) > BUF_LEN) { |
db02399a9ad7
[gaim-migrate @ 2384]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2343
diff
changeset
|
254 fprintf(stderr, "Warning: truncating message to 2048 bytes\n"); |
db02399a9ad7
[gaim-migrate @ 2384]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2343
diff
changeset
|
255 msg[2047] = '\0'; |
db02399a9ad7
[gaim-migrate @ 2384]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2343
diff
changeset
|
256 } |
db02399a9ad7
[gaim-migrate @ 2384]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2343
diff
changeset
|
257 |
db02399a9ad7
[gaim-migrate @ 2384]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2343
diff
changeset
|
258 cpy = g_strdup(msg); |
db02399a9ad7
[gaim-migrate @ 2384]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2343
diff
changeset
|
259 c = cpy; |
db02399a9ad7
[gaim-migrate @ 2384]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2343
diff
changeset
|
260 while (*c) { |
db02399a9ad7
[gaim-migrate @ 2384]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2343
diff
changeset
|
261 switch (*c) { |
db02399a9ad7
[gaim-migrate @ 2384]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2343
diff
changeset
|
262 case '\n': |
db02399a9ad7
[gaim-migrate @ 2384]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2343
diff
changeset
|
263 msg[cnt++] = '<'; |
db02399a9ad7
[gaim-migrate @ 2384]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2343
diff
changeset
|
264 msg[cnt++] = 'B'; |
db02399a9ad7
[gaim-migrate @ 2384]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2343
diff
changeset
|
265 msg[cnt++] = 'R'; |
db02399a9ad7
[gaim-migrate @ 2384]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2343
diff
changeset
|
266 msg[cnt++] = '>'; |
db02399a9ad7
[gaim-migrate @ 2384]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2343
diff
changeset
|
267 break; |
db02399a9ad7
[gaim-migrate @ 2384]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2343
diff
changeset
|
268 case '{': |
db02399a9ad7
[gaim-migrate @ 2384]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2343
diff
changeset
|
269 case '}': |
db02399a9ad7
[gaim-migrate @ 2384]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2343
diff
changeset
|
270 case '\\': |
db02399a9ad7
[gaim-migrate @ 2384]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2343
diff
changeset
|
271 case '"': |
db02399a9ad7
[gaim-migrate @ 2384]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2343
diff
changeset
|
272 msg[cnt++] = '\\'; |
db02399a9ad7
[gaim-migrate @ 2384]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2343
diff
changeset
|
273 /* Fall through */ |
db02399a9ad7
[gaim-migrate @ 2384]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2343
diff
changeset
|
274 default: |
db02399a9ad7
[gaim-migrate @ 2384]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2343
diff
changeset
|
275 msg[cnt++] = *c; |
db02399a9ad7
[gaim-migrate @ 2384]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2343
diff
changeset
|
276 } |
db02399a9ad7
[gaim-migrate @ 2384]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2343
diff
changeset
|
277 c++; |
db02399a9ad7
[gaim-migrate @ 2384]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2343
diff
changeset
|
278 } |
db02399a9ad7
[gaim-migrate @ 2384]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2343
diff
changeset
|
279 msg[cnt] = '\0'; |
db02399a9ad7
[gaim-migrate @ 2384]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2343
diff
changeset
|
280 g_free(cpy); |
db02399a9ad7
[gaim-migrate @ 2384]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2343
diff
changeset
|
281 return cnt; |
db02399a9ad7
[gaim-migrate @ 2384]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2343
diff
changeset
|
282 } |
db02399a9ad7
[gaim-migrate @ 2384]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2343
diff
changeset
|
283 |
2086 | 284 static int sflap_send(struct gaim_connection *gc, char *buf, int olen, int type) |
285 { | |
286 int len; | |
287 int slen = 0; | |
288 struct sflap_hdr hdr; | |
289 char obuf[MSG_LEN]; | |
290 struct toc_data *tdt = (struct toc_data *)gc->proto_data; | |
291 | |
292 if (tdt->state == STATE_PAUSE) | |
293 /* TOC has given us the PAUSE message; sending could cause a disconnect | |
294 * so we just return here like everything went through fine */ | |
295 return 0; | |
296 | |
2281
cc462108c101
[gaim-migrate @ 2291]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
297 if (olen < 0) |
cc462108c101
[gaim-migrate @ 2291]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
298 len = escape_message(buf); |
cc462108c101
[gaim-migrate @ 2291]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
299 else |
cc462108c101
[gaim-migrate @ 2291]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
300 len = olen; |
cc462108c101
[gaim-migrate @ 2291]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
301 |
2086 | 302 /* One _last_ 2048 check here! This shouldn't ever |
303 * get hit though, hopefully. If it gets hit on an IM | |
304 * It'll lose the last " and the message won't go through, | |
305 * but this'll stop a segfault. */ | |
2281
cc462108c101
[gaim-migrate @ 2291]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
306 if (len > MSG_LEN) { |
2086 | 307 debug_printf("message too long, truncating\n"); |
2281
cc462108c101
[gaim-migrate @ 2291]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
308 buf[MSG_LEN - 1] = '\0'; |
cc462108c101
[gaim-migrate @ 2291]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
309 len = MSG_LEN; |
2086 | 310 } |
311 | |
2334
b53cd5b63a99
[gaim-migrate @ 2347]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2309
diff
changeset
|
312 if (olen < 0) |
b53cd5b63a99
[gaim-migrate @ 2347]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2309
diff
changeset
|
313 debug_printf("TOC C: %s\n", buf); |
b53cd5b63a99
[gaim-migrate @ 2347]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2309
diff
changeset
|
314 |
2086 | 315 hdr.ast = '*'; |
316 hdr.type = type; | |
317 hdr.seqno = htons(tdt->seqno++ & 0xffff); | |
318 hdr.len = htons(len + (type == TYPE_SIGNON ? 0 : 1)); | |
319 | |
320 memcpy(obuf, &hdr, sizeof(hdr)); | |
321 slen += sizeof(hdr); | |
322 memcpy(&obuf[slen], buf, len); | |
323 slen += len; | |
324 if (type != TYPE_SIGNON) { | |
325 obuf[slen] = '\0'; | |
326 slen += 1; | |
327 } | |
328 | |
329 return write(tdt->toc_fd, obuf, slen); | |
330 } | |
331 | |
332 static int wait_reply(struct gaim_connection *gc, char *buffer, size_t buflen) | |
333 { | |
334 struct toc_data *tdt = (struct toc_data *)gc->proto_data; | |
335 struct sflap_hdr *hdr; | |
336 int ret; | |
337 | |
338 if (read(tdt->toc_fd, buffer, sizeof(struct sflap_hdr)) < 0) { | |
339 debug_printf("error, couldn't read flap header\n"); | |
340 return -1; | |
341 } | |
342 | |
343 hdr = (struct sflap_hdr *)buffer; | |
344 | |
345 if (buflen < ntohs(hdr->len)) { | |
346 /* fake like there's a read error */ | |
347 debug_printf("buffer too small (have %d, need %d)\n", buflen, ntohs(hdr->len)); | |
348 return -1; | |
349 } | |
350 | |
351 if (ntohs(hdr->len) > 0) { | |
352 int count = 0; | |
353 ret = 0; | |
354 do { | |
355 count += ret; | |
356 ret = read(tdt->toc_fd, | |
357 buffer + sizeof(struct sflap_hdr) + count, ntohs(hdr->len) - count); | |
358 } while (count + ret < ntohs(hdr->len) && ret > 0); | |
359 buffer[sizeof(struct sflap_hdr) + count + ret] = '\0'; | |
360 return ret; | |
361 } else | |
362 return 0; | |
363 } | |
364 | |
365 static unsigned char *roast_password(char *pass) | |
366 { | |
367 /* Trivial "encryption" */ | |
368 static unsigned char rp[256]; | |
369 static char *roast = ROAST; | |
370 int pos = 2; | |
371 int x; | |
372 strcpy(rp, "0x"); | |
373 for (x = 0; (x < 150) && pass[x]; x++) | |
374 pos += sprintf(&rp[pos], "%02x", pass[x] ^ roast[x % strlen(roast)]); | |
375 rp[pos] = '\0'; | |
376 return rp; | |
377 } | |
378 | |
379 static void toc_got_info(gpointer data, char *url_text) | |
380 { | |
381 if (!url_text) | |
382 return; | |
383 | |
2137
18722ae5b882
[gaim-migrate @ 2147]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2136
diff
changeset
|
384 g_show_info_text(url_text, NULL); |
2086 | 385 } |
386 | |
2453
b72143059ad4
[gaim-migrate @ 2466]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2382
diff
changeset
|
387 static char *show_error_message() |
2334
b53cd5b63a99
[gaim-migrate @ 2347]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2309
diff
changeset
|
388 { |
b53cd5b63a99
[gaim-migrate @ 2347]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2309
diff
changeset
|
389 int no = atoi(strtok(NULL, ":")); |
b53cd5b63a99
[gaim-migrate @ 2347]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2309
diff
changeset
|
390 char *w = strtok(NULL, ":"); |
b53cd5b63a99
[gaim-migrate @ 2347]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2309
diff
changeset
|
391 static char buf[256]; |
b53cd5b63a99
[gaim-migrate @ 2347]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2309
diff
changeset
|
392 |
b53cd5b63a99
[gaim-migrate @ 2347]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2309
diff
changeset
|
393 plugin_event(event_error, (void *)no, 0, 0, 0); |
b53cd5b63a99
[gaim-migrate @ 2347]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2309
diff
changeset
|
394 |
b53cd5b63a99
[gaim-migrate @ 2347]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2309
diff
changeset
|
395 switch(no) { |
b53cd5b63a99
[gaim-migrate @ 2347]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2309
diff
changeset
|
396 case 69: |
b53cd5b63a99
[gaim-migrate @ 2347]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2309
diff
changeset
|
397 g_snprintf(buf, sizeof(buf), _("Unable to write file %s."), w); |
b53cd5b63a99
[gaim-migrate @ 2347]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2309
diff
changeset
|
398 break; |
b53cd5b63a99
[gaim-migrate @ 2347]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2309
diff
changeset
|
399 case 169: |
b53cd5b63a99
[gaim-migrate @ 2347]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2309
diff
changeset
|
400 g_snprintf(buf, sizeof(buf), _("Unable to read file %s."), w); |
b53cd5b63a99
[gaim-migrate @ 2347]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2309
diff
changeset
|
401 break; |
b53cd5b63a99
[gaim-migrate @ 2347]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2309
diff
changeset
|
402 case 269: |
b53cd5b63a99
[gaim-migrate @ 2347]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2309
diff
changeset
|
403 g_snprintf(buf, sizeof(buf), _("Message too long, last %s bytes truncated."), w); |
b53cd5b63a99
[gaim-migrate @ 2347]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2309
diff
changeset
|
404 break; |
b53cd5b63a99
[gaim-migrate @ 2347]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2309
diff
changeset
|
405 case 901: |
b53cd5b63a99
[gaim-migrate @ 2347]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2309
diff
changeset
|
406 g_snprintf(buf, sizeof(buf), _("%s not currently logged in."), w); |
b53cd5b63a99
[gaim-migrate @ 2347]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2309
diff
changeset
|
407 break; |
b53cd5b63a99
[gaim-migrate @ 2347]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2309
diff
changeset
|
408 case 902: |
b53cd5b63a99
[gaim-migrate @ 2347]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2309
diff
changeset
|
409 g_snprintf(buf, sizeof(buf), _("Warning of %s not allowed."), w); |
b53cd5b63a99
[gaim-migrate @ 2347]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2309
diff
changeset
|
410 break; |
b53cd5b63a99
[gaim-migrate @ 2347]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2309
diff
changeset
|
411 case 903: |
b53cd5b63a99
[gaim-migrate @ 2347]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2309
diff
changeset
|
412 g_snprintf(buf, sizeof(buf), _("A message has been dropped, you are exceeding the server speed limit.")); |
b53cd5b63a99
[gaim-migrate @ 2347]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2309
diff
changeset
|
413 break; |
b53cd5b63a99
[gaim-migrate @ 2347]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2309
diff
changeset
|
414 case 950: |
b53cd5b63a99
[gaim-migrate @ 2347]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2309
diff
changeset
|
415 g_snprintf(buf, sizeof(buf), _("Chat in %s is not available."), w); |
b53cd5b63a99
[gaim-migrate @ 2347]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2309
diff
changeset
|
416 break; |
b53cd5b63a99
[gaim-migrate @ 2347]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2309
diff
changeset
|
417 case 960: |
b53cd5b63a99
[gaim-migrate @ 2347]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2309
diff
changeset
|
418 g_snprintf(buf, sizeof(buf), _("You are sending messages too fast to %s."), w); |
b53cd5b63a99
[gaim-migrate @ 2347]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2309
diff
changeset
|
419 break; |
b53cd5b63a99
[gaim-migrate @ 2347]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2309
diff
changeset
|
420 case 961: |
b53cd5b63a99
[gaim-migrate @ 2347]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2309
diff
changeset
|
421 g_snprintf(buf, sizeof(buf), _("You missed an IM from %s because it was too big."), w); |
b53cd5b63a99
[gaim-migrate @ 2347]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2309
diff
changeset
|
422 break; |
b53cd5b63a99
[gaim-migrate @ 2347]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2309
diff
changeset
|
423 case 962: |
b53cd5b63a99
[gaim-migrate @ 2347]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2309
diff
changeset
|
424 g_snprintf(buf, sizeof(buf), _("You missed an IM from %s because it was sent too fast."), w); |
b53cd5b63a99
[gaim-migrate @ 2347]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2309
diff
changeset
|
425 break; |
b53cd5b63a99
[gaim-migrate @ 2347]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2309
diff
changeset
|
426 case 970: |
b53cd5b63a99
[gaim-migrate @ 2347]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2309
diff
changeset
|
427 g_snprintf(buf, sizeof(buf), _("Failure.")); |
b53cd5b63a99
[gaim-migrate @ 2347]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2309
diff
changeset
|
428 break; |
b53cd5b63a99
[gaim-migrate @ 2347]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2309
diff
changeset
|
429 case 971: |
b53cd5b63a99
[gaim-migrate @ 2347]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2309
diff
changeset
|
430 g_snprintf(buf, sizeof(buf), _("Too many matches.")); |
b53cd5b63a99
[gaim-migrate @ 2347]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2309
diff
changeset
|
431 break; |
b53cd5b63a99
[gaim-migrate @ 2347]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2309
diff
changeset
|
432 case 972: |
b53cd5b63a99
[gaim-migrate @ 2347]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2309
diff
changeset
|
433 g_snprintf(buf, sizeof(buf), _("Need more qualifiers.")); |
b53cd5b63a99
[gaim-migrate @ 2347]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2309
diff
changeset
|
434 break; |
b53cd5b63a99
[gaim-migrate @ 2347]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2309
diff
changeset
|
435 case 973: |
b53cd5b63a99
[gaim-migrate @ 2347]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2309
diff
changeset
|
436 g_snprintf(buf, sizeof(buf), _("Dir service temporarily unavailable.")); |
b53cd5b63a99
[gaim-migrate @ 2347]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2309
diff
changeset
|
437 break; |
b53cd5b63a99
[gaim-migrate @ 2347]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2309
diff
changeset
|
438 case 974: |
b53cd5b63a99
[gaim-migrate @ 2347]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2309
diff
changeset
|
439 g_snprintf(buf, sizeof(buf), _("Email lookup restricted.")); |
b53cd5b63a99
[gaim-migrate @ 2347]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2309
diff
changeset
|
440 break; |
b53cd5b63a99
[gaim-migrate @ 2347]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2309
diff
changeset
|
441 case 975: |
b53cd5b63a99
[gaim-migrate @ 2347]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2309
diff
changeset
|
442 g_snprintf(buf, sizeof(buf), _("Keyword ignored.")); |
b53cd5b63a99
[gaim-migrate @ 2347]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2309
diff
changeset
|
443 break; |
b53cd5b63a99
[gaim-migrate @ 2347]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2309
diff
changeset
|
444 case 976: |
b53cd5b63a99
[gaim-migrate @ 2347]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2309
diff
changeset
|
445 g_snprintf(buf, sizeof(buf), _("No keywords.")); |
b53cd5b63a99
[gaim-migrate @ 2347]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2309
diff
changeset
|
446 break; |
b53cd5b63a99
[gaim-migrate @ 2347]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2309
diff
changeset
|
447 case 977: |
b53cd5b63a99
[gaim-migrate @ 2347]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2309
diff
changeset
|
448 g_snprintf(buf, sizeof(buf), _("User has no directory information.")); |
b53cd5b63a99
[gaim-migrate @ 2347]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2309
diff
changeset
|
449 /* g_snprintf(buf, sizeof(buf), "Language not supported."); */ |
b53cd5b63a99
[gaim-migrate @ 2347]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2309
diff
changeset
|
450 break; |
b53cd5b63a99
[gaim-migrate @ 2347]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2309
diff
changeset
|
451 case 978: |
b53cd5b63a99
[gaim-migrate @ 2347]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2309
diff
changeset
|
452 g_snprintf(buf, sizeof(buf), _("Country not supported.")); |
b53cd5b63a99
[gaim-migrate @ 2347]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2309
diff
changeset
|
453 break; |
b53cd5b63a99
[gaim-migrate @ 2347]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2309
diff
changeset
|
454 case 979: |
b53cd5b63a99
[gaim-migrate @ 2347]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2309
diff
changeset
|
455 g_snprintf(buf, sizeof(buf), _("Failure unknown: %s."), w); |
b53cd5b63a99
[gaim-migrate @ 2347]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2309
diff
changeset
|
456 break; |
b53cd5b63a99
[gaim-migrate @ 2347]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2309
diff
changeset
|
457 case 980: |
b53cd5b63a99
[gaim-migrate @ 2347]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2309
diff
changeset
|
458 g_snprintf(buf, sizeof(buf), _("Incorrect nickname or password.")); |
b53cd5b63a99
[gaim-migrate @ 2347]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2309
diff
changeset
|
459 break; |
b53cd5b63a99
[gaim-migrate @ 2347]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2309
diff
changeset
|
460 case 981: |
b53cd5b63a99
[gaim-migrate @ 2347]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2309
diff
changeset
|
461 g_snprintf(buf, sizeof(buf), _("The service is temporarily unavailable.")); |
b53cd5b63a99
[gaim-migrate @ 2347]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2309
diff
changeset
|
462 break; |
b53cd5b63a99
[gaim-migrate @ 2347]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2309
diff
changeset
|
463 case 982: |
b53cd5b63a99
[gaim-migrate @ 2347]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2309
diff
changeset
|
464 g_snprintf(buf, sizeof(buf), _("Your warning level is currently too high to log in.")); |
b53cd5b63a99
[gaim-migrate @ 2347]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2309
diff
changeset
|
465 break; |
b53cd5b63a99
[gaim-migrate @ 2347]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2309
diff
changeset
|
466 case 983: |
b53cd5b63a99
[gaim-migrate @ 2347]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2309
diff
changeset
|
467 g_snprintf(buf, sizeof(buf), _("You have been connecting and disconnecting too frequently. Wait ten minutes and try again. If you continue to try, you will need to wait even longer.")); |
b53cd5b63a99
[gaim-migrate @ 2347]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2309
diff
changeset
|
468 break; |
b53cd5b63a99
[gaim-migrate @ 2347]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2309
diff
changeset
|
469 case 989: |
b53cd5b63a99
[gaim-migrate @ 2347]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2309
diff
changeset
|
470 g_snprintf(buf, sizeof(buf), _("An unknown signon error has occurred: %s."), w); |
b53cd5b63a99
[gaim-migrate @ 2347]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2309
diff
changeset
|
471 break; |
b53cd5b63a99
[gaim-migrate @ 2347]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2309
diff
changeset
|
472 default: |
b53cd5b63a99
[gaim-migrate @ 2347]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2309
diff
changeset
|
473 g_snprintf(buf, sizeof(buf), _("An unknown error, %d, has occured. Info: %s"), no, w); |
b53cd5b63a99
[gaim-migrate @ 2347]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2309
diff
changeset
|
474 } |
b53cd5b63a99
[gaim-migrate @ 2347]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2309
diff
changeset
|
475 |
b53cd5b63a99
[gaim-migrate @ 2347]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2309
diff
changeset
|
476 return buf; |
b53cd5b63a99
[gaim-migrate @ 2347]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2309
diff
changeset
|
477 } |
b53cd5b63a99
[gaim-migrate @ 2347]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2309
diff
changeset
|
478 |
2090
b66aca8e8dce
[gaim-migrate @ 2100]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
479 static void toc_callback(gpointer data, gint source, GaimInputCondition condition) |
2086 | 480 { |
481 struct gaim_connection *gc = (struct gaim_connection *)data; | |
482 struct toc_data *tdt = (struct toc_data *)gc->proto_data; | |
483 struct sflap_hdr *hdr; | |
484 struct signon so; | |
485 char buf[8 * 1024], *c; | |
486 char snd[BUF_LEN * 2]; | |
487 | |
488 /* there's data waiting to be read, so read it. */ | |
489 if (wait_reply(gc, buf, 8 * 1024) <= 0) { | |
490 hide_login_progress(gc, _("Connection Closed")); | |
491 signoff(gc); | |
492 return; | |
493 } | |
494 | |
495 if (tdt->state == STATE_FLAPON) { | |
496 hdr = (struct sflap_hdr *)buf; | |
497 if (hdr->type != TYPE_SIGNON) | |
498 debug_printf("problem, hdr->type != TYPE_SIGNON\n"); | |
499 else | |
500 debug_printf("* TOC sends Client FLAP SIGNON\n"); | |
501 tdt->seqno = ntohs(hdr->seqno); | |
502 tdt->state = STATE_SIGNON_REQUEST; | |
503 | |
504 debug_printf("* Client sends TOC FLAP SIGNON\n"); | |
505 g_snprintf(so.username, sizeof(so.username), "%s", gc->username); | |
506 so.ver = htonl(1); | |
507 so.tag = htons(1); | |
508 so.namelen = htons(strlen(so.username)); | |
509 if (sflap_send(gc, (char *)&so, ntohs(so.namelen) + 8, TYPE_SIGNON) < 0) { | |
510 hide_login_progress(gc, _("Disconnected.")); | |
511 signoff(gc); | |
512 return; | |
513 } | |
514 | |
515 debug_printf("* Client sends TOC \"toc_signon\" message\n"); | |
516 g_snprintf(snd, sizeof snd, "toc_signon %s %d %s %s %s \"%s\"", | |
517 AUTH_HOST, AUTH_PORT, normalize(gc->username), | |
518 roast_password(gc->password), LANGUAGE, REVISION); | |
519 if (sflap_send(gc, snd, -1, TYPE_DATA) < 0) { | |
520 hide_login_progress(gc, _("Disconnected.")); | |
521 signoff(gc); | |
522 return; | |
523 } | |
524 | |
525 set_login_progress(gc, 3, _("Waiting for reply...")); | |
526 return; | |
527 } | |
528 | |
529 if (tdt->state == STATE_SIGNON_REQUEST) { | |
530 debug_printf("* TOC sends client SIGN_ON reply\n"); | |
531 if (g_strncasecmp(buf + sizeof(struct sflap_hdr), "SIGN_ON", strlen("SIGN_ON"))) { | |
532 debug_printf("Didn't get SIGN_ON! buf was: %s\n", | |
533 buf + sizeof(struct sflap_hdr)); | |
2334
b53cd5b63a99
[gaim-migrate @ 2347]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2309
diff
changeset
|
534 if (!g_strncasecmp(buf + sizeof(struct sflap_hdr), "ERROR", 5)) { |
b53cd5b63a99
[gaim-migrate @ 2347]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2309
diff
changeset
|
535 strtok(buf + sizeof(struct sflap_hdr), ":"); |
2453
b72143059ad4
[gaim-migrate @ 2466]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2382
diff
changeset
|
536 hide_login_progress(gc, show_error_message()); |
2334
b53cd5b63a99
[gaim-migrate @ 2347]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2309
diff
changeset
|
537 } else |
b53cd5b63a99
[gaim-migrate @ 2347]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2309
diff
changeset
|
538 hide_login_progress(gc, _("Authentication Failed")); |
2086 | 539 signoff(gc); |
540 return; | |
541 } | |
542 /* we're supposed to check that it's really TOC v1 here but we know it is ;) */ | |
2128
bc79be34eb73
[gaim-migrate @ 2138]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2123
diff
changeset
|
543 debug_printf("TOC version: %s\n", buf + sizeof(struct sflap_hdr) + 8); |
2086 | 544 |
545 /* we used to check for the CONFIG here, but we'll wait until we've sent our | |
546 * version of the config and then the toc_init_done message. we'll come back to | |
547 * the callback in a better state if we get CONFIG anyway */ | |
548 | |
549 tdt->state = STATE_ONLINE; | |
550 | |
551 account_online(gc); | |
552 serv_finish_login(gc); | |
553 | |
2518
e7478176e760
[gaim-migrate @ 2531]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2501
diff
changeset
|
554 if (bud_list_cache_exists(gc)) |
e7478176e760
[gaim-migrate @ 2531]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2501
diff
changeset
|
555 do_import(gc, NULL); |
2086 | 556 |
557 /* Client sends TOC toc_init_done message */ | |
558 debug_printf("* Client sends TOC toc_init_done message\n"); | |
559 g_snprintf(snd, sizeof snd, "toc_init_done"); | |
560 sflap_send(gc, snd, -1, TYPE_DATA); | |
561 | |
562 /* | |
563 g_snprintf(snd, sizeof snd, "toc_set_caps %s %s %s", | |
564 FILE_SEND_UID, FILE_GET_UID, B_ICON_UID); | |
565 */ | |
566 g_snprintf(snd, sizeof snd, "toc_set_caps %s %s", FILE_SEND_UID, FILE_GET_UID); | |
567 sflap_send(gc, snd, -1, TYPE_DATA); | |
568 | |
569 return; | |
570 } | |
571 | |
2334
b53cd5b63a99
[gaim-migrate @ 2347]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2309
diff
changeset
|
572 debug_printf("TOC S: %s\n", buf + sizeof(struct sflap_hdr)); |
2086 | 573 |
574 c = strtok(buf + sizeof(struct sflap_hdr), ":"); /* Ditch the first part */ | |
575 | |
576 if (!g_strcasecmp(c, "SIGN_ON")) { | |
577 /* we should only get here after a PAUSE */ | |
578 if (tdt->state != STATE_PAUSE) | |
579 debug_printf("got SIGN_ON but not PAUSE!\n"); | |
580 else { | |
581 tdt->state = STATE_ONLINE; | |
582 g_snprintf(snd, sizeof snd, "toc_signon %s %d %s %s %s \"%s\"", | |
583 AUTH_HOST, AUTH_PORT, normalize(gc->username), | |
584 roast_password(gc->password), LANGUAGE, REVISION); | |
585 if (sflap_send(gc, snd, -1, TYPE_DATA) < 0) { | |
586 hide_login_progress(gc, _("Disconnected.")); | |
587 signoff(gc); | |
588 return; | |
589 } | |
2518
e7478176e760
[gaim-migrate @ 2531]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2501
diff
changeset
|
590 if (bud_list_cache_exists(gc)) |
e7478176e760
[gaim-migrate @ 2531]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2501
diff
changeset
|
591 do_import(gc, NULL); |
2086 | 592 g_snprintf(snd, sizeof snd, "toc_init_done"); |
593 sflap_send(gc, snd, -1, TYPE_DATA); | |
594 do_error_dialog(_("TOC has come back from its pause. You may now send" | |
595 " messages again."), _("TOC Resume")); | |
596 } | |
597 } else if (!strcasecmp(c, "CONFIG")) { | |
598 c = strtok(NULL, ":"); | |
599 parse_toc_buddy_list(gc, c, 0); | |
600 } else if (!strcasecmp(c, "NICK")) { | |
601 /* ignore NICK so that things get imported/exported properly | |
602 c = strtok(NULL, ":"); | |
603 g_snprintf(gc->username, sizeof(gc->username), "%s", c); | |
604 */ | |
605 } else if (!strcasecmp(c, "IM_IN")) { | |
606 char *away, *message; | |
607 int a = 0; | |
608 | |
609 c = strtok(NULL, ":"); | |
610 away = strtok(NULL, ":"); | |
611 | |
612 message = away; | |
613 while (*message && (*message != ':')) | |
614 message++; | |
615 message++; | |
616 | |
2273
0b5c3338fa3d
[gaim-migrate @ 2283]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2232
diff
changeset
|
617 a = (away && (*away == 'T')) ? IM_FLAG_AWAY : 0; |
2086 | 618 |
619 serv_got_im(gc, c, message, a, time((time_t)NULL)); | |
620 } else if (!strcasecmp(c, "UPDATE_BUDDY")) { | |
2305
0371b905baef
[gaim-migrate @ 2315]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2303
diff
changeset
|
621 char *l, *uc, *tmp; |
2086 | 622 int logged, evil, idle, type = 0; |
623 time_t signon, time_idle; | |
624 | |
625 c = strtok(NULL, ":"); /* name */ | |
626 l = strtok(NULL, ":"); /* online */ | |
627 sscanf(strtok(NULL, ":"), "%d", &evil); | |
628 sscanf(strtok(NULL, ":"), "%ld", &signon); | |
629 sscanf(strtok(NULL, ":"), "%d", &idle); | |
630 uc = strtok(NULL, ":"); | |
631 | |
632 logged = (l && (*l == 'T')) ? 1 : 0; | |
633 | |
634 if (uc[0] == 'A') | |
635 type |= UC_AOL; | |
636 switch (uc[1]) { | |
637 case 'A': | |
638 type |= UC_ADMIN; | |
639 break; | |
640 case 'U': | |
641 type |= UC_UNCONFIRMED; | |
642 break; | |
643 case 'O': | |
644 type |= UC_NORMAL; | |
645 break; | |
646 default: | |
647 break; | |
648 } | |
649 if (uc[2] == 'U') | |
650 type |= UC_UNAVAILABLE; | |
651 | |
652 if (idle) { | |
653 time(&time_idle); | |
654 time_idle -= idle * 60; | |
655 } else | |
656 time_idle = 0; | |
657 | |
2305
0371b905baef
[gaim-migrate @ 2315]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2303
diff
changeset
|
658 tmp = g_strdup(normalize(gc->username)); |
0371b905baef
[gaim-migrate @ 2315]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2303
diff
changeset
|
659 if (!strcmp(tmp, normalize(c))) |
0371b905baef
[gaim-migrate @ 2315]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2303
diff
changeset
|
660 g_snprintf(gc->displayname, sizeof(gc->displayname), "%s", c); |
0371b905baef
[gaim-migrate @ 2315]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2303
diff
changeset
|
661 g_free(tmp); |
0371b905baef
[gaim-migrate @ 2315]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2303
diff
changeset
|
662 |
2086 | 663 serv_got_update(gc, c, logged, evil, signon, time_idle, type, 0); |
664 } else if (!strcasecmp(c, "ERROR")) { | |
2453
b72143059ad4
[gaim-migrate @ 2466]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2382
diff
changeset
|
665 do_error_dialog(show_error_message(), "TOC Error"); |
2086 | 666 } else if (!strcasecmp(c, "EVILED")) { |
667 int lev; | |
668 char *name; | |
669 | |
670 sscanf(strtok(NULL, ":"), "%d", &lev); | |
671 name = strtok(NULL, ":"); | |
672 | |
673 serv_got_eviled(gc, name, lev); | |
674 } else if (!strcasecmp(c, "CHAT_JOIN")) { | |
675 char *name; | |
676 int id; | |
677 | |
678 sscanf(strtok(NULL, ":"), "%d", &id); | |
679 name = strtok(NULL, ":"); | |
680 | |
681 serv_got_joined_chat(gc, id, name); | |
682 } else if (!strcasecmp(c, "CHAT_IN")) { | |
683 int id, w; | |
684 char *m, *who, *whisper; | |
685 | |
686 sscanf(strtok(NULL, ":"), "%d", &id); | |
687 who = strtok(NULL, ":"); | |
688 whisper = strtok(NULL, ":"); | |
689 m = whisper; | |
690 while (*m && (*m != ':')) | |
691 m++; | |
692 m++; | |
693 | |
694 w = (whisper && (*whisper == 'T')) ? 1 : 0; | |
695 | |
696 serv_got_chat_in(gc, id, who, w, m, time((time_t)NULL)); | |
697 } else if (!strcasecmp(c, "CHAT_UPDATE_BUDDY")) { | |
698 int id; | |
699 char *in, *buddy; | |
700 GSList *bcs = gc->buddy_chats; | |
701 struct conversation *b = NULL; | |
702 | |
703 sscanf(strtok(NULL, ":"), "%d", &id); | |
704 in = strtok(NULL, ":"); | |
705 | |
706 while (bcs) { | |
707 b = (struct conversation *)bcs->data; | |
708 if (id == b->id) | |
709 break; | |
710 bcs = bcs->next; | |
711 b = NULL; | |
712 } | |
713 | |
714 if (!b) | |
715 return; | |
716 | |
717 if (in && (*in == 'T')) | |
718 while ((buddy = strtok(NULL, ":")) != NULL) | |
719 add_chat_buddy(b, buddy); | |
720 else | |
721 while ((buddy = strtok(NULL, ":")) != NULL) | |
722 remove_chat_buddy(b, buddy); | |
723 } else if (!strcasecmp(c, "CHAT_INVITE")) { | |
724 char *name, *who, *message; | |
2205
cff4fbe01c7b
[gaim-migrate @ 2215]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2170
diff
changeset
|
725 int *id = g_new0(int, 1); |
2086 | 726 |
727 name = strtok(NULL, ":"); | |
2205
cff4fbe01c7b
[gaim-migrate @ 2215]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2170
diff
changeset
|
728 sscanf(strtok(NULL, ":"), "%d", id); |
2086 | 729 who = strtok(NULL, ":"); |
730 message = strtok(NULL, ":"); | |
731 | |
2205
cff4fbe01c7b
[gaim-migrate @ 2215]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2170
diff
changeset
|
732 serv_got_chat_invite(gc, name, who, message, g_list_append(NULL, id)); |
2086 | 733 } else if (!strcasecmp(c, "CHAT_LEFT")) { |
734 GSList *bcs = gc->buddy_chats; | |
735 struct conversation *b = NULL; | |
736 int id; | |
737 | |
738 sscanf(strtok(NULL, ":"), "%d", &id); | |
739 | |
740 while (bcs) { | |
741 b = (struct conversation *)bcs->data; | |
742 if (id == b->id) | |
743 break; | |
744 b = NULL; | |
745 bcs = bcs->next; | |
746 } | |
747 | |
748 if (!b) | |
749 return; | |
750 | |
751 if (b->window) { | |
752 char error_buf[BUF_LONG]; | |
753 b->gc = NULL; | |
754 g_snprintf(error_buf, sizeof error_buf, _("You have been disconnected" | |
755 " from chat room %s."), b->name); | |
756 do_error_dialog(error_buf, _("Chat Error")); | |
757 } else | |
758 serv_got_chat_left(gc, id); | |
759 } else if (!strcasecmp(c, "GOTO_URL")) { | |
760 char *name, *url, tmp[256]; | |
761 | |
762 name = strtok(NULL, ":"); | |
763 url = strtok(NULL, ":"); | |
764 | |
765 g_snprintf(tmp, sizeof(tmp), "http://%s:%d/%s", | |
766 gc->user->proto_opt[USEROPT_AUTH][0] ? | |
767 gc->user->proto_opt[USEROPT_AUTH] : TOC_HOST, | |
768 gc->user->proto_opt[USEROPT_AUTHPORT][0] ? | |
769 atoi(gc->user->proto_opt[USEROPT_AUTHPORT]) : TOC_PORT, | |
770 url); | |
771 grab_url(tmp, toc_got_info, NULL); | |
772 } else if (!strcasecmp(c, "DIR_STATUS")) { | |
773 } else if (!strcasecmp(c, "ADMIN_NICK_STATUS")) { | |
774 } else if (!strcasecmp(c, "ADMIN_PASSWD_STATUS")) { | |
775 do_error_dialog(_("Password Change Successeful"), _("Gaim - Password Change")); | |
776 } else if (!strcasecmp(c, "PAUSE")) { | |
777 tdt->state = STATE_PAUSE; | |
778 do_error_dialog(_("TOC has sent a PAUSE command. When this happens, TOC ignores" | |
779 " any messages sent to it, and may kick you off if you send a" | |
780 " message. Gaim will prevent anything from going through. This" | |
781 " is only temporary, please be patient."), _("TOC Pause")); | |
782 } else if (!strcasecmp(c, "RVOUS_PROPOSE")) { | |
783 char *user, *uuid, *cookie; | |
784 int seq; | |
785 char *rip, *pip, *vip; | |
786 int port; | |
787 | |
788 user = strtok(NULL, ":"); | |
789 uuid = strtok(NULL, ":"); | |
790 cookie = strtok(NULL, ":"); | |
791 sscanf(strtok(NULL, ":"), "%d", &seq); | |
792 rip = strtok(NULL, ":"); | |
793 pip = strtok(NULL, ":"); | |
794 vip = strtok(NULL, ":"); | |
795 sscanf(strtok(NULL, ":"), "%d", &port); | |
796 | |
797 if (!strcmp(uuid, FILE_SEND_UID)) { | |
798 /* they want us to get a file */ | |
799 int unk[4], i; | |
800 char *messages[4], *tmp, *name; | |
801 int subtype, files, totalsize = 0; | |
802 struct ft_request *ft; | |
803 | |
804 for (i = 0; i < 4; i++) { | |
805 sscanf(strtok(NULL, ":"), "%d", &unk[i]); | |
806 if (unk[i] == 10001) | |
807 break; | |
808 frombase64(strtok(NULL, ":"), &messages[i], NULL); | |
809 } | |
810 frombase64(strtok(NULL, ":"), &tmp, NULL); | |
811 | |
812 subtype = tmp[1]; | |
813 files = tmp[3]; | |
814 | |
815 totalsize |= (tmp[4] << 24) & 0xff000000; | |
816 totalsize |= (tmp[5] << 16) & 0x00ff0000; | |
817 totalsize |= (tmp[6] << 8) & 0x0000ff00; | |
818 totalsize |= (tmp[7] << 0) & 0x000000ff; | |
819 | |
820 if (!totalsize) { | |
821 g_free(tmp); | |
822 for (i--; i >= 0; i--) | |
823 g_free(messages[i]); | |
824 return; | |
825 } | |
826 | |
827 name = tmp + 8; | |
828 | |
829 ft = g_new0(struct ft_request, 1); | |
830 ft->cookie = g_strdup(cookie); | |
831 ft->ip = g_strdup(pip); | |
832 ft->port = port; | |
833 if (i) | |
834 ft->message = g_strdup(messages[0]); | |
835 else | |
836 ft->message = NULL; | |
837 ft->filename = g_strdup(name); | |
838 ft->user = g_strdup(user); | |
839 ft->size = totalsize; | |
840 ft->files = files; | |
841 g_snprintf(ft->UID, sizeof(ft->UID), "%s", FILE_SEND_UID); | |
842 ft->gc = gc; | |
843 | |
844 g_free(tmp); | |
845 for (i--; i >= 0; i--) | |
846 g_free(messages[i]); | |
847 | |
848 debug_printf("English translation of RVOUS_PROPOSE: %s requests Send File (i.e." | |
849 " send a file to you); %s:%d (verified_ip:port), %d files at" | |
850 " total size of %ld bytes.\n", user, vip, port, files, totalsize); | |
851 accept_file_dialog(ft); | |
852 } else if (!strcmp(uuid, FILE_GET_UID)) { | |
853 /* they want us to send a file */ | |
854 int unk[4], i; | |
855 char *messages[4], *tmp; | |
856 struct ft_request *ft; | |
857 | |
858 for (i = 0; i < 4; i++) { | |
859 sscanf(strtok(NULL, ":"), "%d", unk + i); | |
860 if (unk[i] == 10001) | |
861 break; | |
862 frombase64(strtok(NULL, ":"), &messages[i], NULL); | |
863 } | |
864 frombase64(strtok(NULL, ":"), &tmp, NULL); | |
865 | |
866 ft = g_new0(struct ft_request, 1); | |
867 ft->cookie = g_strdup(cookie); | |
868 ft->ip = g_strdup(pip); | |
869 ft->port = port; | |
870 if (i) | |
871 ft->message = g_strdup(messages[0]); | |
872 else | |
873 ft->message = NULL; | |
874 ft->user = g_strdup(user); | |
875 g_snprintf(ft->UID, sizeof(ft->UID), "%s", FILE_GET_UID); | |
876 ft->gc = gc; | |
877 | |
878 g_free(tmp); | |
879 for (i--; i >= 0; i--) | |
880 g_free(messages[i]); | |
881 | |
882 accept_file_dialog(ft); | |
883 } else if (!strcmp(uuid, VOICE_UID)) { | |
884 /* oh goody. voice over ip. fun stuff. */ | |
885 } else if (!strcmp(uuid, B_ICON_UID)) { | |
886 /* | |
887 int unk[4], i; | |
888 char *messages[4]; | |
889 struct buddy_icon *icon; | |
890 | |
891 for (i = 0; i < 4; i++) { | |
892 sscanf(strtok(NULL, ":"), "%d", unk + i); | |
893 if (unk[i] == 10001) | |
894 break; | |
895 frombase64(strtok(NULL, ":"), &messages[i], NULL); | |
896 } | |
897 frombase64(strtok(NULL, ":"), (char **)&icon, NULL); | |
898 | |
899 debug_printf("received icon of length %d\n", icon->len); | |
900 g_free(icon); | |
901 for (i--; i >= 0; i--) | |
902 g_free(messages[i]); | |
903 */ | |
904 } else if (!strcmp(uuid, IMAGE_UID)) { | |
905 /* aka Direct IM */ | |
906 } else { | |
907 debug_printf("Don't know what to do with RVOUS UUID %s\n", uuid); | |
908 /* do we have to do anything here? i think it just times out */ | |
909 } | |
910 } else { | |
911 debug_printf("don't know what to do with %s\n", c); | |
912 } | |
913 } | |
914 | |
915 static char *toc_name() | |
916 { | |
917 return "TOC"; | |
918 } | |
919 | |
2231
8c4ff1a368bd
[gaim-migrate @ 2241]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2205
diff
changeset
|
920 static int toc_send_im(struct gaim_connection *gc, char *name, char *message, int flags) |
2086 | 921 { |
922 char buf[BUF_LEN * 2]; | |
2343
29449a6b79e6
[gaim-migrate @ 2356]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2334
diff
changeset
|
923 char *tmp = g_malloc(strlen(message) * 4 + 1); /* 4 because \n gets replaced with <BR> */ |
2086 | 924 |
2136
73253b36c3cb
[gaim-migrate @ 2146]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2130
diff
changeset
|
925 strcpy(tmp, message); |
73253b36c3cb
[gaim-migrate @ 2146]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2130
diff
changeset
|
926 escape_text(tmp); |
73253b36c3cb
[gaim-migrate @ 2146]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2130
diff
changeset
|
927 if (strlen(tmp) + 52 > MSG_LEN) { |
73253b36c3cb
[gaim-migrate @ 2146]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2130
diff
changeset
|
928 g_free(tmp); |
2123
56c4382f2909
[gaim-migrate @ 2133]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2090
diff
changeset
|
929 return -E2BIG; |
2136
73253b36c3cb
[gaim-migrate @ 2146]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2130
diff
changeset
|
930 } |
2086 | 931 g_snprintf(buf, MSG_LEN - 8, "toc_send_im %s \"%s\"%s", normalize(name), |
2231
8c4ff1a368bd
[gaim-migrate @ 2241]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2205
diff
changeset
|
932 tmp, ((flags & IM_FLAG_AWAY) ? " auto" : "")); |
2086 | 933 sflap_send(gc, buf, -1, TYPE_DATA); |
2123
56c4382f2909
[gaim-migrate @ 2133]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2090
diff
changeset
|
934 |
2136
73253b36c3cb
[gaim-migrate @ 2146]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2130
diff
changeset
|
935 g_free(tmp); |
2303
f5bf315e6104
[gaim-migrate @ 2313]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2281
diff
changeset
|
936 return 1; |
2086 | 937 } |
938 | |
939 static void toc_set_config(struct gaim_connection *gc) | |
940 { | |
2281
cc462108c101
[gaim-migrate @ 2291]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
941 char *buf = g_malloc(MSG_LEN), snd[BUF_LEN * 2]; |
cc462108c101
[gaim-migrate @ 2291]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
942 toc_build_config(gc, buf, MSG_LEN - strlen("toc_set_config \\{\\}"), FALSE); |
2086 | 943 g_snprintf(snd, MSG_LEN, "toc_set_config {%s}", buf); |
944 sflap_send(gc, snd, -1, TYPE_DATA); | |
2281
cc462108c101
[gaim-migrate @ 2291]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
945 g_free(buf); |
2086 | 946 } |
947 | |
948 static void toc_get_info(struct gaim_connection *g, char *name) | |
949 { | |
950 char buf[BUF_LEN * 2]; | |
951 g_snprintf(buf, MSG_LEN, "toc_get_info %s", normalize(name)); | |
952 sflap_send(g, buf, -1, TYPE_DATA); | |
953 } | |
954 | |
955 static void toc_get_dir(struct gaim_connection *g, char *name) | |
956 { | |
957 char buf[BUF_LEN * 2]; | |
958 g_snprintf(buf, MSG_LEN, "toc_get_dir %s", normalize(name)); | |
959 sflap_send(g, buf, -1, TYPE_DATA); | |
960 } | |
961 | |
962 static void toc_set_dir(struct gaim_connection *g, char *first, char *middle, char *last, | |
963 char *maiden, char *city, char *state, char *country, int web) | |
964 { | |
965 char buf2[BUF_LEN * 4], buf[BUF_LEN]; | |
966 g_snprintf(buf2, sizeof(buf2), "%s:%s:%s:%s:%s:%s:%s:%s", first, | |
967 middle, last, maiden, city, state, country, (web == 1) ? "Y" : ""); | |
968 escape_text(buf2); | |
969 g_snprintf(buf, sizeof(buf), "toc_set_dir %s", buf2); | |
970 sflap_send(g, buf, -1, TYPE_DATA); | |
971 } | |
972 | |
973 static void toc_dir_search(struct gaim_connection *g, char *first, char *middle, char *last, | |
974 char *maiden, char *city, char *state, char *country, char *email) | |
975 { | |
976 char buf[BUF_LONG]; | |
977 g_snprintf(buf, sizeof(buf) / 2, "toc_dir_search %s:%s:%s:%s:%s:%s:%s:%s", first, middle, | |
978 last, maiden, city, state, country, email); | |
979 debug_printf("Searching for: %s,%s,%s,%s,%s,%s,%s\n", first, middle, last, maiden, | |
980 city, state, country); | |
981 sflap_send(g, buf, -1, TYPE_DATA); | |
982 } | |
983 | |
984 static void toc_set_away(struct gaim_connection *g, char *state, char *message) | |
985 { | |
986 char buf[BUF_LEN * 2]; | |
987 if (g->away) | |
988 g_free (g->away); | |
989 g->away = NULL; | |
990 if (message) { | |
991 g->away = g_strdup (message); | |
992 escape_text(message); | |
993 g_snprintf(buf, MSG_LEN, "toc_set_away \"%s\"", message); | |
994 } else | |
995 g_snprintf(buf, MSG_LEN, "toc_set_away \"\""); | |
996 sflap_send(g, buf, -1, TYPE_DATA); | |
997 } | |
998 | |
999 static void toc_set_info(struct gaim_connection *g, char *info) | |
1000 { | |
1001 char buf[BUF_LEN * 2], buf2[BUF_LEN * 2]; | |
1002 g_snprintf(buf2, sizeof buf2, "%s", info); | |
1003 escape_text(buf2); | |
1004 g_snprintf(buf, sizeof(buf), "toc_set_info \"%s\n\"", buf2); | |
1005 sflap_send(g, buf, -1, TYPE_DATA); | |
1006 } | |
1007 | |
1008 static void toc_change_passwd(struct gaim_connection *g, char *orig, char *new) | |
1009 { | |
1010 char buf[BUF_LEN * 2]; | |
1011 g_snprintf(buf, BUF_LONG, "toc_change_passwd %s %s", orig, new); | |
1012 sflap_send(g, buf, strlen(buf), TYPE_DATA); | |
1013 } | |
1014 | |
1015 static void toc_add_buddy(struct gaim_connection *g, char *name) | |
1016 { | |
1017 char buf[BUF_LEN * 2]; | |
1018 g_snprintf(buf, sizeof(buf), "toc_add_buddy %s", normalize(name)); | |
1019 sflap_send(g, buf, -1, TYPE_DATA); | |
1020 toc_set_config(g); | |
1021 } | |
1022 | |
2334
b53cd5b63a99
[gaim-migrate @ 2347]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2309
diff
changeset
|
1023 static void toc_add_buddies(struct gaim_connection *g, GList *buddies) |
2086 | 1024 { |
1025 char buf[BUF_LEN * 2]; | |
1026 int n; | |
1027 | |
1028 n = g_snprintf(buf, sizeof(buf), "toc_add_buddy"); | |
1029 while (buddies) { | |
2130
50c7a704ee56
[gaim-migrate @ 2140]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2128
diff
changeset
|
1030 if (strlen(normalize(buddies->data)) + n + 32 > MSG_LEN) { |
2086 | 1031 sflap_send(g, buf, -1, TYPE_DATA); |
1032 n = g_snprintf(buf, sizeof(buf), "toc_add_buddy"); | |
1033 } | |
1034 n += g_snprintf(buf + n, sizeof(buf) - n, " %s", normalize(buddies->data)); | |
1035 buddies = buddies->next; | |
1036 } | |
1037 sflap_send(g, buf, -1, TYPE_DATA); | |
1038 } | |
1039 | |
1040 static void toc_remove_buddy(struct gaim_connection *g, char *name) | |
1041 { | |
1042 char buf[BUF_LEN * 2]; | |
1043 g_snprintf(buf, sizeof(buf), "toc_remove_buddy %s", normalize(name)); | |
1044 sflap_send(g, buf, -1, TYPE_DATA); | |
1045 toc_set_config(g); | |
1046 } | |
1047 | |
2334
b53cd5b63a99
[gaim-migrate @ 2347]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2309
diff
changeset
|
1048 static void toc_remove_buddies(struct gaim_connection *g, GList *buddies) |
b53cd5b63a99
[gaim-migrate @ 2347]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2309
diff
changeset
|
1049 { |
b53cd5b63a99
[gaim-migrate @ 2347]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2309
diff
changeset
|
1050 char buf[BUF_LEN * 2]; |
b53cd5b63a99
[gaim-migrate @ 2347]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2309
diff
changeset
|
1051 int n; |
b53cd5b63a99
[gaim-migrate @ 2347]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2309
diff
changeset
|
1052 |
b53cd5b63a99
[gaim-migrate @ 2347]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2309
diff
changeset
|
1053 n = g_snprintf(buf, sizeof(buf), "toc_remove_buddy"); |
b53cd5b63a99
[gaim-migrate @ 2347]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2309
diff
changeset
|
1054 while (buddies) { |
b53cd5b63a99
[gaim-migrate @ 2347]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2309
diff
changeset
|
1055 if (strlen(normalize(buddies->data)) + n + 32 > MSG_LEN) { |
b53cd5b63a99
[gaim-migrate @ 2347]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2309
diff
changeset
|
1056 sflap_send(g, buf, -1, TYPE_DATA); |
b53cd5b63a99
[gaim-migrate @ 2347]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2309
diff
changeset
|
1057 n = g_snprintf(buf, sizeof(buf), "toc_remove_buddy"); |
b53cd5b63a99
[gaim-migrate @ 2347]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2309
diff
changeset
|
1058 } |
b53cd5b63a99
[gaim-migrate @ 2347]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2309
diff
changeset
|
1059 n += g_snprintf(buf + n, sizeof(buf) - n, " %s", normalize(buddies->data)); |
b53cd5b63a99
[gaim-migrate @ 2347]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2309
diff
changeset
|
1060 buddies = buddies->next; |
b53cd5b63a99
[gaim-migrate @ 2347]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2309
diff
changeset
|
1061 } |
b53cd5b63a99
[gaim-migrate @ 2347]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2309
diff
changeset
|
1062 sflap_send(g, buf, -1, TYPE_DATA); |
b53cd5b63a99
[gaim-migrate @ 2347]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2309
diff
changeset
|
1063 toc_set_config(g); |
b53cd5b63a99
[gaim-migrate @ 2347]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2309
diff
changeset
|
1064 } |
b53cd5b63a99
[gaim-migrate @ 2347]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2309
diff
changeset
|
1065 |
2086 | 1066 static void toc_set_idle(struct gaim_connection *g, int time) |
1067 { | |
1068 char buf[BUF_LEN * 2]; | |
1069 g_snprintf(buf, sizeof(buf), "toc_set_idle %d", time); | |
1070 sflap_send(g, buf, -1, TYPE_DATA); | |
1071 } | |
1072 | |
1073 static void toc_warn(struct gaim_connection *g, char *name, int anon) | |
1074 { | |
1075 char send[BUF_LEN * 2]; | |
1076 g_snprintf(send, 255, "toc_evil %s %s", name, ((anon) ? "anon" : "norm")); | |
1077 sflap_send(g, send, -1, TYPE_DATA); | |
1078 } | |
1079 | |
2205
cff4fbe01c7b
[gaim-migrate @ 2215]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2170
diff
changeset
|
1080 static GList *toc_chat_info(struct gaim_connection *gc) |
2086 | 1081 { |
2205
cff4fbe01c7b
[gaim-migrate @ 2215]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2170
diff
changeset
|
1082 GList *m = NULL; |
cff4fbe01c7b
[gaim-migrate @ 2215]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2170
diff
changeset
|
1083 struct proto_chat_entry *pce; |
cff4fbe01c7b
[gaim-migrate @ 2215]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2170
diff
changeset
|
1084 |
cff4fbe01c7b
[gaim-migrate @ 2215]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2170
diff
changeset
|
1085 pce = g_new0(struct proto_chat_entry, 1); |
cff4fbe01c7b
[gaim-migrate @ 2215]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2170
diff
changeset
|
1086 pce->label = _("Join what group:"); |
cff4fbe01c7b
[gaim-migrate @ 2215]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2170
diff
changeset
|
1087 m = g_list_append(m, pce); |
cff4fbe01c7b
[gaim-migrate @ 2215]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2170
diff
changeset
|
1088 |
cff4fbe01c7b
[gaim-migrate @ 2215]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2170
diff
changeset
|
1089 pce = g_new0(struct proto_chat_entry, 1); |
cff4fbe01c7b
[gaim-migrate @ 2215]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2170
diff
changeset
|
1090 pce->label = _("Exchange:"); |
cff4fbe01c7b
[gaim-migrate @ 2215]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2170
diff
changeset
|
1091 pce->is_int = TRUE; |
cff4fbe01c7b
[gaim-migrate @ 2215]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2170
diff
changeset
|
1092 pce->min = 4; |
cff4fbe01c7b
[gaim-migrate @ 2215]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2170
diff
changeset
|
1093 pce->max = 20; |
cff4fbe01c7b
[gaim-migrate @ 2215]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2170
diff
changeset
|
1094 m = g_list_append(m, pce); |
cff4fbe01c7b
[gaim-migrate @ 2215]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2170
diff
changeset
|
1095 |
cff4fbe01c7b
[gaim-migrate @ 2215]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2170
diff
changeset
|
1096 return m; |
2086 | 1097 } |
1098 | |
2205
cff4fbe01c7b
[gaim-migrate @ 2215]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2170
diff
changeset
|
1099 static void toc_join_chat(struct gaim_connection *g, GList *data) |
2086 | 1100 { |
1101 char buf[BUF_LONG]; | |
2205
cff4fbe01c7b
[gaim-migrate @ 2215]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2170
diff
changeset
|
1102 int *exchange; |
cff4fbe01c7b
[gaim-migrate @ 2215]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2170
diff
changeset
|
1103 char *name; |
cff4fbe01c7b
[gaim-migrate @ 2215]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2170
diff
changeset
|
1104 int *i; |
cff4fbe01c7b
[gaim-migrate @ 2215]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2170
diff
changeset
|
1105 |
cff4fbe01c7b
[gaim-migrate @ 2215]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2170
diff
changeset
|
1106 if (!data) |
cff4fbe01c7b
[gaim-migrate @ 2215]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2170
diff
changeset
|
1107 return; |
cff4fbe01c7b
[gaim-migrate @ 2215]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2170
diff
changeset
|
1108 |
cff4fbe01c7b
[gaim-migrate @ 2215]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2170
diff
changeset
|
1109 if (!data->next) { |
cff4fbe01c7b
[gaim-migrate @ 2215]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2170
diff
changeset
|
1110 i = data->data; |
cff4fbe01c7b
[gaim-migrate @ 2215]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2170
diff
changeset
|
1111 g_snprintf(buf, 255, "toc_chat_accept %d", *i); |
cff4fbe01c7b
[gaim-migrate @ 2215]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2170
diff
changeset
|
1112 } else { |
cff4fbe01c7b
[gaim-migrate @ 2215]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2170
diff
changeset
|
1113 name = data->data; |
cff4fbe01c7b
[gaim-migrate @ 2215]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2170
diff
changeset
|
1114 exchange = data->next->data; |
cff4fbe01c7b
[gaim-migrate @ 2215]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2170
diff
changeset
|
1115 g_snprintf(buf, sizeof(buf) / 2, "toc_chat_join %d \"%s\"", *exchange, name); |
cff4fbe01c7b
[gaim-migrate @ 2215]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2170
diff
changeset
|
1116 } |
cff4fbe01c7b
[gaim-migrate @ 2215]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2170
diff
changeset
|
1117 |
2086 | 1118 sflap_send(g, buf, -1, TYPE_DATA); |
1119 } | |
1120 | |
1121 static void toc_chat_invite(struct gaim_connection *g, int id, char *message, char *name) | |
1122 { | |
1123 char buf[BUF_LONG]; | |
1124 g_snprintf(buf, sizeof(buf) / 2, "toc_chat_invite %d \"%s\" %s", id, message, normalize(name)); | |
1125 sflap_send(g, buf, -1, TYPE_DATA); | |
1126 } | |
1127 | |
1128 static void toc_chat_leave(struct gaim_connection *g, int id) | |
1129 { | |
1130 GSList *bcs = g->buddy_chats; | |
1131 struct conversation *b = NULL; | |
1132 char buf[BUF_LEN * 2]; | |
1133 | |
1134 while (bcs) { | |
1135 b = (struct conversation *)bcs->data; | |
1136 if (id == b->id) | |
1137 break; | |
1138 b = NULL; | |
1139 bcs = bcs->next; | |
1140 } | |
1141 | |
1142 if (!b) | |
1143 return; /* can this happen? */ | |
1144 | |
1145 if (!b->gc) /* TOC already kicked us out of this room */ | |
1146 serv_got_chat_left(g, id); | |
1147 else { | |
1148 g_snprintf(buf, 255, "toc_chat_leave %d", id); | |
1149 sflap_send(g, buf, -1, TYPE_DATA); | |
1150 } | |
1151 } | |
1152 | |
1153 static void toc_chat_whisper(struct gaim_connection *g, int id, char *who, char *message) | |
1154 { | |
1155 char buf2[BUF_LEN * 2]; | |
2371
db02399a9ad7
[gaim-migrate @ 2384]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2343
diff
changeset
|
1156 escape_text(message); |
db02399a9ad7
[gaim-migrate @ 2384]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2343
diff
changeset
|
1157 g_snprintf(buf2, sizeof(buf2), "toc_chat_whisper %d %s \"%s\"", id, normalize(who), message); |
2086 | 1158 sflap_send(g, buf2, -1, TYPE_DATA); |
1159 } | |
1160 | |
2167
edf8c5a70e5b
[gaim-migrate @ 2177]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2162
diff
changeset
|
1161 static int toc_chat_send(struct gaim_connection *g, int id, char *message) |
2086 | 1162 { |
1163 char buf[BUF_LEN * 2]; | |
1164 escape_text(message); | |
2167
edf8c5a70e5b
[gaim-migrate @ 2177]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2162
diff
changeset
|
1165 if (strlen(message) > 2000) |
edf8c5a70e5b
[gaim-migrate @ 2177]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2162
diff
changeset
|
1166 return -E2BIG; |
2086 | 1167 g_snprintf(buf, sizeof(buf), "toc_chat_send %d \"%s\"", id, message); |
1168 sflap_send(g, buf, -1, TYPE_DATA); | |
2167
edf8c5a70e5b
[gaim-migrate @ 2177]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2162
diff
changeset
|
1169 return 0; |
2086 | 1170 } |
1171 | |
1172 static void toc_keepalive(struct gaim_connection *gc) | |
1173 { | |
1174 sflap_send(gc, "", 0, TYPE_KEEPALIVE); | |
1175 } | |
1176 | |
1177 static char **toc_list_icon(int uc) | |
1178 { | |
1179 if (uc & UC_UNAVAILABLE) | |
1180 return (char **)away_icon_xpm; | |
1181 if (uc & UC_AOL) | |
1182 return (char **)aol_icon_xpm; | |
1183 if (uc & UC_NORMAL) | |
1184 return (char **)free_icon_xpm; | |
1185 if (uc & UC_ADMIN) | |
1186 return (char **)admin_icon_xpm; | |
1187 if (uc & UC_UNCONFIRMED) | |
1188 return (char **)dt_icon_xpm; | |
1189 return NULL; | |
1190 } | |
1191 | |
2170
c24595d3c364
[gaim-migrate @ 2180]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2167
diff
changeset
|
1192 static GList *toc_buddy_menu(struct gaim_connection *gc, char *who) |
2086 | 1193 { |
2170
c24595d3c364
[gaim-migrate @ 2180]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2167
diff
changeset
|
1194 GList *m = NULL; |
c24595d3c364
[gaim-migrate @ 2180]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2167
diff
changeset
|
1195 struct proto_buddy_menu *pbm; |
2086 | 1196 |
2170
c24595d3c364
[gaim-migrate @ 2180]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2167
diff
changeset
|
1197 pbm = g_new0(struct proto_buddy_menu, 1); |
c24595d3c364
[gaim-migrate @ 2180]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2167
diff
changeset
|
1198 pbm->label = _("Get Info"); |
c24595d3c364
[gaim-migrate @ 2180]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2167
diff
changeset
|
1199 pbm->callback = toc_get_info; |
c24595d3c364
[gaim-migrate @ 2180]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2167
diff
changeset
|
1200 pbm->gc = gc; |
c24595d3c364
[gaim-migrate @ 2180]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2167
diff
changeset
|
1201 m = g_list_append(m, pbm); |
2086 | 1202 |
2170
c24595d3c364
[gaim-migrate @ 2180]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2167
diff
changeset
|
1203 pbm = g_new0(struct proto_buddy_menu, 1); |
c24595d3c364
[gaim-migrate @ 2180]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2167
diff
changeset
|
1204 pbm->label = _("Get Dir Info"); |
c24595d3c364
[gaim-migrate @ 2180]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2167
diff
changeset
|
1205 pbm->callback = toc_get_dir; |
c24595d3c364
[gaim-migrate @ 2180]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2167
diff
changeset
|
1206 pbm->gc = gc; |
c24595d3c364
[gaim-migrate @ 2180]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2167
diff
changeset
|
1207 m = g_list_append(m, pbm); |
c24595d3c364
[gaim-migrate @ 2180]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2167
diff
changeset
|
1208 |
c24595d3c364
[gaim-migrate @ 2180]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2167
diff
changeset
|
1209 return m; |
2086 | 1210 } |
1211 | |
2154
cff133e0ec0c
[gaim-migrate @ 2164]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2149
diff
changeset
|
1212 static GList *toc_user_opts() |
2086 | 1213 { |
2154
cff133e0ec0c
[gaim-migrate @ 2164]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2149
diff
changeset
|
1214 GList *m = NULL; |
cff133e0ec0c
[gaim-migrate @ 2164]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2149
diff
changeset
|
1215 struct proto_user_opt *puo; |
2086 | 1216 |
2154
cff133e0ec0c
[gaim-migrate @ 2164]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2149
diff
changeset
|
1217 puo = g_new0(struct proto_user_opt, 1); |
cff133e0ec0c
[gaim-migrate @ 2164]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2149
diff
changeset
|
1218 puo->label = "TOC Host:"; |
cff133e0ec0c
[gaim-migrate @ 2164]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2149
diff
changeset
|
1219 puo->def = "toc.oscar.aol.com"; |
cff133e0ec0c
[gaim-migrate @ 2164]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2149
diff
changeset
|
1220 puo->pos = USEROPT_AUTH; |
cff133e0ec0c
[gaim-migrate @ 2164]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2149
diff
changeset
|
1221 m = g_list_append(m, puo); |
2086 | 1222 |
2154
cff133e0ec0c
[gaim-migrate @ 2164]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2149
diff
changeset
|
1223 puo = g_new0(struct proto_user_opt, 1); |
cff133e0ec0c
[gaim-migrate @ 2164]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2149
diff
changeset
|
1224 puo->label = "TOC Port:"; |
cff133e0ec0c
[gaim-migrate @ 2164]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2149
diff
changeset
|
1225 puo->def = "9898"; |
cff133e0ec0c
[gaim-migrate @ 2164]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2149
diff
changeset
|
1226 puo->pos = USEROPT_AUTHPORT; |
cff133e0ec0c
[gaim-migrate @ 2164]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2149
diff
changeset
|
1227 m = g_list_append(m, puo); |
2086 | 1228 |
2154
cff133e0ec0c
[gaim-migrate @ 2164]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2149
diff
changeset
|
1229 return m; |
2086 | 1230 } |
1231 | |
1232 static void toc_add_permit(struct gaim_connection *gc, char *who) | |
1233 { | |
1234 char buf2[BUF_LEN * 2]; | |
1235 if (gc->permdeny != 3) | |
1236 return; | |
1237 g_snprintf(buf2, sizeof(buf2), "toc_add_permit %s", normalize(who)); | |
1238 sflap_send(gc, buf2, -1, TYPE_DATA); | |
1239 toc_set_config(gc); | |
1240 } | |
1241 | |
1242 static void toc_add_deny(struct gaim_connection *gc, char *who) | |
1243 { | |
1244 char buf2[BUF_LEN * 2]; | |
1245 if (gc->permdeny != 4) | |
1246 return; | |
1247 g_snprintf(buf2, sizeof(buf2), "toc_add_deny %s", normalize(who)); | |
1248 sflap_send(gc, buf2, -1, TYPE_DATA); | |
1249 toc_set_config(gc); | |
1250 } | |
1251 | |
1252 static void toc_set_permit_deny(struct gaim_connection *gc) | |
1253 { | |
1254 char buf2[BUF_LEN * 2]; | |
1255 GSList *list; | |
1256 int at; | |
1257 | |
1258 switch (gc->permdeny) { | |
1259 case 1: | |
1260 /* permit all, deny none. to get here reliably we need to have been in permit | |
1261 * mode, and send an empty toc_add_deny message, which will switch us to deny none */ | |
1262 g_snprintf(buf2, sizeof(buf2), "toc_add_permit "); | |
1263 sflap_send(gc, buf2, -1, TYPE_DATA); | |
1264 g_snprintf(buf2, sizeof(buf2), "toc_add_deny "); | |
1265 sflap_send(gc, buf2, -1, TYPE_DATA); | |
1266 break; | |
1267 case 2: | |
1268 /* deny all, permit none. to get here reliably we need to have been in deny | |
1269 * mode, and send an empty toc_add_permit message, which will switch us to permit none */ | |
1270 g_snprintf(buf2, sizeof(buf2), "toc_add_deny "); | |
1271 sflap_send(gc, buf2, -1, TYPE_DATA); | |
1272 g_snprintf(buf2, sizeof(buf2), "toc_add_permit "); | |
1273 sflap_send(gc, buf2, -1, TYPE_DATA); | |
1274 break; | |
1275 case 3: | |
1276 /* permit some. we want to switch to deny mode first, then send the toc_add_permit | |
1277 * message, which will clear and set our permit list. toc sucks. */ | |
1278 g_snprintf(buf2, sizeof(buf2), "toc_add_deny "); | |
1279 sflap_send(gc, buf2, -1, TYPE_DATA); | |
1280 | |
1281 at = g_snprintf(buf2, sizeof(buf2), "toc_add_permit "); | |
1282 list = gc->permit; | |
1283 while (list) { | |
1284 at += g_snprintf(buf2 + at, sizeof(buf2) - at, "%s ", normalize(list->data)); | |
1285 if (at > MSG_LEN + 32) { /* from out my ass comes greatness */ | |
1286 sflap_send(gc, buf2, -1, TYPE_DATA); | |
1287 at = g_snprintf(buf2, sizeof(buf2), "toc_add_permit "); | |
1288 } | |
1289 list = list->next; | |
1290 } | |
1291 sflap_send(gc, buf2, -1, TYPE_DATA); | |
1292 break; | |
1293 case 4: | |
1294 /* deny some. we want to switch to permit mode first, then send the toc_add_deny | |
1295 * message, which will clear and set our deny list. toc sucks. */ | |
1296 g_snprintf(buf2, sizeof(buf2), "toc_add_permit "); | |
1297 sflap_send(gc, buf2, -1, TYPE_DATA); | |
1298 | |
1299 at = g_snprintf(buf2, sizeof(buf2), "toc_add_deny "); | |
1300 list = gc->deny; | |
1301 while (list) { | |
1302 at += g_snprintf(buf2 + at, sizeof(buf2) - at, "%s ", normalize(list->data)); | |
1303 if (at > MSG_LEN + 32) { /* from out my ass comes greatness */ | |
1304 sflap_send(gc, buf2, -1, TYPE_DATA); | |
1305 at = g_snprintf(buf2, sizeof(buf2), "toc_add_deny "); | |
1306 } | |
1307 list = list->next; | |
1308 } | |
1309 sflap_send(gc, buf2, -1, TYPE_DATA); | |
1310 break; | |
1311 default: | |
1312 break; | |
1313 } | |
1314 toc_set_config(gc); | |
1315 } | |
1316 | |
1317 static void toc_rem_permit(struct gaim_connection *gc, char *who) | |
1318 { | |
1319 if (gc->permdeny != 3) | |
1320 return; | |
1321 toc_set_permit_deny(gc); | |
1322 } | |
1323 | |
1324 static void toc_rem_deny(struct gaim_connection *gc, char *who) | |
1325 { | |
1326 if (gc->permdeny != 4) | |
1327 return; | |
1328 toc_set_permit_deny(gc); | |
1329 } | |
1330 | |
2501
227cc42ffa6e
[gaim-migrate @ 2514]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2453
diff
changeset
|
1331 static GList *toc_away_states(struct gaim_connection *gc) |
2086 | 1332 { |
1333 return g_list_append(NULL, GAIM_AWAY_CUSTOM); | |
1334 } | |
1335 | |
1336 static void toc_do_action(struct gaim_connection *gc, char *act) | |
1337 { | |
1338 if (!strcmp(act, "Set User Info")) { | |
1339 show_set_info(gc); | |
1340 } else if (!strcmp(act, "Set Dir Info")) { | |
1341 show_set_dir(gc); | |
1342 } else if (!strcmp(act, "Change Password")) { | |
1343 show_change_passwd(gc); | |
1344 } | |
1345 } | |
1346 | |
1347 static GList *toc_actions() | |
1348 { | |
1349 GList *m = NULL; | |
1350 | |
1351 m = g_list_append(m, "Set User Info"); | |
1352 m = g_list_append(m, "Set Dir Info"); | |
1353 m = g_list_append(m, "Change Password"); | |
1354 | |
1355 return m; | |
1356 } | |
1357 | |
1358 static struct prpl *my_protocol = NULL; | |
1359 | |
1360 void toc_init(struct prpl *ret) | |
1361 { | |
1362 ret->protocol = PROTO_TOC; | |
1363 ret->options = OPT_PROTO_HTML | OPT_PROTO_CORRECT_TIME; | |
1364 ret->name = toc_name; | |
1365 ret->list_icon = toc_list_icon; | |
1366 ret->away_states = toc_away_states; | |
1367 ret->actions = toc_actions; | |
1368 ret->do_action = toc_do_action; | |
1369 ret->buddy_menu = toc_buddy_menu; | |
1370 ret->user_opts = toc_user_opts; | |
1371 ret->login = toc_login; | |
1372 ret->close = toc_close; | |
1373 ret->send_im = toc_send_im; | |
1374 ret->set_info = toc_set_info; | |
1375 ret->get_info = toc_get_info; | |
1376 ret->set_away = toc_set_away; | |
1377 ret->set_dir = toc_set_dir; | |
1378 ret->get_dir = toc_get_dir; | |
1379 ret->dir_search = toc_dir_search; | |
1380 ret->set_idle = toc_set_idle; | |
1381 ret->change_passwd = toc_change_passwd; | |
1382 ret->add_buddy = toc_add_buddy; | |
1383 ret->add_buddies = toc_add_buddies; | |
1384 ret->remove_buddy = toc_remove_buddy; | |
2334
b53cd5b63a99
[gaim-migrate @ 2347]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2309
diff
changeset
|
1385 ret->remove_buddies = toc_remove_buddies; |
2086 | 1386 ret->add_permit = toc_add_permit; |
1387 ret->add_deny = toc_add_deny; | |
1388 ret->rem_permit = toc_rem_permit; | |
1389 ret->rem_deny = toc_rem_deny; | |
1390 ret->set_permit_deny = toc_set_permit_deny; | |
1391 ret->warn = toc_warn; | |
2205
cff4fbe01c7b
[gaim-migrate @ 2215]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2170
diff
changeset
|
1392 ret->chat_info = toc_chat_info; |
2086 | 1393 ret->join_chat = toc_join_chat; |
1394 ret->chat_invite = toc_chat_invite; | |
1395 ret->chat_leave = toc_chat_leave; | |
1396 ret->chat_whisper = toc_chat_whisper; | |
1397 ret->chat_send = toc_chat_send; | |
1398 ret->keepalive = toc_keepalive; | |
1399 | |
1400 my_protocol = ret; | |
1401 } | |
1402 | |
1403 #ifndef STATIC | |
1404 | |
1405 char *gaim_plugin_init(GModule *handle) | |
1406 { | |
1407 load_protocol(toc_init, sizeof(struct prpl)); | |
1408 return NULL; | |
1409 } | |
1410 | |
1411 void gaim_plugin_remove() | |
1412 { | |
1413 struct prpl *p = find_prpl(PROTO_TOC); | |
1414 if (p == my_protocol) | |
1415 unload_protocol(p); | |
1416 } | |
1417 | |
1418 char *name() | |
1419 { | |
1420 return "TOC"; | |
1421 } | |
1422 | |
1423 char *description() | |
1424 { | |
2162
a464da684307
[gaim-migrate @ 2172]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2154
diff
changeset
|
1425 return PRPL_DESC("TOC"); |
2086 | 1426 } |
1427 | |
1428 #endif | |
1429 | |
1430 /********* | |
1431 * RVOUS ACTIONS | |
1432 ********/ | |
1433 | |
1434 struct file_header { | |
1435 char magic[4]; /* 0 */ | |
1436 short hdrlen; /* 4 */ | |
1437 short hdrtype; /* 6 */ | |
1438 char bcookie[8]; /* 8 */ | |
1439 short encrypt; /* 16 */ | |
1440 short compress; /* 18 */ | |
1441 short totfiles; /* 20 */ | |
1442 short filesleft; /* 22 */ | |
1443 short totparts; /* 24 */ | |
1444 short partsleft; /* 26 */ | |
1445 long totsize; /* 28 */ | |
1446 long size; /* 32 */ | |
1447 long modtime; /* 36 */ | |
1448 long checksum; /* 40 */ | |
1449 long rfrcsum; /* 44 */ | |
1450 long rfsize; /* 48 */ | |
1451 long cretime; /* 52 */ | |
1452 long rfcsum; /* 56 */ | |
1453 long nrecvd; /* 60 */ | |
1454 long recvcsum; /* 64 */ | |
1455 char idstring[32]; /* 68 */ | |
1456 char flags; /* 100 */ | |
1457 char lnameoffset; /* 101 */ | |
1458 char lsizeoffset; /* 102 */ | |
1459 char dummy[69]; /* 103 */ | |
1460 char macfileinfo[16]; /* 172 */ | |
1461 short nencode; /* 188 */ | |
1462 short nlanguage; /* 190 */ | |
1463 char name[64]; /* 192 */ | |
1464 /* 256 */ | |
1465 }; | |
1466 | |
1467 struct file_transfer { | |
1468 struct file_header hdr; | |
1469 | |
1470 struct gaim_connection *gc; | |
1471 | |
1472 char *user; | |
1473 char *cookie; | |
1474 char *ip; | |
1475 int port; | |
1476 long size; | |
1477 struct stat st; | |
1478 | |
1479 GtkWidget *window; | |
1480 int files; | |
1481 char *filename; | |
1482 FILE *file; | |
1483 int recvsize; | |
1484 | |
1485 gint inpa; | |
1486 }; | |
1487 | |
1488 static void debug_header(struct file_transfer *ft) { | |
1489 struct file_header *f = (struct file_header *)ft; | |
1490 debug_printf("TOC FT HEADER:\n" | |
1491 "\t%s %d 0x%04x\n" | |
1492 "\t%s %d %d\n" | |
1493 "\t%d %d %d %d %ld %ld\n" | |
1494 "\t%ld %ld %ld %ld %ld %ld %ld %ld\n" | |
1495 "\t%s\n" | |
1496 "\t0x%02x, 0x%02x, 0x%02x\n" | |
1497 "\t%s %s\n" | |
1498 "\t%d %d\n" | |
1499 "\t%s\n", | |
1500 f->magic, ntohs(f->hdrlen), f->hdrtype, | |
1501 f->bcookie, ntohs(f->encrypt), ntohs(f->compress), | |
1502 ntohs(f->totfiles), ntohs(f->filesleft), ntohs(f->totparts), | |
1503 ntohs(f->partsleft), ntohl(f->totsize), ntohl(f->size), | |
1504 ntohl(f->modtime), ntohl(f->checksum), ntohl(f->rfrcsum), ntohl(f->rfsize), | |
1505 ntohl(f->cretime), ntohl(f->rfcsum), ntohl(f->nrecvd), | |
1506 ntohl(f->recvcsum), | |
1507 f->idstring, | |
1508 f->flags, f->lnameoffset, f->lsizeoffset, | |
1509 f->dummy, f->macfileinfo, | |
1510 ntohs(f->nencode), ntohs(f->nlanguage), | |
1511 f->name); | |
1512 } | |
1513 | |
2090
b66aca8e8dce
[gaim-migrate @ 2100]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1514 static void toc_send_file_callback(gpointer data, gint source, GaimInputCondition cond) |
2086 | 1515 { |
1516 char buf[BUF_LONG]; | |
1517 int rt, i; | |
1518 | |
1519 struct file_transfer *ft = data; | |
1520 | |
1521 if (ft->hdr.hdrtype != 0x202) { | |
1522 char *buf; | |
1523 frombase64(ft->cookie, &buf, NULL); | |
1524 | |
1525 read(source, ft, 8); | |
1526 read(source, &ft->hdr.bcookie, MIN(256 - 8, ntohs(ft->hdr.hdrlen) - 8)); | |
1527 debug_header(ft); | |
1528 | |
1529 ft->hdr.hdrtype = 0x202; | |
1530 memcpy(ft->hdr.bcookie, buf, 8); | |
1531 g_free(buf); | |
1532 ft->hdr.encrypt = 0; ft->hdr.compress = 0; | |
1533 debug_header(ft); | |
1534 write(source, ft, 256); | |
1535 | |
1536 if (ft->files == 1) { | |
1537 ft->file = fopen(ft->filename, "w"); | |
1538 if (!ft->file) { | |
1539 buf = g_strdup_printf("Could not open %s for writing!", ft->filename); | |
1540 do_error_dialog(buf, _("Error")); | |
1541 g_free(buf); | |
2090
b66aca8e8dce
[gaim-migrate @ 2100]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1542 gaim_input_remove(ft->inpa); |
2086 | 1543 close(source); |
1544 g_free(ft->filename); | |
1545 g_free(ft->user); | |
1546 g_free(ft->ip); | |
1547 g_free(ft->cookie); | |
1548 g_free(ft); | |
1549 } | |
1550 } else { | |
1551 buf = g_strdup_printf("%s/%s", ft->filename, ft->hdr.name); | |
1552 ft->file = fopen(buf, "w"); | |
1553 g_free(buf); | |
1554 if (!ft->file) { | |
1555 buf = g_strdup_printf("Could not open %s/%s for writing!", ft->filename, | |
1556 ft->hdr.name); | |
1557 do_error_dialog(buf, _("Error")); | |
1558 g_free(buf); | |
2090
b66aca8e8dce
[gaim-migrate @ 2100]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1559 gaim_input_remove(ft->inpa); |
2086 | 1560 close(source); |
1561 g_free(ft->filename); | |
1562 g_free(ft->user); | |
1563 g_free(ft->ip); | |
1564 g_free(ft->cookie); | |
1565 g_free(ft); | |
1566 } | |
1567 } | |
1568 | |
1569 return; | |
1570 } | |
1571 | |
1572 rt = read(source, buf, MIN(ntohl(ft->hdr.size) - ft->recvsize, 1024)); | |
1573 if (rt < 0) { | |
1574 do_error_dialog("File transfer failed; other side probably canceled.", "Error"); | |
2090
b66aca8e8dce
[gaim-migrate @ 2100]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1575 gaim_input_remove(ft->inpa); |
2086 | 1576 close(source); |
1577 g_free(ft->user); | |
1578 g_free(ft->ip); | |
1579 g_free(ft->cookie); | |
1580 if (ft->file) | |
1581 fclose(ft->file); | |
1582 g_free(ft); | |
1583 return; | |
1584 } | |
1585 ft->recvsize += rt; | |
1586 for (i = 0; i < rt; i++) | |
1587 fprintf(ft->file, "%c", buf[i]); | |
1588 | |
1589 if (ft->recvsize == ntohl(ft->hdr.size)) { | |
1590 ft->hdr.hdrtype = htons(0x0204); | |
1591 ft->hdr.filesleft = htons(ntohs(ft->hdr.filesleft) - 1); | |
1592 ft->hdr.partsleft = htons(ntohs(ft->hdr.partsleft) - 1); | |
1593 ft->hdr.recvcsum = ft->hdr.checksum; /* uh... */ | |
1594 ft->hdr.nrecvd = htons(ntohs(ft->hdr.nrecvd) + 1); | |
1595 ft->hdr.flags = 0; | |
1596 write(source, ft, 256); | |
1597 debug_header(ft); | |
1598 ft->recvsize = 0; | |
1599 fclose(ft->file); | |
1600 if (ft->hdr.filesleft == 0) { | |
2090
b66aca8e8dce
[gaim-migrate @ 2100]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1601 gaim_input_remove(ft->inpa); |
2086 | 1602 close(source); |
1603 g_free(ft->filename); | |
1604 g_free(ft->user); | |
1605 g_free(ft->ip); | |
1606 g_free(ft->cookie); | |
1607 g_free(ft); | |
1608 } | |
1609 } | |
1610 } | |
1611 | |
2090
b66aca8e8dce
[gaim-migrate @ 2100]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1612 static void toc_send_file_connect(gpointer data, gint src, GaimInputCondition cond) |
2086 | 1613 { |
1614 struct file_transfer *ft = data; | |
1615 | |
1616 if (src == -1) { | |
1617 do_error_dialog(_("Could not connect for transfer!"), _("Error")); | |
1618 g_free(ft->filename); | |
1619 g_free(ft->cookie); | |
1620 g_free(ft->user); | |
1621 g_free(ft->ip); | |
1622 g_free(ft); | |
1623 return; | |
1624 } | |
1625 | |
2090
b66aca8e8dce
[gaim-migrate @ 2100]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1626 ft->inpa = gaim_input_add(src, GAIM_INPUT_READ, toc_send_file_callback, ft); |
2086 | 1627 } |
1628 | |
1629 static void toc_send_file(gpointer a, struct file_transfer *old_ft) | |
1630 { | |
1631 struct file_transfer *ft; | |
1632 const char *dirname = gtk_file_selection_get_filename(GTK_FILE_SELECTION(old_ft->window)); | |
1633 int fd; | |
1634 struct aim_user *user; | |
1635 char buf[BUF_LEN * 2]; | |
1636 | |
1637 if (file_is_dir(dirname, old_ft->window)) | |
1638 return; | |
1639 ft = g_new0(struct file_transfer, 1); | |
1640 if (old_ft->files == 1) | |
1641 ft->filename = g_strdup(dirname); | |
1642 else | |
1643 ft->filename = g_dirname(dirname); | |
1644 ft->cookie = g_strdup(old_ft->cookie); | |
1645 ft->user = g_strdup(old_ft->user); | |
1646 ft->ip = g_strdup(old_ft->ip); | |
1647 ft->files = old_ft->files; | |
1648 ft->port = old_ft->port; | |
1649 ft->gc = old_ft->gc; | |
1650 user = ft->gc->user; | |
1651 gtk_widget_destroy(old_ft->window); | |
1652 | |
1653 g_snprintf(buf, sizeof(buf), "toc_rvous_accept %s %s %s", ft->user, ft->cookie, FILE_SEND_UID); | |
1654 sflap_send(ft->gc, buf, -1, TYPE_DATA); | |
1655 | |
1656 fd = | |
1657 proxy_connect(ft->ip, ft->port, toc_send_file_connect, ft); | |
1658 if (fd < 0) { | |
1659 do_error_dialog(_("Could not connect for transfer!"), _("Error")); | |
1660 g_free(ft->filename); | |
1661 g_free(ft->cookie); | |
1662 g_free(ft->user); | |
1663 g_free(ft->ip); | |
1664 g_free(ft); | |
1665 return; | |
1666 } | |
1667 } | |
1668 | |
2090
b66aca8e8dce
[gaim-migrate @ 2100]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1669 static void toc_get_file_callback(gpointer data, gint source, GaimInputCondition cond) |
2086 | 1670 { |
1671 char buf[BUF_LONG]; | |
1672 | |
1673 struct file_transfer *ft = data; | |
1674 | |
2090
b66aca8e8dce
[gaim-migrate @ 2100]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1675 if (cond & GAIM_INPUT_WRITE) { |
2086 | 1676 int remain = MIN(ntohl(ft->hdr.totsize) - ft->recvsize, 1024); |
1677 int i; | |
1678 for (i = 0; i < remain; i++) | |
1679 fscanf(ft->file, "%c", &buf[i]); | |
1680 write(source, buf, remain); | |
1681 ft->recvsize += remain; | |
1682 if (ft->recvsize == ntohl(ft->hdr.totsize)) { | |
2090
b66aca8e8dce
[gaim-migrate @ 2100]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1683 gaim_input_remove(ft->inpa); |
b66aca8e8dce
[gaim-migrate @ 2100]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1684 ft->inpa = gaim_input_add(source, GAIM_INPUT_READ, |
2086 | 1685 toc_get_file_callback, ft); |
1686 } | |
1687 return; | |
1688 } | |
1689 | |
1690 if (ft->hdr.hdrtype == htons(0x1108)) { | |
1691 struct tm *fortime; | |
1692 struct stat st; | |
1693 | |
1694 read(source, ft, 8); | |
1695 read(source, &ft->hdr.bcookie, MIN(256 - 8, ntohs(ft->hdr.hdrlen) - 8)); | |
1696 debug_header(ft); | |
1697 | |
1698 stat(ft->filename, &st); | |
1699 fortime = localtime(&st.st_mtime); | |
1700 g_snprintf(buf, sizeof(buf), "%2d/%2d/%4d %2d:%2d %8ld %s\r\n", | |
1701 fortime->tm_mon + 1, fortime->tm_mday, fortime->tm_year + 1900, | |
1702 fortime->tm_hour + 1, fortime->tm_min + 1, (long)st.st_size, | |
1703 g_basename(ft->filename)); | |
1704 write(source, buf, ntohl(ft->hdr.size)); | |
1705 return; | |
1706 } | |
1707 | |
1708 if (ft->hdr.hdrtype == htons(0x1209)) { | |
1709 read(source, ft, 8); | |
1710 read(source, &ft->hdr.bcookie, MIN(256 - 8, ntohs(ft->hdr.hdrlen) - 8)); | |
1711 debug_header(ft); | |
1712 return; | |
1713 } | |
1714 | |
1715 if (ft->hdr.hdrtype == htons(0x120b)) { | |
1716 read(source, ft, 8); | |
1717 read(source, &ft->hdr.bcookie, MIN(256 - 8, ntohs(ft->hdr.hdrlen) - 8)); | |
1718 debug_header(ft); | |
1719 | |
1720 if (ft->hdr.hdrtype != htons(0x120c)) { | |
1721 g_snprintf(buf, sizeof(buf), "%s decided to cancel the transfer", ft->user); | |
1722 do_error_dialog(buf, "Error"); | |
2090
b66aca8e8dce
[gaim-migrate @ 2100]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1723 gaim_input_remove(ft->inpa); |
2086 | 1724 close(source); |
1725 g_free(ft->filename); | |
1726 g_free(ft->user); | |
1727 g_free(ft->ip); | |
1728 g_free(ft->cookie); | |
1729 if (ft->file) | |
1730 fclose(ft->file); | |
1731 g_free(ft); | |
1732 return; | |
1733 } | |
1734 | |
1735 ft->hdr.hdrtype = 0x0101; | |
1736 ft->hdr.totfiles = htons(1); ft->hdr.filesleft = htons(1); | |
1737 ft->hdr.flags = 0x20; | |
1738 write(source, ft, 256); | |
1739 return; | |
1740 } | |
1741 | |
1742 if (ft->hdr.hdrtype == 0x0101) { | |
1743 read(source, ft, 8); | |
1744 read(source, &ft->hdr.bcookie, MIN(256 - 8, ntohs(ft->hdr.hdrlen) - 8)); | |
1745 debug_header(ft); | |
1746 | |
2090
b66aca8e8dce
[gaim-migrate @ 2100]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1747 gaim_input_remove(ft->inpa); |
b66aca8e8dce
[gaim-migrate @ 2100]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1748 ft->inpa = gaim_input_add(source, GAIM_INPUT_WRITE, |
2086 | 1749 toc_get_file_callback, ft); |
1750 return; | |
1751 } | |
1752 | |
1753 if (ft->hdr.hdrtype == 0x0202) { | |
1754 read(source, ft, 8); | |
1755 read(source, &ft->hdr.bcookie, MIN(256 - 8, ntohs(ft->hdr.hdrlen) - 8)); | |
1756 debug_header(ft); | |
1757 | |
2090
b66aca8e8dce
[gaim-migrate @ 2100]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1758 gaim_input_remove(ft->inpa); |
2086 | 1759 close(source); |
1760 g_free(ft->filename); | |
1761 g_free(ft->user); | |
1762 g_free(ft->ip); | |
1763 g_free(ft->cookie); | |
1764 if (ft->file) | |
1765 fclose(ft->file); | |
1766 g_free(ft); | |
1767 return; | |
1768 } | |
1769 } | |
1770 | |
2090
b66aca8e8dce
[gaim-migrate @ 2100]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1771 static void toc_get_file_connect(gpointer data, gint src, GaimInputCondition cond) |
2086 | 1772 { |
1773 struct file_transfer *ft = data; | |
1774 struct file_header *hdr; | |
1775 char *buf; | |
1776 | |
1777 if (src == -1) { | |
1778 do_error_dialog(_("Could not connect for transfer!"), _("Error")); | |
1779 fclose(ft->file); | |
1780 g_free(ft->filename); | |
1781 g_free(ft->cookie); | |
1782 g_free(ft->user); | |
1783 g_free(ft->ip); | |
1784 g_free(ft); | |
1785 return; | |
1786 } | |
1787 | |
1788 hdr = (struct file_header *)ft; | |
1789 hdr->magic[0] = 'O'; hdr->magic[1] = 'F'; hdr->magic[2] = 'T'; hdr->magic[3] = '2'; | |
1790 hdr->hdrlen = htons(256); | |
1791 hdr->hdrtype = htons(0x1108); | |
1792 frombase64(ft->cookie, &buf, NULL); | |
1793 g_snprintf(hdr->bcookie, 8, "%s", buf); | |
1794 g_free(buf); | |
1795 hdr->totfiles = htons(1); hdr->filesleft = htons(1); | |
1796 hdr->totparts = htons(1); hdr->partsleft = htons(1); | |
1797 hdr->totsize = htonl((long)ft->st.st_size); /* combined size of all files */ | |
1798 /* size = strlen("mm/dd/yyyy hh:mm sizesize 'name'\r\n") */ | |
1799 hdr->size = htonl(28 + strlen(g_basename(ft->filename))); /* size of listing.txt */ | |
1800 hdr->modtime = htonl(ft->st.st_mtime); | |
1801 hdr->checksum = htonl(0x89f70000); /* uh... */ | |
1802 g_snprintf(hdr->idstring, 32, "OFT_Windows ICBMFT V1.1 32"); | |
1803 hdr->flags = 0x02; | |
1804 hdr->lnameoffset = 0x1A; | |
1805 hdr->lsizeoffset = 0x10; | |
1806 g_snprintf(hdr->name, 64, "listing.txt"); | |
1807 if (write(src, hdr, 256) < 0) { | |
1808 do_error_dialog(_("Could not write file header!"), _("Error")); | |
1809 fclose(ft->file); | |
1810 g_free(ft->filename); | |
1811 g_free(ft->cookie); | |
1812 g_free(ft->user); | |
1813 g_free(ft->ip); | |
1814 g_free(ft); | |
1815 return; | |
1816 } | |
1817 | |
2090
b66aca8e8dce
[gaim-migrate @ 2100]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1818 ft->inpa = gaim_input_add(src, GAIM_INPUT_READ, toc_get_file_callback, ft); |
2086 | 1819 } |
1820 | |
1821 static void toc_get_file(gpointer a, struct file_transfer *old_ft) | |
1822 { | |
1823 struct file_transfer *ft; | |
1824 const char *dirname = gtk_file_selection_get_filename(GTK_FILE_SELECTION(old_ft->window)); | |
1825 int fd; | |
1826 struct aim_user *user; | |
1827 char *buf, buf2[BUF_LEN * 2]; | |
1828 | |
1829 if (file_is_dir(dirname, old_ft->window)) | |
1830 return; | |
1831 ft = g_new0(struct file_transfer, 1); | |
1832 ft->filename = g_strdup(dirname); | |
1833 ft->file = fopen(ft->filename, "r"); | |
1834 if (!ft->file) { | |
1835 buf = g_strdup_printf("Unable to open %s for transfer!", ft->filename); | |
1836 do_error_dialog(buf, "Error"); | |
1837 g_free(buf); | |
1838 g_free(ft->filename); | |
1839 g_free(ft); | |
1840 return; | |
1841 } | |
1842 if (stat(dirname, &ft->st)) { | |
1843 buf = g_strdup_printf("Unable to examine %s!", dirname); | |
1844 do_error_dialog(buf, "Error"); | |
1845 g_free(buf); | |
1846 g_free(ft->filename); | |
1847 g_free(ft); | |
1848 return; | |
1849 } | |
1850 ft->cookie = g_strdup(old_ft->cookie); | |
1851 ft->user = g_strdup(old_ft->user); | |
1852 ft->ip = g_strdup(old_ft->ip); | |
1853 ft->port = old_ft->port; | |
1854 ft->gc = old_ft->gc; | |
1855 user = ft->gc->user; | |
1856 gtk_widget_destroy(old_ft->window); | |
1857 | |
1858 g_snprintf(buf2, sizeof(buf2), "toc_rvous_accept %s %s %s", ft->user, ft->cookie, FILE_GET_UID); | |
1859 sflap_send(ft->gc, buf2, -1, TYPE_DATA); | |
1860 | |
1861 fd = | |
1862 proxy_connect(ft->ip, ft->port, toc_get_file_connect, ft); | |
1863 if (fd < 0) { | |
1864 do_error_dialog(_("Could not connect for transfer!"), _("Error")); | |
1865 fclose(ft->file); | |
1866 g_free(ft->filename); | |
1867 g_free(ft->cookie); | |
1868 g_free(ft->user); | |
1869 g_free(ft->ip); | |
1870 g_free(ft); | |
1871 return; | |
1872 } | |
1873 } | |
1874 | |
1875 static void cancel_callback(gpointer a, struct file_transfer *ft) { | |
1876 gtk_widget_destroy(ft->window); | |
1877 if (a == ft->window) { | |
1878 g_free(ft->cookie); | |
1879 g_free(ft->user); | |
1880 g_free(ft->ip); | |
1881 g_free(ft); | |
1882 } | |
1883 } | |
1884 | |
1885 static void toc_accept_ft(gpointer a, struct ft_request *fr) { | |
1886 GtkWidget *window; | |
1887 char buf[BUF_LEN]; | |
1888 | |
1889 struct file_transfer *ft = g_new0(struct file_transfer, 1); | |
1890 ft->gc = fr->gc; | |
1891 ft->user = g_strdup(fr->user); | |
1892 ft->cookie = g_strdup(fr->cookie); | |
1893 ft->ip = g_strdup(fr->ip); | |
1894 ft->port = fr->port; | |
1895 ft->files = fr->files; | |
1896 | |
1897 ft->window = window = gtk_file_selection_new(_("Gaim - Save As...")); | |
1898 g_snprintf(buf, sizeof(buf), "%s/%s", g_get_home_dir(), fr->filename ? fr->filename : ""); | |
1899 gtk_file_selection_set_filename(GTK_FILE_SELECTION(window), buf); | |
1900 gtk_signal_connect(GTK_OBJECT(window), "destroy", | |
1901 GTK_SIGNAL_FUNC(cancel_callback), ft); | |
1902 gtk_signal_connect(GTK_OBJECT(GTK_FILE_SELECTION(ft->window)->cancel_button), "clicked", | |
1903 GTK_SIGNAL_FUNC(cancel_callback), ft); | |
1904 | |
1905 if (!strcmp(fr->UID, FILE_SEND_UID)) | |
1906 gtk_signal_connect(GTK_OBJECT(GTK_FILE_SELECTION(window)->ok_button), "clicked", | |
1907 GTK_SIGNAL_FUNC(toc_send_file), ft); | |
1908 else | |
1909 gtk_signal_connect(GTK_OBJECT(GTK_FILE_SELECTION(window)->ok_button), "clicked", | |
1910 GTK_SIGNAL_FUNC(toc_get_file), ft); | |
1911 | |
1912 gtk_widget_show(window); | |
1913 } | |
1914 | |
1915 static void toc_reject_ft(gpointer a, struct ft_request *ft) { | |
1916 g_free(ft->user); | |
1917 g_free(ft->filename); | |
1918 g_free(ft->ip); | |
1919 g_free(ft->cookie); | |
1920 if (ft->message) | |
1921 g_free(ft->message); | |
1922 g_free(ft); | |
1923 } | |
1924 | |
1925 static void accept_file_dialog(struct ft_request *ft) { | |
1926 char buf[BUF_LONG]; | |
1927 if (!strcmp(ft->UID, FILE_SEND_UID)) { | |
1928 /* holy crap. who the fuck would transfer gigabytes through AIM?! */ | |
1929 static char *sizes[4] = { "bytes", "KB", "MB", "GB" }; | |
1930 float size = ft->size; | |
1931 int index = 0; | |
1932 while ((index < 4) && (size > 1024)) { | |
1933 size /= 1024; | |
1934 index++; | |
1935 } | |
1936 g_snprintf(buf, sizeof(buf), _("%s requests %s to accept %d file%s: %s (%.2f %s)%s%s"), | |
1937 ft->user, ft->gc->username, ft->files, (ft->files == 1) ? "" : "s", | |
1938 ft->filename, size, sizes[index], (ft->message) ? "\n" : "", | |
1939 (ft->message) ? ft->message : ""); | |
1940 } else { | |
1941 g_snprintf(buf, sizeof(buf), _("%s requests you to send them a file"), ft->user); | |
1942 } | |
1943 do_ask_dialog(buf, ft, toc_accept_ft, toc_reject_ft); | |
1944 } |