]> git.ipfire.org Git - thirdparty/squid.git/blame - src/HttpHeaderTools.h
Fix http_hdr_type layering constraint violations in external_acl.cc
[thirdparty/squid.git] / src / HttpHeaderTools.h
CommitLineData
bbc27441 1/*
bde978a6 2 * Copyright (C) 1996-2015 The Squid Software Foundation and contributors
bbc27441
AJ
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
3b07476b
CT
9#ifndef SQUID_HTTPHEADERTOOLS_H
10#define SQUID_HTTPHEADERTOOLS_H
11
6f58d7d7 12#include "acl/forward.h"
f4698e0b 13#include "format/Format.h"
582c2af2 14#include "HttpHeader.h"
fc54b8d2 15#include "typedefs.h"
f4698e0b 16
620bc212 17#include <functional>
f4698e0b 18#include <list>
3b07476b 19#include <map>
3b07476b 20#include <string>
620bc212
AR
21#if HAVE_STRINGS_H
22#include <strings.h>
23#endif
3b07476b 24
f4698e0b 25class HeaderWithAcl;
001d55dc 26class HttpHeader;
001d55dc
FC
27class HttpRequest;
28class StoreEntry;
29class String;
30
f4698e0b
CT
31typedef std::list<HeaderWithAcl> HeaderWithAclList;
32
001d55dc
FC
33// Currently a POD
34class headerMangler
1b2f0924 35{
09bbee4c 36public:
3b07476b
CT
37 acl_access *access_list;
38 char *replacement;
39};
3b07476b 40
001d55dc 41/// A collection of headerMangler objects for a given message kind.
d3abcb0d
A
42class HeaderManglers
43{
3b07476b
CT
44public:
45 HeaderManglers();
46 ~HeaderManglers();
47
48 /// returns a header mangler for field e or nil if none was specified
001d55dc 49 const headerMangler *find(const HttpHeaderEntry &e) const;
3b07476b
CT
50
51 /// returns a mangler for the named header (known or custom)
001d55dc 52 headerMangler *track(const char *name);
3b07476b
CT
53
54 /// updates mangler for the named header with a replacement value
55 void setReplacement(const char *name, const char *replacementValue);
56
57 /// report the *_header_access part of the configuration
58 void dumpAccess(StoreEntry *entry, const char *optionName) const;
59 /// report the *_header_replace part of the configuration
60 void dumpReplacement(StoreEntry *entry, const char *optionName) const;
61
62private:
620bc212
AR
63 /// Case-insensitive std::string "less than" comparison functor.
64 /// Fast version recommended by Meyers' "Effective STL" for ASCII c-strings.
6e422d23
A
65 class NoCaseLessThan: public std::binary_function<std::string, std::string, bool>
66 {
620bc212
AR
67 public:
68 bool operator()(const std::string &lhs, const std::string &rhs) const {
69 return strcasecmp(lhs.c_str(), rhs.c_str()) < 0;
70 }
71 };
72
3b07476b 73 /// a name:mangler map; optimize: use unordered map or some such
620bc212 74 typedef std::map<std::string, headerMangler, NoCaseLessThan> ManglersByName;
3b07476b
CT
75
76 /// one mangler for each known header
001d55dc 77 headerMangler known[HDR_ENUM_END];
3b07476b
CT
78
79 /// one mangler for each custom header
80 ManglersByName custom;
81
82 /// configured if some mangling ACL applies to all header names
001d55dc 83 headerMangler all;
3b07476b
CT
84
85private:
86 /* not implemented */
87 HeaderManglers(const HeaderManglers &);
88 HeaderManglers &operator =(const HeaderManglers &);
89};
f4698e0b 90
f4698e0b
CT
91class HeaderWithAcl
92{
93public:
796ca6d3 94 HeaderWithAcl() : aclList(NULL), valueFormat(NULL), fieldId(HDR_BAD_HDR), quoted(false) {}
f4698e0b
CT
95
96 /// HTTP header field name
97 std::string fieldName;
98
99 /// HTTP header field value, possibly with macros
100 std::string fieldValue;
101
102 /// when the header field should be added (always if nil)
103 ACLList *aclList;
104
105 /// compiled HTTP header field value (no macros)
106 Format::Format *valueFormat;
107
108 /// internal ID for "known" headers or HDR_OTHER
109 http_hdr_type fieldId;
110
111 /// whether fieldValue may contain macros
112 bool quoted;
113};
582c2af2 114
001d55dc 115int httpHeaderParseOffset(const char *start, int64_t * off);
fc54b8d2 116
001d55dc
FC
117int httpHeaderHasConnDir(const HttpHeader * hdr, const char *directive);
118int httpHeaderParseInt(const char *start, int *val);
119void httpHeaderPutStrf(HttpHeader * hdr, http_hdr_type id, const char *fmt,...) PRINTF_FORMAT_ARG3;
fc54b8d2 120
81858ebc 121const char *getStringPrefix(const char *str, size_t len);
1dff8715 122
001d55dc 123void httpHdrMangleList(HttpHeader *, HttpRequest *, int req_or_rep);
f01162cf 124
3b07476b 125#endif
f53969cc 126