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