]> code.citadel.org Git - citadel.git/blobdiff - webcit/downloads.c
* typedef wcsession, so we don't always need to say gcc again its a struct.
[citadel.git] / webcit / downloads.c
index f2653746ab1ed4335c32906df94d5b0b8fa49a07..8ec1137380154abe0b9ac4074137b8d12b29de22 100644 (file)
@@ -391,7 +391,7 @@ void download_file(void)
        /* Setting to nonzero forces a MIME type of application/octet-stream */
        int force_download = 1;
        
-       safestrncpy(buf, ChrPtr(WC->UrlFragment1), sizeof buf);
+       safestrncpy(buf, ChrPtr(WC->UrlFragment2), sizeof buf);
        unescape_input(buf);
        serv_printf("OPEN %s", buf);
        serv_getln(buf, sizeof buf);
@@ -405,17 +405,17 @@ void download_file(void)
                        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();
        }
 
 }
@@ -426,9 +426,9 @@ void upload_file(void)
 {
        const char *MimeType;
        char buf[1024];
-       size_t bytes_transmitted = 0;
-       size_t blocksize;
-       struct wcsession *WCC = WC;     /* stack this for faster access (WC is a function) */
+       long bytes_transmitted = 0;
+       long blocksize;
+       wcsession *WCC = WC;     /* stack this for faster access (WC is a function) */
 
        MimeType = GuessMimeType(WCC->upload, WCC->upload_length); 
        serv_printf("UOPN %s|%s|%s", WCC->upload_filename, MimeType, bstr("description"));
@@ -463,10 +463,61 @@ void upload_file(void)
        display_room_directory();
 }
 
+
+
+/*
+ * When the browser requests an image file from the Citadel server,
+ * this function is called to transmit it.
+ */
+void output_image()
+{
+       wcsession *WCC = WC;
+       char buf[SIZ];
+       off_t bytes;
+       const char *MimeType;
+       
+       serv_printf("OIMG %s|%s", bstr("name"), bstr("parm"));
+       serv_getln(buf, sizeof buf);
+       if (buf[0] == '2') {
+               bytes = extract_long(&buf[4], 0);
+
+               /** Read it from the server */
+               
+               if (read_server_binary(WCC->WBuf, bytes) > 0) {
+                       serv_puts("CLOS");
+                       serv_getln(buf, sizeof buf);
+               
+                       MimeType = GuessMimeType (ChrPtr(WCC->WBuf), StrLength(WCC->WBuf));
+                       /** Write it to the browser */
+                       if (!IsEmptyStr(MimeType))
+                       {
+                               http_transmit_thing(MimeType, 0);
+                               return;
+                       }
+               }
+               /* hm... unknown mimetype? fallback to blank gif */
+       } 
+
+       
+       /*
+        * Instead of an ugly 404, send a 1x1 transparent GIF
+        * when there's no such image on the server.
+        */
+       char blank_gif[SIZ];
+       snprintf (blank_gif, SIZ, "%s%s", static_dirs[0], "/blank.gif");
+       output_static(blank_gif);
+}
+
+
+
+
 void 
 InitModule_DOWNLOAD
 (void)
 {
+       WebcitAddUrlHandler(HKEY("image"), output_image, 0);
+       WebcitAddUrlHandler(HKEY("display_mime_icon"), display_mime_icon , 0);
+
        WebcitAddUrlHandler(HKEY("display_room_directory"), display_room_directory, 0);
        WebcitAddUrlHandler(HKEY("display_pictureview"), display_pictureview, 0);
        WebcitAddUrlHandler(HKEY("download_file"), download_file, NEED_URL);