]>
git.ipfire.org Git - thirdparty/squid.git/blob - src/adaptation/ecap/MessageRep.h
2 * Copyright (C) 1996-2014 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 "HttpHeader.h"
19 #include <libecap/common/message.h>
20 #include <libecap/common/header.h>
21 #include <libecap/common/body.h>
34 // Translates Squid HttpMsg into libecap::Header.
35 class HeaderRep
: public libecap::Header
38 typedef libecap::Name Name
;
39 typedef libecap::Area Area
;
42 HeaderRep(HttpMsg
&aMessage
);
44 /* libecap::Header API */
45 virtual bool hasAny(const Name
&name
) const;
46 virtual Value
value(const Name
&name
) const;
47 virtual void add(const Name
&name
, const Value
&value
);
48 virtual void removeAny(const Name
&name
);
49 virtual void visitEach(libecap::NamedValueVisitor
&visitor
) const;
50 virtual Area
image() const;
51 virtual void parse(const Area
&buf
); // throws on failures
54 static http_hdr_type
TranslateHeaderId(const Name
&name
);
57 HttpHeader
&theHeader
; // the header being translated to libecap
58 HttpMsg
&theMessage
; // the message being translated to libecap
61 // Helps translate Squid HttpMsg into libecap::FirstLine (see children).
65 typedef libecap::Name Name
;
68 FirstLineRep(HttpMsg
&aMessage
);
70 libecap::Version
version() const;
71 void version(const libecap::Version
&aVersion
);
72 Name
protocol() const;
73 void protocol(const Name
&aProtocol
);
76 static AnyP::ProtocolType
TranslateProtocolId(const Name
&name
);
79 HttpMsg
&theMessage
; // the message which first line is being translated
82 // Translates Squid HttpRequest into libecap::RequestLine.
83 class RequestLineRep
: public libecap::RequestLine
, public FirstLineRep
86 // typedef libecap::Name Name;
87 typedef libecap::Area Area
;
90 RequestLineRep(HttpRequest
&aMessage
);
92 /* libecap::RequestLine API */
93 virtual void uri(const Area
&aUri
);
94 virtual Area
uri() const;
95 virtual void method(const Name
&aMethod
);
96 virtual Name
method() const;
97 virtual libecap::Version
version() const;
98 virtual void version(const libecap::Version
&aVersion
);
99 virtual Name
protocol() const;
100 virtual void protocol(const Name
&aProtocol
);
103 HttpRequest
&theMessage
; // the request header being translated to libecap
106 // Translates Squid HttpReply into libecap::StatusLine.
107 class StatusLineRep
: public libecap::StatusLine
, public FirstLineRep
110 typedef libecap::Name Name
;
111 typedef libecap::Area Area
;
114 StatusLineRep(HttpReply
&aMessage
);
116 /* libecap::StatusLine API */
117 virtual void statusCode(int code
);
118 virtual int statusCode() const;
119 virtual void reasonPhrase(const Area
&phrase
);
120 virtual Area
reasonPhrase() const;
121 virtual libecap::Version
version() const;
122 virtual void version(const libecap::Version
&aVersion
);
123 virtual Name
protocol() const;
124 virtual void protocol(const Name
&aProtocol
);
127 HttpReply
&theMessage
; // the request header being translated to libecap
130 // Translates Squid BodyPipe into libecap::Body.
131 class BodyRep
: public libecap::Body
134 typedef libecap::BodySize BodySize
;
137 BodyRep(const BodyPipe::Pointer
&aBody
); // using NULL pointer? see tie()
139 void tie(const BodyPipe::Pointer
&aBody
); // late binding if !theBody;
142 virtual BodySize
bodySize() const;
145 BodyPipe::Pointer theBody
; // the body being translated to libecap
148 // Translates Squid Adaptation::Message into libecap::Message.
149 class MessageRep
: public libecap::Message
152 explicit MessageRep(HttpMsg
*rawHeader
);
153 virtual ~MessageRep();
155 /* libecap::Message API */
156 virtual libecap::shared_ptr
<libecap::Message
> clone() const;
157 virtual libecap::FirstLine
&firstLine();
158 virtual const libecap::FirstLine
&firstLine() const;
159 virtual libecap::Header
&header();
160 virtual const libecap::Header
&header() const;
161 virtual void addBody();
162 virtual libecap::Body
*body();
163 virtual const libecap::Body
*body() const;
165 void tieBody(Ecap::XactionRep
*x
); // to a specific transaction
167 Adaptation::Message
&raw() { return theMessage
; } // for host access
168 const Adaptation::Message
&raw() const { return theMessage
; } // for host
171 Adaptation::Message theMessage
; // the message being translated to libecap
172 libecap::FirstLine
*theFirstLineRep
; // request or status line wrapper
173 HeaderRep
*theHeaderRep
; // header wrapper
174 BodyRep
*theBodyRep
; // body wrapper
178 } // namespace Adaptation
180 #endif /* SQUID__E_CAP__MESSAGE_REP_H */