]> git.ipfire.org Git - thirdparty/squid.git/blob - src/anyp/UriScheme.cc
SourceFormat Enforcement
[thirdparty/squid.git] / src / anyp / UriScheme.cc
1 /*
2 * Copyright (C) 1996-2017 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
14 AnyP::UriScheme::UriScheme(AnyP::ProtocolType const aScheme, const char *img) :
15 theScheme_(aScheme)
16 {
17 if (img)
18 // image could be provided explicitly (case-sensitive)
19 image_ = img;
20
21 else if (theScheme_ == AnyP::PROTO_UNKNOWN)
22 // image could be actually unknown and not provided
23 image_ = "(unknown)";
24
25 else if (theScheme_ > AnyP::PROTO_NONE && theScheme_ < AnyP::PROTO_MAX) {
26 // image could be implied by a registered transfer protocol
27 // which use upper-case labels, so down-case for scheme image
28 image_ = AnyP::ProtocolType_str[theScheme_];
29 image_.toLower();
30 }
31 // else, image is an empty string ("://example.com/")
32 }
33
34 unsigned short
35 AnyP::UriScheme::defaultPort() const
36 {
37 switch (theScheme_) {
38
39 case AnyP::PROTO_HTTP:
40 return 80;
41
42 case AnyP::PROTO_HTTPS:
43 return 443;
44
45 case AnyP::PROTO_FTP:
46 return 21;
47
48 case AnyP::PROTO_COAP:
49 case AnyP::PROTO_COAPS:
50 // coaps:// default is TBA as of draft-ietf-core-coap-08.
51 // Assuming IANA policy of allocating same port for base and TLS protocol versions will occur.
52 return 5683;
53
54 case AnyP::PROTO_GOPHER:
55 return 70;
56
57 case AnyP::PROTO_WAIS:
58 return 210;
59
60 case AnyP::PROTO_CACHE_OBJECT:
61 return CACHE_HTTP_PORT;
62
63 case AnyP::PROTO_WHOIS:
64 return 43;
65
66 default:
67 return 0;
68 }
69 }
70