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_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 ~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
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 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
113public:
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
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:718
void noteCommConnected(const CommConnectCbParams &io)
called when the connection attempt to an ICAP service completes (successfully or not)
Definition: Xaction.cc:255
void start() override
called by AsyncStart; do not call directly
Definition: Xaction.cc:132
AsyncCall::Pointer reader
Definition: Xaction.h:148
void noteCommWrote(const CommIoCbParams &io)
Definition: Xaction.cc:331
void callException(const std::exception &e) override
called when the job throws during an async call
Definition: Xaction.cc:374
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:541
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 bool fillVirginHttpHeader(MemBuf &) const
Definition: Xaction.cc:677
bool mayReadMore() const
Definition: Xaction.cc:518
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:498
void useTransportConnection(const Comm::ConnectionPointer &)
Definition: Xaction.cc:270
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:292
void noteCommClosed(const CommCloseCbParams &io)
Definition: Xaction.cc:361
virtual AccessLogEntry::Pointer masterLogEntry()
Definition: Xaction.cc:105
bool waitingForDns
expecting a ipcache_nbgethostbyname() callback
Definition: Xaction.h:146
virtual bool doneReading() const
Definition: Xaction.cc:524
Adaptation::Icap::ServiceRep::Pointer theService
Definition: Xaction.h:138
bool doneAll() const override
whether positive goal has been reached
Definition: Xaction.cc:390
virtual bool doneWriting() const
Definition: Xaction.cc:529
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
void swanSong() override
Definition: Xaction.cc:574
bool doneWithIo() const
Definition: Xaction.cc:534
virtual void startShoveling()=0
starts sending/receiving ICAP messages
ServiceRep & service()
Definition: Xaction.cc:112
Xaction(const char *aTypeName, ServiceRep::Pointer &aService)
Definition: Xaction.cc:71
virtual void fillDoneStatus(MemBuf &buf) const
Definition: Xaction.cc:668
void disableRepeats(const char *reason)
Definition: Xaction.cc:125
virtual void detailError(const ErrorDetailPointer &)
record error detail if possible
Definition: Xaction.h:82
void dnsLookupDone(std::optional< Ip::Address >)
Definition: Xaction.cc:189
const char * status() const override
internal cleanup; do not call directly
Definition: Xaction.cc:636
bool repeatable() const
Definition: Xaction.h:53
void noteCommRead(const CommIoCbParams &io)
Definition: Xaction.cc:428
void noteInitiatorAborted() override
Definition: Xaction.cc:547
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:318
AsyncCall::Pointer writer
Definition: Xaction.h:149
virtual void fillPendingStatus(MemBuf &buf) const
Definition: Xaction.cc:650
void callEnd() override
called right after the called job method
Definition: Xaction.cc:381
void setOutcome(const XactOutcome &xo)
Definition: Xaction.cc:561
virtual void handleCommWrote(size_t sz)=0
void noteCommTimedout(const CommTimeoutCbParams &io)
Definition: Xaction.cc:349
virtual void finalizeLogInfo()
Definition: Xaction.cc:613
common parts of HttpRequest and HttpReply
Definition: Message.h:26
Definition: MemBuf.h:24
Definition: SBuf.h:94
const char * XactOutcome
transaction result for logging
Definition: Elements.h:39
Definition: Xaction.cc:40

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors