]>
git.ipfire.org Git - thirdparty/squid.git/blob - src/icp_v3.cc
3 * $Id: icp_v3.cc,v 1.35 2002/10/13 20:35:01 robertc Exp $
5 * DEBUG: section 12 Internet Cache Protocol
6 * AUTHOR: Duane Wessels
8 * SQUID Web Proxy Cache http://www.squid-cache.org/
9 * ----------------------------------------------------------
11 * Squid is the result of efforts by numerous individuals from
12 * the Internet community; see the CONTRIBUTORS file for full
13 * details. Many organizations have provided support for Squid's
14 * development; see the SPONSORS file for full details. Squid is
15 * Copyrighted (C) 2001 by the Regents of the University of
16 * California; see the COPYRIGHT file for full details. Squid
17 * incorporates software developed and/or copyrighted by other
18 * sources; see the CREDITS file for full details.
20 * This program is free software; you can redistribute it and/or modify
21 * it under the terms of the GNU General Public License as published by
22 * the Free Software Foundation; either version 2 of the License, or
23 * (at your option) any later version.
25 * This program is distributed in the hope that it will be useful,
26 * but WITHOUT ANY WARRANTY; without even the implied warranty of
27 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28 * GNU General Public License for more details.
30 * You should have received a copy of the GNU General Public License
31 * along with this program; if not, write to the Free Software
32 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA.
40 class ICP3State
: public ICPState
, public StoreClient
{
42 ICP3State(icp_common_t
&aHeader
):ICPState(aHeader
){}
44 void created (StoreEntry
*newEntry
);
48 doV3Query(int fd
, struct sockaddr_in from
, char *buf
, icp_common_t header
)
50 /* We have a valid packet */
51 char *url
= buf
+ sizeof(icp_common_t
) + sizeof(u_int32_t
);
52 request_t
*icp_request
= icpGetRequest (url
, header
.reqnum
, fd
, &from
);
55 if (!icpAccessAllowed(&from
, icp_request
)) {
56 icpDenyAccess (&from
, url
, header
.reqnum
, fd
);
57 requestDestroy(icp_request
);
60 /* The peer is allowed to use this cache */
61 ICP3State
*state
= new ICP3State (header
);
62 state
->request
= icp_request
;
65 state
->url
= xstrdup (url
);
66 _StoreEntry::getPublic (state
, url
, METHOD_GET
);
69 ICP3State::~ICP3State ()
74 ICP3State::created (StoreEntry
*newEntry
)
76 StoreEntry
*entry
= newEntry
->isNull () ? NULL
: newEntry
;
77 debug(12, 5) ("icpHandleIcpV3: OPCODE %s\n",
78 icp_opcode_str
[header
.opcode
]);
79 icp_opcode codeToSend
;
80 if (icpCheckUdpHit(entry
, request
)) {
82 } else if (icpGetCommonOpcode() == ICP_ERR
)
83 codeToSend
= ICP_MISS
;
85 codeToSend
= icpGetCommonOpcode();
86 icpCreateAndSend (codeToSend
, 0, url
, header
.reqnum
, 0, fd
, &from
);
90 /* Currently Harvest cached-2.x uses ICP_VERSION_3 */
92 icpHandleIcpV3(int fd
, struct sockaddr_in from
, char *buf
, int len
)
95 debug(12, 3) ("icpHandleIcpV3: ICP message is too small\n");
98 icp_common_t
header (buf
, len
);
100 * Length field should match the number of bytes read
102 if (len
!= header
.length
) {
103 debug(12, 3) ("icpHandleIcpV3: ICP message is too small\n");
106 switch (header
.opcode
) {
108 doV3Query(fd
, from
,buf
, header
);
112 #if ALLOW_SOURCE_PING
118 case ICP_MISS_NOFETCH
:
119 header
.handleReply(buf
, &from
);
127 debug(12, 0) ("icpHandleIcpV3: UNKNOWN OPCODE: %d from %s\n",
128 header
.opcode
, inet_ntoa(from
.sin_addr
));