From: Amos Jeffries Date: Thu, 13 Nov 2014 07:45:12 +0000 (-0800) Subject: Fix delay_parameters parsing X-Git-Tag: merge-candidate-3-v1~493 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=6e7502cc5829366310689ef9b8f9408864cd1ffa;p=thirdparty%2Fsquid.git Fix delay_parameters parsing Squid-3.4 parser changes resulted in always getting a BUNGLED error when parsing delay_parameters. Convert to the new ConfigParser engine. Add ability to specify 'none' for no-limit instead of -n/* --- diff --git a/src/DelaySpec.cc b/src/DelaySpec.cc index 631f111e63..72ee98c00a 100644 --- a/src/DelaySpec.cc +++ b/src/DelaySpec.cc @@ -41,19 +41,31 @@ DelaySpec::dump (StoreEntry *entry) const void DelaySpec::parse() { - int r; - char *token; - token = strtok(NULL, "/"); - + // get the token. + char *token = ConfigParser::NextToken(); if (token == NULL) self_destruct(); - if (sscanf(token, "%d", &r) != 1) - self_destruct(); + // no-limit value + if (strcmp(token, "none") == 0 || token[0] == '-') { + restore_bps = -1; + max_bytes = -1; + return; + } - restore_bps = r; + // parse the first digits into restore_bps + const char *p = NULL; + if (!StringToInt(token, restore_bps, &p, 10) && *p != '/') { + debugs(77, DBG_CRITICAL, "ERROR: invalid delay rate '" << token << "'. Expecting restore/max or 'none'."); + self_destruct(); + } + p++; // increment past the '/' - max_bytes = GetInteger64(); + // parse the rest into max_bytes + if (!StringToInt64(p, max_bytes, NULL, 10)) { + debugs(77, DBG_CRITICAL, "ERROR: restore rate in '" << token << "' is not a number."); + self_destruct(); + } } #endif diff --git a/src/cf.data.pre b/src/cf.data.pre index a524ddbc62..47078c378b 100644 --- a/src/cf.data.pre +++ b/src/cf.data.pre @@ -6512,23 +6512,23 @@ DOC_START description of delay_class. For a class 1 delay pool, the syntax is: - delay_pools pool 1 + delay_class pool 1 delay_parameters pool aggregate For a class 2 delay pool: - delay_pools pool 2 + delay_class pool 2 delay_parameters pool aggregate individual For a class 3 delay pool: - delay_pools pool 3 + delay_class pool 3 delay_parameters pool aggregate network individual For a class 4 delay pool: - delay_pools pool 4 + delay_class pool 4 delay_parameters pool aggregate network individual user For a class 5 delay pool: - delay_pools pool 5 + delay_class pool 5 delay_parameters pool tagrate The option variables are: @@ -6564,11 +6564,11 @@ DOC_START above example, and is being used to strictly limit each host to 64Kbit/sec (plus overheads), with no overall limit, the line is: - delay_parameters 1 -1/-1 8000/8000 + delay_parameters 1 none 8000/8000 Note that 8 x 8000 KByte/sec -> 64Kbit/sec. - Note that the figure -1 is used to represent "unlimited". + Note that the word 'none' is used to represent no limit. And, if delay pool number 2 is a class 3 delay pool as in the above