]>
git.ipfire.org Git - thirdparty/squid.git/blob - src/adaptation/ServiceConfig.cc
6 #include "ConfigParser.h"
7 #include "adaptation/ServiceConfig.h"
9 Adaptation::ServiceConfig::ServiceConfig():
10 port(-1), method(methodNone
), point(pointNone
), bypass(false)
14 Adaptation::ServiceConfig::methodStr() const
16 return Adaptation::methodStr(method
);
20 Adaptation::ServiceConfig::vectPointStr() const
22 return Adaptation::vectPointStr(point
);
26 Adaptation::ServiceConfig::parseMethod(const char *str
) const
28 if (!strncasecmp(str
, "REQMOD", 6))
29 return Adaptation::methodReqmod
;
31 if (!strncasecmp(str
, "RESPMOD", 7))
32 return Adaptation::methodRespmod
;
34 return Adaptation::methodNone
;
38 Adaptation::ServiceConfig::parseVectPoint(const char *service_configConfig
) const
40 const char *t
= service_configConfig
;
41 const char *q
= strchr(t
, '_');
46 if (!strcasecmp(t
, "precache"))
47 return Adaptation::pointPreCache
;
49 if (!strcasecmp(t
, "postcache"))
50 return Adaptation::pointPostCache
;
52 return Adaptation::pointNone
;
56 Adaptation::ServiceConfig::parse()
58 char *method_point
= NULL
;
60 ConfigParser::ParseString(&key
);
61 ConfigParser::ParseString(&method_point
);
62 ConfigParser::ParseBool(&bypass
);
63 ConfigParser::ParseString(&uri
);
65 debugs(3, 5, HERE
<< cfg_filename
<< ':' << config_lineno
<< ": " <<
66 key
<< " " << method_point
<< " " << bypass
);
68 method
= parseMethod(method_point
);
69 point
= parseVectPoint(method_point
);
70 safe_free(method_point
);
72 debugs(3, 5, HERE
<< cfg_filename
<< ':' << config_lineno
<< ": " <<
73 "service_configConfig is " << methodStr() << "_" << vectPointStr());
75 // TODO: find core code that parses URLs and extracts various parts
77 // extract scheme and use it as the service_configConfig protocol
78 const char *schemeSuffix
= "://";
79 if (const String::size_type schemeEnd
=uri
.find(schemeSuffix
))
80 protocol
=uri
.substr(0,schemeEnd
-1);
82 debugs(3, 5, HERE
<< cfg_filename
<< ':' << config_lineno
<< ": " <<
83 "service protocol is " << protocol
);
85 if (protocol
.size() == 0)
89 const char *s
= uri
.termedBuf() + protocol
.size() + strlen(schemeSuffix
);
93 bool have_port
= false;
95 if ((e
= strchr(s
, ':')) != NULL
) {
97 } else if ((e
= strchr(s
, '/')) != NULL
) {
104 host
.limitInit(s
, len
);
111 if ((e
= strchr(s
, '/')) != NULL
) {
113 const unsigned long p
= strtoul(s
, &t
, 0);
115 if (p
> 65535) // port value is too high
118 port
= static_cast<int>(p
);
120 if (t
!= e
) // extras after the port
130 // if no port, the caller may use service_configConfigs or supply the default if neeeded
137 debugs(3, 0, HERE
<< cfg_filename
<< ':' << config_lineno
<< ": " <<
138 "long resource name (>1024), probably wrong");
141 resource
.limitInit(s
, len
+ 1);
143 if ((bypass
!= 0) && (bypass
!= 1)) {
144 debugs(3, 0, HERE
<< cfg_filename
<< ':' << config_lineno
<< ": " <<
145 "wrong bypass value; 0 or 1 expected: " << bypass
);