From d1ff575b169bf1028c9b36bd535b467f00ee2c6a Mon Sep 17 00:00:00 2001 From: =?utf8?q?Wilfried=20G=C3=B6esgens?= Date: Fri, 8 Feb 2008 19:31:42 +0000 Subject: [PATCH] * tiny 'file'-extract, now we can detect the type of an image. and set the mimetype apropriate. * First bits to fallback to serverwinde gettext if we don't have uselocale on that system. --- webcit/configure.ac | 1 + webcit/debian/rules | 2 +- webcit/gettext.c | 19 ++++++++++- webcit/webcit.c | 81 +++++++++++++++++++++++++++++++++++++-------- webcit/webcit.h | 3 +- webcit/webserver.c | 1 + 6 files changed, 90 insertions(+), 17 deletions(-) diff --git a/webcit/configure.ac b/webcit/configure.ac index cd036cf37..a10a0d9aa 100644 --- a/webcit/configure.ac +++ b/webcit/configure.ac @@ -350,6 +350,7 @@ fi dnl Here is the check for libintl etc. +AC_CHECK_FUNCS(strftime_l uselocale gettext) AC_ARG_ENABLE(nls, [ --disable-nls do not use Native Language Support], diff --git a/webcit/debian/rules b/webcit/debian/rules index 15846013d..ca73ada21 100755 --- a/webcit/debian/rules +++ b/webcit/debian/rules @@ -18,7 +18,7 @@ ifneq (,$(findstring profiling,$(DEB_BUILD_OPTIONS))) PROFILE_ARGS= --with-gprof endif ifneq (,$(findstring debug,$(DEB_BUILD_OPTIONS))) - CFLAGS += -O0 -ggdb -rdynamic -MD -MP + CFLAGS += -O0 -ggdb -rdynamic -MD -MP -D TECH_PREVIEW LDFLAGS += -pg EXTRA_ARGS = --with-backtrace else diff --git a/webcit/gettext.c b/webcit/gettext.c index 4526bfcdf..37ef96545 100644 --- a/webcit/gettext.c +++ b/webcit/gettext.c @@ -226,20 +226,34 @@ void set_selected_language(char *lang) { * \brief Activate the selected language for this session. */ void go_selected_language(void) { +#ifdef HAVE_USELOCALE if (WC->selected_language < 0) return; uselocale(wc_locales[WC->selected_language]); /** switch locales */ textdomain(textdomain(NULL)); /** clear the cache */ +#endif } /** * \brief Deactivate the selected language for this session. */ void stop_selected_language(void) { +#ifdef HAVE_USELOCALE uselocale(LC_GLOBAL_LOCALE); /** switch locales */ textdomain(textdomain(NULL)); /** clear the cache */ +#endif } - +void preset_locale(void) +{ +#ifndef HAVE_USELOCALE +#ifdef HAVE_GETTEXT + char *language; + + language = getenv("LANG"); + setlocale(LC_MESSAGES, language); +#endif +#endif +} /** * \brief Create a locale_t for each available language */ @@ -294,6 +308,9 @@ void go_selected_language(void) { void stop_selected_language(void) { } +void preset_locale(void) +{ +} #endif /* ENABLE_NLS */ 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); } /** diff --git a/webcit/webcit.h b/webcit/webcit.h index 099684d78..7ca1fac87 100644 --- a/webcit/webcit.h +++ b/webcit/webcit.h @@ -726,7 +726,7 @@ char *read_server_text(void); int goto_config_room(void); long locate_user_vcard(char *username, long usernum); void sleeeeeeeeeep(int); -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); void unescape_input(char *buf); void do_iconbar(void); @@ -742,6 +742,7 @@ void offer_languages(void); void set_selected_language(char *); void go_selected_language(void); void stop_selected_language(void); +void preset_locale(void); void httplang_to_locale(char *LocaleString); void tabbed_dialog(int num_tabs, char *tabnames[]); void begin_tab(int tabnum, int num_tabs); diff --git a/webcit/webserver.c b/webcit/webserver.c index 626922a25..c5f30c2ad 100644 --- a/webcit/webserver.c +++ b/webcit/webserver.c @@ -806,6 +806,7 @@ int main(int argc, char **argv) free(mo); lprintf(9, "Text domain: %s\n", textdomain("webcit")); lprintf(9, "Text domain Charset: %s\n", bind_textdomain_codeset("webcit","UTF8")); + preset_locale(); #endif -- 2.30.2