MessageRep.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 1996-2017 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 
25 namespace Adaptation
26 {
27 namespace Ecap
28 {
29 
30 class XactionRep;
31 
32 // Translates Squid Http::Message into libecap::Header.
33 class HeaderRep: public libecap::Header
34 {
35 public:
36  typedef libecap::Name Name;
37  typedef libecap::Area Area;
38 
39 public:
40  HeaderRep(Http::Message &aMessage);
41 
42  /* libecap::Header API */
43  virtual bool hasAny(const Name &name) const;
44  virtual Value value(const Name &name) const;
45  virtual void add(const Name &name, const Value &value);
46  virtual void removeAny(const Name &name);
47  virtual void visitEach(libecap::NamedValueVisitor &visitor) const;
48  virtual Area image() const;
49  virtual void parse(const Area &buf); // throws on failures
50 
51 protected:
52  static Http::HdrType TranslateHeaderId(const Name &name);
53 
54 private:
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 {
62 public:
63  typedef libecap::Name Name;
64 
65 public:
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 
73 protected:
74  static AnyP::ProtocolType TranslateProtocolId(const Name &name);
75 
76 private:
77  Http::Message &theMessage; // the message which first line is being translated
78 };
79 
80 // Translates Squid HttpRequest into libecap::RequestLine.
81 class RequestLineRep: public libecap::RequestLine, public FirstLineRep
82 {
83 public:
84 // typedef libecap::Name Name;
85  typedef libecap::Area Area;
86 
87 public:
88  RequestLineRep(HttpRequest &aMessage);
89 
90  /* libecap::RequestLine API */
91  virtual void uri(const Area &aUri);
92  virtual Area uri() const;
93  virtual void method(const Name &aMethod);
94  virtual Name method() const;
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 
100 private:
101  HttpRequest &theMessage; // the request header being translated to libecap
102 };
103 
104 // Translates Squid HttpReply into libecap::StatusLine.
105 class StatusLineRep: public libecap::StatusLine, public FirstLineRep
106 {
107 public:
108  typedef libecap::Name Name;
109  typedef libecap::Area Area;
110 
111 public:
112  StatusLineRep(HttpReply &aMessage);
113 
114  /* libecap::StatusLine API */
115  virtual void statusCode(int code);
116  virtual int statusCode() const;
117  virtual void reasonPhrase(const Area &phrase);
118  virtual Area reasonPhrase() const;
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 
124 private:
125  HttpReply &theMessage; // the request header being translated to libecap
126 };
127 
128 // Translates Squid BodyPipe into libecap::Body.
129 class BodyRep: public libecap::Body
130 {
131 public:
132  typedef libecap::BodySize BodySize;
133 
134 public:
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  virtual BodySize bodySize() const;
141 
142 private:
143  BodyPipe::Pointer theBody; // the body being translated to libecap
144 };
145 
146 // Translates Squid Adaptation::Message into libecap::Message.
147 class MessageRep: public libecap::Message
148 {
149 public:
150  explicit MessageRep(Http::Message *rawHeader);
151  virtual ~MessageRep();
152 
153  /* libecap::Message API */
154  virtual libecap::shared_ptr<libecap::Message> clone() const;
155  virtual libecap::FirstLine &firstLine();
156  virtual const libecap::FirstLine &firstLine() const;
157  virtual libecap::Header &header();
158  virtual const libecap::Header &header() const;
159  virtual void addBody();
160  virtual libecap::Body *body();
161  virtual const libecap::Body *body() const;
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 
168 private:
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 
Adaptation::Message & raw()
Definition: MessageRep.h:165
BodyRep(const BodyPipe::Pointer &aBody)
Definition: MessageRep.cc:344
virtual void visitEach(libecap::NamedValueVisitor &visitor) const
Definition: MessageRep.cc:78
virtual Value value(const Name &name) const
Definition: MessageRep.cc:42
libecap::BodySize BodySize
Definition: MessageRep.h:132
virtual Area reasonPhrase() const
Definition: MessageRep.cc:313
virtual libecap::FirstLine & firstLine()
Definition: MessageRep.cc:405
libecap::Version version() const
Definition: MessageRep.cc:120
void tie(const BodyPipe::Pointer &aBody)
Definition: MessageRep.cc:349
virtual void removeAny(const Name &name)
Definition: MessageRep.cc:65
virtual libecap::shared_ptr< libecap::Message > clone() const
Definition: MessageRep.cc:391
virtual libecap::Body * body()
Definition: MessageRep.cc:429
virtual Name protocol() const
Definition: MessageRep.cc:331
virtual Area uri() const
Definition: MessageRep.cc:214
virtual libecap::Header & header()
Definition: MessageRep.cc:417
virtual Area image() const
Definition: MessageRep.cc:89
virtual void add(const Name &name, const Value &value)
Definition: MessageRep.cc:53
static AnyP::ProtocolType TranslateProtocolId(const Name &name)
Definition: MessageRep.cc:189
common parts of HttpRequest and HttpReply
Definition: Message.h:24
virtual int statusCode() const
Definition: MessageRep.cc:298
libecap::FirstLine * theFirstLineRep
Definition: MessageRep.h:170
FirstLineRep(Http::Message &aMessage)
Definition: MessageRep.cc:115
void tieBody(Ecap::XactionRep *x)
Definition: MessageRep.cc:443
virtual Name protocol() const
Definition: MessageRep.cc:273
unsigned char code
Definition: html_quote.c:20
void const char * buf
Definition: stub_helper.cc:16
StatusLineRep(HttpReply &aMessage)
Definition: MessageRep.cc:286
virtual libecap::Version version() const
Definition: MessageRep.cc:319
Http::Message & theMessage
Definition: MessageRep.h:77
virtual bool hasAny(const Name &name) const
Definition: MessageRep.cc:33
virtual BodySize bodySize() const
Definition: MessageRep.cc:357
static Http::HdrType TranslateHeaderId(const Name &name)
Definition: MessageRep.cc:106
ProtocolType
Definition: ProtocolType.h:22
HeaderRep(Http::Message &aMessage)
Definition: MessageRep.cc:27
Adaptation::Message theMessage
Definition: MessageRep.h:169
Http::Message & theMessage
Definition: MessageRep.h:56
const Adaptation::Message & raw() const
Definition: MessageRep.h:166
MessageRep(Http::Message *rawHeader)
Definition: MessageRep.cc:364
virtual libecap::Version version() const
Definition: MessageRep.cc:261
virtual Name method() const
Definition: MessageRep.cc:238
RequestLineRep(HttpRequest &aMessage)
Definition: MessageRep.cc:198
BodyPipe::Pointer theBody
Definition: MessageRep.h:143
virtual void parse(const Area &buf)
Definition: MessageRep.cc:99

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors