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