]> git.ipfire.org Git - thirdparty/squid.git/blob - src/acl/SquidErrorData.cc
SourceFormat Enforcement
[thirdparty/squid.git] / src / acl / SquidErrorData.cc
1 /*
2 * Copyright (C) 1996-2017 The Squid Software Foundation and contributors
3 *
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.
7 */
8
9 #include "squid.h"
10 #include "acl/Data.h"
11 #include "acl/SquidErrorData.h"
12 #include "cache_cf.h"
13 #include "ConfigParser.h"
14 #include "Debug.h"
15 #include "err_type.h"
16 #include "fatal.h"
17 #include "wordlist.h"
18
19 bool
20 ACLSquidErrorData::match(err_type err)
21 {
22 CbDataListIterator<err_type> iter(errors);
23 while (!iter.end()) {
24 err_type localErr = iter.next();
25 debugs(28, 4, "check (" << err << "):" << errorTypeName(err) << " against " << errorTypeName(localErr));
26 if (err == localErr)
27 return true;
28 }
29
30 return false;
31 }
32
33 SBufList
34 ACLSquidErrorData::dump() const
35 {
36 SBufList sl;
37 CbDataListIterator<err_type> iter(errors);
38 while (!iter.end()) {
39 err_type err = iter.next();
40 const char *errName = errorTypeName(err);
41 sl.push_back(SBuf(errName));
42 }
43
44 return sl;
45 }
46
47 void
48 ACLSquidErrorData::parse()
49 {
50 while (char *token = ConfigParser::NextToken()) {
51 err_type err = errorTypeByName(token);
52
53 if (err < ERR_MAX)
54 errors.push_back(err);
55 else {
56 debugs(28, DBG_CRITICAL, "FATAL: Invalid squid error name");
57 if (!opt_parse_cfg_only)
58 self_destruct();
59 }
60 }
61 }
62
63 bool
64 ACLSquidErrorData::empty() const
65 {
66 return errors.empty();
67 }
68
69 ACLData<err_type> *
70 ACLSquidErrorData::clone() const
71 {
72 if (!errors.empty())
73 fatal("ACLSquidError::clone: attempt to clone used ACL");
74
75 return new ACLSquidErrorData (*this);
76 }
77