]>
git.ipfire.org Git - thirdparty/squid.git/blob - src/adaptation/ecap/MessageRep.h
2 * Copyright (C) 1996-2021 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__ECAP__MESSAGE_REP_H
12 #define SQUID__ECAP__MESSAGE_REP_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 virtual bool hasAny(const Name
&name
) const;
44 virtual Value
value(const Name
&name
) const;
45 virtual void add(const Name
&name
, const Value
&value
);
46 virtual void removeAny(const Name
&name
);
47 virtual void visitEach(libecap::NamedValueVisitor
&visitor
) const;
48 virtual Area
image() const;
49 virtual void parse(const Area
&buf
); // 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 virtual void uri(const Area
&aUri
);
92 virtual Area
uri() const;
93 virtual void method(const Name
&aMethod
);
94 virtual Name
method() const;
95 virtual libecap::Version
version() const;
96 virtual void version(const libecap::Version
&aVersion
);
97 virtual Name
protocol() const;
98 virtual void protocol(const Name
&aProtocol
);
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 virtual void statusCode(int code
);
116 virtual int statusCode() const;
117 virtual void reasonPhrase(const Area
&phrase
);
118 virtual Area
reasonPhrase() const;
119 virtual libecap::Version
version() const;
120 virtual void version(const libecap::Version
&aVersion
);
121 virtual Name
protocol() const;
122 virtual void protocol(const Name
&aProtocol
);
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 virtual BodySize
bodySize() const;
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 virtual ~MessageRep();
153 /* libecap::Message API */
154 virtual libecap::shared_ptr
<libecap::Message
> clone() const;
155 virtual libecap::FirstLine
&firstLine();
156 virtual const libecap::FirstLine
&firstLine() const;
157 virtual libecap::Header
&header();
158 virtual const libecap::Header
&header() const;
159 virtual void addBody();
160 virtual libecap::Body
*body();
161 virtual const libecap::Body
*body() const;
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__E_CAP__MESSAGE_REP_H */