]>
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
.buf() << " " << method_point
<< " " << bypass
);
68 method
= parseMethod(method_point
);
69 point
= parseVectPoint(method_point
);
71 debugs(3, 5, HERE
<< cfg_filename
<< ':' << config_lineno
<< ": " <<
72 "service_configConfig is " << methodStr() << "_" << vectPointStr());
74 // TODO: find core code that parses URLs and extracts various parts
76 // extract scheme and use it as the service_configConfig protocol
77 const char *schemeSuffix
= "://";
78 if (const char *schemeEnd
= uri
.pos(schemeSuffix
))
79 protocol
.limitInit(uri
.buf(), schemeEnd
- uri
.buf());
80 debugs(3, 5, HERE
<< cfg_filename
<< ':' << config_lineno
<< ": " <<
81 "service protocol is " << protocol
);
86 const char *s
= uri
.buf() + protocol
.size() + strlen(schemeSuffix
);
90 bool have_port
= false;
92 if ((e
= strchr(s
, ':')) != NULL
) {
94 } else if ((e
= strchr(s
, '/')) != NULL
) {
101 host
.limitInit(s
, len
);
108 if ((e
= strchr(s
, '/')) != NULL
) {
110 const unsigned long p
= strtoul(s
, &t
, 0);
112 if (p
> 65535) // port value is too high
115 port
= static_cast<int>(p
);
117 if (t
!= e
) // extras after the port
127 // if no port, the caller may use service_configConfigs or supply the default if neeeded
134 debugs(3, 0, HERE
<< cfg_filename
<< ':' << config_lineno
<< ": " <<
135 "long resource name (>1024), probably wrong");
138 resource
.limitInit(s
, len
+ 1);
140 if ((bypass
!= 0) && (bypass
!= 1)) {
141 debugs(3, 0, HERE
<< cfg_filename
<< ':' << config_lineno
<< ": " <<
142 "wrong bypass value; 0 or 1 expected: " << bypass
);