MessageRep.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 1996-2023 The Squid Software Foundation and contributors
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.
7 */
8
9/* DEBUG: section 93 eCAP Interface */
10
11#ifndef SQUID__ECAP__MESSAGE_REP_H
12#define SQUID__ECAP__MESSAGE_REP_H
13
14#include "adaptation/forward.h"
15#include "adaptation/Message.h"
16#include "anyp/ProtocolType.h"
17#include "BodyPipe.h"
18#include "http/forward.h"
19#include "HttpHeader.h"
20
21#include <libecap/common/message.h>
22#include <libecap/common/header.h>
23#include <libecap/common/body.h>
24
25namespace Adaptation
26{
27namespace Ecap
28{
29
30class XactionRep;
31
32// Translates Squid Http::Message into libecap::Header.
33class HeaderRep: public libecap::Header
34{
35public:
36 typedef libecap::Name Name;
37 typedef libecap::Area Area;
38
39public:
40 HeaderRep(Http::Message &aMessage);
41
42 /* libecap::Header API */
43 bool hasAny(const Name &name) const override;
44 Value value(const Name &name) const override;
45 void add(const Name &name, const Value &value) override;
46 void removeAny(const Name &name) override;
47 void visitEach(libecap::NamedValueVisitor &visitor) const override;
48 Area image() const override;
49 void parse(const Area &buf) override; // throws on failures
50
51protected:
52 static Http::HdrType TranslateHeaderId(const Name &name);
53
54private:
55 HttpHeader &theHeader; // the header being translated to libecap
56 Http::Message &theMessage; // the message being translated to libecap
57};
58
59// Helps translate Squid Http::Message into libecap::FirstLine (see children).
61{
62public:
63 typedef libecap::Name Name;
64
65public:
66 FirstLineRep(Http::Message &aMessage);
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:
75
76private:
77 Http::Message &theMessage; // the message which first line is being translated
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);
89
90 /* libecap::RequestLine API */
91 void uri(const Area &aUri) override;
92 Area uri() const override;
93 void method(const Name &aMethod) override;
94 Name method() const override;
95 libecap::Version version() const override;
96 void version(const libecap::Version &aVersion) override;
97 Name protocol() const override;
98 void protocol(const Name &aProtocol) override;
99
100private:
101 HttpRequest &theMessage; // the request header being translated to libecap
102};
103
104// Translates Squid HttpReply into libecap::StatusLine.
105class StatusLineRep: public libecap::StatusLine, public FirstLineRep
106{
107public:
108 typedef libecap::Name Name;
109 typedef libecap::Area Area;
110
111public:
112 StatusLineRep(HttpReply &aMessage);
113
114 /* libecap::StatusLine API */
115 void statusCode(int code) override;
116 int statusCode() const override;
117 void reasonPhrase(const Area &phrase) override;
118 Area reasonPhrase() const override;
119 libecap::Version version() const override;
120 void version(const libecap::Version &aVersion) override;
121 Name protocol() const override;
122 void protocol(const Name &aProtocol) override;
123
124private:
125 HttpReply &theMessage; // the request header being translated to libecap
126};
127
128// Translates Squid BodyPipe into libecap::Body.
129class BodyRep: public libecap::Body
130{
131public:
132 typedef libecap::BodySize BodySize;
133
134public:
135 BodyRep(const BodyPipe::Pointer &aBody); // using NULL pointer? see tie()
136
137 void tie(const BodyPipe::Pointer &aBody); // late binding if !theBody;
138
139 // libecap::Body API
140 BodySize bodySize() const override;
141
142private:
143 BodyPipe::Pointer theBody; // the body being translated to libecap
144};
145
146// Translates Squid Adaptation::Message into libecap::Message.
147class MessageRep: public libecap::Message
148{
149public:
150 explicit MessageRep(Http::Message *rawHeader);
151 ~MessageRep() override;
152
153 /* libecap::Message API */
154 libecap::shared_ptr<libecap::Message> clone() const override;
155 libecap::FirstLine &firstLine() override;
156 const libecap::FirstLine &firstLine() const override;
157 libecap::Header &header() override;
158 const libecap::Header &header() const override;
159 void addBody() override;
160 libecap::Body *body() override;
161 const libecap::Body *body() const override;
162
163 void tieBody(Ecap::XactionRep *x); // to a specific transaction
164
165 Adaptation::Message &raw() { return theMessage; } // for host access
166 const Adaptation::Message &raw() const { return theMessage; } // for host
167
168private:
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
173};
174
175} // namespace Ecap
176} // namespace Adaptation
177
178#endif /* SQUID__E_CAP__MESSAGE_REP_H */
179
BodyRep(const BodyPipe::Pointer &aBody)
Definition: MessageRep.cc:338
BodySize bodySize() const override
Definition: MessageRep.cc:351
BodyPipe::Pointer theBody
Definition: MessageRep.h:143
libecap::BodySize BodySize
Definition: MessageRep.h:132
void tie(const BodyPipe::Pointer &aBody)
Definition: MessageRep.cc:343
Http::Message & theMessage
Definition: MessageRep.h:77
libecap::Version version() const
Definition: MessageRep.cc:119
static AnyP::ProtocolType TranslateProtocolId(const Name &name)
Definition: MessageRep.cc:184
FirstLineRep(Http::Message &aMessage)
Definition: MessageRep.cc:114
Http::Message & theMessage
Definition: MessageRep.h:56
Value value(const Name &name) const override
Definition: MessageRep.cc:41
void add(const Name &name, const Value &value) override
Definition: MessageRep.cc:52
HeaderRep(Http::Message &aMessage)
Definition: MessageRep.cc:26
void parse(const Area &buf) override
Definition: MessageRep.cc:98
static Http::HdrType TranslateHeaderId(const Name &name)
Definition: MessageRep.cc:105
bool hasAny(const Name &name) const override
Definition: MessageRep.cc:32
void removeAny(const Name &name) override
Definition: MessageRep.cc:64
Area image() const override
Definition: MessageRep.cc:88
void visitEach(libecap::NamedValueVisitor &visitor) const override
Definition: MessageRep.cc:77
Adaptation::Message theMessage
Definition: MessageRep.h:169
Adaptation::Message & raw()
Definition: MessageRep.h:165
const Adaptation::Message & raw() const
Definition: MessageRep.h:166
MessageRep(Http::Message *rawHeader)
Definition: MessageRep.cc:358
libecap::FirstLine * theFirstLineRep
Definition: MessageRep.h:170
libecap::Body * body() override
Definition: MessageRep.cc:423
libecap::FirstLine & firstLine() override
Definition: MessageRep.cc:399
libecap::Header & header() override
Definition: MessageRep.cc:411
libecap::shared_ptr< libecap::Message > clone() const override
Definition: MessageRep.cc:385
void tieBody(Ecap::XactionRep *x)
Definition: MessageRep.cc:437
libecap::Version version() const override
Definition: MessageRep.cc:255
Name method() const override
Definition: MessageRep.cc:232
Area uri() const override
Definition: MessageRep.cc:208
RequestLineRep(HttpRequest &aMessage)
Definition: MessageRep.cc:193
Name protocol() const override
Definition: MessageRep.cc:267
int statusCode() const override
Definition: MessageRep.cc:292
libecap::Version version() const override
Definition: MessageRep.cc:313
Name protocol() const override
Definition: MessageRep.cc:325
Area reasonPhrase() const override
Definition: MessageRep.cc:307
StatusLineRep(HttpReply &aMessage)
Definition: MessageRep.cc:280
common parts of HttpRequest and HttpReply
Definition: Message.h:26
ProtocolType
Definition: ProtocolType.h:23
int code
Definition: smb-errors.c:145

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors