Xaction.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 1996-2022 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
22class MemBuf;
23
24namespace Ssl {
25class IcapPeerConnector;
26}
27
28namespace Adaptation
29{
30namespace 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
46public:
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
57 void noteCommWrote(const CommIoCbParams &io);
58 void noteCommRead(const CommIoCbParams &io);
60 void noteCommClosed(const CommCloseCbParams &io);
61
62 // TODO: create these only when actually sending/receiving
65
68
69protected:
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
113public:
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() {}
121
122protected:
123 // logging
124 void setOutcome(const XactOutcome &xo);
125 virtual void finalizeLogInfo();
126
127public:
129
130private:
134 void tellQueryAborted();
135 void maybeLog();
136
137protected:
139
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
158private:
161
164
167
169};
170
171} // namespace Icap
172} // namespace Adaptation
173
174#endif /* SQUID_ICAPXACTION_H */
175
bool isRetriable
can retry on persistent connection failures
Definition: Xaction.h:143
int attempts
the number of times we tried to get to the service, including this time
Definition: Xaction.h:67
void handleSecuredPeer(Security::EncryptorAnswer &answer)
Definition: Xaction.cc:714
void noteCommConnected(const CommConnectCbParams &io)
called when the connection attempt to an ICAP service completes (successfully or not)
Definition: Xaction.cc:248
AsyncCall::Pointer reader
Definition: Xaction.h:148
void noteCommWrote(const CommIoCbParams &io)
Definition: Xaction.cc:327
Comm::ConnectionPointer connection
open and, if necessary, secured connection to the ICAP server (or nil)
Definition: Xaction.h:166
bool haveConnection() const
Definition: Xaction.cc:537
virtual void handleCommRead(size_t sz)=0
JobWait< Ssl::IcapPeerConnector > encryptionWait
waits for the established transport connection to be secured/encrypted
Definition: Xaction.h:163
virtual void callEnd()
called right after the called job method
Definition: Xaction.cc:377
virtual bool fillVirginHttpHeader(MemBuf &) const
Definition: Xaction.cc:673
bool mayReadMore() const
Definition: Xaction.cc:514
void dnsLookupDone(Optional< Ip::Address >)
Definition: Xaction.cc:182
AccessLogEntry::Pointer alep
icap.log entry
Definition: Xaction.h:151
HttpReply::Pointer icapReply
received ICAP reply, if any
Definition: Xaction.h:64
AsyncCall::Pointer closer
Definition: Xaction.h:168
HttpRequest * icapRequest
sent (or at least created) ICAP request
Definition: Xaction.h:63
bool parseHttpMsg(Http::Message *msg)
Definition: Xaction.cc:494
void useTransportConnection(const Comm::ConnectionPointer &)
Definition: Xaction.cc:263
bool isRepeatable
can repeat if no or unsatisfactory response
Definition: Xaction.h:144
void useIcapConnection(const Comm::ConnectionPointer &)
react to the availability of a fully-ready ICAP connection
Definition: Xaction.cc:288
void noteCommClosed(const CommCloseCbParams &io)
Definition: Xaction.cc:357
virtual void noteInitiatorAborted()
Definition: Xaction.cc:543
virtual AccessLogEntry::Pointer masterLogEntry()
Definition: Xaction.cc:114
bool waitingForDns
expecting a ipcache_nbgethostbyname() callback
Definition: Xaction.h:146
virtual bool doneReading() const
Definition: Xaction.cc:520
virtual bool doneAll() const
whether positive goal has been reached
Definition: Xaction.cc:386
Adaptation::Icap::ServiceRep::Pointer theService
Definition: Xaction.h:138
virtual bool doneWriting() const
Definition: Xaction.cc:525
JobWait< Comm::ConnOpener > transportWait
waits for a transport connection to the ICAP server to be established/opened
Definition: Xaction.h:160
bool retriable() const
Definition: Xaction.h:52
bool doneWithIo() const
Definition: Xaction.cc:530
virtual const char * status() const
internal cleanup; do not call directly
Definition: Xaction.cc:632
virtual void startShoveling()=0
starts sending/receiving ICAP messages
ServiceRep & service()
Definition: Xaction.cc:121
Xaction(const char *aTypeName, ServiceRep::Pointer &aService)
Definition: Xaction.cc:80
virtual void fillDoneStatus(MemBuf &buf) const
Definition: Xaction.cc:664
virtual void swanSong()
Definition: Xaction.cc:570
void disableRepeats(const char *reason)
Definition: Xaction.cc:134
virtual void detailError(const ErrorDetailPointer &)
record error detail if possible
Definition: Xaction.h:82
virtual void start()
called by AsyncStart; do not call directly
Definition: Xaction.cc:141
bool repeatable() const
Definition: Xaction.h:53
void noteCommRead(const CommIoCbParams &io)
Definition: Xaction.cc:424
AccessLogEntry & al
short for *alep
Definition: Xaction.h:152
virtual void clearError()
clear stored error details, if any; used for retries/repeats
Definition: Xaction.h:118
void scheduleWrite(MemBuf &buf)
Definition: Xaction.cc:314
AsyncCall::Pointer writer
Definition: Xaction.h:149
virtual void fillPendingStatus(MemBuf &buf) const
Definition: Xaction.cc:646
virtual void callException(const std::exception &e)
called when the job throws during an async call
Definition: Xaction.cc:370
void setOutcome(const XactOutcome &xo)
Definition: Xaction.cc:557
virtual void handleCommWrote(size_t sz)=0
void noteCommTimedout(const CommTimeoutCbParams &io)
Definition: Xaction.cc:345
virtual void finalizeLogInfo()
Definition: Xaction.cc:609
common parts of HttpRequest and HttpReply
Definition: Message.h:26
Definition: MemBuf.h:24
(limited) std::optional replacement (until we upgrade to C++17)
Definition: Optional.h:30
Definition: SBuf.h:94
const char * XactOutcome
transaction result for logging
Definition: Elements.h:39
Definition: Xaction.cc:49
void const char int sz
Definition: stub_cbdata.cc:16

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors