]> git.ipfire.org Git - thirdparty/squid.git/blame - src/adaptation/ecap/MessageRep.h
SourceFormat Enforcement
[thirdparty/squid.git] / src / adaptation / ecap / MessageRep.h
CommitLineData
fdc96a39
AR
1/*
2 * $Id$
b510f3a1 3 * DEBUG: section 93 eCAP Interface
fdc96a39
AR
4 */
5
7b67e5b6
AR
6#ifndef SQUID__ECAP__MESSAGE_REP_H
7#define SQUID__ECAP__MESSAGE_REP_H
fdc96a39 8
1f3c65fc
AR
9#include "HttpHeader.h"
10#include "BodyPipe.h"
fdc96a39 11#include "adaptation/forward.h"
1f3c65fc 12#include "adaptation/Message.h"
555aedbf 13#include "anyp/ProtocolType.h"
fdc96a39 14#include <libecap/common/message.h>
cf331c99
AR
15#include <libecap/common/header.h>
16#include <libecap/common/body.h>
fdc96a39 17
1f3c65fc
AR
18class HttpMsg;
19class HttpRequest;
20class HttpReply;
21
af6a12ee
AJ
22namespace Adaptation
23{
e1381638
AJ
24namespace Ecap
25{
fdc96a39 26
cf331c99
AR
27class XactionRep;
28
29// Translates Squid HttpMsg into libecap::Header.
30class HeaderRep: public libecap::Header
31{
32public:
33 typedef libecap::Name Name;
34 typedef libecap::Area Area;
35
36public:
37 HeaderRep(HttpMsg &aMessage);
38
8442a9b2 39 /* libecap::Header API */
cf331c99
AR
40 virtual bool hasAny(const Name &name) const;
41 virtual Value value(const Name &name) const;
cf331c99
AR
42 virtual void add(const Name &name, const Value &value);
43 virtual void removeAny(const Name &name);
12a410c3 44 virtual void visitEach(libecap::NamedValueVisitor &visitor) const;
cf331c99
AR
45 virtual Area image() const;
46 virtual void parse(const Area &buf); // throws on failures
47
cf331c99
AR
48protected:
49 static http_hdr_type TranslateHeaderId(const Name &name);
cf331c99
AR
50
51private:
52 HttpHeader &theHeader; // the header being translated to libecap
53 HttpMsg &theMessage; // the message being translated to libecap
54};
55
77773405
AR
56// Helps translate Squid HttpMsg into libecap::FirstLine (see children).
57class FirstLineRep
cf331c99
AR
58{
59public:
77773405
AR
60 typedef libecap::Name Name;
61
62public:
63 FirstLineRep(HttpMsg &aMessage);
64
65 libecap::Version version() const;
66 void version(const libecap::Version &aVersion);
67 Name protocol() const;
68 void protocol(const Name &aProtocol);
69
70protected:
555aedbf 71 static AnyP::ProtocolType TranslateProtocolId(const Name &name);
77773405
AR
72
73private:
74 HttpMsg &theMessage; // the message which first line is being translated
75};
76
77// Translates Squid HttpRequest into libecap::RequestLine.
78class RequestLineRep: public libecap::RequestLine, public FirstLineRep
79{
80public:
81// typedef libecap::Name Name;
82 typedef libecap::Area Area;
83
84public:
85 RequestLineRep(HttpRequest &aMessage);
cf331c99 86
8442a9b2 87 /* libecap::RequestLine API */
cf331c99
AR
88 virtual void uri(const Area &aUri);
89 virtual Area uri() const;
cf331c99
AR
90 virtual void method(const Name &aMethod);
91 virtual Name method() const;
77773405
AR
92 virtual libecap::Version version() const;
93 virtual void version(const libecap::Version &aVersion);
94 virtual Name protocol() const;
95 virtual void protocol(const Name &aProtocol);
96
cf331c99
AR
97private:
98 HttpRequest &theMessage; // the request header being translated to libecap
99};
100
77773405
AR
101// Translates Squid HttpReply into libecap::StatusLine.
102class StatusLineRep: public libecap::StatusLine, public FirstLineRep
cf331c99
AR
103{
104public:
77773405
AR
105 typedef libecap::Name Name;
106 typedef libecap::Area Area;
107
108public:
109 StatusLineRep(HttpReply &aMessage);
cf331c99 110
8442a9b2 111 /* libecap::StatusLine API */
cf331c99
AR
112 virtual void statusCode(int code);
113 virtual int statusCode() const;
cf331c99
AR
114 virtual void reasonPhrase(const Area &phrase);
115 virtual Area reasonPhrase() const;
77773405
AR
116 virtual libecap::Version version() const;
117 virtual void version(const libecap::Version &aVersion);
118 virtual Name protocol() const;
119 virtual void protocol(const Name &aProtocol);
120
cf331c99
AR
121private:
122 HttpReply &theMessage; // the request header being translated to libecap
123};
124
77773405 125// Translates Squid BodyPipe into libecap::Body.
cf331c99
AR
126class BodyRep: public libecap::Body
127{
128public:
cf331c99
AR
129 typedef libecap::BodySize BodySize;
130
131public:
77773405 132 BodyRep(const BodyPipe::Pointer &aBody); // using NULL pointer? see tie()
cf331c99 133
77773405
AR
134 void tie(const BodyPipe::Pointer &aBody); // late binding if !theBody;
135
136 // libecap::Body API
cf331c99 137 virtual BodySize bodySize() const;
cf331c99
AR
138
139private:
140 BodyPipe::Pointer theBody; // the body being translated to libecap
141};
142
fdc96a39 143// Translates Squid Adaptation::Message into libecap::Message.
7b67e5b6 144class MessageRep: public libecap::Message
fdc96a39 145{
fdc96a39 146public:
77773405 147 explicit MessageRep(HttpMsg *rawHeader);
cf331c99
AR
148 virtual ~MessageRep();
149
8442a9b2 150 /* libecap::Message API */
f1a768b2 151 virtual libecap::shared_ptr<libecap::Message> clone() const;
f1a768b2
AR
152 virtual libecap::FirstLine &firstLine();
153 virtual const libecap::FirstLine &firstLine() const;
cf331c99
AR
154 virtual libecap::Header &header();
155 virtual const libecap::Header &header() const;
cf331c99
AR
156 virtual void addBody();
157 virtual libecap::Body *body();
158 virtual const libecap::Body *body() const;
8442a9b2 159
f1a768b2 160 void tieBody(Ecap::XactionRep *x); // to a specific transaction
77773405 161
f1a768b2
AR
162 Adaptation::Message &raw() { return theMessage; } // for host access
163 const Adaptation::Message &raw() const { return theMessage; } // for host
fdc96a39
AR
164
165private:
77773405
AR
166 Adaptation::Message theMessage; // the message being translated to libecap
167 libecap::FirstLine *theFirstLineRep; // request or status line wrapper
168 HeaderRep *theHeaderRep; // header wrapper
169 BodyRep *theBodyRep; // body wrapper
fdc96a39
AR
170};
171
574b508c
AR
172} // namespace Ecap
173} // namespace Adaptation
fdc96a39 174
7b67e5b6 175#endif /* SQUID__E_CAP__MESSAGE_REP_H */