]> git.ipfire.org Git - thirdparty/squid.git/blob - src/ICP.h
Source Format Enforcement (#1234)
[thirdparty/squid.git] / src / ICP.h
1 /*
2 * Copyright (C) 1996-2023 The Squid Software Foundation and contributors
3 *
4 * Squid software is distributed under GPLv2+ license and includes
5 * contributions from numerous individuals and organizations.
6 * Please see the COPYING and CONTRIBUTORS files for details.
7 */
8
9 #ifndef SQUID_ICP_H
10 #define SQUID_ICP_H
11
12 /**
13 \defgroup ServerProtocolICPAPI ICP
14 \ingroup ServerProtocol
15 */
16
17 #include "base/RefCount.h"
18 #include "comm/forward.h"
19 #include "icp_opcode.h"
20 #include "ip/Address.h"
21 #include "LogTags.h"
22 #include "store_key_md5.h"
23 #include "StoreClient.h"
24
25 class AccessLogEntry;
26 class HttpRequest;
27
28 typedef RefCount<AccessLogEntry> AccessLogEntryPointer;
29
30 /**
31 * Wire-level ICP header.
32 * DO NOT add or move fields.
33 * DO NOT add virtual methods.
34 */
35 class icp_common_t {
36 public:
37 /** opcode */
38 unsigned char opcode;
39 /** version number */
40 unsigned char version;
41 /** total length (bytes) */
42 unsigned short length;
43 /** req number (req'd for UDP) */
44 uint32_t reqnum;
45 uint32_t flags;
46 uint32_t pad;
47 /** sender host id */
48 uint32_t shostid;
49
50 icp_common_t();
51 icp_common_t(char *buf, unsigned int len);
52
53 void handleReply(char *buf, Ip::Address &from);
54 icp_opcode getOpCode() const;
55
56 /// \returns newly allocated buffer with an ICP message, including header
57 static icp_common_t *CreateMessage(icp_opcode opcode, int flags, const char *url, int reqnum, int pad);
58 };
59
60 // TODO: mempool this
61 class ICPState: public StoreClient
62 {
63
64 public:
65 ICPState(icp_common_t &aHeader, HttpRequest *aRequest);
66 ~ICPState() override;
67
68 /// whether the cache contains the requested entry
69 bool isHit() const;
70
71 icp_common_t header;
72 HttpRequest *request;
73 int fd;
74
75 Ip::Address from;
76 char *url;
77 mutable AccessLogEntryPointer al;
78
79 protected:
80 /* StoreClient API */
81 LogTags *loggingTags() const override;
82 void fillChecklist(ACLFilledChecklist &) const override;
83
84 /// either confirms and starts processing a cache hit or returns false
85 bool confirmAndPrepHit(const StoreEntry &) const;
86 };
87
88 extern Comm::ConnectionPointer icpIncomingConn;
89 extern Comm::ConnectionPointer icpOutgoingConn;
90 extern Ip::Address theIcpPublicHostID;
91
92 /// \ingroup ServerProtocolICPAPI
93 HttpRequest* icpGetRequest(char *url, int reqnum, int fd, Ip::Address &from);
94
95 /// \ingroup ServerProtocolICPAPI
96 bool icpAccessAllowed(Ip::Address &from, HttpRequest * icp_request);
97
98 /// \ingroup ServerProtocolICPAPI
99 void icpCreateAndSend(icp_opcode, int flags, char const *url, int reqnum, int pad, int fd, const Ip::Address &from, AccessLogEntryPointer);
100
101 /// \ingroup ServerProtocolICPAPI
102 icp_opcode icpGetCommonOpcode();
103
104 /// \ingroup ServerProtocolICPAPI
105 void icpDenyAccess(Ip::Address &from, char *url, int reqnum, int fd);
106
107 /// \ingroup ServerProtocolICPAPI
108 PF icpHandleUdp;
109
110 /// \ingroup ServerProtocolICPAPI
111 void icpHandleIcpV3(int, Ip::Address &, char *, int);
112
113 /// \ingroup ServerProtocolICPAPI
114 void icpOpenPorts(void);
115
116 /// \ingroup ServerProtocolICPAPI
117 void icpConnectionShutdown(void);
118
119 /// \ingroup ServerProtocolICPAPI
120 void icpClosePorts(void);
121
122 /// \ingroup ServerProtocolICPAPI
123 int icpSetCacheKey(const cache_key * key);
124
125 /// \ingroup ServerProtocolICPAPI
126 const cache_key *icpGetCacheKey(const char *url, int reqnum);
127
128 #endif /* SQUID_ICP_H */
129