]> git.ipfire.org Git - thirdparty/squid.git/blame - src/DelaySpec.cc
Fix crash when configuring with invalid delay_parameters restore value.
[thirdparty/squid.git] / src / DelaySpec.cc
CommitLineData
b67e2c8c 1/*
2cd0bda2 2 * Copyright (C) 1996-2017 The Squid Software Foundation and contributors
26ac0430 3 *
bbc27441
AJ
4 * Squid software is distributed under GPLv2+ license and includes
5 * contributions from numerous individuals and organizations.
6 * Please see the COPYING and CONTRIBUTORS files for details.
b67e2c8c 7 */
8
bbc27441
AJ
9/* DEBUG: section 77 Delay Pools */
10
f7f3304a 11#include "squid.h"
b67e2c8c 12
9a0a18de 13#if USE_DELAY_POOLS
8a01b99e 14#include "cache_cf.h"
b67e2c8c 15#include "DelaySpec.h"
c8709c9f 16#include "Parsing.h"
582c2af2 17#include "Store.h"
b67e2c8c 18
19DelaySpec::DelaySpec() : restore_bps(-1), max_bytes (-1)
62e76326 20{}
b67e2c8c 21
22void
23DelaySpec::stats (StoreEntry * sentry, char const *label) const
24{
25 if (restore_bps == -1) {
62e76326 26 storeAppendPrintf(sentry, "\t%s:\n\t\tDisabled.\n\n", label);
27 return;
b67e2c8c 28 }
62e76326 29
b67e2c8c 30 storeAppendPrintf(sentry, "\t%s:\n", label);
c91ca3ce 31 storeAppendPrintf(sentry, "\t\tMax: %" PRId64 "\n", max_bytes);
b67e2c8c 32 storeAppendPrintf(sentry, "\t\tRestore: %d\n", restore_bps);
33}
34
35void
36DelaySpec::dump (StoreEntry *entry) const
37{
c91ca3ce 38 storeAppendPrintf(entry, " %d/%" PRId64 "", restore_bps, max_bytes);
b67e2c8c 39}
40
41void
42DelaySpec::parse()
43{
6e7502cc
AJ
44 // get the token.
45 char *token = ConfigParser::NextToken();
b9e4cf09 46 if (!token) {
62e76326 47 self_destruct();
b9e4cf09
AJ
48 return;
49 }
62e76326 50
6e7502cc
AJ
51 // no-limit value
52 if (strcmp(token, "none") == 0 || token[0] == '-') {
53 restore_bps = -1;
54 max_bytes = -1;
55 return;
56 }
62e76326 57
6e7502cc
AJ
58 // parse the first digits into restore_bps
59 const char *p = NULL;
6596970b 60 if (!StringToInt(token, restore_bps, &p, 10) || *p != '/') {
6e7502cc
AJ
61 debugs(77, DBG_CRITICAL, "ERROR: invalid delay rate '" << token << "'. Expecting restore/max or 'none'.");
62 self_destruct();
63 }
64 p++; // increment past the '/'
62e76326 65
6e7502cc
AJ
66 // parse the rest into max_bytes
67 if (!StringToInt64(p, max_bytes, NULL, 10)) {
68 debugs(77, DBG_CRITICAL, "ERROR: restore rate in '" << token << "' is not a number.");
69 self_destruct();
70 }
b67e2c8c 71}
62e76326 72
b67e2c8c 73#endif
f53969cc 74