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