~ubuntu-branches/ubuntu/oneiric/squid3/oneiric-security

« back to all changes in this revision

Viewing changes to src/adaptation/icap/Xaction.cc

  • Committer: Bazaar Package Importer
  • Author(s): Mahyuddin Susanto
  • Date: 2011-02-15 18:46:13 UTC
  • mfrom: (21.2.4 sid)
  • Revision ID: james.westby@ubuntu.com-20110215184613-1u3dh5sz4i055flk
Tags: 3.1.10-1ubuntu1
* Merge from debian unstable. (LP: #719283)  Remaining changes:
  - debian/patches/18-fix-ftbfs-binutils-gold.dpatch: Add library linker into
    LIBS instead to LDFLAGS to fixing FTBFS binutils-gold.
* Drop Ubuntu configuration for ufw which landed in Debian and sync it: 
  - debian/squid3.ufw.profile.

Show diffs side-by-side

added added

removed removed

Lines of Context:
13
13
#include "pconn.h"
14
14
#include "HttpRequest.h"
15
15
#include "HttpReply.h"
 
16
#include "ip/tools.h"
16
17
#include "acl/FilledChecklist.h"
17
18
#include "icap_log.h"
18
19
#include "fde.h"
23
24
 
24
25
//CBDATA_NAMESPACED_CLASS_INIT(Adaptation::Icap, Xaction);
25
26
 
26
 
Adaptation::Icap::Xaction::Xaction(const char *aTypeName, Adaptation::Initiator *anInitiator, Adaptation::Icap::ServiceRep::Pointer &aService):
 
27
Adaptation::Icap::Xaction::Xaction(const char *aTypeName,
 
28
                                   Adaptation::Icap::ServiceRep::Pointer &aService):
27
29
        AsyncJob(aTypeName),
28
 
        Adaptation::Initiate(aTypeName, anInitiator),
 
30
        Adaptation::Initiate(aTypeName),
29
31
        icapRequest(NULL),
30
32
        icapReply(NULL),
31
33
        attempts(0),
50
52
    debugs(93,3, typeName << " destructed, this=" << this <<
51
53
           " [icapx" << id << ']'); // we should not call virtual status() here
52
54
    HTTPMSGUNLOCK(icapRequest);
53
 
    HTTPMSGUNLOCK(icapReply);
54
55
}
55
56
 
56
57
Adaptation::Icap::ServiceRep &
104
105
        // fake the connect callback
105
106
        // TODO: can we sync call Adaptation::Icap::Xaction::noteCommConnected here instead?
106
107
        typedef CommCbMemFunT<Adaptation::Icap::Xaction, CommConnectCbParams> Dialer;
107
 
        Dialer dialer(this, &Adaptation::Icap::Xaction::noteCommConnected);
 
108
        CbcPointer<Xaction> self(this);
 
109
        Dialer dialer(self, &Adaptation::Icap::Xaction::noteCommConnected);
108
110
        dialer.params.fd = connection;
109
111
        dialer.params.flag = COMM_OK;
110
112
        // fake other parameters by copying from the existing connection
116
118
    disableRetries(); // we only retry pconn failures
117
119
 
118
120
    IpAddress outgoing;
 
121
    if (!Ip::EnableIpv6 && !outgoing.SetIPv4()) {
 
122
        debugs(31, DBG_CRITICAL, "ERROR: IPv6 is disabled. " << outgoing << " is not an IPv4 address.");
 
123
        dieOnConnectionFailure(); // throws
 
124
    }
 
125
    /* split-stack for now requires default IPv4-only socket */
 
126
    if (Ip::EnableIpv6&IPV6_SPECIAL_SPLITSTACK && outgoing.IsAnyAddr() && !s.cfg().ipv6) {
 
127
        outgoing.SetIPv4();
 
128
    }
 
129
 
119
130
    connection = comm_open(SOCK_STREAM, 0, outgoing,
120
131
                           COMM_NONBLOCKING, s.cfg().uri.termedBuf());
121
132
 
126
137
 
127
138
    // TODO: service bypass status may differ from that of a transaction
