Mercurial > pidgin
comparison src/protocols/toc/toc.c @ 2090:b66aca8e8dce
[gaim-migrate @ 2100]
change ../config.h to <config.h> because that's better. change from GdkInput functions to GaimInput for reasons mentioned elsewhere.
committer: Tailor Script <tailor@pidgin.im>
| author | Eric Warmenhoven <eric@warmenhoven.org> |
|---|---|
| date | Tue, 31 Jul 2001 23:23:40 +0000 |
| parents | 424a40f12a6c |
| children | 56c4382f2909 |
comparison
equal
deleted
inserted
replaced
| 2089:bb1ddaaf0d26 | 2090:b66aca8e8dce |
|---|---|
| 20 */ | 20 */ |
| 21 | 21 |
| 22 | 22 |
| 23 | 23 |
| 24 #ifdef HAVE_CONFIG_H | 24 #ifdef HAVE_CONFIG_H |
| 25 #include "../config.h" | 25 #include <config.h> |
| 26 #endif | 26 #endif |
| 27 #include <netdb.h> | 27 #include <netdb.h> |
| 28 #include <gtk/gtk.h> | 28 #include <gtk/gtk.h> |
| 29 #include <unistd.h> | 29 #include <unistd.h> |
| 30 #include <errno.h> | 30 #include <errno.h> |
| 124 #define USEROPT_AUTHPORT 1 | 124 #define USEROPT_AUTHPORT 1 |
| 125 | 125 |
| 126 static GtkWidget *join_chat_spin = NULL; | 126 static GtkWidget *join_chat_spin = NULL; |
| 127 static GtkWidget *join_chat_entry = NULL; | 127 static GtkWidget *join_chat_entry = NULL; |
| 128 | 128 |
| 129 static void toc_login_callback(gpointer, gint, GdkInputCondition); | 129 static void toc_login_callback(gpointer, gint, GaimInputCondition); |
| 130 static void toc_callback(gpointer, gint, GdkInputCondition); | 130 static void toc_callback(gpointer, gint, GaimInputCondition); |
| 131 static unsigned char *roast_password(char *); | 131 static unsigned char *roast_password(char *); |
| 132 static void accept_file_dialog(struct ft_request *); | 132 static void accept_file_dialog(struct ft_request *); |
| 133 | 133 |
| 134 /* ok. this function used to take username/password, and return 0 on success. | 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 | 135 * now, it takes username/password, and returns NULL on error or a new gaim_connection |
| 160 signoff(gc); | 160 signoff(gc); |
| 161 return; | 161 return; |
| 162 } | 162 } |
| 163 } | 163 } |
| 164 | 164 |
| 165 static void toc_login_callback(gpointer data, gint source, GdkInputCondition cond) | 165 static void toc_login_callback(gpointer data, gint source, GaimInputCondition cond) |
| 166 { | 166 { |
| 167 struct gaim_connection *gc = data; | 167 struct gaim_connection *gc = data; |
| 168 struct toc_data *tdt; | 168 struct toc_data *tdt; |
| 169 char buf[80]; | 169 char buf[80]; |
| 170 | 170 |
| 194 tdt->state = STATE_FLAPON; | 194 tdt->state = STATE_FLAPON; |
| 195 | 195 |
| 196 /* i know a lot of people like to look at gaim to see how TOC works. so i'll comment | 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 | 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. */ | 198 * toc_fd file descriptor, toc_callback is called, with gc passed as its data arg. */ |
| 199 gc->inpa = gdk_input_add(tdt->toc_fd, GDK_INPUT_READ | GDK_INPUT_EXCEPTION, toc_callback, gc); | 199 gc->inpa = gaim_input_add(tdt->toc_fd, GAIM_INPUT_READ, toc_callback, gc); |
| 200 | 200 |
| 201 g_snprintf(buf, sizeof(buf), "Signon: %s", gc->username); | 201 g_snprintf(buf, sizeof(buf), "Signon: %s", gc->username); |
| 202 set_login_progress(gc, 2, buf); | 202 set_login_progress(gc, 2, buf); |
| 203 } | 203 } |
| 204 | 204 |
| 205 static void toc_close(struct gaim_connection *gc) | 205 static void toc_close(struct gaim_connection *gc) |
| 206 { | 206 { |
| 207 if (gc->inpa > 0) | 207 if (gc->inpa > 0) |
| 208 gdk_input_remove(gc->inpa); | 208 gaim_input_remove(gc->inpa); |
| 209 gc->inpa = 0; | 209 gc->inpa = 0; |
| 210 close(((struct toc_data *)gc->proto_data)->toc_fd); | 210 close(((struct toc_data *)gc->proto_data)->toc_fd); |
| 211 g_free(gc->proto_data); | 211 g_free(gc->proto_data); |
| 212 } | 212 } |
| 213 | 213 |
| 308 return; | 308 return; |
| 309 | 309 |
| 310 g_show_info_text(url_text); | 310 g_show_info_text(url_text); |
| 311 } | 311 } |
| 312 | 312 |
| 313 static void toc_callback(gpointer data, gint source, GdkInputCondition condition) | 313 static void toc_callback(gpointer data, gint source, GaimInputCondition condition) |
| 314 { | 314 { |
| 315 struct gaim_connection *gc = (struct gaim_connection *)data; | 315 struct gaim_connection *gc = (struct gaim_connection *)data; |
| 316 struct toc_data *tdt = (struct toc_data *)gc->proto_data; | 316 struct toc_data *tdt = (struct toc_data *)gc->proto_data; |
| 317 struct sflap_hdr *hdr; | 317 struct sflap_hdr *hdr; |
| 318 struct signon so; | 318 struct signon so; |
| 319 char buf[8 * 1024], *c; | 319 char buf[8 * 1024], *c; |
| 320 char snd[BUF_LEN * 2]; | 320 char snd[BUF_LEN * 2]; |
| 321 | |
| 322 if (condition & GDK_INPUT_EXCEPTION) { | |
| 323 debug_printf("gdk_input exception! check internet connection\n"); | |
| 324 hide_login_progress(gc, _("Connection Closed")); | |
| 325 signoff(gc); | |
| 326 return; | |
| 327 } | |
| 328 | 321 |
| 329 /* there's data waiting to be read, so read it. */ | 322 /* there's data waiting to be read, so read it. */ |
| 330 if (wait_reply(gc, buf, 8 * 1024) <= 0) { | 323 if (wait_reply(gc, buf, 8 * 1024) <= 0) { |
| 331 hide_login_progress(gc, _("Connection Closed")); | 324 hide_login_progress(gc, _("Connection Closed")); |
| 332 signoff(gc); | 325 signoff(gc); |
| 1409 f->dummy, f->macfileinfo, | 1402 f->dummy, f->macfileinfo, |
| 1410 ntohs(f->nencode), ntohs(f->nlanguage), | 1403 ntohs(f->nencode), ntohs(f->nlanguage), |
| 1411 f->name); | 1404 f->name); |
| 1412 } | 1405 } |
| 1413 | 1406 |
| 1414 static void toc_send_file_callback(gpointer data, gint source, GdkInputCondition cond) | 1407 static void toc_send_file_callback(gpointer data, gint source, GaimInputCondition cond) |
| 1415 { | 1408 { |
| 1416 char buf[BUF_LONG]; | 1409 char buf[BUF_LONG]; |
| 1417 int rt, i; | 1410 int rt, i; |
| 1418 | 1411 |
| 1419 struct file_transfer *ft = data; | 1412 struct file_transfer *ft = data; |
| 1420 | |
| 1421 if (cond & GDK_INPUT_EXCEPTION) { | |
| 1422 gdk_input_remove(ft->inpa); | |
| 1423 close(source); | |
| 1424 g_free(ft->filename); | |
| 1425 g_free(ft->user); | |
| 1426 g_free(ft->ip); | |
| 1427 g_free(ft->cookie); | |
| 1428 if (ft->file) | |
| 1429 fclose(ft->file); | |
| 1430 g_free(ft); | |
| 1431 return; | |
| 1432 } | |
| 1433 | 1413 |
| 1434 if (ft->hdr.hdrtype != 0x202) { | 1414 if (ft->hdr.hdrtype != 0x202) { |
| 1435 char *buf; | 1415 char *buf; |
| 1436 frombase64(ft->cookie, &buf, NULL); | 1416 frombase64(ft->cookie, &buf, NULL); |
| 1437 | 1417 |
| 1450 ft->file = fopen(ft->filename, "w"); | 1430 ft->file = fopen(ft->filename, "w"); |
| 1451 if (!ft->file) { | 1431 if (!ft->file) { |
| 1452 buf = g_strdup_printf("Could not open %s for writing!", ft->filename); | 1432 buf = g_strdup_printf("Could not open %s for writing!", ft->filename); |
| 1453 do_error_dialog(buf, _("Error")); | 1433 do_error_dialog(buf, _("Error")); |
| 1454 g_free(buf); | 1434 g_free(buf); |
| 1455 gdk_input_remove(ft->inpa); | 1435 gaim_input_remove(ft->inpa); |
| 1456 close(source); | 1436 close(source); |
| 1457 g_free(ft->filename); | 1437 g_free(ft->filename); |
| 1458 g_free(ft->user); | 1438 g_free(ft->user); |
| 1459 g_free(ft->ip); | 1439 g_free(ft->ip); |
| 1460 g_free(ft->cookie); | 1440 g_free(ft->cookie); |
| 1467 if (!ft->file) { | 1447 if (!ft->file) { |
| 1468 buf = g_strdup_printf("Could not open %s/%s for writing!", ft->filename, | 1448 buf = g_strdup_printf("Could not open %s/%s for writing!", ft->filename, |
| 1469 ft->hdr.name); | 1449 ft->hdr.name); |
| 1470 do_error_dialog(buf, _("Error")); | 1450 do_error_dialog(buf, _("Error")); |
| 1471 g_free(buf); | 1451 g_free(buf); |
| 1472 gdk_input_remove(ft->inpa); | 1452 gaim_input_remove(ft->inpa); |
| 1473 close(source); | 1453 close(source); |
| 1474 g_free(ft->filename); | 1454 g_free(ft->filename); |
| 1475 g_free(ft->user); | 1455 g_free(ft->user); |
| 1476 g_free(ft->ip); | 1456 g_free(ft->ip); |
| 1477 g_free(ft->cookie); | 1457 g_free(ft->cookie); |
| 1483 } | 1463 } |
| 1484 | 1464 |
| 1485 rt = read(source, buf, MIN(ntohl(ft->hdr.size) - ft->recvsize, 1024)); | 1465 rt = read(source, buf, MIN(ntohl(ft->hdr.size) - ft->recvsize, 1024)); |
| 1486 if (rt < 0) { | 1466 if (rt < 0) { |
| 1487 do_error_dialog("File transfer failed; other side probably canceled.", "Error"); | 1467 do_error_dialog("File transfer failed; other side probably canceled.", "Error"); |
| 1488 gdk_input_remove(ft->inpa); | 1468 gaim_input_remove(ft->inpa); |
| 1489 close(source); | 1469 close(source); |
| 1490 g_free(ft->user); | 1470 g_free(ft->user); |
| 1491 g_free(ft->ip); | 1471 g_free(ft->ip); |
| 1492 g_free(ft->cookie); | 1472 g_free(ft->cookie); |
| 1493 if (ft->file) | 1473 if (ft->file) |
| 1509 write(source, ft, 256); | 1489 write(source, ft, 256); |
| 1510 debug_header(ft); | 1490 debug_header(ft); |
| 1511 ft->recvsize = 0; | 1491 ft->recvsize = 0; |
| 1512 fclose(ft->file); | 1492 fclose(ft->file); |
| 1513 if (ft->hdr.filesleft == 0) { | 1493 if (ft->hdr.filesleft == 0) { |
| 1514 gdk_input_remove(ft->inpa); | 1494 gaim_input_remove(ft->inpa); |
| 1515 close(source); | 1495 close(source); |
| 1516 g_free(ft->filename); | 1496 g_free(ft->filename); |
| 1517 g_free(ft->user); | 1497 g_free(ft->user); |
| 1518 g_free(ft->ip); | 1498 g_free(ft->ip); |
| 1519 g_free(ft->cookie); | 1499 g_free(ft->cookie); |
| 1520 g_free(ft); | 1500 g_free(ft); |
| 1521 } | 1501 } |
| 1522 } | 1502 } |
| 1523 } | 1503 } |
| 1524 | 1504 |
| 1525 static void toc_send_file_connect(gpointer data, gint src, GdkInputCondition cond) | 1505 static void toc_send_file_connect(gpointer data, gint src, GaimInputCondition cond) |
| 1526 { | 1506 { |
| 1527 struct file_transfer *ft = data; | 1507 struct file_transfer *ft = data; |
| 1528 | 1508 |
| 1529 if (src == -1) { | 1509 if (src == -1) { |
| 1530 do_error_dialog(_("Could not connect for transfer!"), _("Error")); | 1510 do_error_dialog(_("Could not connect for transfer!"), _("Error")); |
| 1534 g_free(ft->ip); | 1514 g_free(ft->ip); |
| 1535 g_free(ft); | 1515 g_free(ft); |
| 1536 return; | 1516 return; |
| 1537 } | 1517 } |
| 1538 | 1518 |
| 1539 ft->inpa = gdk_input_add(src, GDK_INPUT_READ | GDK_INPUT_EXCEPTION, toc_send_file_callback, ft); | 1519 ft->inpa = gaim_input_add(src, GAIM_INPUT_READ, toc_send_file_callback, ft); |
| 1540 } | 1520 } |
| 1541 | 1521 |
| 1542 static void toc_send_file(gpointer a, struct file_transfer *old_ft) | 1522 static void toc_send_file(gpointer a, struct file_transfer *old_ft) |
| 1543 { | 1523 { |
| 1544 struct file_transfer *ft; | 1524 struct file_transfer *ft; |
| 1577 g_free(ft); | 1557 g_free(ft); |
| 1578 return; | 1558 return; |
| 1579 } | 1559 } |
| 1580 } | 1560 } |
| 1581 | 1561 |
| 1582 static void toc_get_file_callback(gpointer data, gint source, GdkInputCondition cond) | 1562 static void toc_get_file_callback(gpointer data, gint source, GaimInputCondition cond) |
| 1583 { | 1563 { |
| 1584 char buf[BUF_LONG]; | 1564 char buf[BUF_LONG]; |
| 1585 | 1565 |
| 1586 struct file_transfer *ft = data; | 1566 struct file_transfer *ft = data; |
| 1587 | 1567 |
| 1588 if (cond & GDK_INPUT_EXCEPTION) { | 1568 if (cond & GAIM_INPUT_WRITE) { |
| 1589 do_error_dialog("The file tranfer has been aborted; the other side most likely" | |
| 1590 " cancelled.", "Error"); | |
| 1591 gdk_input_remove(ft->inpa); | |
| 1592 close(source); | |
| 1593 g_free(ft->filename); | |
| 1594 g_free(ft->user); | |
| 1595 g_free(ft->ip); | |
| 1596 g_free(ft->cookie); | |
| 1597 if (ft->file) | |
| 1598 fclose(ft->file); | |
| 1599 g_free(ft); | |
| 1600 return; | |
| 1601 } | |
| 1602 | |
| 1603 if (cond & GDK_INPUT_WRITE) { | |
| 1604 int remain = MIN(ntohl(ft->hdr.totsize) - ft->recvsize, 1024); | 1569 int remain = MIN(ntohl(ft->hdr.totsize) - ft->recvsize, 1024); |
| 1605 int i; | 1570 int i; |
| 1606 for (i = 0; i < remain; i++) | 1571 for (i = 0; i < remain; i++) |
| 1607 fscanf(ft->file, "%c", &buf[i]); | 1572 fscanf(ft->file, "%c", &buf[i]); |
| 1608 write(source, buf, remain); | 1573 write(source, buf, remain); |
| 1609 ft->recvsize += remain; | 1574 ft->recvsize += remain; |
| 1610 if (ft->recvsize == ntohl(ft->hdr.totsize)) { | 1575 if (ft->recvsize == ntohl(ft->hdr.totsize)) { |
| 1611 gdk_input_remove(ft->inpa); | 1576 gaim_input_remove(ft->inpa); |
| 1612 ft->inpa = gdk_input_add(source, GDK_INPUT_READ | GDK_INPUT_EXCEPTION, | 1577 ft->inpa = gaim_input_add(source, GAIM_INPUT_READ, |
| 1613 toc_get_file_callback, ft); | 1578 toc_get_file_callback, ft); |
| 1614 } | 1579 } |
| 1615 return; | 1580 return; |
| 1616 } | 1581 } |
| 1617 | 1582 |
| 1646 debug_header(ft); | 1611 debug_header(ft); |
| 1647 | 1612 |
| 1648 if (ft->hdr.hdrtype != htons(0x120c)) { | 1613 if (ft->hdr.hdrtype != htons(0x120c)) { |
| 1649 g_snprintf(buf, sizeof(buf), "%s decided to cancel the transfer", ft->user); | 1614 g_snprintf(buf, sizeof(buf), "%s decided to cancel the transfer", ft->user); |
| 1650 do_error_dialog(buf, "Error"); | 1615 do_error_dialog(buf, "Error"); |
| 1651 gdk_input_remove(ft->inpa); | 1616 gaim_input_remove(ft->inpa); |
| 1652 close(source); | 1617 close(source); |
| 1653 g_free(ft->filename); | 1618 g_free(ft->filename); |
| 1654 g_free(ft->user); | 1619 g_free(ft->user); |
| 1655 g_free(ft->ip); | 1620 g_free(ft->ip); |
| 1656 g_free(ft->cookie); | 1621 g_free(ft->cookie); |
| 1670 if (ft->hdr.hdrtype == 0x0101) { | 1635 if (ft->hdr.hdrtype == 0x0101) { |
| 1671 read(source, ft, 8); | 1636 read(source, ft, 8); |
| 1672 read(source, &ft->hdr.bcookie, MIN(256 - 8, ntohs(ft->hdr.hdrlen) - 8)); | 1637 read(source, &ft->hdr.bcookie, MIN(256 - 8, ntohs(ft->hdr.hdrlen) - 8)); |
| 1673 debug_header(ft); | 1638 debug_header(ft); |
| 1674 | 1639 |
| 1675 gdk_input_remove(ft->inpa); | 1640 gaim_input_remove(ft->inpa); |
| 1676 ft->inpa = gdk_input_add(source, GDK_INPUT_WRITE | GDK_INPUT_EXCEPTION, | 1641 ft->inpa = gaim_input_add(source, GAIM_INPUT_WRITE, |
| 1677 toc_get_file_callback, ft); | 1642 toc_get_file_callback, ft); |
| 1678 return; | 1643 return; |
| 1679 } | 1644 } |
| 1680 | 1645 |
| 1681 if (ft->hdr.hdrtype == 0x0202) { | 1646 if (ft->hdr.hdrtype == 0x0202) { |
| 1682 read(source, ft, 8); | 1647 read(source, ft, 8); |
| 1683 read(source, &ft->hdr.bcookie, MIN(256 - 8, ntohs(ft->hdr.hdrlen) - 8)); | 1648 read(source, &ft->hdr.bcookie, MIN(256 - 8, ntohs(ft->hdr.hdrlen) - 8)); |
| 1684 debug_header(ft); | 1649 debug_header(ft); |
| 1685 | 1650 |
| 1686 gdk_input_remove(ft->inpa); | 1651 gaim_input_remove(ft->inpa); |
| 1687 close(source); | 1652 close(source); |
| 1688 g_free(ft->filename); | 1653 g_free(ft->filename); |
| 1689 g_free(ft->user); | 1654 g_free(ft->user); |
| 1690 g_free(ft->ip); | 1655 g_free(ft->ip); |
| 1691 g_free(ft->cookie); | 1656 g_free(ft->cookie); |
| 1694 g_free(ft); | 1659 g_free(ft); |
| 1695 return; | 1660 return; |
| 1696 } | 1661 } |
| 1697 } | 1662 } |
| 1698 | 1663 |
| 1699 static void toc_get_file_connect(gpointer data, gint src, GdkInputCondition cond) | 1664 static void toc_get_file_connect(gpointer data, gint src, GaimInputCondition cond) |
| 1700 { | 1665 { |
| 1701 struct file_transfer *ft = data; | 1666 struct file_transfer *ft = data; |
| 1702 struct file_header *hdr; | 1667 struct file_header *hdr; |
| 1703 char *buf; | 1668 char *buf; |
| 1704 | 1669 |
| 1741 g_free(ft->ip); | 1706 g_free(ft->ip); |
| 1742 g_free(ft); | 1707 g_free(ft); |
| 1743 return; | 1708 return; |
| 1744 } | 1709 } |
| 1745 | 1710 |
| 1746 ft->inpa = gdk_input_add(src, GDK_INPUT_READ | GDK_INPUT_EXCEPTION, toc_get_file_callback, ft); | 1711 ft->inpa = gaim_input_add(src, GAIM_INPUT_READ, toc_get_file_callback, ft); |
| 1747 } | 1712 } |
| 1748 | 1713 |
| 1749 static void toc_get_file(gpointer a, struct file_transfer *old_ft) | 1714 static void toc_get_file(gpointer a, struct file_transfer *old_ft) |
| 1750 { | 1715 { |
| 1751 struct file_transfer *ft; | 1716 struct file_transfer *ft; |
