comparison src/toc.c @ 1459:d6340f73e94b

[gaim-migrate @ 1469] multi-file file receive committer: Tailor Script <tailor@pidgin.im>
author Eric Warmenhoven <eric@warmenhoven.org>
date Thu, 01 Feb 2001 12:02:13 +0000
parents c6f9d0cdaa00
children 1a24237f5865
comparison
equal deleted inserted replaced
1458:6933fd960557 1459:d6340f73e94b
44 #include "pixmaps/aol_icon.xpm" 44 #include "pixmaps/aol_icon.xpm"
45 #include "pixmaps/away_icon.xpm" 45 #include "pixmaps/away_icon.xpm"
46 #include "pixmaps/dt_icon.xpm" 46 #include "pixmaps/dt_icon.xpm"
47 #include "pixmaps/free_icon.xpm" 47 #include "pixmaps/free_icon.xpm"
48 48
49 #define REVISION "gaim:$Revision: 1467 $" 49 #define REVISION "gaim:$Revision: 1469 $"
50 50
51 #define TYPE_SIGNON 1 51 #define TYPE_SIGNON 1
52 #define TYPE_DATA 2 52 #define TYPE_DATA 2
53 #define TYPE_ERROR 3 53 #define TYPE_ERROR 3
54 #define TYPE_SIGNOFF 4 54 #define TYPE_SIGNOFF 4
357 /* Client sends TOC toc_init_done message */ 357 /* Client sends TOC toc_init_done message */
358 debug_printf("* Client sends TOC toc_init_done message\n"); 358 debug_printf("* Client sends TOC toc_init_done message\n");
359 g_snprintf(snd, sizeof snd, "toc_init_done"); 359 g_snprintf(snd, sizeof snd, "toc_init_done");
360 sflap_send(gc, snd, -1, TYPE_DATA); 360 sflap_send(gc, snd, -1, TYPE_DATA);
361 361
362 g_snprintf(snd, sizeof snd, "toc_set_caps %s", FILE_SEND_UID); 362 g_snprintf(snd, sizeof snd, "toc_set_caps %s %s", FILE_SEND_UID, FILE_GET_UID);
363 sflap_send(gc, snd, -1, TYPE_DATA); 363 sflap_send(gc, snd, -1, TYPE_DATA);
364 364
365 return; 365 return;
366 } 366 }
367 367
631 debug_printf("English translation of RVOUS_PROPOSE: %s requests Send File (i.e." 631 debug_printf("English translation of RVOUS_PROPOSE: %s requests Send File (i.e."
632 " send a file to you); %s:%d (verified_ip:port), %d files at" 632 " send a file to you); %s:%d (verified_ip:port), %d files at"
633 " total size of %ld bytes.\n", user, vip, port, files, totalsize); 633 " total size of %ld bytes.\n", user, vip, port, files, totalsize);
634 accept_file_dialog(ft); 634 accept_file_dialog(ft);
635 } else if (!strcmp(uuid, FILE_GET_UID)) { 635 } else if (!strcmp(uuid, FILE_GET_UID)) {
636 /* they want us to send a file 636 /* they want us to send a file */
637 int unk[4], i; 637 int unk[4], i;
638 char *messages[4], *tmp; 638 char *messages[4], *tmp;
639 struct ft_request *ft; 639 struct ft_request *ft;
640 640
641 for (i = 0; i < 4; i++) { 641 for (i = 0; i < 4; i++) {
661 g_free(tmp); 661 g_free(tmp);
662 for (i--; i >= 0; i--) 662 for (i--; i >= 0; i--)
663 g_free(messages[i]); 663 g_free(messages[i]);
664 664
665 accept_file_dialog(ft); 665 accept_file_dialog(ft);
666 */
667 } else if (!strcmp(uuid, VOICE_UID)) { 666 } else if (!strcmp(uuid, VOICE_UID)) {
668 /* oh goody. voice over ip. fun stuff. */ 667 /* oh goody. voice over ip. fun stuff. */
669 } else if (!strcmp(uuid, B_ICON_UID)) { 668 } else if (!strcmp(uuid, B_ICON_UID)) {
670 /* buddy icon... */ 669 /* buddy icon... */
671 } else if (!strcmp(uuid, IMAGE_UID)) { 670 } else if (!strcmp(uuid, IMAGE_UID)) {
1293 char *ip; 1292 char *ip;
1294 int port; 1293 int port;
1295 long size; 1294 long size;
1296 1295
1297 GtkWidget *window; 1296 GtkWidget *window;
1297 int files;
1298 char *filename;
1298 FILE *file; 1299 FILE *file;
1299 int recvsize; 1300 int recvsize;
1300 1301
1301 gint inpa; 1302 gint inpa;
1302 }; 1303 };
1342 struct file_transfer *ft = data; 1343 struct file_transfer *ft = data;
1343 1344
1344 if (cond & GDK_INPUT_EXCEPTION) { 1345 if (cond & GDK_INPUT_EXCEPTION) {
1345 gdk_input_remove(ft->inpa); 1346 gdk_input_remove(ft->inpa);
1346 close(source); 1347 close(source);
1348 g_free(ft->filename);
1347 g_free(ft->user); 1349 g_free(ft->user);
1348 g_free(ft->ip); 1350 g_free(ft->ip);
1349 g_free(ft->cookie); 1351 g_free(ft->cookie);
1350 fclose(ft->file); 1352 if (ft->file)
1353 fclose(ft->file);
1351 g_free(ft); 1354 g_free(ft);
1352 return; 1355 return;
1353 } 1356 }
1354 1357
1355 if (ft->hdr.hdrtype != 0x202) { 1358 if (ft->hdr.hdrtype != 0x202) {
1363 memcpy(ft->hdr.bcookie, buf, 8); 1366 memcpy(ft->hdr.bcookie, buf, 8);
1364 g_free(buf); 1367 g_free(buf);
1365 ft->hdr.encrypt = 0; ft->hdr.compress = 0; 1368 ft->hdr.encrypt = 0; ft->hdr.compress = 0;
1366 debug_header(ft); 1369 debug_header(ft);
1367 write(source, ft, 256); 1370 write(source, ft, 256);
1371
1372 if (ft->files == 1) {
1373 ft->file = fopen(ft->filename, "w");
1374 if (!ft->file) {
1375 buf = g_strdup_printf("Could not open %s for writing!", ft->filename);
1376 do_error_dialog(buf, _("Error"));
1377 g_free(buf);
1378 gdk_input_remove(ft->inpa);
1379 close(source);
1380 g_free(ft->filename);
1381 g_free(ft->user);
1382 g_free(ft->ip);
1383 g_free(ft->cookie);
1384 g_free(ft);
1385 }
1386 } else {
1387 buf = g_strdup_printf("%s/%s", ft->filename, ft->hdr.name);
1388 ft->file = fopen(buf, "w");
1389 g_free(buf);
1390 if (!ft->file) {
1391 buf = g_strdup_printf("Could not open %s/%s for writing!", ft->filename,
1392 ft->hdr.name);
1393 do_error_dialog(buf, _("Error"));
1394 g_free(buf);
1395 gdk_input_remove(ft->inpa);
1396 close(source);
1397 g_free(ft->filename);
1398 g_free(ft->user);
1399 g_free(ft->ip);
1400 g_free(ft->cookie);
1401 g_free(ft);
1402 }
1403 }
1368 1404
1369 return; 1405 return;
1370 } 1406 }
1371 1407
1372 rt = read(source, buf, MIN(ntohl(ft->hdr.size) - ft->recvsize, 1024)); 1408 rt = read(source, buf, MIN(ntohl(ft->hdr.size) - ft->recvsize, 1024));
1375 gdk_input_remove(ft->inpa); 1411 gdk_input_remove(ft->inpa);
1376 close(source); 1412 close(source);
1377 g_free(ft->user); 1413 g_free(ft->user);
1378 g_free(ft->ip); 1414 g_free(ft->ip);
1379 g_free(ft->cookie); 1415 g_free(ft->cookie);
1380 fclose(ft->file); 1416 if (ft->file)
1417 fclose(ft->file);
1381 g_free(ft); 1418 g_free(ft);
1382 return; 1419 return;
1383 } 1420 }
1384 ft->recvsize += rt; 1421 ft->recvsize += rt;
1385 for (i = 0; i < rt; i++) 1422 for (i = 0; i < rt; i++)
1392 ft->hdr.recvcsum = ft->hdr.checksum; /* uh... */ 1429 ft->hdr.recvcsum = ft->hdr.checksum; /* uh... */
1393 ft->hdr.nrecvd = htons(ntohs(ft->hdr.nrecvd) + 1); 1430 ft->hdr.nrecvd = htons(ntohs(ft->hdr.nrecvd) + 1);
1394 ft->hdr.flags = 0; 1431 ft->hdr.flags = 0;
1395 write(source, ft, 256); 1432 write(source, ft, 256);
1396 ft->recvsize = 0; 1433 ft->recvsize = 0;
1397 if (ft->hdr.filesleft != 0) { 1434 fclose(ft->file);
1398 char *msg = g_strdup_printf("%s tried to send you more than one file, but" 1435 if (ft->hdr.filesleft == 0) {
1399 " currently that is not possible.", ft->user); 1436 gdk_input_remove(ft->inpa);
1400 do_error_dialog(msg, "Error"); 1437 close(source);
1401 g_free(msg); 1438 g_free(ft->filename);
1439 g_free(ft->user);
1440 g_free(ft->ip);
1441 g_free(ft->cookie);
1442 g_free(ft);
1402 } 1443 }
1403 gdk_input_remove(ft->inpa);
1404 close(source);
1405 g_free(ft->user);
1406 g_free(ft->ip);
1407 g_free(ft->cookie);
1408 fclose(ft->file);
1409 g_free(ft);
1410 } 1444 }
1411 } 1445 }
1412 1446
1413 static void toc_send_file(gpointer a, struct file_transfer *old_ft) { 1447 static void toc_send_file(gpointer a, struct file_transfer *old_ft) {
1414 struct file_transfer *ft; 1448 struct file_transfer *ft;
1418 char *buf; 1452 char *buf;
1419 1453
1420 if (file_is_dir(dirname, old_ft->window)) 1454 if (file_is_dir(dirname, old_ft->window))
1421 return; 1455 return;
1422 ft = g_new0(struct file_transfer, 1); 1456 ft = g_new0(struct file_transfer, 1);
1423 ft->file = fopen(dirname, "w"); 1457 if (old_ft->files == 1)
1424 if (!ft->file) { 1458 ft->filename = g_strdup(dirname);
1425 do_error_dialog(_("Could not open file for writing!"), _("Error")); 1459 else
1426 g_free(ft); 1460 ft->filename = g_dirname(dirname);
1427 gtk_widget_destroy(old_ft->window);
1428 return;
1429 }
1430
1431 ft->cookie = g_strdup(old_ft->cookie); 1461 ft->cookie = g_strdup(old_ft->cookie);
1432 ft->user = g_strdup(old_ft->user); 1462 ft->user = g_strdup(old_ft->user);
1433 ft->ip = g_strdup(old_ft->ip); 1463 ft->ip = g_strdup(old_ft->ip);
1464 ft->files = old_ft->files;
1434 ft->port = old_ft->port; 1465 ft->port = old_ft->port;
1435 ft->gc = old_ft->gc; 1466 ft->gc = old_ft->gc;
1436 user = ft->gc->user; 1467 user = ft->gc->user;
1437 gtk_widget_destroy(old_ft->window); 1468 gtk_widget_destroy(old_ft->window);
1438 1469
1445 user->proto_opt[USEROPT_SOCKSHOST], 1476 user->proto_opt[USEROPT_SOCKSHOST],
1446 atoi(user->proto_opt[USEROPT_SOCKSPORT]), 1477 atoi(user->proto_opt[USEROPT_SOCKSPORT]),
1447 atoi(user->proto_opt[USEROPT_PROXYTYPE])); 1478 atoi(user->proto_opt[USEROPT_PROXYTYPE]));
1448 if (fd < 0) { 1479 if (fd < 0) {
1449 do_error_dialog(_("Could not connect for transfer!"), _("Error")); 1480 do_error_dialog(_("Could not connect for transfer!"), _("Error"));
1481 g_free(ft->filename);
1450 g_free(ft->cookie); 1482 g_free(ft->cookie);
1451 g_free(ft->user); 1483 g_free(ft->user);
1452 g_free(ft->ip); 1484 g_free(ft->ip);
1453 g_free(ft); 1485 g_free(ft);
1454 return; 1486 return;
1475 ft->gc = fr->gc; 1507 ft->gc = fr->gc;
1476 ft->user = g_strdup(fr->user); 1508 ft->user = g_strdup(fr->user);
1477 ft->cookie = g_strdup(fr->cookie); 1509 ft->cookie = g_strdup(fr->cookie);
1478 ft->ip = g_strdup(fr->ip); 1510 ft->ip = g_strdup(fr->ip);
1479 ft->port = fr->port; 1511 ft->port = fr->port;
1512 ft->files = fr->files;
1480 1513
1481 ft->window = window = gtk_file_selection_new(_("Gaim - Save As...")); 1514 ft->window = window = gtk_file_selection_new(_("Gaim - Save As..."));
1482 g_snprintf(buf, sizeof(buf), "%s/%s", g_get_home_dir(), fr->filename ? fr->filename : ""); 1515 g_snprintf(buf, sizeof(buf), "%s/%s", g_get_home_dir(), fr->filename ? fr->filename : "");
1483 gtk_file_selection_set_filename(GTK_FILE_SELECTION(window), buf); 1516 gtk_file_selection_set_filename(GTK_FILE_SELECTION(window), buf);
1484 gtk_signal_connect(GTK_OBJECT(window), "destroy", 1517 gtk_signal_connect(GTK_OBJECT(window), "destroy",