]>
git.ipfire.org Git - thirdparty/squid.git/blob - src/icp_v3.cc
52434d9b0c90748c0a54738ee3e68edbde109935
4 * DEBUG: section 12 Internet Cache Protocol (ICP)
5 * AUTHOR: Duane Wessels
7 * SQUID Web Proxy Cache http://www.squid-cache.org/
8 * ----------------------------------------------------------
10 * Squid is the result of efforts by numerous individuals from
11 * the Internet community; see the CONTRIBUTORS file for full
12 * details. Many organizations have provided support for Squid's
13 * development; see the SPONSORS file for full details. Squid is
14 * Copyrighted (C) 2001 by the Regents of the University of
15 * California; see the COPYRIGHT file for full details. Squid
16 * incorporates software developed and/or copyrighted by other
17 * sources; see the CREDITS file for full details.
19 * This program is free software; you can redistribute it and/or modify
20 * it under the terms of the GNU General Public License as published by
21 * the Free Software Foundation; either version 2 of the License, or
22 * (at your option) any later version.
24 * This program is distributed in the hope that it will be useful,
25 * but WITHOUT ANY WARRANTY; without even the implied warranty of
26 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27 * GNU General Public License for more details.
29 * You should have received a copy of the GNU General Public License
30 * along with this program; if not, write to the Free Software
31 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA.
36 \defgroup ServerProtocolICPInternal3 ICPv3 Internals
37 \ingroup ServerProtocolICPAPI
43 #include "HttpRequest.h"
45 /// \ingroup ServerProtocolICPInternal3
46 class ICP3State
: public ICPState
, public StoreClient
50 ICP3State(icp_common_t
&aHeader
, HttpRequest
*aRequest
) :
51 ICPState(aHeader
, aRequest
) {}
54 void created (StoreEntry
*newEntry
);
57 /// \ingroup ServerProtocolICPInternal3
59 doV3Query(int fd
, IpAddress
&from
, char *buf
, icp_common_t header
)
61 /* We have a valid packet */
62 char *url
= buf
+ sizeof(icp_common_t
) + sizeof(u_int32_t
);
63 HttpRequest
*icp_request
= icpGetRequest (url
, header
.reqnum
, fd
, from
);
68 if (!icpAccessAllowed(from
, icp_request
)) {
69 icpDenyAccess (from
, url
, header
.reqnum
, fd
);
74 /* The peer is allowed to use this cache */
75 ICP3State
*state
= new ICP3State (header
, icp_request
);
81 state
->url
= xstrdup (url
);
83 StoreEntry::getPublic (state
, url
, METHOD_GET
);
86 ICP3State::~ICP3State()
90 ICP3State::created(StoreEntry
*newEntry
)
92 StoreEntry
*entry
= newEntry
->isNull () ? NULL
: newEntry
;
93 debugs(12, 5, "icpHandleIcpV3: OPCODE " << icp_opcode_str
[header
.opcode
]);
94 icp_opcode codeToSend
;
96 if (icpCheckUdpHit(entry
, request
)) {
98 } else if (icpGetCommonOpcode() == ICP_ERR
)
99 codeToSend
= ICP_MISS
;
101 codeToSend
= icpGetCommonOpcode();
103 icpCreateAndSend (codeToSend
, 0, url
, header
.reqnum
, 0, fd
, from
);
109 /// \ingroup ServerProtocolICPInternal3
110 /* Currently Harvest cached-2.x uses ICP_VERSION_3 */
112 icpHandleIcpV3(int fd
, IpAddress
&from
, char *buf
, int len
)
115 debugs(12, 3, "icpHandleIcpV3: ICP message is too small");
119 icp_common_t
header (buf
, len
);
121 * Length field should match the number of bytes read
124 if (len
!= header
.length
) {
125 debugs(12, 3, "icpHandleIcpV3: ICP message is too small");
129 switch (header
.opcode
) {
132 doV3Query(fd
, from
, buf
, header
);
143 case ICP_MISS_NOFETCH
:
144 header
.handleReply(buf
, from
);
153 debugs(12, 0, "icpHandleIcpV3: UNKNOWN OPCODE: " << header
.opcode
<< " from " << from
);