]> git.ipfire.org Git - thirdparty/squid.git/blame - src/ConfigOption.h
Simplify appending SBuf to String (#2108)
[thirdparty/squid.git] / src / ConfigOption.h
CommitLineData
b9ae18aa 1/*
1f7b830e 2 * Copyright (C) 1996-2025 The Squid Software Foundation and contributors
b9ae18aa 3 *
bbc27441
AJ
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.
b9ae18aa 7 */
bbc27441 8
ff9d9458
FC
9#ifndef SQUID_SRC_CONFIGOPTION_H
10#define SQUID_SRC_CONFIGOPTION_H
b9ae18aa 11
2e6535ab 12#include <iosfwd>
c8ea3cc0 13#include <vector>
b9ae18aa 14
fafe8849 15class StoreEntry;
2e6535ab 16class ConfigParser;
fafe8849 17
2e6535ab
AR
18namespace 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.
29template <class T>
30class Component
31{
32public:
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 */
b9ae18aa 56
57class ConfigOption
58{
59
60public:
61 virtual ~ConfigOption() {}
62
63 virtual bool parse(char const *option, const char *value, int reconfiguring) = 0;
6ca34f6f 64 virtual void dump(StoreEntry * e) const = 0;
b9ae18aa 65};
66
67class ConfigOptionVector : public ConfigOption
68{
69
70public:
337b9aa4
AR
71 ~ConfigOptionVector() override;
72 bool parse(char const *option, const char *value, int reconfiguring) override;
73 void dump(StoreEntry * e) const override;
c8ea3cc0 74 std::vector<ConfigOption *>options;
b9ae18aa 75};
76
77template <class C>
b9ae18aa 78class ConfigOptionAdapter : public ConfigOption
79{
80
81public:
6ca34f6f 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) {}
b9ae18aa 83
337b9aa4 84 bool parse(char const *option, const char *value, int isaReconf) override {
b9ae18aa 85 if (parser)
18ec8500 86 return (object.*parser)(option, value, isaReconf);
b9ae18aa 87
88 return false;
89 }
90
337b9aa4 91 void dump(StoreEntry * e) const override {
b9ae18aa 92 if (dumper)
6ca34f6f 93 (object.*dumper)(e);
b9ae18aa 94 }
95
96private:
97 C &object;
6ca34f6f 98 bool (C::*parser)(char const *option, const char *value, int reconfiguring) ;
b9ae18aa 99 void (C::*dumper)(StoreEntry * e) const;
100};
101
ff9d9458 102#endif /* SQUID_SRC_CONFIGOPTION_H */
f53969cc 103