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