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