]> git.ipfire.org Git - thirdparty/squid.git/blob - src/structs.h
Moved SquidConfig2 class to SquidConfig.h
[thirdparty/squid.git] / src / structs.h
1 /*
2 * SQUID Web Proxy Cache http://www.squid-cache.org/
3 * ----------------------------------------------------------
4 *
5 * Squid is the result of efforts by numerous individuals from
6 * the Internet community; see the CONTRIBUTORS file for full
7 * details. Many organizations have provided support for Squid's
8 * development; see the SPONSORS file for full details. Squid is
9 * Copyrighted (C) 2001 by the Regents of the University of
10 * California; see the COPYRIGHT file for full details. Squid
11 * incorporates software developed and/or copyrighted by other
12 * sources; see the CREDITS file for full details.
13 *
14 * This program is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License as published by
16 * the Free Software Foundation; either version 2 of the License, or
17 * (at your option) any later version.
18 *
19 * This program is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
23 *
24 * You should have received a copy of the GNU General Public License
25 * along with this program; if not, write to the Free Software
26 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA.
27 *
28 */
29 #ifndef SQUID_STRUCTS_H
30 #define SQUID_STRUCTS_H
31
32 #include "RefCount.h"
33 #include "cbdata.h"
34 #include "defines.h"
35 #include "dlink.h"
36 #include "err_type.h"
37 #include "hash.h"
38 #include "ip/Address.h"
39
40 /* needed for the global config */
41 #include "HttpHeader.h"
42 #include "HttpHeaderTools.h"
43
44 /* for ICP_END */
45 #include "icp_opcode.h"
46
47 #if USE_SSL
48 #include <openssl/ssl.h>
49 #endif
50
51 #define PEER_MULTICAST_SIBLINGS 1
52
53 struct acl_name_list {
54 char name[ACL_NAME_SZ];
55 acl_name_list *next;
56 };
57
58 struct acl_deny_info_list {
59 err_type err_page_id;
60 char *err_page_name;
61 acl_name_list *acl_list;
62 acl_deny_info_list *next;
63 };
64
65 class ACLChecklist;
66
67 #if SQUID_SNMP
68
69 #include "snmp_session.h"
70 struct _snmp_request_t {
71 u_char *buf;
72 u_char *outbuf;
73 int len;
74 int sock;
75 long reqid;
76 int outlen;
77
78 Ip::Address from;
79
80 struct snmp_pdu *PDU;
81 ACLChecklist *acl_checklist;
82 u_char *community;
83
84 struct snmp_session session;
85 };
86
87 #endif
88
89 class ACLList;
90
91 struct acl_address {
92 acl_address *next;
93 ACLList *aclList;
94
95 Ip::Address addr;
96 };
97
98 struct acl_tos {
99 acl_tos *next;
100 ACLList *aclList;
101 tos_t tos;
102 };
103
104 struct acl_nfmark {
105 acl_nfmark *next;
106 ACLList *aclList;
107 nfmark_t nfmark;
108 };
109
110 struct acl_size_t {
111 acl_size_t *next;
112 ACLList *aclList;
113 int64_t size;
114 };
115
116 struct relist {
117 int flags;
118 char *pattern;
119 regex_t regex;
120 relist *next;
121 };
122
123 #if USE_DELAY_POOLS
124 #include "DelayConfig.h"
125 #include "ClientDelayConfig.h"
126 #endif
127
128 #if USE_ICMP
129 #include "icmp/IcmpConfig.h"
130 #endif
131
132 #include "HelperChildConfig.h"
133
134 /* forward decl for SquidConfig, see RemovalPolicy.h */
135
136 class CpuAffinityMap;
137 class RemovalPolicySettings;
138 class external_acl;
139 class Store;
140 class customlog;
141 class cachemgr_passwd;
142 class refresh_t;
143 namespace AnyP
144 {
145 struct PortCfg;
146 }
147 class SwapDir;
148
149 class close_handler {
150 public:
151 PF *handler;
152 void *data;
153 close_handler *next;
154 };
155
156 class dread_ctrl {
157 public:
158 int fd;
159 off_t offset;
160 int req_len;
161 char *buf;
162 int end_of_file;
163 DRCB *handler;
164 void *client_data;
165 };
166
167 class dwrite_q {
168 public:
169 off_t file_offset;
170 char *buf;
171 size_t len;
172 size_t buf_offset;
173 dwrite_q *next;
174 FREE *free_func;
175 };
176
177 struct _fde_disk {
178 DWCB *wrt_handle;
179 void *wrt_handle_data;
180 dwrite_q *write_q;
181 dwrite_q *write_q_tail;
182 off_t offset;
183 };
184
185 /* per field statistics */
186
187 class HttpHeaderFieldStat
188 {
189
190 public:
191 HttpHeaderFieldStat() : aliveCount(0), seenCount(0), parsCount(0), errCount(0), repCount(0) {}
192
193 int aliveCount; /* created but not destroyed (count) */
194 int seenCount; /* #fields we've seen */
195 int parsCount; /* #parsing attempts */
196 int errCount; /* #pasring errors */
197 int repCount; /* #repetitons */
198 };
199
200 /* compiled version of HttpHeaderFieldAttrs plus stats */
201 #include "SquidString.h"
202
203 class HttpHeaderFieldInfo
204 {
205
206 public:
207 HttpHeaderFieldInfo() : id (HDR_ACCEPT), type (ftInvalid) {}
208
209 http_hdr_type id;
210 String name;
211 field_type type;
212 HttpHeaderFieldStat stat;
213 };
214
215 class http_state_flags {
216 public:
217 unsigned int proxying:1;
218 unsigned int keepalive:1;
219 unsigned int only_if_cached:1;
220 unsigned int handling1xx:1; ///< we are ignoring or forwarding 1xx response
221 unsigned int headers_parsed:1;
222 unsigned int front_end_https:2;
223 unsigned int originpeer:1;
224 unsigned int keepalive_broken:1;
225 unsigned int abuse_detected:1;
226 unsigned int request_sent:1;
227 unsigned int do_next_read:1;
228 unsigned int consume_body_data:1;
229 unsigned int chunked:1; ///< reading a chunked response; TODO: rename
230 unsigned int chunked_request:1; ///< writing a chunked request
231 unsigned int sentLastChunk:1; ///< do not try to write last-chunk again
232 };
233
234 class domain_ping {
235 public:
236 char *domain;
237 int do_ping; /* boolean */
238 domain_ping *next;
239 };
240
241 class domain_type {
242 public:
243 char *domain;
244 peer_t type;
245 domain_type *next;
246 };
247
248 class PeerDigest;
249
250 struct peer {
251 u_int index;
252 char *name;
253 char *host;
254 peer_t type;
255
256 Ip::Address in_addr;
257
258 struct {
259 int pings_sent;
260 int pings_acked;
261 int fetches;
262 int rtt;
263 int ignored_replies;
264 int n_keepalives_sent;
265 int n_keepalives_recv;
266 time_t probe_start;
267 time_t last_query;
268 time_t last_reply;
269 time_t last_connect_failure;
270 time_t last_connect_probe;
271 int logged_state; /* so we can print dead/revived msgs */
272 int conn_open; /* current opened connections */
273 } stats;
274
275 struct {
276 int version;
277 int counts[ICP_END+1];
278 unsigned short port;
279 } icp;
280
281 #if USE_HTCP
282 struct {
283 double version;
284 int counts[2];
285 unsigned short port;
286 } htcp;
287 #endif
288
289 unsigned short http_port;
290 domain_ping *peer_domain;
291 domain_type *typelist;
292 acl_access *access;
293
294 struct {
295 unsigned int proxy_only:1;
296 unsigned int no_query:1;
297 unsigned int background_ping:1;
298 unsigned int no_digest:1;
299 unsigned int default_parent:1;
300 unsigned int roundrobin:1;
301 unsigned int weighted_roundrobin:1;
302 unsigned int mcast_responder:1;
303 unsigned int closest_only:1;
304 #if USE_HTCP
305 unsigned int htcp:1;
306 unsigned int htcp_oldsquid:1;
307 unsigned int htcp_no_clr:1;
308 unsigned int htcp_no_purge_clr:1;
309 unsigned int htcp_only_clr:1;
310 unsigned int htcp_forward_clr:1;
311 #endif
312 unsigned int no_netdb_exchange:1;
313 #if USE_DELAY_POOLS
314 unsigned int no_delay:1;
315 #endif
316 unsigned int allow_miss:1;
317 unsigned int carp:1;
318 struct {
319 unsigned int set:1; //If false, whole url is to be used. Overrides others
320 unsigned int scheme:1;
321 unsigned int host:1;
322 unsigned int port:1;
323 unsigned int path:1;
324 unsigned int params:1;
325 } carp_key;
326 #if USE_AUTH
327 unsigned int userhash:1;
328 #endif
329 unsigned int sourcehash:1;
330 unsigned int originserver:1;
331 unsigned int no_tproxy:1;
332 #if PEER_MULTICAST_SIBLINGS
333 unsigned int mcast_siblings:1;
334 #endif
335 } options;
336
337 int weight;
338 int basetime;
339
340 struct {
341 double avg_n_members;
342 int n_times_counted;
343 int n_replies_expected;
344 int ttl;
345 int id;
346
347 struct {
348 unsigned int count_event_pending:1;
349 unsigned int counting:1;
350 } flags;
351 } mcast;
352 #if USE_CACHE_DIGESTS
353
354 PeerDigest *digest;
355 char *digest_url;
356 #endif
357
358 int tcp_up; /* 0 if a connect() fails */
359
360 Ip::Address addresses[10];
361 int n_addresses;
362 int rr_count;
363 peer *next;
364 int testing_now;
365
366 struct {
367 unsigned int hash;
368 double load_multiplier;
369 double load_factor; /* normalized weight value */
370 } carp;
371 #if USE_AUTH
372 struct {
373 unsigned int hash;
374 double load_multiplier;
375 double load_factor; /* normalized weight value */
376 } userhash;
377 #endif
378 struct {
379 unsigned int hash;
380 double load_multiplier;
381 double load_factor; /* normalized weight value */
382 } sourcehash;
383
384 char *login; /* Proxy authorization */
385 time_t connect_timeout;
386 int connect_fail_limit;
387 int max_conn;
388 char *domain; /* Forced domain */
389 #if USE_SSL
390
391 int use_ssl;
392 char *sslcert;
393 char *sslkey;
394 int sslversion;
395 char *ssloptions;
396 char *sslcipher;
397 char *sslcafile;
398 char *sslcapath;
399 char *sslcrlfile;
400 char *sslflags;
401 char *ssldomain;
402 SSL_CTX *sslContext;
403 SSL_SESSION *sslSession;
404 #endif
405
406 int front_end_https;
407 int connection_auth;
408 };
409
410 class netdbEntry;
411
412 class net_db_name {
413 public:
414 hash_link hash; /* must be first */
415 net_db_name *next;
416 netdbEntry *net_db_entry;
417 };
418
419 class net_db_peer {
420 public:
421 const char *peername;
422 double hops;
423 double rtt;
424 time_t expires;
425 };
426
427 class netdbEntry {
428 public:
429 hash_link hash; /* must be first */
430 char network[MAX_IPSTRLEN];
431 int pings_sent;
432 int pings_recv;
433 double hops;
434 double rtt;
435 time_t next_ping_time;
436 time_t last_use_time;
437 int link_count;
438 net_db_name *hosts;
439 net_db_peer *peers;
440 int n_peers_alloc;
441 int n_peers;
442 };
443
444 class iostats {
445 public:
446 static const int histSize=16;
447
448 // enum { histSize = 16 };
449
450 struct {
451 int reads;
452 int reads_deferred;
453 int read_hist[histSize];
454 int writes;
455 int write_hist[histSize];
456 }
457
458 Http, Ftp, Gopher;
459 };
460
461 struct request_flags {
462 request_flags(): range(0),nocache(0),ims(0),auth(0),cachable(0),hierarchical(0),loopdetect(0),proxy_keepalive(0),proxying(0),refresh(0),redirected(0),need_validation(0),fail_on_validation_err(0),stale_if_hit(0),accelerated(0),ignore_cc(0),intercepted(0),hostVerified(0),spoof_client_ip(0),internal(0),internalclient(0),must_keepalive(0),pinned(0),canRePin(0),chunked_reply(0),stream_error(0),sslPeek(0),sslBumped(0),destinationIPLookedUp_(0) {
463 #if USE_HTTP_VIOLATIONS
464 nocache_hack = 0;
465 #endif
466 #if FOLLOW_X_FORWARDED_FOR
467 done_follow_x_forwarded_for = 0;
468 #endif /* FOLLOW_X_FORWARDED_FOR */
469 }
470
471 unsigned int range:1;
472 unsigned int nocache:1; ///< whether the response to this request may be READ from cache
473 unsigned int ims:1;
474 unsigned int auth:1;
475 unsigned int cachable:1; ///< whether the response to thie request may be stored in the cache
476 unsigned int hierarchical:1;
477 unsigned int loopdetect:1;
478 unsigned int proxy_keepalive:1;
479 unsigned int proxying:
480 1; /* this should be killed, also in httpstateflags */
481 unsigned int refresh:1;
482 unsigned int redirected:1;
483 unsigned int need_validation:1;
484 unsigned int fail_on_validation_err:1; ///< whether we should fail if validation fails
485 unsigned int stale_if_hit:1; ///< reply is stale if it is a hit
486 #if USE_HTTP_VIOLATIONS
487 unsigned int nocache_hack:1; /* for changing/ignoring no-cache requests */
488 #endif
489 unsigned int accelerated:1;
490 unsigned int ignore_cc:1;
491 unsigned int intercepted:1; ///< intercepted request
492 unsigned int hostVerified:1; ///< whether the Host: header passed verification
493 unsigned int spoof_client_ip:1; /**< spoof client ip if possible */
494 unsigned int internal:1;
495 unsigned int internalclient:1;
496 unsigned int must_keepalive:1;
497 unsigned int connection_auth:1; /** Request wants connection oriented auth */
498 unsigned int connection_auth_disabled:1; /** Connection oriented auth can not be supported */
499 unsigned int connection_proxy_auth:1; /** Request wants connection oriented auth */
500 unsigned int pinned:1; /* Request sent on a pinned connection */
501 unsigned int canRePin:1; ///< OK to reopen a failed pinned connection
502 unsigned int auth_sent:1; /* Authentication forwarded */
503 unsigned int no_direct:1; /* Deny direct forwarding unless overriden by always_direct. Used in accelerator mode */
504 unsigned int chunked_reply:1; /**< Reply with chunked transfer encoding */
505 unsigned int stream_error:1; /**< Whether stream error has occured */
506 unsigned int sslPeek:1; ///< internal ssl-bump request to get server cert
507 unsigned int sslBumped:1; /**< ssl-bumped request*/
508
509 // When adding new flags, please update cloneAdaptationImmune() as needed.
510
511 bool resetTCP() const;
512 void setResetTCP();
513 void clearResetTCP();
514 void destinationIPLookupCompleted();
515 bool destinationIPLookedUp() const;
516
517 // returns a partial copy of the flags that includes only those flags
518 // that are safe for a related (e.g., ICAP-adapted) request to inherit
519 request_flags cloneAdaptationImmune() const;
520
521 #if FOLLOW_X_FORWARDED_FOR
522 unsigned int done_follow_x_forwarded_for;
523 #endif /* FOLLOW_X_FORWARDED_FOR */
524 private:
525
526 unsigned int reset_tcp:1;
527 unsigned int destinationIPLookedUp_:1;
528 };
529
530
531 class cachemgr_passwd {
532 public:
533 char *passwd;
534 wordlist *actions;
535 cachemgr_passwd *next;
536 };
537
538 class refresh_t {
539 public:
540 const char *pattern;
541 regex_t compiled_pattern;
542 time_t min;
543 double pct;
544 time_t max;
545 refresh_t *next;
546
547 struct {
548 unsigned int icase:1;
549 unsigned int refresh_ims:1;
550 unsigned int store_stale:1;
551 #if USE_HTTP_VIOLATIONS
552 unsigned int override_expire:1;
553 unsigned int override_lastmod:1;
554 unsigned int reload_into_ims:1;
555 unsigned int ignore_reload:1;
556 unsigned int ignore_no_cache:1;
557 unsigned int ignore_no_store:1;
558 unsigned int ignore_must_revalidate:1;
559 unsigned int ignore_private:1;
560 unsigned int ignore_auth:1;
561 #endif
562 } flags;
563 int max_stale;
564 };
565
566 class CacheDigest {
567 public:
568 /* public, read-only */
569 char *mask; /* bit mask */
570 int mask_size; /* mask size in bytes */
571 int capacity; /* expected maximum for .count, not a hard limit */
572 int bits_per_entry; /* number of bits allocated for each entry from capacity */
573 int count; /* number of digested entries */
574 int del_count; /* number of deletions performed so far */
575 };
576
577 struct _store_rebuild_data {
578 int objcount; /* # objects successfully reloaded */
579 int expcount; /* # objects expired */
580 int scancount; /* # entries scanned or read from state file */
581 int clashcount; /* # swapfile clashes avoided */
582 int dupcount; /* # duplicates purged */
583 int cancelcount; /* # SWAP_LOG_DEL objects purged */
584 int invalid; /* # bad lines */
585 int badflags; /* # bad e->flags */
586 int bad_log_op;
587 int zero_object_sz;
588 };
589
590 #if USE_SSL
591 struct _sslproxy_cert_sign {
592 int alg;
593 ACLList *aclList;
594 sslproxy_cert_sign *next;
595 };
596
597 struct _sslproxy_cert_adapt {
598 int alg;
599 char *param;
600 ACLList *aclList;
601 sslproxy_cert_adapt *next;
602 };
603 #endif
604
605 class Logfile;
606
607 #include "format/Format.h"
608 #include "log/Formats.h"
609 class customlog {
610 public:
611 char *filename;
612 ACLList *aclList;
613 Format::Format *logFormat;
614 Logfile *logfile;
615 customlog *next;
616 Log::Format::log_type type;
617 };
618
619 #endif /* SQUID_STRUCTS_H */