[mod-xhtml-neg-cvs] mod_xhtml_neg mod_xhtml_neg.c,1.13,1.14
Brought to you by:
run2000
From: <ru...@us...> - 2004-03-12 10:00:18
|
Update of /cvsroot/mod-xhtml-neg/mod_xhtml_neg In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv1671 Modified Files: mod_xhtml_neg.c Log Message: Create Etags out of a simple hash of the negotiated content. Simplify some code slightly. Index: mod_xhtml_neg.c =================================================================== RCS file: /cvsroot/mod-xhtml-neg/mod_xhtml_neg/mod_xhtml_neg.c,v retrieving revision 1.13 retrieving revision 1.14 diff -C2 -d -r1.13 -r1.14 *** mod_xhtml_neg.c 11 Mar 2004 13:06:04 -0000 1.13 --- mod_xhtml_neg.c 12 Mar 2004 09:32:59 -0000 1.14 *************** *** 151,154 **** --- 151,155 ---- char *profile; /* The XHTML profile, as per RFC 3236 */ int stars; /* How many stars in this accept name? */ + char *hashcode; } accept_rec; *************** *** 468,471 **** --- 469,498 ---- /* + * Make a simple hash code for the given accept_rec structure. This allows + * us to generate unique Etags for accepted content-types. The Etag + * consists of two simple values, the length of the interesting data, + * and a simple hash of each character. These are then represented as + * two hyphen separated hexadecimal numbers. + */ + + static void make_hashcode( pool *p, accept_rec *rec ) + { + char *data; + unsigned long hash; + int len, i; + + data = ap_pstrcat( p, rec->name, rec->charset, rec->profile, NULL ); + len = mod_xhtml_strlen( data ); + hash = 7; + + for( i = 0; i < len; i++ ) { + hash = hash * 128 + data[ i ]; + } + + rec->hashcode = ap_psprintf(p, "\"%02x-%lx\"", + len, (unsigned long) hash); + } + + /* * Merge vlist_validators from different modules. This code is adapted * from code in http_protocol.c in the Apache 1.3 core. *************** *** 553,556 **** --- 580,584 ---- result->profile = ""; result->stars = 0; + result->hashcode = ""; /* *************** *** 711,714 **** --- 739,743 ---- new->profile = ""; new->stars = 0; + new->hashcode = ""; } *************** *** 877,884 **** */ ! static char *best_match(pool *p, array_header *accept_type, array_header *content_type, array_header *accept_charset, ! int stars_to_match, xhtml_neg_state *xns, ! int *result_index) { float best_q = 0.0f; --- 906,912 ---- */ ! static accept_rec *best_match(array_header *accept_type, array_header *content_type, array_header *accept_charset, ! int stars_to_match, xhtml_neg_state *xns) { float best_q = 0.0f; *************** *** 892,898 **** char *logmessage; - /* Set result index to 0 initially. */ - *result_index = 0; - /* Deal with silly null pointers when Accept: header is empty */ if((content_type == NULL) || (accept_type == NULL)) { --- 920,923 ---- *************** *** 950,954 **** best_stars = curr_stars; best_type = curr_content; - *result_index = i + 1; } } --- 975,978 ---- *************** *** 963,967 **** /* Return the reconstructed content-type header. */ ! return reconstruct_content_type( p, best_type ); } --- 987,991 ---- /* Return the reconstructed content-type header. */ ! return best_type; } *************** *** 1002,1006 **** { array_header *extensions, *accept_types, *accept_charsets, *content_types; ! const char *content_accept, *accept_charset, *result_type; char *filename, *extension, *logmessage; xhtml_dir_config *conf; --- 1026,1030 ---- { array_header *extensions, *accept_types, *accept_charsets, *content_types; ! const char *content_accept, *accept_charset; char *filename, *extension, *logmessage; xhtml_dir_config *conf; *************** *** 1008,1012 **** extension_rec *item; table *hdrs; ! int *result_index; conf = (xhtml_dir_config *) ap_get_module_config( --- 1032,1036 ---- extension_rec *item; table *hdrs; ! accept_rec *result_rec; conf = (xhtml_dir_config *) ap_get_module_config( *************** *** 1098,1120 **** /* Allocate storage for index of result, used in Etag. */ ! result_index = (int *) ap_palloc( r->pool, sizeof(int)); ! result_type = best_match( r->pool, accept_types, content_types, ! accept_charsets, conf->stars_ignore, ! xns, result_index ); ! if( result_type != NULL ) { /* Construct a "suffix" for the ETag, and make sure it gets * appended to the ETag that would normally be returned * by Apache. */ - char *new_validator = construct_etag_suffix( r->pool, *result_index ); r->vlist_validator = merge_validators( r->pool, r->vlist_validator, ! new_validator ); ! r->content_type = result_type; if( xns->log_fd > 0 ) { logmessage = ap_pstrcat(r->pool, ! "Best content-type: ", result_type, "\n", ! "New validator is: ", new_validator, "\n", NULL ); write(xns->log_fd, logmessage, mod_xhtml_strlen( logmessage )); --- 1122,1142 ---- /* Allocate storage for index of result, used in Etag. */ ! result_rec = best_match( accept_types, content_types, ! accept_charsets, conf->stars_ignore, ! xns ); ! if( result_rec != NULL ) { /* Construct a "suffix" for the ETag, and make sure it gets * appended to the ETag that would normally be returned * by Apache. */ r->vlist_validator = merge_validators( r->pool, r->vlist_validator, ! result_rec->hashcode ); ! r->content_type = reconstruct_content_type( r->pool, result_rec ); if( xns->log_fd > 0 ) { logmessage = ap_pstrcat(r->pool, ! "Best content-type: ", r->content_type, "\n", ! "New validator is: ", r->vlist_validator, "\n", NULL ); write(xns->log_fd, logmessage, mod_xhtml_strlen( logmessage )); *************** *** 1199,1202 **** --- 1221,1225 ---- new = (accept_rec *) ap_push_array( rec->content_types ); get_entry( cmd->pool, new, contenttype ); + make_hashcode( cmd->pool, new ); return NULL; |