httpd-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From guill...@clipper.ens.fr (Florent Guillaume)
Subject Re: Patches to handle content-language
Date Mon, 17 Jul 1995 23:10:33 GMT
>[rst]
> BTW, I'm running with Florent's language negotiation code, so I think
> it works; this is also a much-requested feature, so it would be nice
> to have it in the release.  My only problem with it is that it sets
> the priority for languages by the order of AddLanguage directives in
> the config files --- I'd prefer an explicit LanguagePriority directive
> for two reasons.
> 
> First off, [... should be an explicit priority, ordering is clearer ...]
> Secondly, [... not modular ...]
> 
> Otherwise, as I said, the code seems to work fine, and though it comes
> in a bit late, if this problem is solved, then I at least would be
> happy to have it.


You're right, the code I gave you was ugly, I was a bit ashamed to call
a module from another module.  But it was a first test, anyway.

Okay, here's a new patch (over 0.8.1) that does it cleanly.  There's a
new per-directory config directive, LanguagePriority, that lists the
languages (and not the suffixes) in decreasing priority of preference.
A directive in .htaccess is treated as if it was _before_ the
directory-wide config, because it has to be able to override it.
(My description of AddLanguage in the first version still applies.)


[I just received Brian's comments, I'll send a seperate mail about them.]

	Florent


Index: src/http_config.h
*** apache_0.8.1.orig/src/http_config.h	Mon Jun 26 00:42:14 1995
--- apache_0.8.1/src/http_config.h	Mon Jul 17 22:39:34 1995
***************
*** 176,182 ****
       *                  (as a SERVER_ERROR, since the module which was
       *                  supposed to handle this was configured wrong).
       * type_checker --- Determine MIME type of the requested entity;
!      *                  sets content_type and _encoding fields.
       * logger --- log a transaction.  Not supported yet out of sheer
       *            laziness on my part.
       */
--- 176,182 ----
       *                  (as a SERVER_ERROR, since the module which was
       *                  supposed to handle this was configured wrong).
       * type_checker --- Determine MIME type of the requested entity;
!      *                  sets content_type, _encoding and _language fields.
       * logger --- log a transaction.  Not supported yet out of sheer
       *            laziness on my part.
       */
Index: src/http_protocol.c
*** apache_0.8.1.orig/src/http_protocol.c	Thu Jul 13 02:28:05 1995
--- apache_0.8.1/src/http_protocol.c	Mon Jul 17 22:39:35 1995
***************
*** 499,504 ****
--- 499,507 ----
      if (r->content_encoding)
          fprintf (fd, "Content-encoding: %s\015\012", r->content_encoding);
      
+     if (r->content_language)
+         fprintf (fd, "Content-language: %s\015\012", r->content_language);
+     
      for (i = 0; i < hdrs_arr->nelts; ++i) {
          if (!hdrs[i].key) continue;
  	fprintf (fd, "%s: %s\015\012", hdrs[i].key, hdrs[i].val);
Index: src/httpd.h
*** apache_0.8.1.orig/src/httpd.h	Mon Jul 17 15:24:32 1995
--- apache_0.8.1/src/httpd.h	Mon Jul 17 22:39:34 1995
***************
*** 282,287 ****
--- 282,288 ----
  
    char *content_type;		/* Break these out --- we dispatch on 'em */
    char *content_encoding;
+   char *content_language;
    
    int no_cache;
    
Index: src/mod_mime.c
*** apache_0.8.1.orig/src/mod_mime.c	Fri Jun 30 13:54:26 1995
--- apache_0.8.1/src/mod_mime.c	Mon Jul 17 23:16:03 1995
***************
*** 69,74 ****
--- 69,75 ----
  typedef struct {
      table *forced_types;	/* Additional AddTyped stuff */
      table *encoding_types;	/* Added with AddEncoding... */
+     table *language_types;	/* Added with AddLanguage... */
  } mime_dir_config;
  
  module mime_module;
***************
*** 80,85 ****
--- 81,87 ----
  
      new->forced_types = make_table (p, 4);
      new->encoding_types = make_table (p, 4);
+     new->language_types = make_table (p, 4);
      
      return new;
  }
***************
*** 95,100 ****
--- 97,104 ----
  					base->forced_types);
      new->encoding_types = overlay_tables (p, add->encoding_types,
  					  base->encoding_types);
+     new->language_types = overlay_tables (p, add->language_types,
+ 					  base->language_types);
  
      return new;
  }
***************
*** 113,118 ****
--- 117,129 ----
      return NULL;
  }
  
+ char *add_language(cmd_parms *cmd, mime_dir_config *m, char *lang, char *ext)
+ {
+     if (*ext == '.') ++ext;
+     table_set (m->language_types, ext, lang);
+     return NULL;
+ }
+ 
  /* The sole bit of server configuration that the MIME module has is
   * the name of its config file, so...
   */
***************
*** 129,134 ****
--- 140,147 ----
      "a mime type followed by a file extension" },
  { "AddEncoding", add_encoding, NULL, OR_FILEINFO, TAKE2, 
      "an encoding (e.g., gzip), followed by a file extension" },
