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