HttpUpgradeProtocolAccess.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#include "squid.h"
10#include "acl/Acl.h"
11#include "acl/Gadgets.h"
12#include "cache_cf.h"
13#include "ConfigParser.h"
14#include "globals.h"
16#include "sbuf/Stream.h"
17
18#include <algorithm>
19
21
22ProtocolView::ProtocolView(const char * const start, const size_t len):
23 ProtocolView(SBuf(start, len))
24{
25}
26
28 name(proto.substr(0, proto.find('/'))),
29 version(proto.substr(name.length()))
30{
31}
32
33std::ostream &
34operator <<(std::ostream &os, const ProtocolView &view)
35{
36 os << view.name;
37 if (!view.version.isEmpty())
38 os << view.version;
39 return os;
40}
41
42/* HttpUpgradeProtocolAccess */
43
45{
47}
48
49void
51{
52 const auto rawProto = parser.NextToken();
53 if (!rawProto)
54 throw TextException(ToSBuf("expected a protocol name or ", ProtoOther), Here());
55
56 if (ProtoOther.cmp(rawProto) == 0) {
58 return;
59 }
60
61 // To preserve ACL rules checking order, to exclude inapplicable (i.e. wrong
62 // protocol version) rules, and to keep things simple, we merge no rules.
63 acl_access *access = nullptr;
64 aclParseAccessLine(cfg_directive, parser, &access);
65 if (access)
66 namedGuards.emplace_back(rawProto, access);
67}
68
69/* HttpUpgradeProtocolAccess::NamedGuard */
70
72 protocol(rawProtocol),
73 proto(protocol),
74 guard(acls)
75{
76}
77
80}
81
#define Here()
source code location of the caller
Definition: Here.h:15
std::ostream & operator<<(std::ostream &os, const ProtocolView &view)
void aclParseAccessLine(const char *directive, ConfigParser &, acl_access **treep)
Definition: Gadgets.cc:135
#define acl_access
Definition: forward.h:45
static int version
const char * cfg_directive
During parsing, the name of the current squid.conf directive being parsed.
Definition: cache_cf.cc:271
static char * NextToken()
NamedGuard(const char *rawProtocol, acl_access *)
void configureGuard(ConfigParser &)
parses a single allow/deny rule
acl_access * other
OTHER rules governing unnamed protocols.
static const SBuf ProtoOther
pseudonym to specify rules for "all other protocols"
NamedGuards namedGuards
rules governing upgrades to explicitly named protocols
a reference to a protocol name[/version] string; no 0-termination is assumed
ProtocolView(const char *const start, const size_t len)
SBuf version
everything after the name, including the slash('/')
SBuf name
everything up to (but excluding) the first slash('/')
Definition: SBuf.h:94
int cmp(const SBuf &S, const size_type n) const
shorthand version for compare()
Definition: SBuf.h:275
bool isEmpty() const
Definition: SBuf.h:431
an std::runtime_error with thrower location info
Definition: TextException.h:21
void aclDestroyAccessList(acl_access **list)
Definition: Gadgets.cc:276
SBuf ToSBuf(Args &&... args)
slowly stream-prints all arguments into a freshly allocated SBuf
Definition: Stream.h:63

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors