]>
git.ipfire.org Git - thirdparty/squid.git/blob - src/adaptation/ecap/Host.cc
2 * DEBUG: section 93 eCAP Interface
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"
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());
19 const libecap::Name
Adaptation::Ecap::protocolHtcp("Htcp", libecap::Name::NextId());
22 /// the host application (i.e., Squid) wrapper registered with libecap
23 static libecap::shared_ptr
<Adaptation::Ecap::Host
> TheHost
;
25 Adaptation::Ecap::Host::Host()
27 // assign our host-specific IDs to well-known names
28 // this code can run only once
30 libecap::headerContentLength
.assignHostId(HDR_CONTENT_LENGTH
);
31 libecap::headerTransferEncoding
.assignHostId(HDR_TRANSFER_ENCODING
);
32 libecap::headerReferer
.assignHostId(HDR_REFERER
);
33 libecap::headerVia
.assignHostId(HDR_VIA
);
34 // TODO: libecap::headerXClientIp.assignHostId(HDR_X_CLIENT_IP);
35 // TODO: libecap::headerXServerIp.assignHostId(HDR_X_SERVER_IP);
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
);
48 protocolHtcp
.assignHostId(PROTO_HTCP
);
53 Adaptation::Ecap::Host::uri() const
55 return "ecap://squid-cache.org/ecap/hosts/squid";
59 Adaptation::Ecap::Host::describe(std::ostream
&os
) const
61 os
<< PACKAGE_NAME
<< " v" << PACKAGE_VERSION
;
65 Adaptation::Ecap::Host::noteService(const libecap::weak_ptr
<libecap::adapter::Service
> &weak
)
67 Must(!weak
.expired());
68 RegisterAdapterService(weak
.lock());
72 SquidLogLevel(libecap::LogVerbosity lv
)
75 return DBG_CRITICAL
; // is it a good idea to ignore other flags?
78 return DBG_DATA
; // is it a good idea to ignore other flags?
81 return DBG_IMPORTANT
; // is it a good idea to ignore other flags?
83 return 2 + 2*lv
.debugging() + 3*lv
.operation() + 2*lv
.xaction();
87 Adaptation::Ecap::Host::openDebug(libecap::LogVerbosity lv
)
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
92 if ((Debug::level
= squidLevel
) <= Debug::Levels
[squidSection
])
93 return &Debug::getDebugOut();
99 Adaptation::Ecap::Host::closeDebug(std::ostream
*debug
)
102 Debug::finishDebug();
106 Adaptation::Ecap::Host::MessagePtr
107 Adaptation::Ecap::Host::newRequest() const
109 return MessagePtr(new Adaptation::Ecap::MessageRep(new HttpRequest
));
112 Adaptation::Ecap::Host::MessagePtr
113 Adaptation::Ecap::Host::newResponse() const
115 return MessagePtr(new Adaptation::Ecap::MessageRep(new HttpReply
));
119 Adaptation::Ecap::Host::Register()
122 TheHost
.reset(new Adaptation::Ecap::Host
);
123 libecap::RegisterHost(TheHost
);