]> git.ipfire.org Git - thirdparty/squid.git/blame - src/eCAP/Host.cc
Updates for running on squid-cache.org
[thirdparty/squid.git] / src / eCAP / Host.cc
CommitLineData
fdc96a39
AR
1#include "squid.h"
2#include <libecap/adapter/service.h>
530f96dd 3#include <libecap/common/names.h>
fdc96a39
AR
4#include "TextException.h"
5#include "eCAP/ServiceRep.h"
6#include "eCAP/Host.h"
7
530f96dd
AR
8const libecap::Name Ecap::protocolInternal("internal", libecap::Name::NextId());
9const libecap::Name Ecap::protocolCacheObj("cache_object", libecap::Name::NextId());
10const libecap::Name Ecap::protocolIcp("ICP", libecap::Name::NextId());
11#if USE_HTCP
12const libecap::Name Ecap::protocolHtcp("Htcp", libecap::Name::NextId());
13#endif
14
15Ecap::Host::Host()
16{
17 // assign our host-specific IDs to well-known names
18 libecap::headerReferer.assignHostId(HDR_REFERER);
19
20 libecap::protocolHttp.assignHostId(PROTO_HTTP);
21 libecap::protocolHttps.assignHostId(PROTO_HTTPS);
22 libecap::protocolFtp.assignHostId(PROTO_FTP);
23 libecap::protocolGopher.assignHostId(PROTO_GOPHER);
24 libecap::protocolWais.assignHostId(PROTO_WAIS);
25 libecap::protocolUrn.assignHostId(PROTO_URN);
26 libecap::protocolWhois.assignHostId(PROTO_WHOIS);
27 protocolInternal.assignHostId(PROTO_INTERNAL);
28 protocolCacheObj.assignHostId(PROTO_CACHEOBJ);
29 protocolIcp.assignHostId(PROTO_ICP);
30#if USE_HTCP
31 protocolHtcp.assignHostId(PROTO_HTCP);
32#endif
33}
fdc96a39
AR
34
35std::string
36Ecap::Host::uri() const
37{
38 return "ecap://squid-cache.org/ecap/hosts/squid";
39}
40
41void
42Ecap::Host::describe(std::ostream &os) const
43{
44 os << PACKAGE_NAME << " v" << PACKAGE_VERSION;
45}
46
47void
48Ecap::Host::noteService(const libecap::weak_ptr<libecap::adapter::Service> &weak)
49{
50 // Many ecap_service lines may use the same service URI. Find each
51 // matching service rep, make sure it is an eCAP rep,
52 // and update it with the actual eCAP service.
53 int found = 0;
54
55 libecap::shared_ptr<libecap::adapter::Service> shared(weak);
56 typedef Adaptation::Services::iterator SI;
57 for (SI i = Adaptation::AllServices().begin(); i != Adaptation::AllServices().end(); ++i) {
58 if ((*i)->cfg().uri == shared->uri().c_str()) {
59 ServiceRep *rep = dynamic_cast<ServiceRep*>(i->getRaw());
60 Must(rep);
61 rep->noteService(shared);
62 ++found;
63 }
64 }
65
66 debugs(93,5, "Found " << found << " ecap_service configs for " <<
67 shared->uri());
68 if (!found) {
69 debugs(93,1, "Warning: ignoring loaded eCAP module service without " <<
70 "a matching ecap_service configuration: " << shared->uri());
71 }
72}
73
74static int
75SquidLogLevel(libecap::LogVerbosity lv)
76{
77 if (lv.critical())
78 return DBG_CRITICAL; // is it a good idea to ignore other flags?
79
80 if (lv.large())
81 return DBG_DATA; // is it a good idea to ignore other flags?
82
83 if (lv.application())
84 return DBG_DATA; // is it a good idea to ignore other flags?
85
86 return 2 + 2*lv.debugging() + 3*lv.operation() + 2*lv.xaction();
87}
88
89std::ostream *
90Ecap::Host::openDebug(libecap::LogVerbosity lv)
91{
92 const int squidLevel = SquidLogLevel(lv);
93 const int squidSection = 93; // XXX: this should be a global constant
94 // XXX: Debug.h should provide this to us
95 if ((Debug::level = squidLevel) <= Debug::Levels[squidSection])
96 return &Debug::getDebugOut();
97 else
98 return NULL;
99}
100
101void
102Ecap::Host::closeDebug(std::ostream *debug)
103{
104 if (debug)
105 Debug::finishDebug();
106}