]>
Commit | Line | Data |
---|---|---|
77b32a34 | 1 | |
af6691cc | 2 | /* |
e6ccf245 | 3 | * $Id: whois.cc,v 1.19 2002/10/13 20:35:06 robertc 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 | ||
41 | typedef struct { | |
42 | StoreEntry *entry; | |
43 | request_t *request; | |
db1cd23c | 44 | FwdState *fwd; |
af6691cc | 45 | } WhoisState; |
46 | ||
47 | static PF whoisClose; | |
48 | static PF whoisTimeout; | |
49 | static PF whoisReadReply; | |
50 | ||
51 | /* PUBLIC */ | |
52 | ||
28c60158 | 53 | CBDATA_TYPE(WhoisState); |
54 | ||
af6691cc | 55 | void |
db1cd23c | 56 | whoisStart(FwdState * fwd) |
af6691cc | 57 | { |
28c60158 | 58 | WhoisState *p; |
db1cd23c | 59 | int fd = fwd->server_fd; |
af6691cc | 60 | char *buf; |
61 | size_t l; | |
28c60158 | 62 | CBDATA_INIT_TYPE(WhoisState); |
72711e31 | 63 | p = cbdataAlloc(WhoisState); |
db1cd23c | 64 | p->request = fwd->request; |
65 | p->entry = fwd->entry; | |
66 | p->fwd = fwd; | |
af6691cc | 67 | storeLockObject(p->entry); |
68 | comm_add_close_handler(fd, whoisClose, p); | |
0cdcddb9 | 69 | l = strLen(p->request->urlpath) + 3; |
e6ccf245 | 70 | buf = (char *)xmalloc(l); |
af6691cc | 71 | snprintf(buf, l, "%s\r\n", strBuf(p->request->urlpath) + 1); |
72 | comm_write(fd, buf, strlen(buf), NULL, p, xfree); | |
73 | commSetSelect(fd, COMM_SELECT_READ, whoisReadReply, p, 0); | |
74 | commSetTimeout(fd, Config.Timeout.read, whoisTimeout, p); | |
75 | } | |
76 | ||
77 | /* PRIVATE */ | |
78 | ||
79 | static void | |
80 | whoisTimeout(int fd, void *data) | |
81 | { | |
e6ccf245 | 82 | WhoisState *p = (WhoisState *)data; |
af6691cc | 83 | debug(75, 1) ("whoisTimeout: %s\n", storeUrl(p->entry)); |
84 | whoisClose(fd, p); | |
85 | } | |
86 | ||
87 | static void | |
88 | whoisReadReply(int fd, void *data) | |
89 | { | |
e6ccf245 | 90 | WhoisState *p = (WhoisState *)data; |
af6691cc | 91 | StoreEntry *entry = p->entry; |
e6ccf245 | 92 | char *buf = (char *)memAllocate(MEM_4K_BUF); |
d20b1cd0 | 93 | MemObject *mem = entry->mem_obj; |
af6691cc | 94 | int len; |
83704487 | 95 | statCounter.syscalls.sock.reads++; |
1f7c9178 | 96 | len = FD_READ_METHOD(fd, buf, 4095); |
af6691cc | 97 | buf[len] = '\0'; |
98 | debug(75, 3) ("whoisReadReply: FD %d read %d bytes\n", fd, len); | |
99 | debug(75, 5) ("{%s}\n", buf); | |
abdacbb5 | 100 | if (len > 0) { |
d20b1cd0 | 101 | if (0 == mem->inmem_hi) |
102 | mem->reply->sline.status = HTTP_OK; | |
abdacbb5 | 103 | fd_bytes(fd, len, FD_READ); |
83704487 | 104 | kb_incr(&statCounter.server.all.kbytes_in, len); |
105 | kb_incr(&statCounter.server.http.kbytes_in, len); | |
abdacbb5 | 106 | storeAppend(entry, buf, len); |
107 | commSetSelect(fd, COMM_SELECT_READ, whoisReadReply, p, Config.Timeout.read); | |
108 | } else if (len < 0) { | |
109 | debug(50, 2) ("whoisReadReply: FD %d: read failure: %s.\n", | |
110 | fd, xstrerror()); | |
111 | if (ignoreErrno(errno)) { | |
112 | commSetSelect(fd, COMM_SELECT_READ, whoisReadReply, p, Config.Timeout.read); | |
d20b1cd0 | 113 | } else if (mem->inmem_hi == 0) { |
ec250dfd | 114 | ErrorState *err; |
115 | err = errorCon(ERR_READ_ERROR, HTTP_INTERNAL_SERVER_ERROR); | |
116 | err->xerrno = errno; | |
117 | fwdFail(p->fwd, err); | |
abdacbb5 | 118 | comm_close(fd); |
119 | } else { | |
abdacbb5 | 120 | comm_close(fd); |
121 | } | |
122 | } else { | |
1a497c8c | 123 | storeTimestampsSet(entry); |
124 | storeBufferFlush(entry); | |
bac6d4bd | 125 | if (!EBIT_TEST(entry->flags, RELEASE_REQUEST)) |
1a497c8c | 126 | storeSetPublicKey(entry); |
db1cd23c | 127 | fwdComplete(p->fwd); |
af6691cc | 128 | debug(75, 3) ("whoisReadReply: Done: %s\n", storeUrl(entry)); |
129 | comm_close(fd); | |
af6691cc | 130 | } |
db1cd23c | 131 | memFree(buf, MEM_4K_BUF); |
af6691cc | 132 | } |
133 | ||
134 | static void | |
135 | whoisClose(int fd, void *data) | |
136 | { | |
e6ccf245 | 137 | WhoisState *p = (WhoisState *)data; |
af6691cc | 138 | debug(75, 3) ("whoisClose: FD %d\n", fd); |
139 | storeUnlockObject(p->entry); | |
140 | cbdataFree(p); | |
141 | } |