]>
Commit | Line | Data |
---|---|---|
774c051c | 1 | |
2 | /* | |
33ff9dbf | 3 | * $Id: ICAPServiceRep.h,v 1.3 2005/12/22 22:26:31 wessels 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 | ||
37 | #include "ICAPElements.h" | |
38 | ||
39 | class ICAPOptions; | |
40 | ||
41 | class ICAPOptXact; | |
42 | ||
43 | /* The ICAP service representative maintains information about a single ICAP | |
44 | service that Squid communicates with. The representative initiates OPTIONS | |
45 | requests to the service to keep cached options fresh. One ICAP server may | |
46 | host many ICAP services */ | |
47 | ||
48 | class ICAPServiceRep : public RefCountable | |
49 | { | |
50 | ||
51 | public: | |
52 | typedef RefCount<ICAPServiceRep> Pointer; | |
53 | ||
54 | public: | |
55 | ICAPServiceRep(); | |
56 | virtual ~ICAPServiceRep(); | |
57 | ||
58 | bool configure(Pointer &aSelf); // needs self pointer for ICAPOptXact | |
59 | void invalidate(); // call when the service is no longer needed or valid | |
60 | ||
61 | const char *methodStr() const; | |
62 | const char *vectPointStr() const; | |
63 | ||
64 | bool up() const; | |
65 | ||
66 | /* Service is "up" iff there is a fresh cached OPTIONS response. To | |
67 | get an OPTIONS response, ICAPServiceRep does an OPTIONS | |
68 | transaction. Failed transaction results in a "down" service. The | |
69 | Callback is called if/once the service is in a steady ("up" or | |
70 | "down") state. */ | |
71 | typedef void Callback(void *data, Pointer &service); | |
72 | void callWhenReady(Callback *cb, void *data); | |
73 | ||
74 | ||
75 | // the methods below can only be called on an up() service | |
76 | ||
77 | bool wantsPreview(size_t &wantedSize) const; | |
78 | bool allows204() const; | |
79 | ||
80 | public: | |
81 | String key; | |
82 | ICAP::Method method; | |
83 | ICAP::VectPoint point; | |
84 | String uri; // service URI | |
85 | ||
86 | // URI components | |
87 | String host; | |
88 | int port; | |
89 | String resource; | |
90 | ||
91 | // non-options flags; TODO: check that both are used. | |
92 | bool bypass; | |
93 | bool unreachable; | |
94 | ||
95 | public: // treat these as private, they are for callbacks only | |
96 | void noteTimeToUpdate(); | |
97 | void noteTimeToNotify(); | |
98 | void noteNewOptions(ICAPOptXact *x); | |
99 | ||
100 | private: | |
101 | // stores Prepare() callback info | |
102 | ||
103 | struct Client | |
104 | { | |
105 | Pointer service; // one for each client to preserve service | |
106 | Callback *callback; | |
107 | void *data; | |
108 | }; | |
109 | ||
110 | typedef Vector<Client> Clients; | |
111 | Clients theClients; // all clients waiting for a call back | |
112 | ||
113 | ICAPOptions *theOptions; | |
114 | ||
115 | typedef enum { stateInit, stateWait, stateUp, stateDown } State; | |
116 | State theState; | |
117 | bool notifying; // may be true in any state except for the initial | |
118 | ||
119 | private: | |
120 | ICAP::Method parseMethod(const char *) const; | |
121 | ICAP::VectPoint parseVectPoint(const char *) const; | |
122 | ||
123 | bool waiting() const; | |
124 | bool needNewOptions() const; | |
125 | ||
126 | void scheduleNotification(); | |
127 | void changeOptions(ICAPOptions *newOptions); | |
128 | void startGettingOptions(); | |
129 | void scheduleUpdate(); | |
130 | ||
131 | const char *status() const; | |
132 | ||
133 | Pointer self; | |
134 | CBDATA_CLASS2(ICAPServiceRep); | |
135 | }; | |
136 | ||
137 | ||
138 | #endif /* SQUID_ICAPSERVICEREP_H */ |