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