]> git.ipfire.org Git - thirdparty/squid.git/blobdiff - src/anyp/UriScheme.cc
Source Format Enforcement (#763)
[thirdparty/squid.git] / src / anyp / UriScheme.cc
index 2782051b996cb1923866b59331caa41430cb96dd..bac54353c78ff9f6ac5be0270b94a9883a825d31 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 1996-2017 The Squid Software Foundation and contributors
+ * Copyright (C) 1996-2021 The Squid Software Foundation and contributors
  *
  * Squid software is distributed under GPLv2+ license and includes
  * contributions from numerous individuals and organizations.
@@ -21,12 +21,12 @@ AnyP::UriScheme::UriScheme(AnyP::ProtocolType const aScheme, const char *img) :
     // To improve diagnostic, remember exactly how an unsupported scheme looks like.
     // XXX: Object users may rely on toLower() canonicalization that we refuse to provide.
     if (img && theScheme_ == AnyP::PROTO_UNKNOWN)
-         image_ = img;
+        image_ = img;
 
     // XXX: A broken caller supplies an image of an absent scheme?
     // XXX: We assume that the caller is using a lower-case image.
     else if (img && theScheme_ == AnyP::PROTO_NONE)
-         image_ = img;
+        image_ = img;
 
     else if (theScheme_ > AnyP::PROTO_NONE && theScheme_ < AnyP::PROTO_MAX)
         image_ = LowercaseSchemeNames_.at(theScheme_);
@@ -48,6 +48,25 @@ AnyP::UriScheme::Init()
     }
 }
 
+const AnyP::ProtocolType
+AnyP::UriScheme::FindProtocolType(const SBuf &scheme)
+{
+    if (scheme.isEmpty())
+        return AnyP::PROTO_NONE;
+
+    Init();
+
+    auto img = scheme;
+    img.toLower();
+    // TODO: use base/EnumIterator.h if possible
+    for (int i = AnyP::PROTO_NONE + 1; i < AnyP::PROTO_UNKNOWN; ++i) {
+        if (LowercaseSchemeNames_.at(i) == img)
+            return AnyP::ProtocolType(i);
+    }
+
+    return AnyP::PROTO_UNKNOWN;
+}
+
 unsigned short
 AnyP::UriScheme::defaultPort() const
 {