HttpUpgradeProtocolAccess.h
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#ifndef SQUID_HTTP_UPGRADE_H
10#define SQUID_HTTP_UPGRADE_H
11
12#include "acl/forward.h"
13#include "sbuf/SBuf.h"
14
15#include <deque>
16#include <map>
17
20{
21public:
22 ProtocolView(const char * const start, const size_t len);
23 explicit ProtocolView(const SBuf &proto);
24
27};
28
29std::ostream &operator <<(std::ostream &, const ProtocolView &);
30
31// HTTP is not explicit about case sensitivity of Upgrade protocol strings, but
32// there are bug reports showing different case variants used for WebSocket. We
33// conservatively preserve the received case and compare case-sensitively.
34
37inline bool
38vAinB(const ProtocolView &a, const ProtocolView &b)
39{
40 // Optimization: Do not assert(a.name == b.name).
41 return b.version.isEmpty() || (a.version == b.version);
42}
43
44class ConfigParser;
45
48{
49public:
52 HttpUpgradeProtocolAccess(HttpUpgradeProtocolAccess &&) = delete; // no copying of any kind
53
55 const acl_access *findGuard(const SBuf &proto) const;
56
59
61 template <typename Visitor> inline void forEach(const Visitor &) const;
62
65 template <typename Visitor> inline void forApplicable(const ProtocolView &, const Visitor &) const;
66
67private:
70 {
71 public:
72 NamedGuard(const char *rawProtocol, acl_access*);
73 NamedGuard(const NamedGuard &&) = delete; // no copying of any kind
75
76 const SBuf protocol;
78 acl_access *guard = nullptr;
79 };
80
82 typedef std::deque<NamedGuard> NamedGuards;
83
85 static const SBuf ProtoOther;
86
89
91 acl_access *other = nullptr;
92};
93
94template <typename Visitor>
95inline void
96HttpUpgradeProtocolAccess::forEach(const Visitor &visitor) const
97{
98 for (const auto &namedGuard: namedGuards)
99 visitor(namedGuard.protocol, namedGuard.guard);
100 if (other)
101 visitor(ProtoOther, other);
102}
103
104template <typename Visitor>
105inline void
106HttpUpgradeProtocolAccess::forApplicable(const ProtocolView &offer, const Visitor &visitor) const
107{
108 auto seenApplicable = false;
109 for (const auto &namedGuard: namedGuards) {
110 if (offer.name != namedGuard.proto.name)
111 continue;
112 if (vAinB(offer, namedGuard.proto) && visitor(namedGuard.protocol, namedGuard.guard))
113 return;
114 seenApplicable = true; // may already be true
115 }
116 if (!seenApplicable && other) // OTHER is applicable if named rules were not
117 (void)visitor(ProtoOther, other);
118}
119
120#endif /* SQUID_HTTP_UPGRADE_H */
121
bool vAinB(const ProtocolView &a, const ProtocolView &b)
std::ostream & operator<<(std::ostream &, const ProtocolView &)
#define acl_access
Definition: forward.h:45
a single configured access rule for an explicitly named protocol
NamedGuard(const NamedGuard &&)=delete
NamedGuard(const char *rawProtocol, acl_access *)
acl_access * guard
configured access rule; never nil
const SBuf protocol
configured protocol name (and version)
const ProtocolView proto
optimization: compiled this->protocol
Allows or blocks HTTP Upgrade protocols (see http_upgrade_request_protocols)
void configureGuard(ConfigParser &)
parses a single allow/deny rule
HttpUpgradeProtocolAccess(HttpUpgradeProtocolAccess &&)=delete
const acl_access * findGuard(const SBuf &proto) const
std::deque< NamedGuard > NamedGuards
maps HTTP Upgrade protocol name/version to the ACLs guarding its usage
acl_access * other
OTHER rules governing unnamed protocols.
void forEach(const Visitor &) const
iterates over all configured rules, calling the given visitor
void forApplicable(const ProtocolView &, const Visitor &) const
static const SBuf ProtoOther
pseudonym to specify rules for "all other protocols"
NamedGuards namedGuards
rules governing upgrades to explicitly named protocols
HttpUpgradeProtocolAccess()=default
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
bool isEmpty() const
Definition: SBuf.h:431

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors