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