]>
Commit | Line | Data |
---|---|---|
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" |
a68cf076 | 38 | #include "adaptation/Service.h" |
d81a31f1 AR |
39 | #include "adaptation/forward.h" |
40 | #include "adaptation/Initiator.h" | |
774c051c | 41 | #include "ICAPElements.h" |
42 | ||
43 | class ICAPOptions; | |
774c051c | 44 | class ICAPOptXact; |
45 | ||
46 | /* The ICAP service representative maintains information about a single ICAP | |
47 | service that Squid communicates with. The representative initiates OPTIONS | |
48 | requests to the service to keep cached options fresh. One ICAP server may | |
c99de607 | 49 | host many ICAP services. */ |
50 | ||
51 | /* | |
1299ecbf | 52 | * A service with a fresh cached OPTIONS response and without many failures |
53 | * is an "up" service. All other services are "down". A service is "probed" | |
54 | * if we tried to get an OPTIONS response from it and succeeded or failed. | |
55 | * A probed down service is called "broken". | |
56 | * | |
57 | * The number of failures required to bring an up service down is determined | |
58 | * by icap_service_failure_limit in squid.conf. | |
c99de607 | 59 | * |
60 | * As a bootstrapping mechanism, ICAP transactions wait for an unprobed | |
61 | * service to get a fresh OPTIONS response (see the callWhenReady method). | |
62 | * The waiting callback is called when the OPTIONS transaction completes, | |
63 | * even if the service is now broken. | |
64 | * | |
65 | * We do not initiate ICAP transactions with a broken service, but will | |
66 | * eventually retry to fetch its options in hope to bring the service up. | |
67 | * | |
68 | * A service that should no longer be used after Squid reconfiguration is | |
9e008dda AJ |
69 | * treated as if it does not have a fresh cached OPTIONS response. We do |
70 | * not try to fetch fresh options for such a service. It should be | |
c99de607 | 71 | * auto-destroyed by refcounting when no longer used. |
72 | */ | |
73 | ||
774c051c | 74 | |
a68cf076 | 75 | class ICAPServiceRep : public RefCountable, public Adaptation::Service, |
9e008dda | 76 | public Adaptation::Initiator |
774c051c | 77 | { |
78 | ||
79 | public: | |
80 | typedef RefCount<ICAPServiceRep> Pointer; | |
81 | ||
82 | public: | |
d81a31f1 | 83 | ICAPServiceRep(const Adaptation::ServiceConfig &config); |
774c051c | 84 | virtual ~ICAPServiceRep(); |
85 | ||
62c7f90e AR |
86 | void setSelf(Pointer &aSelf); // needs self pointer for ICAPOptXact |
87 | virtual void finalize(); | |
88 | ||
774c051c | 89 | void invalidate(); // call when the service is no longer needed or valid |
90 | ||
c99de607 | 91 | bool probed() const; // see comments above |
c99de607 | 92 | bool up() const; // see comments above |
774c051c | 93 | |
d81a31f1 AR |
94 | virtual Adaptation::Initiate *makeXactLauncher(Adaptation::Initiator *, HttpMsg *virginHeader, HttpRequest *virginCause); |
95 | ||
bd7f2ede | 96 | void callWhenReady(AsyncCall::Pointer &cb); |
774c051c | 97 | |
774c051c | 98 | // the methods below can only be called on an up() service |
30abd221 | 99 | bool wantsUrl(const String &urlPath) const; |
100 | bool wantsPreview(const String &urlPath, size_t &wantedSize) const; | |
774c051c | 101 | bool allows204() const; |
102 | ||
c99de607 | 103 | void noteFailure(); // called by transactions to report service failure |
9e008dda | 104 | |
bd7f2ede | 105 | //AsyncJob virtual methods |
d81a31f1 | 106 | virtual bool doneAll() const { return Adaptation::Initiator::doneAll() && false;} |
c99de607 | 107 | |
774c051c | 108 | public: // treat these as private, they are for callbacks only |
109 | void noteTimeToUpdate(); | |
110 | void noteTimeToNotify(); | |
c824c43b | 111 | |
112 | // receive either an ICAP OPTIONS response header or an abort message | |
d81a31f1 AR |
113 | virtual void noteAdaptationAnswer(HttpMsg *msg); |
114 | virtual void noteAdaptationQueryAbort(bool); | |
774c051c | 115 | |
116 | private: | |
117 | // stores Prepare() callback info | |
118 | ||
9e008dda | 119 | struct Client { |
774c051c | 120 | Pointer service; // one for each client to preserve service |
bd7f2ede | 121 | AsyncCall::Pointer callback; |
774c051c | 122 | }; |
123 | ||
124 | typedef Vector<Client> Clients; | |
125 | Clients theClients; // all clients waiting for a call back | |
126 | ||
127 | ICAPOptions *theOptions; | |
d81a31f1 | 128 | Adaptation::Initiate *theOptionsFetcher; // pending ICAP OPTIONS transaction |
c99de607 | 129 | time_t theLastUpdate; // time the options were last updated |
130 | ||
131 | static const int TheSessionFailureLimit; | |
132 | int theSessionFailures; | |
133 | const char *isSuspended; // also stores suspension reason for debugging | |
774c051c | 134 | |
774c051c | 135 | bool notifying; // may be true in any state except for the initial |
c99de607 | 136 | bool updateScheduled; // time-based options update has been scheduled |
774c051c | 137 | |
138 | private: | |
139 | ICAP::Method parseMethod(const char *) const; | |
140 | ICAP::VectPoint parseVectPoint(const char *) const; | |
141 | ||
c99de607 | 142 | void suspend(const char *reason); |
143 | ||
144 | bool hasOptions() const; | |
774c051c | 145 | bool needNewOptions() const; |
1299ecbf | 146 | time_t optionsFetchTime() const; |
774c051c | 147 | |
1299ecbf | 148 | void scheduleUpdate(time_t when); |
774c051c | 149 | void scheduleNotification(); |
c99de607 | 150 | |
774c051c | 151 | void startGettingOptions(); |
c824c43b | 152 | void handleNewOptions(ICAPOptions *newOptions); |
c99de607 | 153 | void changeOptions(ICAPOptions *newOptions); |
154 | void checkOptions(); | |
155 | ||
156 | void announceStatusChange(const char *downPhrase, bool important) const; | |
774c051c | 157 | |
158 | const char *status() const; | |
159 | ||
160 | Pointer self; | |
c99de607 | 161 | mutable bool wasAnnouncedUp; // prevent sequential same-state announcements |
774c051c | 162 | CBDATA_CLASS2(ICAPServiceRep); |
163 | }; | |
164 | ||
774c051c | 165 | #endif /* SQUID_ICAPSERVICEREP_H */ |