]> git.ipfire.org Git - thirdparty/squid.git/blame - src/ICAP/ICAPServiceRep.h
Bug #1974 fix: Bypass failures of optional ICAP services.
[thirdparty/squid.git] / src / ICAP / ICAPServiceRep.h
CommitLineData
774c051c 1
2/*
30abd221 3 * $Id: ICAPServiceRep.h,v 1.9 2007/05/29 13:31:44 amosjeffries Exp $
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.
22 *
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.
27 *
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"
c824c43b 38#include "ICAPInitiator.h"
774c051c 39#include "ICAPElements.h"
40
41class ICAPOptions;
774c051c 42class ICAPOptXact;
43
44/* The ICAP service representative maintains information about a single ICAP
45 service that Squid communicates with. The representative initiates OPTIONS
46 requests to the service to keep cached options fresh. One ICAP server may
c99de607 47 host many ICAP services. */
48
49/*
50 * A service is "up" if there is a fresh cached OPTIONS response and is
51 * "down" otherwise. A service is "probed" if we tried to get an OPTIONS
52 * response from it and succeeded or failed. A probed down service is
53 * called "broken".
54 *
55 * As a bootstrapping mechanism, ICAP transactions wait for an unprobed
56 * service to get a fresh OPTIONS response (see the callWhenReady method).
57 * The waiting callback is called when the OPTIONS transaction completes,
58 * even if the service is now broken.
59 *
60 * We do not initiate ICAP transactions with a broken service, but will
61 * eventually retry to fetch its options in hope to bring the service up.
62 *
63 * A service that should no longer be used after Squid reconfiguration is
64 * treated as if it does not have a fresh cached OPTIONS response. We do
65 * not try to fetch fresh options for such a service. It should be
66 * auto-destroyed by refcounting when no longer used.
67 */
68
774c051c 69
c824c43b 70class ICAPServiceRep : public RefCountable, public ICAPInitiator
774c051c 71{
72
73public:
74 typedef RefCount<ICAPServiceRep> Pointer;
75
76public:
77 ICAPServiceRep();
78 virtual ~ICAPServiceRep();
79
80 bool configure(Pointer &aSelf); // needs self pointer for ICAPOptXact
81 void invalidate(); // call when the service is no longer needed or valid
82
83 const char *methodStr() const;
84 const char *vectPointStr() const;
85
c99de607 86 bool probed() const; // see comments above
87 bool broken() const; // see comments above
88 bool up() const; // see comments above
774c051c 89
774c051c 90 typedef void Callback(void *data, Pointer &service);
91 void callWhenReady(Callback *cb, void *data);
92
774c051c 93 // the methods below can only be called on an up() service
30abd221 94 bool wantsUrl(const String &urlPath) const;
95 bool wantsPreview(const String &urlPath, size_t &wantedSize) const;
774c051c 96 bool allows204() const;
97
c99de607 98 void noteFailure(); // called by transactions to report service failure
99
774c051c 100public:
30abd221 101 String key;
774c051c 102 ICAP::Method method;
103 ICAP::VectPoint point;
30abd221 104 String uri; // service URI
774c051c 105
106 // URI components
30abd221 107 String host;
774c051c 108 int port;
30abd221 109 String resource;
774c051c 110
c99de607 111 // XXX: use it when selecting a service and handling ICAP errors!
774c051c 112 bool bypass;
774c051c 113
114public: // treat these as private, they are for callbacks only
115 void noteTimeToUpdate();
116 void noteTimeToNotify();
c824c43b 117
118 // receive either an ICAP OPTIONS response header or an abort message
119 virtual void noteIcapAnswer(HttpMsg *msg);
120 virtual void noteIcapQueryAbort(bool);
774c051c 121
122private:
123 // stores Prepare() callback info
124
125 struct Client
126 {
127 Pointer service; // one for each client to preserve service
128 Callback *callback;
129 void *data;
130 };
131
132 typedef Vector<Client> Clients;
133 Clients theClients; // all clients waiting for a call back
134
135 ICAPOptions *theOptions;
c99de607 136 time_t theLastUpdate; // time the options were last updated
137
138 static const int TheSessionFailureLimit;
139 int theSessionFailures;
140 const char *isSuspended; // also stores suspension reason for debugging
774c051c 141
c99de607 142 bool waiting; // for an OPTIONS transaction to finish
774c051c 143 bool notifying; // may be true in any state except for the initial
c99de607 144 bool updateScheduled; // time-based options update has been scheduled
774c051c 145
146private:
147 ICAP::Method parseMethod(const char *) const;
148 ICAP::VectPoint parseVectPoint(const char *) const;
149
c99de607 150 void suspend(const char *reason);
151
152 bool hasOptions() const;
774c051c 153 bool needNewOptions() const;
154
c99de607 155 void scheduleUpdate();
774c051c 156 void scheduleNotification();
c99de607 157
774c051c 158 void startGettingOptions();
c824c43b 159 void handleNewOptions(ICAPOptions *newOptions);
c99de607 160 void changeOptions(ICAPOptions *newOptions);
161 void checkOptions();
162
163 void announceStatusChange(const char *downPhrase, bool important) const;
774c051c 164
165 const char *status() const;
166
167 Pointer self;
c99de607 168 mutable bool wasAnnouncedUp; // prevent sequential same-state announcements
774c051c 169 CBDATA_CLASS2(ICAPServiceRep);
170};
171
172
173#endif /* SQUID_ICAPSERVICEREP_H */