+ { "AddLanguage", add_language, NULL, OR_FILEINFO, TAKE2, 
+     "a language (e.g., fr), followed by a file extension" },
  { "TypesConfig", set_types_config, NULL, RSRC_CONF, TAKE1,
      "the MIME types config file" },
  { NULL }
***************
*** 198,203 ****
--- 211,227 ----
      if ((type = table_get (conf->encoding_types, &fn[i])))
      {
          r->content_encoding = type;
+ 
+ 	/* go back to previous extension to try to use it as a language */
+ 	
+         fn[i-1] = '\0';
+ 	if((i=rind(fn,'.')) < 0) return OK;
+ 	++i;
+     }
+ 
+     if ((type = table_get (conf->language_types, &fn[i])))
+     {
+         r->content_language = type;
  
  	/* go back to previous extension to try to use it as a type */
  	
Index: src/mod_negotiation.c
*** apache_0.8.1.orig/src/mod_negotiation.c	Sat Jul  1 19:46:05 1995
--- apache_0.8.1/src/mod_negotiation.c	Tue Jul 18 00:22:28 1995
***************
*** 71,78 ****
--- 71,113 ----
   * server basis...
   */
  
+ typedef struct {
+     array_header *language_priority;
+ } neg_dir_config;
+ 
  module negotiation_module;
  
+ void *create_neg_dir_config (pool *p, char *dummy)
+ {
+     neg_dir_config *new =
+       (neg_dir_config *) palloc (p, sizeof (neg_dir_config));
+ 
+     new->language_priority = make_array (p, 4, sizeof (char *));
+     return new;
+ }
+ 
+ void *merge_neg_dir_configs (pool *p, void *basev, void *addv)
+ {
+     neg_dir_config *base = (neg_dir_config *)basev;
+     neg_dir_config *add = (neg_dir_config *)addv;
+     neg_dir_config *new =
+       (neg_dir_config *) palloc (p, sizeof (neg_dir_config));
+ 
+     /* give priority to the config in the subdirectory */
+     new->language_priority = append_arrays (p, add->language_priority,
+ 					    base->language_priority);
+     return new;
+ }
+ 
+ char *set_language_priority (cmd_parms *cmd, void *n, char *lang)
+ {
+     array_header *arr = ((neg_dir_config *) n)->language_priority;
+     char **langp = (char **) push_array (arr);
+ 
+     *langp = pstrdup (arr->pool, lang);
+     return NULL;
+ }
+ 
  char *cache_negotiated_docs (cmd_parms *cmd, void *dummy, char *dummy2)
  {
      void *server_conf = cmd->server->module_config;
***************
*** 89,94 ****
--- 124,131 ----
  command_rec negotiation_cmds[] = {
  { "CacheNegotiatedDocs", cache_negotiated_docs, NULL, RSRC_CONF, RAW_ARGS,
      NULL },
+ { "LanguagePriority", set_language_priority, NULL, OR_FILEINFO, ITERATE,
+     NULL },
  { NULL }
  };
  
***************
*** 132,138 ****
      char *type_name;
      char *file_name;
      char *content_encoding;
!     char *lang;
      float level;		/* Auxiliary to content-type... */
      float qs;
      float bytes;
--- 169,175 ----
      char *type_name;
      char *file_name;
      char *content_encoding;
!     char *content_language;
      float level;		/* Auxiliary to content-type... */
      float qs;
      float bytes;
***************
*** 172,178 ****
      mime_info->type_name = "";
      mime_info->file_name = "";
      mime_info->content_encoding = "";
!     mime_info->lang = "";
  
      mime_info->is_pseudo_html = 0.0;
      mime_info->level = 0.0;
--- 209,215 ----
      mime_info->type_name = "";
      mime_info->file_name = "";
      mime_info->content_encoding = "";
!     mime_info->content_language = "";
  
      mime_info->is_pseudo_html = 0.0;
      mime_info->level = 0.0;
***************
*** 560,567 ****
  		mime_info.bytes = atoi(body);
  	    }
  	    else if (!strncmp (buffer, "content-language:", 17)) {
! 		mime_info.lang = get_token (neg->pool, &body, 0);
! 		str_tolower (mime_info.lang);
  	    }
  	    else if (!strncmp (buffer, "content-encoding:", 17)) {
  		mime_info.content_encoding = get_token (neg->pool, &body, 0);
--- 597,604 ----
  		mime_info.bytes = atoi(body);
  	    }
  	    else if (!strncmp (buffer, "content-language:", 17)) {
! 		mime_info.content_language = get_token (neg->pool, &body, 0);
! 		str_tolower (mime_info.content_language);
  	    }
  	    else if (!strncmp (buffer, "content-encoding:", 17)) {
  		mime_info.content_encoding = get_token (neg->pool, &body, 0);
***************
*** 589,597 ****
  int read_types_multi (negotiation_state *neg)
  {
      request_rec *r = neg->r;
-     char *file_name = pstrdup (r->pool, r->filename);
      
!     char *filp = &file_name[strlen(file_name) - 1];
      int prefix_len;
      DIR *dirp;
      struct DIR_TYPE *dir_entry;
--- 626,633 ----
  int read_types_multi (negotiation_state *neg)
  {
      request_rec *r = neg->r;
      
!     char *filp;
      int prefix_len;
      DIR *dirp;
      struct DIR_TYPE *dir_entry;
***************
*** 648,653 ****
--- 684,690 ----
  	mime_info.sub_req = sub_req;
  	mime_info.file_name = dir_entry->d_name;
  	mime_info.content_encoding = sub_req->content_encoding;
+ 	mime_info.content_language = sub_req->content_language;
  	
  	get_entry (neg->pool, &accept_info, sub_req->content_type);
  	set_mime_fields (&mime_info, &accept_info);
***************
*** 759,767 ****
  
  int find_lang_index (array_header *accept_langs, char *lang)
  {
!     accept_rec *accs = (accept_rec *)accept_langs->elts;
      int i;
  
      for (i = 0; i < accept_langs->nelts; ++i)
  	if (!strncmp (lang, accs[i].type_name, strlen(accs[i].type_name)))
  	    return i;
--- 796,809 ----
  
  int find_lang_index (array_header *accept_langs, char *lang)
  {
!     accept_rec *accs;
      int i;
  
+     if (!lang)
+ 	return -1;
+ 
+     accs = (accept_rec *)accept_langs->elts;
+ 
      for (i = 0; i < accept_langs->nelts; ++i)
  	if (!strncmp (lang, accs[i].type_name, strlen(accs[i].type_name)))
  	    return i;
***************
*** 769,774 ****
--- 811,842 ----
      return -1;		
  }
  
+ /* This function returns the priority of a given language
+  * according to LanguagePriority.  It is used in case of a tie
+  * between several languages.
+  */
+ 
+ int find_default_index (neg_dir_config *conf, char *lang)
+ {
+     array_header *arr;
+     int nelts;
+     char **elts;
+     int i;
+ 
+     if (!lang)
+ 	return -1;
+ 
+     arr = conf->language_priority;
+     nelts = arr->nelts;
+     elts = (char **) arr->elts;
+ 
+     for (i = 0; i < nelts; ++i)
+         if (!strcasecmp (elts[i], lang))
+ 	    return i;
+ 
+     return -1;
+ }
+ 
  void find_lang_indexes (negotiation_state *neg)
  {
      var_rec *var_recs = (var_rec*)neg->avail_vars->elts;
***************
*** 776,793 ****
      int found_any = 0;
  
      if (neg->accept_langs->nelts == 0) {
- 	
- 	/* Client doesn't care */
  
  	for (i = 0; i < neg->avail_vars->nelts; ++i)
! 	    var_recs[i].lang_index = -1;
  
  	return;
      }
      
      for (i = 0; i < neg->avail_vars->nelts; ++i)
  	if (var_recs[i].quality > 0) {
! 	    int index = find_lang_index (neg->accept_langs, var_recs[i].lang);
  
  	    var_recs[i].lang_index = index;
  	    if (index >= 0) found_any = 1;
--- 844,866 ----
      int found_any = 0;
  
      if (neg->accept_langs->nelts == 0) {
  
+ 	/* Client doesn't care : use LanguagePriority order */
+ 
+ 	neg_dir_config *conf =
+ 	    (neg_dir_config *) get_module_config (neg->r->per_dir_config,
+ 						  &negotiation_module);
  	for (i = 0; i < neg->avail_vars->nelts; ++i)
! 	    var_recs[i].lang_index =
! 		find_default_index (conf, var_recs[i].content_language);
  
  	return;
      }
      
      for (i = 0; i < neg->avail_vars->nelts; ++i)
  	if (var_recs[i].quality > 0) {
! 	    int index = find_lang_index (neg->accept_langs,
! 					 var_recs[i].content_language);
  
  	    var_recs[i].lang_index = index;
  	    if (index >= 0) found_any = 1;
***************
*** 1031,1036 ****
--- 1104,1110 ----
      r->filename = sub_req->filename;
      r->content_type = sub_req->content_type;
      r->content_encoding = sub_req->content_encoding;
+     r->content_language = sub_req->content_language;
      r->finfo = sub_req->finfo;
      
      return OK;
***************
*** 1044,1051 ****
  module negotiation_module = {
     STANDARD_MODULE_STUFF,
     NULL,			/* initializer */
!    NULL,			/* dir config creater */
!    NULL,			/* dir merger --- default is to override */
     NULL,			/* server config */
     NULL,			/* merge server config */
     negotiation_cmds,		/* command table */
--- 1118,1125 ----
  module negotiation_module = {
     STANDARD_MODULE_STUFF,
     NULL,			/* initializer */
!    create_neg_dir_config,	/* dir config creater */
!    merge_neg_dir_configs,	/* dir merger --- default is to override */
     NULL,			/* server config */
     NULL,			/* merge server config */
     negotiation_cmds,		/* command table */

-- 
Florent.Guillaume@ens.fr

Mime
View raw message