]>
git.ipfire.org Git - thirdparty/squid.git/blob - src/adaptation/ecap/MessageRep.h
2 * Copyright (C) 1996-2023 The Squid Software Foundation and contributors
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.
9 /* DEBUG: section 93 eCAP Interface */
11 #ifndef SQUID_SRC_ADAPTATION_ECAP_MESSAGEREP_H
12 #define SQUID_SRC_ADAPTATION_ECAP_MESSAGEREP_H
14 #include "adaptation/forward.h"
15 #include "adaptation/Message.h"
16 #include "anyp/ProtocolType.h"
18 #include "http/forward.h"
19 #include "HttpHeader.h"
21 #include <libecap/common/message.h>
22 #include <libecap/common/header.h>
23 #include <libecap/common/body.h>
32 // Translates Squid Http::Message into libecap::Header.
33 class HeaderRep
: public libecap::Header
36 typedef libecap::Name Name
;
37 typedef libecap::Area Area
;
40 HeaderRep(Http::Message
&aMessage
);
42 /* libecap::Header API */
43 bool hasAny(const Name
&name
) const override
;
44 Value
value(const Name
&name
) const override
;
45 void add(const Name
&name
, const Value
&value
) override
;
46 void removeAny(const Name
&name
) override
;
47 void visitEach(libecap::NamedValueVisitor
&visitor
) const override
;
48 Area
image() const override
;
49 void parse(const Area
&buf
) override
; // throws on failures
52 static Http::HdrType
TranslateHeaderId(const Name
&name
);
55 HttpHeader
&theHeader
; // the header being translated to libecap
56 Http::Message
&theMessage
; // the message being translated to libecap
59 // Helps translate Squid Http::Message into libecap::FirstLine (see children).
63 typedef libecap::Name Name
;
66 FirstLineRep(Http::Message
&aMessage
);
68 libecap::Version
version() const;
69 void version(const libecap::Version
&aVersion
);
70 Name
protocol() const;
71 void protocol(const Name
&aProtocol
);
74 static AnyP::ProtocolType
TranslateProtocolId(const Name
&name
);
77 Http::Message
&theMessage
; // the message which first line is being translated
80 // Translates Squid HttpRequest into libecap::RequestLine.
81 class RequestLineRep
: public libecap::RequestLine
, public FirstLineRep
84 // typedef libecap::Name Name;
85 typedef libecap::Area Area
;
88 RequestLineRep(HttpRequest
&aMessage
);
90 /* libecap::RequestLine API */
91 void uri(const Area
&aUri
) override
;
92 Area
uri() const override
;
93 void method(const Name
&aMethod
) override
;
94 Name
method() const override
;
95 libecap::Version
version() const override
;
96 void version(const libecap::Version
&aVersion
) override
;
97 Name
protocol() const override
;
98 void protocol(const Name
&aProtocol
) override
;
101 HttpRequest
&theMessage
; // the request header being translated to libecap
104 // Translates Squid HttpReply into libecap::StatusLine.
105 class StatusLineRep
: public libecap::StatusLine
, public FirstLineRep
108 typedef libecap::Name Name
;
109 typedef libecap::Area Area
;
112 StatusLineRep(HttpReply
&aMessage
);
114 /* libecap::StatusLine API */
115 void statusCode(int code
) override
;
116 int statusCode() const override
;
117 void reasonPhrase(const Area
&phrase
) override
;
118 Area
reasonPhrase() const override
;
119 libecap::Version
version() const override
;
120 void version(const libecap::Version
&aVersion
) override
;
121 Name
protocol() const override
;
122 void protocol(const Name
&aProtocol
) override
;
125 HttpReply
&theMessage
; // the request header being translated to libecap
128 // Translates Squid BodyPipe into libecap::Body.
129 class BodyRep
: public libecap::Body
132 typedef libecap::BodySize BodySize
;
135 BodyRep(const BodyPipe::Pointer
&aBody
); // using NULL pointer? see tie()
137 void tie(const BodyPipe::Pointer
&aBody
); // late binding if !theBody;
140 BodySize
bodySize() const override
;
143 BodyPipe::Pointer theBody
; // the body being translated to libecap
146 // Translates Squid Adaptation::Message into libecap::Message.
147 class MessageRep
: public libecap::Message
150 explicit MessageRep(Http::Message
*rawHeader
);
151 ~MessageRep() override
;
153 /* libecap::Message API */
154 libecap::shared_ptr
<libecap::Message
> clone() const override
;
155 libecap::FirstLine
&firstLine() override
;
156 const libecap::FirstLine
&firstLine() const override
;
157 libecap::Header
&header() override
;
158 const libecap::Header
&header() const override
;
159 void addBody() override
;
160 libecap::Body
*body() override
;
161 const libecap::Body
*body() const override
;
163 void tieBody(Ecap::XactionRep
*x
); // to a specific transaction
165 Adaptation::Message
&raw() { return theMessage
; } // for host access
166 const Adaptation::Message
&raw() const { return theMessage
; } // for host
169 Adaptation::Message theMessage
; // the message being translated to libecap
170 libecap::FirstLine
*theFirstLineRep
; // request or status line wrapper
171 HeaderRep
*theHeaderRep
; // header wrapper
172 BodyRep
*theBodyRep
; // body wrapper
176 } // namespace Adaptation
178 #endif /* SQUID_SRC_ADAPTATION_ECAP_MESSAGEREP_H */