]> git.ipfire.org Git - thirdparty/squid.git/blob - src/adaptation/icap/ServiceRep.cc
SourceLayout: C++11 upgrade for class YesNoNone
[thirdparty/squid.git] / src / adaptation / icap / ServiceRep.cc
1 /*
2 * Copyright (C) 1996-2016 The Squid Software Foundation and contributors
3 *
4 * Squid software is distributed under GPLv2+ license and includes
5 * contributions from numerous individuals and organizations.
6 * Please see the COPYING and CONTRIBUTORS files for details.
7 */
8
9 /* DEBUG: section 93 ICAP (RFC 3507) Client */
10
11 #include "squid.h"
12 #include "adaptation/Answer.h"
13 #include "adaptation/icap/Config.h"
14 #include "adaptation/icap/ModXact.h"
15 #include "adaptation/icap/Options.h"
16 #include "adaptation/icap/OptXact.h"
17 #include "adaptation/icap/ServiceRep.h"
18 #include "base/TextException.h"
19 #include "comm/Connection.h"
20 #include "ConfigParser.h"
21 #include "Debug.h"
22 #include "fde.h"
23 #include "globals.h"
24 #include "HttpReply.h"
25 #include "ip/tools.h"
26 #include "SquidConfig.h"
27 #include "SquidTime.h"
28
29 #define DEFAULT_ICAP_PORT 1344
30 #define DEFAULT_ICAPS_PORT 11344
31
32 CBDATA_NAMESPACED_CLASS_INIT(Adaptation::Icap, ServiceRep);
33
34 Adaptation::Icap::ServiceRep::ServiceRep(const ServiceConfigPointer &svcCfg):
35 AsyncJob("Adaptation::Icap::ServiceRep"), Adaptation::Service(svcCfg),
36 sslContext(NULL),
37 #if USE_OPENSSL
38 sslSession(NULL),
39 #endif
40 theOptions(NULL), theOptionsFetcher(0), theLastUpdate(0),
41 theBusyConns(0),
42 theAllWaiters(0),
43 connOverloadReported(false),
44 theIdleConns(NULL),
45 isSuspended(0), notifying(false),
46 updateScheduled(false),
47 wasAnnouncedUp(true), // do not announce an "up" service at startup
48 isDetached(false)
49 {
50 setMaxConnections();
51 theIdleConns = new IdleConnList("ICAP Service", NULL);
52 }
53
54 Adaptation::Icap::ServiceRep::~ServiceRep()
55 {
56 delete theIdleConns;
57 Must(!theOptionsFetcher);
58 delete theOptions;
59 }
60
61 void
62 Adaptation::Icap::ServiceRep::finalize()
63 {
64 Adaptation::Service::finalize();
65
66 // use /etc/services or default port if needed
67 const bool have_port = cfg().port >= 0;
68 if (!have_port) {
69 struct servent *serv;
70 if (cfg().protocol.caseCmp("icaps") == 0)
71 serv = getservbyname("icaps", "tcp");
72 else
73 serv = getservbyname("icap", "tcp");
74
75 if (serv) {
76 writeableCfg().port = htons(serv->s_port);
77 } else {
78 writeableCfg().port = cfg().protocol.caseCmp("icaps") == 0 ? DEFAULT_ICAPS_PORT : DEFAULT_ICAP_PORT;
79 }
80 }
81
82 if (cfg().protocol.caseCmp("icaps") == 0)
83 writeableCfg().secure.encryptTransport = true;
84
85 if (cfg().secure.encryptTransport) {
86 debugs(3, DBG_IMPORTANT, "Initializing service " << cfg().resource << " SSL context");
87 sslContext = writeableCfg().secure.createClientContext(true);
88 }
89
90 if (!cfg().connectionEncryption.configured())
91 writeableCfg().connectionEncryption.defaultTo(cfg().secure.encryptTransport);
92
93 theSessionFailures.configure(TheConfig.oldest_service_failure > 0 ?
94 TheConfig.oldest_service_failure : -1);
95 }
96
97 void Adaptation::Icap::ServiceRep::noteFailure()
98 {
99 const int failures = theSessionFailures.count(1);
100 debugs(93,4, HERE << " failure " << failures << " out of " <<
101 TheConfig.service_failure_limit << " allowed in " <<
102 TheConfig.oldest_service_failure << "sec " << status());
103
104 if (isSuspended)
105 return;
106
107 if (TheConfig.service_failure_limit >= 0 &&
108 failures > TheConfig.service_failure_limit)
109 suspend("too many failures");
110
111 // TODO: Should bypass setting affect how much Squid tries to talk to
112 // the ICAP service that is currently unusable and is likely to remain
113 // so for some time? The current code says "no". Perhaps the answer
114 // should be configurable.
115 }
116
117 // returns a persistent or brand new connection; negative int on failures
118 Comm::ConnectionPointer
119 Adaptation::Icap::ServiceRep::getConnection(bool retriableXact, bool &reused)
120 {
121 Comm::ConnectionPointer connection;
122
123 /* 2011-06-17: rousskov:
124 * There are two things that happen at the same time in pop(). Both are important.
125 * 1) Ensure that we can use a pconn for this transaction.
126 * 2) Ensure that the number of idle pconns does not grow without bounds.
127 *
128 * Both happen in the beginning of the transaction. Both are dictated by real-world problems.
129 * retriable means you can repeat the request if you suspect the first try failed due to a pconn race.
130 * HTTP and ICAP rules prohibit the use of pconns for non-retriable requests.
131 *
132 * If there are zero idle connections, (2) is irrelevant. (2) is only relevant when there are many
133 * idle connections and we should not open more connections without closing some idle ones,
134 * or instead of just opening a new connection and leaving idle connections as is.
135 * In other words, (2) tells us to close one FD for each new one we open due to retriable.
136 */
137 if (retriableXact)
138 connection = theIdleConns->pop();
139 else
140 theIdleConns->closeN(1);
141
142 reused = Comm::IsConnOpen(connection);
143 ++theBusyConns;
144 debugs(93,3, HERE << "got connection: " << connection);
145 return connection;
146 }
147
148 // pools connection if it is reusable or closes it
149 void Adaptation::Icap::ServiceRep::putConnection(const Comm::ConnectionPointer &conn, bool isReusable, bool sendReset, const char *comment)
150 {
151 Must(Comm::IsConnOpen(conn));
152 // do not pool an idle connection if we owe connections
153 if (isReusable && excessConnections() == 0) {
154 debugs(93, 3, HERE << "pushing pconn" << comment);
155 commUnsetConnTimeout(conn);
156 theIdleConns->push(conn);
157 } else {
158 debugs(93, 3, HERE << (sendReset ? "RST" : "FIN") << "-closing " <<
159 comment);
160 // comm_close called from Connection::close will clear timeout
161 // TODO: add "bool sendReset = false" to Connection::close()?
162 if (sendReset)
163 comm_reset_close(conn);
164 else
165 conn->close();
166 }
167
168 Must(theBusyConns > 0);
169 --theBusyConns;
170 // a connection slot released. Check if there are waiters....
171 busyCheckpoint();
172 }
173
174 // a wrapper to avoid exposing theIdleConns
175 void Adaptation::Icap::ServiceRep::noteConnectionUse(const Comm::ConnectionPointer &conn)
176 {
177 Must(Comm::IsConnOpen(conn));
178 fd_table[conn->fd].noteUse(); // pconn re-use, albeit not via PconnPool API
179 }
180
181 void Adaptation::Icap::ServiceRep::noteConnectionFailed(const char *comment)
182 {
183 debugs(93, 3, HERE << "Connection failed: " << comment);
184 --theBusyConns;
185 }
186
187 void Adaptation::Icap::ServiceRep::setMaxConnections()
188 {
189 if (cfg().maxConn >= 0)
190 theMaxConnections = cfg().maxConn;
191 else if (theOptions && theOptions->max_connections >= 0)
192 theMaxConnections = theOptions->max_connections;
193 else {
194 theMaxConnections = -1;
195 return;
196 }
197
198 if (::Config.workers > 1 )
199 theMaxConnections /= ::Config.workers;
200 }
201
202 int Adaptation::Icap::ServiceRep::availableConnections() const
203 {
204 if (theMaxConnections < 0)
205 return -1;
206
207 // we are available if we can open or reuse connections
208 // in other words, if we will not create debt
209 int available = max(0, theMaxConnections - theBusyConns);
210
211 if (!available && !connOverloadReported) {
212 debugs(93, DBG_IMPORTANT, "WARNING: ICAP Max-Connections limit " <<
213 "exceeded for service " << cfg().uri << ". Open connections now: " <<
214 theBusyConns + theIdleConns->count() << ", including " <<
215 theIdleConns->count() << " idle persistent connections.");
216 connOverloadReported = true;
217 }
218
219 if (cfg().onOverload == srvForce)
220 return -1;
221
222 return available;
223 }
224
225 // The number of connections which excess the Max-Connections limit
226 int Adaptation::Icap::ServiceRep::excessConnections() const
227 {
228 if (theMaxConnections < 0)
229 return 0;
230
231 // Waiters affect the number of needed connections but a needed
232 // connection may still be excessive from Max-Connections p.o.v.
233 // so we should not account for waiting transaction needs here.
234 const int debt = theBusyConns + theIdleConns->count() - theMaxConnections;
235 if (debt > 0)
236 return debt;
237 else
238 return 0;
239 }
240
241 void Adaptation::Icap::ServiceRep::noteGoneWaiter()
242 {
243 --theAllWaiters;
244
245 // in case the notified transaction did not take the connection slot
246 busyCheckpoint();
247 }
248
249 // called when a connection slot may become available
250 void Adaptation::Icap::ServiceRep::busyCheckpoint()
251 {
252 if (theNotificationWaiters.empty()) // nobody is waiting for a slot
253 return;
254
255 int freed = 0;
256 int available = availableConnections();
257
258 if (available < 0) {
259 // It is possible to have waiters when no limit on connections exist in
260 // case of reconfigure or because new Options received.
261 // In this case, notify all waiting transactions.
262 freed = theNotificationWaiters.size();
263 } else {
264 // avoid notifying more waiters than there will be available slots
265 const int notifiedWaiters = theAllWaiters - theNotificationWaiters.size();
266 freed = available - notifiedWaiters;
267 }
268
269 debugs(93,7, HERE << "Available connections: " << available <<
270 " freed slots: " << freed <<
271 " waiting in queue: " << theNotificationWaiters.size());
272
273 while (freed > 0 && !theNotificationWaiters.empty()) {
274 Client i = theNotificationWaiters.front();
275 theNotificationWaiters.pop_front();
276 ScheduleCallHere(i.callback);
277 i.callback = NULL;
278 --freed;
279 }
280 }
281
282 void Adaptation::Icap::ServiceRep::suspend(const char *reason)
283 {
284 if (isSuspended) {
285 debugs(93,4, HERE << "keeping suspended, also for " << reason);
286 } else {
287 isSuspended = reason;
288 debugs(93, DBG_IMPORTANT, "suspending ICAP service for " << reason);
289 scheduleUpdate(squid_curtime + TheConfig.service_revival_delay);
290 announceStatusChange("suspended", true);
291 }
292 }
293
294 bool Adaptation::Icap::ServiceRep::probed() const
295 {
296 return theLastUpdate != 0;
297 }
298
299 bool Adaptation::Icap::ServiceRep::hasOptions() const
300 {
301 return theOptions && theOptions->valid() && theOptions->fresh();
302 }
303
304 bool Adaptation::Icap::ServiceRep::up() const
305 {
306 return !isSuspended && hasOptions();
307 }
308
309 bool Adaptation::Icap::ServiceRep::availableForNew() const
310 {
311 Must(up());
312 int available = availableConnections();
313 if (available < 0)
314 return true;
315 else
316 return (available - theAllWaiters > 0);
317 }
318
319 bool Adaptation::Icap::ServiceRep::availableForOld() const
320 {
321 Must(up());
322
323 int available = availableConnections();
324 return (available != 0); // it is -1 (no limit) or has available slots
325 }
326
327 bool Adaptation::Icap::ServiceRep::wantsUrl(const SBuf &urlPath) const
328 {
329 Must(hasOptions());
330 return theOptions->transferKind(urlPath) != Adaptation::Icap::Options::xferIgnore;
331 }
332
333 bool Adaptation::Icap::ServiceRep::wantsPreview(const SBuf &urlPath, size_t &wantedSize) const
334 {
335 Must(hasOptions());
336
337 if (theOptions->preview < 0)
338 return false;
339
340 if (theOptions->transferKind(urlPath) != Adaptation::Icap::Options::xferPreview)
341 return false;
342
343 wantedSize = theOptions->preview;
344
345 return true;
346 }
347
348 bool Adaptation::Icap::ServiceRep::allows204() const
349 {
350 Must(hasOptions());
351 return true; // in the future, we may have ACLs to prevent 204s
352 }
353
354 bool Adaptation::Icap::ServiceRep::allows206() const
355 {
356 Must(hasOptions());
357 if (theOptions->allow206)
358 return true; // in the future, we may have ACLs to prevent 206s
359 return false;
360 }
361
362 static
363 void ServiceRep_noteTimeToUpdate(void *data)
364 {
365 Adaptation::Icap::ServiceRep *service = static_cast<Adaptation::Icap::ServiceRep*>(data);
366 Must(service);
367 service->noteTimeToUpdate();
368 }
369
370 void Adaptation::Icap::ServiceRep::noteTimeToUpdate()
371 {
372 if (!detached())
373 updateScheduled = false;
374
375 if (detached() || theOptionsFetcher.set()) {
376 debugs(93,5, HERE << "ignores options update " << status());
377 return;
378 }
379
380 debugs(93,5, HERE << "performs a regular options update " << status());
381 startGettingOptions();
382 }
383
384 #if 0
385 static
386 void Adaptation::Icap::ServiceRep_noteTimeToNotify(void *data)
387 {
388 Adaptation::Icap::ServiceRep *service = static_cast<Adaptation::Icap::ServiceRep*>(data);
389 Must(service);
390 service->noteTimeToNotify();
391 }
392 #endif
393
394 void Adaptation::Icap::ServiceRep::noteTimeToNotify()
395 {
396 Must(!notifying);
397 notifying = true;
398 debugs(93,7, HERE << "notifies " << theClients.size() << " clients " <<
399 status());
400
401 // note: we must notify even if we are invalidated
402
403 Pointer us = NULL;
404
405 while (!theClients.empty()) {
406 Client i = theClients.back();
407 theClients.pop_back();
408 ScheduleCallHere(i.callback);
409 i.callback = 0;
410 }
411
412 notifying = false;
413 }
414
415 void Adaptation::Icap::ServiceRep::callWhenAvailable(AsyncCall::Pointer &cb, bool priority)
416 {
417 debugs(93,8, "ICAPServiceRep::callWhenAvailable");
418 Must(cb!=NULL);
419 Must(up());
420 Must(!theIdleConns->count()); // or we should not be waiting
421
422 Client i;
423 i.service = Pointer(this);
424 i.callback = cb;
425 if (priority)
426 theNotificationWaiters.push_front(i);
427 else
428 theNotificationWaiters.push_back(i);
429
430 busyCheckpoint();
431 }
432
433 void Adaptation::Icap::ServiceRep::callWhenReady(AsyncCall::Pointer &cb)
434 {
435 Must(cb!=NULL);
436
437 debugs(93,5, HERE << "Adaptation::Icap::Service is asked to call " << *cb <<
438 " when ready " << status());
439
440 Must(!broken()); // we do not wait for a broken service
441
442 Client i;
443 i.service = Pointer(this); // TODO: is this really needed?
444 i.callback = cb;
445 theClients.push_back(i);
446
447 if (theOptionsFetcher.set() || notifying)
448 return; // do nothing, we will be picked up in noteTimeToNotify()
449
450 if (needNewOptions())
451 startGettingOptions();
452 else
453 scheduleNotification();
454 }
455
456 void Adaptation::Icap::ServiceRep::scheduleNotification()
457 {
458 debugs(93,7, HERE << "will notify " << theClients.size() << " clients");
459 CallJobHere(93, 5, this, Adaptation::Icap::ServiceRep, noteTimeToNotify);
460 }
461
462 bool Adaptation::Icap::ServiceRep::needNewOptions() const
463 {
464 return !detached() && !up();
465 }
466
467 void Adaptation::Icap::ServiceRep::changeOptions(Adaptation::Icap::Options *newOptions)
468 {
469 debugs(93,8, HERE << "changes options from " << theOptions << " to " <<
470 newOptions << ' ' << status());
471
472 delete theOptions;
473 theOptions = newOptions;
474 theSessionFailures.clear();
475 isSuspended = 0;
476 theLastUpdate = squid_curtime;
477
478 checkOptions();
479 announceStatusChange("down after an options fetch failure", true);
480 }
481
482 void Adaptation::Icap::ServiceRep::checkOptions()
483 {
484 if (theOptions == NULL)
485 return;
486
487 if (!theOptions->valid()) {
488 debugs(93, DBG_IMPORTANT, "WARNING: Squid got an invalid ICAP OPTIONS response " <<
489 "from service " << cfg().uri << "; error: " << theOptions->error);
490 return;
491 }
492
493 /*
494 * Issue a warning if the ICAP server returned methods in the
495 * options response that don't match the method from squid.conf.
496 */
497
498 if (!theOptions->methods.empty()) {
499 bool method_found = false;
500 String method_list;
501 std::vector <ICAP::Method>::iterator iter = theOptions->methods.begin();
502
503 while (iter != theOptions->methods.end()) {
504
505 if (*iter == cfg().method) {
506 method_found = true;
507 break;
508 }
509
510 method_list.append(ICAP::methodStr(*iter));
511 method_list.append(" ", 1);
512 ++iter;
513 }
514
515 if (!method_found) {
516 debugs(93, DBG_IMPORTANT, "WARNING: Squid is configured to use ICAP method " <<
517 cfg().methodStr() <<
518 " for service " << cfg().uri <<
519 " but OPTIONS response declares the methods are " << method_list);
520 }
521 }
522
523 /*
524 * Check the ICAP server's date header for clock skew
525 */
526 const int skew = (int)(theOptions->timestamp() - squid_curtime);
527 if (abs(skew) > theOptions->ttl()) {
528 // TODO: If skew is negative, the option will be considered down
529 // because of stale options. We should probably change this.
530 debugs(93, DBG_IMPORTANT, "ICAP service's clock is skewed by " << skew <<
531 " seconds: " << cfg().uri);
532 }
533 }
534
535 void Adaptation::Icap::ServiceRep::announceStatusChange(const char *downPhrase, bool important) const
536 {
537 if (wasAnnouncedUp == up()) // no significant changes to announce
538 return;
539
540 const char *what = cfg().bypass ? "optional" : "essential";
541 const char *state = wasAnnouncedUp ? downPhrase : "up";
542 const int level = important ? 1 :2;
543 debugs(93,level, what << " ICAP service is " << state << ": " <<
544 cfg().uri << ' ' << status());
545
546 wasAnnouncedUp = !wasAnnouncedUp;
547 }
548
549 // we are receiving ICAP OPTIONS response headers here or NULL on failures
550 void Adaptation::Icap::ServiceRep::noteAdaptationAnswer(const Answer &answer)
551 {
552 Must(initiated(theOptionsFetcher));
553 clearAdaptation(theOptionsFetcher);
554
555 if (answer.kind == Answer::akError) {
556 debugs(93,3, HERE << "failed to fetch options " << status());
557 handleNewOptions(0);
558 return;
559 }
560
561 Must(answer.kind == Answer::akForward); // no akBlock for OPTIONS requests
562 const HttpMsg *msg = answer.message.getRaw();
563 Must(msg);
564
565 debugs(93,5, HERE << "is interpreting new options " << status());
566
567 Adaptation::Icap::Options *newOptions = NULL;
568 if (const HttpReply *r = dynamic_cast<const HttpReply*>(msg)) {
569 newOptions = new Adaptation::Icap::Options;
570 newOptions->configure(r);
571 } else {
572 debugs(93, DBG_IMPORTANT, "ICAP service got wrong options message " << status());
573 }
574
575 handleNewOptions(newOptions);
576 }
577
578 // we (a) must keep trying to get OPTIONS and (b) are RefCounted so we
579 // must keep our job alive (XXX: until nobody needs us)
580 void Adaptation::Icap::ServiceRep::callException(const std::exception &e)
581 {
582 clearAdaptation(theOptionsFetcher);
583 debugs(93,2, "ICAP probably failed to fetch options (" << e.what() <<
584 ")" << status());
585 handleNewOptions(0);
586 }
587
588 void Adaptation::Icap::ServiceRep::handleNewOptions(Adaptation::Icap::Options *newOptions)
589 {
590 // new options may be NULL
591 changeOptions(newOptions);
592
593 debugs(93,3, HERE << "got new options and is now " << status());
594
595 scheduleUpdate(optionsFetchTime());
596
597 // XXX: this whole feature bases on the false assumption a service only has one IP
598 setMaxConnections();
599 const int excess = excessConnections();
600 // if we owe connections and have idle pconns, close the latter
601 if (excess && theIdleConns->count() > 0) {
602 const int n = min(excess, theIdleConns->count());
603 debugs(93,5, HERE << "closing " << n << " pconns to relief debt");
604 theIdleConns->closeN(n);
605 }
606
607 scheduleNotification();
608 }
609
610 void Adaptation::Icap::ServiceRep::startGettingOptions()
611 {
612 Must(!theOptionsFetcher);
613 debugs(93,6, HERE << "will get new options " << status());
614
615 // XXX: "this" here is "self"; works until refcounting API changes
616 theOptionsFetcher = initiateAdaptation(
617 new Adaptation::Icap::OptXactLauncher(this));
618 // TODO: timeout in case Adaptation::Icap::OptXact never calls us back?
619 // Such a timeout should probably be a generic AsyncStart feature.
620 }
621
622 void Adaptation::Icap::ServiceRep::scheduleUpdate(time_t when)
623 {
624 if (updateScheduled) {
625 debugs(93,7, HERE << "reschedules update");
626 // XXX: check whether the event is there because AR saw
627 // an unreproducible eventDelete assertion on 2007/06/18
628 if (eventFind(&ServiceRep_noteTimeToUpdate, this))
629 eventDelete(&ServiceRep_noteTimeToUpdate, this);
630 else
631 debugs(93, DBG_IMPORTANT, "XXX: ICAP service lost an update event.");
632 updateScheduled = false;
633 }
634
635 debugs(93,7, HERE << "raw OPTIONS fetch at " << when << " or in " <<
636 (when - squid_curtime) << " sec");
637 debugs(93,9, HERE << "last fetched at " << theLastUpdate << " or " <<
638 (squid_curtime - theLastUpdate) << " sec ago");
639
640 /* adjust update time to prevent too-frequent updates */
641
642 if (when < squid_curtime)
643 when = squid_curtime;
644
645 // XXX: move hard-coded constants from here to Adaptation::Icap::TheConfig
646 const int minUpdateGap = 30; // seconds
647 if (when < theLastUpdate + minUpdateGap)
648 when = theLastUpdate + minUpdateGap;
649
650 const int delay = when - squid_curtime;
651 debugs(93,5, HERE << "will fetch OPTIONS in " << delay << " sec");
652
653 eventAdd("Adaptation::Icap::ServiceRep::noteTimeToUpdate",
654 &ServiceRep_noteTimeToUpdate, this, delay, 0, true);
655 updateScheduled = true;
656 }
657
658 // returns absolute time when OPTIONS should be fetched
659 time_t
660 Adaptation::Icap::ServiceRep::optionsFetchTime() const
661 {
662 if (theOptions && theOptions->valid()) {
663 const time_t expire = theOptions->expire();
664 debugs(93,7, HERE << "options expire on " << expire << " >= " << squid_curtime);
665
666 // conservative estimate of how long the OPTIONS transaction will take
667 // XXX: move hard-coded constants from here to Adaptation::Icap::TheConfig
668 const int expectedWait = 20; // seconds
669
670 // Unknown or invalid (too small) expiration times should not happen.
671 // Adaptation::Icap::Options should use the default TTL, and ICAP servers should not
672 // send invalid TTLs, but bugs and attacks happen.
673 if (expire < expectedWait)
674 return squid_curtime;
675 else
676 return expire - expectedWait; // before the current options expire
677 }
678
679 // use revival delay as "expiration" time for a service w/o valid options
680 return squid_curtime + TheConfig.service_revival_delay;
681 }
682
683 Adaptation::Initiate *
684 Adaptation::Icap::ServiceRep::makeXactLauncher(HttpMsg *virgin,
685 HttpRequest *cause, AccessLogEntry::Pointer &alp)
686 {
687 return new Adaptation::Icap::ModXactLauncher(virgin, cause, alp, this);
688 }
689
690 // returns a temporary string depicting service status, for debugging
691 const char *Adaptation::Icap::ServiceRep::status() const
692 {
693 static MemBuf buf;
694
695 buf.reset();
696 buf.append("[", 1);
697
698 if (up())
699 buf.append("up", 2);
700 else {
701 buf.append("down", 4);
702 if (isSuspended)
703 buf.append(",susp", 5);
704
705 if (!theOptions)
706 buf.append(",!opt", 5);
707 else if (!theOptions->valid())
708 buf.append(",!valid", 7);
709 else if (!theOptions->fresh())
710 buf.append(",stale", 6);
711 }
712
713 if (detached())
714 buf.append(",detached", 9);
715
716 if (theOptionsFetcher.set())
717 buf.append(",fetch", 6);
718
719 if (notifying)
720 buf.append(",notif", 6);
721
722 if (const int failures = theSessionFailures.remembered())
723 buf.appendf(",fail%d", failures);
724
725 buf.append("]", 1);
726 buf.terminate();
727
728 return buf.content();
729 }
730
731 void Adaptation::Icap::ServiceRep::detach()
732 {
733 debugs(93,3, HERE << "detaching ICAP service: " << cfg().uri <<
734 ' ' << status());
735 isDetached = true;
736 }
737
738 bool Adaptation::Icap::ServiceRep::detached() const
739 {
740 return isDetached;
741 }
742
743 Adaptation::Icap::ConnWaiterDialer::ConnWaiterDialer(const CbcPointer<Adaptation::Icap::ModXact> &xact,
744 Adaptation::Icap::ConnWaiterDialer::Parent::Method aHandler):
745 Parent(xact, aHandler)
746 {
747 theService = &xact->service();
748 theService->noteNewWaiter();
749 }
750
751 Adaptation::Icap::ConnWaiterDialer::ConnWaiterDialer(const Adaptation::Icap::ConnWaiterDialer &aConnWaiter): Parent(aConnWaiter)
752 {
753 theService = aConnWaiter.theService;
754 theService->noteNewWaiter();
755 }
756
757 Adaptation::Icap::ConnWaiterDialer::~ConnWaiterDialer()
758 {
759 theService->noteGoneWaiter();
760 }
761