You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@httpd.apache.org by Paul Sutton <pa...@c2.net> on 1998/11/23 10:38:46 UTC

[PATCH] adding a DefaultLanguage directive

On 20 Nov 1998, Rainer Scherg wrote:
> >Number:         3430
> >Synopsis:       Enhancement: MultiViews, Multi-Language Documents
> [...]
>  The Enhancement Request (Proposal):
>  -----------------------------------
> 
>  1. Config-directive for standard language, handling
>     the language for e.g. "test.htm".
> 
>       >> LanguageDefault       en          #  (test.htm = Lang. en)
> 
>     [Right now, apache sometimes return wrong (lang.) docs.]
>     [see also: PR#1180]

PR#1180 and PR#3430 both request a way to specify a default language for
documents which don't have an explicit language extension. This is
useful for sites moving to multiviews/language negotiation which will
typically already have a lot of resources in a common language, and do not
want to rename every file.

This patch implements a DefaultLanguage directive. It sets the language to
apply to files with no explicit language set via AddLanguage. Typical use
would be to set HTML files as English with:

  <Files *.html>
  DefaultLanguage en
  </Files>

Paul

Index: mod_mime.c
===================================================================
RCS file: /export/home/cvs/apache-1.3/src/modules/standard/mod_mime.c,v
retrieving revision 1.45
diff -u -r1.45 mod_mime.c
--- mod_mime.c	1998/10/23 19:28:53	1.45
+++ mod_mime.c	1998/11/23 09:24:50
@@ -81,6 +81,7 @@
 
     char *type;                 /* Type forced with ForceType  */
     char *handler;              /* Handler forced with SetHandler */
+    char *default_language;     /* Language if no AddLanguage ext found */
 } mime_dir_config;
 
 module MODULE_VAR_EXPORT mime_module;
@@ -98,6 +99,7 @@
 
     new->type = NULL;
     new->handler = NULL;
+    new->default_language = NULL;
 
     return new;
 }
@@ -107,13 +109,13 @@
     mime_dir_config *base = (mime_dir_config *) basev;
     mime_dir_config *add = (mime_dir_config *) addv;
     mime_dir_config *new =
-	(mime_dir_config *) ap_palloc(p, sizeof(mime_dir_config));
+        (mime_dir_config *) ap_palloc(p, sizeof(mime_dir_config));
     int i;
     handlers_info *hand;
 
     hand = (handlers_info *) add->handlers_remove->elts;
     for (i = 0; i < add->handlers_remove->nelts; i++) {
-	ap_table_unset(base->handlers, hand[i].name);
+        ap_table_unset(base->handlers, hand[i].name);
     }
 
     new->forced_types = ap_overlay_tables(p, add->forced_types,
@@ -127,6 +129,8 @@
 
     new->type = add->type ? add->type : base->type;
     new->handler = add->handler ? add->handler : base->handler;
+    new->default_language = add->default_language ? 
+        add->default_language : base->default_language;
 
     return new;
 }
@@ -182,7 +186,7 @@
     handlers_info *hand;
 
     if (*ext == '.') {
-	++ext;
+        ++ext;
     }
     hand = (handlers_info *) ap_push_array(mcfg->handlers_remove);
     hand->name = ap_pstrdup(cmd->pool, ext);
@@ -219,6 +223,9 @@
      "a handler name"},
     {"TypesConfig", set_types_config, NULL, RSRC_CONF, TAKE1,
      "the MIME types config file"},
+    {"DefaultLanguage", ap_set_string_slot, 
+     (void*)XtOffsetOf(mime_dir_config, default_language), OR_FILEINFO, TAKE1,
+     "language to use for documents with no other language file extension" },
     {NULL}
 };
 
@@ -250,7 +257,7 @@
 
     if (!(f = ap_pcfg_openfile(p, types_confname))) {
         ap_log_error(APLOG_MARK, APLOG_ERR, s,
-		     "httpd: could not open mime types log file %s.", types_confname);
+                     "httpd: could not open mime types log file %s.", types_confname);
         exit(1);
     }
 
