]> 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 Adaptation
23 {
24 namespace Ecap {
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 virtual bool hasAny(const Name &name) const;
39 virtual Value value(const Name &name) const;
40
41 virtual void add(const Name &name, const Value &value);
42 virtual void removeAny(const Name &name);
43
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
56 // Helps translate Squid HttpMsg into libecap::FirstLine (see children).
57 class FirstLineRep
58 {
59 public:
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:
71 static protocol_t TranslateProtocolId(const Name &name);
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);
86
87 virtual void uri(const Area &aUri);
88 virtual Area uri() const;
89
90 virtual void method(const Name &aMethod);
91 virtual Name method() const;
92
93 virtual libecap::Version version() const;
94 virtual void version(const libecap::Version &aVersion);
95 virtual Name protocol() const;
96 virtual void protocol(const Name &aProtocol);
97
98 private:
99 HttpRequest &theMessage; // the request header being translated to libecap
100 };
101
102 // Translates Squid HttpReply into libecap::StatusLine.
103 class StatusLineRep: public libecap::StatusLine, public FirstLineRep
104 {
105 public:
106 typedef libecap::Name Name;
107 typedef libecap::Area Area;
108
109 public:
110 StatusLineRep(HttpReply &aMessage);
111
112 virtual void statusCode(int code);
113 virtual int statusCode() const;
114
115 virtual void reasonPhrase(const Area &phrase);
116 virtual Area reasonPhrase() const;
117
118 virtual libecap::Version version() const;
119 virtual void version(const libecap::Version &aVersion);
120 virtual Name protocol() const;
121 virtual void protocol(const Name &aProtocol);
122
123 private:
124 HttpReply &theMessage; // the request header being translated to libecap
125 };
126
127
128 // Translates Squid BodyPipe into libecap::Body.
129 class BodyRep: public libecap::Body
130 {
131 public:
132 typedef libecap::BodySize BodySize;
133
134 public:
135 BodyRep(const BodyPipe::Pointer &aBody); // using NULL pointer? see tie()
136
137 void tie(const BodyPipe::Pointer &aBody); // late binding if !theBody;
138
139 // libecap::Body API
140 virtual BodySize bodySize() const;
141
142 private:
143 BodyPipe::Pointer theBody; // the body being translated to libecap
144 };
145
146 // Translates Squid Adaptation::Message into libecap::Message.
147 class MessageRep: public libecap::Message
148 {
149 public:
150 explicit MessageRep(HttpMsg *rawHeader);
151 virtual ~MessageRep();
152
153 virtual libecap::shared_ptr<libecap::Message> clone() const;
154
155 virtual libecap::FirstLine &firstLine();
156 virtual const libecap::FirstLine &firstLine() const;
157
158 virtual libecap::Header &header();
159 virtual const libecap::Header &header() const;
160
161 virtual void addBody();
162 virtual libecap::Body *body();
163 virtual const libecap::Body *body() const;
164 void tieBody(Ecap::XactionRep *x); // to a specific transaction
165
166 Adaptation::Message &raw() { return theMessage; } // for host access
167 const Adaptation::Message &raw() const { return theMessage; } // for host
168
169 private:
170 Adaptation::Message theMessage; // the message being translated to libecap
171 libecap::FirstLine *theFirstLineRep; // request or status line wrapper
172 HeaderRep *theHeaderRep; // header wrapper
173 BodyRep *theBodyRep; // body wrapper
174 };
175
176 } // namespace Ecap
177 } // namespace Adaptation
178
179 #endif /* SQUID__E_CAP__MESSAGE_REP_H */