]>
Commit | Line | Data |
---|---|---|
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 | 23 | class MemBuf; |
774c051c | 24 | |
af6a12ee AJ |
25 | namespace Adaptation |
26 | { | |
e1381638 AJ |
27 | namespace 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 | 40 | class Xaction: public Adaptation::Initiate |
774c051c | 41 | { |
42 | ||
43 | public: | |
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 | 66 | protected: |
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 | 111 | public: |
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() {} |
fb505fa1 | 117 | void dnsLookupDone(const ipcache_addrs *ia); |
c824c43b | 118 | |
4299f876 | 119 | protected: |
3ff65596 AR |
120 | // logging |
121 | void setOutcome(const XactOutcome &xo); | |
122 | virtual void finalizeLogInfo(); | |
123 | ||
2dba5b8e | 124 | public: |
26cc52cb | 125 | ServiceRep &service(); |
0bef8dd7 | 126 | |
3ff65596 AR |
127 | private: |
128 | void tellQueryAborted(); | |
129 | void maybeLog(); | |
130 | ||
774c051c | 131 | protected: |
aed188fd | 132 | Comm::ConnectionPointer connection; ///< ICAP server connection |
a22e6cd3 | 133 | Adaptation::Icap::ServiceRep::Pointer theService; |
774c051c | 134 | |
84ae6223 | 135 | SBuf readBuf; |
774c051c | 136 | bool commEof; |
2dfede9e | 137 | bool reuseConnection; |
3ff65596 AR |
138 | bool isRetriable; ///< can retry on persistent connection failures |
139 | bool isRepeatable; ///< can repeat if no or unsatisfactory response | |
cfc68405 | 140 | bool ignoreLastWrite; |
774c051c | 141 | |
142 | const char *stopReason; | |
143 | ||
774c051c | 144 | // active (pending) comm callbacks for the ICAP server connection |
bd7f2ede | 145 | AsyncCall::Pointer connector; |
146 | AsyncCall::Pointer reader; | |
147 | AsyncCall::Pointer writer; | |
148 | AsyncCall::Pointer closer; | |
774c051c | 149 | |
41ebd397 CT |
150 | AccessLogEntry::Pointer alep; ///< icap.log entry |
151 | AccessLogEntry &al; ///< short for *alep | |
3ff65596 AR |
152 | |
153 | timeval icap_tr_start; /*time when the ICAP transaction was created */ | |
154 | timeval icap_tio_start; /*time when the first ICAP request byte was scheduled for sending*/ | |
155 | timeval icap_tio_finish; /*time when the last byte of the ICAP responsewas received*/ | |
156 | ||
774c051c | 157 | private: |
5c720aa0 | 158 | Comm::ConnOpener::Pointer cs; |
1b091aec | 159 | AsyncCall::Pointer securer; ///< whether we are securing a connection |
774c051c | 160 | }; |
161 | ||
26cc52cb AR |
162 | } // namespace Icap |
163 | } // namespace Adaptation | |
164 | ||
774c051c | 165 | #endif /* SQUID_ICAPXACTION_H */ |
f53969cc | 166 |