httpd-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Rob Hartill <r...@imdb.com>
Subject Re: This patch adds charset= handling for .var files (1.0.5)
Date Sat, 27 Apr 1996 17:58:35 GMT

thanks, we'll take a look at your changes.

regards,
rob

>--ELM830626757-7960-0_
>Content-Type: text/plain; charset=US-ASCII
>Content-Transfer-Encoding: 7bit
>
>Choosing right document charset according to client Accept-Charset
>header field is very actual problem for countries with several
>active code tables (like Russian or Japan). .var files is perfect
>place to handle such cases, so I add needed functionality.
>This patch conforms draft-ietf-http-v11-spec-02 for Accept-Charset
>syntax and draft-holtman-http-negotiation-00 for qc= parameter.
>Please apply it or at least tell me any problems you find here.
>Thanx in advance.
>
>-- 
>Andrey A. Chernov        : And I rest so composedly,  /Now, in my bed,
>ache@astral.msk.su       : That any beholder  /Might fancy me dead -
>http://dt.demos.su/~ache : Might start at beholding me,  /Thinking me dead.
>RELCOM Team,FreeBSD Team :         E.A.Poe         From "For Annie" 1849
>
*** src/mod_negotiation.c.orig	Sat Feb 17 11:32:09 1996
--- src/mod_negotiation.c	Sat Apr 27 20:32:54 1996
***************
*** 139,145 ****
--- 139,147 ----
  
  typedef struct accept_rec {
      char *type_name;
+     char *charset;
      float quality;
+     float qc;
      float max_bytes;
      float level;
  } accept_rec;
***************
*** 168,175 ****
--- 170,179 ----
      char *file_name;
      char *content_encoding;
      char *content_language;
+     char *charset;
      float level;		/* Auxiliary to content-type... */
      float qs;
+     float qc;
      float bytes;
      int lang_index;
      int is_pseudo_html;		/* text/html, *or* the INCLUDES_MAGIC_TYPEs */
***************
*** 194,199 ****
--- 198,204 ----
      array_header *accepts;	/* accept_recs */
      array_header *accept_encodings;	/* accept_recs */
      array_header *accept_langs;	/* accept_recs */
+     array_header *accept_charsets; /* accept_recs */
      array_header *avail_vars;	/* available variants */
  } negotiation_state;
  
***************
*** 208,218 ****
--- 213,225 ----
      mime_info->file_name = "";
      mime_info->content_encoding = "";
      mime_info->content_language = "";
+     mime_info->charset = "";
  
      mime_info->is_pseudo_html = 0.0;
      mime_info->level = 0.0;
      mime_info->level_matched = 0.0;
      mime_info->qs = 0.0;
+     mime_info->qc = 0.0;
      mime_info->quality = 0.0;
      mime_info->bytes = 0;
      mime_info->lang_index = -1;
