#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)
{
}
void ICAPLauncher::start()
{
- ICAPInitiate::start();
+ Adaptation::Initiate::start();
Must(theInitiator);
launchXaction(false);
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()
}
-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) {
}
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();
}
#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
// 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();
void launchXaction(bool final);
- ICAPInitiate *theXaction; // current ICAP transaction
+ Adaptation::Initiate *theXaction; // current ICAP transaction
int theLaunches; // the number of transaction launches
};
#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"
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),
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
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;
/*
* 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));
/* 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)
{
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);
}
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);
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();
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)
{
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);
}
/* ICAPOptXactLauncher */
-ICAPOptXactLauncher::ICAPOptXactLauncher(ICAPInitiator *anInitiator, ICAPServiceRep::Pointer &aService):
+ICAPOptXactLauncher::ICAPOptXactLauncher(Adaptation::Initiator *anInitiator, Adaptation::ServicePointer aService):
AsyncJob("ICAPOptXactLauncher"),
ICAPLauncher("ICAPOptXactLauncher", anInitiator, aService)
{
ICAPXaction *ICAPOptXactLauncher::createXaction()
{
- return new ICAPOptXact(this, theService);
+ ICAPServiceRep::Pointer s =
+ dynamic_cast<ICAPServiceRep*>(theService.getRaw());
+ Must(s != NULL);
+ return new ICAPOptXact(this, s);
}
{
public:
- ICAPOptXact(ICAPInitiator *anInitiator, ICAPServiceRep::Pointer &aService);
+ ICAPOptXact(Adaptation::Initiator *anInitiator, ICAPServiceRep::Pointer &aService);
protected:
virtual void start();
class ICAPOptXactLauncher: public ICAPLauncher
{
public:
- ICAPOptXactLauncher(ICAPInitiator *anInitiator, ICAPServiceRep::Pointer &aService);
+ ICAPOptXactLauncher(Adaptation::Initiator *anInitiator, Adaptation::ServicePointer aService);
protected:
virtual ICAPXaction *createXaction();
//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),
" [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());
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);
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);
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",
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);
}
/*
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());
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");
}
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();
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() {
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?
if (theInitiator)
tellQueryAborted(!isRetriable);
- ICAPInitiate::swanSong();
+ Adaptation::Initiate::swanSong();
}
// returns a temporary string depicting transaction status, for debugging
#include "CommCalls.h"
#include "MemBuf.h"
#include "ICAPServiceRep.h"
-#include "ICAPInitiate.h"
+#include "adaptation/Initiate.h"
class HttpMsg;
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();
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;
// custom end-of-call checks
virtual void callEnd();
+ ICAPServiceRep &service();
+
protected:
int connection; // FD of the ICAP server connection