]>
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 #if HAVE_LIBECAP_COMMON_BODY_H
22 #include <libecap/common/body.h>
24 #if HAVE_LIBECAP_COMMON_HEADER_H
25 #include <libecap/common/header.h>
27 #if HAVE_LIBECAP_COMMON_MESSAGE_H
28 #include <libecap/common/message.h>
38 // Translates Squid Http::Message into libecap::Header.
39 class HeaderRep
: public libecap::Header
42 typedef libecap::Name Name
;
43 typedef libecap::Area Area
;
46 HeaderRep(Http::Message
&aMessage
);
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
58 static Http::HdrType
TranslateHeaderId(const Name
&name
);
61 HttpHeader
&theHeader
; // the header being translated to libecap
62 Http::Message
&theMessage
; // the message being translated to libecap
65 // Helps translate Squid Http::Message into libecap::FirstLine (see children).
69 typedef libecap::Name Name
;
72 FirstLineRep(Http::Message
&aMessage
);
74 libecap::Version
version() const;
75 void version(const libecap::Version
&aVersion
);
76 Name
protocol() const;
77 void protocol(const Name
&aProtocol
);
80 static AnyP::ProtocolType
TranslateProtocolId(const Name
&name
);
83 Http::Message
&theMessage
; // the message which first line is being translated
86 // Translates Squid HttpRequest into libecap::RequestLine.
87 class RequestLineRep
: public libecap::RequestLine
, public FirstLineRep
90 // typedef libecap::Name Name;
91 typedef libecap::Area Area
;
94 RequestLineRep(HttpRequest
&aMessage
);
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
;
107 HttpRequest
&theMessage
; // the request header being translated to libecap
110 // Translates Squid HttpReply into libecap::StatusLine.
111 class StatusLineRep
: public libecap::StatusLine
, public FirstLineRep
114 typedef libecap::Name Name
;
115 typedef libecap::Area Area
;
118 StatusLineRep(HttpReply
&aMessage
);
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
;
131 HttpReply
&theMessage
; // the request header being translated to libecap
134 // Translates Squid BodyPipe into libecap::Body.
135 class BodyRep
: public libecap::Body
138 typedef libecap::BodySize BodySize
;
141 BodyRep(const BodyPipe::Pointer
&aBody
); // using NULL pointer? see tie()
143 void tie(const BodyPipe::Pointer
&aBody
); // late binding if !theBody;
146 BodySize
bodySize() const override
;
149 BodyPipe::Pointer theBody
; // the body being translated to libecap
152 // Translates Squid Adaptation::Message into libecap::Message.
153 class MessageRep
: public libecap::Message
156 explicit MessageRep(Http::Message
*rawHeader
);
157 ~MessageRep() override
;
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
;
169 void tieBody(Ecap::XactionRep
*x
); // to a specific transaction
171 Adaptation::Message
&raw() { return theMessage
; } // for host access
172 const Adaptation::Message
&raw() const { return theMessage
; } // for host
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
182 } // namespace Adaptation
184 #endif /* SQUID_SRC_ADAPTATION_ECAP_MESSAGEREP_H */