***************
*** 225,231 ****
--- 232,240 ----
  void set_mime_fields (var_rec *var, accept_rec *mime_info)
  {
      var->type_name = mime_info->type_name;
+     var->charset = mime_info->charset;
      var->qs = mime_info->quality;
+     var->qc = mime_info->qc;
      var->quality = mime_info->quality; /* Initial quality is just qs */
      var->level = mime_info->level;
  
***************
*** 295,301 ****
--- 304,312 ----
  char *get_entry (pool *p, accept_rec *result, char *accept_line)
  {
      result->quality = 1.0;
+     result->qc = 1.0;
      result->max_bytes = 0.0;
+     result->charset = "";
      result->level = 0.0;
      
      /* Note that this handles what I gather is the "old format",
***************
*** 351,361 ****
--- 362,382 ----
  	if (parm[0] == 'q'
  	    && (parm[1] == '\0' || (parm[1] == 's' && parm[2] == '\0')))
  	    result->quality = atof(cp);
+ 	else if (parm[0] == 'q' && parm[1] == 'c' && parm[2] == '\0')
+ 	    result->qc = atof(cp);
  	else if (parm[0] == 'm' && parm[1] == 'x' &&
  		 parm[2] == 'b' && parm[3] == '\0')
  	    result->max_bytes = atof(cp);
  	else if (parm[0] == 'l' && !strcmp (&parm[1], "evel"))
  	    result->level = atof(cp);
+ 	else if (parm[0] == 'c' && !strcmp (&parm[1], "harset")) {
+ 	    result->charset = cp;
+ 	    if ((cp = strchr (result->charset, '\n')) != NULL)
+ 		*cp = '\0';
+ 	    if ((cp = strrchr (result->charset, '"')) != NULL)
+ 		*cp = '\0';
+ 	    str_tolower (result->charset);
+ 	}
      }
  
      if (*accept_line == ',') ++accept_line;
***************
*** 403,408 ****
--- 424,431 ----
        do_header_line (r->pool, table_get (hdrs, "Accept-encoding"));
      new->accept_langs =
        do_header_line (r->pool, table_get (hdrs, "Accept-language"));
+     new->accept_charsets =
+       do_header_line (r->pool, table_get (hdrs, "Accept-charset"));
      new->avail_vars = make_array (r->pool, 40, sizeof (var_rec));
  
      return new;
***************
*** 421,428 ****
--- 444,453 ----
    
      new_accept->type_name = CGI_MAGIC_TYPE;
      new_accept->quality = prefer_scripts ? 1e-20 : 1e20;
+     new_accept->qc = 1.0;
      new_accept->level = 0.0;
      new_accept->max_bytes = 0.0;
+     new_accept->charset = "";
  
      if (neg->accepts->nelts > 1) return;
      
***************
*** 430,437 ****
--- 455,464 ----
      
      new_accept->type_name = "*/*";
      new_accept->quality = 1.0;
+     new_accept->qc = 1.0;
      new_accept->level = 0.0;
      new_accept->max_bytes = 0.0;
+     new_accept->charset = "";
  }
  
  /*****************************************************************
***************
*** 735,740 ****
--- 762,794 ----
      return OK;
  }
  
+ float charset_quality (negotiation_state *neg, var_rec *avail)
+ {
+     accept_rec *accs;
+     char *charset;
+     int i;
+ 
+     /* If no Accept-Charset is present, everything is acceptable */
+ 
+     if (!neg->accept_charsets->nelts)
+ 	return 1.0;
+ 
+     charset = avail->charset;
+     if (!*charset)
+ 	charset = "iso-8859-1"; /* default */
+ 
+     accs = (accept_rec *)neg->accept_charsets->elts;
+ 
+     for (i = 0; i < neg->accept_charsets->nelts; ++i)
+ 	if (!strcmp (charset, accs[i].type_name))
+ 	    return accs[i].quality;
+ 
+     if (!strcmp (charset, "iso-8859-1"))
+ 	return 1.0;
+ 	    
+     return 0.0;
+ }
+ 
  /* This code implements a piece of the tie-breaking algorithm between
   * variants of equal quality.  This piece is the treatment of variants
   * of the same base media type, but different levels.  What we want to
***************
*** 966,977 ****
  	for (j = 0; j < neg->avail_vars->nelts; ++j) {
  	    
  	    var_rec *variant = &avail_recs[j];
! 	    float q = type->quality * variant->quality;
  		
  	    /* If we've already rejected this variant, don't waste time */
  	    
  	    if (q == 0.0) continue;	
  	    
  	    /* If media types don't match, forget it.
  	     * (This includes the level check).
  	     */
--- 1020,1035 ----
  	for (j = 0; j < neg->avail_vars->nelts; ++j) {
  	    
  	    var_rec *variant = &avail_recs[j];
! 	    float q = type->quality * variant->quality * variant->qc;
  		
  	    /* If we've already rejected this variant, don't waste time */
  	    
  	    if (q == 0.0) continue;	
  	    
+ 	    q *= charset_quality(neg, variant);
+ 
+ 	    if (q == 0.0) continue;	
+ 
  	    /* If media types don't match, forget it.
  	     * (This includes the level check).
  	     */


Mime
View raw message