21#if HAVE_LIBECAP_ADAPTER_SERVICE_H
22#include <libecap/adapter/service.h>
24#if HAVE_LIBECAP_COMMON_OPTIONS_H
25#include <libecap/common/options.h>
27#if HAVE_LIBECAP_COMMON_NAME_H
28#include <libecap/common/name.h>
30#if HAVE_LIBECAP_COMMON_NAMED_VALUES_H
31#include <libecap/common/named_values.h>
38typedef std::map<std::string, Adaptation::Ecap::ServiceRep::AdapterService>
AdapterServices;
54 typedef libecap::Name
Name;
55 typedef libecap::Area
Area;
60 const libecap::Area
option(
const libecap::Name &name)
const override;
61 void visitEachOption(libecap::NamedValueVisitor &visitor)
const override;
89 return Area(master.bypass ?
"1" :
"0", 1);
93 typedef Master::Extensions::const_iterator MECI;
94 for (MECI i = master.extensions.begin(); i != master.extensions.end(); ++i) {
96 return Area(i->second.data(), i->second.size());
109 typedef Master::Extensions::const_iterator MECI;
110 for (MECI i = master.extensions.begin(); i != master.extensions.end(); ++i)
111 visitor.visit(
Name(i->first), Area::FromTempString(i->second));
120 static const struct timeval maxTimeout = {
124 struct timeval timeout = maxTimeout;
126 kickAsyncServices(timeout);
127 if (timeout.tv_sec == maxTimeout.tv_sec && timeout.tv_usec == maxTimeout.tv_usec)
130 debugs(93, 7,
"timeout: " << timeout.tv_sec <<
"s+" << timeout.tv_usec <<
"us");
133 if (timeout.tv_sec >= std::numeric_limits<int>::max()/1000 - 1000)
134 return std::numeric_limits<int>::max();
136 return timeout.tv_sec*1000 + timeout.tv_usec/1000;
149 typedef AdapterServices::iterator ASI;
157 s->second->suspend(timeout);
182 if (!cfg().connectionEncryption.configured())
183 writeableCfg().connectionEncryption.defaultTo(
true);
187 tryConfigureAndStart();
189 }
catch (
const std::exception &e) {
190 if (!handleFinalizeFailure(e.what()))
193 if (!handleFinalizeFailure(
"unrecognized exception"))
198 debugs(93,
DBG_IMPORTANT,
"WARNING: configured ecap_service was not loaded: " << cfg().uri);
206 debugs(93,2,
"configuring eCAP service: " << theService->uri());
208 theService->configure(cfgRep);
213 if (theService->makesAsyncXactions()) {
224 const bool salvage = cfg().bypass;
226 const char *kind = salvage ?
"optional" :
"essential";
227 debugs(93, level,
"ERROR: failed to start " << kind <<
" eCAP service: " <<
228 cfg().uri <<
":\n" <<
error);
235 debugs(93, level,
"WARNING: " << kind <<
" eCAP service is " <<
236 "down after initialization failure: " << cfg().uri);
248 return bool(theService);
254 SBuf nonConstUrlPath = urlPath;
256 return theService->wantsUrl(nonConstUrlPath.
c_str());
295 buf.
append(
",detached", 9);
327 TheServices[adapterService->uri()] = adapterService;
328 debugs(93, 3,
"stored eCAP module service: " << adapterService->uri());
336 debugs(93, 3,
"unregistered eCAP module service: " << serviceUri);
340 debugs(93, 3,
"failed to unregister eCAP module service: " << serviceUri);
346 typedef AdapterServices::const_iterator ASCI;
350 for (Services::const_iterator cfged = cfgs.begin();
351 cfged != cfgs.end() && !found; ++cfged) {
352 found = (*cfged)->cfg().uri == loaded->second->uri().c_str();
356 "ecap_service config option: " << loaded->second->uri());
#define EVENT_LOOP_TIMEOUT
void error(char *format,...)
wraps Adaptation::Ecap::ServiceConfig to allow eCAP visitors
void visitEachOption(libecap::NamedValueVisitor &visitor) const override
const Master & master
the configuration being wrapped
ConfigRep(const Master &aMaster)
Adaptation::Ecap::ServiceConfig Master
const libecap::Area option(const libecap::Name &name) const override
manages async eCAP transactions
void kickAsyncServices(timeval &timeout)
resumes async transactions (if any) and returns true if they set a timeout
int checkEvents(int timeout) override
eCAP service configuration
ServiceRep(const ServiceConfigPointer &aConfig)
bool probed() const override
void tryConfigureAndStart()
attempts to configure and start eCAP service; the caller handles exceptions
bool wantsUrl(const SBuf &urlPath) const override
Adaptation::Initiate * makeXactLauncher(Http::Message *virginHeader, HttpRequest *virginCause, AccessLogEntry::Pointer &alp) override
bool handleFinalizeFailure(const char *error)
virtual const char * status() const
void noteFailure() override
bool detached() const override
whether detached() was called
libecap::shared_ptr< libecap::adapter::Service > AdapterService
void master(const AdapterXaction &aMaster)
libecap::shared_ptr< libecap::adapter::Xaction > AdapterXaction
static EventLoop * Running
void registerEngine(AsyncEngine *engine)
common parts of HttpRequest and HttpReply
void append(const char *c, int sz) override
char * content()
start of the added data
char const * termedBuf() const
#define debugs(SECTION, LEVEL, CONTENT)
static AdapterServices TheServices
all loaded services
std::map< std::string, Adaptation::Ecap::ServiceRep::AdapterService > AdapterServices
libecap::adapter::services indexed by their URI
static AdapterServices AsyncServices
configured services producing async transactions
void RegisterAdapterService(const ServiceRep::AdapterService &adapterService)
register loaded eCAP module service
const libecap::Name metaBypassable
an ecap_service parameter
void CheckUnusedAdapterServices(const Services &services)
check for loaded eCAP services without matching ecap_service in squid.conf
ServiceRep::AdapterService FindAdapterService(const String &serviceUri)
returns loaded eCAP module service by service uri
void UnregisterAdapterService(const String &serviceUri)
unregister loaded eCAP module service by service uri
std::vector< Adaptation::ServicePointer > Services