2 * Copyright (C) 1996-2017 The Squid Software Foundation and contributors
4 * Squid software is distributed under GPLv2+ license and includes
5 * contributions from numerous individuals and organizations.
6 * Please see the COPYING and CONTRIBUTORS files for details.
9 #ifndef SQUID_ICAPXACTION_H
10 #define SQUID_ICAPXACTION_H
12 #include "AccessLogEntry.h"
13 #include "adaptation/icap/ServiceRep.h"
14 #include "adaptation/Initiate.h"
15 #include "comm/ConnOpener.h"
16 #include "HttpReply.h"
18 #include "sbuf/SBuf.h"
28 * The ICAP Xaction implements common tasks for ICAP OPTIONS, REQMOD, and
29 * RESPMOD transactions. It is started by an Initiator. It terminates
30 * on its own, when done. Transactions communicate with Initiator using
31 * asynchronous messages because a transaction or Initiator may be gone at
35 // Note: Xaction must be the first parent for object-unaware cbdata to work
37 class Xaction
: public Adaptation::Initiate
41 Xaction(const char *aTypeName
, ServiceRep::Pointer
&aService
);
44 void disableRetries();
45 void disableRepeats(const char *reason
);
46 bool retriable() const { return isRetriable
; }
47 bool repeatable() const { return isRepeatable
; }
49 // comm handler wrappers, treat as private
50 void noteCommConnected(const CommConnectCbParams
&io
);
51 void noteCommWrote(const CommIoCbParams
&io
);
52 void noteCommRead(const CommIoCbParams
&io
);
53 void noteCommTimedout(const CommTimeoutCbParams
&io
);
54 void noteCommClosed(const CommCloseCbParams
&io
);
56 // TODO: create these only when actually sending/receiving
57 HttpRequest
*icapRequest
; ///< sent (or at least created) ICAP request
58 HttpReply::Pointer icapReply
; ///< received ICAP reply, if any
60 /// the number of times we tried to get to the service, including this time
65 virtual void noteInitiatorAborted(); // TODO: move to Adaptation::Initiate
67 // comm hanndlers; called by comm handler wrappers
68 virtual void handleCommConnected() = 0;
69 virtual void handleCommWrote(size_t sz
) = 0;
70 virtual void handleCommRead(size_t sz
) = 0;
71 virtual void handleCommTimedout();
72 virtual void handleCommClosed();
74 void handleSecuredPeer(Security::EncryptorAnswer
&answer
);
75 /// record error detail if possible
76 virtual void detailError(int) {}
78 void openConnection();
79 void closeConnection();
80 void dieOnConnectionFailure();
81 bool haveConnection() const;
84 void scheduleWrite(MemBuf
&buf
);
89 bool parseHttpMsg(HttpMsg
*msg
); // true=success; false=needMore; throw=err
90 bool mayReadMore() const;
92 virtual bool doneReading() const;
93 virtual bool doneWriting() const;
94 bool doneWithIo() const;
95 virtual bool doneAll() const;
97 // called just before the 'done' transaction is deleted
98 virtual void swanSong();
100 // returns a temporary string depicting transaction status, for debugging
101 virtual const char *status() const;
102 virtual void fillPendingStatus(MemBuf
&buf
) const;
103 virtual void fillDoneStatus(MemBuf
&buf
) const;
105 // useful for debugging
106 virtual bool fillVirginHttpHeader(MemBuf
&) const;
109 // custom exception handling and end-of-call checks
110 virtual void callException(const std::exception
&e
);
111 virtual void callEnd();
112 /// clear stored error details, if any; used for retries/repeats
113 virtual void clearError() {}
114 virtual AccessLogEntry::Pointer
masterLogEntry();
115 void dnsLookupDone(const ipcache_addrs
*ia
);
119 void setOutcome(const XactOutcome
&xo
);
120 virtual void finalizeLogInfo();
123 ServiceRep
&service();
126 void tellQueryAborted();
130 Comm::ConnectionPointer connection
; ///< ICAP server connection
131 Adaptation::Icap::ServiceRep::Pointer theService
;
135 bool reuseConnection
;
136 bool isRetriable
; ///< can retry on persistent connection failures
137 bool isRepeatable
; ///< can repeat if no or unsatisfactory response
138 bool ignoreLastWrite
;
140 const char *stopReason
;
142 // active (pending) comm callbacks for the ICAP server connection
143 AsyncCall::Pointer connector
;
144 AsyncCall::Pointer reader
;
145 AsyncCall::Pointer writer
;
146 AsyncCall::Pointer closer
;
148 AccessLogEntry::Pointer alep
; ///< icap.log entry
149 AccessLogEntry
&al
; ///< short for *alep
151 timeval icap_tr_start
; /*time when the ICAP transaction was created */
152 timeval icap_tio_start
; /*time when the first ICAP request byte was scheduled for sending*/
153 timeval icap_tio_finish
; /*time when the last byte of the ICAP responsewas received*/
156 Comm::ConnOpener::Pointer cs
;
157 AsyncCall::Pointer securer
; ///< whether we are securing a connection
161 } // namespace Adaptation
163 #endif /* SQUID_ICAPXACTION_H */