X-Git-Url: https://code.citadel.org/?a=blobdiff_plain;f=webcit%2Fwebcit.c;h=67ed35c212eb393005d22acbbead1c5f376c4bfe;hb=d1ff575b169bf1028c9b36bd535b467f00ee2c6a;hp=71b780a76a4c3d6b7d78f9bb5c43c597846c1967;hpb=4173c5f13716fb5658deaa4046c5b3d99682e413;p=citadel.git diff --git a/webcit/webcit.c b/webcit/webcit.c index 71b780a76..67ed35c21 100644 --- a/webcit/webcit.c +++ b/webcit/webcit.c @@ -589,7 +589,7 @@ void http_redirect(char *whichpage) { /** * \brief Output a piece of content to the web browser */ -void http_transmit_thing(char *thing, size_t length, char *content_type, +void http_transmit_thing(char *thing, size_t length, const char *content_type, int is_static) { output_headers(0, 0, 0, 0, 0, is_static); @@ -764,6 +764,43 @@ 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. @@ -773,6 +810,7 @@ void output_image() char buf[SIZ]; char *xferbuf = NULL; off_t bytes; + int MimeIndex = 0; serv_printf("OIMG %s|%s", bstr("name"), bstr("parm")); serv_getln(buf, sizeof buf); @@ -785,22 +823,37 @@ 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 ++; + } + /** Write it to the browser */ - http_transmit_thing(xferbuf, (size_t)bytes, "image/gif", 0); + if (MyMimes[MimeIndex].PatternLen != 0) + { + http_transmit_thing(xferbuf, + (size_t)bytes, + MyMimes[MimeIndex].MimeString, + 0); + free(xferbuf); + return; + } + /* hm... unknown mimetype? fallback to blank gif */ free(xferbuf); + } - } else { - /** - * 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); - } - - - + + /** + * 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); } /**