@@ -347,6 +354,20 @@
             r->handler = orighandler;
         }
 
+    }
+
+    /* Set default language, if none was specified by the extensions
+     * and we have a DefaultLanguage setting in force
+     */
+
+    if (!r->content_languages && conf->default_language) {
+        const char **new;
+
+        r->content_language = conf->default_language; /* back compat. only */
+        if (!r->content_languages)
+            r->content_languages = ap_make_array(r->pool, 2, sizeof(char *));
+        new = (const char **) ap_push_array(r->content_languages);
+        *new = conf->default_language;
     }
 
     /* Check for overrides with ForceType/SetHandler */


Re: [PATCH] adding a DefaultLanguage directive

Posted by Rodent of Unusual Size <Ke...@Golux.Com>.
Paul Sutton wrote:
> 
> This patch implements a DefaultLanguage directive. It sets the language to
> apply to files with no explicit language set via AddLanguage. Typical use
> would be to set HTML files as English with:

+1 (tested).
-- 
#ken	P-)}

Ken Coar                    <http://Web.Golux.Com/coar/>
Apache Group member         <http://www.apache.org/>
"Apache Server for Dummies" <http://Web.Golux.Com/coar/ASFD/>

Re: [PATCH] adding a DefaultLanguage directive

Posted by Dirk-Willem van Gulik <di...@jrc.it>.

On Mon, 23 Nov 1998, Paul Sutton wrote:

