]>
Commit | Line | Data |
---|---|---|
1 | /* | |
2 | * Copyright (C) 1996-2025 The Squid Software Foundation and contributors | |
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 | ||
9 | #ifndef SQUID_SRC_CONFIGOPTION_H | |
10 | #define SQUID_SRC_CONFIGOPTION_H | |
11 | ||
12 | #include <iosfwd> | |
13 | #include <vector> | |
14 | ||
15 | class StoreEntry; | |
16 | class ConfigParser; | |
17 | ||
18 | namespace Configuration { | |
19 | ||
20 | /// Interface for basic/low-level manipulation of a squid.conf directive value. | |
21 | /// Hides T's declarations from squid.conf parsing/reconfiguring/reporting code. | |
22 | /// | |
23 | /// Implementations/specializations must not modify the current configuration | |
24 | /// (i.e. the Config objects and similar/related global state). To facilitate | |
25 | /// reuse, implementations/specializations should also be independent from any | |
26 | /// specific configuration directive name and its squid.conf location. | |
27 | /// | |
28 | /// TODO: Support multi-directive components of various kinds. | |
29 | template <class T> | |
30 | class Component | |
31 | { | |
32 | public: | |
33 | /* the code adding "TYPE: T" to cf.data.pre must specialize these */ | |
34 | ||
35 | /// creates a new T instance using the given parser; never returns nil | |
36 | static T Parse(ConfigParser &); | |
37 | ||
38 | /// reports the current T instance configuration in squid.conf format | |
39 | static void Print(std::ostream &, const T &); | |
40 | ||
41 | /// destroys Parse() result | |
42 | static void Free(T); | |
43 | }; | |
44 | ||
45 | } // namespace Configuration | |
46 | ||
47 | /* | |
48 | * Deprecated squid.conf option wrappers used by cache_dir handling code. These | |
49 | * classes are similar to Configuration::Component<T>, but they merge T with T | |
50 | * parsing API, making them ill-suited for handling SquidConfig data members | |
51 | * with built-in C++ types and, more importantly, forcing SquidConfig users to | |
52 | * know about parsing/dumping/freeing capabilities of each SquidConfig | |
53 | * component. They also do not hide T details from the generic squid.conf | |
54 | * parsing code -- one has to provide a type-specific parse_T() for each T. | |
55 | */ | |
56 | ||
57 | class ConfigOption | |
58 | { | |
59 | ||
60 | public: | |
61 | virtual ~ConfigOption() {} | |
62 | ||
63 | virtual bool parse(char const *option, const char *value, int reconfiguring) = 0; | |
64 | virtual void dump(StoreEntry * e) const = 0; | |
65 | }; | |
66 | ||
67 | class ConfigOptionVector : public ConfigOption | |
68 | { | |
69 | ||
70 | public: | |
71 | ~ConfigOptionVector() override; | |
72 | bool parse(char const *option, const char *value, int reconfiguring) override; | |
73 | void dump(StoreEntry * e) const override; | |
74 | std::vector<ConfigOption *>options; | |
75 | }; | |
76 | ||
77 | template <class C> | |
78 | class ConfigOptionAdapter : public ConfigOption | |
79 | { | |
80 | ||
81 | public: | |
82 | ConfigOptionAdapter(C& theObject, bool (C::*parseFP)(char const *option, const char *value, int reconfiguring), void (C::*dumpFP)(StoreEntry * e) const) : object(theObject), parser(parseFP), dumper(dumpFP) {} | |
83 | ||
84 | bool parse(char const *option, const char *value, int isaReconf) override { | |
85 | if (parser) | |
86 | return (object.*parser)(option, value, isaReconf); | |
87 | ||
88 | return false; | |
89 | } | |
90 | ||
91 | void dump(StoreEntry * e) const override { | |
92 | if (dumper) | |
93 | (object.*dumper)(e); | |
94 | } | |
95 | ||
96 | private: | |
97 | C &object; | |
98 | bool (C::*parser)(char const *option, const char *value, int reconfiguring) ; | |
99 | void (C::*dumper)(StoreEntry * e) const; | |
100 | }; | |
101 | ||
102 | #endif /* SQUID_SRC_CONFIGOPTION_H */ | |
103 |