]> git.ipfire.org Git - thirdparty/squid.git/blob - src/adaptation/Config.h
adaptation_meta option
[thirdparty/squid.git] / src / adaptation / Config.h
1 #ifndef SQUID_ADAPTATION__CONFIG_H
2 #define SQUID_ADAPTATION__CONFIG_H
3
4 #include "event.h"
5 #include "acl/Gadgets.h"
6 #include "base/AsyncCall.h"
7 #include "adaptation/forward.h"
8 #include "adaptation/Elements.h"
9
10 class acl_access;
11 class ConfigParser;
12
13 namespace Adaptation
14 {
15
16 class Config
17 {
18 public:
19 static void Finalize(bool enable);
20
21 static void ParseServiceSet(void);
22 static void ParseServiceChain(void);
23 static void ParseMetaHeader(ConfigParser &parser);
24 static void FreeMetaHeader();
25 static void DumpMetaHeader(StoreEntry *, const char *);
26
27 static void ParseAccess(ConfigParser &parser);
28 static void FreeAccess(void);
29 static void DumpAccess(StoreEntry *, const char *);
30
31 friend class AccessCheck;
32
33 public:
34 static bool Enabled; // true if at least one adaptation mechanism is
35
36 // these are global squid.conf options, documented elsewhere
37 static char *masterx_shared_name; // global TODO: do we need TheConfig?
38 static int service_iteration_limit;
39 static int send_client_ip;
40 static int send_username;
41 static int use_indirect_client;
42
43 // Options below are accessed via Icap::TheConfig or Ecap::TheConfig
44 // TODO: move ICAP-specific options to Icap::Config and add TheConfig
45 int onoff;
46 int service_failure_limit;
47 time_t oldest_service_failure;
48 int service_revival_delay;
49
50 /**
51 * Used to store meta headers. The meta headers are custom
52 * ICAP request headers or ECAP options used to pass custom
53 * transaction-state related meta information to a service.
54 */
55 class MetaHeader: public RefCountable {
56 public:
57 typedef RefCount<MetaHeader> Pointer;
58 /// Stores a value for the meta header.
59 class Value: public RefCountable {
60 public:
61 typedef RefCount<Value> Pointer;
62 String value; ///< a header value
63 ACLList *aclList; ///< The access list used to determine if this value is valid for a request
64 explicit Value(const String &aVal) : value(aVal), aclList(NULL) {}
65 ~Value();
66 };
67 typedef Vector<Value::Pointer> Values;
68
69 explicit MetaHeader(const String &aName): name(aName) {}
70
71 /**
72 * Adds a value to the meta header and returns a pointer to the
73 * related Value object.
74 */
75 Value::Pointer addValue(const String &value);
76
77 /**
78 * Walks through the possible values list of the meta and selects
79 * the first value which matches the given HttpRequest and HttpReply
80 * or NULL if none matches.
81 */
82 const char *match(HttpRequest *request, HttpReply *reply);
83 String name; ///< The meta header name
84 Values values; ///< The possible values list for the meta header
85 };
86 typedef Vector<MetaHeader::Pointer> MetaHeaders;
87 static MetaHeaders metaHeaders; ///< The list of configured meta headers
88
89 /**
90 * Adds a header to the meta headers list and returns a pointer to the
91 * related metaHeaders object. If the header name already exists in list,
92 * returns a pointer to the existing object.
93 */
94 static MetaHeader::Pointer addMetaHeader(const String &header);
95
96 typedef Vector<ServiceConfigPointer> ServiceConfigs;
97 ServiceConfigs serviceConfigs;
98
99 Config();
100 virtual ~Config();
101
102 void parseService(void);
103 void freeService(void);
104 void dumpService(StoreEntry *, const char *) const;
105 ServicePointer findService(const String&);
106
107 /**
108 * Creates and starts the adaptation services. In the case the adaptation
109 * mechanism is disabled then removes any reference to the services from
110 * access rules and service groups, and returns false.
111 * \return true if the services are ready and running, false otherwise
112 */
113 virtual bool finalize();
114
115 protected:
116 /// Removes any reference to the services from configuration
117 virtual void clear();
118
119 /// creates service configuration object that will parse and keep cfg info
120 virtual ServiceConfig *newServiceConfig() const;
121
122 /// Removes the given service from all service groups.
123 void removeService(const String& service);
124
125 /// Removes access rules of the given service or group
126 void removeRule(const String& id);
127
128 private:
129 Config(const Config &); // unsupported
130 Config &operator =(const Config &); // unsupported
131
132 virtual ServicePointer createService(const ServiceConfigPointer &cfg) = 0;
133
134 static void ParseServiceGroup(ServiceGroupPointer group);
135 static void FreeServiceGroups(void);
136 static void DumpServiceGroups(StoreEntry *, const char *);
137 };
138
139 } // namespace Adaptation
140
141 #endif /* SQUID_ADAPTATION__CONFIG_H */