* don't nail upload hellos to .gif as we don't need that anymore
authorWilfried Göesgens <willi@citadel.org>
Sat, 9 Feb 2008 15:46:20 +0000 (15:46 +0000)
committerWilfried Göesgens <willi@citadel.org>
Sat, 9 Feb 2008 15:46:20 +0000 (15:46 +0000)
* specify mimetype at image upload
* display the current image in the upload dialog
* specify mimetype at file upload
* display listing with mimetypes
* dummy implementation with mime-icons, just does diskette fallback atm.
* some tiny inacuracy in the translation.

webcit/downloads.c
webcit/graphics.c
webcit/po/de.po
webcit/webcit.c
webcit/webcit.h

index f500fbc84387fef615666d86bbbfa6095c7e64f1..f97b1b4fdbab42be3a0ae7234f642ad46a18e427 100644 (file)
@@ -8,6 +8,7 @@ void display_room_directory(void)
        char buf[1024];
        char filename[256];
        char filesize[256];
+       char mimetype[64];
        char comment[512];
        int bg = 0;
        char title[256];
@@ -24,10 +25,11 @@ void display_room_directory(void)
 
        wprintf("<div class=\"fix_scrollbar_bug\">"
                "<table class=\"downloads_background\"><tr><td>\n");
-       wprintf("<tr><th>%s</th><th>%s</th><th>%s</th></tr>\n",
-                       _("Filename"),
-                       _("Size"),
-                       _("Description")
+       wprintf("<tr><th>%s</th><th>%s</th><th>%s</th><th>%s</th></tr>\n",
+               _("Filename"),
+               _("Size"),
+               _("Content"),
+               _("Description")
        );
 
        serv_puts("RDIR");
@@ -36,19 +38,20 @@ void display_room_directory(void)
        {
                extract_token(filename, buf, 0, '|', sizeof filename);
                extract_token(filesize, buf, 1, '|', sizeof filesize);
-               extract_token(comment, buf, 2, '|', sizeof comment);
+               extract_token(mimetype, buf, 2, '|', sizeof mimetype);
+               extract_token(comment,  buf, 3, '|', sizeof comment);
                bg = 1 - bg;
                wprintf("<tr bgcolor=\"#%s\">", (bg ? "DDDDDD" : "FFFFFF"));
                wprintf("<td>"
                        "<a href=\"download_file/");
                urlescputs(filename);
-               wprintf("\"><img src=\"static/diskette_24x.gif\" border=0 align=middle>\n");
+               wprintf("\"><img src=\"display_mime_icon?type=%s\" border=0 align=middle>\n", mimetype);
                                        escputs(filename);      wprintf("</a></td>");
                wprintf("<td>");        escputs(filesize);      wprintf("</td>");
+               wprintf("<td>");        escputs(mimetype);      wprintf("</td>");
                wprintf("<td>");        escputs(comment);       wprintf("</td>");
                wprintf("</tr>\n");
        }
-
        wprintf("</table>\n");
 
        /** Now offer the ability to upload files... */
@@ -78,6 +81,15 @@ void display_room_directory(void)
        wDumpContent(1);
 }
 
+extern char* static_dirs[];
+void display_mime_icon(void)
+{
+       char diskette[SIZ];
+
+       snprintf (diskette, SIZ, "%s%s", static_dirs[0], "/diskette_24x.gif");
+       output_static(diskette);
+
+}
 
 void download_file(char *filename)
 {
@@ -122,38 +134,41 @@ void download_file(char *filename)
 
 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) */
 
-       serv_printf("UOPN %s|%s", WC->upload_filename, bstr("description"));
+       MimeType = GuessMimeType(WCC->upload, WCC->upload_length); 
+       serv_printf("UOPN %s|%s|%s", WCC->upload_filename, MimeType, bstr("description"));
        serv_getln(buf, sizeof buf);
        if (buf[0] != '2')
        {
-               strcpy(WC->ImportantMessage, &buf[4]);
+               strcpy(WCC->ImportantMessage, &buf[4]);
                display_room_directory();
                return;
        }
 
-       while (bytes_transmitted < WC->upload_length)
+       while (bytes_transmitted < WCC->upload_length)
        {
                blocksize = 4096;
-               if (blocksize > (WC->upload_length - bytes_transmitted))
+               if (blocksize > (WCC->upload_length - bytes_transmitted))
                {
-                       blocksize = (WC->upload_length - bytes_transmitted);
+                       blocksize = (WCC->upload_length - bytes_transmitted);
                }
                serv_printf("WRIT %d", blocksize);
                serv_getln(buf, sizeof buf);
                if (buf[0] == '7')
                {
                        blocksize = atoi(&buf[4]);
-                       serv_write(&WC->upload[bytes_transmitted], blocksize);
+                       serv_write(&WCC->upload[bytes_transmitted], blocksize);
                        bytes_transmitted += blocksize;
                }
        }
 
        serv_puts("UCLS 1");
        serv_getln(buf, sizeof buf);
