[mod-xhtml-neg-cvs] mod_xhtml_neg-2.0 Makefile,1.1.1.1,1.2 mod_xhtml_neg.c,1.8,1.9
Brought to you by:
run2000
From: <ru...@us...> - 2004-03-25 09:50:54
|
Update of /cvsroot/mod-xhtml-neg/mod_xhtml_neg-2.0 In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv19646 Modified Files: Makefile mod_xhtml_neg.c Log Message: Added facility to default charset to the value of AddDefaultCharset directive. Index: Makefile =================================================================== RCS file: /cvsroot/mod-xhtml-neg/mod_xhtml_neg-2.0/Makefile,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -C2 -d -r1.1.1.1 -r1.2 *** Makefile 13 Mar 2004 07:07:49 -0000 1.1.1.1 --- Makefile 25 Mar 2004 09:40:01 -0000 1.2 *************** *** 7,11 **** clean: ! $(RM) -rf *.o distclean: clean --- 7,11 ---- clean: ! $(RM) -rf *.o *.la *.slo distclean: clean Index: mod_xhtml_neg.c =================================================================== RCS file: /cvsroot/mod-xhtml-neg/mod_xhtml_neg-2.0/mod_xhtml_neg.c,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** mod_xhtml_neg.c 24 Mar 2004 11:06:40 -0000 1.8 --- mod_xhtml_neg.c 25 Mar 2004 09:40:01 -0000 1.9 *************** *** 77,81 **** * @author Nicholas Cull <ru...@us...> * @date 1 March 2004 ! * @version 0.91 * * @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 *************** *** 120,123 **** --- 116,123 ---- #include "http_request.h" #include "http_protocol.h" + + /* This is naughty */ + #define CORE_PRIVATE + #include "http_core.h" #include "http_log.h" *************** *** 453,456 **** --- 453,477 ---- /** + * 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 const 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 *************** *** 567,570 **** --- 588,619 ---- /** + * 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( apr_pool_t *p, accept_rec *rec, + const char *default_charset ) + { + accept_rec *newrec; + + if( ! mod_xhtml_strempty( rec->charset )) { + return rec; + } + + newrec = (accept_rec *) apr_palloc(p, sizeof (accept_rec)); + newrec->name = rec->name; + newrec->q_value = rec->q_value; + newrec->charset = ( default_charset ? + apr_pstrdup( p, 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. *************** *** 824,828 **** static float charsets_match( apr_array_header_t *accept_charsets, ! char *content_charset ) { accept_rec *list, *item; --- 873,877 ---- static float charsets_match( apr_array_header_t *accept_charsets, ! const char *content_charset ) { accept_rec *list, *item; *************** *** 869,876 **** static float types_match( accept_rec *content_type, accept_rec *content_accept, ! apr_array_header_t *accept_charsets ) { int offset = 0; ! char *content_charset; char *accept_profile, *content_profile; float charset_q, accept_q, server_q; --- 918,926 ---- static float types_match( accept_rec *content_type, accept_rec *content_accept, ! apr_array_header_t *accept_charsets, ! const char *default_charset ) { int offset = 0; ! const char *content_charset; char *accept_profile, *content_profile; float charset_q, accept_q, server_q; *************** *** 937,942 **** * "US-ASCII". */ ! content_charset = content_type->charset; ! if( mod_xhtml_strempty( content_charset )) { /* Sigh... RFC 3023 comes into play here. For most content-types * RFC 2616 specifies the default character set should be --- 987,991 ---- * "US-ASCII". */ ! if( mod_xhtml_strempty( content_type->charset )) { /* Sigh... RFC 3023 comes into play here. For most content-types * RFC 2616 specifies the default character set should be *************** *** 947,955 **** * 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 { content_charset = DEFAULT_CHARSET_NAME; } } --- 996,1009 ---- * See also example 8.5 of RFC 3023. */ ! if( ! mod_xhtml_strempty( default_charset )) { ! content_charset = default_charset; ! } else if( mod_xhtml_strnicmp( content_type->name, "text/xml", 8 ) ! == 0 ) { content_charset = DEFAULT_TEXT_XML_CHARSET; } else { content_charset = DEFAULT_CHARSET_NAME; } + } else { + content_charset = content_type->charset; } *************** *** 982,986 **** apr_array_header_t *content_type, apr_array_header_t *accept_charset, ! int stars_to_match, xhtml_neg_state *xns) { float best_q = 0.0f; --- 1036,1041 ---- apr_array_header_t *content_type, apr_array_header_t *accept_charset, ! const char *default_charset, int stars_to_match, ! xhtml_neg_state *xns, apr_pool_t *p) { float best_q = 0.0f; *************** *** 1030,1034 **** 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 --- 1085,1090 ---- 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 *************** *** 1061,1066 **** } ! /* Return the reconstructed content-type header. */ ! return best_type; } --- 1117,1122 ---- } ! /* Return the reconstructed content-type record. */ ! return make_default_accept( p, best_type, default_charset ); } *************** *** 1107,1111 **** apr_array_header_t *extensions, *accept_types, *accept_charsets, *content_types; ! const char *content_accept, *accept_charset; char *filename, *extension, *logmessage; apr_size_t logsize; --- 1163,1167 ---- apr_array_header_t *extensions, *accept_types, *accept_charsets, *content_types; ! const char *content_accept, *accept_charset, *default_charset; char *filename, *extension, *logmessage; apr_size_t logsize; *************** *** 1171,1174 **** --- 1227,1231 ---- content_accept = apr_table_get(hdrs, "Accept"); accept_charset = apr_table_get(hdrs, "Accept-Charset"); + default_charset = get_default_charset( r ); /* More logging... */ *************** *** 1179,1182 **** --- 1236,1241 ---- "Accept charset is: ", (accept_charset ? accept_charset : ""), "\n", + "Default charset is: ", + (default_charset ? default_charset : ""), "\n", NULL); *************** *** 1191,1196 **** /* 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 ) { --- 1250,1255 ---- /* 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 ) { |