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