httpd-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jmil...@mwci.net (Jeremie Miller)
Subject Re: New Module. mod_agent.c
Date Mon, 18 Dec 1995 19:03:40 GMT
>Hi,
>
>	Barry Books <bfb@planet-texas.com> of Planet Texas has given us 
>a copy of a module he's working on which performs content negotiation
>based upon the contents of the User-Agent: header.  I've uploaded
>it to hyperreal's dist/incoming as mod_agent.c

        I just wrote something to that effect, and am testing it right now.
I thought it was more appropriate as an extension to mod_negotiation.c so I
added it there.  So far, it seems to work realy well, and integrates into
the mod_negotiation.c with ease.  The patch follows...

Questions/comments/corrections welcome.

Jeremie Miller
jmiller@mwci.net



*** mod_negotiation.c-old	Fri Dec 15 17:41:59 1995
--- mod_negotiation.c	Sat Dec 16 14:04:32 1995
***************
*** 168,173 ****
--- 168,174 ----
      char *file_name;
      char *content_encoding;
      char *content_language;
+     char *agent_enhanced;
      float level;		/* Auxiliary to content-type... */
      float qs;
      float bytes;
***************
*** 195,200 ****
--- 196,202 ----
      array_header *accept_encodings;	/* accept_recs */
      array_header *accept_langs;	/* accept_recs */
      array_header *avail_vars;	/* available variants */
+     array_header *agent;	/* user agent */
  } negotiation_state;
  
  /* A few functions to manipulate var_recs.
***************
*** 208,213 ****
--- 210,217 ----
      mime_info->file_name = "";
      mime_info->content_encoding = "";
      mime_info->content_language = "";
+     mime_info->agent_enhanced = "";
+ 
  
      mime_info->is_pseudo_html = 0.0;
      mime_info->level = 0.0;
***************
*** 403,408 ****
--- 407,414 ----
        do_header_line (r->pool, table_get (hdrs, "Accept-encoding"));
      new->accept_langs =
        do_header_line (r->pool, table_get (hdrs, "Accept-language"));
+     new->agent =
+       do_header_line (r->pool, table_get (hdrs, "User-Agent"));
      new->avail_vars = make_array (r->pool, 40, sizeof (var_rec));
  
      return new;
***************
*** 602,607 ****
--- 608,617 ----
  		mime_info.content_encoding = get_token (neg->pool, &body, 0);
  		str_tolower (mime_info.content_encoding);
  	    }
+ 	    else if (!strncmp (buffer, "user-agent:", 11)) {
+ 		mime_info.agent_enhanced = get_token (neg->pool, &body, 0);
+ 		str_tolower (mime_info.agent_enhanced);
+ 	    }
  	} else {
  	    if (mime_info.quality > 0) {
  	        void *new_var = push_array (neg->avail_vars);
***************
*** 915,920 ****
--- 925,962 ----
  	    var_recs[i].quality = 0;
  }
  
+ int find_agent (array_header *agent, char *aef)
+ {
+     accept_rec *agnt = (accept_rec *)agent->elts;
+     int i;
+ 
+     for (i = 0; i < agent->nelts; ++i)
+ 	if (strstr (agnt[i].type_name, aef))
+ 	    return 1;
+ 
+     return 0;
+ }
+ 
+ void do_agent (negotiation_state *neg)
+ {
+     var_rec *var_recs = (var_rec*)neg->avail_vars->elts;
+     int i;
+ 
+     /* If no Accept-Encoding is present, everything is acceptable */
+ 
+     if (!neg->agent->nelts)
+ 	return;
+ 
+     /* Lose any variant with an unacceptable content encoding */
+ 
+     for (i = 0; i < neg->avail_vars->nelts; ++i)
+ 	if (var_recs[i].quality > 0
+ 	    && !find_agent (neg->agent,
+ 			       var_recs[i].agent_enhanced))
+ 	    
+ 	    var_recs[i].quality = 0;
+ }
+ 
  /* Determining the content length --- if the map didn't tell us,
   * we have to do a stat() and remember for next time.
   *
***************
*** 955,961 ****
       * find_lang_indexes keeps 'em all, so we still wind up serving
       * something...).
       */
!     
      do_encodings (neg);
      find_lang_indexes (neg);
      
--- 997,1004 ----
       * find_lang_indexes keeps 'em all, so we still wind up serving
       * something...).
       */
! 
!     do_agent (neg);
      do_encodings (neg);
      find_lang_indexes (neg);
      


Mime
View raw message