6 void display_room_directory(void)
16 output_headers(1, 1, 2, 0, 0, 0);
17 wprintf("<div id=\"banner\">\n");
19 snprintf(title, sizeof title, _("Files available for download in %s"), WC->wc_roomname);
24 wprintf("<div id=\"content\" class=\"service\">\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><th>%s</th></tr>\n",
36 serv_getln(buf, sizeof buf);
37 if (buf[0] == '1') while (serv_getln(buf, sizeof buf), strcmp(buf, "000"))
39 extract_token(filename, buf, 0, '|', sizeof filename);
40 extract_token(filesize, buf, 1, '|', sizeof filesize);
41 extract_token(mimetype, buf, 2, '|', sizeof mimetype);
42 extract_token(comment, buf, 3, '|', sizeof comment);
44 wprintf("<tr bgcolor=\"#%s\">", (bg ? "DDDDDD" : "FFFFFF"));
46 "<a href=\"download_file/");
48 wprintf("\"><img src=\"display_mime_icon?type=%s\" border=0 align=middle>\n", mimetype);
49 escputs(filename); wprintf("</a></td>");
50 wprintf("<td>"); escputs(filesize); wprintf("</td>");
51 wprintf("<td>"); escputs(mimetype); wprintf("</td>");
52 wprintf("<td>"); escputs(comment); wprintf("</td>");
55 wprintf("</table>\n");
57 /** Now offer the ability to upload files... */
58 if (WC->room_flags & QR_UPLOAD)
62 "enctype=\"multipart/form-data\" "
64 "accept-charset=\"UTF-8\" "
65 "action=\"upload_file\" "
66 "name=\"upload_file_form\""
69 wprintf("<input type=\"hidden\" name=\"nonce\" value=\"%ld\">\n", WC->nonce);
71 wprintf(_("Upload a file:"));
72 wprintf(" <input NAME=\"filename\" SIZE=16 TYPE=\"file\"> \n");
73 wprintf(_("Description:"));
74 wprintf(" <input type=\"text\" name=\"description\" maxlength=\"64\" size=\"64\"> ");
75 wprintf("<input type=\"submit\" name=\"attach_button\" value=\"%s\">\n", _("Upload"));
84 extern char* static_dirs[];
85 void display_mime_icon(void)
89 snprintf (diskette, SIZ, "%s%s", static_dirs[0], "/diskette_24x.gif");
90 output_static(diskette);
94 void download_file(char *filename)
98 char content_type[256];
101 /* Setting to nonzero forces a MIME type of application/octet-stream */
102 int force_download = 1;
104 safestrncpy(buf, filename, sizeof buf);
106 serv_printf("OPEN %s", buf);
107 serv_getln(buf, sizeof buf);
109 bytes = extract_long(&buf[4], 0);
110 content = malloc(bytes + 2);
111 if (force_download) {
112 strcpy(content_type, "application/octet-stream");
115 extract_token(content_type, &buf[4], 3, '|', sizeof content_type);
117 output_headers(0, 0, 0, 0, 0, 0);
118 read_server_binary(content, bytes);
120 serv_getln(buf, sizeof buf);
121 http_transmit_thing(content, bytes, content_type, 0);
124 wprintf("HTTP/1.1 404 %s\n", &buf[4]);
125 output_headers(0, 0, 0, 0, 0, 0);
126 wprintf("Content-Type: text/plain\r\n");
128 wprintf(_("An error occurred while retrieving this file: %s\n"), &buf[4]);
135 void upload_file(void)
137 const char *MimeType;
139 size_t bytes_transmitted = 0;
141 struct wcsession *WCC = WC; /* stack this for faster access (WC is a function) */
143 MimeType = GuessMimeType(WCC->upload, WCC->upload_length);
144 serv_printf("UOPN %s|%s|%s", WCC->upload_filename, MimeType, bstr("description"));
145 serv_getln(buf, sizeof buf);
148 strcpy(WCC->ImportantMessage, &buf[4]);
149 display_room_directory();
153 while (bytes_transmitted < WCC->upload_length)
156 if (blocksize > (WCC->upload_length - bytes_transmitted))
158 blocksize = (WCC->upload_length - bytes_transmitted);
160 serv_printf("WRIT %d", blocksize);
161 serv_getln(buf, sizeof buf);
164 blocksize = atoi(&buf[4]);
165 serv_write(&WCC->upload[bytes_transmitted], blocksize);
166 bytes_transmitted += blocksize;
171 serv_getln(buf, sizeof buf);
172 strcpy(WCC->ImportantMessage, &buf[4]);
173 display_room_directory();