]> git.ipfire.org Git - thirdparty/squid.git/blame - src/icp_v3.cc
Removed squid-old.h
[thirdparty/squid.git] / src / icp_v3.cc
CommitLineData
9cef6668 1/*
262a0e14 2 * $Id$
9cef6668 3 *
cc192b50 4 * DEBUG: section 12 Internet Cache Protocol (ICP)
9cef6668 5 * AUTHOR: Duane Wessels
6 *
2b6662ba 7 * SQUID Web Proxy Cache http://www.squid-cache.org/
9cef6668 8 * ----------------------------------------------------------
9 *
2b6662ba 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.
9cef6668 18 *
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.
26ac0430 23 *
9cef6668 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.
26ac0430 28 *
9cef6668 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.
32 *
33 */
34
63be0a78 35/**
36 \defgroup ServerProtocolICPInternal3 ICPv3 Internals
37 \ingroup ServerProtocolICPAPI
38 */
39
582c2af2 40#include "squid.h"
e6ccf245 41#include "Store.h"
42#include "ICP.h"
528b2c61 43#include "HttpRequest.h"
e6ccf245 44
63be0a78 45/// \ingroup ServerProtocolICPInternal3
62e76326 46class ICP3State : public ICPState, public StoreClient
47{
48
e6ccf245 49public:
63be0a78 50 ICP3State(icp_common_t &aHeader, HttpRequest *aRequest) :
26ac0430 51 ICPState(aHeader, aRequest) {}
62e76326 52
e6ccf245 53 ~ICP3State();
54 void created (StoreEntry *newEntry);
55};
56
63be0a78 57/// \ingroup ServerProtocolICPInternal3
e6ccf245 58static void
b7ac5457 59doV3Query(int fd, Ip::Address &from, char *buf, icp_common_t header)
e6ccf245 60{
61 /* We have a valid packet */
09aabd84 62 char *url = buf + sizeof(icp_common_t) + sizeof(uint32_t);
cc192b50 63 HttpRequest *icp_request = icpGetRequest (url, header.reqnum, fd, from);
62e76326 64
e6ccf245 65 if (!icp_request)
62e76326 66 return;
67
26ac0430 68 if (!icpAccessAllowed(from, icp_request)) {
cc192b50 69 icpDenyAccess (from, url, header.reqnum, fd);
5cafad19 70 delete icp_request;
62e76326 71 return;
e6ccf245 72 }
62e76326 73
e6ccf245 74 /* The peer is allowed to use this cache */
f72fb56b 75 ICP3State *state = new ICP3State (header, icp_request);
62e76326 76
e6ccf245 77 state->fd = fd;
62e76326 78
e6ccf245 79 state->from = from;
62e76326 80
e6ccf245 81 state->url = xstrdup (url);
62e76326 82
3b13a8fd 83 StoreEntry::getPublic (state, url, METHOD_GET);
e6ccf245 84}
85
63be0a78 86ICP3State::~ICP3State()
62e76326 87{}
e6ccf245 88
89void
63be0a78 90ICP3State::created(StoreEntry *newEntry)
e6ccf245 91{
92 StoreEntry *entry = newEntry->isNull () ? NULL : newEntry;
bf8fe701 93 debugs(12, 5, "icpHandleIcpV3: OPCODE " << icp_opcode_str[header.opcode]);
e6ccf245 94 icp_opcode codeToSend;
62e76326 95
e6ccf245 96 if (icpCheckUdpHit(entry, request)) {
62e76326 97 codeToSend = ICP_HIT;
e6ccf245 98 } else if (icpGetCommonOpcode() == ICP_ERR)
62e76326 99 codeToSend = ICP_MISS;
e6ccf245 100 else
62e76326 101 codeToSend = icpGetCommonOpcode();
102
cc192b50 103 icpCreateAndSend (codeToSend, 0, url, header.reqnum, 0, fd, from);
62e76326 104
e6ccf245 105 delete this;
106}
7a2f978b 107
63be0a78 108
109/// \ingroup ServerProtocolICPInternal3
7a2f978b 110/* Currently Harvest cached-2.x uses ICP_VERSION_3 */
111void
b7ac5457 112icpHandleIcpV3(int fd, Ip::Address &from, char *buf, int len)
7a2f978b 113{
26ac0430 114 if (len <= 0) {
bf8fe701 115 debugs(12, 3, "icpHandleIcpV3: ICP message is too small");
62e76326 116 return;
e6ccf245 117 }
62e76326 118
e6ccf245 119 icp_common_t header (buf, len);
7b83b3d9 120 /*
121 * Length field should match the number of bytes read
122 */
62e76326 123
26ac0430 124 if (len != header.length) {
bf8fe701 125 debugs(12, 3, "icpHandleIcpV3: ICP message is too small");
62e76326 126 return;
7b83b3d9 127 }
62e76326 128
26ac0430 129 switch (header.opcode) {
62e76326 130
27cd7235 131 case ICP_QUERY:
cc192b50 132 doV3Query(fd, from, buf, header);
62e76326 133 break;
7a2f978b 134
27cd7235 135 case ICP_HIT:
62e76326 136
27cd7235 137 case ICP_DECHO:
62e76326 138
27cd7235 139 case ICP_MISS:
62e76326 140
27cd7235 141 case ICP_DENIED:
62e76326 142
27cd7235 143 case ICP_MISS_NOFETCH:
cc192b50 144 header.handleReply(buf, from);
62e76326 145 break;
7a2f978b 146
27cd7235 147 case ICP_INVALID:
62e76326 148
27cd7235 149 case ICP_ERR:
62e76326 150 break;
7a2f978b 151
152 default:
fa84c01d 153 debugs(12, DBG_CRITICAL, "icpHandleIcpV3: UNKNOWN OPCODE: " << header.opcode << " from " << from);
62e76326 154 break;
7a2f978b 155 }
7a2f978b 156}