00001
00002
00003
00004 #include "webcit.h"
00005
00006 void display_room_directory(void)
00007 {
00008 char buf[1024];
00009 char filename[256];
00010 char filesize[256];
00011 char comment[512];
00012 int bg = 0;
00013 char title[256];
00014
00015 output_headers(1, 1, 2, 0, 0, 0);
00016 wprintf("<div id=\"banner\">\n"
00017 "<table class=\"downloads_banner\"><tr><td>"
00018 "<span class=\"titlebar\">");
00019 snprintf(title, sizeof title, _("Files available for download in %s"), WC->wc_roomname);
00020 escputs(title);
00021 wprintf("</span>"
00022 "</td></tr></table>\n"
00023 "</div>\n<div id=\"content\">\n"
00024 );
00025
00026 wprintf("<div class=\"fix_scrollbar_bug\">"
00027 "<table class=\"downloads_background\"><tr><td>\n");
00028 wprintf("<tr><th>%s</th><th>%s</th><th>%s</th></tr>\n",
00029 _("Filename"),
00030 _("Size"),
00031 _("Description")
00032 );
00033
00034 serv_puts("RDIR");
00035 serv_getln(buf, sizeof buf);
00036 if (buf[0] == '1') while (serv_getln(buf, sizeof buf), strcmp(buf, "000"))
00037 {
00038 extract_token(filename, buf, 0, '|', sizeof filename);
00039 extract_token(filesize, buf, 1, '|', sizeof filesize);
00040 extract_token(comment, buf, 2, '|', sizeof comment);
00041 bg = 1 - bg;
00042 wprintf("<tr bgcolor=\"#%s\">", (bg ? "DDDDDD" : "FFFFFF"));
00043 wprintf("<td>"
00044 "<a href=\"download_file/");
00045 urlescputs(filename);
00046 wprintf("\"><img src=\"static/diskette_24x.gif\" border=0 align=middle>\n");
00047 escputs(filename); wprintf("</a></td>");
00048 wprintf("<td>"); escputs(filesize); wprintf("</td>");
00049 wprintf("<td>"); escputs(comment); wprintf("</td>");
00050 wprintf("</tr>\n");
00051 }
00052
00053 wprintf("</table>\n");
00054
00056 if (WC->room_flags & QR_UPLOAD)
00057 {
00058 wprintf("<hr>");
00059 wprintf("<form "
00060 "enctype=\"multipart/form-data\" "
00061 "method=\"POST\" "
00062 "accept-charset=\"UTF-8\" "
00063 "action=\"upload_file\" "
00064 "name=\"upload_file_form\""
00065 ">\n"
00066 );
00067
00068 wprintf(_("Upload a file:"));
00069 wprintf(" <input NAME=\"filename\" SIZE=16 TYPE=\"file\"> \n");
00070 wprintf(_("Description:"));
00071 wprintf(" <input type=\"text\" name=\"description\" maxlength=\"64\" size=\"64\"> ");
00072 wprintf("<input type=\"submit\" name=\"attach_button\" value=\"%s\">\n", _("Upload"));
00073
00074 wprintf("</form>\n");
00075 }
00076
00077 wprintf("</div>\n");
00078 wDumpContent(1);
00079 }
00080
00081
00082 void download_file(char *filename)
00083 {
00084 char buf[256];
00085 off_t bytes;
00086 char content_type[256];
00087 char *content = NULL;
00088
00089
00090 int force_download = 1;
00091
00092 safestrncpy(buf, filename, sizeof buf);
00093 unescape_input(buf);
00094 serv_printf("OPEN %s", buf);
00095 serv_getln(buf, sizeof buf);
00096 if (buf[0] == '2') {
00097 bytes = extract_long(&buf[4], 0);
00098 content = malloc(bytes + 2);
00099 if (force_download) {
00100 strcpy(content_type, "application/octet-stream");
00101 }
00102 else {
00103 extract_token(content_type, &buf[4], 3, '|', sizeof content_type);
00104 }
00105 output_headers(0, 0, 0, 0, 0, 0);
00106 read_server_binary(content, bytes);
00107 serv_puts("CLOS");
00108 serv_getln(buf, sizeof buf);
00109 http_transmit_thing(content, bytes, content_type, 0);
00110 free(content);
00111 } else {
00112 wprintf("HTTP/1.1 404 %s\n", &buf[4]);
00113 output_headers(0, 0, 0, 0, 0, 0);
00114 wprintf("Content-Type: text/plain\r\n");
00115 wprintf("\r\n");
00116 wprintf(_("An error occurred while retrieving this file: %s\n"), &buf[4]);
00117 }
00118
00119 }
00120
00121
00122
00123 void upload_file(void)
00124 {
00125 char buf[1024];
00126 size_t bytes_transmitted = 0;
00127 size_t blocksize;
00128
00129 serv_printf("UOPN %s|%s", WC->upload_filename, bstr("description"));
00130 serv_getln(buf, sizeof buf);
00131 if (buf[0] != '2')
00132 {
00133 strcpy(WC->ImportantMessage, &buf[4]);
00134 display_room_directory();
00135 return;
00136 }
00137
00138 while (bytes_transmitted < WC->upload_length)
00139 {
00140 blocksize = 4096;
00141 if (blocksize > (WC->upload_length - bytes_transmitted))
00142 {
00143 blocksize = (WC->upload_length - bytes_transmitted);
00144 }
00145 serv_printf("WRIT %d", blocksize);
00146 serv_getln(buf, sizeof buf);
00147 if (buf[0] == '7')
00148 {
00149 blocksize = atoi(&buf[4]);
00150 serv_write(&WC->upload[bytes_transmitted], blocksize);
00151 bytes_transmitted += blocksize;
00152 }
00153 }
00154
00155 serv_puts("UCLS 1");
00156 serv_getln(buf, sizeof buf);
00157 strcpy(WC->ImportantMessage, &buf[4]);
00158 display_room_directory();
00159 }