]> git.ipfire.org Git - thirdparty/squid.git/blob - src/helper.h
Merged from trunk
[thirdparty/squid.git] / src / helper.h
1 /*
2 * DEBUG: section 84 Helper process maintenance
3 * AUTHOR: Harvest Derived?
4 *
5 * SQUID Web Proxy Cache http://www.squid-cache.org/
6 * ----------------------------------------------------------
7 *
8 * Squid is the result of efforts by numerous individuals from
9 * the Internet community; see the CONTRIBUTORS file for full
10 * details. Many organizations have provided support for Squid's
11 * development; see the SPONSORS file for full details. Squid is
12 * Copyrighted (C) 2001 by the Regents of the University of
13 * California; see the COPYRIGHT file for full details. Squid
14 * incorporates software developed and/or copyrighted by other
15 * sources; see the CREDITS file for full details.
16 *
17 * This program is free software; you can redistribute it and/or modify
18 * it under the terms of the GNU General Public License as published by
19 * the Free Software Foundation; either version 2 of the License, or
20 * (at your option) any later version.
21 *
22 * This program is distributed in the hope that it will be useful,
23 * but WITHOUT ANY WARRANTY; without even the implied warranty of
24 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 * GNU General Public License for more details.
26 *
27 * You should have received a copy of the GNU General Public License
28 * along with this program; if not, write to the Free Software
29 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA.
30 *
31 */
32
33 #ifndef SQUID_HELPER_H
34 #define SQUID_HELPER_H
35
36 #include "base/AsyncCall.h"
37 #include "cbdata.h"
38 #include "comm/forward.h"
39 #include "dlink.h"
40 #include "ip/Address.h"
41 #include "HelperChildConfig.h"
42 #include "HelperReply.h"
43
44 class helper_request;
45
46 typedef void HLPCB(void *, const HelperReply &reply);
47
48 class helper
49 {
50 public:
51 inline helper(const char *name) : cmdline(NULL), id_name(name), eom('\n'), url_quoting(false) {}
52 ~helper();
53
54 public:
55 wordlist *cmdline;
56 dlink_list servers;
57 dlink_list queue;
58 const char *id_name;
59 HelperChildConfig childs; ///< Configuration settings for number running.
60 int ipc_type;
61 Ip::Address addr;
62 time_t last_queue_warn;
63 time_t last_restart;
64 char eom; ///< The char which marks the end of (response) message, normally '\n'
65 bool url_quoting;
66
67 struct _stats {
68 int requests;
69 int replies;
70 int queue_size;
71 int avg_svc_time;
72 } stats;
73
74 private:
75 CBDATA_CLASS2(helper);
76 };
77
78 class statefulhelper : public helper
79 {
80 public:
81 inline statefulhelper(const char *name) : helper(name) {};
82 inline ~statefulhelper() {};
83
84 public:
85 MemAllocator *datapool;
86 HLPSAVAIL *IsAvailable;
87 HLPSONEQ *OnEmptyQueue;
88
89 private:
90 CBDATA_CLASS2(statefulhelper);
91 };
92
93 /**
94 * Fields shared between stateless and stateful helper servers.
95 */
96 class HelperServerBase
97 {
98 public:
99 /** Closes pipes to the helper safely.
100 * Handles the case where the read and write pipes are the same FD.
101 */
102 void closePipesSafely();
103
104 /** Closes the reading pipe.
105 * If the read and write sockets are the same the write pipe will
106 * also be closed. Otherwise its left open for later handling.
107 */
108 void closeWritePipeSafely();
109
110 public:
111 int index;
112 int pid;
113 Ip::Address addr;
114 Comm::ConnectionPointer readPipe;
115 Comm::ConnectionPointer writePipe;
116 void *hIpc;
117
118 char *rbuf;
119 size_t rbuf_sz;
120 size_t roffset;
121
122 struct timeval dispatch_time;
123 struct timeval answer_time;
124
125 dlink_node link;
126
127 struct _helper_flags {
128 unsigned int busy:1;
129 unsigned int writing:1;
130 unsigned int closing:1;
131 unsigned int shutdown:1;
132 unsigned int reserved:1;
133 } flags;
134
135 struct {
136 uint64_t uses; //< requests sent to this helper
137 uint64_t replies; //< replies received from this helper
138 uint64_t pending; //< queued lookups waiting to be sent to this helper
139 uint64_t releases; //< times release() has been called on this helper (if stateful)
140 } stats;
141 void initStats();
142 };
143
144 class MemBuf;
145
146 class helper_server : public HelperServerBase
147 {
148 public:
149 MemBuf *wqueue;
150 MemBuf *writebuf;
151
152 helper *parent;
153 helper_request **requests;
154
155 private:
156 CBDATA_CLASS2(helper_server);
157 };
158
159 class helper_stateful_request;
160
161 class helper_stateful_server : public HelperServerBase
162 {
163 public:
164 /* MemBuf wqueue; */
165 /* MemBuf writebuf; */
166
167 statefulhelper *parent;
168 helper_stateful_request *request;
169
170 void *data; /* State data used by the calling routines */
171
172 private:
173 CBDATA_CLASS2(helper_stateful_server);
174 };
175
176 class helper_request
177 {
178
179 public:
180 MEMPROXY_CLASS(helper_request);
181 char *buf;
182 HLPCB *callback;
183 void *data;
184
185 struct timeval dispatch_time;
186 };
187
188 MEMPROXY_CLASS_INLINE(helper_request);
189
190 class helper_stateful_request
191 {
192
193 public:
194 MEMPROXY_CLASS(helper_stateful_request);
195 char *buf;
196 HLPCB *callback;
197 int placeholder; /* if 1, this is a dummy request waiting for a stateful helper to become available */
198 void *data;
199 };
200
201 MEMPROXY_CLASS_INLINE(helper_stateful_request);
202
203 /* helper.c */
204 void helperOpenServers(helper * hlp);
205 void helperStatefulOpenServers(statefulhelper * hlp);
206 void helperSubmit(helper * hlp, const char *buf, HLPCB * callback, void *data);
207 void helperStatefulSubmit(statefulhelper * hlp, const char *buf, HLPCB * callback, void *data, helper_stateful_server * lastserver);
208 void helperStats(StoreEntry * sentry, helper * hlp, const char *label = NULL);
209 void helperStatefulStats(StoreEntry * sentry, statefulhelper * hlp, const char *label = NULL);
210 void helperShutdown(helper * hlp);
211 void helperStatefulShutdown(statefulhelper * hlp);
212 void helperStatefulReleaseServer(helper_stateful_server * srv);
213 void *helperStatefulServerGetData(helper_stateful_server * srv);
214
215 #endif /* SQUID_HELPER_H */