]> git.ipfire.org Git - thirdparty/squid.git/blob - src/adaptation/ecap/MessageRep.h
Merged from trunk.
[thirdparty/squid.git] / src / adaptation / ecap / MessageRep.h
1
2 /*
3 * $Id$
4 */
5
6 #ifndef SQUID__ECAP__MESSAGE_REP_H
7 #define SQUID__ECAP__MESSAGE_REP_H
8
9 #include "config.h"
10 #include "HttpHeader.h"
11 #include "BodyPipe.h"
12 #include "adaptation/forward.h"
13 #include "adaptation/Message.h"
14 #include <libecap/common/message.h>
15 #include <libecap/common/header.h>
16 #include <libecap/common/body.h>
17
18 class HttpMsg;
19 class HttpRequest;
20 class HttpReply;
21
22 namespace Ecap
23 {
24
25 class XactionRep;
26
27 // Translates Squid HttpMsg into libecap::Header.
28 class HeaderRep: public libecap::Header
29 {
30 public:
31 typedef libecap::Name Name;
32 typedef libecap::Area Area;
33
34 public:
35 HeaderRep(HttpMsg &aMessage);
36
37 virtual bool hasAny(const Name &name) const;
38 virtual Value value(const Name &name) const;
39
40 virtual void add(const Name &name, const Value &value);
41 virtual void removeAny(const Name &name);
42
43 virtual Area image() const;
44 virtual void parse(const Area &buf); // throws on failures
45
46 protected:
47 static http_hdr_type TranslateHeaderId(const Name &name);
48
49 private:
50 HttpHeader &theHeader; // the header being translated to libecap
51 HttpMsg &theMessage; // the message being translated to libecap
52 };
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 protocol_t 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 virtual void uri(const Area &aUri);
87 virtual Area uri() const;
88
89 virtual void method(const Name &aMethod);
90 virtual Name method() const;
91
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
97 private:
98 HttpRequest &theMessage; // the request header being translated to libecap
99 };
100
101 // Translates Squid HttpReply into libecap::StatusLine.
102 class StatusLineRep: public libecap::StatusLine, public FirstLineRep
103 {
104 public:
105 typedef libecap::Name Name;
106 typedef libecap::Area Area;
107
108 public:
109 StatusLineRep(HttpReply &aMessage);
110
111 virtual void statusCode(int code);
112 virtual int statusCode() const;
113
114 virtual void reasonPhrase(const Area &phrase);
115 virtual Area reasonPhrase() const;
116
117 virtual libecap::Version version() const;
118 virtual void version(const libecap::Version &aVersion);
119 virtual Name protocol() const;
120 virtual void protocol(const Name &aProtocol);
121
122 private:
123 HttpReply &theMessage; // the request header being translated to libecap
124 };
125
126
127 // Translates Squid BodyPipe into libecap::Body.
128 class BodyRep: public libecap::Body
129 {
130 public:
131 typedef libecap::BodySize BodySize;
132
133 public:
134 BodyRep(const BodyPipe::Pointer &aBody); // using NULL pointer? see tie()
135
136 void tie(const BodyPipe::Pointer &aBody); // late binding if !theBody;
137
138 // libecap::Body API
139 virtual BodySize bodySize() const;
140
141 private:
142 BodyPipe::Pointer theBody; // the body being translated to libecap
143 };
144
145 // Translates Squid Adaptation::Message into libecap::Message.
146 class MessageRep: public libecap::Message
147 {
148 public:
149 explicit MessageRep(HttpMsg *rawHeader);
150 virtual ~MessageRep();
151
152 virtual libecap::shared_ptr<libecap::Message> clone() const;
153
154 virtual libecap::FirstLine &firstLine();
155 virtual const libecap::FirstLine &firstLine() const;
156
157 virtual libecap::Header &header();
158 virtual const libecap::Header &header() const;
159
160 virtual void addBody();
161 virtual libecap::Body *body();
162 virtual const libecap::Body *body() const;
163 void tieBody(Ecap::XactionRep *x); // to a specific transaction
164
165 Adaptation::Message &raw() { return theMessage; } // for host access
166 const Adaptation::Message &raw() const { return theMessage; } // for host
167
168 private:
169 Adaptation::Message theMessage; // the message being translated to libecap
170 libecap::FirstLine *theFirstLineRep; // request or status line wrapper
171 HeaderRep *theHeaderRep; // header wrapper
172 BodyRep *theBodyRep; // body wrapper
173 };
174
175 } // namespace Ecap;
176
177 #endif /* SQUID__E_CAP__MESSAGE_REP_H */