]> git.ipfire.org Git - thirdparty/squid.git/blame - src/acl/SquidErrorData.cc
SourceFormat Enforcement
[thirdparty/squid.git] / src / acl / SquidErrorData.cc
CommitLineData
3248e962 1/*
4ac4a490 2 * Copyright (C) 1996-2017 The Squid Software Foundation and contributors
3248e962
CT
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
19bool
20ACLSquidErrorData::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
33SBufList
34ACLSquidErrorData::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
47void
48ACLSquidErrorData::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
63bool
64ACLSquidErrorData::empty() const
65{
66 return errors.empty();
67}
68
69ACLData<err_type> *
70ACLSquidErrorData::clone() const
71{
72 if (!errors.empty())
73 fatal("ACLSquidError::clone: attempt to clone used ACL");
74
75 return new ACLSquidErrorData (*this);
76}
77