]>
git.ipfire.org Git - thirdparty/squid.git/blob - src/adaptation/ServiceConfig.cc
2 * DEBUG: section 93 Adaptation
6 #include "ConfigParser.h"
7 #include "adaptation/ServiceConfig.h"
10 Adaptation::ServiceConfig::ServiceConfig():
11 port(-1), method(methodNone
), point(pointNone
),
12 bypass(false), routing(false), ipv6(false)
16 Adaptation::ServiceConfig::methodStr() const
18 return Adaptation::methodStr(method
);
22 Adaptation::ServiceConfig::vectPointStr() const
24 return Adaptation::vectPointStr(point
);
28 Adaptation::ServiceConfig::parseMethod(const char *str
) const
30 if (!strncasecmp(str
, "REQMOD", 6))
31 return Adaptation::methodReqmod
;
33 if (!strncasecmp(str
, "RESPMOD", 7))
34 return Adaptation::methodRespmod
;
36 return Adaptation::methodNone
;
40 Adaptation::ServiceConfig::parseVectPoint(const char *service_configConfig
) const
42 const char *t
= service_configConfig
;
43 const char *q
= strchr(t
, '_');
48 if (!strcasecmp(t
, "precache"))
49 return Adaptation::pointPreCache
;
51 if (!strcasecmp(t
, "postcache"))
52 return Adaptation::pointPostCache
;
54 return Adaptation::pointNone
;
58 Adaptation::ServiceConfig::parse()
62 ConfigParser::ParseString(&key
);
63 ConfigParser::ParseString(&method_point
);
64 method
= parseMethod(method_point
.termedBuf());
65 point
= parseVectPoint(method_point
.termedBuf());
67 // reset optional parameters in case we are reconfiguring
68 bypass
= routing
= false;
70 // handle optional service name=value parameters
71 const char *lastOption
= NULL
;
72 bool grokkedUri
= false;
73 while (char *option
= strtok(NULL
, w_space
)) {
74 if (strcmp(option
, "0") == 0) { // backward compatibility
78 if (strcmp(option
, "1") == 0) { // backward compatibility
83 const char *name
= option
;
84 char *value
= strstr(option
, "=");
89 *value
= '\0'; // terminate option name
92 // TODO: warn if option is set twice?
94 if (strcmp(name
, "bypass") == 0)
95 grokked
= grokBool(bypass
, name
, value
);
96 else if (strcmp(name
, "routing") == 0)
97 grokked
= grokBool(routing
, name
, value
);
98 else if (strcmp(name
, "uri") == 0)
99 grokked
= grokkedUri
= grokUri(value
);
100 else if (strcmp(name
, "ipv6") == 0) {
101 grokked
= grokBool(ipv6
, name
, value
);
102 if (grokked
&& ipv6
&& !Ip::EnableIpv6
)
103 debugs(3, DBG_IMPORTANT
, "WARNING: IPv6 is disabled. ICAP service option ignored.");
105 grokked
= grokExtension(name
, value
);
111 // what is left must be the service URI
112 if (!grokkedUri
&& !grokUri(lastOption
))
115 // there should be nothing else left
116 if (const char *tail
= strtok(NULL
, w_space
)) {
117 debugs(3, 0, cfg_filename
<< ':' << config_lineno
<< ": " <<
118 "garbage after adaptation service URI: " << tail
);
122 debugs(3,5, cfg_filename
<< ':' << config_lineno
<< ": " <<
123 "adaptation_service " << key
<< ' ' <<
124 methodStr() << "_" << vectPointStr() << ' ' <<
125 bypass
<< routing
<< ' ' <<
132 Adaptation::ServiceConfig::grokUri(const char *value
)
134 // TODO: find core code that parses URLs and extracts various parts
135 // AYJ: most of this is duplicate of urlParse() in src/url.cc
137 if (!value
|| !*value
) {
138 debugs(3, 0, HERE
<< cfg_filename
<< ':' << config_lineno
<< ": " <<
139 "empty adaptation service URI");
145 // extract scheme and use it as the service_configConfig protocol
146 const char *schemeSuffix
= "://";
147 const String::size_type schemeEnd
= uri
.find(schemeSuffix
);
148 if (schemeEnd
!= String::npos
)
149 protocol
=uri
.substr(0,schemeEnd
);
151 debugs(3, 5, HERE
<< cfg_filename
<< ':' << config_lineno
<< ": " <<
152 "service protocol is " << protocol
);
154 if (protocol
.size() == 0)
158 const char *s
= uri
.termedBuf() + protocol
.size() + strlen(schemeSuffix
);
162 bool have_port
= false;
167 if ((t
= strchr(s
, ']')) == NULL
)
172 if ((e
= strchr(t
, ':')) != NULL
) {
174 } else if ((e
= strchr(t
, '/')) != NULL
) {
180 if ((e
= strchr(s
, ':')) != NULL
) {
182 } else if ((e
= strchr(s
, '/')) != NULL
) {
190 host
.limitInit(s
, len
);
197 if ((e
= strchr(s
, '/')) != NULL
) {
199 const unsigned long p
= strtoul(s
, &t
, 0);
201 if (p
> 65535) // port value is too high
204 port
= static_cast<int>(p
);
206 if (t
!= e
) // extras after the port
216 // if no port, the caller may use service_configConfigs or supply the default if neeeded
223 debugs(3, 0, HERE
<< cfg_filename
<< ':' << config_lineno
<< ": " <<
224 "long resource name (>1024), probably wrong");
227 resource
.limitInit(s
, len
+ 1);
233 Adaptation::ServiceConfig::grokBool(bool &var
, const char *name
, const char *value
)
235 if (!strcmp(value
, "0") || !strcmp(value
, "off"))
237 else if (!strcmp(value
, "1") || !strcmp(value
, "on"))
240 debugs(3, 0, HERE
<< cfg_filename
<< ':' << config_lineno
<< ": " <<
241 "wrong value for boolean " << name
<< "; " <<
242 "'0', '1', 'on', or 'off' expected but got: " << value
);
250 Adaptation::ServiceConfig::grokExtension(const char *name
, const char *value
)
252 // we do not accept extensions by default
253 debugs(3, DBG_CRITICAL
, cfg_filename
<< ':' << config_lineno
<< ": " <<
254 "ERROR: unknown adaptation service option: " <<
255 name
<< '=' << value
);