Xaction.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 1996-2021 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_ICAPXACTION_H
10 #define SQUID_ICAPXACTION_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  virtual ~Xaction();
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  virtual void start();
71  virtual void noteInitiatorAborted(); // 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  virtual bool doneAll() const;
101 
102  // called just before the 'done' transaction is deleted
103  virtual void swanSong();
104 
105  // returns a temporary string depicting transaction status, for debugging
106  virtual const char *status() const;
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  virtual void callException(const std::exception &e);
116  virtual void callEnd();
118  virtual void clearError() {}
120  void dnsLookupDone(const ipcache_addrs *ia);
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_ICAPXACTION_H */
175 
void noteCommConnected(const CommConnectCbParams &io)
called when the connection attempt to an ICAP service completes (successfully or not)
Definition: Xaction.cc:249
common parts of HttpRequest and HttpReply
Definition: Message.h:26
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:665
void dnsLookupDone(const ipcache_addrs *ia)
Definition: Xaction.cc:183
Xaction(const char *aTypeName, ServiceRep::Pointer &aService)
Definition: Xaction.cc:80
Definition: SBuf.h:87
virtual bool doneAll() const
whether positive goal has been reached
Definition: Xaction.cc:387
ServiceRep & service()
Definition: Xaction.cc:121
virtual void fillPendingStatus(MemBuf &buf) const
Definition: Xaction.cc:647
void setOutcome(const XactOutcome &xo)
Definition: Xaction.cc:558
void useTransportConnection(const Comm::ConnectionPointer &)
Definition: Xaction.cc:264
void disableRepeats(const char *reason)
Definition: Xaction.cc:134
bool haveConnection() const
Definition: Xaction.cc:538
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:358
void noteCommWrote(const CommIoCbParams &io)
Definition: Xaction.cc:328
virtual void handleCommRead(size_t sz)=0
void noteCommRead(const CommIoCbParams &io)
Definition: Xaction.cc:425
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
virtual void callEnd()
called right after the called job method
Definition: Xaction.cc:378
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
Definition: MemBuf.h:24
Definition: Xaction.cc:49
void useIcapConnection(const Comm::ConnectionPointer &)
react to the availability of a fully-ready ICAP connection
Definition: Xaction.cc:289
virtual bool fillVirginHttpHeader(MemBuf &) const
Definition: Xaction.cc:674
bool doneWithIo() const
Definition: Xaction.cc:531
HttpRequest * icapRequest
sent (or at least created) ICAP request
Definition: Xaction.h:63
void const char int sz
Definition: stub_cbdata.cc:16
bool waitingForDns
expecting a ipcache_nbgethostbyname() callback
Definition: Xaction.h:146
virtual void callException(const std::exception &e)
called when the job throws during an async call
Definition: Xaction.cc:371
bool mayReadMore() const
Definition: Xaction.cc:515
virtual void finalizeLogInfo()
Definition: Xaction.cc:610
virtual void noteInitiatorAborted()
Definition: Xaction.cc:544
void handleSecuredPeer(Security::EncryptorAnswer &answer)
Definition: Xaction.cc:715
virtual void startShoveling()=0
starts sending/receiving ICAP messages
AsyncCall::Pointer reader
Definition: Xaction.h:148
JobWait< Comm::ConnOpener > transportWait
waits for a transport connection to the ICAP server to be established/opened
Definition: Xaction.h:160
virtual void swanSong()
Definition: Xaction.cc:571
void noteCommTimedout(const CommTimeoutCbParams &io)
Definition: Xaction.cc:346
virtual const char * status() const
internal cleanup; do not call directly
Definition: Xaction.cc:633
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:315
AsyncCall::Pointer closer
Definition: Xaction.h:168
virtual void start()
called by AsyncStart; do not call directly
Definition: Xaction.cc:141
virtual AccessLogEntry::Pointer masterLogEntry()
Definition: Xaction.cc:114
const char * XactOutcome
transaction result for logging
Definition: Elements.h:39
virtual bool doneReading() const
Definition: Xaction.cc:521
bool parseHttpMsg(Http::Message *msg)
Definition: Xaction.cc:495
virtual bool doneWriting() const
Definition: Xaction.cc:526

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors