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