128
139
    typedef CommCbMemFunT<Adaptation::Icap::Xaction, CommTimeoutCbParams> TimeoutDialer;
129
 
    AsyncCall::Pointer timeoutCall =  asyncCall(93, 5, "Adaptation::Icap::Xaction::noteCommTimedout",
130
 
                                      TimeoutDialer(this,&Adaptation::Icap::Xaction::noteCommTimedout));
131
 
 
 
140
    AsyncCall::Pointer timeoutCall = JobCallback(93, 5,
 
141
                                     TimeoutDialer, this, Adaptation::Icap::Xaction::noteCommTimedout);
132
142
    commSetTimeout(connection, TheConfig.connect_timeout(
133
143
                       service().cfg().bypass), timeoutCall);
134
144
 
135
145
    typedef CommCbMemFunT<Adaptation::Icap::Xaction, CommCloseCbParams> CloseDialer;
136
 
    closer =  asyncCall(93, 5, "Adaptation::Icap::Xaction::noteCommClosed",
137
 
                        CloseDialer(this,&Adaptation::Icap::Xaction::noteCommClosed));
 
146
    closer = JobCallback(93, 5,
 
147
                         CloseDialer, this, Adaptation::Icap::Xaction::noteCommClosed);
138
148
    comm_add_close_handler(connection, closer);
139
149
 
140
150
    typedef CommCbMemFunT<Adaptation::Icap::Xaction, CommConnectCbParams> ConnectDialer;
141
 
    connector = asyncCall(93,3, "Adaptation::Icap::Xaction::noteCommConnected",
142
 
                          ConnectDialer(this, &Adaptation::Icap::Xaction::noteCommConnected));
 
151
    connector = JobCallback(93,3,
 
152
                            ConnectDialer, this, Adaptation::Icap::Xaction::noteCommConnected);
143
153
    commConnectStart(connection, s.cfg().host.termedBuf(), s.cfg().port, connector);
144
154
}
145
155
 
223
233
{
224
234
    // comm module will free the buffer
225
235
    typedef CommCbMemFunT<Adaptation::Icap::Xaction, CommIoCbParams> Dialer;
226
 
    writer = asyncCall(93,3, "Adaptation::Icap::Xaction::noteCommWrote",
227
 
                       Dialer(this, &Adaptation::Icap::Xaction::noteCommWrote));
 
236
    writer = JobCallback(93,3,
 
237
                         Dialer, this, Adaptation::Icap::Xaction::noteCommWrote);
228
238
 
229
239
    comm_write_mbuf(connection, &buf, writer);
230
240
    updateTimeout();
259
269
           theService->cfg().methodStr() << " " <<
260
270
           theService->cfg().uri << status());
261
271
    reuseConnection = false;
262
 
    service().noteFailure();
263
272
 
264
 
    throw TexcHere(connector != NULL ?
 
273
    const bool whileConnecting = connector != NULL;
 
274
    closeConnection(); // so that late Comm callbacks do not disturb bypass
 
275
    throw TexcHere(whileConnecting ?
265
276
                   "timed out while connecting to the ICAP service" :
266
277
                   "timed out while talking to the ICAP service");
267
278
}
306
317
        // XXX: why does Config.Timeout lacks a write timeout?
307
318
        // TODO: service bypass status may differ from that of a transaction
308
319
        typedef CommCbMemFunT<Adaptation::Icap::Xaction, CommTimeoutCbParams> TimeoutDialer;
309
 
        AsyncCall::Pointer call =  asyncCall(93, 5, "Adaptation::Icap::Xaction::noteCommTimedout",
310
 
                                             TimeoutDialer(this,&Adaptation::Icap::Xaction::noteCommTimedout));
 
320
        AsyncCall::Pointer call = JobCallback(93,5,
 
321
                                              TimeoutDialer, this, Adaptation::Icap::Xaction::noteCommTimedout);
311
322
 
312
323
        commSetTimeout(connection,
313
324
                       TheConfig.io_timeout(service().cfg().bypass), call);
330
341
     * here instead of reading directly into readBuf.buf.
331
342
     */
