~clint-fewbar/ubuntu/precise/squid3/ignore-sighup-early

« back to all changes in this revision

Viewing changes to src/whois.cc

  • Committer: Bazaar Package Importer
  • Author(s): Luigi Gangitano
  • Date: 2010-05-04 11:15:49 UTC
  • mfrom: (1.3.1 upstream)
  • mto: (20.3.1 squeeze) (21.2.1 sid)
  • mto: This revision was merged to the branch mainline in revision 21.
  • Revision ID: james.westby@ubuntu.com-20100504111549-1apjh2g5sndki4te
Tags: upstream-3.1.3
ImportĀ upstreamĀ versionĀ 3.1.3

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
 
2
2
/*
3
 
 * $Id: whois.cc,v 1.45 2007/05/29 13:31:41 amosjeffries Exp $
 
3
 * $Id$
4
4
 *
5
5
 * DEBUG: section 75    WHOIS protocol
6
6
 * AUTHOR: Duane Wessels, Kostas Anagnostakis
21
21
 *  it under the terms of the GNU General Public License as published by
22
22
 *  the Free Software Foundation; either version 2 of the License, or
23
23
 *  (at your option) any later version.
24
 
 *  
 
24
 *
25
25
 *  This program is distributed in the hope that it will be useful,
26
26
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
27
27
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
28
28
 *  GNU General Public License for more details.
29
 
 *  
 
29
 *
30
30
 *  You should have received a copy of the GNU General Public License
31
31
 *  along with this program; if not, write to the Free Software
32
32
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA.
49
49
 
50
50
public:
51
51
    ~WhoisState();
52
 
    void readReply (int fd, char *buf, size_t len, comm_err_t flag, int xerrno);
53
 
    void setReplyToOK(StoreEntry *entry);
 
52
    void readReply (int fd, char *aBuffer, size_t aBufferLength, comm_err_t flag, int xerrno);
 
53
    void setReplyToOK(StoreEntry *sentry);
54
54
    StoreEntry *entry;
55
55
    HttpRequest *request;
56
56
    FwdState::Pointer fwd;
91
91
    p->fwd = fwd;
92
92
    p->dataWritten = false;
93
93
 
94
 
    p->entry->lock()
95
 
 
96
 
    ;
 
94
    p->entry->lock();
97
95
    comm_add_close_handler(fd, whoisClose, p);
98
96
 
99
97
    l = p->request->urlpath.size() + 3;
100
98
 
101
99
    buf = (char *)xmalloc(l);
102
100
 
103
 
    snprintf(buf, l, "%s\r\n", p->request->urlpath.buf() + 1);
 
101
    String str_print=p->request->urlpath.substr(1,p->request->urlpath.size());
 
102
    snprintf(buf, l, SQUIDSTRINGPH"\r\n", SQUIDSTRINGPRINT(str_print));
104
103
 
105
104
    comm_write(fd, buf, strlen(buf), whoisWriteComplete, p, NULL);
106
105
    comm_read(fd, p->buf, BUFSIZ, whoisReadReply, p);
125
124
}
126
125
 
127
126
void
128
 
WhoisState::setReplyToOK(StoreEntry *entry)
 
127
WhoisState::setReplyToOK(StoreEntry *sentry)
129
128
{
130
129
    HttpReply *reply = new HttpReply;
131
 
    entry->buffer();
132
 
    HttpVersion version(1, 0);
133
 
    reply->setHeaders(version, HTTP_OK, "Gatewaying", "text/plain", -1, -1, -2);
134
 
    entry->replaceHttpReply(reply);
 
130
    sentry->buffer();
 
131
    reply->setHeaders(HTTP_OK, "Gatewaying", "text/plain", -1, -1, -2);
 
132
    sentry->replaceHttpReply(reply);
135
133
}
136
134
 
137
135
void
138
 
WhoisState::readReply (int fd, char *buf, size_t len, comm_err_t flag, int xerrno)
 
136
WhoisState::readReply (int fd, char *aBuffer, size_t aBufferLength, comm_err_t flag, int xerrno)
139
137
{
140
138
    int do_next_read = 0;
141
139
 
145
143
        return;
146
144
    }
147
145
 
148
 
    buf[len] = '\0';
149
 
    debugs(75, 3, "whoisReadReply: FD " << fd << " read " << len << " bytes");
150
 
    debugs(75, 5, "{" << buf << "}");
 
146
    aBuffer[aBufferLength] = '\0';
 
147
    debugs(75, 3, "whoisReadReply: FD " << fd << " read " << aBufferLength << " bytes");
 
148
    debugs(75, 5, "{" << aBuffer << "}");
151
149
 
152
 
    if (flag == COMM_OK && len > 0) {
 
150
    if (flag == COMM_OK && aBufferLength > 0) {
153
151
        if (!dataWritten)
154
152
            setReplyToOK(entry);
155
153
 
156
 
        kb_incr(&statCounter.server.all.kbytes_in, len);
 
154
        kb_incr(&statCounter.server.all.kbytes_in, aBufferLength);
157
155
 
158
 
        kb_incr(&statCounter.server.http.kbytes_in, len);
 
156
        kb_incr(&statCounter.server.http.kbytes_in, aBufferLength);
159
157
 
160
158
        /* No range support, we always grab it all */
161
159
        dataWritten = true;
162
160
 
163
 
        entry->append(buf, len);
 
161
        entry->append(aBuffer, aBufferLength);
164
162
 
165
163
        entry->flush();
166
164
 
167
165
        do_next_read = 1;
168
 
    } else if (flag != COMM_OK || len < 0) {
 
166
    } else if (flag != COMM_OK || aBufferLength < 0) {
169
167
        debugs(50, 2, "whoisReadReply: FD " << fd << ": read failure: " << xstrerror() << ".");
170
168
 
171
169
        if (ignoreErrno(errno)) {
195
193
    }
196
194
 
197
195
    if (do_next_read)
198
 
        comm_read(fd, buf, BUFSIZ, whoisReadReply, this);
 
196
        comm_read(fd, aBuffer, BUFSIZ, whoisReadReply, this);
199
197
}
200
198
 
201
199
static void