From: Alex Rousskov Date: Sun, 30 Mar 2008 19:40:57 +0000 (-0600) Subject: Renamed types and members after moving adaptation-method-agnostic APIs to the X-Git-Tag: SQUID_3_1_0_1~49^2~302^2~24 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=0bef8dd7255b92e0f0de92ddb516f6eb2eb59dd2;p=thirdparty%2Fsquid.git Renamed types and members after moving adaptation-method-agnostic APIs to the Adaptation namespace and adding support for delayed adaptation service creation. --- diff --git a/src/ICAP/ICAPLauncher.cc b/src/ICAP/ICAPLauncher.cc index de11975b09..7e738605ac 100644 --- a/src/ICAP/ICAPLauncher.cc +++ b/src/ICAP/ICAPLauncher.cc @@ -7,10 +7,13 @@ #include "HttpMsg.h" #include "ICAPLauncher.h" #include "ICAPXaction.h" +#include "ICAPServiceRep.h" -ICAPLauncher::ICAPLauncher(const char *aTypeName, ICAPInitiator *anInitiator, ICAPServiceRep::Pointer &aService):AsyncJob(aTypeName), - ICAPInitiate(aTypeName, anInitiator, aService), +ICAPLauncher::ICAPLauncher(const char *aTypeName, + Adaptation::Initiator *anInitiator, Adaptation::ServicePointer &aService): + AsyncJob(aTypeName), + Adaptation::Initiate(aTypeName, anInitiator, aService), theXaction(0), theLaunches(0) { } @@ -22,7 +25,7 @@ ICAPLauncher::~ICAPLauncher() void ICAPLauncher::start() { - ICAPInitiate::start(); + Adaptation::Initiate::start(); Must(theInitiator); launchXaction(false); @@ -36,16 +39,16 @@ void ICAPLauncher::launchXaction(bool final) ICAPXaction *x = createXaction(); if (final) x->disableRetries(); - theXaction = initiateIcap(x); + theXaction = initiateAdaptation(x); Must(theXaction); } -void ICAPLauncher::noteIcapAnswer(HttpMsg *message) +void ICAPLauncher::noteAdaptationAnswer(HttpMsg *message) { sendAnswer(message); - clearIcap(theXaction); + clearAdaptation(theXaction); Must(done()); - debugs(93,3, HERE << "ICAPLauncher::noteIcapAnswer exiting "); + debugs(93,3, HERE << "ICAPLauncher::noteAdaptationAnswer exiting "); } void ICAPLauncher::noteInitiatorAborted() @@ -57,9 +60,9 @@ void ICAPLauncher::noteInitiatorAborted() } -void ICAPLauncher::noteIcapQueryAbort(bool final) +void ICAPLauncher::noteAdaptationQueryAbort(bool final) { - clearIcap(theXaction); + clearAdaptation(theXaction); // TODO: add more checks from FwdState::checkRetry()? if (!final && theLaunches < 2 && !shutting_down) { @@ -73,16 +76,16 @@ void ICAPLauncher::noteIcapQueryAbort(bool final) } bool ICAPLauncher::doneAll() const { - return (!theInitiator || !theXaction) && ICAPInitiate::doneAll(); + return (!theInitiator || !theXaction) && Adaptation::Initiate::doneAll(); } void ICAPLauncher::swanSong() { if (theInitiator) - tellQueryAborted(!service().bypass); + tellQueryAborted(!service().cfg().bypass); if (theXaction) - clearIcap(theXaction); + clearAdaptation(theXaction); - ICAPInitiate::swanSong(); + Adaptation::Initiate::swanSong(); } diff --git a/src/ICAP/ICAPLauncher.h b/src/ICAP/ICAPLauncher.h index 9d5d22d1b6..ef11ec746a 100644 --- a/src/ICAP/ICAPLauncher.h +++ b/src/ICAP/ICAPLauncher.h @@ -34,8 +34,9 @@ #ifndef SQUID_ICAPLAUNCHER_H #define SQUID_ICAPLAUNCHER_H -#include "ICAP/ICAPInitiator.h" -#include "ICAP/ICAPInitiate.h" +#include "adaptation/Initiator.h" +#include "adaptation/Initiate.h" +#include "ICAP/ICAPServiceRep.h" /* * The ICAP Launcher starts an ICAP transaction. If the transaction fails @@ -62,21 +63,21 @@ class ICAPXaction; // Note: ICAPInitiate must be the first parent for cbdata to work. We use // a temporary ICAPInitaitorHolder/toCbdata hacks and do not call cbdata // operations on the initiator directly. -class ICAPLauncher: public ICAPInitiate, public ICAPInitiator +class ICAPLauncher: public Adaptation::Initiate, public Adaptation::Initiator { public: - ICAPLauncher(const char *aTypeName, ICAPInitiator *anInitiator, ICAPServiceRep::Pointer &aService); + ICAPLauncher(const char *aTypeName, Adaptation::Initiator *anInitiator, Adaptation::ServicePointer &aService); virtual ~ICAPLauncher(); - // ICAPInitiate: asynchronous communication with the initiator + // Adaptation::Initiate: asynchronous communication with the initiator void noteInitiatorAborted(); - // ICAPInitiator: asynchronous communication with the current transaction - virtual void noteIcapAnswer(HttpMsg *message); - virtual void noteIcapQueryAbort(bool final); + // Adaptation::Initiator: asynchronous communication with the current transaction + virtual void noteAdaptationAnswer(HttpMsg *message); + virtual void noteAdaptationQueryAbort(bool final); protected: - // ICAPInitiate API implementation + // Adaptation::Initiate API implementation virtual void start(); virtual bool doneAll() const; virtual void swanSong(); @@ -86,7 +87,7 @@ protected: void launchXaction(bool final); - ICAPInitiate *theXaction; // current ICAP transaction + Adaptation::Initiate *theXaction; // current ICAP transaction int theLaunches; // the number of transaction launches }; diff --git a/src/ICAP/ICAPModXact.cc b/src/ICAP/ICAPModXact.cc index be6fa95553..8da4103401 100644 --- a/src/ICAP/ICAPModXact.cc +++ b/src/ICAP/ICAPModXact.cc @@ -7,8 +7,8 @@ #include "HttpMsg.h" #include "HttpRequest.h" #include "HttpReply.h" +#include "adaptation/Initiator.h" #include "ICAPServiceRep.h" -#include "ICAPInitiator.h" #include "ICAPLauncher.h" #include "ICAPModXact.h" #include "ICAPClient.h" @@ -37,7 +37,7 @@ ICAPModXact::State::State() memset(this, 0, sizeof(*this)); } -ICAPModXact::ICAPModXact(ICAPInitiator *anInitiator, HttpMsg *virginHeader, +ICAPModXact::ICAPModXact(Adaptation::Initiator *anInitiator, HttpMsg *virginHeader, HttpRequest *virginCause, ICAPServiceRep::Pointer &aService): AsyncJob("ICAPModXact"), ICAPXaction("ICAPModXact", anInitiator, aService), @@ -72,7 +72,7 @@ void ICAPModXact::start() estimateVirginBody(); // before virgin disappears! - canStartBypass = service().bypass; + canStartBypass = service().cfg().bypass; // it is an ICAP violation to send request to a service w/o known OPTIONS @@ -716,14 +716,14 @@ void ICAPModXact::parseIcapHead() bool ICAPModXact::validate200Ok() { - if (ICAP::methodRespmod == service().method) { + if (ICAP::methodRespmod == service().cfg().method) { if (!gotEncapsulated("res-hdr")) return false; return true; } - if (ICAP::methodReqmod == service().method) { + if (ICAP::methodReqmod == service().cfg().method) { if (!gotEncapsulated("res-hdr") && !gotEncapsulated("req-hdr")) return false; @@ -1047,7 +1047,7 @@ void ICAPModXact::makeRequestHeaders(MemBuf &buf) /* * XXX These should use HttpHdr interfaces instead of Printfs */ - const ICAPServiceRep &s = service(); + const Adaptation::ServiceConfig &s = service().cfg(); buf.Printf("%s %s ICAP/1.0\r\n", s.methodStr(), s.uri.buf()); buf.Printf("Host: %s:%d\r\n", s.host.buf(), s.port); buf.Printf("Date: %s\r\n", mkrfc1123(squid_curtime)); @@ -1540,7 +1540,7 @@ bool ICAPModXact::fillVirginHttpHeader(MemBuf &mb) const /* ICAPModXactLauncher */ -ICAPModXactLauncher::ICAPModXactLauncher(ICAPInitiator *anInitiator, HttpMsg *virginHeader, HttpRequest *virginCause, ICAPServiceRep::Pointer &aService): +ICAPModXactLauncher::ICAPModXactLauncher(Adaptation::Initiator *anInitiator, HttpMsg *virginHeader, HttpRequest *virginCause, Adaptation::ServicePointer aService): AsyncJob("ICAPModXactLauncher"), ICAPLauncher("ICAPModXactLauncher", anInitiator, aService) { @@ -1550,5 +1550,8 @@ ICAPModXactLauncher::ICAPModXactLauncher(ICAPInitiator *anInitiator, HttpMsg *vi ICAPXaction *ICAPModXactLauncher::createXaction() { - return new ICAPModXact(this, virgin.header, virgin.cause, theService); + ICAPServiceRep::Pointer s = + dynamic_cast(theService.getRaw()); + Must(s != NULL); + return new ICAPModXact(this, virgin.header, virgin.cause, s); } diff --git a/src/ICAP/ICAPModXact.h b/src/ICAP/ICAPModXact.h index ebb69e1b3a..446c23f551 100644 --- a/src/ICAP/ICAPModXact.h +++ b/src/ICAP/ICAPModXact.h @@ -127,13 +127,11 @@ private: enum State { stDisabled, stWriting, stIeof, stDone } theState; }; -class ICAPInitiator; - class ICAPModXact: public ICAPXaction, public BodyProducer, public BodyConsumer { public: - ICAPModXact(ICAPInitiator *anInitiator, HttpMsg *virginHeader, HttpRequest *virginCause, ICAPServiceRep::Pointer &s); + ICAPModXact(Adaptation::Initiator *anInitiator, HttpMsg *virginHeader, HttpRequest *virginCause, ICAPServiceRep::Pointer &s); // BodyProducer methods virtual void noteMoreBodySpaceAvailable(BodyPipe::Pointer); @@ -312,7 +310,7 @@ private: class ICAPModXactLauncher: public ICAPLauncher { public: - ICAPModXactLauncher(ICAPInitiator *anInitiator, HttpMsg *virginHeader, HttpRequest *virginCause, ICAPServiceRep::Pointer &s); + ICAPModXactLauncher(Adaptation::Initiator *anInitiator, HttpMsg *virginHeader, HttpRequest *virginCause, Adaptation::ServicePointer s); protected: virtual ICAPXaction *createXaction(); diff --git a/src/ICAP/ICAPOptXact.cc b/src/ICAP/ICAPOptXact.cc index 644e06f5d8..e6e415f22d 100644 --- a/src/ICAP/ICAPOptXact.cc +++ b/src/ICAP/ICAPOptXact.cc @@ -14,7 +14,7 @@ CBDATA_CLASS_INIT(ICAPOptXact); CBDATA_CLASS_INIT(ICAPOptXactLauncher); -ICAPOptXact::ICAPOptXact(ICAPInitiator *anInitiator, ICAPServiceRep::Pointer &aService): +ICAPOptXact::ICAPOptXact(Adaptation::Initiator *anInitiator, ICAPServiceRep::Pointer &aService): AsyncJob("ICAPOptXact"), ICAPXaction("ICAPOptXact", anInitiator, aService) { @@ -42,9 +42,9 @@ void ICAPOptXact::handleCommConnected() void ICAPOptXact::makeRequest(MemBuf &buf) { - const ICAPServiceRep &s = service(); - buf.Printf("OPTIONS %s ICAP/1.0\r\n", s.uri.buf()); - buf.Printf("Host: %s:%d\r\n", s.host.buf(), s.port); + const Adaptation::Service &s = service(); + buf.Printf("OPTIONS %s ICAP/1.0\r\n", s.cfg().uri.buf()); + buf.Printf("Host: %s:%d\r\n", s.cfg().host.buf(), s.cfg().port); buf.append(ICAP::crlf, 2); } @@ -88,7 +88,7 @@ HttpMsg *ICAPOptXact::parseResponse() /* ICAPOptXactLauncher */ -ICAPOptXactLauncher::ICAPOptXactLauncher(ICAPInitiator *anInitiator, ICAPServiceRep::Pointer &aService): +ICAPOptXactLauncher::ICAPOptXactLauncher(Adaptation::Initiator *anInitiator, Adaptation::ServicePointer aService): AsyncJob("ICAPOptXactLauncher"), ICAPLauncher("ICAPOptXactLauncher", anInitiator, aService) { @@ -96,5 +96,8 @@ ICAPOptXactLauncher::ICAPOptXactLauncher(ICAPInitiator *anInitiator, ICAPService ICAPXaction *ICAPOptXactLauncher::createXaction() { - return new ICAPOptXact(this, theService); + ICAPServiceRep::Pointer s = + dynamic_cast(theService.getRaw()); + Must(s != NULL); + return new ICAPOptXact(this, s); } diff --git a/src/ICAP/ICAPOptXact.h b/src/ICAP/ICAPOptXact.h index fae8801557..20ef83ee6d 100644 --- a/src/ICAP/ICAPOptXact.h +++ b/src/ICAP/ICAPOptXact.h @@ -48,7 +48,7 @@ class ICAPOptXact: public ICAPXaction { public: - ICAPOptXact(ICAPInitiator *anInitiator, ICAPServiceRep::Pointer &aService); + ICAPOptXact(Adaptation::Initiator *anInitiator, ICAPServiceRep::Pointer &aService); protected: virtual void start(); @@ -70,7 +70,7 @@ private: class ICAPOptXactLauncher: public ICAPLauncher { public: - ICAPOptXactLauncher(ICAPInitiator *anInitiator, ICAPServiceRep::Pointer &aService); + ICAPOptXactLauncher(Adaptation::Initiator *anInitiator, Adaptation::ServicePointer aService); protected: virtual ICAPXaction *createXaction(); diff --git a/src/ICAP/ICAPXaction.cc b/src/ICAP/ICAPXaction.cc index d71114e8c9..d6fc964061 100644 --- a/src/ICAP/ICAPXaction.cc +++ b/src/ICAP/ICAPXaction.cc @@ -17,9 +17,9 @@ static PconnPool *icapPconnPool = new PconnPool("ICAP Servers"); //CBDATA_CLASS_INIT(ICAPXaction); -ICAPXaction::ICAPXaction(const char *aTypeName, ICAPInitiator *anInitiator, ICAPServiceRep::Pointer &aService): +ICAPXaction::ICAPXaction(const char *aTypeName, Adaptation::Initiator *anInitiator, ICAPServiceRep::Pointer &aService): AsyncJob(aTypeName), - ICAPInitiate(aTypeName, anInitiator, aService), + Adaptation::Initiate(aTypeName, anInitiator, aService.getRaw()), connection(-1), commBuf(NULL), commBufSize(0), commEof(false), @@ -38,6 +38,14 @@ ICAPXaction::~ICAPXaction() " [icapx" << id << ']'); // we should not call virtual status() here } +ICAPServiceRep & +ICAPXaction::service() +{ + ICAPServiceRep *s = dynamic_cast(&Initiate::service()); + Must(s); + return *s; +} + void ICAPXaction::disableRetries() { debugs(93,5, typeName << (isRetriable ? " becomes" : " remains") << " final" << status()); @@ -46,7 +54,7 @@ void ICAPXaction::disableRetries() { void ICAPXaction::start() { - ICAPInitiate::start(); + Adaptation::Initiate::start(); readBuf.init(SQUID_TCP_SO_RCVBUF, SQUID_TCP_SO_RCVBUF); commBuf = (char*)memAllocBuf(SQUID_TCP_SO_RCVBUF, &commBufSize); @@ -61,13 +69,13 @@ void ICAPXaction::openConnection() Must(connection < 0); - const ICAPServiceRep &s = service(); + const Adaptation::Service &s = service(); if (!TheICAPConfig.reuse_connections) disableRetries(); // this will also safely drain pconn pool // TODO: check whether NULL domain is appropriate here - connection = icapPconnPool->pop(s.host.buf(), s.port, NULL, client_addr, isRetriable); + connection = icapPconnPool->pop(s.cfg().host.buf(), s.cfg().port, NULL, client_addr, isRetriable); if (connection >= 0) { debugs(93,3, HERE << "reused pconn FD " << connection); @@ -86,19 +94,20 @@ void ICAPXaction::openConnection() IPAddress outgoing; connection = comm_open(SOCK_STREAM, 0, outgoing, - COMM_NONBLOCKING, s.uri.buf()); + COMM_NONBLOCKING, s.cfg().uri.buf()); if (connection < 0) dieOnConnectionFailure(); // throws - debugs(93,3, typeName << " opens connection to " << s.host.buf() << ":" << s.port); + debugs(93,3, typeName << " opens connection to " << s.cfg().host.buf() << ":" << s.cfg().port); // TODO: service bypass status may differ from that of a transaction typedef CommCbMemFunT TimeoutDialer; AsyncCall::Pointer timeoutCall = asyncCall(93, 5, "ICAPXaction::noteCommTimedout", TimeoutDialer(this,&ICAPXaction::noteCommTimedout)); - commSetTimeout(connection, TheICAPConfig.connect_timeout(service().bypass), timeoutCall); + commSetTimeout(connection, TheICAPConfig.connect_timeout( + service().cfg().bypass), timeoutCall); typedef CommCbMemFunT CloseDialer; closer = asyncCall(93, 5, "ICAPXaction::noteCommClosed", @@ -108,7 +117,7 @@ void ICAPXaction::openConnection() typedef CommCbMemFunT ConnectDialer; connector = asyncCall(93,3, "ICAPXaction::noteCommConnected", ConnectDialer(this, &ICAPXaction::noteCommConnected)); - commConnectStart(connection, s.host.buf(), s.port, connector); + commConnectStart(connection, s.cfg().host.buf(), s.cfg().port, connector); } /* @@ -146,7 +155,8 @@ void ICAPXaction::closeConnection() debugs(93,3, HERE << "pushing pconn" << status()); AsyncCall::Pointer call = NULL; commSetTimeout(connection, -1, call); - icapPconnPool->push(connection, theService->host.buf(), theService->port, NULL, client_addr); + icapPconnPool->push(connection, theService->cfg().host.buf(), + theService->cfg().port, NULL, client_addr); disableRetries(); } else { debugs(93,3, HERE << "closing pconn" << status()); @@ -177,7 +187,7 @@ void ICAPXaction::noteCommConnected(const CommConnectCbParams &io) void ICAPXaction::dieOnConnectionFailure() { debugs(93, 2, HERE << typeName << - " failed to connect to " << service().uri); + " failed to connect to " << service().cfg().uri); theService->noteFailure(); throw TexcHere("cannot connect to the ICAP service"); } @@ -218,7 +228,8 @@ void ICAPXaction::noteCommTimedout(const CommTimeoutCbParams &io) void ICAPXaction::handleCommTimedout() { debugs(93, 2, HERE << typeName << " failed: timeout with " << - theService->methodStr() << " " << theService->uri.buf() << status()); + theService->cfg().methodStr() << " " << + theService->cfg().uri.buf() << status()); reuseConnection = false; service().noteFailure(); @@ -245,12 +256,12 @@ void ICAPXaction::callEnd() debugs(93, 5, HERE << typeName << " done with I/O" << status()); closeConnection(); } - ICAPInitiate::callEnd(); // may destroy us + Adaptation::Initiate::callEnd(); // may destroy us } bool ICAPXaction::doneAll() const { - return !connector && !reader && !writer && ICAPInitiate::doneAll(); + return !connector && !reader && !writer && Adaptation::Initiate::doneAll(); } void ICAPXaction::updateTimeout() { @@ -262,7 +273,8 @@ void ICAPXaction::updateTimeout() { AsyncCall::Pointer call = asyncCall(93, 5, "ICAPXaction::noteCommTimedout", TimeoutDialer(this,&ICAPXaction::noteCommTimedout)); - commSetTimeout(connection, TheICAPConfig.io_timeout(service().bypass), call); + commSetTimeout(connection, + TheICAPConfig.io_timeout(service().cfg().bypass), call); } else { // clear timeout when there is no I/O // Do we need a lifetime timeout? @@ -396,7 +408,7 @@ void ICAPXaction::swanSong() if (theInitiator) tellQueryAborted(!isRetriable); - ICAPInitiate::swanSong(); + Adaptation::Initiate::swanSong(); } // returns a temporary string depicting transaction status, for debugging diff --git a/src/ICAP/ICAPXaction.h b/src/ICAP/ICAPXaction.h index 4c04a12da6..badd84ced1 100644 --- a/src/ICAP/ICAPXaction.h +++ b/src/ICAP/ICAPXaction.h @@ -38,7 +38,7 @@ #include "CommCalls.h" #include "MemBuf.h" #include "ICAPServiceRep.h" -#include "ICAPInitiate.h" +#include "adaptation/Initiate.h" class HttpMsg; class CommConnectCbParams; @@ -53,11 +53,11 @@ class CommConnectCbParams; // Note: ICAPXaction must be the first parent for object-unaware cbdata to work -class ICAPXaction: public ICAPInitiate +class ICAPXaction: public Adaptation::Initiate { public: - ICAPXaction(const char *aTypeName, ICAPInitiator *anInitiator, ICAPServiceRep::Pointer &aService); + ICAPXaction(const char *aTypeName, Adaptation::Initiator *anInitiator, ICAPServiceRep::Pointer &aService); virtual ~ICAPXaction(); void disableRetries(); @@ -71,7 +71,7 @@ public: protected: virtual void start(); - virtual void noteInitiatorAborted(); // TODO: move to ICAPInitiate + virtual void noteInitiatorAborted(); // TODO: move to Adaptation::Initiate // comm hanndlers; called by comm handler wrappers virtual void handleCommConnected() = 0; @@ -112,6 +112,8 @@ protected: // custom end-of-call checks virtual void callEnd(); + ICAPServiceRep &service(); + protected: int connection; // FD of the ICAP server connection