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