UriScheme.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 23 URL Scheme parsing */
10
11#include "squid.h"
12#include "anyp/UriScheme.h"
13
15
16AnyP::UriScheme::UriScheme(AnyP::ProtocolType const aScheme, const char *img) :
17 theScheme_(aScheme)
18{
19 // RFC 3986 section 3.1: schemes are case-insensitive.
20
21 // To improve diagnostic, remember exactly how an unsupported scheme looks like.
22 // XXX: Object users may rely on toLower() canonicalization that we refuse to provide.
23 if (img && theScheme_ == AnyP::PROTO_UNKNOWN)
24 image_ = img;
25
26 // XXX: A broken caller supplies an image of an absent scheme?
27 // XXX: We assume that the caller is using a lower-case image.
28 else if (img && theScheme_ == AnyP::PROTO_NONE)
29 image_ = img;
30
33 // else, the image remains empty (e.g., "://example.com/")
34 // hopefully, theScheme_ is PROTO_NONE here
35}
36
37void
39{
40 if (LowercaseSchemeNames_.empty()) {
41 LowercaseSchemeNames_.reserve(sizeof(SBuf) * AnyP::PROTO_MAX);
42 // TODO: use base/EnumIterator.h if possible
43 for (int i = AnyP::PROTO_NONE; i < AnyP::PROTO_MAX; ++i) {
44 SBuf image(ProtocolType_str[i]);
45 image.toLower();
46 LowercaseSchemeNames_.emplace_back(image);
47 }
48 }
49}
50
53{
54 if (scheme.isEmpty())
55 return AnyP::PROTO_NONE;
56
57 Init();
58
59 auto img = scheme;
60 img.toLower();
61 // TODO: use base/EnumIterator.h if possible
62 for (int i = AnyP::PROTO_NONE + 1; i < AnyP::PROTO_UNKNOWN; ++i) {
63 if (LowercaseSchemeNames_.at(i) == img)
64 return AnyP::ProtocolType(i);
65 }
66
68}
69
72{
73 switch (theScheme_) {
74
76 return 80;
77
79 return 443;
80
81 case AnyP::PROTO_FTP:
82 return 21;
83
86 // coaps:// default is TBA as of draft-ietf-core-coap-08.
87 // Assuming IANA policy of allocating same port for base and TLS protocol versions will occur.
88 return 5683;
89
91 return 210;
92
94 return 43;
95
96 default:
97 return std::nullopt;
98 }
99}
100
std::vector< SBuf > LowercaseSchemeNames
Definition: UriScheme.h:34
AnyP::ProtocolType theScheme_
This is a typecode pointer into the enum/registry of protocols handled.
Definition: UriScheme.h:73
static void Init()
initializes down-cased protocol scheme names array
Definition: UriScheme.cc:38
static AnyP::ProtocolType FindProtocolType(const SBuf &)
Definition: UriScheme.cc:52
SBuf image_
the string representation
Definition: UriScheme.h:76
Port defaultPort() const
Definition: UriScheme.cc:71
static LowercaseSchemeNames LowercaseSchemeNames_
Definition: UriScheme.h:70
Definition: SBuf.h:94
bool isEmpty() const
Definition: SBuf.h:431
void toLower()
converts all characters to lower case;
Definition: SBuf.cc:811
void Init(void)
prepares to parse ACLs configuration
Definition: AclRegs.cc:191
std::optional< KnownPort > Port
validated/supported port number (if any)
Definition: UriScheme.h:26
const char * ProtocolType_str[]
ProtocolType
Definition: ProtocolType.h:23
@ PROTO_NONE
Definition: ProtocolType.h:24
@ PROTO_HTTPS
Definition: ProtocolType.h:27
@ PROTO_UNKNOWN
Definition: ProtocolType.h:41
@ PROTO_HTTP
Definition: ProtocolType.h:25
@ PROTO_COAP
Definition: ProtocolType.h:28
@ PROTO_FTP
Definition: ProtocolType.h:26
@ PROTO_WHOIS
Definition: ProtocolType.h:36
@ PROTO_MAX
Definition: ProtocolType.h:42
@ PROTO_COAPS
Definition: ProtocolType.h:29
@ PROTO_WAIS
Definition: ProtocolType.h:30

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors