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></div>\n");
58 void download_file(char *filename)
62 char content_type[256];
65 /* Setting to nonzero forces a MIME type of application/octet-stream */
66 int force_download = 1;
68 serv_printf("OPEN %s", filename);
69 serv_getln(buf, sizeof buf);
71 bytes = extract_long(&buf[4], 0);
72 content = malloc(bytes + 2);
74 strcpy(content_type, "application/octet-stream");
77 extract_token(content_type, &buf[4], 3, '|', sizeof content_type);
79 output_headers(0, 0, 0, 0, 0, 0);
80 read_server_binary(content, bytes);
82 serv_getln(buf, sizeof buf);
83 http_transmit_thing(content, bytes, content_type, 0);
86 wprintf("HTTP/1.1 404 %s\n", &buf[4]);
87 output_headers(0, 0, 0, 0, 0, 0);
88 wprintf("Content-Type: text/plain\r\n");
90 wprintf(_("An error occurred while retrieving this file: %s\n"), &buf[4]);