]> 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 * Copyright (C) 1996-2017 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.
7 */
8
9 /* DEBUG: section 93 eCAP Interface */
10
11 #ifndef SQUID__ECAP__MESSAGE_REP_H
12 #define SQUID__ECAP__MESSAGE_REP_H
13
14 #include "adaptation/forward.h"
15 #include "adaptation/Message.h"
16 #include "anyp/ProtocolType.h"
17 #include "BodyPipe.h"
18 #include "HttpHeader.h"
19 #include <libecap/common/message.h>
20 #include <libecap/common/header.h>
21 #include <libecap/common/body.h>
22
23 class HttpMsg;
24 class HttpRequest;
25 class HttpReply;
26
27 namespace Adaptation
28 {
29 namespace Ecap
30 {
31
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
44 /* libecap::Header API */
45 virtual bool hasAny(const Name &name) const;
46 virtual Value value(const Name &name) const;
47 virtual void add(const Name &name, const Value &value);
48 virtual void removeAny(const Name &name);
49 virtual void visitEach(libecap::NamedValueVisitor &visitor) const;
50 virtual Area image() const;
51 virtual void parse(const Area &buf); // throws on failures
52
53 protected:
54 static Http::HdrType TranslateHeaderId(const Name &name);
55
56 private:
57 HttpHeader &theHeader; // the header being translated to libecap
58 HttpMsg &theMessage; // the message being translated to libecap
59 };
60
61 // Helps translate Squid HttpMsg into libecap::FirstLine (see children).
62 class FirstLineRep
63 {
64 public:
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:
76 static AnyP::ProtocolType TranslateProtocolId(const Name &name);
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);
91
92 /* libecap::RequestLine API */
93 virtual void uri(const Area &aUri);
94 virtual Area uri() const;
95 virtual void method(const Name &aMethod);
96 virtual Name method() const;
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
102 private:
103 HttpRequest &theMessage; // the request header being translated to libecap
104 };
105
106 // Translates Squid HttpReply into libecap::StatusLine.
107 class StatusLineRep: public libecap::StatusLine, public FirstLineRep
108 {
109 public:
110 typedef libecap::Name Name;
111 typedef libecap::Area Area;
112
113 public:
114 StatusLineRep(HttpReply &aMessage);
115
116 /* libecap::StatusLine API */
117 virtual void statusCode(int code);
118 virtual int statusCode() const;
119 virtual void reasonPhrase(const Area &phrase);
120 virtual Area reasonPhrase() const;
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
126 private:
127 HttpReply &theMessage; // the request header being translated to libecap
128 };
129
130 // Translates Squid BodyPipe into libecap::Body.
131 class BodyRep: public libecap::Body
132 {
133 public:
134 typedef libecap::BodySize BodySize;
135
136 public:
137 BodyRep(const BodyPipe::Pointer &aBody); // using NULL pointer? see tie()
138
139 void tie(const BodyPipe::Pointer &aBody); // late binding if !theBody;
140
141 // libecap::Body API
142 virtual BodySize bodySize() const;
143
144 private:
145 BodyPipe::Pointer theBody; // the body being translated to libecap
146 };
147
148 // Translates Squid Adaptation::Message into libecap::Message.
149 class MessageRep: public libecap::Message
150 {
151 public:
152 explicit MessageRep(HttpMsg *rawHeader);
153 virtual ~MessageRep();
154
155 /* libecap::Message API */
156 virtual libecap::shared_ptr<libecap::Message> clone() const;
157 virtual libecap::FirstLine &firstLine();
158 virtual const libecap::FirstLine &firstLine() const;
159 virtual libecap::Header &header();
160 virtual const libecap::Header &header() const;
161 virtual void addBody();
162 virtual libecap::Body *body();
163 virtual const libecap::Body *body() const;
164
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 */
181