]> git.ipfire.org Git - thirdparty/squid.git/blob - src/ICP.h
SourceFormat Enforcement
[thirdparty/squid.git] / src / ICP.h
1 /*
2 * Copyright (C) 1996-2014 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 "comm/forward.h"
18 #include "icp_opcode.h"
19 #include "ip/Address.h"
20 #include "LogTags.h"
21 #include "StoreClient.h"
22
23 class HttpRequest;
24
25 /**
26 \ingroup ServerProtocolICPAPI
27 *
28 * This struct is the wire-level header.
29 * DO NOT add more move fields on pain of breakage.
30 * DO NOT add virtual methods.
31 */
32 struct _icp_common_t {
33 /** opcode */
34 unsigned char opcode;
35 /** version number */
36 unsigned char version;
37 /** total length (bytes) */
38 unsigned short length;
39 /** req number (req'd for UDP) */
40 uint32_t reqnum;
41 uint32_t flags;
42 uint32_t pad;
43 /** sender host id */
44 uint32_t shostid;
45
46 /// \todo I don't believe this header is included in non-c++ code anywhere
47 /// the struct should become a public POD class and kill these ifdef.
48 #ifdef __cplusplus
49
50 _icp_common_t();
51 _icp_common_t(char *buf, unsigned int len);
52
53 void handleReply(char *buf, Ip::Address &from);
54 static _icp_common_t *createMessage(icp_opcode opcode, int flags, const char *url, int reqnum, int pad);
55 icp_opcode getOpCode() const;
56 #endif
57 };
58 typedef struct _icp_common_t icp_common_t;
59
60 #ifdef __cplusplus
61
62 /// \ingroup ServerProtocolICPAPI
63 inline icp_opcode & operator++ (icp_opcode & aCode)
64 {
65 int tmp = (int) aCode;
66 aCode = (icp_opcode) (++tmp);
67 return aCode;
68 }
69
70 /**
71 \ingroup ServerProtocolICPAPI
72 \todo mempool this
73 */
74 class ICPState
75 {
76
77 public:
78 ICPState(icp_common_t &aHeader, HttpRequest *aRequest);
79 virtual ~ICPState();
80 icp_common_t header;
81 HttpRequest *request;
82 int fd;
83
84 Ip::Address from;
85 char *url;
86 };
87
88 #endif
89
90 /// \ingroup ServerProtocolICPAPI
91 struct icpUdpData {
92
93 /// IP address for the remote end. Because we reply to packets from unknown non-peers.
94 Ip::Address address;
95
96 void *msg;
97 size_t len;
98 icpUdpData *next;
99 #ifndef LESS_TIMING
100
101 struct timeval start;
102 #endif
103
104 LogTags logcode;
105
106 struct timeval queue_time;
107 };
108
109 extern Comm::ConnectionPointer icpIncomingConn;
110 extern Comm::ConnectionPointer icpOutgoingConn;
111 extern Ip::Address theIcpPublicHostID;
112
113 /// \ingroup ServerProtocolICPAPI
114 HttpRequest* icpGetRequest(char *url, int reqnum, int fd, Ip::Address &from);
115
116 /// \ingroup ServerProtocolICPAPI
117 bool icpAccessAllowed(Ip::Address &from, HttpRequest * icp_request);
118
119 /// \ingroup ServerProtocolICPAPI
120 void icpCreateAndSend(icp_opcode, int flags, char const *url, int reqnum, int pad, int fd, const Ip::Address &from);
121
122 /// \ingroup ServerProtocolICPAPI
123 icp_opcode icpGetCommonOpcode();
124
125 /// \ingroup ServerProtocolICPAPI
126 int icpUdpSend(int, const Ip::Address &, icp_common_t *, LogTags, int);
127
128 /// \ingroup ServerProtocolICPAPI
129 LogTags icpLogFromICPCode(icp_opcode opcode);
130
131 /// \ingroup ServerProtocolICPAPI
132 void icpDenyAccess(Ip::Address &from, char *url, int reqnum, int fd);
133
134 /// \ingroup ServerProtocolICPAPI
135 PF icpHandleUdp;
136
137 /// \ingroup ServerProtocolICPAPI
138 PF icpUdpSendQueue;
139
140 /// \ingroup ServerProtocolICPAPI
141 void icpHandleIcpV3(int, Ip::Address &, char *, int);
142
143 /// \ingroup ServerProtocolICPAPI
144 int icpCheckUdpHit(StoreEntry *, HttpRequest * request);
145
146 /// \ingroup ServerProtocolICPAPI
147 void icpOpenPorts(void);
148
149 /// \ingroup ServerProtocolICPAPI
150 void icpConnectionShutdown(void);
151
152 /// \ingroup ServerProtocolICPAPI
153 void icpClosePorts(void);
154
155 /// \ingroup ServerProtocolICPAPI
156 int icpSetCacheKey(const cache_key * key);
157
158 /// \ingroup ServerProtocolICPAPI
159 const cache_key *icpGetCacheKey(const char *url, int reqnum);
160
161 #endif /* SQUID_ICP_H */
162