]> git.ipfire.org Git - thirdparty/squid.git/blob - src/acl/MaxConnection.cc
Boilerplate: update copyright blurbs on src/
[thirdparty/squid.git] / src / acl / MaxConnection.cc
1 /*
2 * Copyright (C) 1996-2014 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 /* DEBUG: section 28 Access Control */
10
11 #include "squid.h"
12 #include "acl/FilledChecklist.h"
13 #include "acl/MaxConnection.h"
14 #include "cache_cf.h"
15 #include "client_db.h"
16 #include "Debug.h"
17 #include "SquidConfig.h"
18
19 ACL *
20 ACLMaxConnection::clone() const
21 {
22 return new ACLMaxConnection(*this);
23 }
24
25 ACLMaxConnection::ACLMaxConnection (char const *theClass) : class_ (theClass), limit(-1)
26 {}
27
28 ACLMaxConnection::ACLMaxConnection (ACLMaxConnection const & old) :class_ (old.class_), limit (old.limit)
29 {}
30
31 ACLMaxConnection::~ACLMaxConnection()
32 {}
33
34 char const *
35 ACLMaxConnection::typeString() const
36 {
37 return class_;
38 }
39
40 bool
41 ACLMaxConnection::empty () const
42 {
43 return false;
44 }
45
46 bool
47 ACLMaxConnection::valid () const
48 {
49 return limit > 0;
50 }
51
52 void
53 ACLMaxConnection::parse()
54 {
55 char *t = strtokFile();
56
57 if (!t)
58 return;
59
60 limit = (atoi (t));
61
62 /* suck out file contents */
63 // ignore comments
64 bool ignore = false;
65 while ((t = strtokFile())) {
66 ignore |= (*t != '#');
67
68 if (ignore)
69 continue;
70
71 debugs(89, DBG_CRITICAL, "WARNING: max_conn only accepts a single limit value.");
72 limit = 0;
73 }
74 }
75
76 int
77 ACLMaxConnection::match(ACLChecklist *checklist)
78 {
79 return clientdbEstablished(Filled(checklist)->src_addr, 0) > limit ? 1 : 0;
80 }
81
82 SBufList
83 ACLMaxConnection::dump() const
84 {
85 SBufList sl;
86 if (!limit)
87 return sl;
88
89 SBuf s;
90 s.Printf("%d", limit);
91 sl.push_back(s);
92 return sl;
93 }
94
95 void
96 ACLMaxConnection::prepareForUse()
97 {
98 if (0 != Config.onoff.client_db)
99 return;
100
101 debugs(22, DBG_CRITICAL, "WARNING: 'maxconn' ACL (" << name << ") won't work with client_db disabled");
102 }