libzypp  17.35.8
PluginFrame.h
Go to the documentation of this file.
1 /*---------------------------------------------------------------------\
2 | ____ _ __ __ ___ |
3 | |__ / \ / / . \ . \ |
4 | / / \ V /| _/ _/ |
5 | / /__ | | | | | | |
6 | /_____||_| |_| |_| |
7 | |
8 \---------------------------------------------------------------------*/
12 #ifndef ZYPP_CORE_PLUGINFRAME_H
13 #define ZYPP_CORE_PLUGINFRAME_H
14 
15 #include <iosfwd>
16 #include <string>
17 #include <map>
18 
19 #include <zypp/base/PtrTypes.h>
20 
21 #include <zypp-core/ByteArray.h>
23 
25 namespace zypp
26 {
27 
42  {
43  friend std::ostream & operator<<( std::ostream & str, const PluginFrame & obj );
44  friend bool operator==( const PluginFrame & lhs, const PluginFrame & rhs );
45 
46  using HeaderInitializerList = const std::initializer_list<std::pair<std::string, std::string>> &;
47 
48  public:
50  static const std::string & ackCommand();
52  static const std::string & errorCommand();
54  static const std::string & enomethodCommand();
56  static const std::string &contentLengthHeader();
57 
58  public:
61 
63  PluginFrame();
64 
68  PluginFrame( const std::string & command_r );
69 
73  PluginFrame(const std::string & command_r, std::string body_r );
74 
78  PluginFrame(const std::string & command_r, ByteArray body_r );
79 
83  PluginFrame( const std::string & command_r, HeaderInitializerList contents_r );
84 
88  PluginFrame(const std::string & command_r, ByteArray body_r, HeaderInitializerList contents_r );
89 
94  PluginFrame( std::istream & stream_r );
95 
96  public:
98  bool empty() const;
99 
101  explicit operator bool() const
102  { return !empty(); }
103 
104  public:
106  const std::string & command() const;
107 
111  void setCommand( const std::string & command_r );
112 
114  bool isAckCommand() const
115  { return command() == ackCommand(); }
116 
118  bool isErrorCommand() const
119  {return command() == errorCommand(); }
120 
122  bool isEnomethodCommand() const
123  {return command() == enomethodCommand(); }
124 
126  const ByteArray & body() const;
127 
136  ByteArray & bodyRef();
137 
139  void setBody( const std::string & body_r );
140 
142  void setBody( const ByteArray & body_r );
143 
145  void setBody( ByteArray && body_r );
146 
147  public:
149  using HeaderList = std::multimap<std::string, std::string>;
150 
152  using HeaderListIterator = HeaderList::const_iterator;
153 
154  private:
156  HeaderList & headerList();
157 
158  public:
160  const HeaderList & headerList() const;
161 
163  bool headerEmpty() const
164  { return headerList().empty(); }
165 
167  unsigned headerSize() const
168  { return headerList().size(); }
169 
172  { return headerList().begin(); }
173 
176  { return headerList().end(); }
177 
179  void headerClear()
180  { headerList().clear(); }
181 
182 
184  bool hasKey( const std::string & key_r ) const
185  { return ! keyEmpty( key_r ); }
186 
188  bool keyEmpty( const std::string & key_r ) const
189  { return headerList().find( key_r ) == headerEnd(); }
190 
192  bool keySize( const std::string & key_r ) const
193  { return headerList().count( key_r ); }
194 
196  HeaderListIterator keyBegin( const std::string & key_r ) const
197  { return headerList().lower_bound( key_r ); }
198 
200  HeaderListIterator keyEnd( const std::string & key_r ) const
201  { return headerList().upper_bound( key_r ); }
202 
203 
208  const std::string & getHeader( const std::string & key_r ) const;
209 
213  const std::string & getHeader( const std::string & key_r, const std::string & default_r ) const;
214 
216  const std::string & getHeaderNT( const std::string & key_r, const std::string & default_r = std::string() ) const;
217 
222  void setHeader( const std::string & key_r, const std::string & value_r = std::string() );
223 
228  void setHeader( HeaderInitializerList contents_r )
229  { headerList().clear(); addHeader( contents_r ); }
230 
235  void addHeader( const std::string & key_r, const std::string & value_r = std::string() );
237  void addHeader( HeaderInitializerList contents_r );
238 
243  void addRawHeader ( const ByteArray &header );
244 
246  void clearHeader( const std::string & key_r );
247 
248  public:
252  std::ostream & writeTo( std::ostream & stream_r ) const;
253 
255  static std::ostream & writeTo( std::ostream & stream_r, const PluginFrame & frame_r )
256  { return frame_r.writeTo( stream_r ); }
257 
261  std::istream & readFrom( std::istream & stream_r )
262  { *this = PluginFrame( stream_r ); return stream_r; }
263 
265  static std::istream & readFrom( std::istream & stream_r, PluginFrame & frame_r )
266  { frame_r = PluginFrame( stream_r ); return stream_r; }
267 
268  public:
270  struct Impl;
271  private:
274  };
275 
277  std::ostream & operator<<( std::ostream & str, const PluginFrame & obj );
278 
280  inline std::ostream & dumpOn( std::ostream & str, const PluginFrame & obj )
281  { if ( str ) try { PluginFrame::writeTo( str, obj ); } catch(...){}; return str; }
282 
284  inline std::istream & operator>>( std::istream & str, PluginFrame & obj )
285  { return PluginFrame::readFrom( str, obj ); }
286 
288  bool operator==( const PluginFrame & lhs, const PluginFrame & rhs );
289 
291  inline bool operator!=( const PluginFrame & lhs, const PluginFrame & rhs )
292  { return( ! operator==( lhs, rhs ) ); }
293 
295 } // namespace zypp
297 #endif // ZYPP_CORE_PLUGINFRAME_H
std::ostream & writeTo(std::ostream &stream_r) const
Write frame to stream.
Definition: PluginFrame.cc:448
bool headerEmpty() const
Whether header list is empty.
Definition: PluginFrame.h:163
bool hasKey(const std::string &key_r) const
Whether the header list contains at least one entry for key_r.
Definition: PluginFrame.h:184
Command frame for communication with PluginScript.
Definition: PluginFrame.h:41
std::istream & operator>>(std::istream &str, PluginFrame &obj)
Definition: PluginFrame.h:284
std::multimap< std::string, std::string > HeaderList
The header list.
Definition: PluginFrame.h:149
std::ostream & dumpOn(std::ostream &str, const PluginFrame &obj)
Definition: PluginFrame.h:280
bool operator!=(const PluginFrame &lhs, const PluginFrame &rhs)
Definition: PluginFrame.h:291
String related utilities and Regular expression matching.
std::ostream & operator<<(std::ostream &str, const SerialNumber &obj)
Definition: SerialNumber.cc:52
bool operator==(const SetRelation::Enum &lhs, const SetCompare &rhs)
static std::istream & readFrom(std::istream &stream_r, PluginFrame &frame_r)
Definition: PluginFrame.h:265
bool keyEmpty(const std::string &key_r) const
Definition: PluginFrame.h:188
HeaderListIterator headerBegin() const
Return iterator pointing to the 1st header (or headerEnd)
Definition: PluginFrame.h:171
void headerClear()
Clear the list of headers.
Definition: PluginFrame.h:179
bool isEnomethodCommand() const
Convenience to identify an _ENOMETHOD command.
Definition: PluginFrame.h:122
bool isErrorCommand() const
Convenience to identify an ERROR command.
Definition: PluginFrame.h:118
const Arch Arch_armv7hnl Arch_armv7nhl ZYPP_API
Definition: ResTraits.h:93
Base class for PluginFrame Exception.
RWCOW_pointer< Impl > _pimpl
Pointer to implementation.
Definition: PluginFrame.h:270
bool isAckCommand() const
Convenience to identify an ACK command.
Definition: PluginFrame.h:114
HeaderListIterator headerEnd() const
Return iterator pointing behind the last header.
Definition: PluginFrame.h:175
HeaderListIterator keyBegin(const std::string &key_r) const
Return iterator pointing to the 1st header for key_r (or keyEnd(key_r))
Definition: PluginFrame.h:196
void setHeader(HeaderInitializerList contents_r)
Set a new header list.
Definition: PluginFrame.h:228
bool keySize(const std::string &key_r) const
Return number of header entries for key_r.
Definition: PluginFrame.h:192
const std::initializer_list< std::pair< std::string, std::string > > & HeaderInitializerList
Definition: PluginFrame.h:46
HeaderList::const_iterator HeaderListIterator
Header list iterator.
Definition: PluginFrame.h:152
PluginFrame implementation.
Definition: PluginFrame.cc:32
std::istream & readFrom(std::istream &stream_r)
Read frame from stream.
Definition: PluginFrame.h:261
Easy-to use interface to the ZYPP dependency resolver.
Definition: Application.cc:19
unsigned headerSize() const
Return size of the header list.
Definition: PluginFrame.h:167
HeaderListIterator keyEnd(const std::string &key_r) const
Return iterator pointing behind the last header for key_r.
Definition: PluginFrame.h:200
static std::ostream & writeTo(std::ostream &stream_r, const PluginFrame &frame_r)
Definition: PluginFrame.h:255