-       strcpy(WC->ImportantMessage, &buf[4]);
+       strcpy(WCC->ImportantMessage, &buf[4]);
        display_room_directory();
 }
index 3179d580f01bb33c789f2e3c7628b40f868ec4d7..3c16baf414e218dd2c91fa16de6880e26ced0bcd 100644 (file)
@@ -7,11 +7,13 @@
 
 #include "webcit.h"
 
-void display_graphics_upload(char *description, char *check_cmd, char *uplurl)
+void display_graphics_upload(char *description, char *filename, char *uplurl)
 {
        char buf[SIZ];
 
-       serv_puts(check_cmd);
+
+       snprintf(buf, SIZ, "UIMG 0||%s", filename);
+       serv_puts(buf);
        serv_getln(buf, sizeof buf);
        if (buf[0] != '2') {
                strcpy(WC->ImportantMessage, &buf[4]);
@@ -33,12 +35,14 @@ void display_graphics_upload(char *description, char *check_cmd, char *uplurl)
        urlescputs(bstr("which_room"));
        wprintf("\">\n");
 
-       wprintf(_("You can upload any image directly from your computer, "
-                 "as long as it is in GIF, JPEG or PNG"));
+       wprintf(_("You can upload an image directly from your computer"));
        wprintf("<br /><br />\n");
 
        wprintf(_("Please select a file to upload:"));
        wprintf("<input type=\"file\" name=\"filename\" size=\"35\">\n");
+
+       wprintf("<div class=\"uploadpic\"><img src=\"image&name=%s\"></div>\n", filename);
+
        wprintf("<div class=\"buttons\">");
        wprintf("<input type=\"submit\" name=\"upload_button\" value=\"%s\">\n", _("Upload"));
        wprintf("&nbsp;");
@@ -53,12 +57,14 @@ void display_graphics_upload(char *description, char *check_cmd, char *uplurl)
        wDumpContent(1);
 }
 
-void do_graphics_upload(char *upl_cmd)
+void do_graphics_upload(char *filename)
 {
+       const char *MimeType;
        char buf[SIZ];
        int bytes_remaining;
        int pos = 0;
        int thisblock;
+       bytes_remaining = WC->upload_length;
 
        if (!IsEmptyStr(bstr("cancel_button"))) {
                strcpy(WC->ImportantMessage,
@@ -73,14 +79,17 @@ void do_graphics_upload(char *upl_cmd)
                display_main_menu();
                return;
        }
-       serv_puts(upl_cmd);
+       
+       MimeType = GuessMimeType(&WC->upload[0], bytes_remaining);
+       snprintf(buf, SIZ, "UIMG 1|%s|%s", MimeType, filename);
+       serv_puts(buf);
+
        serv_getln(buf, sizeof buf);
        if (buf[0] != '2') {
                strcpy(WC->ImportantMessage, &buf[4]);
                display_main_menu();
                return;
        }
-       bytes_remaining = WC->upload_length;
        while (bytes_remaining) {
                thisblock = ((bytes_remaining > 4096) ? 4096 : bytes_remaining);
                serv_printf("WRIT %d", thisblock);
index 6a976b56b8486de4991fde6442e2c997e2eb8b98..16e912fd098adff88907ed79f39b71ad58b00fc3 100644 (file)
@@ -631,7 +631,7 @@ msgstr "Eine neue Etage wurde erstellt."
 
 #: ../graphics.c:25
 msgid "Image upload"
-msgstr "Bild hochgeladen"
+msgstr "Bild hochladen"
 
 #: ../graphics.c:36
 msgid ""
index 729f753c1cbd296e8f481ba1c8a56f45a6a6250e..29463d6c972808a73f2092b0572c113a39efd009 100644 (file)
@@ -680,7 +680,7 @@ void output_static(char *what)
        off_t count = 0;
        size_t res;
        char *bigbuffer;
-       char content_type[128];
+       const char *content_type;
        int len;
 
        fp = fopen(what, "rb");
@@ -692,36 +692,7 @@ void output_static(char *what)
                wprintf("Cannot open %s: %s\r\n", what, strerror(errno));
        } else {
                len = strlen (what);
-               if (!strncasecmp(&what[len - 4], ".gif", 4))
-                       safestrncpy(content_type, "image/gif", sizeof content_type);
-               else if (!strncasecmp(&what[len - 4], ".txt", 4))
-                       safestrncpy(content_type, "text/plain", sizeof content_type);
-               else if (!strncasecmp(&what[len - 4], ".css", 4))
-                       safestrncpy(content_type, "text/css", sizeof content_type);
-               else if (!strncasecmp(&what[len - 4], ".jpg", 4))
-                       safestrncpy(content_type, "image/jpeg", sizeof content_type);
-               else if (!strncasecmp(&what[len - 4], ".png", 4))
-                       safestrncpy(content_type, "image/png", sizeof content_type);
-               else if (!strncasecmp(&what[len - 4], ".ico", 4))
-                       safestrncpy(content_type, "image/x-icon", sizeof content_type);
-               else if (!strncasecmp(&what[len - 5], ".html", 5))
-                       safestrncpy(content_type, "text/html", sizeof content_type);
-               else if (!strncasecmp(&what[len - 4], ".htm", 4))
-                       safestrncpy(content_type, "text/html", sizeof content_type);
-               else if (!strncasecmp(&what[len - 4], ".wml", 4))
-                       safestrncpy(content_type, "text/vnd.wap.wml", sizeof content_type);
-               else if (!strncasecmp(&what[len - 5], ".wmls", 5))
-                       safestrncpy(content_type, "text/vnd.wap.wmlscript", sizeof content_type);
-               else if (!strncasecmp(&what[len - 5], ".wmlc", 5))
-                       safestrncpy(content_type, "application/vnd.wap.wmlc", sizeof content_type);
-               else if (!strncasecmp(&what[len - 6], ".wmlsc", 6))
-                       safestrncpy(content_type, "application/vnd.wap.wmlscriptc", sizeof content_type);
-               else if (!strncasecmp(&what[len - 5], ".wbmp", 5))
-                       safestrncpy(content_type, "image/vnd.wap.wbmp", sizeof content_type);
-               else if (!strncasecmp(&what[len - 3], ".js", 3))
-                       safestrncpy(content_type, "text/javascript", sizeof content_type);
-               else
-                       safestrncpy(content_type, "application/octet-stream", sizeof content_type);
+               content_type = GuessMimeByFilename(what, len);
 
                if (fstat(fileno(fp), &statbuf) == -1) {
                        lprintf(9, "output_static('%s')  -- FSTAT FAILED --\n", what);
@@ -1547,6 +1518,8 @@ void session_loop(struct httprequest *req)
 
        if (!strcasecmp(action, "image")) {
                output_image();
+       } else if (!strcasecmp(action, "display_mime_icon")) {
+               display_mime_icon();
 
                /**
                 * All functions handled below this point ... make sure we log in
@@ -1706,31 +1679,31 @@ void session_loop(struct httprequest *req)
                /* The users photo display / upload facility */
        } else if (!strcasecmp(action, "display_editpic")) {
                display_graphics_upload(_("your photo"),
-                                       "UIMG 0|_userpic_",
+                                       "_userpic_",
                                        "editpic");
        } else if (!strcasecmp(action, "editpic")) {
-               do_graphics_upload("UIMG 1|_userpic_");
+               do_graphics_upload("_userpic_");
                 /* room picture dispay / upload facility */
        } else if (!strcasecmp(action, "display_editroompic")) {
                display_graphics_upload(_("the icon for this room"),
-                                       "UIMG 0|_roompic_",
+                                       "_roompic_",
                                        "editroompic");
        } else if (!strcasecmp(action, "editroompic")) {
-               do_graphics_upload("UIMG 1|_roompic_");
+               do_graphics_upload("_roompic_");
                /* the greetingpage hello pic */
        } else if (!strcasecmp(action, "display_edithello")) {
                display_graphics_upload(_("the Greetingpicture for the login prompt"),
-                                       "UIMG 0|hello.gif",
+                                       "hello",
                                        "edithellopic");
        } else if (!strcasecmp(action, "edithellopic")) {
-               do_graphics_upload("UIMG 1|hello.gif");
+               do_graphics_upload("hello");
                /* the logoff banner */
        } else if (!strcasecmp(action, "display_editgoodbyepic")) {
                display_graphics_upload(_("the Logoff banner picture"),
-                                       "UIMG 0|goodbuye.gif",
+                                       "UIMG 0|%s|goodbuye",
                                        "editgoodbuyepic");
        } else if (!strcasecmp(action, "editgoodbuyepic")) {
-               do_graphics_upload("UIMG 1|goodbuye.gif");
+               do_graphics_upload("UIMG 1|%s|goodbuye");
 
        } else if (!strcasecmp(action, "delete_floor")) {
                delete_floor();
index ba1b40a9affb61e58e512728d57fb25cae969fb7..a616dc89b908c70f4d038a66fd2440f33623ddf3 100644 (file)
@@ -510,6 +510,7 @@ void output_headers(    int do_httpheaders,
                        int cache);
 void wprintf(const char *format,...);
 void output_static(char *what);
+void display_mime_icon(void);
 void print_menu_box(char* Title, char *Class, int nLines, ...);
 long stresc(char *target, long tSize, char *strbuf, int nbsp, int nolinebreaks);
 void escputs(char *strbuf);