]>
git.ipfire.org Git - thirdparty/squid.git/blob - src/icp_v3.cc
bdaf1a63297e8973c7c52d026de00ffe860a3dfa
2 * Copyright (C) 1996-2016 The Squid Software Foundation and contributors
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.
9 /* DEBUG: section 12 Internet Cache Protocol (ICP) */
12 \defgroup ServerProtocolICPInternal3 ICPv3 Internals
13 \ingroup ServerProtocolICPAPI
17 #include "HttpRequest.h"
21 /// \ingroup ServerProtocolICPInternal3
22 class ICP3State
: public ICPState
, public StoreClient
26 ICP3State(icp_common_t
&aHeader
, HttpRequest
*aRequest
) :
27 ICPState(aHeader
, aRequest
) {}
30 void created (StoreEntry
*newEntry
);
33 /// \ingroup ServerProtocolICPInternal3
35 doV3Query(int fd
, Ip::Address
&from
, char *buf
, icp_common_t header
)
37 /* We have a valid packet */
38 char *url
= buf
+ sizeof(icp_common_t
) + sizeof(uint32_t);
39 HttpRequest
*icp_request
= icpGetRequest(url
, header
.reqnum
, fd
, from
);
44 if (!icpAccessAllowed(from
, icp_request
)) {
45 icpDenyAccess (from
, url
, header
.reqnum
, fd
);
50 /* The peer is allowed to use this cache */
51 ICP3State
*state
= new ICP3State (header
, icp_request
);
54 state
->url
= xstrdup(url
);
56 StoreEntry::getPublic (state
, url
, Http::METHOD_GET
);
59 ICP3State::~ICP3State()
63 ICP3State::created(StoreEntry
*newEntry
)
65 StoreEntry
*entry
= newEntry
->isNull () ? NULL
: newEntry
;
66 debugs(12, 5, "icpHandleIcpV3: OPCODE " << icp_opcode_str
[header
.opcode
]);
67 icp_opcode codeToSend
;
69 if (icpCheckUdpHit(entry
, request
)) {
71 } else if (icpGetCommonOpcode() == ICP_ERR
)
72 codeToSend
= ICP_MISS
;
74 codeToSend
= icpGetCommonOpcode();
76 icpCreateAndSend (codeToSend
, 0, url
, header
.reqnum
, 0, fd
, from
);
81 /// \ingroup ServerProtocolICPInternal3
82 /* Currently Harvest cached-2.x uses ICP_VERSION_3 */
84 icpHandleIcpV3(int fd
, Ip::Address
&from
, char *buf
, int len
)
87 debugs(12, 3, "icpHandleIcpV3: ICP message is too small");
91 icp_common_t
header (buf
, len
);
93 * Length field should match the number of bytes read
96 if (len
!= header
.length
) {
97 debugs(12, 3, "icpHandleIcpV3: ICP message is too small");
101 switch (header
.opcode
) {
104 doV3Query(fd
, from
, buf
, header
);
115 case ICP_MISS_NOFETCH
:
116 header
.handleReply(buf
, from
);
125 debugs(12, DBG_CRITICAL
, "icpHandleIcpV3: UNKNOWN OPCODE: " << header
.opcode
<< " from " << from
);