Xaction.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 1996-2023 The Squid Software Foundation and contributors
3  *
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.
7  */
8 
9 #ifndef SQUID_SRC_ADAPTATION_ICAP_XACTION_H
10 #define SQUID_SRC_ADAPTATION_ICAP_XACTION_H
11 
12 #include "AccessLogEntry.h"
14 #include "adaptation/Initiate.h"
15 #include "base/JobWait.h"
16 #include "comm/ConnOpener.h"
17 #include "error/forward.h"
18 #include "HttpReply.h"
19 #include "ipcache.h"
20 #include "sbuf/SBuf.h"
21 
22 class MemBuf;
23 
24 namespace Ssl {
25 class IcapPeerConnector;
26 }
27 
28 namespace Adaptation
29 {
30 namespace Icap
31 {
32 
33 /*
34  * The ICAP Xaction implements common tasks for ICAP OPTIONS, REQMOD, and
35  * RESPMOD transactions. It is started by an Initiator. It terminates
36  * on its own, when done. Transactions communicate with Initiator using
37  * asynchronous messages because a transaction or Initiator may be gone at
38  * any time.
39  */
40 
41 // Note: Xaction must be the first parent for object-unaware cbdata to work
42 
44 {
45 
46 public:
47  Xaction(const char *aTypeName, ServiceRep::Pointer &aService);
48  ~Xaction() override;
49 
50  void disableRetries();
51  void disableRepeats(const char *reason);
52  bool retriable() const { return isRetriable; }
53  bool repeatable() const { return isRepeatable; }
54 
55  // comm handler wrappers, treat as private
56  void noteCommConnected(const CommConnectCbParams &io);
57  void noteCommWrote(const CommIoCbParams &io);
58  void noteCommRead(const CommIoCbParams &io);
59  void noteCommTimedout(const CommTimeoutCbParams &io);
60  void noteCommClosed(const CommCloseCbParams &io);
61 
62  // TODO: create these only when actually sending/receiving
65 
67  int attempts;
68 
69 protected:
70  void start() override;
71  void noteInitiatorAborted() override; // TODO: move to Adaptation::Initiate
72 
74  virtual void startShoveling() = 0;
75 
76  // comm hanndlers; called by comm handler wrappers
77  virtual void handleCommWrote(size_t sz) = 0;
78  virtual void handleCommRead(size_t sz) = 0;
79 
82  virtual void detailError(const ErrorDetailPointer &) {}
83 
84  void openConnection();
85  void closeConnection();
86  bool haveConnection() const;
87 
88  void scheduleRead();
89  void scheduleWrite(MemBuf &buf);
90  void updateTimeout();
91 
92  void cancelRead();
93 
94  bool parseHttpMsg(Http::Message *msg); // true=success; false=needMore; throw=err
95  bool mayReadMore() const;
96 
97  virtual bool doneReading() const;
98  virtual bool doneWriting() const;
99  bool doneWithIo() const;
100  bool doneAll() const override;
101 
102  // called just before the 'done' transaction is deleted
103  void swanSong() override;
104 
105  // returns a temporary string depicting transaction status, for debugging
106  const char *status() const override;
107  virtual void fillPendingStatus(MemBuf &buf) const;
108  virtual void fillDoneStatus(MemBuf &buf) const;
109 
110  // useful for debugging
111  virtual bool fillVirginHttpHeader(MemBuf&) const;
112 
113 public:
114  // custom exception handling and end-of-call checks
115  void callException(const std::exception &e) override;
116  void callEnd() override;
118  virtual void clearError() {}
120  void dnsLookupDone(std::optional<Ip::Address>);
121 
122 protected:
123  // logging
124  void setOutcome(const XactOutcome &xo);
125  virtual void finalizeLogInfo();
126 
127 public:
128  ServiceRep &service();
129 
130 private:
133  void dieOnConnectionFailure();
134  void tellQueryAborted();
135  void maybeLog();
136 
137 protected:
139 
141  bool commEof;
143  bool isRetriable;
147 
150 
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 
158 private:
161 
164 
167 
169 };
170 
171 } // namespace Icap
172 } // namespace Adaptation
173 
174 #endif /* SQUID_SRC_ADAPTATION_ICAP_XACTION_H */
175 
void noteCommConnected(const CommConnectCbParams &io)
called when the connection attempt to an ICAP service completes (successfully or not)
Definition: Xaction.cc:253
common parts of HttpRequest and HttpReply
Definition: Message.h:25
AccessLogEntry & al
short for *alep
Definition: Xaction.h:152
int attempts
the number of times we tried to get to the service, including this time
Definition: Xaction.h:67
virtual void fillDoneStatus(MemBuf &buf) const
Definition: Xaction.cc:667
Xaction(const char *aTypeName, ServiceRep::Pointer &aService)
Definition: Xaction.cc:69
Definition: SBuf.h:93
ServiceRep & service()
Definition: Xaction.cc:110
virtual void fillPendingStatus(MemBuf &buf) const
Definition: Xaction.cc:649
void noteInitiatorAborted() override
Definition: Xaction.cc:546
void setOutcome(const XactOutcome &xo)
Definition: Xaction.cc:560
void useTransportConnection(const Comm::ConnectionPointer &)
Definition: Xaction.cc:268
void dnsLookupDone(std::optional< Ip::Address >)
Definition: Xaction.cc:187
void disableRepeats(const char *reason)
Definition: Xaction.cc:123
bool haveConnection() const
Definition: Xaction.cc:540
virtual void clearError()
clear stored error details, if any; used for retries/repeats
Definition: Xaction.h:118
void noteCommClosed(const CommCloseCbParams &io)
Definition: Xaction.cc:359
void noteCommWrote(const CommIoCbParams &io)
Definition: Xaction.cc:329
virtual void handleCommRead(size_t sz)=0
void noteCommRead(const CommIoCbParams &io)
Definition: Xaction.cc:426
bool isRepeatable
can repeat if no or unsatisfactory response
Definition: Xaction.h:144
AccessLogEntry::Pointer alep
icap.log entry
Definition: Xaction.h:151
AsyncCall::Pointer writer
Definition: Xaction.h:149
virtual void detailError(const ErrorDetailPointer &)
record error detail if possible
Definition: Xaction.h:82
bool repeatable() const
Definition: Xaction.h:53
Comm::ConnectionPointer connection
open and, if necessary, secured connection to the ICAP server (or nil)
Definition: Xaction.h:166
bool isRetriable
can retry on persistent connection failures
Definition: Xaction.h:143
Adaptation::Icap::ServiceRep::Pointer theService
Definition: Xaction.h:138
JobWait< Ssl::IcapPeerConnector > encryptionWait
waits for the established transport connection to be secured/encrypted
Definition: Xaction.h:163
void start() override
called by AsyncStart; do not call directly
Definition: Xaction.cc:130
Definition: MemBuf.h:23
const char * status() const override
internal cleanup; do not call directly
Definition: Xaction.cc:635
Definition: Xaction.cc:39
void swanSong() override
Definition: Xaction.cc:573
void useIcapConnection(const Comm::ConnectionPointer &)
react to the availability of a fully-ready ICAP connection
Definition: Xaction.cc:290
virtual bool fillVirginHttpHeader(MemBuf &) const
Definition: Xaction.cc:676
bool doneWithIo() const
Definition: Xaction.cc:533
HttpRequest * icapRequest
sent (or at least created) ICAP request
Definition: Xaction.h:63
bool waitingForDns
expecting a ipcache_nbgethostbyname() callback
Definition: Xaction.h:146
void callException(const std::exception &e) override
called when the job throws during an async call
Definition: Xaction.cc:372
bool mayReadMore() const
Definition: Xaction.cc:517
virtual void finalizeLogInfo()
Definition: Xaction.cc:612
const typedef char * XactOutcome
transaction result for logging
Definition: Elements.h:39
void handleSecuredPeer(Security::EncryptorAnswer &answer)
Definition: Xaction.cc:717
virtual void startShoveling()=0
starts sending/receiving ICAP messages
AsyncCall::Pointer reader
Definition: Xaction.h:148
void callEnd() override
called right after the called job method
Definition: Xaction.cc:379
JobWait< Comm::ConnOpener > transportWait
waits for a transport connection to the ICAP server to be established/opened
Definition: Xaction.h:160
bool doneAll() const override
whether positive goal has been reached
Definition: Xaction.cc:388
void noteCommTimedout(const CommTimeoutCbParams &io)
Definition: Xaction.cc:347
bool retriable() const
Definition: Xaction.h:52
virtual void handleCommWrote(size_t sz)=0
HttpReply::Pointer icapReply
received ICAP reply, if any
Definition: Xaction.h:64
void scheduleWrite(MemBuf &buf)
Definition: Xaction.cc:316
AsyncCall::Pointer closer
Definition: Xaction.h:168
virtual AccessLogEntry::Pointer masterLogEntry()
Definition: Xaction.cc:103
virtual bool doneReading() const
Definition: Xaction.cc:523
bool parseHttpMsg(Http::Message *msg)
Definition: Xaction.cc:497
virtual bool doneWriting() const
Definition: Xaction.cc:528

 

Introduction

Documentation

Support

Miscellaneous