332
343
    typedef CommCbMemFunT<Adaptation::Icap::Xaction, CommIoCbParams> Dialer;
333
 
    reader = asyncCall(93,3, "Adaptation::Icap::Xaction::noteCommRead",
334
 
                       Dialer(this, &Adaptation::Icap::Xaction::noteCommRead));
 
344
    reader = JobCallback(93,3,
 
345
                         Dialer, this, Adaptation::Icap::Xaction::noteCommRead);
335
346
 
336
347
    comm_read(connection, commBuf, readBuf.spaceSize(), reader);
337
348
    updateTimeout();
346
357
    Must(io.flag == COMM_OK);
347
358
    Must(io.size >= 0);
348
359
 
349
 
    al.icap.bytesRead+=io.size;
350
 
 
351
 
    updateTimeout();
352
 
 
353
 
    debugs(93, 3, HERE << "read " << io.size << " bytes");
354
 
 
355
 
    /*
356
 
     * See comments in Adaptation::Icap::Xaction.h about why we use commBuf
357
 
     * here instead of reading directly into readBuf.buf.
358
 
     */
359
 
 
360
 
    if (io.size > 0) {
 
360
    if (!io.size) {
 
361
        commEof = true;
 
362
        reuseConnection = false;
 
363
 
 
364
        // detect a pconn race condition: eof on the first pconn read
 
365
        if (!al.icap.bytesRead && retriable()) {
 
366
            setOutcome(xoRace);
 
367
            mustStop("pconn race");
 
368
            return;
 
369
        }
 
370
    } else {
 
371
 
 
372
        al.icap.bytesRead+=io.size;
 
373
 
 
374
        updateTimeout();
 
375
 
 
376
        debugs(93, 3, HERE << "read " << io.size << " bytes");
 
377
 
 
378
        /*
 
379
         * See comments in Adaptation::Icap::Xaction.h about why we use commBuf
 
380
         * here instead of reading directly into readBuf.buf.
 
381
         */
 
382
 
361
383
        readBuf.append(commBuf, io.size);
362
384
        disableRetries(); // because pconn did not fail
363
 
    } else {
364
 
        reuseConnection = false;
365
 
        commEof = true;
366
385
    }
367
386
 
368
387
    handleCommRead(io.size);
421
440
void Adaptation::Icap::Xaction::noteInitiatorAborted()
422
441
{
423
442
 
424
 
    if (theInitiator) {
 
443
    if (theInitiator.set()) {
425
444
        clearInitiator();
426
445
        mustStop("initiator aborted");
427
446
    }
454
473
    if (commBuf)
455
474
        memFreeBuf(commBufSize, commBuf);
456
475
 
457
 
    if (theInitiator)
458
 
        tellQueryAborted();
 
476
    tellQueryAborted();
459
477
 
460
478
    maybeLog();
461
479
 
464
482
 
465
483
void Adaptation::Icap::Xaction::tellQueryAborted()
466
484
{
467
 
    Adaptation::Icap::Launcher *l = dynamic_cast<Adaptation::Icap::Launcher*>(theInitiator.ptr());
468
 
    Adaptation::Icap::XactAbortInfo abortInfo(icapRequest, icapReply, retriable(), repeatable());
469
 
    CallJob(91, 5, __FILE__, __LINE__,
470
 
            "Adaptation::Icap::Launcher::noteXactAbort",
471
 
            XactAbortCall(l, &Adaptation::Icap::Launcher::noteXactAbort, abortInfo) );
472
 
    clearInitiator();
 
485
    if (theInitiator.set()) {
 
486
        Adaptation::Icap::XactAbortInfo abortInfo(icapRequest, icapReply,
 
487
                retriable(), repeatable());
 
488
        Launcher *launcher = dynamic_cast<Launcher*>(theInitiator.get());
 
489
        // launcher may be nil if initiator is invalid
 
490
        CallJobHere1(91,5, CbcPointer<Launcher>(launcher),
 
491
                     Launcher, noteXactAbort, abortInfo);
 
492
        clearInitiator();
 
493
    }
473
494
}
474
495
 
475
496