]>
git.ipfire.org Git - thirdparty/squid.git/blob - src/icp_v3.cc
3 * $Id: icp_v3.cc,v 1.42 2007/04/28 22:26:37 hno 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.
39 #include "HttpRequest.h"
41 class ICP3State
: public ICPState
, public StoreClient
45 ICP3State(icp_common_t
&aHeader
, HttpRequest
*aRequest
):
46 ICPState(aHeader
, aRequest
)
50 void created (StoreEntry
*newEntry
);
55 doV3Query(int fd
, struct sockaddr_in from
, char *buf
, icp_common_t header
)
57 /* We have a valid packet */
58 char *url
= buf
+ sizeof(icp_common_t
) + sizeof(u_int32_t
);
59 HttpRequest
*icp_request
= icpGetRequest (url
, header
.reqnum
, fd
, &from
);
64 if (!icpAccessAllowed(&from
, icp_request
))
66 icpDenyAccess (&from
, url
, header
.reqnum
, fd
);
71 /* The peer is allowed to use this cache */
72 ICP3State
*state
= new ICP3State (header
, icp_request
);
78 state
->url
= xstrdup (url
);
80 StoreEntry::getPublic (state
, url
, METHOD_GET
);
83 ICP3State::~ICP3State ()
87 ICP3State::created (StoreEntry
*newEntry
)
89 StoreEntry
*entry
= newEntry
->isNull () ? NULL
: newEntry
;
90 debugs(12, 5, "icpHandleIcpV3: OPCODE " << icp_opcode_str
[header
.opcode
]);
91 icp_opcode codeToSend
;
93 if (icpCheckUdpHit(entry
, request
)) {
95 } else if (icpGetCommonOpcode() == ICP_ERR
)
96 codeToSend
= ICP_MISS
;
98 codeToSend
= icpGetCommonOpcode();
100 icpCreateAndSend (codeToSend
, 0, url
, header
.reqnum
, 0, fd
, &from
);
105 /* Currently Harvest cached-2.x uses ICP_VERSION_3 */
108 icpHandleIcpV3(int fd
, struct sockaddr_in from
, char *buf
, int len
)
112 debugs(12, 3, "icpHandleIcpV3: ICP message is too small");
116 icp_common_t
header (buf
, len
);
118 * Length field should match the number of bytes read
121 if (len
!= header
.length
)
123 debugs(12, 3, "icpHandleIcpV3: ICP message is too small");
127 switch (header
.opcode
)
131 doV3Query(fd
, from
,buf
, header
);
135 #if ALLOW_SOURCE_PING
146 case ICP_MISS_NOFETCH
:
147 header
.handleReply(buf
, &from
);
156 debugs(12, 0, "icpHandleIcpV3: UNKNOWN OPCODE: " << header
.opcode
<< " from " << inet_ntoa(from
.sin_addr
));