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