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