]> git.ipfire.org Git - thirdparty/squid.git/blobdiff - src/anyp/UriScheme.cc
SourceFormat Enforcement
[thirdparty/squid.git] / src / anyp / UriScheme.cc
index 36a873fedc6df50dac01f803e5c01fc52330864f..6e2e86ca9dd6253e18dc5798c7e668db8e60793f 100644 (file)
@@ -1,24 +1,70 @@
 /*
- * DEBUG: section 23    URL Scheme parsing
- * AUTHOR: Robert Collins, Amos Jeffries
+ * Copyright (C) 1996-2017 The Squid Software Foundation and contributors
+ *
+ * Squid software is distributed under GPLv2+ license and includes
+ * contributions from numerous individuals and organizations.
+ * Please see the COPYING and CONTRIBUTORS files for details.
  */
+
+/* DEBUG: section 23    URL Scheme parsing */
+
 #include "squid.h"
 #include "anyp/UriScheme.h"
 
-char const *
-AnyP::UriScheme::c_str() const
+AnyP::UriScheme::UriScheme(AnyP::ProtocolType const aScheme, const char *img) :
+    theScheme_(aScheme)
+{
+    if (img)
+        // image could be provided explicitly (case-sensitive)
+        image_ = img;
+
+    else if (theScheme_ == AnyP::PROTO_UNKNOWN)
+        // image could be actually unknown and not provided
+        image_ = "(unknown)";
+
+    else if (theScheme_ > AnyP::PROTO_NONE && theScheme_ < AnyP::PROTO_MAX) {
+        // image could be implied by a registered transfer protocol
+        // which use upper-case labels, so down-case for scheme image
+        image_ = AnyP::ProtocolType_str[theScheme_];
+        image_.toLower();
+    }
+    // else, image is an empty string ("://example.com/")
+}
+
+unsigned short
+AnyP::UriScheme::defaultPort() const
 {
-    if (theScheme_ == AnyP::PROTO_UNKNOWN)
-        return "(unknown)";
+    switch (theScheme_) {
 
-    static char out[BUFSIZ];
-    int p = 0;
+    case AnyP::PROTO_HTTP:
+        return 80;
 
-    if (theScheme_ > AnyP::PROTO_NONE && theScheme_ < AnyP::PROTO_MAX) {
-        const char *in = AnyP::ProtocolType_str[theScheme_];
-        for (; p < (BUFSIZ-1) && in[p] != '\0'; ++p)
-            out[p] = xtolower(in[p]);
+    case AnyP::PROTO_HTTPS:
+        return 443;
+
+    case AnyP::PROTO_FTP:
+        return 21;
+
+    case AnyP::PROTO_COAP:
+    case AnyP::PROTO_COAPS:
+        // coaps:// default is TBA as of draft-ietf-core-coap-08.
+        // Assuming IANA policy of allocating same port for base and TLS protocol versions will occur.
+        return 5683;
+
+    case AnyP::PROTO_GOPHER:
+        return 70;
+
+    case AnyP::PROTO_WAIS:
+        return 210;
+
+    case AnyP::PROTO_CACHE_OBJECT:
+        return CACHE_HTTP_PORT;
+
+    case AnyP::PROTO_WHOIS:
+        return 43;
+
+    default:
+        return 0;
     }
-    out[p] = '\0';
-    return out;
 }
+