16#include <zypp-core/zyppng/core/String>
20#undef ZYPP_BASE_LOGGER_LOGGROUP
21#define ZYPP_BASE_LOGGER_LOGGROUP "zypp::plugin"
63 if (
command_r.find(
'\n' ) != std::string::npos )
93 for (
auto c = val.begin ();
c!= val.end();
c++ ) {
128 for (
auto c = val.begin ();
c!= val.end(); ) {
136 if (
c == val.end() )
170 using KeyRange = std::pair<HeaderList::iterator, HeaderList::iterator>;
181 if (
r.first ==
r.second )
183 const std::string &
ret(
r.first->second );
184 if ( ++
r.first !=
r.second )
192 if (
r.first ==
r.second )
194 const std::string &
ret(
r.first->second );
195 if ( ++
r.first !=
r.second )
230 std::string::size_type
sep( data.find(
':') );
231 if (
sep == std::string::npos )
261 {
return new Impl( *
this ); }
268 return str <<
"PluginFrame[" <<
obj.command() <<
"](" <<
obj.headerList().size() <<
"){" <<
obj.body().size() <<
"}";
307 std::optional<uint64_t>
cLen;
330 if (
_body.back() !=
'\0' )
360 for_(
it, _header.begin(), _header.end() )
361 stream_r << escapeHeader(
it->first) <<
':' << escapeHeader(
it->second,
false) <<
"\n";
367 stream_r.write( _body.data(), _body.size() );
386 static std::string _val(
"ACK" );
392 static std::string _val(
"ERROR" );
398 static std::string _val(
"_ENOMETHOD" );
404 static std::string _val(
"content-length");
437 {
return _pimpl->empty(); }
440 {
return _pimpl->command(); }
446 {
return _pimpl->body(); }
449 {
return _pimpl->bodyRef(); }
464 {
return _pimpl->headerList(); }
467 {
return _pimpl->headerList(); }
489 _pimpl->addRawHeader( header.asStringView() );
Reference counted access to a Tp object calling a custom Dispose function when the last AutoDispose h...
shared_ptr< Impl > _pimpl
Base class for PluginFrame Exception.
Command frame for communication with PluginScript.
static const std::string & ackCommand()
"ACK" command.
ByteArray & bodyRef()
Return a reference to the frame body.
void setCommand(const std::string &command_r)
Set the frame command.
HeaderList::const_iterator HeaderListIterator
Header list iterator.
void setBody(const std::string &body_r)
Set the frame body.
const std::initializer_list< std::pair< std::string, std::string > > & HeaderInitializerList
PluginFrame()
Default ctor (empty frame)
void clearHeader(const std::string &key_r)
Remove all headers for key_r.
static const std::string & contentLengthHeader()
"content-lenght" header name
bool empty() const
Whether this is an empty frame.
const ByteArray & body() const
Return the frame body.
static const std::string & enomethodCommand()
"_ENOMETHOD" command.
const std::string & command() const
Return the frame command.
void addHeader(const std::string &key_r, const std::string &value_r=std::string())
Add header for key_r leaving already existing headers for key_r unchanged.
RWCOW_pointer< Impl > _pimpl
Pointer to implementation.
static const std::string & errorCommand()
"ERROR" command.
const std::string & getHeader(const std::string &key_r) const
Return header value for key_r.
std::multimap< std::string, std::string > HeaderList
The header list.
HeaderList & headerList()
Modifyalble header list for internal use only.
void addRawHeader(const ByteArray &header)
void setHeader(const std::string &key_r, const std::string &value_r=std::string())
Set header for key_r removing all other occurrences of key_r.
const std::string & getHeaderNT(const std::string &key_r, const std::string &default_r=std::string()) const
Not throwing version returing one of the matching header values or default_r string.
std::ostream & writeTo(std::ostream &stream_r) const
Write frame to stream.
String related utilities and Regular expression matching.
std::string numstring(char n, int w=0)
std::string receiveUpTo(std::istream &str, const char delim_r, bool returnDelim_r)
Return stream content up to the next ocurrence of delim_r or EOF delim_r, if found,...
std::string getline(std::istream &str, const Trim trim_r)
Return stream content up to (but not returning) the next newline.
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)
PluginFrame implementation.
std::ostream & writeTo(std::ostream &stream_r) const
void setCommand(const std::string &command_r)
Impl(const std::string &command_r, HeaderInitializerList contents_r)
const std::string & getHeader(const std::string &key_r) const
static shared_ptr< Impl > nullimpl()
Offer default Impl.
const std::string & command() const
const std::string & getHeaderNT(const std::string &key_r, const std::string &default_r) const
Impl(const std::string &command_r, ByteArray &&body_r)
HeaderList & headerList()
static std::string unescapeHeader(std::string_view val)
Impl(const std::string &command_r)
const HeaderList & headerList() const
std::pair< HeaderListIterator, HeaderListIterator > constKeyRange
const std::string & getHeader(const std::string &key_r, const std::string &default_r) const
void setHeader(const std::string &key_r, const std::string &value_r)
void clearHeader(const std::string &key_r)
void addHeader(const std::string &key_r, const std::string &value_r)
static std::string escapeHeader(std::string_view val, bool escapeColon=true)
std::pair< HeaderList::iterator, HeaderList::iterator > KeyRange
Impl * clone() const
clone for RWCOW_pointer
void addRawHeader(const std::string_view data)
void addHeader(HeaderInitializerList contents_r)
HeaderList::value_type mkHeaderPair(const std::string &key_r, const std::string &value_r)
void setBody(ByteArray &&body_r)
std::ostream & operator<<(std::ostream &str, const PluginFrame::Impl &obj)
Stream output.
Impl(const std::string &command_r, ByteArray &&body_r, HeaderInitializerList contents_r)
const ByteArray & body() const
#define for_(IT, BEG, END)
Convenient for-loops using iterator.
#define ZYPP_THROW(EXCPT)
Drops a logline and throws the Exception.