From 129bc3bcfdd155b8e2095f64cd1a62249dfc363e Mon Sep 17 00:00:00 2001 From: =?utf8?q?Wilfried=20G=C3=B6esgens?= Date: Fri, 8 Feb 2008 21:47:41 +0000 Subject: [PATCH] * move the mime guesser out into libcitadel --- webcit/webcit.c | 54 ++++--------------------------------------------- webcit/webcit.h | 2 +- 2 files changed, 5 insertions(+), 51 deletions(-) diff --git a/webcit/webcit.c b/webcit/webcit.c index 67ed35c21..729f753c1 100644 --- a/webcit/webcit.c +++ b/webcit/webcit.c @@ -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; diff --git a/webcit/webcit.h b/webcit/webcit.h index 7ca1fac87..ba1b40a9a 100644 --- a/webcit/webcit.h +++ b/webcit/webcit.h @@ -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 */ -- 2.39.2