libzypp 17.35.11
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
25namespace 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
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
84
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
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
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
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
RepoManager implementation.
Reference counted access to a Tp object calling a custom Dispose function when the last AutoDispose h...
Definition AutoDispose.h:95
Base class for PluginFrame Exception.
Command frame for communication with PluginScript.
Definition PluginFrame.h:42
HeaderList::const_iterator HeaderListIterator
Header list iterator.
const std::initializer_list< std::pair< std::string, std::string > > & HeaderInitializerList
Definition PluginFrame.h:46
HeaderListIterator keyBegin(const std::string &key_r) const
Return iterator pointing to the 1st header for key_r (or keyEnd(key_r))
void headerClear()
Clear the list of headers.
void setHeader(HeaderInitializerList contents_r)
Set a new header list.
bool headerEmpty() const
Whether header list is empty.
bool keyEmpty(const std::string &key_r) const
This is an overloaded member function, provided for convenience. It differs from the above function o...
unsigned headerSize() const
Return size of the header list.
bool isErrorCommand() const
Convenience to identify an ERROR command.
std::istream & readFrom(std::istream &stream_r)
Read frame from stream.
bool keySize(const std::string &key_r) const
Return number of header entries for key_r.
std::ostream & dumpOn(std::ostream &str, const PluginFrame &obj)
Stream output writing all data for logging (no throw)
RWCOW_pointer< Impl > _pimpl
Pointer to implementation.
bool isEnomethodCommand() const
Convenience to identify an _ENOMETHOD command.
HeaderListIterator keyEnd(const std::string &key_r) const
Return iterator pointing behind the last header for key_r.
bool operator!=(const PluginFrame &lhs, const PluginFrame &rhs)
Comparison based on content.
static std::istream & readFrom(std::istream &stream_r, PluginFrame &frame_r)
static std::ostream & writeTo(std::ostream &stream_r, const PluginFrame &frame_r)
HeaderListIterator headerEnd() const
Return iterator pointing behind the last header.
std::multimap< std::string, std::string > HeaderList
The header list.
std::istream & operator>>(std::istream &str, PluginFrame &obj)
Construct from stream.
bool isAckCommand() const
Convenience to identify an ACK command.
HeaderListIterator headerBegin() const
Return iterator pointing to the 1st header (or headerEnd)
std::ostream & writeTo(std::ostream &stream_r) const
Write frame to stream.
bool hasKey(const std::string &key_r) const
Whether the header list contains at least one entry for key_r.
String related utilities and Regular expression matching.
Easy-to use interface to the ZYPP dependency resolver.
bool operator==(const SetRelation::Enum &lhs, const SetCompare &rhs)
This is an overloaded member function, provided for convenience. It differs from the above function o...
std::ostream & operator<<(std::ostream &str, const SerialNumber &obj)
const Arch Arch_armv7hnl Arch_armv7nhl ZYPP_API
Definition Arch.h:247