]> git.ipfire.org Git - thirdparty/squid.git/blob - src/adaptation/ecap/Host.cc
Update PROTO_CACHEOBJ to PROTO_CACHE_OBJECT name
[thirdparty/squid.git] / src / adaptation / ecap / Host.cc
1 /*
2 * DEBUG: section 93 eCAP Interface
3 */
4 #include "squid.h"
5 #include <libecap/adapter/service.h>
6 #include <libecap/common/names.h>
7 #include <libecap/common/registry.h>
8 #include "base/TextException.h"
9 #include "adaptation/ecap/ServiceRep.h"
10 #include "adaptation/ecap/Host.h"
11 #include "adaptation/ecap/MessageRep.h"
12 #include "HttpRequest.h"
13 #include "HttpReply.h"
14
15 const libecap::Name Adaptation::Ecap::protocolInternal("internal", libecap::Name::NextId());
16 const libecap::Name Adaptation::Ecap::protocolCacheObj("cache_object", libecap::Name::NextId());
17 const libecap::Name Adaptation::Ecap::protocolIcp("ICP", libecap::Name::NextId());
18 #if USE_HTCP
19 const libecap::Name Adaptation::Ecap::protocolHtcp("Htcp", libecap::Name::NextId());
20 #endif
21
22 /// the host application (i.e., Squid) wrapper registered with libecap
23 static libecap::shared_ptr<Adaptation::Ecap::Host> TheHost;
24
25 Adaptation::Ecap::Host::Host()
26 {
27 // assign our host-specific IDs to well-known names
28 // this code can run only once
29
30 libecap::headerReferer.assignHostId(HDR_REFERER);
31 libecap::headerContentLength.assignHostId(HDR_CONTENT_LENGTH);
32
33 libecap::protocolHttp.assignHostId(AnyP::PROTO_HTTP);
34 libecap::protocolHttps.assignHostId(AnyP::PROTO_HTTPS);
35 libecap::protocolFtp.assignHostId(AnyP::PROTO_FTP);
36 libecap::protocolGopher.assignHostId(AnyP::PROTO_GOPHER);
37 libecap::protocolWais.assignHostId(AnyP::PROTO_WAIS);
38 libecap::protocolUrn.assignHostId(AnyP::PROTO_URN);
39 libecap::protocolWhois.assignHostId(AnyP::PROTO_WHOIS);
40 protocolInternal.assignHostId(AnyP::PROTO_INTERNAL);
41 protocolCacheObj.assignHostId(AnyP::PROTO_CACHE_OBJECT);
42 protocolIcp.assignHostId(AnyP::PROTO_ICP);
43 #if USE_HTCP
44 protocolHtcp.assignHostId(AnyP::PROTO_HTCP);
45 #endif
46 }
47
48 std::string
49 Adaptation::Ecap::Host::uri() const
50 {
51 return "ecap://squid-cache.org/ecap/hosts/squid";
52 }
53
54 void
55 Adaptation::Ecap::Host::describe(std::ostream &os) const
56 {
57 os << PACKAGE_NAME << " v" << PACKAGE_VERSION;
58 }
59
60 void
61 Adaptation::Ecap::Host::noteService(const libecap::weak_ptr<libecap::adapter::Service> &weak)
62 {
63 Must(!weak.expired());
64 RegisterAdapterService(weak.lock());
65 }
66
67 static int
68 SquidLogLevel(libecap::LogVerbosity lv)
69 {
70 if (lv.critical())
71 return DBG_CRITICAL; // is it a good idea to ignore other flags?
72
73 if (lv.large())
74 return DBG_DATA; // is it a good idea to ignore other flags?
75
76 if (lv.application())
77 return DBG_DATA; // is it a good idea to ignore other flags?
78
79 return 2 + 2*lv.debugging() + 3*lv.operation() + 2*lv.xaction();
80 }
81
82 std::ostream *
83 Adaptation::Ecap::Host::openDebug(libecap::LogVerbosity lv)
84 {
85 const int squidLevel = SquidLogLevel(lv);
86 const int squidSection = 93; // XXX: this should be a global constant
87 // XXX: Debug.h should provide this to us
88 if ((Debug::level = squidLevel) <= Debug::Levels[squidSection])
89 return &Debug::getDebugOut();
90 else
91 return NULL;
92 }
93
94 void
95 Adaptation::Ecap::Host::closeDebug(std::ostream *debug)
96 {
97 if (debug)
98 Debug::finishDebug();
99 }
100
101
102 Adaptation::Ecap::Host::MessagePtr
103 Adaptation::Ecap::Host::newRequest() const
104 {
105 return MessagePtr(new Adaptation::Ecap::MessageRep(new HttpRequest));
106 }
107
108 Adaptation::Ecap::Host::MessagePtr
109 Adaptation::Ecap::Host::newResponse() const
110 {
111 return MessagePtr(new Adaptation::Ecap::MessageRep(new HttpReply));
112 }
113
114 void
115 Adaptation::Ecap::Host::Register()
116 {
117 if (!TheHost) {
118 TheHost.reset(new Adaptation::Ecap::Host);
119 libecap::RegisterHost(TheHost);
120 }
121 }