------------------------------------------------------------ revno: 13125 revision-id: chtsanti@users.sourceforge.net-20131112144850-0olwk4546blau8z6 parent: squid3@treenet.co.nz-20131103043023-2o2jp6j90hxddgst committer: Christos Tsantilas branch nick: trunk timestamp: Tue 2013-11-12 16:48:50 +0200 message: adaptation_service ACL This patch adds the new ACL adaptation_service, to match the name of: - an adaptation service or group that had been applied to the master transaction in the past - an adaptation service or group that is being applied to the master transaction now An adaptation group is formed by adaptation_service_chain or adaptation_service_set directives. Both REQMOD and RESPMOD services, successful or failed service applications matches this acl. This is a Measurement Factory project ------------------------------------------------------------ # Bazaar merge directive format 2 (Bazaar 0.90) # revision_id: chtsanti@users.sourceforge.net-20131112144850-\ # 0olwk4546blau8z6 # target_branch: http://bzr.squid-cache.org/bzr/squid3/trunk/ # testament_sha1: e630c9f4c1376337a052299fbaf703f1674be9d8 # timestamp: 2013-11-12 14:55:29 +0000 # source_branch: http://bzr.squid-cache.org/bzr/squid3/trunk/ # base_revision_id: squid3@treenet.co.nz-20131103043023-\ # 2o2jp6j90hxddgst # # Begin patch === modified file 'src/AclRegs.cc' --- src/AclRegs.cc 2013-10-25 00:13:46 +0000 +++ src/AclRegs.cc 2013-11-12 14:48:50 +0000 @@ -5,6 +5,10 @@ does not get linked in, because nobody is using these classes by name. */ +#if USE_ADAPTATION +#include "acl/AdaptationService.h" +#include "acl/AdaptationServiceData.h" +#endif #include "acl/AllOf.h" #include "acl/AnyOf.h" #if USE_SQUID_EUI @@ -193,3 +197,8 @@ ACL::Prototype ACLNote::RegistryProtoype(&ACLNote::RegistryEntry_, "note"); ACLStrategised ACLNote::RegistryEntry_(new ACLNoteData, ACLNoteStrategy::Instance(), "note"); + +#if USE_ADAPTATION +ACL::Prototype ACLAdaptationService::RegistryProtoype(&ACLAdaptationService::RegistryEntry_, "adaptation_service"); +ACLStrategised ACLAdaptationService::RegistryEntry_(new ACLAdaptationServiceData, ACLAdaptationServiceStrategy::Instance(), "adaptation_service"); +#endif === added file 'src/acl/AdaptationService.cc' --- src/acl/AdaptationService.cc 1970-01-01 00:00:00 +0000 +++ src/acl/AdaptationService.cc 2013-11-12 14:48:50 +0000 @@ -0,0 +1,34 @@ +#include "squid.h" +#include "acl/Checklist.h" +#include "acl/IntRange.h" +#include "acl/AdaptationService.h" +#include "adaptation/Config.h" +#include "adaptation/History.h" +#include "HttpRequest.h" + +int +ACLAdaptationServiceStrategy::match (ACLData * &data, ACLFilledChecklist *checklist, ACLFlags &) +{ + HttpRequest::Pointer request = checklist->request; + if (request == NULL) + return 0; + Adaptation::History::Pointer ah = request->adaptHistory(); + if (ah == NULL) + return 0; + + Adaptation::History::AdaptationServices::iterator it; + for (it = ah->theAdaptationServices.begin(); it != ah->theAdaptationServices.end(); ++it) { + if (data->match(it->c_str())) + return 1; + } + + return 0; +} + +ACLAdaptationServiceStrategy * +ACLAdaptationServiceStrategy::Instance() +{ + return &Instance_; +} + +ACLAdaptationServiceStrategy ACLAdaptationServiceStrategy::Instance_; === added file 'src/acl/AdaptationService.h' --- src/acl/AdaptationService.h 1970-01-01 00:00:00 +0000 +++ src/acl/AdaptationService.h 2013-11-12 14:48:50 +0000 @@ -0,0 +1,35 @@ +#ifndef SQUID_ACLADAPTATIONSERVICE_H +#define SQUID_ACLADAPTATIONSERVICE_H + +#include "acl/Strategised.h" +#include "acl/Strategy.h" + +/// \ingroup ACLAPI +class ACLAdaptationServiceStrategy : public ACLStrategy +{ + +public: + virtual int match (ACLData * &, ACLFilledChecklist *, ACLFlags &); + static ACLAdaptationServiceStrategy *Instance(); + /** + * Not implemented to prevent copies of the instance. + */ + ACLAdaptationServiceStrategy(ACLAdaptationServiceStrategy const &); + +private: + static ACLAdaptationServiceStrategy Instance_; + ACLAdaptationServiceStrategy() {} + + ACLAdaptationServiceStrategy &operator = (ACLAdaptationServiceStrategy const &); +}; + +/// \ingroup ACLAPI +class ACLAdaptationService +{ + +private: + static ACL::Prototype RegistryProtoype; + static ACLStrategised RegistryEntry_; +}; + +#endif /* SQUID_ACLADAPTATIONSERVICE_H */ === added file 'src/acl/AdaptationServiceData.cc' --- src/acl/AdaptationServiceData.cc 1970-01-01 00:00:00 +0000 +++ src/acl/AdaptationServiceData.cc 2013-11-12 14:48:50 +0000 @@ -0,0 +1,39 @@ +#include "squid.h" +#include "acl/AdaptationServiceData.h" +#include "acl/Checklist.h" +#include "adaptation/Config.h" +#include "adaptation/ecap/Config.h" +#include "adaptation/icap/Config.h" +#include "adaptation/Service.h" +#include "adaptation/ServiceGroups.h" +#include "cache_cf.h" +#include "ConfigParser.h" +#include "Debug.h" +#include "wordlist.h" + +void +ACLAdaptationServiceData::parse() +{ + Adaptation::Config::needHistory = true; + while (char *t = ConfigParser::strtokFile()) { + if ( +#if USE_ECAP + Adaptation::Ecap::TheConfig.findServiceConfig(t) == NULL && +#endif +#if ICAP_CLIENT + Adaptation::Icap::TheConfig.findServiceConfig(t) == NULL && +#endif + Adaptation::FindGroup(t) == NULL) { + debugs(28, DBG_CRITICAL, "FATAL: Adaptation service/group " << t << " in adaptation_service acl is not defined"); + self_destruct(); + } + insert(t); + } +} + +ACLData * +ACLAdaptationServiceData::clone() const +{ + return new ACLAdaptationServiceData(*this); +} + === added file 'src/acl/AdaptationServiceData.h' --- src/acl/AdaptationServiceData.h 1970-01-01 00:00:00 +0000 +++ src/acl/AdaptationServiceData.h 2013-11-12 14:48:50 +0000 @@ -0,0 +1,21 @@ + +#ifndef SQUID_ADAPTATIONSERVICEDATA_H +#define SQUID_ADAPTATIONSERVICEDATA_H + +#include "acl/Acl.h" +#include "acl/Data.h" +#include "acl/StringData.h" + +/// \ingroup ACLAPI +class ACLAdaptationServiceData : public ACLStringData +{ +public: + ACLAdaptationServiceData() : ACLStringData() {} + ACLAdaptationServiceData(ACLAdaptationServiceData const &old) : ACLStringData(old) {}; + // Not implemented + ACLAdaptationServiceData &operator= (ACLAdaptationServiceData const &); + virtual void parse(); + virtual ACLData *clone() const; +}; + +#endif /* SQUID_ADAPTATIONSERVICEDATA_H */ === modified file 'src/acl/Makefile.am' --- src/acl/Makefile.am 2013-05-26 01:08:42 +0000 +++ src/acl/Makefile.am 2013-11-12 14:48:50 +0000 @@ -148,6 +148,14 @@ libacls_la_SOURCES += $(SSL_ACLS) endif +if USE_ADAPTATION +libacls_la_SOURCES += AdaptationService.h \ + AdaptationService.cc \ + AdaptationServiceData.h \ + AdaptationServiceData.cc +endif + + EXTRA_libacls_la_SOURCES += $(SSL_ACLS) === modified file 'src/acl/StringData.h' --- src/acl/StringData.h 2013-10-25 00:13:46 +0000 +++ src/acl/StringData.h 2013-11-12 14:48:50 +0000 @@ -49,7 +49,7 @@ virtual ~ACLStringData(); bool match(char const *); wordlist *dump(); - void parse(); + virtual void parse(); bool empty() const; virtual ACLData *clone() const; /// Insert a string data value === modified file 'src/adaptation/Config.cc' --- src/adaptation/Config.cc 2013-07-21 19:24:35 +0000 +++ src/adaptation/Config.cc 2013-11-12 14:48:50 +0000 @@ -67,6 +67,7 @@ NULL }; Notes Adaptation::Config::metaHeaders("ICAP header", metasBlacklist); +bool Adaptation::Config::needHistory = false; Adaptation::ServiceConfig* Adaptation::Config::newServiceConfig() const @@ -101,6 +102,18 @@ } } +Adaptation::ServiceConfigPointer +Adaptation::Config::findServiceConfig(const String &service) +{ + typedef ServiceConfigs::const_iterator SCI; + const ServiceConfigs& configs = serviceConfigs; + for (SCI cfg = configs.begin(); cfg != configs.end(); ++cfg) { + if ((*cfg)->key == service) + return *cfg; + } + return NULL; +} + void Adaptation::Config::removeRule(const String& id) { === modified file 'src/adaptation/Config.h' --- src/adaptation/Config.h 2013-10-25 00:13:46 +0000 +++ src/adaptation/Config.h 2013-11-12 14:48:50 +0000 @@ -49,6 +49,8 @@ static Notes metaHeaders; ///< The list of configured meta headers + static bool needHistory; ///< HttpRequest adaptation history should recorded + typedef Vector ServiceConfigs; ServiceConfigs serviceConfigs; @@ -58,7 +60,7 @@ void parseService(void); void freeService(void); void dumpService(StoreEntry *, const char *) const; - ServicePointer findService(const String&); + ServiceConfigPointer findServiceConfig(const String&); /** * Creates and starts the adaptation services. In the case the adaptation === modified file 'src/adaptation/History.cc' --- src/adaptation/History.cc 2012-09-03 08:58:40 +0000 +++ src/adaptation/History.cc 2013-11-12 14:48:50 +0000 @@ -149,6 +149,12 @@ } void +Adaptation::History::recordAdaptationService(SBuf &srvId) +{ + theAdaptationServices.push_back(srvId); +} + +void Adaptation::History::setFutureServices(const DynamicGroupCfg &services) { if (!theFutureServices.empty()) === modified file 'src/adaptation/History.h' --- src/adaptation/History.h 2013-10-25 00:13:46 +0000 +++ src/adaptation/History.h 2013-11-12 14:48:50 +0000 @@ -6,6 +6,7 @@ #include "base/Vector.h" #include "HttpHeader.h" #include "Notes.h" +#include "SBuf.h" #include "SquidString.h" namespace Adaptation @@ -46,6 +47,7 @@ /// store the last meta header fields received from the adaptation service void recordMeta(const HttpHeader *lm); + void recordAdaptationService(SBuf &srvId); public: /// Last received meta header (REQMOD or RESPMOD, whichever comes last). HttpHeader lastMeta; @@ -55,6 +57,9 @@ /// AccessLogEntry::notes when ALE becomes available NotePairs::Pointer metaHeaders; + typedef Vector AdaptationServices; + AdaptationServices theAdaptationServices; ///< The service groups used + /// sets future services for the Adaptation::AccessCheck to notice void setFutureServices(const DynamicGroupCfg &services); === modified file 'src/adaptation/Iterator.cc' --- src/adaptation/Iterator.cc 2013-10-25 00:13:46 +0000 +++ src/adaptation/Iterator.cc 2013-11-12 14:48:50 +0000 @@ -45,6 +45,19 @@ Adaptation::Initiate::start(); thePlan = ServicePlan(theGroup, filter()); + + // Add adaptation group name once and now, before + // dynamic groups change it at step() time. + if (Adaptation::Config::needHistory && !thePlan.exhausted() && (dynamic_cast(theGroup.getRaw()) || dynamic_cast(theGroup.getRaw()))) { + HttpRequest *request = dynamic_cast(theMsg); + if (!request) + request = theCause; + Must(request); + Adaptation::History::Pointer ah = request->adaptHistory(true); + SBuf gid(theGroup->id); + ah->recordAdaptationService(gid); + } + step(); } @@ -79,6 +92,12 @@ Must(service != NULL); debugs(93,5, HERE << "using adaptation service: " << service->cfg().key); + if (Adaptation::Config::needHistory) { + Adaptation::History::Pointer ah = request->adaptHistory(true); + SBuf uid(thePlan.current()->cfg().key); + ah->recordAdaptationService(uid); + } + theLauncher = initiateAdaptation( service->makeXactLauncher(theMsg, theCause)); Must(initiated(theLauncher)); === modified file 'src/cf.data.pre' --- src/cf.data.pre 2013-11-03 04:30:23 +0000 +++ src/cf.data.pre 2013-11-12 14:48:50 +0000 @@ -1073,6 +1073,15 @@ # Annotation sources include note and adaptation_meta directives # as well as helper and eCAP responses. + acl aclname adaptation_service service ... + # Matches the name of any icap_service, ecap_service, + # adaptation_service_set, or adaptation_service_chain that Squid + # has used (or attempted to use) for the master transaction. + # This ACL must be defined after the corresponding adaptation + # service is named in squid.conf. This ACL is usable with + # adaptation_meta because it starts matching immediately after + # the service has been selected for adaptation. + IF USE_SSL acl aclname ssl_error errorname # match against SSL certificate validation error [fast]