]> git.ipfire.org Git - thirdparty/squid.git/blame - src/adaptation/Service.cc
Source Format Enforcement (#532)
[thirdparty/squid.git] / src / adaptation / Service.cc
CommitLineData
a68cf076 1/*
77b1029d 2 * Copyright (C) 1996-2020 The Squid Software Foundation and contributors
bbc27441
AJ
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.
a68cf076
AR
7 */
8
bbc27441
AJ
9/* DEBUG: section 93 Adaptation */
10
582c2af2 11#include "squid.h"
a68cf076 12#include "adaptation/Service.h"
602d9612
A
13#include "adaptation/ServiceFilter.h"
14#include "HttpRequest.h"
a68cf076 15
6666da11 16Adaptation::Service::Service(const ServiceConfigPointer &aConfig): theConfig(aConfig)
a5c0ca41 17{
e1e90d26
AR
18 Must(theConfig != NULL);
19 debugs(93,3, HERE << "creating adaptation service " << cfg().key);
a5c0ca41 20}
a68cf076
AR
21
22Adaptation::Service::~Service()
23{}
24
62c7f90e 25void
d81a31f1 26Adaptation::Service::finalize()
a68cf076 27{
62c7f90e
AR
28}
29
201438ac
AR
30bool Adaptation::Service::broken() const
31{
32 return probed() && !up();
33}
34
a22e6cd3
AR
35bool
36Adaptation::Service::wants(const ServiceFilter &filter) const
37{
38 if (cfg().method != filter.method)
39 return false;
40
41 if (cfg().point != filter.point)
42 return false;
43
44 // sending a message to a broken service is likely to cause errors
45 if (cfg().bypass && broken())
46 return false;
47
48 if (up()) {
49 // Sending a message to a service that does not want it is useless.
50 // note that we cannot check wantsUrl for service that is not "up"
51 // note that even essential services are skipped on unwanted URLs!
51b5dcf5 52 return wantsUrl(filter.request->url.path());
a22e6cd3
AR
53 }
54
55 // The service is down and is either not bypassable or not probed due
56 // to the bypass && broken() test above. Thus, we want to use it!
57 return true;
58}
59
62c7f90e
AR
60Adaptation::Services &
61Adaptation::AllServices()
62{
28b58ffc
CT
63 static Services *TheServices = new Services;
64 return *TheServices;
62c7f90e
AR
65}
66
67Adaptation::ServicePointer
68Adaptation::FindService(const Service::Id& key)
69{
70 typedef Services::iterator SI;
71 for (SI i = AllServices().begin(); i != AllServices().end(); ++i) {
72 if ((*i)->cfg().key == key)
73 return *i;
26ac0430 74 }
62c7f90e 75 return NULL;
a68cf076 76}
76fc7e57
AJ
77
78void Adaptation::DetachServices()
79{
38c22baf
FC
80 while (!AllServices().empty()) {
81 AllServices().back()->detach();
82 AllServices().pop_back();
83 }
76fc7e57 84}
f53969cc 85