]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Fix build broken by missing <map> in 36c774 (#384)
authorEduard Bagdasaryan <eduard.bagdasaryan@measurement-factory.com>
Wed, 3 Apr 2019 03:09:14 +0000 (03:09 +0000)
committerSquid Anubis <squid-anubis@squid-cache.org>
Wed, 3 Apr 2019 05:05:50 +0000 (05:05 +0000)
In all tested environments, something else #included `<map>`.

src/proxyp/Elements.cc
src/proxyp/Elements.h
src/proxyp/Header.cc

index a7c0a20efb2e6980f24edae1d579bbee32e62fa5..9a2b981a655932f7efb08bee13e28814c46c6b49 100644 (file)
 #include "proxyp/Elements.h"
 #include "sbuf/Stream.h"
 
+#include <algorithm>
 #include <limits>
+#include <vector>
 
-const ProxyProtocol::FieldMap ProxyProtocol::PseudoHeaderFields = {
-    { SBuf(":version"), ProxyProtocol::Two::htPseudoVersion },
-    { SBuf(":command"), ProxyProtocol::Two::htPseudoCommand },
-    { SBuf(":src_addr"), ProxyProtocol::Two::htPseudoSrcAddr },
-    { SBuf(":dst_addr"), ProxyProtocol::Two::htPseudoDstAddr },
-    { SBuf(":src_port"), ProxyProtocol::Two::htPseudoSrcPort },
-    { SBuf(":dst_port"), ProxyProtocol::Two::htPseudoDstPort }
+namespace ProxyProtocol {
+namespace Two {
+
+/// a mapping between pseudo header names and ids
+typedef std::vector< std::pair<SBuf, FieldType> > FieldMap;
+static const FieldMap PseudoHeaderFields = {
+    { SBuf(":version"), htPseudoVersion },
+    { SBuf(":command"), htPseudoCommand },
+    { SBuf(":src_addr"), htPseudoSrcAddr },
+    { SBuf(":dst_addr"), htPseudoDstAddr },
+    { SBuf(":src_port"), htPseudoSrcPort },
+    { SBuf(":dst_port"), htPseudoDstPort }
 };
 
-namespace ProxyProtocol {
+} // namespace Two
+
 static Two::FieldType NameToFieldType(const SBuf &);
 static Two::FieldType IntegerToFieldType(const SBuf &);
+
 } // namespace ProxyProtocol
 
+const SBuf &
+ProxyProtocol::PseudoFieldTypeToFieldName(const Two::FieldType fieldType)
+{
+    const auto it = std::find_if(Two::PseudoHeaderFields.begin(), Two::PseudoHeaderFields.end(),
+    [fieldType](const Two::FieldMap::value_type &item) {
+        return item.second == fieldType;
+    });
+
+    assert(it != Two::PseudoHeaderFields.end());
+    return it->first;
+}
+
 /// FieldNameToFieldType() helper that handles pseudo headers
 ProxyProtocol::Two::FieldType
 ProxyProtocol::NameToFieldType(const SBuf &name)
 {
-    const auto it = PseudoHeaderFields.find(name);
-    if (it != PseudoHeaderFields.end())
+    const auto it = std::find_if(Two::PseudoHeaderFields.begin(), Two::PseudoHeaderFields.end(),
+    [&name](const Two::FieldMap::value_type &item) {
+        return item.first == name;
+    });
+
+    if (it != Two::PseudoHeaderFields.end())
         return it->second;
 
     static const SBuf pseudoMark(":");
index aad90eb5d1663fbc090ebf04d958bef481ed50a0..996b92569cfce88842a18242abff31adf075cc20 100644 (file)
@@ -34,12 +34,14 @@ typedef enum {
 
     // IDs for PROXY protocol header pseudo-headers.
     // Larger than 255 to avoid clashes with possible TLV type IDs.
-    htPseudoVersion = 0x101,
-    htPseudoCommand = 0x102,
-    htPseudoSrcAddr = 0x103,
-    htPseudoDstAddr = 0x104,
-    htPseudoSrcPort = 0x105,
-    htPseudoDstPort = 0x106
+    htPseudoBegin = 0x101, // smallest pseudo-header value (for iteration)
+    htPseudoVersion,
+    htPseudoCommand,
+    htPseudoSrcAddr,
+    htPseudoDstAddr,
+    htPseudoSrcPort,
+    htPseudoDstPort,
+    htPseudoEnd // largest pseudo-header value plus 1 (for iteration)
 } FieldType;
 
 /// PROXY protocol 'command' field value
@@ -76,9 +78,9 @@ public:
 
 } // namespace Two
 
-typedef std::map<SBuf, Two::FieldType> FieldMap;
-/// a mapping between pseudo header names and ids
-extern const FieldMap PseudoHeaderFields;
+/// \returns human-friendly PROXY protocol field name for the given field type
+/// from the [htPseudoBegin,htPseudoEnd) range
+const SBuf &PseudoFieldTypeToFieldName(const Two::FieldType);
 
 /// Parses human-friendly PROXY protocol field type representation.
 /// Only pseudo headers can (and should) be represented by their names.
index da3aef46a3801573ee48739ad25f0f275dded893..cff8804e18162ec47ce4cab55a599c961e5ec517 100644 (file)
@@ -7,6 +7,7 @@
  */
 
 #include "squid.h"
+#include "base/EnumIterator.h"
 #include "proxyp/Elements.h"
 #include "proxyp/Header.h"
 #include "sbuf/Stream.h"
@@ -24,10 +25,10 @@ SBuf
 ProxyProtocol::Header::toMime() const
 {
     SBufStream result;
-    for (const auto &p: PseudoHeaderFields) {
-        const auto value = getValues(p.second);
+    for (const auto fieldType: EnumRange(Two::htPseudoBegin, Two::htPseudoEnd)) {
+        const auto value = getValues(fieldType);
         if (!value.isEmpty())
-            result << p.first << ": " << value << "\r\n";
+            result << PseudoFieldTypeToFieldName(fieldType) << ": " << value << "\r\n";
     }
     // cannot reuse Header::getValues(): need the original TLVs layout
     for (const auto &tlv: tlvs)