> On 20 Nov 1998, Rainer Scherg wrote:
> > >Number:         3430
> > >Synopsis:       Enhancement: MultiViews, Multi-Language Documents
> > [...]
> >  The Enhancement Request (Proposal):
> >  -----------------------------------
> > 
> >  1. Config-directive for standard language, handling
> >     the language for e.g. "test.htm".
> > 
> >       >> LanguageDefault       en          #  (test.htm = Lang. en)
> > 
> >     [Right now, apache sometimes return wrong (lang.) docs.]
> >     [see also: PR#1180]
> 
> PR#1180 and PR#3430 both request a way to specify a default language for
> documents which don't have an explicit language extension. This is
> useful for sites moving to multiviews/language negotiation which will
> typically already have a lot of resources in a common language, and do not
> want to rename every file.

Although another way to do this is of course (if you only want the
labeling) to just add Charset=xx;Language=xx to the right line in
the mime file.
 
> This patch implements a DefaultLanguage directive. It sets the language to
> apply to files with no explicit language set via AddLanguage. Typical use
> would be to set HTML files as English with:

Hmm.. yet another reason to rewrite mod_negotiation; as this is again a
bit too subtle to do it dynamic.

Perhaps a marker in the docs that the user is encouraged NOT to mix this
with dynamic language or content-type negotiation might be in order.

Dw
 
>   <Files *.html>
>   DefaultLanguage en
>   </Files>
> 
> Paul
> 
> Index: mod_mime.c
> ===================================================================
> RCS file: /export/home/cvs/apache-1.3/src/modules/standard/mod_mime.c,v
> retrieving revision 1.45
> diff -u -r1.45 mod_mime.c
> --- mod_mime.c	1998/10/23 19:28:53	1.45
> +++ mod_mime.c	1998/11/23 09:24:50
> @@ -81,6 +81,7 @@
>  
>      char *type;                 /* Type forced with ForceType  */
>      char *handler;              /* Handler forced with SetHandler */
> +    char *default_language;     /* Language if no AddLanguage ext found */
>  } mime_dir_config;
>  
>  module MODULE_VAR_EXPORT mime_module;
> @@ -98,6 +99,7 @@
>  
>      new->type = NULL;
>      new->handler = NULL;
> +    new->default_language = NULL;
>  
>      return new;
>  }
> @@ -107,13 +109,13 @@
>      mime_dir_config *base = (mime_dir_config *) basev;
>      mime_dir_config *add = (mime_dir_config *) addv;
>      mime_dir_config *new =
> -	(mime_dir_config *) ap_palloc(p, sizeof(mime_dir_config));
> +        (mime_dir_config *) ap_palloc(p, sizeof(mime_dir_config));
>      int i;
>      handlers_info *hand;
>  
>      hand = (handlers_info *) add->handlers_remove->elts;
>      for (i = 0; i < add->handlers_remove->nelts; i++) {
> -	ap_table_unset(base->handlers, hand[i].name);
> +        ap_table_unset(base->handlers, hand[i].name);
>      }
>  
>      new->forced_types = ap_overlay_tables(p, add->forced_types,
> @@ -127,6 +129,8 @@
>  
>      new->type = add->type ? add->type : base->type;
>      new->handler = add->handler ? add->handler : base->handler;
> +    new->default_language = add->default_language ? 
> +        add->default_language : base->default_language;
>  
>      return new;
>  }
> @@ -182,7 +186,7 @@
>      handlers_info *hand;
>  
>      if (*ext == '.') {
> -	++ext;
> +        ++ext;
>      }
>      hand = (handlers_info *) ap_push_array(mcfg->handlers_remove);
>      hand->name = ap_pstrdup(cmd->pool, ext);
> @@ -219,6 +223,9 @@
>       "a handler name"},
>      {"TypesConfig", set_types_config, NULL, RSRC_CONF, TAKE1,
>       "the MIME types config file"},
> +    {"DefaultLanguage", ap_set_string_slot, 
> +     (void*)XtOffsetOf(mime_dir_config, default_language), OR_FILEINFO, TAKE1,
> +     "language to use for documents with no other language file extension" },
>      {NULL}
>  };
>  
> @@ -250,7 +257,7 @@
>  
>      if (!(f = ap_pcfg_openfile(p, types_confname))) {
>          ap_log_error(APLOG_MARK, APLOG_ERR, s,
> -		     "httpd: could not open mime types log file %s.", types_confname);
> +                     "httpd: could not open mime types log file %s.", types_confname);
>          exit(1);
>      }
>  
> @@ -347,6 +354,20 @@
>              r->handler = orighandler;
>          }
>  
> +    }
> +
> +    /* Set default language, if none was specified by the extensions
> +     * and we have a DefaultLanguage setting in force
> +     */
> +
> +    if (!r->content_languages && conf->default_language) {
> +        const char **new;
> +
> +        r->content_language = conf->default_language; /* back compat. only */
> +        if (!r->content_languages)
> +            r->content_languages = ap_make_array(r->pool, 2, sizeof(char *));
> +        new = (const char **) ap_push_array(r->content_languages);
> +        *new = conf->default_language;
>      }
>  
>      /* Check for overrides with ForceType/SetHandler */
> 
> 


Re: [PATCH] adding a DefaultLanguage directive

Posted by Dirk-Willem van Gulik <di...@jrc.it>.
On Mon, 23 Nov 1998, Paul Sutton wrote:

