[mod-xhtml-neg-cvs] mod_xhtml_neg mod_xhtml_neg.c,1.23,1.24
Brought to you by:
run2000
From: <ru...@us...> - 2004-03-25 09:51:55
|
Update of /cvsroot/mod-xhtml-neg/mod_xhtml_neg In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv19828 Modified Files: mod_xhtml_neg.c Log Message: Added facility to default charset to the value of AddDefaultCharset directive. Index: mod_xhtml_neg.c =================================================================== RCS file: /cvsroot/mod-xhtml-neg/mod_xhtml_neg/mod_xhtml_neg.c,v retrieving revision 1.23 retrieving revision 1.24 diff -C2 -d -r1.23 -r1.24 *** mod_xhtml_neg.c 24 Mar 2004 11:07:14 -0000 1.23 --- mod_xhtml_neg.c 25 Mar 2004 09:41:09 -0000 1.24 *************** *** 77,81 **** * @author Nicholas Cull <ru...@us...> * @date 1 March 2004 ! * @version 0.9 * * @history --- 77,81 ---- * @author Nicholas Cull <ru...@us...> * @date 1 March 2004 ! * @version 0.92 * * @history *************** *** 85,93 **** * 0.8 First public release. \n * 0.9 ETag handled correctly for different content types. \n ! * ! * @todo ! * Pick up the AddDefaultCharset directive from the Apache core and use that ! * where appropriate instead of defaulting to ISO-8859-1. If this is not set, ! * then we fallback on existing methods. * * @directive --- 85,89 ---- * 0.8 First public release. \n * 0.9 ETag handled correctly for different content types. \n ! * 0.92 Pick up the AddDefaultCharset directive from the Apache core \n * * @directive *************** *** 111,116 **** #include "http_config.h" #include "http_request.h" ! #include "http_protocol.h" #include "http_core.h" #include "http_log.h" --- 107,116 ---- #include "http_config.h" #include "http_request.h" ! ! /* This is naughty... */ ! #define CORE_PRIVATE ! #include "http_core.h" + #include "http_protocol.h" #include "http_log.h" *************** *** 451,454 **** --- 451,475 ---- /** + * This naughty function goes digging into the Apache http_core module + * to find the default character set. + * + * @todo Is there a cleaner way to find the default charset information? + */ + + static char *get_default_charset( request_rec *r ) + { + core_dir_config *conf; + + conf = (core_dir_config *) + ap_get_module_config(r->per_dir_config, &core_module); + + if( conf->add_default_charset == ADD_DEFAULT_CHARSET_ON ) { + return conf->add_default_charset_name; + } + + return NULL; + } + + /** * Given an array of extension_rec records, find one with the given file * extension. If a match is found, return the extension_rec, otherwise *************** *** 565,568 **** --- 586,616 ---- /** + * Make an accept_rec with an explicit charset. If the record already + * contains a charset parameter, it is returned as-is. Otherwise, the + * parameter default_charset is used. Note that default_charset can be + * NULL, in which case charset will be set to the empty string. + */ + + static accept_rec *make_default_accept( pool *p, accept_rec *rec, + char *default_charset ) + { + accept_rec *newrec; + + if( ! mod_xhtml_strempty( rec->charset )) { + return rec; + } + + newrec = (accept_rec *) ap_palloc(p, sizeof (accept_rec)); + newrec->name = rec->name; + newrec->q_value = rec->q_value; + newrec->charset = ( default_charset ? default_charset : "" ); + newrec->profile = rec->profile; + newrec->stars = rec->stars; + make_etag_hashcode( p, newrec ); + + return newrec; + } + + /** * Merge vlist_validators from different modules. This code is adapted * from code in http_protocol.c in the Apache 1.3 core. *************** *** 821,825 **** static float charsets_match( array_header *accept_charsets, ! char *content_charset ) { accept_rec *list, *item; --- 869,873 ---- static float charsets_match( array_header *accept_charsets, ! const char *content_charset ) { accept_rec *list, *item; *************** *** 866,870 **** static float types_match( accept_rec *content_type, accept_rec *content_accept, ! array_header *accept_charsets ) { int offset = 0; --- 914,919 ---- static float types_match( accept_rec *content_type, accept_rec *content_accept, ! array_header *accept_charsets, ! char *default_charset ) { int offset = 0; *************** *** 944,948 **** * See also example 8.5 of RFC 3023. */ ! if( mod_xhtml_strnicmp( content_type->name, "text/xml", 8 ) == 0 ) { content_charset = DEFAULT_TEXT_XML_CHARSET; } else { --- 993,999 ---- * See also example 8.5 of RFC 3023. */ ! if( default_charset != NULL ) { ! content_charset = default_charset; ! } else if( mod_xhtml_strnicmp( content_type->name, "text/xml", 8 ) == 0 ) { content_charset = DEFAULT_TEXT_XML_CHARSET; } else { *************** *** 978,982 **** 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; --- 1029,1034 ---- static accept_rec *best_match(array_header *accept_type, array_header *content_type, array_header *accept_charset, ! char *default_charset, int stars_to_match, ! xhtml_neg_state *xns, pool *p) { float best_q = 0.0f; *************** *** 1025,1029 **** curr_accept = &list_accept[j]; curr_stars = curr_accept->stars; ! curr_q = types_match( curr_content, curr_accept, accept_charset ); #ifdef MOD_XHTML_NEG_DEBUG --- 1077,1082 ---- curr_accept = &list_accept[j]; curr_stars = curr_accept->stars; ! curr_q = types_match( curr_content, curr_accept, accept_charset, ! default_charset ); #ifdef MOD_XHTML_NEG_DEBUG *************** *** 1056,1061 **** } ! /* Return the reconstructed content-type header. */ ! return best_type; } --- 1109,1114 ---- } ! /* Return the reconstructed content-type record. */ ! return make_default_accept( p, best_type, default_charset ); } *************** *** 1090,1094 **** /** ! * The actual content-negotiation phase of this module goes here. */ --- 1143,1149 ---- /** ! * The main routine for the content-negotiation phase of this module ! * goes here. This is mainly setup, control flow and logging going on ! * here. */ *************** *** 1097,1101 **** array_header *extensions, *accept_types, *accept_charsets, *content_types; const char *content_accept, *accept_charset; ! char *filename, *extension, *logmessage; xhtml_dir_config *conf; xhtml_neg_state *xns; --- 1152,1156 ---- array_header *extensions, *accept_types, *accept_charsets, *content_types; const char *content_accept, *accept_charset; ! char *filename, *extension, *logmessage, *default_charset; xhtml_dir_config *conf; xhtml_neg_state *xns; *************** *** 1174,1177 **** --- 1229,1233 ---- content_accept = ap_table_get(hdrs, "Accept"); accept_charset = ap_table_get(hdrs, "Accept-Charset"); + default_charset = get_default_charset( r ); /* More logging... */ *************** *** 1182,1185 **** --- 1238,1243 ---- "Accept charset is: ", (accept_charset ? accept_charset : ""), "\n", + "Default charset is: ", + (default_charset ? default_charset : ""), "\n", NULL); *************** *** 1193,1198 **** /* Find accept_rec of best result, if any. */ result_rec = best_match( accept_types, content_types, ! accept_charsets, conf->stars_ignore, ! xns ); if( result_rec != NULL ) { --- 1251,1256 ---- /* Find accept_rec of best result, if any. */ result_rec = best_match( accept_types, content_types, ! accept_charsets, default_charset, ! conf->stars_ignore, xns, r->pool ); if( result_rec != NULL ) { |