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