]> git.ipfire.org Git - thirdparty/squid.git/blob - src/adaptation/ecap/MessageRep.h
Merge from trunk
[thirdparty/squid.git] / src / adaptation / ecap / MessageRep.h
1 /*
2 * $Id$
3 * DEBUG: section 93 eCAP Interface
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
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
39 virtual bool hasAny(const Name &name) const;
40 virtual Value value(const Name &name) const;
41
42 virtual void add(const Name &name, const Value &value);
43 virtual void removeAny(const Name &name);
44
45 virtual Area image() const;
46 virtual void parse(const Area &buf); // throws on failures
47
48 protected:
49 static http_hdr_type TranslateHeaderId(const Name &name);
50
51 private:
52 HttpHeader &theHeader; // the header being translated to libecap
53 HttpMsg &theMessage; // the message being translated to libecap
54 };
55
56
57 // Helps translate Squid HttpMsg into libecap::FirstLine (see children).
58 class FirstLineRep
59 {
60 public:
61 typedef libecap::Name Name;
62
63 public:
64 FirstLineRep(HttpMsg &aMessage);
65
66 libecap::Version version() const;
67 void version(const libecap::Version &aVersion);
68 Name protocol() const;
69 void protocol(const Name &aProtocol);
70
71 protected:
72 static protocol_t TranslateProtocolId(const Name &name);
73
74 private:
75 HttpMsg &theMessage; // the message which first line is being translated
76 };
77
78 // Translates Squid HttpRequest into libecap::RequestLine.
79 class RequestLineRep: public libecap::RequestLine, public FirstLineRep
80 {
81 public:
82 // typedef libecap::Name Name;
83 typedef libecap::Area Area;
84
85 public:
86 RequestLineRep(HttpRequest &aMessage);
87
88 virtual void uri(const Area &aUri);
89 virtual Area uri() const;
90
91 virtual void method(const Name &aMethod);
92 virtual Name method() const;
93
94 virtual libecap::Version version() const;
95 virtual void version(const libecap::Version &aVersion);
96 virtual Name protocol() const;
97 virtual void protocol(const Name &aProtocol);
98
99 private:
100 HttpRequest &theMessage; // the request header being translated to libecap
101 };
102
103 // Translates Squid HttpReply into libecap::StatusLine.
104 class StatusLineRep: public libecap::StatusLine, public FirstLineRep
105 {
106 public:
107 typedef libecap::Name Name;
108 typedef libecap::Area Area;
109
110 public:
111 StatusLineRep(HttpReply &aMessage);
112
113 virtual void statusCode(int code);
114 virtual int statusCode() const;
115
116 virtual void reasonPhrase(const Area &phrase);
117 virtual Area reasonPhrase() const;
118
119 virtual libecap::Version version() const;
120 virtual void version(const libecap::Version &aVersion);
121 virtual Name protocol() const;
122 virtual void protocol(const Name &aProtocol);
123
124 private:
125 HttpReply &theMessage; // the request header being translated to libecap
126 };
127
128
129 // Translates Squid BodyPipe into libecap::Body.
130 class BodyRep: public libecap::Body
131 {
132 public:
133 typedef libecap::BodySize BodySize;
134
135 public:
136 BodyRep(const BodyPipe::Pointer &aBody); // using NULL pointer? see tie()
137
138 void tie(const BodyPipe::Pointer &aBody); // late binding if !theBody;
139
140 // libecap::Body API
141 virtual BodySize bodySize() const;
142
143 private:
144 BodyPipe::Pointer theBody; // the body being translated to libecap
145 };
146
147 // Translates Squid Adaptation::Message into libecap::Message.
148 class MessageRep: public libecap::Message
149 {
150 public:
151 explicit MessageRep(HttpMsg *rawHeader);
152 virtual ~MessageRep();
153
154 virtual libecap::shared_ptr<libecap::Message> clone() const;
155
156 virtual libecap::FirstLine &firstLine();
157 virtual const libecap::FirstLine &firstLine() const;
158
159 virtual libecap::Header &header();
160 virtual const libecap::Header &header() const;
161
162 virtual void addBody();
163 virtual libecap::Body *body();
164 virtual const libecap::Body *body() const;
165 void tieBody(Ecap::XactionRep *x); // to a specific transaction
166
167 Adaptation::Message &raw() { return theMessage; } // for host access
168 const Adaptation::Message &raw() const { return theMessage; } // for host
169
170 private:
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
175 };
176
177 } // namespace Ecap
178 } // namespace Adaptation
179
180 #endif /* SQUID__E_CAP__MESSAGE_REP_H */