Xaction.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 1996-2017 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 "comm/ConnOpener.h"
16 #include "HttpReply.h"
17 #include "ipcache.h"
18 #include "sbuf/SBuf.h"
19 
20 class MemBuf;
21 
22 namespace Adaptation
23 {
24 namespace Icap
25 {
26 
27 /*
28  * The ICAP Xaction implements common tasks for ICAP OPTIONS, REQMOD, and
29  * RESPMOD transactions. It is started by an Initiator. It terminates
30  * on its own, when done. Transactions communicate with Initiator using
31  * asynchronous messages because a transaction or Initiator may be gone at
32  * any time.
33  */
34 
35 // Note: Xaction must be the first parent for object-unaware cbdata to work
36 
38 {
39 
40 public:
41  Xaction(const char *aTypeName, ServiceRep::Pointer &aService);
42  virtual ~Xaction();
43 
44  void disableRetries();
45  void disableRepeats(const char *reason);
46  bool retriable() const { return isRetriable; }
47  bool repeatable() const { return isRepeatable; }
48 
49  // comm handler wrappers, treat as private
50  void noteCommConnected(const CommConnectCbParams &io);
51  void noteCommWrote(const CommIoCbParams &io);
52  void noteCommRead(const CommIoCbParams &io);
53  void noteCommTimedout(const CommTimeoutCbParams &io);
54  void noteCommClosed(const CommCloseCbParams &io);
55 
56  // TODO: create these only when actually sending/receiving
59 
61  int attempts;
62 
63 protected:
64  virtual void start();
65  virtual void noteInitiatorAborted(); // TODO: move to Adaptation::Initiate
66 
67  // comm hanndlers; called by comm handler wrappers
68  virtual void handleCommConnected() = 0;
69  virtual void handleCommWrote(size_t sz) = 0;
70  virtual void handleCommRead(size_t sz) = 0;
71  virtual void handleCommTimedout();
72  virtual void handleCommClosed();
73 
76  virtual void detailError(int) {}
77 
78  void openConnection();
79  void closeConnection();
81  bool haveConnection() const;
82 
83  void scheduleRead();
84  void scheduleWrite(MemBuf &buf);
85  void updateTimeout();
86 
87  void cancelRead();
88 
89  bool parseHttpMsg(Http::Message *msg); // true=success; false=needMore; throw=err
90  bool mayReadMore() const;
91 
92  virtual bool doneReading() const;
93  virtual bool doneWriting() const;
94  bool doneWithIo() const;
95  virtual bool doneAll() const;
96 
97  // called just before the 'done' transaction is deleted
98  virtual void swanSong();
99 
100  // returns a temporary string depicting transaction status, for debugging
101  virtual const char *status() const;
102  virtual void fillPendingStatus(MemBuf &buf) const;
103  virtual void fillDoneStatus(MemBuf &buf) const;
104 
105  // useful for debugging
106  virtual bool fillVirginHttpHeader(MemBuf&) const;
107 
108 public:
109  // custom exception handling and end-of-call checks
110  virtual void callException(const std::exception &e);
111  virtual void callEnd();
113  virtual void clearError() {}
115  void dnsLookupDone(const ipcache_addrs *ia);
116 
117 protected:
118  // logging
119  void setOutcome(const XactOutcome &xo);
120  virtual void finalizeLogInfo();
121 
122 public:
123  ServiceRep &service();
124 
125 private:
126  void tellQueryAborted();
127  void maybeLog();
128 
129 protected:
132 
134  bool commEof;
136  bool isRetriable;
139 
140  const char *stopReason;
141 
142  // active (pending) comm callbacks for the ICAP server connection
147 
150 
151  timeval icap_tr_start; /*time when the ICAP transaction was created */
152  timeval icap_tio_start; /*time when the first ICAP request byte was scheduled for sending*/
153  timeval icap_tio_finish; /*time when the last byte of the ICAP responsewas received*/
154 
155 private:
158 };
159 
160 } // namespace Icap
161 } // namespace Adaptation
162 
163 #endif /* SQUID_ICAPXACTION_H */
164 
bool retriable() const
Definition: Xaction.h:46
bool isRepeatable
can repeat if no or unsatisfactory response
Definition: Xaction.h:137
void noteCommClosed(const CommCloseCbParams &io)
Definition: Xaction.cc:385
void handleSecuredPeer(Security::EncryptorAnswer &answer)
Definition: Xaction.cc:738
bool isRetriable
can retry on persistent connection failures
Definition: Xaction.h:136
AsyncCall::Pointer reader
Definition: Xaction.h:144
virtual void start()
called by AsyncStart; do not call directly
Definition: Xaction.cc:143
AsyncCall::Pointer writer
Definition: Xaction.h:145
Definition: SBuf.h:87
virtual void noteInitiatorAborted()
Definition: Xaction.cc:572
HttpReply::Pointer icapReply
received ICAP reply, if any
Definition: Xaction.h:58
const char * XactOutcome
transaction result for logging
Definition: Elements.h:39
AsyncCall::Pointer closer
Definition: Xaction.h:146
void noteCommTimedout(const CommTimeoutCbParams &io)
Definition: Xaction.cc:362
bool repeatable() const
Definition: Xaction.h:47
virtual void handleCommTimedout()
Definition: Xaction.cc:367
virtual void callEnd()
called right after the called job method
Definition: Xaction.cc:408
virtual bool doneReading() const
Definition: Xaction.cc:549
void noteCommConnected(const CommConnectCbParams &io)
Definition: Xaction.cc:278
virtual void handleCommWrote(size_t sz)=0
virtual void detailError(int)
record error detail if possible
Definition: Xaction.h:76
bool parseHttpMsg(Http::Message *msg)
Definition: Xaction.cc:523
virtual void handleCommConnected()=0
virtual void callException(const std::exception &e)
called when the job throws during an async call
Definition: Xaction.cc:401
ServiceRep & service()
Definition: Xaction.cc:123
virtual void swanSong()
Definition: Xaction.cc:599
virtual AccessLogEntry::Pointer masterLogEntry()
Definition: Xaction.cc:116
virtual void fillDoneStatus(MemBuf &buf) const
Definition: Xaction.cc:693
const char * stopReason
Definition: Xaction.h:140
int attempts
the number of times we tried to get to the service, including this time
Definition: Xaction.h:61
virtual bool doneWriting() const
Definition: Xaction.cc:554
bool haveConnection() const
Definition: Xaction.cc:566
common parts of HttpRequest and HttpReply
Definition: Message.h:24
virtual void clearError()
clear stored error details, if any; used for retries/repeats
Definition: Xaction.h:113
bool doneWithIo() const
Definition: Xaction.cc:559
virtual void handleCommClosed()
Definition: Xaction.cc:395
void dnsLookupDone(const ipcache_addrs *ia)
Definition: Xaction.cc:194
Xaction(const char *aTypeName, ServiceRep::Pointer &aService)
Definition: Xaction.cc:76
void const char * buf
Definition: stub_helper.cc:16
void noteCommRead(const CommIoCbParams &io)
Definition: Xaction.cc:453
void disableRepeats(const char *reason)
Definition: Xaction.cc:136
AsyncCall::Pointer securer
whether we are securing a connection
Definition: Xaction.h:157
virtual const char * status() const
internal cleanup; do not call directly
Definition: Xaction.cc:664
virtual bool doneAll() const
whether positive goal has been reached
Definition: Xaction.cc:417
AsyncCall::Pointer connector
Definition: Xaction.h:143
void scheduleWrite(MemBuf &buf)
Definition: Xaction.cc:331
HttpRequest * icapRequest
sent (or at least created) ICAP request
Definition: Xaction.h:57
void noteCommWrote(const CommIoCbParams &io)
Definition: Xaction.cc:344
void setOutcome(const XactOutcome &xo)
Definition: Xaction.cc:585
Definition: MemBuf.h:23
Comm::ConnectionPointer connection
ICAP server connection.
Definition: Xaction.h:130
virtual bool fillVirginHttpHeader(MemBuf &) const
Definition: Xaction.cc:702
AccessLogEntry & al
short for *alep
Definition: Xaction.h:149
AccessLogEntry::Pointer alep
icap.log entry
Definition: Xaction.h:148
virtual void fillPendingStatus(MemBuf &buf) const
Definition: Xaction.cc:678
virtual void finalizeLogInfo()
Definition: Xaction.cc:641
bool mayReadMore() const
Definition: Xaction.cc:543
Comm::ConnOpener::Pointer cs
Definition: Xaction.h:156
virtual void handleCommRead(size_t sz)=0
Adaptation::Icap::ServiceRep::Pointer theService
Definition: Xaction.h:131

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors