]> code.citadel.org Git - citadel.git/blobdiff - webcit/downloads.c
* read static/server files directly into the outbuffer
[citadel.git] / webcit / downloads.c
index 88ec86f749067259dfd11a30af90dd0fe3756a22..23bf5f801391e0b410fbd920e3005b4bae7e1ddd 100644 (file)
@@ -237,7 +237,7 @@ void display_room_directory(void)
                switch (SortDirections[i]) {
                default:
                case 0:
-                       Order = 1;
+                       Order = 2;
                        break;
                case 1:
                        Order = 0;
@@ -279,7 +279,7 @@ void display_room_directory(void)
                        "name=\"upload_file_form\""
                        ">\n"
                );
-               wprintf("<input type=\"hidden\" name=\"nonce\" value=\"%ld\">\n", WC->nonce);
+               wprintf("<input type=\"hidden\" name=\"nonce\" value=\"%d\">\n", WC->nonce);
 
                wprintf(_("Upload a file:"));
                wprintf("&nbsp;<input NAME=\"filename\" SIZE=16 TYPE=\"file\">&nbsp;\n");
@@ -381,7 +381,7 @@ void display_mime_icon(void)
 
 }
 
-void download_file(char *filename)
+void download_file(void)
 {
        char buf[256];
        off_t bytes;
@@ -391,7 +391,7 @@ void download_file(char *filename)
        /* Setting to nonzero forces a MIME type of application/octet-stream */
        int force_download = 1;
        
-       safestrncpy(buf, filename, sizeof buf);
+       safestrncpy(buf, ChrPtr(WC->UrlFragment1), sizeof buf);
        unescape_input(buf);
        serv_printf("OPEN %s", buf);
        serv_getln(buf, sizeof buf);
@@ -405,17 +405,17 @@ void download_file(char *filename)
                        extract_token(content_type, &buf[4], 3, '|', sizeof content_type);
                }
                output_headers(0, 0, 0, 0, 0, 0);
-               read_server_binary(content, bytes);
+               read_server_binary(WC->WBuf, bytes);
                serv_puts("CLOS");
                serv_getln(buf, sizeof buf);
-               http_transmit_thing(content, bytes, content_type, 0);
+               http_transmit_thing(content_type, 0);
                free(content);
        } else {
-               wprintf("HTTP/1.1 404 %s\n", &buf[4]);
+               hprintf("HTTP/1.1 404 %s\n", &buf[4]);
                output_headers(0, 0, 0, 0, 0, 0);
-               wprintf("Content-Type: text/plain\r\n");
-               wprintf("\r\n");
+               hprintf("Content-Type: text/plain\r\n");
                wprintf(_("An error occurred while retrieving this file: %s\n"), &buf[4]);
+               end_burst();
        }
 
 }
@@ -462,3 +462,13 @@ void upload_file(void)
        strcpy(WCC->ImportantMessage, &buf[4]);
        display_room_directory();
 }
+
+void 
+InitModule_DOWNLOAD
+(void)
+{
+       WebcitAddUrlHandler(HKEY("display_room_directory"), display_room_directory, 0);
+       WebcitAddUrlHandler(HKEY("display_pictureview"), display_pictureview, 0);
+       WebcitAddUrlHandler(HKEY("download_file"), download_file, NEED_URL);
+       WebcitAddUrlHandler(HKEY("upload_file"), upload_file, 0);
+}