2 * $Id: downloads.c 4849 2007-01-08 20:05:56Z ajc $
6 void display_room_directory(void)
15 output_headers(1, 1, 2, 0, 0, 0);
16 wprintf("<div id=\"banner\">\n"
17 "<table class=\"downloads_banner\"><tr><td>"
18 "<span class=\"titlebar\">");
19 snprintf(title, sizeof title, _("Files available for download in %s"), WC->wc_roomname);
22 "</td></tr></table>\n"
23 "</div>\n<div id=\"content\">\n"
26 wprintf("<div class=\"fix_scrollbar_bug\">"
27 "<table class=\"downloads_background\"><tr><td>\n");
28 wprintf("<tr><th>%s</th><th>%s</th><th>%s</th></tr>\n",
35 serv_getln(buf, sizeof buf);
36 if (buf[0] == '1') while (serv_getln(buf, sizeof buf), strcmp(buf, "000"))
38 extract_token(filename, buf, 0, '|', sizeof filename);
39 extract_token(filesize, buf, 1, '|', sizeof filesize);
40 extract_token(comment, buf, 2, '|', sizeof comment);
42 wprintf("<tr bgcolor=\"#%s\">", (bg ? "DDDDDD" : "FFFFFF"));
44 "<a href=\"download_file/");
46 wprintf("\"><img src=\"static/diskette_24x.gif\" border=0 align=middle>\n");
47 escputs(filename); wprintf("</a></td>");
48 wprintf("<td>"); escputs(filesize); wprintf("</td>");
49 wprintf("<td>"); escputs(comment); wprintf("</td>");
53 wprintf("</table>\n");
55 /** Now offer the ability to upload files... */
56 if (WC->room_flags & QR_UPLOAD)
60 "enctype=\"multipart/form-data\" "
62 "accept-charset=\"UTF-8\" "
63 "action=\"upload_file\" "
64 "name=\"upload_file_form\""
68 wprintf(_("Upload a file:"));
69 wprintf(" <input NAME=\"filename\" SIZE=16 TYPE=\"file\"> \n");
70 wprintf(_("Description:"));
71 wprintf(" <input type=\"text\" name=\"description\" maxlength=\"64\" size=\"64\"> ");
72 wprintf("<input type=\"submit\" name=\"attach_button\" value=\"%s\">\n", _("Upload"));
82 void download_file(char *filename)
86 char content_type[256];
89 /* Setting to nonzero forces a MIME type of application/octet-stream */
90 int force_download = 1;
92 safestrncpy(buf, filename, sizeof buf);
94 serv_printf("OPEN %s", buf);
95 serv_getln(buf, sizeof buf);
97 bytes = extract_long(&buf[4], 0);
98 content = malloc(bytes + 2);
100 strcpy(content_type, "application/octet-stream");
103 extract_token(content_type, &buf[4], 3, '|', sizeof content_type);
105 output_headers(0, 0, 0, 0, 0, 0);
106 read_server_binary(content, bytes);
108 serv_getln(buf, sizeof buf);
109 http_transmit_thing(content, bytes, content_type, 0);
112 wprintf("HTTP/1.1 404 %s\n", &buf[4]);
113 output_headers(0, 0, 0, 0, 0, 0);
114 wprintf("Content-Type: text/plain\r\n");
116 wprintf(_("An error occurred while retrieving this file: %s\n"), &buf[4]);
123 void upload_file(void)
126 size_t bytes_transmitted = 0;
129 serv_printf("UOPN %s|%s", WC->upload_filename, bstr("description"));
130 serv_getln(buf, sizeof buf);
133 strcpy(WC->ImportantMessage, &buf[4]);
134 display_room_directory();
138 while (bytes_transmitted < WC->upload_length)
141 if (blocksize > (WC->upload_length - bytes_transmitted))
143 blocksize = (WC->upload_length - bytes_transmitted);
145 serv_printf("WRIT %d", blocksize);
146 serv_getln(buf, sizeof buf);
149 blocksize = atoi(&buf[4]);
150 serv_write(&WC->upload[bytes_transmitted], blocksize);
151 bytes_transmitted += blocksize;
156 serv_getln(buf, sizeof buf);
157 strcpy(WC->ImportantMessage, &buf[4]);
158 display_room_directory();