]>
Commit | Line | Data |
---|---|---|
fdc96a39 AR |
1 | /* |
2 | * $Id$ | |
b510f3a1 | 3 | * DEBUG: section 93 eCAP Interface |
fdc96a39 AR |
4 | */ |
5 | ||
7b67e5b6 AR |
6 | #ifndef SQUID__ECAP__MESSAGE_REP_H |
7 | #define SQUID__ECAP__MESSAGE_REP_H | |
fdc96a39 | 8 | |
1f3c65fc AR |
9 | #include "HttpHeader.h" |
10 | #include "BodyPipe.h" | |
fdc96a39 | 11 | #include "adaptation/forward.h" |
1f3c65fc | 12 | #include "adaptation/Message.h" |
555aedbf | 13 | #include "anyp/ProtocolType.h" |
fdc96a39 | 14 | #include <libecap/common/message.h> |
cf331c99 AR |
15 | #include <libecap/common/header.h> |
16 | #include <libecap/common/body.h> | |
fdc96a39 | 17 | |
1f3c65fc AR |
18 | class HttpMsg; |
19 | class HttpRequest; | |
20 | class HttpReply; | |
21 | ||
af6a12ee AJ |
22 | namespace Adaptation |
23 | { | |
e1381638 AJ |
24 | namespace Ecap |
25 | { | |
fdc96a39 | 26 | |
cf331c99 AR |
27 | class XactionRep; |
28 | ||
29 | // Translates Squid HttpMsg into libecap::Header. | |
30 | class HeaderRep: public libecap::Header | |
31 | { | |
32 | public: | |
33 | typedef libecap::Name Name; | |
34 | typedef libecap::Area Area; | |
35 | ||
36 | public: | |
37 | HeaderRep(HttpMsg &aMessage); | |
38 | ||
8442a9b2 | 39 | /* libecap::Header API */ |
cf331c99 AR |
40 | virtual bool hasAny(const Name &name) const; |
41 | virtual Value value(const Name &name) const; | |
cf331c99 AR |
42 | virtual void add(const Name &name, const Value &value); |
43 | virtual void removeAny(const Name &name); | |
12a410c3 | 44 | virtual void visitEach(libecap::NamedValueVisitor &visitor) const; |
cf331c99 AR |
45 | virtual Area image() const; |
46 | virtual void parse(const Area &buf); // throws on failures | |
47 | ||
cf331c99 AR |
48 | protected: |
49 | static http_hdr_type TranslateHeaderId(const Name &name); | |
cf331c99 AR |
50 | |
51 | private: | |
52 | HttpHeader &theHeader; // the header being translated to libecap | |
53 | HttpMsg &theMessage; // the message being translated to libecap | |
54 | }; | |
55 | ||
77773405 AR |
56 | // Helps translate Squid HttpMsg into libecap::FirstLine (see children). |
57 | class FirstLineRep | |
cf331c99 AR |
58 | { |
59 | public: | |
77773405 AR |
60 | typedef libecap::Name Name; |
61 | ||
62 | public: | |
63 | FirstLineRep(HttpMsg &aMessage); | |
64 | ||
65 | libecap::Version version() const; | |
66 | void version(const libecap::Version &aVersion); | |
67 | Name protocol() const; | |
68 | void protocol(const Name &aProtocol); | |
69 | ||
70 | protected: | |
555aedbf | 71 | static AnyP::ProtocolType TranslateProtocolId(const Name &name); |
77773405 AR |
72 | |
73 | private: | |
74 | HttpMsg &theMessage; // the message which first line is being translated | |
75 | }; | |
76 | ||
77 | // Translates Squid HttpRequest into libecap::RequestLine. | |
78 | class RequestLineRep: public libecap::RequestLine, public FirstLineRep | |
79 | { | |
80 | public: | |
81 | // typedef libecap::Name Name; | |
82 | typedef libecap::Area Area; | |
83 | ||
84 | public: | |
85 | RequestLineRep(HttpRequest &aMessage); | |
cf331c99 | 86 | |
8442a9b2 | 87 | /* libecap::RequestLine API */ |
cf331c99 AR |
88 | virtual void uri(const Area &aUri); |
89 | virtual Area uri() const; | |
cf331c99 AR |
90 | virtual void method(const Name &aMethod); |
91 | virtual Name method() const; | |
77773405 AR |
92 | virtual libecap::Version version() const; |
93 | virtual void version(const libecap::Version &aVersion); | |
94 | virtual Name protocol() const; | |
95 | virtual void protocol(const Name &aProtocol); | |
96 | ||
cf331c99 AR |
97 | private: |
98 | HttpRequest &theMessage; // the request header being translated to libecap | |
99 | }; | |
100 | ||
77773405 AR |
101 | // Translates Squid HttpReply into libecap::StatusLine. |
102 | class StatusLineRep: public libecap::StatusLine, public FirstLineRep | |
cf331c99 AR |
103 | { |
104 | public: | |
77773405 AR |
105 | typedef libecap::Name Name; |
106 | typedef libecap::Area Area; | |
107 | ||
108 | public: | |
109 | StatusLineRep(HttpReply &aMessage); | |
cf331c99 | 110 | |
8442a9b2 | 111 | /* libecap::StatusLine API */ |
cf331c99 AR |
112 | virtual void statusCode(int code); |
113 | virtual int statusCode() const; | |
cf331c99 AR |
114 | virtual void reasonPhrase(const Area &phrase); |
115 | virtual Area reasonPhrase() const; | |
77773405 AR |
116 | virtual libecap::Version version() const; |
117 | virtual void version(const libecap::Version &aVersion); | |
118 | virtual Name protocol() const; | |
119 | virtual void protocol(const Name &aProtocol); | |
120 | ||
cf331c99 AR |
121 | private: |
122 | HttpReply &theMessage; // the request header being translated to libecap | |
123 | }; | |
124 | ||
77773405 | 125 | // Translates Squid BodyPipe into libecap::Body. |
cf331c99 AR |
126 | class BodyRep: public libecap::Body |
127 | { | |
128 | public: | |
cf331c99 AR |
129 | typedef libecap::BodySize BodySize; |
130 | ||
131 | public: | |
77773405 | 132 | BodyRep(const BodyPipe::Pointer &aBody); // using NULL pointer? see tie() |
cf331c99 | 133 | |
77773405 AR |
134 | void tie(const BodyPipe::Pointer &aBody); // late binding if !theBody; |
135 | ||
136 | // libecap::Body API | |
cf331c99 | 137 | virtual BodySize bodySize() const; |
cf331c99 AR |
138 | |
139 | private: | |
140 | BodyPipe::Pointer theBody; // the body being translated to libecap | |
141 | }; | |
142 | ||
fdc96a39 | 143 | // Translates Squid Adaptation::Message into libecap::Message. |
7b67e5b6 | 144 | class MessageRep: public libecap::Message |
fdc96a39 | 145 | { |
fdc96a39 | 146 | public: |
77773405 | 147 | explicit MessageRep(HttpMsg *rawHeader); |
cf331c99 AR |
148 | virtual ~MessageRep(); |
149 | ||
8442a9b2 | 150 | /* libecap::Message API */ |
f1a768b2 | 151 | virtual libecap::shared_ptr<libecap::Message> clone() const; |
f1a768b2 AR |
152 | virtual libecap::FirstLine &firstLine(); |
153 | virtual const libecap::FirstLine &firstLine() const; | |
cf331c99 AR |
154 | virtual libecap::Header &header(); |
155 | virtual const libecap::Header &header() const; | |
cf331c99 AR |
156 | virtual void addBody(); |
157 | virtual libecap::Body *body(); | |
158 | virtual const libecap::Body *body() const; | |
8442a9b2 | 159 | |
f1a768b2 | 160 | void tieBody(Ecap::XactionRep *x); // to a specific transaction |
77773405 | 161 | |
f1a768b2 AR |
162 | Adaptation::Message &raw() { return theMessage; } // for host access |
163 | const Adaptation::Message &raw() const { return theMessage; } // for host | |
fdc96a39 AR |
164 | |
165 | private: | |
77773405 AR |
166 | Adaptation::Message theMessage; // the message being translated to libecap |
167 | libecap::FirstLine *theFirstLineRep; // request or status line wrapper | |
168 | HeaderRep *theHeaderRep; // header wrapper | |
169 | BodyRep *theBodyRep; // body wrapper | |
fdc96a39 AR |
170 | }; |
171 | ||
574b508c AR |
172 | } // namespace Ecap |
173 | } // namespace Adaptation | |
fdc96a39 | 174 | |
7b67e5b6 | 175 | #endif /* SQUID__E_CAP__MESSAGE_REP_H */ |