* tiny 'file'-extract, now we can detect the type of an image. and set the mimetype...
authorWilfried Göesgens <willi@citadel.org>
Fri, 8 Feb 2008 19:31:42 +0000 (19:31 +0000)
committerWilfried Göesgens <willi@citadel.org>
Fri, 8 Feb 2008 19:31:42 +0000 (19:31 +0000)
* First bits to fallback to serverwinde gettext if we don't have uselocale on that system.

webcit/configure.ac
webcit/debian/rules
webcit/gettext.c
webcit/webcit.c
webcit/webcit.h
webcit/webserver.c

index cd036cf3766a91458838bd6cd3c9155aab4ab3f6..a10a0d9aa98688e1b2f6f1e109769cf85e5bf8cd 100644 (file)
@@ -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],
index 15846013d6c2529885dc65147d7c4ae4c70d29cb..ca73ada2140c5c4a066ef8fca739ddf51168bcdb 100755 (executable)
@@ -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
index 4526bfcdfb7533eee8f729332f7aac850fda6905..37ef96545f418cc51afd6586be8f63aa2476f826 100644 (file)
@@ -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 */
 
 
index 71b780a76a4c3d6b7d78f9bb5c43c597846c1967..67ed35c212eb393005d22acbbead1c5f376c4bfe 100644 (file)
@@ -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);
 }
 
 /**
index 099684d78d2987500eab9d892b46849c10d30bea..7ca1fac8718af549c25095e007f18d3489d515ca 100644 (file)
@@ -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);
index 626922a251d98b936b95ae0abf08788a0d7e9717..c5f30c2ad7c0e4122e9ffec14b26195cf0d29e0e 100644 (file)
@@ -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