Mercurial > pidgin
comparison src/protocols/toc/toc.c @ 9134:6d7bb1274755
[gaim-migrate @ 9916]
Remove some silly things that I don't think should be needed anymore.
committer: Tailor Script <tailor@pidgin.im>
| author | Mark Doliner <mark@kingant.net> |
|---|---|
| date | Sun, 30 May 2004 21:00:36 +0000 |
| parents | cde9fb3546ed |
| children | 8b1af7cadeb8 |
comparison
equal
deleted
inserted
replaced
| 9133:c42c3ac3466e | 9134:6d7bb1274755 |
|---|---|
| 118 #define TOC_CONNECT_STEPS 4 | 118 #define TOC_CONNECT_STEPS 4 |
| 119 | 119 |
| 120 static void toc_login_callback(gpointer, gint, GaimInputCondition); | 120 static void toc_login_callback(gpointer, gint, GaimInputCondition); |
| 121 static void toc_callback(gpointer, gint, GaimInputCondition); | 121 static void toc_callback(gpointer, gint, GaimInputCondition); |
| 122 | 122 |
| 123 /* The following were added for win32 port - Herman */ | |
| 124 | |
| 125 int toc_write(int fd, const void *buffer, int len) | |
| 126 { | |
| 127 #ifndef _WIN32 | |
| 128 return write(fd, buffer, len); | |
| 129 #else | |
| 130 return send(fd, buffer, len, 0); | |
| 131 #endif | |
| 132 } | |
| 133 | |
| 134 int toc_read(int fd, void *buffer, int size) | |
| 135 { | |
| 136 #ifndef _WIN32 | |
| 137 return read(fd, buffer, size); | |
| 138 #else | |
| 139 return recv(fd, buffer, size, 0); | |
| 140 #endif | |
| 141 } | |
| 142 | |
| 143 int toc_soc_close( int fd ) | |
| 144 { | |
| 145 #ifndef _WIN32 | |
| 146 return close(fd); | |
| 147 #else | |
| 148 return closesocket(fd); | |
| 149 #endif | |
| 150 } | |
| 151 | |
| 152 | |
| 153 /* ok. this function used to take username/password, and return 0 on success. | 123 /* ok. this function used to take username/password, and return 0 on success. |
| 154 * now, it takes username/password, and returns NULL on error or a new gaim_connection | 124 * now, it takes username/password, and returns NULL on error or a new gaim_connection |
| 155 * on success. */ | 125 * on success. */ |
| 156 static void toc_login(GaimAccount *account) | 126 static void toc_login(GaimAccount *account) |
| 157 { | 127 { |
| 187 char buf[80]; | 157 char buf[80]; |
| 188 struct sockaddr_in name; | 158 struct sockaddr_in name; |
| 189 socklen_t namelen; | 159 socklen_t namelen; |
| 190 | 160 |
| 191 if (!g_list_find(gaim_connections_get_all(), data)) { | 161 if (!g_list_find(gaim_connections_get_all(), data)) { |
| 192 toc_soc_close(source); | 162 close(source); |
| 193 return; | 163 return; |
| 194 } | 164 } |
| 195 | 165 |
| 196 tdt = gc->proto_data; | 166 tdt = gc->proto_data; |
| 197 | 167 |
| 212 else | 182 else |
| 213 strncpy(tdt->toc_ip, gaim_account_get_string(gc->account, "server", TOC_HOST), sizeof(tdt->toc_ip)); | 183 strncpy(tdt->toc_ip, gaim_account_get_string(gc->account, "server", TOC_HOST), sizeof(tdt->toc_ip)); |
| 214 | 184 |
| 215 gaim_debug(GAIM_DEBUG_INFO, "toc", | 185 gaim_debug(GAIM_DEBUG_INFO, "toc", |
| 216 "Client sends \"FLAPON\\r\\n\\r\\n\"\n"); | 186 "Client sends \"FLAPON\\r\\n\\r\\n\"\n"); |
| 217 if (toc_write(tdt->toc_fd, FLAPON, strlen(FLAPON)) < 0) { | 187 if (write(tdt->toc_fd, FLAPON, strlen(FLAPON)) < 0) { |
| 218 gaim_connection_error(gc, _("Disconnected.")); | 188 gaim_connection_error(gc, _("Disconnected.")); |
| 219 return; | 189 return; |
| 220 } | 190 } |
| 221 tdt->state = STATE_FLAPON; | 191 tdt->state = STATE_FLAPON; |
| 222 | 192 |
| 232 static void toc_close(GaimConnection *gc) | 202 static void toc_close(GaimConnection *gc) |
| 233 { | 203 { |
| 234 if (gc->inpa > 0) | 204 if (gc->inpa > 0) |
| 235 gaim_input_remove(gc->inpa); | 205 gaim_input_remove(gc->inpa); |
| 236 gc->inpa = 0; | 206 gc->inpa = 0; |
| 237 toc_soc_close(((struct toc_data *)gc->proto_data)->toc_fd); | 207 close(((struct toc_data *)gc->proto_data)->toc_fd); |
| 238 g_free(gc->proto_data); | 208 g_free(gc->proto_data); |
| 239 } | 209 } |
| 240 | 210 |
| 241 static void toc_build_config(GaimAccount *account, char *s, int len, gboolean show) | 211 static void toc_build_config(GaimAccount *account, char *s, int len, gboolean show) |
| 242 { | 212 { |
| 432 if (type != TYPE_SIGNON) { | 402 if (type != TYPE_SIGNON) { |
| 433 obuf[slen] = '\0'; | 403 obuf[slen] = '\0'; |
| 434 slen += 1; | 404 slen += 1; |
| 435 } | 405 } |
| 436 | 406 |
| 437 ret = toc_write(tdt->toc_fd, obuf, slen); | 407 ret = write(tdt->toc_fd, obuf, slen); |
| 438 free(obuf); | 408 free(obuf); |
| 439 g_free(escaped); | 409 g_free(escaped); |
| 440 | 410 |
| 441 return ret; | 411 return ret; |
| 442 } | 412 } |
| 445 { | 415 { |
| 446 struct toc_data *tdt = (struct toc_data *)gc->proto_data; | 416 struct toc_data *tdt = (struct toc_data *)gc->proto_data; |
| 447 struct sflap_hdr *hdr; | 417 struct sflap_hdr *hdr; |
| 448 int ret; | 418 int ret; |
| 449 | 419 |
| 450 if (toc_read(tdt->toc_fd, buffer, sizeof(struct sflap_hdr)) < 0) { | 420 if (read(tdt->toc_fd, buffer, sizeof(struct sflap_hdr)) < 0) { |
| 451 gaim_debug(GAIM_DEBUG_ERROR, "toc", "Couldn't read flap header\n"); | 421 gaim_debug(GAIM_DEBUG_ERROR, "toc", "Couldn't read flap header\n"); |
| 452 return -1; | 422 return -1; |
| 453 } | 423 } |
| 454 | 424 |
| 455 hdr = (struct sflap_hdr *)buffer; | 425 hdr = (struct sflap_hdr *)buffer; |
| 465 if (ntohs(hdr->len) > 0) { | 435 if (ntohs(hdr->len) > 0) { |
| 466 int count = 0; | 436 int count = 0; |
| 467 ret = 0; | 437 ret = 0; |
| 468 do { | 438 do { |
| 469 count += ret; | 439 count += ret; |
| 470 ret = toc_read(tdt->toc_fd, | 440 ret = read(tdt->toc_fd, |
| 471 buffer + sizeof(struct sflap_hdr) + count, ntohs(hdr->len) - count); | 441 buffer + sizeof(struct sflap_hdr) + count, ntohs(hdr->len) - count); |
| 472 } while (count + ret < ntohs(hdr->len) && ret > 0); | 442 } while (count + ret < ntohs(hdr->len) && ret > 0); |
| 473 buffer[sizeof(struct sflap_hdr) + count + ret] = '\0'; | 443 buffer[sizeof(struct sflap_hdr) + count + ret] = '\0'; |
| 474 return ret; | 444 return ret; |
| 475 } else | 445 } else |
| 1671 | 1641 |
| 1672 if (ft->hdr.hdrtype != 0x202) { | 1642 if (ft->hdr.hdrtype != 0x202) { |
| 1673 char *buf; | 1643 char *buf; |
| 1674 frombase64(ft->cookie, &buf, NULL); | 1644 frombase64(ft->cookie, &buf, NULL); |
| 1675 | 1645 |
| 1676 toc_read(source, ft, 8); | 1646 read(source, ft, 8); |
| 1677 toc_read(source, &ft->hdr.bcookie, MIN(256 - 8, ntohs(ft->hdr.hdrlen) - 8)); | 1647 read(source, &ft->hdr.bcookie, MIN(256 - 8, ntohs(ft->hdr.hdrlen) - 8)); |
| 1678 debug_header(ft); | 1648 debug_header(ft); |
| 1679 | 1649 |
| 1680 ft->hdr.hdrtype = 0x202; | 1650 ft->hdr.hdrtype = 0x202; |
| 1681 memcpy(ft->hdr.bcookie, buf, 8); | 1651 memcpy(ft->hdr.bcookie, buf, 8); |
| 1682 g_free(buf); | 1652 g_free(buf); |
| 1683 ft->hdr.encrypt = 0; ft->hdr.compress = 0; | 1653 ft->hdr.encrypt = 0; ft->hdr.compress = 0; |
| 1684 debug_header(ft); | 1654 debug_header(ft); |
| 1685 toc_write(source, ft, 256); | 1655 write(source, ft, 256); |
| 1686 | 1656 |
| 1687 if (ft->files == 1) { | 1657 if (ft->files == 1) { |
| 1688 ft->file = fopen(ft->filename, "w"); | 1658 ft->file = fopen(ft->filename, "w"); |
| 1689 if (!ft->file) { | 1659 if (!ft->file) { |
| 1690 buf = g_strdup_printf(_("Could not open %s for writing!"), ft->filename); | 1660 buf = g_strdup_printf(_("Could not open %s for writing!"), ft->filename); |
| 1691 gaim_notify_error(ft->gc, NULL, buf, strerror(errno)); | 1661 gaim_notify_error(ft->gc, NULL, buf, strerror(errno)); |
| 1692 g_free(buf); | 1662 g_free(buf); |
| 1693 gaim_input_remove(ft->inpa); | 1663 gaim_input_remove(ft->inpa); |
| 1694 toc_soc_close(source); | 1664 close(source); |
| 1695 g_free(ft->filename); | 1665 g_free(ft->filename); |
| 1696 g_free(ft->user); | 1666 g_free(ft->user); |
| 1697 g_free(ft->ip); | 1667 g_free(ft->ip); |
| 1698 g_free(ft->cookie); | 1668 g_free(ft->cookie); |
| 1699 g_free(ft); | 1669 g_free(ft); |
| 1706 buf = g_strdup_printf("Could not open %s/%s for writing!", ft->filename, | 1676 buf = g_strdup_printf("Could not open %s/%s for writing!", ft->filename, |
| 1707 ft->hdr.name); | 1677 ft->hdr.name); |
| 1708 gaim_notify_error(ft->gc, NULL, buf, strerror(errno)); | 1678 gaim_notify_error(ft->gc, NULL, buf, strerror(errno)); |
| 1709 g_free(buf); | 1679 g_free(buf); |
| 1710 gaim_input_remove(ft->inpa); | 1680 gaim_input_remove(ft->inpa); |
| 1711 toc_soc_close(source); | 1681 close(source); |
| 1712 g_free(ft->filename); | 1682 g_free(ft->filename); |
| 1713 g_free(ft->user); | 1683 g_free(ft->user); |
| 1714 g_free(ft->ip); | 1684 g_free(ft->ip); |
| 1715 g_free(ft->cookie); | 1685 g_free(ft->cookie); |
| 1716 g_free(ft); | 1686 g_free(ft); |
| 1718 } | 1688 } |
| 1719 | 1689 |
| 1720 return; | 1690 return; |
| 1721 } | 1691 } |
| 1722 | 1692 |
| 1723 rt = toc_read(source, buf, MIN(ntohl(ft->hdr.size) - ft->recvsize, 1024)); | 1693 rt = read(source, buf, MIN(ntohl(ft->hdr.size) - ft->recvsize, 1024)); |
| 1724 if (rt < 0) { | 1694 if (rt < 0) { |
| 1725 gaim_notify_error(ft->gc, NULL, | 1695 gaim_notify_error(ft->gc, NULL, |
| 1726 _("File transfer failed; other side probably " | 1696 _("File transfer failed; other side probably " |
| 1727 "canceled."), NULL); | 1697 "canceled."), NULL); |
| 1728 gaim_input_remove(ft->inpa); | 1698 gaim_input_remove(ft->inpa); |
| 1729 toc_soc_close(source); | 1699 close(source); |
| 1730 g_free(ft->user); | 1700 g_free(ft->user); |
| 1731 g_free(ft->ip); | 1701 g_free(ft->ip); |
| 1732 g_free(ft->cookie); | 1702 g_free(ft->cookie); |
| 1733 if (ft->file) | 1703 if (ft->file) |
| 1734 fclose(ft->file); | 1704 fclose(ft->file); |
| 1744 ft->hdr.filesleft = htons(ntohs(ft->hdr.filesleft) - 1); | 1714 ft->hdr.filesleft = htons(ntohs(ft->hdr.filesleft) - 1); |
| 1745 ft->hdr.partsleft = htons(ntohs(ft->hdr.partsleft) - 1); | 1715 ft->hdr.partsleft = htons(ntohs(ft->hdr.partsleft) - 1); |
| 1746 ft->hdr.recvcsum = ft->hdr.checksum; /* uh... */ | 1716 ft->hdr.recvcsum = ft->hdr.checksum; /* uh... */ |
| 1747 ft->hdr.nrecvd = htons(ntohs(ft->hdr.nrecvd) + 1); | 1717 ft->hdr.nrecvd = htons(ntohs(ft->hdr.nrecvd) + 1); |
| 1748 ft->hdr.flags = 0; | 1718 ft->hdr.flags = 0; |
| 1749 toc_write(source, ft, 256); | 1719 write(source, ft, 256); |
| 1750 debug_header(ft); | 1720 debug_header(ft); |
| 1751 ft->recvsize = 0; | 1721 ft->recvsize = 0; |
| 1752 fclose(ft->file); | 1722 fclose(ft->file); |
| 1753 if (ft->hdr.filesleft == 0) { | 1723 if (ft->hdr.filesleft == 0) { |
| 1754 gaim_input_remove(ft->inpa); | 1724 gaim_input_remove(ft->inpa); |
| 1755 toc_soc_close(source); | 1725 close(source); |
| 1756 g_free(ft->filename); | 1726 g_free(ft->filename); |
| 1757 g_free(ft->user); | 1727 g_free(ft->user); |
| 1758 g_free(ft->ip); | 1728 g_free(ft->ip); |
| 1759 g_free(ft->cookie); | 1729 g_free(ft->cookie); |
| 1760 g_free(ft); | 1730 g_free(ft); |
| 1827 if (cond & GAIM_INPUT_WRITE) { | 1797 if (cond & GAIM_INPUT_WRITE) { |
| 1828 int remain = MIN(ntohl(ft->hdr.totsize) - ft->recvsize, 1024); | 1798 int remain = MIN(ntohl(ft->hdr.totsize) - ft->recvsize, 1024); |
| 1829 int i; | 1799 int i; |
| 1830 for (i = 0; i < remain; i++) | 1800 for (i = 0; i < remain; i++) |
| 1831 fscanf(ft->file, "%c", &buf[i]); | 1801 fscanf(ft->file, "%c", &buf[i]); |
| 1832 toc_write(source, buf, remain); | 1802 write(source, buf, remain); |
| 1833 ft->recvsize += remain; | 1803 ft->recvsize += remain; |
| 1834 if (ft->recvsize == ntohl(ft->hdr.totsize)) { | 1804 if (ft->recvsize == ntohl(ft->hdr.totsize)) { |
| 1835 gaim_input_remove(ft->inpa); | 1805 gaim_input_remove(ft->inpa); |
| 1836 ft->inpa = gaim_input_add(source, GAIM_INPUT_READ, | 1806 ft->inpa = gaim_input_add(source, GAIM_INPUT_READ, |
| 1837 toc_get_file_callback, ft); | 1807 toc_get_file_callback, ft); |
| 1842 if (ft->hdr.hdrtype == htons(0x1108)) { | 1812 if (ft->hdr.hdrtype == htons(0x1108)) { |
| 1843 struct tm *fortime; | 1813 struct tm *fortime; |
| 1844 struct stat st; | 1814 struct stat st; |
| 1845 char *basename; | 1815 char *basename; |
| 1846 | 1816 |
| 1847 toc_read(source, ft, 8); | 1817 read(source, ft, 8); |
| 1848 toc_read(source, &ft->hdr.bcookie, MIN(256 - 8, ntohs(ft->hdr.hdrlen) - 8)); | 1818 read(source, &ft->hdr.bcookie, MIN(256 - 8, ntohs(ft->hdr.hdrlen) - 8)); |
| 1849 debug_header(ft); | 1819 debug_header(ft); |
| 1850 | 1820 |
| 1851 stat(ft->filename, &st); | 1821 stat(ft->filename, &st); |
| 1852 fortime = localtime(&st.st_mtime); | 1822 fortime = localtime(&st.st_mtime); |
| 1853 basename = g_path_get_basename(ft->filename); | 1823 basename = g_path_get_basename(ft->filename); |
| 1854 g_snprintf(buf, sizeof(buf), "%2d/%2d/%4d %2d:%2d %8ld %s\r\n", | 1824 g_snprintf(buf, sizeof(buf), "%2d/%2d/%4d %2d:%2d %8ld %s\r\n", |
| 1855 fortime->tm_mon + 1, fortime->tm_mday, fortime->tm_year + 1900, | 1825 fortime->tm_mon + 1, fortime->tm_mday, fortime->tm_year + 1900, |
| 1856 fortime->tm_hour + 1, fortime->tm_min + 1, (long)st.st_size, | 1826 fortime->tm_hour + 1, fortime->tm_min + 1, (long)st.st_size, |
| 1857 basename); | 1827 basename); |
| 1858 toc_write(source, buf, ntohl(ft->hdr.size)); | 1828 write(source, buf, ntohl(ft->hdr.size)); |
| 1859 g_free(basename); | 1829 g_free(basename); |
| 1860 return; | 1830 return; |
| 1861 } | 1831 } |
| 1862 | 1832 |
| 1863 if (ft->hdr.hdrtype == htons(0x1209)) { | 1833 if (ft->hdr.hdrtype == htons(0x1209)) { |
| 1864 toc_read(source, ft, 8); | 1834 read(source, ft, 8); |
| 1865 toc_read(source, &ft->hdr.bcookie, MIN(256 - 8, ntohs(ft->hdr.hdrlen) - 8)); | 1835 read(source, &ft->hdr.bcookie, MIN(256 - 8, ntohs(ft->hdr.hdrlen) - 8)); |
| 1866 debug_header(ft); | 1836 debug_header(ft); |
| 1867 return; | 1837 return; |
| 1868 } | 1838 } |
| 1869 | 1839 |
| 1870 if (ft->hdr.hdrtype == htons(0x120b)) { | 1840 if (ft->hdr.hdrtype == htons(0x120b)) { |
| 1871 toc_read(source, ft, 8); | 1841 read(source, ft, 8); |
| 1872 toc_read(source, &ft->hdr.bcookie, MIN(256 - 8, ntohs(ft->hdr.hdrlen) - 8)); | 1842 read(source, &ft->hdr.bcookie, MIN(256 - 8, ntohs(ft->hdr.hdrlen) - 8)); |
| 1873 debug_header(ft); | 1843 debug_header(ft); |
| 1874 | 1844 |
| 1875 if (ft->hdr.hdrtype != htons(0x120c)) { | 1845 if (ft->hdr.hdrtype != htons(0x120c)) { |
| 1876 g_snprintf(buf, sizeof(buf), "%s decided to cancel the transfer", ft->user); | 1846 g_snprintf(buf, sizeof(buf), "%s decided to cancel the transfer", ft->user); |
| 1877 gaim_notify_error(ft->gc, NULL, buf, NULL); | 1847 gaim_notify_error(ft->gc, NULL, buf, NULL); |
| 1878 gaim_input_remove(ft->inpa); | 1848 gaim_input_remove(ft->inpa); |
| 1879 toc_soc_close(source); | 1849 close(source); |
| 1880 g_free(ft->filename); | 1850 g_free(ft->filename); |
| 1881 g_free(ft->user); | 1851 g_free(ft->user); |
| 1882 g_free(ft->ip); | 1852 g_free(ft->ip); |
| 1883 g_free(ft->cookie); | 1853 g_free(ft->cookie); |
| 1884 if (ft->file) | 1854 if (ft->file) |
| 1888 } | 1858 } |
| 1889 | 1859 |
| 1890 ft->hdr.hdrtype = 0x0101; | 1860 ft->hdr.hdrtype = 0x0101; |
| 1891 ft->hdr.totfiles = htons(1); ft->hdr.filesleft = htons(1); | 1861 ft->hdr.totfiles = htons(1); ft->hdr.filesleft = htons(1); |
| 1892 ft->hdr.flags = 0x20; | 1862 ft->hdr.flags = 0x20; |
| 1893 toc_write(source, ft, 256); | 1863 write(source, ft, 256); |
| 1894 return; | 1864 return; |
| 1895 } | 1865 } |
| 1896 | 1866 |
| 1897 if (ft->hdr.hdrtype == 0x0101) { | 1867 if (ft->hdr.hdrtype == 0x0101) { |
| 1898 toc_read(source, ft, 8); | 1868 read(source, ft, 8); |
| 1899 toc_read(source, &ft->hdr.bcookie, MIN(256 - 8, ntohs(ft->hdr.hdrlen) - 8)); | 1869 read(source, &ft->hdr.bcookie, MIN(256 - 8, ntohs(ft->hdr.hdrlen) - 8)); |
| 1900 debug_header(ft); | 1870 debug_header(ft); |
| 1901 | 1871 |
| 1902 gaim_input_remove(ft->inpa); | 1872 gaim_input_remove(ft->inpa); |
| 1903 ft->inpa = gaim_input_add(source, GAIM_INPUT_WRITE, | 1873 ft->inpa = gaim_input_add(source, GAIM_INPUT_WRITE, |
| 1904 toc_get_file_callback, ft); | 1874 toc_get_file_callback, ft); |
| 1905 return; | 1875 return; |
| 1906 } | 1876 } |
| 1907 | 1877 |
| 1908 if (ft->hdr.hdrtype == 0x0202) { | 1878 if (ft->hdr.hdrtype == 0x0202) { |
| 1909 toc_read(source, ft, 8); | 1879 read(source, ft, 8); |
| 1910 toc_read(source, &ft->hdr.bcookie, MIN(256 - 8, ntohs(ft->hdr.hdrlen) - 8)); | 1880 read(source, &ft->hdr.bcookie, MIN(256 - 8, ntohs(ft->hdr.hdrlen) - 8)); |
| 1911 debug_header(ft); | 1881 debug_header(ft); |
| 1912 | 1882 |
| 1913 gaim_input_remove(ft->inpa); | 1883 gaim_input_remove(ft->inpa); |
| 1914 toc_soc_close(source); | 1884 close(source); |
| 1915 g_free(ft->filename); | 1885 g_free(ft->filename); |
| 1916 g_free(ft->user); | 1886 g_free(ft->user); |
| 1917 g_free(ft->ip); | 1887 g_free(ft->ip); |
| 1918 g_free(ft->cookie); | 1888 g_free(ft->cookie); |
| 1919 if (ft->file) | 1889 if (ft->file) |
| 1961 g_snprintf(hdr->idstring, 32, "OFT_Windows ICBMFT V1.1 32"); | 1931 g_snprintf(hdr->idstring, 32, "OFT_Windows ICBMFT V1.1 32"); |
| 1962 hdr->flags = 0x02; | 1932 hdr->flags = 0x02; |
| 1963 hdr->lnameoffset = 0x1A; | 1933 hdr->lnameoffset = 0x1A; |
| 1964 hdr->lsizeoffset = 0x10; | 1934 hdr->lsizeoffset = 0x10; |
| 1965 g_snprintf(hdr->name, 64, "listing.txt"); | 1935 g_snprintf(hdr->name, 64, "listing.txt"); |
| 1966 if (toc_write(src, hdr, 256) < 0) { | 1936 if (write(src, hdr, 256) < 0) { |
| 1967 gaim_notify_error(ft->gc, NULL, | 1937 gaim_notify_error(ft->gc, NULL, |
| 1968 _("Could not write file header. The file will " | 1938 _("Could not write file header. The file will " |
| 1969 "not be transferred."), NULL); | 1939 "not be transferred."), NULL); |
| 1970 fclose(ft->file); | 1940 fclose(ft->file); |
| 1971 g_free(ft->filename); | 1941 g_free(ft->filename); |
