MaxConnection.cc
Go to the documentation of this file.
1/*
2 * Copyright (C) 1996-2023 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 "client_db.h"
15#include "debug/Stream.h"
16#include "SquidConfig.h"
17
18ACLMaxConnection::ACLMaxConnection (char const *theClass) : class_ (theClass), limit(-1)
19{}
20
22{}
23
24char const *
26{
27 return class_;
28}
29
30bool
32{
33 return false;
34}
35
36bool
38{
39 return limit > 0;
40}
41
42void
44{
45 char *t = ConfigParser::strtokFile();
46
47 if (!t)
48 return;
49
50 limit = (atoi (t));
51
52 /* suck out file contents */
53 // ignore comments
54 bool ignore = false;
55 while ((t = ConfigParser::strtokFile())) {
56 ignore |= (*t != '#');
57
58 if (ignore)
59 continue;
60
61 debugs(89, DBG_CRITICAL, "WARNING: max_conn only accepts a single limit value.");
62 limit = 0;
63 }
64}
65
66int
68{
69 return clientdbEstablished(Filled(checklist)->src_addr, 0) > limit ? 1 : 0;
70}
71
74{
75 SBufList sl;
76 if (!limit)
77 return sl;
78
79 SBuf s;
80 s.Printf("%d", limit);
81 sl.push_back(s);
82 return sl;
83}
84
85void
87{
88 if (0 != Config.onoff.client_db)
89 return;
90
91 debugs(22, DBG_CRITICAL, "WARNING: 'maxconn' ACL (" << name << ") won't work with client_db disabled");
92}
93
ACLFilledChecklist * Filled(ACLChecklist *checklist)
convenience and safety wrapper for dynamic_cast<ACLFilledChecklist*>
class SquidConfig Config
Definition: SquidConfig.cc:12
void parse() override
parses node representation in squid.conf; dies on failures
~ACLMaxConnection() override
char const * class_
Definition: MaxConnection.h:32
char const * typeString() const override
bool empty() const override
ACLMaxConnection(char const *)
int match(ACLChecklist *checklist) override
Matches the actual data in checklist against this ACL.
bool valid() const override
void prepareForUse() override
SBufList dump() const override
char name[ACL_NAME_SZ]
Definition: Acl.h:87
static char * strtokFile()
Definition: ConfigParser.cc:65
Definition: SBuf.h:94
SBuf & Printf(const char *fmt,...) PRINTF_FORMAT_ARG2
Definition: SBuf.cc:214
struct SquidConfig::@106 onoff
int clientdbEstablished(const Ip::Address &addr, int delta)
Definition: client_db.cc:182
#define debugs(SECTION, LEVEL, CONTENT)
Definition: Stream.h:194
#define DBG_CRITICAL
Definition: Stream.h:37
std::list< SBuf > SBufList
Definition: forward.h:23

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors