]> git.ipfire.org Git - thirdparty/squid.git/blobdiff - src/HttpHeaderTools.h
SourceFormat Enforcement
[thirdparty/squid.git] / src / HttpHeaderTools.h
index 781a7e471124adc04a24015185a96796ef11666b..822d93f66d3825d874b60608914e9211b8373863 100644 (file)
@@ -1,34 +1,45 @@
+/*
+ * Copyright (C) 1996-2015 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.
+ */
+
 #ifndef SQUID_HTTPHEADERTOOLS_H
 #define SQUID_HTTPHEADERTOOLS_H
 
+#include "acl/forward.h"
 #include "format/Format.h"
 #include "HttpHeader.h"
 #include "typedefs.h"
 
-#if HAVE_LIST
+#include <functional>
 #include <list>
-#endif
-#if HAVE_MAP
 #include <map>
-#endif
-#if HAVE_STRING
 #include <string>
+#if HAVE_STRINGS_H
+#include <strings.h>
 #endif
 
 class HeaderWithAcl;
+class HttpHeader;
+class HttpHeaderFieldInfo;
+class HttpRequest;
+class StoreEntry;
+class String;
+
 typedef std::list<HeaderWithAcl> HeaderWithAclList;
 
-class acl_access;
-class header_mangler
+// Currently a POD
+class headerMangler
 {
 public:
     acl_access *access_list;
     char *replacement;
 };
 
-class StoreEntry;
-
-/// A collection of header_mangler objects for a given message kind.
+/// A collection of headerMangler objects for a given message kind.
 class HeaderManglers
 {
 public:
@@ -36,10 +47,10 @@ public:
     ~HeaderManglers();
 
     /// returns a header mangler for field e or nil if none was specified
-    const header_mangler *find(const HttpHeaderEntry &e) const;
+    const headerMangler *find(const HttpHeaderEntry &e) const;
 
     /// returns a mangler for the named header (known or custom)
-    header_mangler *track(const char *name);
+    headerMangler *track(const char *name);
 
     /// updates mangler for the named header with a replacement value
     void setReplacement(const char *name, const char *replacementValue);
@@ -50,17 +61,27 @@ public:
     void dumpReplacement(StoreEntry *entry, const char *optionName) const;
 
 private:
+    /// Case-insensitive std::string "less than" comparison functor.
+    /// Fast version recommended by Meyers' "Effective STL" for ASCII c-strings.
+    class NoCaseLessThan: public std::binary_function<std::string, std::string, bool>
+    {
+    public:
+        bool operator()(const std::string &lhs, const std::string &rhs) const {
+            return strcasecmp(lhs.c_str(), rhs.c_str()) < 0;
+        }
+    };
+
     /// a name:mangler map; optimize: use unordered map or some such
-    typedef std::map<std::string, header_mangler> ManglersByName;
+    typedef std::map<std::string, headerMangler, NoCaseLessThan> ManglersByName;
 
     /// one mangler for each known header
-    header_mangler known[HDR_ENUM_END];
+    headerMangler known[HDR_ENUM_END];
 
     /// one mangler for each custom header
     ManglersByName custom;
 
     /// configured if some mangling ACL applies to all header names
-    header_mangler all;
+    headerMangler all;
 
 private:
     /* not implemented */
@@ -68,11 +89,10 @@ private:
     HeaderManglers &operator =(const HeaderManglers &);
 };
 
-class ACLList;
 class HeaderWithAcl
 {
 public:
-    HeaderWithAcl() :  aclList(NULL), fieldId (HDR_BAD_HDR), quoted(false) {}
+    HeaderWithAcl() : aclList(NULL), valueFormat(NULL), fieldId(HDR_BAD_HDR), quoted(false) {}
 
     /// HTTP header field name
     std::string fieldName;
@@ -93,24 +113,20 @@ public:
     bool quoted;
 };
 
-extern int httpHeaderParseOffset(const char *start, int64_t * off);
+int httpHeaderParseOffset(const char *start, int64_t * off);
 
-class HttpHeader;
-class HttpHeaderFieldInfo;
-class HttpRequest;
-class String;
+HttpHeaderFieldInfo *httpHeaderBuildFieldsInfo(const HttpHeaderFieldAttrs * attrs, int count);
+void httpHeaderDestroyFieldsInfo(HttpHeaderFieldInfo * info, int count);
+http_hdr_type httpHeaderIdByName(const char *name, size_t name_len, const HttpHeaderFieldInfo * attrs, int end);
+http_hdr_type httpHeaderIdByNameDef(const char *name, int name_len);
+const char *httpHeaderNameById(int id);
+int httpHeaderHasConnDir(const HttpHeader * hdr, const char *directive);
+int httpHeaderParseInt(const char *start, int *val);
+void httpHeaderPutStrf(HttpHeader * hdr, http_hdr_type id, const char *fmt,...) PRINTF_FORMAT_ARG3;
 
-extern HttpHeaderFieldInfo *httpHeaderBuildFieldsInfo(const HttpHeaderFieldAttrs * attrs, int count);
-extern void httpHeaderDestroyFieldsInfo(HttpHeaderFieldInfo * info, int count);
-extern http_hdr_type httpHeaderIdByName(const char *name, size_t name_len, const HttpHeaderFieldInfo * attrs, int end);
-extern http_hdr_type httpHeaderIdByNameDef(const char *name, int name_len);
-extern const char *httpHeaderNameById(int id);
-extern int httpHeaderHasConnDir(const HttpHeader * hdr, const char *directive);
-extern int httpHeaderParseInt(const char *start, int *val);
-extern void httpHeaderPutStrf(HttpHeader * hdr, http_hdr_type id, const char *fmt,...) PRINTF_FORMAT_ARG3;
+const char *getStringPrefix(const char *str, size_t len);
 
-extern const char *getStringPrefix(const char *str, const char *end);
-
-extern void httpHdrMangleList(HttpHeader *, HttpRequest *, int req_or_rep);
+void httpHdrMangleList(HttpHeader *, HttpRequest *, int req_or_rep);
 
 #endif
+