]> git.ipfire.org Git - thirdparty/squid.git/blame - src/whois.cc
Missed conversion.
[thirdparty/squid.git] / src / whois.cc
CommitLineData
77b32a34 1
af6691cc 2/*
d4cb310b 3 * $Id: whois.cc,v 1.21 2002/10/21 14:00:03 adrian Exp $
af6691cc 4 *
5 * DEBUG: section 75 WHOIS protocol
6 * AUTHOR: Duane Wessels, Kostas Anagnostakis
7 *
2b6662ba 8 * SQUID Web Proxy Cache http://www.squid-cache.org/
e25c139f 9 * ----------------------------------------------------------
af6691cc 10 *
2b6662ba 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.
af6691cc 19 *
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.
24 *
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.
29 *
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
cbdec147 32 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA.
e25c139f 33 *
af6691cc 34 */
35
36#include "squid.h"
e6ccf245 37#include "Store.h"
af6691cc 38
39#define WHOIS_PORT 43
40
41typedef struct {
42 StoreEntry *entry;
43 request_t *request;
db1cd23c 44 FwdState *fwd;
c4b7a5a9 45 char buf[BUFSIZ];
af6691cc 46} WhoisState;
47
48static PF whoisClose;
49static PF whoisTimeout;
c4b7a5a9 50static IOCB whoisReadReply;
af6691cc 51
52/* PUBLIC */
53
28c60158 54CBDATA_TYPE(WhoisState);
55
af6691cc 56void
db1cd23c 57whoisStart(FwdState * fwd)
af6691cc 58{
28c60158 59 WhoisState *p;
db1cd23c 60 int fd = fwd->server_fd;
af6691cc 61 char *buf;
62 size_t l;
28c60158 63 CBDATA_INIT_TYPE(WhoisState);
72711e31 64 p = cbdataAlloc(WhoisState);
db1cd23c 65 p->request = fwd->request;
66 p->entry = fwd->entry;
67 p->fwd = fwd;
af6691cc 68 storeLockObject(p->entry);
69 comm_add_close_handler(fd, whoisClose, p);
0cdcddb9 70 l = strLen(p->request->urlpath) + 3;
e6ccf245 71 buf = (char *)xmalloc(l);
af6691cc 72 snprintf(buf, l, "%s\r\n", strBuf(p->request->urlpath) + 1);
d4cb310b 73 comm_old_write(fd, buf, strlen(buf), NULL, p, xfree);
c4b7a5a9 74 comm_read(fd, p->buf, BUFSIZ, whoisReadReply, p);
af6691cc 75 commSetTimeout(fd, Config.Timeout.read, whoisTimeout, p);
76}
77
78/* PRIVATE */
79
80static void
81whoisTimeout(int fd, void *data)
82{
e6ccf245 83 WhoisState *p = (WhoisState *)data;
af6691cc 84 debug(75, 1) ("whoisTimeout: %s\n", storeUrl(p->entry));
85 whoisClose(fd, p);
86}
87
88static void
c4b7a5a9 89whoisReadReply(int fd, char *buf, size_t len, comm_err_t flag, int xerrno, void *data)
af6691cc 90{
e6ccf245 91 WhoisState *p = (WhoisState *)data;
af6691cc 92 StoreEntry *entry = p->entry;
d20b1cd0 93 MemObject *mem = entry->mem_obj;
c4b7a5a9 94 int do_next_read = 0;
95
96 /* Bail out early on COMM_ERR_CLOSING - close handlers will tidy up for us */
97 if (flag == COMM_ERR_CLOSING) {
98 return;
99 }
100
af6691cc 101 buf[len] = '\0';
c4b7a5a9 102 debug(75, 3) ("whoisReadReply: FD %d read %d bytes\n", fd, (int)len);
af6691cc 103 debug(75, 5) ("{%s}\n", buf);
c4b7a5a9 104 if (flag == COMM_OK && len > 0) {
d20b1cd0 105 if (0 == mem->inmem_hi)
106 mem->reply->sline.status = HTTP_OK;
83704487 107 kb_incr(&statCounter.server.all.kbytes_in, len);
108 kb_incr(&statCounter.server.http.kbytes_in, len);
abdacbb5 109 storeAppend(entry, buf, len);
c4b7a5a9 110 do_next_read = 1;
111 } else if (flag != COMM_OK || len < 0) {
abdacbb5 112 debug(50, 2) ("whoisReadReply: FD %d: read failure: %s.\n",
113 fd, xstrerror());
114 if (ignoreErrno(errno)) {
c4b7a5a9 115 do_next_read = 1;
d20b1cd0 116 } else if (mem->inmem_hi == 0) {
ec250dfd 117 ErrorState *err;
118 err = errorCon(ERR_READ_ERROR, HTTP_INTERNAL_SERVER_ERROR);
119 err->xerrno = errno;
120 fwdFail(p->fwd, err);
abdacbb5 121 comm_close(fd);
c4b7a5a9 122 do_next_read = 0;
abdacbb5 123 } else {
abdacbb5 124 comm_close(fd);
c4b7a5a9 125 do_next_read = 0;
abdacbb5 126 }
127 } else {
1a497c8c 128 storeTimestampsSet(entry);
129 storeBufferFlush(entry);
bac6d4bd 130 if (!EBIT_TEST(entry->flags, RELEASE_REQUEST))
1a497c8c 131 storeSetPublicKey(entry);
db1cd23c 132 fwdComplete(p->fwd);
af6691cc 133 debug(75, 3) ("whoisReadReply: Done: %s\n", storeUrl(entry));
134 comm_close(fd);
c4b7a5a9 135 do_next_read = 0;
af6691cc 136 }
c4b7a5a9 137 if (do_next_read)
138 comm_read(fd, p->buf, BUFSIZ, whoisReadReply, p);
af6691cc 139}
140
141static void
142whoisClose(int fd, void *data)
143{
e6ccf245 144 WhoisState *p = (WhoisState *)data;
af6691cc 145 debug(75, 3) ("whoisClose: FD %d\n", fd);
146 storeUnlockObject(p->entry);
147 cbdataFree(p);
148}