Actually Paul, you do realize that if one combines this patch
with DefaultLanguage setting in the srm.conf file (and some
message during install/compile) to make sure people set it
right! that this could be the first GOOD thing ever done since
netscape broke Accept with their */*.

Dw

> On 20 Nov 1998, Rainer Scherg wrote:
> > >Number:         3430
> > >Synopsis:       Enhancement: MultiViews, Multi-Language Documents
> > [...]
> >  The Enhancement Request (Proposal):
> >  -----------------------------------
> > 
> >  1. Config-directive for standard language, handling
> >     the language for e.g. "test.htm".
> > 
> >       >> LanguageDefault       en          #  (test.htm = Lang. en)
> > 
> >     [Right now, apache sometimes return wrong (lang.) docs.]
> >     [see also: PR#1180]
> 
> PR#1180 and PR#3430 both request a way to specify a default language for
> documents which don't have an explicit language extension. This is
> useful for sites moving to multiviews/language negotiation which will
> typically already have a lot of resources in a common language, and do not
> want to rename every file.
> 
> This patch implements a DefaultLanguage directive. It sets the language to
> apply to files with no explicit language set via AddLanguage. Typical use
> would be to set HTML files as English with:
> 
>   <Files *.html>
>   DefaultLanguage en
>   </Files>
> 
> Paul
> 
> Index: mod_mime.c
> ===================================================================
> RCS file: /export/home/cvs/apache-1.3/src/modules/standard/mod_mime.c,v
> retrieving revision 1.45
> diff -u -r1.45 mod_mime.c
> --- mod_mime.c	1998/10/23 19:28:53	1.45
> +++ mod_mime.c	1998/11/23 09:24:50
> @@ -81,6 +81,7 @@
>  
>      char *type;                 /* Type forced with ForceType  */
>      char *handler;              /* Handler forced with SetHandler */
> +    char *default_language;     /* Language if no AddLanguage ext found */
>  } mime_dir_config;
>  
>  module MODULE_VAR_EXPORT mime_module;
> @@ -98,6 +99,7 @@
>  
>      new->type = NULL;
>      new->handler = NULL;
> +    new->default_language = NULL;
>  
>      return new;
>  }
> @@ -107,13 +109,13 @@
>      mime_dir_config *base = (mime_dir_config *) basev;
>      mime_dir_config *add = (mime_dir_config *) addv;
>      mime_dir_config *new =
> -	(mime_dir_config *) ap_palloc(p, sizeof(mime_dir_config));
> +        (mime_dir_config *) ap_palloc(p, sizeof(mime_dir_config));
>      int i;
>      handlers_info *hand;
>  
>      hand = (handlers_info *) add->handlers_remove->elts;
>      for (i = 0; i < add->handlers_remove->nelts; i++) {
> -	ap_table_unset(base->handlers, hand[i].name);
> +        ap_table_unset(base->handlers, hand[i].name);
>      }
>  
>      new->forced_types = ap_overlay_tables(p, add->forced_types,
> @@ -127,6 +129,8 @@
>  
>      new->type = add->type ? add->type : base->type;
>      new->handler = add->handler ? add->handler : base->handler;
> +    new->default_language = add->default_language ? 
> +        add->default_language : base->default_language;
>  
>      return new;
>  }
> @@ -182,7 +186,7 @@
>      handlers_info *hand;
>  
>      if (*ext == '.') {
> -	++ext;
> +        ++ext;
>      }
>      hand = (handlers_info *) ap_push_array(mcfg->handlers_remove);
>      hand->name = ap_pstrdup(cmd->pool, ext);
> @@ -219,6 +223,9 @@
>       "a handler name"},
>      {"TypesConfig", set_types_config, NULL, RSRC_CONF, TAKE1,
>       "the MIME types config file"},
> +    {"DefaultLanguage", ap_set_string_slot, 
> +     (void*)XtOffsetOf(mime_dir_config, default_language), OR_FILEINFO, TAKE1,
> +     "language to use for documents with no other language file extension" },
>      {NULL}
>  };
>  
> @@ -250,7 +257,7 @@
>  
>      if (!(f = ap_pcfg_openfile(p, types_confname))) {
>          ap_log_error(APLOG_MARK, APLOG_ERR, s,
> -		     "httpd: could not open mime types log file %s.", types_confname);
> +                     "httpd: could not open mime types log file %s.", types_confname);
>          exit(1);
>      }
>  
> @@ -347,6 +354,20 @@
>              r->handler = orighandler;
>          }
>  
> +    }
> +
> +    /* Set default language, if none was specified by the extensions
> +     * and we have a DefaultLanguage setting in force
> +     */
> +
> +    if (!r->content_languages && conf->default_language) {
> +        const char **new;
> +
> +        r->content_language = conf->default_language; /* back compat. only */
> +        if (!r->content_languages)
> +            r->content_languages = ap_make_array(r->pool, 2, sizeof(char *));
> +        new = (const char **) ap_push_array(r->content_languages);
> +        *new = conf->default_language;
>      }
>  
>      /* Check for overrides with ForceType/SetHandler */
> 
>