comparison src/toc.c @ 1840:00aef397a1fe

[gaim-migrate @ 1850] reworked some of the proxy stuff so that it's non-blocking now. next thing to do is to get IRC, MSN, Napster, and Jabber to use the new proxy_connect code. After that, Oscar and Yahoo (maybe Zephyr too? not likely) committer: Tailor Script <tailor@pidgin.im>
author Eric Warmenhoven <eric@warmenhoven.org>
date Sat, 12 May 2001 01:38:04 +0000
parents bb115612a2ed
children 1d137dde946f
comparison
equal deleted inserted replaced
1839:109cacf1ff97 1840:00aef397a1fe
113 }; 113 };
114 114
115 /* constants to identify proto_opts */ 115 /* constants to identify proto_opts */
116 #define USEROPT_AUTH 0 116 #define USEROPT_AUTH 0
117 #define USEROPT_AUTHPORT 1 117 #define USEROPT_AUTHPORT 1
118 #define USEROPT_SOCKSHOST 2 118 #define USEROPT_PROXYHOST 2
119 #define USEROPT_SOCKSPORT 3 119 #define USEROPT_PROXYPORT 3
120 #define USEROPT_PROXYTYPE 4 120 #define USEROPT_PROXYTYPE 4
121 121
122 static GtkWidget *join_chat_spin = NULL; 122 static GtkWidget *join_chat_spin = NULL;
123 static GtkWidget *join_chat_entry = NULL; 123 static GtkWidget *join_chat_entry = NULL;
124 124
125 static void toc_login_callback(gpointer, gint, GdkInputCondition);
125 static void toc_callback(gpointer, gint, GdkInputCondition); 126 static void toc_callback(gpointer, gint, GdkInputCondition);
126 static unsigned char *roast_password(char *); 127 static unsigned char *roast_password(char *);
127 static void accept_file_dialog(struct ft_request *); 128 static void accept_file_dialog(struct ft_request *);
128 129
129 /* ok. this function used to take username/password, and return 0 on success. 130 /* ok. this function used to take username/password, and return 0 on success.
138 gc = new_gaim_conn(user); 139 gc = new_gaim_conn(user);
139 gc->proto_data = tdt = g_new0(struct toc_data, 1); 140 gc->proto_data = tdt = g_new0(struct toc_data, 1);
140 141
141 g_snprintf(buf, sizeof buf, "Looking up %s", 142 g_snprintf(buf, sizeof buf, "Looking up %s",
142 user->proto_opt[USEROPT_AUTH][0] ? user->proto_opt[USEROPT_AUTH] : TOC_HOST); 143 user->proto_opt[USEROPT_AUTH][0] ? user->proto_opt[USEROPT_AUTH] : TOC_HOST);
143 /* this is such a hack */
144 set_login_progress(gc, 1, buf); 144 set_login_progress(gc, 1, buf);
145 while (gtk_events_pending()) 145
146 gtk_main_iteration(); 146 debug_printf("* Client connects to TOC\n");
147 if (!g_slist_find(connections, gc))
148 return;
149
150 tdt->toc_fd = 147 tdt->toc_fd =
151 proxy_connect(user->proto_opt[USEROPT_AUTH][0] ? user->proto_opt[USEROPT_AUTH] : TOC_HOST, 148 proxy_connect(user->proto_opt[USEROPT_AUTH][0] ? user->proto_opt[USEROPT_AUTH] : TOC_HOST,
152 user->proto_opt[USEROPT_AUTHPORT][0] ? atoi(user-> 149 user->proto_opt[USEROPT_AUTHPORT][0] ?
153 proto_opt[USEROPT_AUTHPORT]) : 150 atoi(user->proto_opt[USEROPT_AUTHPORT]) : TOC_PORT,
154 TOC_PORT, user->proto_opt[USEROPT_SOCKSHOST], 151 user->proto_opt[USEROPT_PROXYHOST],
155 atoi(user->proto_opt[USEROPT_SOCKSPORT]), 152 atoi(user->proto_opt[USEROPT_PROXYPORT]),
156 atoi(user->proto_opt[USEROPT_PROXYTYPE])); 153 atoi(user->proto_opt[USEROPT_PROXYTYPE]),
157 154 toc_login_callback, gc);
158 debug_printf("* Client connects to TOC\n"); 155
159 if (tdt->toc_fd < 0) { 156 if (tdt->toc_fd < 0) {
160 g_snprintf(buf, sizeof(buf), "Connect to %s failed", user->proto_opt[USEROPT_AUTH]); 157 g_snprintf(buf, sizeof(buf), "Connect to %s failed", user->proto_opt[USEROPT_AUTH]);
161 hide_login_progress(gc, buf); 158 hide_login_progress(gc, buf);
162 signoff(gc); 159 signoff(gc);
163 return; 160 return;
164 } 161 }
162 }
163
164 static void toc_login_callback(gpointer data, gint source, GdkInputCondition cond)
165 {
166 struct gaim_connection *gc = data;
167 struct toc_data *tdt = gc->proto_data;
168 char buf[80];
169
170 if (source == -1) {
171 /* we didn't successfully connect. tdt->toc_fd is valid here */
172 hide_login_progress(gc, "Unable to connect.");
173 signoff(gc);
174 return;
175 }
176
177 if (tdt->toc_fd == 0)
178 tdt->toc_fd = source;
165 179
166 debug_printf("* Client sends \"FLAPON\\r\\n\\r\\n\"\n"); 180 debug_printf("* Client sends \"FLAPON\\r\\n\\r\\n\"\n");
167 if (write(tdt->toc_fd, FLAPON, strlen(FLAPON)) < 0) { 181 if (write(tdt->toc_fd, FLAPON, strlen(FLAPON)) < 0) {
168 hide_login_progress(gc, "Disconnected."); 182 hide_login_progress(gc, "Disconnected.");
169 signoff(gc); 183 signoff(gc);
276 strcpy(rp, "0x"); 290 strcpy(rp, "0x");
277 for (x = 0; (x < 150) && pass[x]; x++) 291 for (x = 0; (x < 150) && pass[x]; x++)
278 pos += sprintf(&rp[pos], "%02x", pass[x] ^ roast[x % strlen(roast)]); 292 pos += sprintf(&rp[pos], "%02x", pass[x] ^ roast[x % strlen(roast)]);
279 rp[pos] = '\0'; 293 rp[pos] = '\0';
280 return rp; 294 return rp;
295 }
296
297 static void toc_got_info(gpointer data, char *url_text)
298 {
299 if (!url_text)
300 return;
301
302 g_show_info_text(url_text);
281 } 303 }
282 304
283 static void toc_callback(gpointer data, gint source, GdkInputCondition condition) 305 static void toc_callback(gpointer data, gint source, GdkInputCondition condition)
284 { 306 {
285 struct gaim_connection *gc = (struct gaim_connection *)data; 307 struct gaim_connection *gc = (struct gaim_connection *)data;
555 char *name, *url, tmp[256]; 577 char *name, *url, tmp[256];
556 578
557 name = strtok(NULL, ":"); 579 name = strtok(NULL, ":");
558 url = strtok(NULL, ":"); 580 url = strtok(NULL, ":");
559 581
560 g_snprintf(tmp, sizeof(tmp), "http://%s:%d/%s", TOC_HOST, TOC_PORT, url); 582 g_snprintf(tmp, sizeof(tmp), "http://%s:%d/%s",
561 g_show_info(gc->user, tmp); 583 gc->user->proto_opt[USEROPT_AUTH][0] ?
584 gc->user->proto_opt[USEROPT_AUTH] : TOC_HOST,
585 gc->user->proto_opt[USEROPT_AUTHPORT][0] ?
586 atoi(gc->user->proto_opt[USEROPT_AUTHPORT]) : TOC_PORT,
587 url);
588 grab_url(gc->user, tmp, toc_got_info, NULL);
562 } else if (!strcasecmp(c, "DIR_STATUS")) { 589 } else if (!strcasecmp(c, "DIR_STATUS")) {
563 } else if (!strcasecmp(c, "ADMIN_NICK_STATUS")) { 590 } else if (!strcasecmp(c, "ADMIN_NICK_STATUS")) {
564 } else if (!strcasecmp(c, "ADMIN_PASSWD_STATUS")) { 591 } else if (!strcasecmp(c, "ADMIN_PASSWD_STATUS")) {
565 do_error_dialog(_("Password Change Successeful"), _("Gaim - Password Change")); 592 do_error_dialog(_("Password Change Successeful"), _("Gaim - Password Change"));
566 } else if (!strcasecmp(c, "PAUSE")) { 593 } else if (!strcasecmp(c, "PAUSE")) {
991 g_snprintf(user->proto_opt[USEROPT_AUTH], 1018 g_snprintf(user->proto_opt[USEROPT_AUTH],
992 sizeof(user->proto_opt[USEROPT_AUTH]), "%s", gtk_entry_get_text(entry)); 1019 sizeof(user->proto_opt[USEROPT_AUTH]), "%s", gtk_entry_get_text(entry));
993 } else if (entrynum == USEROPT_AUTHPORT) { 1020 } else if (entrynum == USEROPT_AUTHPORT) {
994 g_snprintf(user->proto_opt[USEROPT_AUTHPORT], 1021 g_snprintf(user->proto_opt[USEROPT_AUTHPORT],
995 sizeof(user->proto_opt[USEROPT_AUTHPORT]), "%s", gtk_entry_get_text(entry)); 1022 sizeof(user->proto_opt[USEROPT_AUTHPORT]), "%s", gtk_entry_get_text(entry));
996 } else if (entrynum == USEROPT_SOCKSHOST) { 1023 } else if (entrynum == USEROPT_PROXYHOST) {
997 g_snprintf(user->proto_opt[USEROPT_SOCKSHOST], 1024 g_snprintf(user->proto_opt[USEROPT_PROXYHOST],
998 sizeof(user->proto_opt[USEROPT_SOCKSHOST]), "%s", gtk_entry_get_text(entry)); 1025 sizeof(user->proto_opt[USEROPT_PROXYHOST]), "%s", gtk_entry_get_text(entry));
999 } else if (entrynum == USEROPT_SOCKSPORT) { 1026 } else if (entrynum == USEROPT_PROXYPORT) {
1000 g_snprintf(user->proto_opt[USEROPT_SOCKSPORT], 1027 g_snprintf(user->proto_opt[USEROPT_PROXYPORT],
1001 sizeof(user->proto_opt[USEROPT_SOCKSPORT]), "%s", gtk_entry_get_text(entry)); 1028 sizeof(user->proto_opt[USEROPT_PROXYPORT]), "%s", gtk_entry_get_text(entry));
1002 } 1029 }
1003 } 1030 }
1004 1031
1005 static void toc_print_optionrad(GtkRadioButton * entry, struct aim_user *user) 1032 static void toc_print_optionrad(GtkRadioButton * entry, struct aim_user *user)
1006 { 1033 {
1076 gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0); 1103 gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0);
1077 gtk_widget_show(label); 1104 gtk_widget_show(label);
1078 1105
1079 entry = gtk_entry_new(); 1106 entry = gtk_entry_new();
1080 gtk_box_pack_end(GTK_BOX(hbox), entry, FALSE, FALSE, 0); 1107 gtk_box_pack_end(GTK_BOX(hbox), entry, FALSE, FALSE, 0);
1081 gtk_object_set_user_data(GTK_OBJECT(entry), (void *)USEROPT_SOCKSHOST); 1108 gtk_object_set_user_data(GTK_OBJECT(entry), (void *)USEROPT_PROXYHOST);
1082 gtk_signal_connect(GTK_OBJECT(entry), "changed", GTK_SIGNAL_FUNC(toc_print_option), user); 1109 gtk_signal_connect(GTK_OBJECT(entry), "changed", GTK_SIGNAL_FUNC(toc_print_option), user);
1083 if (user->proto_opt[USEROPT_SOCKSHOST][0]) { 1110 if (user->proto_opt[USEROPT_PROXYHOST][0]) {
1084 debug_printf("setting text %s\n", user->proto_opt[USEROPT_SOCKSHOST]); 1111 debug_printf("setting text %s\n", user->proto_opt[USEROPT_PROXYHOST]);
1085 gtk_entry_set_text(GTK_ENTRY(entry), user->proto_opt[USEROPT_SOCKSHOST]); 1112 gtk_entry_set_text(GTK_ENTRY(entry), user->proto_opt[USEROPT_PROXYHOST]);
1086 } 1113 }
1087 gtk_widget_show(entry); 1114 gtk_widget_show(entry);
1088 1115
1089 1116
1090 hbox = gtk_hbox_new(FALSE, 0); 1117 hbox = gtk_hbox_new(FALSE, 0);
1095 gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0); 1122 gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0);
1096 gtk_widget_show(label); 1123 gtk_widget_show(label);
1097 1124
1098 entry = gtk_entry_new(); 1125 entry = gtk_entry_new();
1099 gtk_box_pack_end(GTK_BOX(hbox), entry, FALSE, FALSE, 0); 1126 gtk_box_pack_end(GTK_BOX(hbox), entry, FALSE, FALSE, 0);
1100 gtk_object_set_user_data(GTK_OBJECT(entry), (void *)USEROPT_SOCKSPORT); 1127 gtk_object_set_user_data(GTK_OBJECT(entry), (void *)USEROPT_PROXYPORT);
1101 gtk_signal_connect(GTK_OBJECT(entry), "changed", GTK_SIGNAL_FUNC(toc_print_option), user); 1128 gtk_signal_connect(GTK_OBJECT(entry), "changed", GTK_SIGNAL_FUNC(toc_print_option), user);
1102 if (user->proto_opt[USEROPT_SOCKSPORT][0]) { 1129 if (user->proto_opt[USEROPT_PROXYPORT][0]) {
1103 debug_printf("setting text %s\n", user->proto_opt[USEROPT_SOCKSPORT]); 1130 debug_printf("setting text %s\n", user->proto_opt[USEROPT_PROXYPORT]);
1104 gtk_entry_set_text(GTK_ENTRY(entry), user->proto_opt[USEROPT_SOCKSPORT]); 1131 gtk_entry_set_text(GTK_ENTRY(entry), user->proto_opt[USEROPT_PROXYPORT]);
1105 } 1132 }
1106 gtk_widget_show(entry); 1133 gtk_widget_show(entry);
1107 1134
1108 1135
1109 first = gtk_radio_button_new_with_label(NULL, "No proxy"); 1136 first = gtk_radio_button_new_with_label(NULL, "No proxy");
1373 char *user; 1400 char *user;
1374 char *cookie; 1401 char *cookie;
1375 char *ip; 1402 char *ip;
1376 int port; 1403 int port;
1377 long size; 1404 long size;
1405 struct stat st;
1378 1406
1379 GtkWidget *window; 1407 GtkWidget *window;
1380 int files; 1408 int files;
1381 char *filename; 1409 char *filename;
1382 FILE *file; 1410 FILE *file;
1519 g_free(ft); 1547 g_free(ft);
1520 } 1548 }
1521 } 1549 }
1522 } 1550 }
1523 1551
1552 static void toc_send_file_connect(gpointer data, gint src, GdkInputCondition cond)
1553 {
1554 struct file_transfer *ft = data;
1555
1556 if (src == -1) {
1557 do_error_dialog(_("Could not connect for transfer!"), _("Error"));
1558 g_free(ft->filename);
1559 g_free(ft->cookie);
1560 g_free(ft->user);
1561 g_free(ft->ip);
1562 g_free(ft);
1563 return;
1564 }
1565
1566 ft->inpa = gdk_input_add(src, GDK_INPUT_READ | GDK_INPUT_EXCEPTION, toc_send_file_callback, ft);
1567 }
1568
1524 static void toc_send_file(gpointer a, struct file_transfer *old_ft) 1569 static void toc_send_file(gpointer a, struct file_transfer *old_ft)
1525 { 1570 {
1526 struct file_transfer *ft; 1571 struct file_transfer *ft;
1527 char *dirname = gtk_file_selection_get_filename(GTK_FILE_SELECTION(old_ft->window)); 1572 char *dirname = gtk_file_selection_get_filename(GTK_FILE_SELECTION(old_ft->window));
1528 int fd; 1573 int fd;
1548 g_snprintf(buf, sizeof(buf), "toc_rvous_accept %s %s %s", ft->user, ft->cookie, FILE_SEND_UID); 1593 g_snprintf(buf, sizeof(buf), "toc_rvous_accept %s %s %s", ft->user, ft->cookie, FILE_SEND_UID);
1549 sflap_send(ft->gc, buf, -1, TYPE_DATA); 1594 sflap_send(ft->gc, buf, -1, TYPE_DATA);
1550 1595
1551 fd = 1596 fd =
1552 proxy_connect(ft->ip, ft->port, 1597 proxy_connect(ft->ip, ft->port,
1553 user->proto_opt[USEROPT_SOCKSHOST], 1598 user->proto_opt[USEROPT_PROXYHOST],
1554 atoi(user->proto_opt[USEROPT_SOCKSPORT]), 1599 atoi(user->proto_opt[USEROPT_PROXYPORT]),
1555 atoi(user->proto_opt[USEROPT_PROXYTYPE])); 1600 atoi(user->proto_opt[USEROPT_PROXYTYPE]),
1601 toc_send_file_connect, ft);
1556 if (fd < 0) { 1602 if (fd < 0) {
1557 do_error_dialog(_("Could not connect for transfer!"), _("Error")); 1603 do_error_dialog(_("Could not connect for transfer!"), _("Error"));
1558 g_free(ft->filename); 1604 g_free(ft->filename);
1559 g_free(ft->cookie); 1605 g_free(ft->cookie);
1560 g_free(ft->user); 1606 g_free(ft->user);
1561 g_free(ft->ip); 1607 g_free(ft->ip);
1562 g_free(ft); 1608 g_free(ft);
1563 return; 1609 return;
1564 } 1610 }
1565
1566 ft->inpa = gdk_input_add(fd, GDK_INPUT_READ | GDK_INPUT_EXCEPTION, toc_send_file_callback, ft);
1567 } 1611 }
1568 1612
1569 static void toc_get_file_callback(gpointer data, gint source, GdkInputCondition cond) 1613 static void toc_get_file_callback(gpointer data, gint source, GdkInputCondition cond)
1570 { 1614 {
1571 char buf[BUF_LONG]; 1615 char buf[BUF_LONG];
1681 g_free(ft); 1725 g_free(ft);
1682 return; 1726 return;
1683 } 1727 }
1684 } 1728 }
1685 1729
1730 static void toc_get_file_connect(gpointer data, gint src, GdkInputCondition cond)
1731 {
1732 struct file_transfer *ft = data;
1733 struct file_header *hdr;
1734 char *buf;
1735
1736 if (src == -1) {
1737 do_error_dialog(_("Could not connect for transfer!"), _("Error"));
1738 fclose(ft->file);
1739 g_free(ft->filename);
1740 g_free(ft->cookie);
1741 g_free(ft->user);
1742 g_free(ft->ip);
1743 g_free(ft);
1744 return;
1745 }
1746
1747 hdr = (struct file_header *)ft;
1748 hdr->magic[0] = 'O'; hdr->magic[1] = 'F'; hdr->magic[2] = 'T'; hdr->magic[3] = '2';
1749 hdr->hdrlen = htons(256);
1750 hdr->hdrtype = htons(0x1108);
1751 buf = frombase64(ft->cookie);
1752 g_snprintf(hdr->bcookie, 8, "%s", buf);
1753 g_free(buf);
1754 hdr->totfiles = htons(1); hdr->filesleft = htons(1);
1755 hdr->totparts = htons(1); hdr->partsleft = htons(1);
1756 hdr->totsize = htonl((long)ft->st.st_size); /* combined size of all files */
1757 /* size = strlen("mm/dd/yyyy hh:mm sizesize 'name'\r\n") */
1758 hdr->size = htonl(28 + strlen(g_basename(ft->filename))); /* size of listing.txt */
1759 hdr->modtime = htonl(ft->st.st_mtime);
1760 hdr->checksum = htonl(0x89f70000); /* uh... */
1761 g_snprintf(hdr->idstring, 32, "OFT_Windows ICBMFT V1.1 32");
1762 hdr->flags = 0x02;
1763 hdr->lnameoffset = 0x1A;
1764 hdr->lsizeoffset = 0x10;
1765 g_snprintf(hdr->name, 64, "listing.txt");
1766 if (write(src, hdr, 256) < 0) {
1767 do_error_dialog(_("Could not write file header!"), _("Error"));
1768 fclose(ft->file);
1769 g_free(ft->filename);
1770 g_free(ft->cookie);
1771 g_free(ft->user);
1772 g_free(ft->ip);
1773 g_free(ft);
1774 return;
1775 }
1776
1777 ft->inpa = gdk_input_add(src, GDK_INPUT_READ | GDK_INPUT_EXCEPTION, toc_get_file_callback, ft);
1778 }
1779
1686 static void toc_get_file(gpointer a, struct file_transfer *old_ft) 1780 static void toc_get_file(gpointer a, struct file_transfer *old_ft)
1687 { 1781 {
1688 struct file_transfer *ft; 1782 struct file_transfer *ft;
1689 struct file_header *hdr;
1690 char *dirname = gtk_file_selection_get_filename(GTK_FILE_SELECTION(old_ft->window)); 1783 char *dirname = gtk_file_selection_get_filename(GTK_FILE_SELECTION(old_ft->window));
1691 int fd; 1784 int fd;
1692 struct aim_user *user; 1785 struct aim_user *user;
1693 char *buf, buf2[BUF_LEN * 2]; 1786 char *buf, buf2[BUF_LEN * 2];
1694 struct stat st;
1695 1787
1696 if (file_is_dir(dirname, old_ft->window)) 1788 if (file_is_dir(dirname, old_ft->window))
1697 return; 1789 return;
1698 ft = g_new0(struct file_transfer, 1); 1790 ft = g_new0(struct file_transfer, 1);
1699 ft->filename = g_strdup(dirname); 1791 ft->filename = g_strdup(dirname);
1704 g_free(buf); 1796 g_free(buf);
1705 g_free(ft->filename); 1797 g_free(ft->filename);
1706 g_free(ft); 1798 g_free(ft);
1707 return; 1799 return;
1708 } 1800 }
1709 if (stat(dirname, &st)) { 1801 if (stat(dirname, &ft->st)) {
1710 buf = g_strdup_printf("Unable to examine %s!", dirname); 1802 buf = g_strdup_printf("Unable to examine %s!", dirname);
1711 do_error_dialog(buf, "Error"); 1803 do_error_dialog(buf, "Error");
1712 g_free(buf); 1804 g_free(buf);
1713 g_free(ft->filename); 1805 g_free(ft->filename);
1714 g_free(ft); 1806 g_free(ft);
1725 g_snprintf(buf2, sizeof(buf2), "toc_rvous_accept %s %s %s", ft->user, ft->cookie, FILE_GET_UID); 1817 g_snprintf(buf2, sizeof(buf2), "toc_rvous_accept %s %s %s", ft->user, ft->cookie, FILE_GET_UID);
1726 sflap_send(ft->gc, buf2, -1, TYPE_DATA); 1818 sflap_send(ft->gc, buf2, -1, TYPE_DATA);
1727 1819
1728 fd = 1820 fd =
1729 proxy_connect(ft->ip, ft->port, 1821 proxy_connect(ft->ip, ft->port,
1730 user->proto_opt[USEROPT_SOCKSHOST], 1822 user->proto_opt[USEROPT_PROXYHOST],
1731 atoi(user->proto_opt[USEROPT_SOCKSPORT]), 1823 atoi(user->proto_opt[USEROPT_PROXYPORT]),
1732 atoi(user->proto_opt[USEROPT_PROXYTYPE])); 1824 atoi(user->proto_opt[USEROPT_PROXYTYPE]),
1825 toc_get_file_connect, ft);
1733 if (fd < 0) { 1826 if (fd < 0) {
1734 do_error_dialog(_("Could not connect for transfer!"), _("Error")); 1827 do_error_dialog(_("Could not connect for transfer!"), _("Error"));
1735 fclose(ft->file); 1828 fclose(ft->file);
1736 g_free(ft->filename); 1829 g_free(ft->filename);
1737 g_free(ft->cookie); 1830 g_free(ft->cookie);
1738 g_free(ft->user); 1831 g_free(ft->user);
1739 g_free(ft->ip); 1832 g_free(ft->ip);
1740 g_free(ft); 1833 g_free(ft);
1741 return; 1834 return;
1742 } 1835 }
1743
1744 hdr = (struct file_header *)ft;
1745 hdr->magic[0] = 'O'; hdr->magic[1] = 'F'; hdr->magic[2] = 'T'; hdr->magic[3] = '2';
1746 hdr->hdrlen = htons(256);
1747 hdr->hdrtype = htons(0x1108);
1748 buf = frombase64(ft->cookie);
1749 g_snprintf(hdr->bcookie, 8, "%s", buf);
1750 g_free(buf);
1751 hdr->totfiles = htons(1); hdr->filesleft = htons(1);
1752 hdr->totparts = htons(1); hdr->partsleft = htons(1);
1753 hdr->totsize = htonl((long)st.st_size); /* combined size of all files */
1754 /* size = strlen("mm/dd/yyyy hh:mm sizesize 'name'\r\n") */
1755 hdr->size = htonl(28 + strlen(g_basename(ft->filename))); /* size of listing.txt */
1756 hdr->modtime = htonl(st.st_mtime);
1757 hdr->checksum = htonl(0x89f70000); /* uh... */
1758 g_snprintf(hdr->idstring, 32, "OFT_Windows ICBMFT V1.1 32");
1759 hdr->flags = 0x02;
1760 hdr->lnameoffset = 0x1A;
1761 hdr->lsizeoffset = 0x10;
1762 g_snprintf(hdr->name, 64, "listing.txt");
1763 if (write(fd, hdr, 256) < 0) {
1764 do_error_dialog(_("Could not write file header!"), _("Error"));
1765 fclose(ft->file);
1766 g_free(ft->filename);
1767 g_free(ft->cookie);
1768 g_free(ft->user);
1769 g_free(ft->ip);
1770 g_free(ft);
1771 return;
1772 }
1773
1774 ft->inpa = gdk_input_add(fd, GDK_INPUT_READ | GDK_INPUT_EXCEPTION, toc_get_file_callback, ft);
1775 } 1836 }
1776 1837
1777 static void cancel_callback(gpointer a, struct file_transfer *ft) { 1838 static void cancel_callback(gpointer a, struct file_transfer *ft) {
1778 gtk_widget_destroy(ft->window); 1839 gtk_widget_destroy(ft->window);
1779 if (a == ft->window) { 1840 if (a == ft->window) {