]> code.citadel.org Git - citadel.git/commitdiff
* move the mime guesser out into libcitadel
authorWilfried Göesgens <willi@citadel.org>
Fri, 8 Feb 2008 21:47:41 +0000 (21:47 +0000)
committerWilfried Göesgens <willi@citadel.org>
Fri, 8 Feb 2008 21:47:41 +0000 (21:47 +0000)
webcit/webcit.c
webcit/webcit.h

index 67ed35c212eb393005d22acbbead1c5f376c4bfe..729f753c1cbd296e8f481ba1c8a56f45a6a6250e 100644 (file)
@@ -763,44 +763,6 @@ void output_static(char *what)
        }
 }
 
-
-
-typedef struct _MimeGuess {
-       const char *Pattern;
-       size_t PatternLen;
-       long PatternOffset;
-       const char *MimeString;
-} MimeGuess;
-
-MimeGuess MyMimes [] = {
-       {
-               "GIF",
-               3,
-               0,
-               "image/gif"
-       },
-       {
-               "\xff\xd8",
-               2,
-               0,
-               "image/jpeg"
-       },
-       {
-               "\x89PNG",
-               4,
-               0,
-               "image/png"
-       },
-       { // last...
-               "",
-               0,
-               0,
-               ""
-       }
-};
-
-
-
 /**
  * \brief When the browser requests an image file from the Citadel server,
  * this function is called to transmit it.
@@ -810,7 +772,7 @@ void output_image()
        char buf[SIZ];
        char *xferbuf = NULL;
        off_t bytes;
-       int MimeIndex = 0;
+       const char *MimeType;
 
        serv_printf("OIMG %s|%s", bstr("name"), bstr("parm"));
        serv_getln(buf, sizeof buf);
@@ -823,21 +785,13 @@ void output_image()
                serv_puts("CLOS");
                serv_getln(buf, sizeof buf);
 
-               while (MyMimes[MimeIndex].PatternLen != 0)
-               {
-                       if (strncmp(MyMimes[MimeIndex].Pattern, 
-                                   &xferbuf[MyMimes[MimeIndex].PatternOffset], 
-                                   MyMimes[MimeIndex].PatternLen) == 0)
-                               break;
-                       MimeIndex ++;
-               }
-
+               MimeType = GuessMimeType (xferbuf, bytes);
                /** Write it to the browser */
-               if (MyMimes[MimeIndex].PatternLen != 0)
+               if (!IsEmptyStr(MimeType))
                {
                        http_transmit_thing(xferbuf, 
                                            (size_t)bytes, 
-                                           MyMimes[MimeIndex].MimeString
+                                           MimeType
                                            0);
                        free(xferbuf);
                        return;
index 7ca1fac8718af549c25095e007f18d3489d515ca..ba1b40a9affb61e58e512728d57fb25cae969fb7 100644 (file)
@@ -124,7 +124,7 @@ extern locale_t wc_locales[];
 #define CLIENT_ID              4
 #define CLIENT_VERSION         730             /* This version of WebCit */
 #define MINIMUM_CIT_VERSION    730             /* min required Citadel ver */
-#define        LIBCITADEL_MIN          103             /* min required libcitadel ver */
+#define        LIBCITADEL_MIN          104             /* min required libcitadel ver */
 #define DEFAULT_HOST           "localhost"     /* Default Citadel server */
 #define DEFAULT_PORT           "504"
 #define LB                     (1)             /* Internal escape chars */