]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Renamed types and members after moving adaptation-method-agnostic APIs to the
authorAlex Rousskov <rousskov@measurement-factory.com>
Sun, 30 Mar 2008 19:40:57 +0000 (13:40 -0600)
committerAlex Rousskov <rousskov@measurement-factory.com>
Sun, 30 Mar 2008 19:40:57 +0000 (13:40 -0600)
Adaptation namespace and adding support for delayed adaptation service
creation.

src/ICAP/ICAPLauncher.cc
src/ICAP/ICAPLauncher.h
src/ICAP/ICAPModXact.cc
src/ICAP/ICAPModXact.h
src/ICAP/ICAPOptXact.cc
src/ICAP/ICAPOptXact.h
src/ICAP/ICAPXaction.cc
src/ICAP/ICAPXaction.h

index de11975b09d5d7f85fdb198b063de48bc184afb9..7e738605ac25fe4072ac62264d2bc931aa65b5fc 100644 (file)
@@ -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();
 }
index 9d5d22d1b6c2c6869d23ab77be3983a52eba8dfb..ef11ec746abd66897bffc6d33ff5bdc151bf55f1 100644 (file)
@@ -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
 };
 
index be6fa9555323dd98b38b899e0edac876ac82f2f5..8da4103401d14dae546cb7b50ee844b442d2e930 100644 (file)
@@ -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<ICAPServiceRep*>(theService.getRaw());
+    Must(s != NULL);
+    return new ICAPModXact(this, virgin.header, virgin.cause, s);
 }
index ebb69e1b3a49ecdbc18ff26f59da33d455b762d4..446c23f551daa9331cecb4c45902cb978ae90b8e 100644 (file)
@@ -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();
index 644e06f5d8de95d90d9da1ee1eb21c114f748a5e..e6e415f22da95512f834403bebcc6aea983a4ce8 100644 (file)
@@ -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<ICAPServiceRep*>(theService.getRaw());
+    Must(s != NULL);
+    return new ICAPOptXact(this, s);
 }
index fae8801557addf18eba8c69446bf368afe876887..20ef83ee6d583fa79a3d8feed26c1443f460af5d 100644 (file)
@@ -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();
index d71114e8c9023c405c92ee127f0e777dc43f6013..d6fc9640618b603d6c9320c02355260c9ed6e7bc 100644 (file)
@@ -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<ICAPServiceRep*>(&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<ICAPXaction, CommTimeoutCbParams> 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<ICAPXaction, CommCloseCbParams> CloseDialer;
     closer =  asyncCall(93, 5, "ICAPXaction::noteCommClosed",
@@ -108,7 +117,7 @@ void ICAPXaction::openConnection()
     typedef CommCbMemFunT<ICAPXaction, CommConnectCbParams> 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
index 4c04a12da6adaead8dd806995fd9b81bc34eb090..badd84ced15dda9e4766fca0647d0574908192ca 100644 (file)
@@ -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