]> git.ipfire.org Git - thirdparty/squid.git/blame - src/adaptation/icap/ServiceRep.h
Author: Tsantilas Christos <chtsanti@users.sourceforge.net> , Alex Rousskov <rousskov...
[thirdparty/squid.git] / src / adaptation / icap / ServiceRep.h
CommitLineData
774c051c 1
2/*
262a0e14 3 * $Id$
774c051c 4 *
5 *
6 * SQUID Web Proxy Cache http://www.squid-cache.org/
7 * ----------------------------------------------------------
8 *
9 * Squid is the result of efforts by numerous individuals from
10 * the Internet community; see the CONTRIBUTORS file for full
11 * details. Many organizations have provided support for Squid's
12 * development; see the SPONSORS file for full details. Squid is
13 * Copyrighted (C) 2001 by the Regents of the University of
14 * California; see the COPYRIGHT file for full details. Squid
15 * incorporates software developed and/or copyrighted by other
33ff9dbf 16 * sources; see the CREDITS file for full details.
774c051c 17 *
18 * This program is free software; you can redistribute it and/or modify
19 * it under the terms of the GNU General Public License as published by
20 * the Free Software Foundation; either version 2 of the License, or
21 * (at your option) any later version.
9e008dda 22 *
774c051c 23 * This program is distributed in the hope that it will be useful,
24 * but WITHOUT ANY WARRANTY; without even the implied warranty of
25 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26 * GNU General Public License for more details.
9e008dda 27 *
774c051c 28 * You should have received a copy of the GNU General Public License
29 * along with this program; if not, write to the Free Software
30 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA.
31 *
32 */
33
34#ifndef SQUID_ICAPSERVICEREP_H
35#define SQUID_ICAPSERVICEREP_H
36
aa839030 37#include "cbdata.h"
8277060a 38#include "FadingCounter.h"
a68cf076 39#include "adaptation/Service.h"
d81a31f1
AR
40#include "adaptation/forward.h"
41#include "adaptation/Initiator.h"
26cc52cb 42#include "adaptation/icap/Elements.h"
774c051c 43
26cc52cb 44
af6a12ee
AJ
45namespace Adaptation
46{
e1381638
AJ
47namespace Icap
48{
26cc52cb
AR
49
50class Options;
51class OptXact;
774c051c 52
53/* The ICAP service representative maintains information about a single ICAP
54 service that Squid communicates with. The representative initiates OPTIONS
55 requests to the service to keep cached options fresh. One ICAP server may
c99de607 56 host many ICAP services. */
57
58/*
1299ecbf 59 * A service with a fresh cached OPTIONS response and without many failures
60 * is an "up" service. All other services are "down". A service is "probed"
61 * if we tried to get an OPTIONS response from it and succeeded or failed.
62 * A probed down service is called "broken".
63 *
64 * The number of failures required to bring an up service down is determined
65 * by icap_service_failure_limit in squid.conf.
c99de607 66 *
67 * As a bootstrapping mechanism, ICAP transactions wait for an unprobed
68 * service to get a fresh OPTIONS response (see the callWhenReady method).
69 * The waiting callback is called when the OPTIONS transaction completes,
70 * even if the service is now broken.
71 *
72 * We do not initiate ICAP transactions with a broken service, but will
73 * eventually retry to fetch its options in hope to bring the service up.
74 *
75 * A service that should no longer be used after Squid reconfiguration is
9e008dda
AJ
76 * treated as if it does not have a fresh cached OPTIONS response. We do
77 * not try to fetch fresh options for such a service. It should be
c99de607 78 * auto-destroyed by refcounting when no longer used.
79 */
80
774c051c 81
26cc52cb 82class ServiceRep : public RefCountable, public Adaptation::Service,
e1381638 83 public Adaptation::Initiator
774c051c 84{
85
86public:
26cc52cb 87 typedef RefCount<ServiceRep> Pointer;
774c051c 88
89public:
26cc52cb
AR
90 ServiceRep(const Adaptation::ServiceConfig &config);
91 virtual ~ServiceRep();
774c051c 92
62c7f90e
AR
93 virtual void finalize();
94
76fc7e57
AJ
95 virtual bool probed() const; // see comments above
96 virtual bool up() const; // see comments above
774c051c 97
d81a31f1
AR
98 virtual Adaptation::Initiate *makeXactLauncher(Adaptation::Initiator *, HttpMsg *virginHeader, HttpRequest *virginCause);
99
bd7f2ede 100 void callWhenReady(AsyncCall::Pointer &cb);
774c051c 101
774c051c 102 // the methods below can only be called on an up() service
30abd221 103 bool wantsUrl(const String &urlPath) const;
104 bool wantsPreview(const String &urlPath, size_t &wantedSize) const;
774c051c 105 bool allows204() const;
83c51da9 106 bool allows206() const;
774c051c 107
c99de607 108 void noteFailure(); // called by transactions to report service failure
9e008dda 109
bd7f2ede 110 //AsyncJob virtual methods
d81a31f1 111 virtual bool doneAll() const { return Adaptation::Initiator::doneAll() && false;}
c99de607 112
76fc7e57
AJ
113 virtual void detach();
114 virtual bool detached() const;
115
774c051c 116public: // treat these as private, they are for callbacks only
117 void noteTimeToUpdate();
118 void noteTimeToNotify();
c824c43b 119
120 // receive either an ICAP OPTIONS response header or an abort message
d81a31f1
AR
121 virtual void noteAdaptationAnswer(HttpMsg *msg);
122 virtual void noteAdaptationQueryAbort(bool);
774c051c 123
124private:
125 // stores Prepare() callback info
126
9e008dda 127 struct Client {
774c051c 128 Pointer service; // one for each client to preserve service
bd7f2ede 129 AsyncCall::Pointer callback;
774c051c 130 };
131
132 typedef Vector<Client> Clients;
133 Clients theClients; // all clients waiting for a call back
134
26cc52cb 135 Options *theOptions;
d81a31f1 136 Adaptation::Initiate *theOptionsFetcher; // pending ICAP OPTIONS transaction
c99de607 137 time_t theLastUpdate; // time the options were last updated
138
8277060a 139 FadingCounter theSessionFailures;
c99de607 140 const char *isSuspended; // also stores suspension reason for debugging
774c051c 141
774c051c 142 bool notifying; // may be true in any state except for the initial
c99de607 143 bool updateScheduled; // time-based options update has been scheduled
774c051c 144
145private:
146 ICAP::Method parseMethod(const char *) const;
147 ICAP::VectPoint parseVectPoint(const char *) const;
148
c99de607 149 void suspend(const char *reason);
150
151 bool hasOptions() const;
774c051c 152 bool needNewOptions() const;
1299ecbf 153 time_t optionsFetchTime() const;
774c051c 154
1299ecbf 155 void scheduleUpdate(time_t when);
774c051c 156 void scheduleNotification();
c99de607 157
774c051c 158 void startGettingOptions();
26cc52cb
AR
159 void handleNewOptions(Options *newOptions);
160 void changeOptions(Options *newOptions);
c99de607 161 void checkOptions();
162
163 void announceStatusChange(const char *downPhrase, bool important) const;
774c051c 164
165 const char *status() const;
166
c99de607 167 mutable bool wasAnnouncedUp; // prevent sequential same-state announcements
76fc7e57 168 bool isDetached;
26cc52cb 169 CBDATA_CLASS2(ServiceRep);
774c051c 170};
171
26cc52cb
AR
172
173} // namespace Icap
174} // namespace Adaptation
175
774c051c 176#endif /* SQUID_ICAPSERVICEREP_H */