]> git.ipfire.org Git - thirdparty/squid.git/blame - src/whois.cc
adding
[thirdparty/squid.git] / src / whois.cc
CommitLineData
af6691cc 1/*
2 * $Id: whois.cc,v 1.1 1998/06/04 19:06:15 wessels Exp $
3 *
4 * DEBUG: section 75 WHOIS protocol
5 * AUTHOR: Duane Wessels, Kostas Anagnostakis
6 *
7 * SQUID Internet Object Cache http://squid.nlanr.net/Squid/
8 * --------------------------------------------------------
9 *
10 * Squid is the result of efforts by numerous individuals from the
11 * Internet community. Development is led by Duane Wessels of the
12 * National Laboratory for Applied Network Research and funded by
13 * the National Science Foundation.
14 *
15 * This program is free software; you can redistribute it and/or modify
16 * it under the terms of the GNU General Public License as published by
17 * the Free Software Foundation; either version 2 of the License, or
18 * (at your option) any later version.
19 *
20 * This program is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
24 *
25 * You should have received a copy of the GNU General Public License
26 * along with this program; if not, write to the Free Software
27 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
28 *
29 */
30
31#include "squid.h"
32
33#define WHOIS_PORT 43
34
35typedef struct {
36 StoreEntry *entry;
37 request_t *request;
38} WhoisState;
39
40static PF whoisClose;
41static PF whoisTimeout;
42static PF whoisReadReply;
43
44/* PUBLIC */
45
46void
47whoisStart(request_t * request, StoreEntry * entry, int fd)
48{
49 WhoisState *p = xcalloc(1, sizeof(*p));
50 char *buf;
51 size_t l;
52 p->request = request;
53 p->entry = entry;
54 cbdataAdd(p, MEM_NONE);
55 storeLockObject(p->entry);
56 comm_add_close_handler(fd, whoisClose, p);
57 l = strLen(p->request->urlpath)+3;
58 buf = xmalloc(l);
59 snprintf(buf, l, "%s\r\n", strBuf(p->request->urlpath) + 1);
60 comm_write(fd, buf, strlen(buf), NULL, p, xfree);
61 commSetSelect(fd, COMM_SELECT_READ, whoisReadReply, p, 0);
62 commSetTimeout(fd, Config.Timeout.read, whoisTimeout, p);
63}
64
65/* PRIVATE */
66
67static void
68whoisTimeout(int fd, void *data)
69{
70 WhoisState *p = data;
71 debug(75, 1) ("whoisTimeout: %s\n", storeUrl(p->entry));
72 whoisClose(fd, p);
73}
74
75static void
76whoisReadReply(int fd, void *data)
77{
78 WhoisState *p = data;
79 StoreEntry *entry = p->entry;
80 char *buf = memAllocate(MEM_4K_BUF);
81 int len;
82 len = read(fd, buf, 4095);
83 buf[len] = '\0';
84 debug(75, 3) ("whoisReadReply: FD %d read %d bytes\n", fd, len);
85 debug(75, 5) ("{%s}\n", buf);
86 if (len <= 0) {
87 storeComplete(entry);
88 debug(75, 3) ("whoisReadReply: Done: %s\n", storeUrl(entry));
89 comm_close(fd);
90 memFree(MEM_4K_BUF, buf);
91 return;
92 }
93 storeAppend(entry, buf, len);
94 memFree(MEM_4K_BUF, buf);
95 fd_bytes(fd, len, FD_READ);
96 commSetSelect(fd, COMM_SELECT_READ, whoisReadReply, p, Config.Timeout.read);
97}
98
99static void
100whoisClose(int fd, void *data)
101{
102 WhoisState *p = data;
103 debug(75, 3) ("whoisClose: FD %d\n", fd);
104 storeUnlockObject(p->entry);
105 cbdataFree(p);
106}