]> git.ipfire.org Git - thirdparty/squid.git/blame - src/adaptation/ecap/MessageRep.h
Simplify appending SBuf to String (#2108)
[thirdparty/squid.git] / src / adaptation / ecap / MessageRep.h
CommitLineData
fdc96a39 1/*
1f7b830e 2 * Copyright (C) 1996-2025 The Squid Software Foundation and contributors
bbc27441
AJ
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.
fdc96a39
AR
7 */
8
bbc27441
AJ
9/* DEBUG: section 93 eCAP Interface */
10
ff9d9458
FC
11#ifndef SQUID_SRC_ADAPTATION_ECAP_MESSAGEREP_H
12#define SQUID_SRC_ADAPTATION_ECAP_MESSAGEREP_H
fdc96a39
AR
13
14#include "adaptation/forward.h"
1f3c65fc 15#include "adaptation/Message.h"
555aedbf 16#include "anyp/ProtocolType.h"
602d9612 17#include "BodyPipe.h"
63df1d28 18#include "http/forward.h"
602d9612 19#include "HttpHeader.h"
63df1d28 20
8800478b 21#if HAVE_LIBECAP_COMMON_BODY_H
cf331c99 22#include <libecap/common/body.h>
8800478b
AJ
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
fdc96a39 30
af6a12ee
AJ
31namespace Adaptation
32{
e1381638
AJ
33namespace Ecap
34{
fdc96a39 35
cf331c99
AR
36class XactionRep;
37
63df1d28 38// Translates Squid Http::Message into libecap::Header.
cf331c99
AR
39class HeaderRep: public libecap::Header
40{
41public:
42 typedef libecap::Name Name;
43 typedef libecap::Area Area;
44
45public:
63df1d28 46 HeaderRep(Http::Message &aMessage);
cf331c99 47
8442a9b2 48 /* libecap::Header API */
337b9aa4
AR
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
cf331c99 56
cf331c99 57protected:
789217a2 58 static Http::HdrType TranslateHeaderId(const Name &name);
cf331c99
AR
59
60private:
61 HttpHeader &theHeader; // the header being translated to libecap
63df1d28 62 Http::Message &theMessage; // the message being translated to libecap
cf331c99
AR
63};
64
63df1d28 65// Helps translate Squid Http::Message into libecap::FirstLine (see children).
77773405 66class FirstLineRep
cf331c99
AR
67{
68public:
77773405
AR
69 typedef libecap::Name Name;
70
71public:
63df1d28 72 FirstLineRep(Http::Message &aMessage);
77773405
AR
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:
555aedbf 80 static AnyP::ProtocolType TranslateProtocolId(const Name &name);
77773405
AR
81
82private:
63df1d28 83 Http::Message &theMessage; // the message which first line is being translated
77773405
AR
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);
cf331c99 95
8442a9b2 96 /* libecap::RequestLine API */
337b9aa4
AR
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;
77773405 105
cf331c99
AR
106private:
107 HttpRequest &theMessage; // the request header being translated to libecap
108};
109
77773405
AR
110// Translates Squid HttpReply into libecap::StatusLine.
111class StatusLineRep: public libecap::StatusLine, public FirstLineRep
cf331c99
AR
112{
113public:
77773405
AR
114 typedef libecap::Name Name;
115 typedef libecap::Area Area;
116
117public:
118 StatusLineRep(HttpReply &aMessage);
cf331c99 119
8442a9b2 120 /* libecap::StatusLine API */
337b9aa4
AR
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;
77773405 129
cf331c99
AR
130private:
131 HttpReply &theMessage; // the request header being translated to libecap
132};
133
77773405 134// Translates Squid BodyPipe into libecap::Body.
cf331c99
AR
135class BodyRep: public libecap::Body
136{
137public:
cf331c99
AR
138 typedef libecap::BodySize BodySize;
139
140public:
77773405 141 BodyRep(const BodyPipe::Pointer &aBody); // using NULL pointer? see tie()
cf331c99 142
77773405
AR
143 void tie(const BodyPipe::Pointer &aBody); // late binding if !theBody;
144
145 // libecap::Body API
337b9aa4 146 BodySize bodySize() const override;
cf331c99
AR
147
148private:
149 BodyPipe::Pointer theBody; // the body being translated to libecap
150};
151
fdc96a39 152// Translates Squid Adaptation::Message into libecap::Message.
7b67e5b6 153class MessageRep: public libecap::Message
fdc96a39 154{
fdc96a39 155public:
63df1d28 156 explicit MessageRep(Http::Message *rawHeader);
337b9aa4 157 ~MessageRep() override;
cf331c99 158
8442a9b2 159 /* libecap::Message API */
337b9aa4
AR
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;
8442a9b2 168
f1a768b2 169 void tieBody(Ecap::XactionRep *x); // to a specific transaction
77773405 170
f1a768b2
AR
171 Adaptation::Message &raw() { return theMessage; } // for host access
172 const Adaptation::Message &raw() const { return theMessage; } // for host
fdc96a39
AR
173
174private:
77773405
AR
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
fdc96a39
AR
179};
180
574b508c
AR
181} // namespace Ecap
182} // namespace Adaptation
fdc96a39 183
ff9d9458 184#endif /* SQUID_SRC_ADAPTATION_ECAP_MESSAGEREP_H */
f53969cc 185