]> git.ipfire.org Git - thirdparty/squid.git/blob - src/HttpUpgradeProtocolAccess.cc
168076c74830da331781842e6e6a4fe83d236d93
[thirdparty/squid.git] / src / HttpUpgradeProtocolAccess.cc
1 /*
2 * Copyright (C) 1996-2025 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"
15 #include "HttpUpgradeProtocolAccess.h"
16 #include "sbuf/Stream.h"
17
18 #include <algorithm>
19
20 ProtocolView::ProtocolView(const char * const start, const size_t len):
21 ProtocolView(SBuf(start, len))
22 {
23 }
24
25 ProtocolView::ProtocolView(const SBuf &proto):
26 name(proto.substr(0, proto.find('/'))),
27 version(proto.substr(name.length()))
28 {
29 }
30
31 std::ostream &
32 operator <<(std::ostream &os, const ProtocolView &view)
33 {
34 os << view.name;
35 if (!view.version.isEmpty())
36 os << view.version;
37 return os;
38 }
39
40 /* HttpUpgradeProtocolAccess */
41
42 HttpUpgradeProtocolAccess::~HttpUpgradeProtocolAccess()
43 {
44 aclDestroyAccessList(&other);
45 }
46
47 void
48 HttpUpgradeProtocolAccess::configureGuard(ConfigParser &parser)
49 {
50 const auto rawProto = parser.NextToken();
51 if (!rawProto)
52 throw TextException(ToSBuf("expected a protocol name or ", ProtoOther()), Here());
53
54 if (ProtoOther().cmp(rawProto) == 0) {
55 aclParseAccessLine(cfg_directive, parser, &other);
56 return;
57 }
58
59 // To preserve ACL rules checking order, to exclude inapplicable (i.e. wrong
60 // protocol version) rules, and to keep things simple, we merge no rules.
61 acl_access *access = nullptr;
62 aclParseAccessLine(cfg_directive, parser, &access);
63 if (access)
64 namedGuards.emplace_back(rawProto, access);
65 }
66
67 /* HttpUpgradeProtocolAccess::NamedGuard */
68
69 HttpUpgradeProtocolAccess::NamedGuard::NamedGuard(const char *rawProtocol, acl_access *acls):
70 protocol(rawProtocol),
71 proto(protocol),
72 guard(acls)
73 {
74 }
75
76 HttpUpgradeProtocolAccess::NamedGuard::~NamedGuard() {
77 aclDestroyAccessList(&guard);
78 }
79