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