]> git.ipfire.org Git - thirdparty/squid.git/blame - src/adaptation/icap/Xaction.h
MacOS fix: shorten testRock store path to fit in shm segment filename size limitation...
[thirdparty/squid.git] / src / adaptation / icap / Xaction.h
CommitLineData
774c051c 1/*
ef57eb7b 2 * Copyright (C) 1996-2016 The Squid Software Foundation and contributors
774c051c 3 *
bbc27441
AJ
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.
774c051c 7 */
8
9#ifndef SQUID_ICAPXACTION_H
10#define SQUID_ICAPXACTION_H
11
602d9612 12#include "AccessLogEntry.h"
26cc52cb 13#include "adaptation/icap/ServiceRep.h"
0bef8dd7 14#include "adaptation/Initiate.h"
5c720aa0 15#include "comm/ConnOpener.h"
c7d51c86 16#include "HttpReply.h"
fb505fa1 17#include "ipcache.h"
84ae6223 18#include "SBuf.h"
2f32154e 19#if USE_OPENSSL
1b091aec 20#include "ssl/PeerConnector.h"
2f32154e 21#endif
84ae6223 22
477f45eb 23class MemBuf;
774c051c 24
af6a12ee
AJ
25namespace Adaptation
26{
e1381638
AJ
27namespace Icap
28{
26cc52cb 29
5f8252d2 30/*
31 * The ICAP Xaction implements common tasks for ICAP OPTIONS, REQMOD, and
26cc52cb 32 * RESPMOD transactions. It is started by an Initiator. It terminates
c824c43b 33 * on its own, when done. Transactions communicate with Initiator using
34 * asynchronous messages because a transaction or Initiator may be gone at
35 * any time.
5f8252d2 36 */
774c051c 37
26cc52cb 38// Note: Xaction must be the first parent for object-unaware cbdata to work
774c051c 39
26cc52cb 40class Xaction: public Adaptation::Initiate
774c051c 41{
42
43public:
4299f876 44 Xaction(const char *aTypeName, ServiceRep::Pointer &aService);
26cc52cb 45 virtual ~Xaction();
774c051c 46
c824c43b 47 void disableRetries();
3ff65596
AR
48 void disableRepeats(const char *reason);
49 bool retriable() const { return isRetriable; }
50 bool repeatable() const { return isRepeatable; }
c824c43b 51
774c051c 52 // comm handler wrappers, treat as private
bd7f2ede 53 void noteCommConnected(const CommConnectCbParams &io);
54 void noteCommWrote(const CommIoCbParams &io);
55 void noteCommRead(const CommIoCbParams &io);
56 void noteCommTimedout(const CommTimeoutCbParams &io);
57 void noteCommClosed(const CommCloseCbParams &io);
774c051c 58
3ff65596
AR
59 // TODO: create these only when actually sending/receiving
60 HttpRequest *icapRequest; ///< sent (or at least created) ICAP request
c7d51c86 61 HttpReply::Pointer icapReply; ///< received ICAP reply, if any
3ff65596
AR
62
63 /// the number of times we tried to get to the service, including this time
64 int attempts;
65
774c051c 66protected:
c824c43b 67 virtual void start();
0bef8dd7 68 virtual void noteInitiatorAborted(); // TODO: move to Adaptation::Initiate
774c051c 69
70 // comm hanndlers; called by comm handler wrappers
71 virtual void handleCommConnected() = 0;
72 virtual void handleCommWrote(size_t sz) = 0;
73 virtual void handleCommRead(size_t sz) = 0;
74 virtual void handleCommTimedout();
75 virtual void handleCommClosed();
76
1b091aec 77 void handleSecuredPeer(Security::EncryptorAnswer &answer);
64b66b76 78 /// record error detail if possible
ced8def3 79 virtual void detailError(int) {}
64b66b76 80
774c051c 81 void openConnection();
82 void closeConnection();
c99de607 83 void dieOnConnectionFailure();
aed188fd 84 bool haveConnection() const;
c99de607 85
774c051c 86 void scheduleRead();
87 void scheduleWrite(MemBuf &buf);
c99de607 88 void updateTimeout();
774c051c 89
90 void cancelRead();
91
92 bool parseHttpMsg(HttpMsg *msg); // true=success; false=needMore; throw=err
93 bool mayReadMore() const;
c824c43b 94
774c051c 95 virtual bool doneReading() const;
c99de607 96 virtual bool doneWriting() const;
97 bool doneWithIo() const;
774c051c 98 virtual bool doneAll() const;
774c051c 99
5f8252d2 100 // called just before the 'done' transaction is deleted
9e008dda 101 virtual void swanSong();
5f8252d2 102
774c051c 103 // returns a temporary string depicting transaction status, for debugging
c824c43b 104 virtual const char *status() const;
774c051c 105 virtual void fillPendingStatus(MemBuf &buf) const;
106 virtual void fillDoneStatus(MemBuf &buf) const;
107
3cfc19b3 108 // useful for debugging
109 virtual bool fillVirginHttpHeader(MemBuf&) const;
110
4299f876 111public:
3ff65596
AR
112 // custom exception handling and end-of-call checks
113 virtual void callException(const std::exception &e);
c824c43b 114 virtual void callEnd();
7a957a93 115 /// clear stored error details, if any; used for retries/repeats
129fe2a1 116 virtual void clearError() {}
d4ddb3e6 117 virtual AccessLogEntry::Pointer masterLogEntry();
fb505fa1 118 void dnsLookupDone(const ipcache_addrs *ia);
c824c43b 119
4299f876 120protected:
3ff65596
AR
121 // logging
122 void setOutcome(const XactOutcome &xo);
123 virtual void finalizeLogInfo();
124
2dba5b8e 125public:
26cc52cb 126 ServiceRep &service();
0bef8dd7 127
3ff65596
AR
128private:
129 void tellQueryAborted();
130 void maybeLog();
131
774c051c 132protected:
aed188fd 133 Comm::ConnectionPointer connection; ///< ICAP server connection
a22e6cd3 134 Adaptation::Icap::ServiceRep::Pointer theService;
774c051c 135
84ae6223 136 SBuf readBuf;
774c051c 137 bool commEof;
2dfede9e 138 bool reuseConnection;
3ff65596
AR
139 bool isRetriable; ///< can retry on persistent connection failures
140 bool isRepeatable; ///< can repeat if no or unsatisfactory response
cfc68405 141 bool ignoreLastWrite;
774c051c 142
143 const char *stopReason;
144
774c051c 145 // active (pending) comm callbacks for the ICAP server connection
bd7f2ede 146 AsyncCall::Pointer connector;
147 AsyncCall::Pointer reader;
148 AsyncCall::Pointer writer;
149 AsyncCall::Pointer closer;
774c051c 150
41ebd397
CT
151 AccessLogEntry::Pointer alep; ///< icap.log entry
152 AccessLogEntry &al; ///< short for *alep
3ff65596
AR
153
154 timeval icap_tr_start; /*time when the ICAP transaction was created */
155 timeval icap_tio_start; /*time when the first ICAP request byte was scheduled for sending*/
156 timeval icap_tio_finish; /*time when the last byte of the ICAP responsewas received*/
157
774c051c 158private:
5c720aa0 159 Comm::ConnOpener::Pointer cs;
1b091aec 160 AsyncCall::Pointer securer; ///< whether we are securing a connection
774c051c 161};
162
26cc52cb
AR
163} // namespace Icap
164} // namespace Adaptation
165
774c051c 166#endif /* SQUID_ICAPXACTION_H */
f53969cc 167