UriScheme.cc
Go to the documentation of this file.
1 /*
2  * Copyright (C) 1996-2019 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 
16 AnyP::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 
37 void
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) {
45  image.toLower();
46  LowercaseSchemeNames_.emplace_back(image);
47  }
48  }
49 }
50 
51 unsigned short
53 {
54  switch (theScheme_) {
55 
56  case AnyP::PROTO_HTTP:
57  return 80;
58 
59  case AnyP::PROTO_HTTPS:
60  return 443;
61 
62  case AnyP::PROTO_FTP:
63  return 21;
64 
65  case AnyP::PROTO_COAP:
66  case AnyP::PROTO_COAPS:
67  // coaps:// default is TBA as of draft-ietf-core-coap-08.
68  // Assuming IANA policy of allocating same port for base and TLS protocol versions will occur.
69  return 5683;
70 
71  case AnyP::PROTO_GOPHER:
72  return 70;
73 
74  case AnyP::PROTO_WAIS:
75  return 210;
76 
78  return CACHE_HTTP_PORT;
79 
80  case AnyP::PROTO_WHOIS:
81  return 43;
82 
83  default:
84  return 0;
85  }
86 }
87 
SBuf image() const
Definition: UriScheme.h:50
Definition: SBuf.h:86
int i
Definition: membanger.c:49
unsigned short defaultPort() const
Definition: UriScheme.cc:52
SBuf image_
the string representation
Definition: UriScheme.h:66
void toLower()
converts all characters to lower case;
Definition: SBuf.cc:821
#define CACHE_HTTP_PORT
Definition: squid.h:21
std::vector< SBuf > LowercaseSchemeNames
Definition: UriScheme.h:27
ProtocolType
Definition: ProtocolType.h:22
AnyP::ProtocolType theScheme_
This is a typecode pointer into the enum/registry of protocols handled.
Definition: UriScheme.h:63
const char * ProtocolType_str[]
static void Init()
initializes down-cased protocol scheme names array
Definition: UriScheme.cc:38
static LowercaseSchemeNames LowercaseSchemeNames_
Definition: UriScheme.h:60

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors