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