]>
git.ipfire.org Git - thirdparty/squid.git/blob - src/icp_v3.cc
2 * DEBUG: section 12 Internet Cache Protocol (ICP)
3 * AUTHOR: Duane Wessels
5 * SQUID Web Proxy Cache http://www.squid-cache.org/
6 * ----------------------------------------------------------
8 * Squid is the result of efforts by numerous individuals from
9 * the Internet community; see the CONTRIBUTORS file for full
10 * details. Many organizations have provided support for Squid's
11 * development; see the SPONSORS file for full details. Squid is
12 * Copyrighted (C) 2001 by the Regents of the University of
13 * California; see the COPYRIGHT file for full details. Squid
14 * incorporates software developed and/or copyrighted by other
15 * sources; see the CREDITS file for full details.
17 * This program is free software; you can redistribute it and/or modify
18 * it under the terms of the GNU General Public License as published by
19 * the Free Software Foundation; either version 2 of the License, or
20 * (at your option) any later version.
22 * This program is distributed in the hope that it will be useful,
23 * but WITHOUT ANY WARRANTY; without even the implied warranty of
24 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 * GNU General Public License for more details.
27 * You should have received a copy of the GNU General Public License
28 * along with this program; if not, write to the Free Software
29 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA.
34 \defgroup ServerProtocolICPInternal3 ICPv3 Internals
35 \ingroup ServerProtocolICPAPI
39 #include "HttpRequest.h"
43 /// \ingroup ServerProtocolICPInternal3
44 class ICP3State
: public ICPState
, public StoreClient
48 ICP3State(icp_common_t
&aHeader
, HttpRequest
*aRequest
) :
49 ICPState(aHeader
, aRequest
) {}
52 void created (StoreEntry
*newEntry
);
55 /// \ingroup ServerProtocolICPInternal3
57 doV3Query(int fd
, Ip::Address
&from
, char *buf
, icp_common_t header
)
59 /* We have a valid packet */
60 char *url
= buf
+ sizeof(icp_common_t
) + sizeof(uint32_t);
61 HttpRequest
*icp_request
= icpGetRequest(url
, header
.reqnum
, fd
, from
);
66 if (!icpAccessAllowed(from
, icp_request
)) {
67 icpDenyAccess (from
, url
, header
.reqnum
, fd
);
72 /* The peer is allowed to use this cache */
73 ICP3State
*state
= new ICP3State (header
, icp_request
);
76 state
->url
= xstrdup(url
);
78 StoreEntry::getPublic (state
, url
, Http::METHOD_GET
);
81 ICP3State::~ICP3State()
85 ICP3State::created(StoreEntry
*newEntry
)
87 StoreEntry
*entry
= newEntry
->isNull () ? NULL
: newEntry
;
88 debugs(12, 5, "icpHandleIcpV3: OPCODE " << icp_opcode_str
[header
.opcode
]);
89 icp_opcode codeToSend
;
91 if (icpCheckUdpHit(entry
, request
)) {
93 } else if (icpGetCommonOpcode() == ICP_ERR
)
94 codeToSend
= ICP_MISS
;
96 codeToSend
= icpGetCommonOpcode();
98 icpCreateAndSend (codeToSend
, 0, url
, header
.reqnum
, 0, fd
, from
);
103 /// \ingroup ServerProtocolICPInternal3
104 /* Currently Harvest cached-2.x uses ICP_VERSION_3 */
106 icpHandleIcpV3(int fd
, Ip::Address
&from
, char *buf
, int len
)
109 debugs(12, 3, "icpHandleIcpV3: ICP message is too small");
113 icp_common_t
header (buf
, len
);
115 * Length field should match the number of bytes read
118 if (len
!= header
.length
) {
119 debugs(12, 3, "icpHandleIcpV3: ICP message is too small");
123 switch (header
.opcode
) {
126 doV3Query(fd
, from
, buf
, header
);
137 case ICP_MISS_NOFETCH
:
138 header
.handleReply(buf
, from
);
147 debugs(12, DBG_CRITICAL
, "icpHandleIcpV3: UNKNOWN OPCODE: " << header
.opcode
<< " from " << from
);