Return-Path: Delivered-To: apmail-httpd-cvs-archive@httpd.apache.org Received: (qmail 67607 invoked by uid 500); 10 Mar 2003 23:36:21 -0000 Mailing-List: contact cvs-help@httpd.apache.org; run by ezmlm Precedence: bulk Reply-To: dev@httpd.apache.org list-help: list-unsubscribe: list-post: Delivered-To: mailing list cvs@httpd.apache.org Received: (qmail 67590 invoked by uid 500); 10 Mar 2003 23:36:21 -0000 Delivered-To: apmail-httpd-2.0-cvs@apache.org Date: 10 Mar 2003 23:36:19 -0000 Message-ID: <20030310233619.99004.qmail@icarus.apache.org> From: nd@apache.org To: httpd-2.0-cvs@apache.org Subject: cvs commit: httpd-2.0/modules/mappers mod_negotiation.c X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N nd 2003/03/10 15:36:18 Modified: . CHANGES modules/mappers mod_negotiation.c Log: mod_negotiation: quality values are now parsed independent from the current locale. level values are now really parsed as integers. PR: 17564 Reviewed by: Dirk-Willem van Gulik Revision Changes Path 1.1116 +4 -0 httpd-2.0/CHANGES Index: CHANGES =================================================================== RCS file: /home/cvs/httpd-2.0/CHANGES,v retrieving revision 1.1115 retrieving revision 1.1116 diff -u -r1.1115 -r1.1116 --- CHANGES 9 Mar 2003 17:02:03 -0000 1.1115 +++ CHANGES 10 Mar 2003 23:36:16 -0000 1.1116 @@ -2,6 +2,10 @@ [Remove entries to the current 2.0 section below, when backported] + *) mod_negotiation: quality values are now parsed independent from + the current locale. level values are now really parsed as integers. + PR 17564. [Andr� Malo] + *) mod_deflate: Check also err_headers_out for an already set Content-Encoding: gzip header. This prevents gzip compressed content from a CGI script from being compressed once more. PR 17797. 1.114 +61 -2 httpd-2.0/modules/mappers/mod_negotiation.c Index: mod_negotiation.c =================================================================== RCS file: /home/cvs/httpd-2.0/modules/mappers/mod_negotiation.c,v retrieving revision 1.113 retrieving revision 1.114 diff -u -r1.113 -r1.114 --- mod_negotiation.c 1 Mar 2003 23:57:32 -0000 1.113 +++ mod_negotiation.c 10 Mar 2003 23:36:18 -0000 1.114 @@ -385,6 +385,65 @@ */ /* + * parse quality value. atof(3) is not well-usable here, because it + * depends on the locale (argh). + * + * However, RFC 2616 states: + * 3.9 Quality Values + * + * [...] HTTP/1.1 applications MUST NOT generate more than three digits + * after the decimal point. User configuration of these values SHOULD also + * be limited in this fashion. + * + * qvalue = ( "0" [ "." 0*3DIGIT ] ) + * | ( "1" [ "." 0*3("0") ] ) + * + * This is quite easy. If the supplied string doesn't match the above + * definition (loosely), we simply return 1 (same as if there's no qvalue) + */ + +static float atoq(const char *string) +{ + if (!string || !*string) { + return 1.0f; + } + + while (*string && apr_isspace(*string)) { + ++string; + } + + /* be tolerant and accept qvalues without leading zero + * (also for backwards compat, where atof() was in use) + */ + if (*string != '.' && *string++ != '0') { + return 1.0f; + } + + if (*string == '.') { + /* better only one division later, than dealing with fscking + * IEEE format 0.1 factors ... + */ + int i = 0; + + if (*++string >= '0' && *string <= '9') { + i += (*string - '0') * 100; + + if (*++string >= '0' && *string <= '9') { + i += (*string - '0') * 10; + + if (*++string > '0' && *string <= '9') { + i += (*string - '0'); + } + } + } + + return (float)i / 1000.0f; + } + + return 0.0f; +} + +/* * Get a single mime type entry --- one media type and parameters; * enter the values we recognize into the argument accept_rec */ @@ -467,10 +526,10 @@ if (parm[0] == 'q' && (parm[1] == '\0' || (parm[1] == 's' && parm[2] == '\0'))) { - result->quality = (float)atof(cp); + result->quality = atoq(cp); } else if (parm[0] == 'l' && !strcmp(&parm[1], "evel")) { - result->level = (float)atof(cp); + result->level = (float)atoi(cp); } else if (!strcmp(parm, "charset")) { result->charset = cp;