]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Fix delay_parameters parsing
authorAmos Jeffries <squid3@treenet.co.nz>
Thu, 13 Nov 2014 07:45:12 +0000 (23:45 -0800)
committerAmos Jeffries <squid3@treenet.co.nz>
Thu, 13 Nov 2014 07:45:12 +0000 (23:45 -0800)
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/*

src/DelaySpec.cc
src/cf.data.pre

index 631f111e63c042abfd4c789e7c0830f7bd8b9eeb..72ee98c00a7a6b081ba835d32a52be1d9a5a1c91 100644 (file)
@@ -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
index a524ddbc6272a8a2f82e2a79ab1fcfb0b08e4efc..47078c378b738adb825be89476a6cd9b1aa2a1d1 100644 (file)
@@ -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