h.addHeader( "" ); // empty KV in header is ok, if you like it
BOOST_CHECK_EQUAL( (g == h), false );
- h.addHeader( "a", "a1" );
- h.addHeader( "a", "a2" );
- h.addHeader( "b", "b1" );
- h.addHeader( "b", "b2" );
- h.addHeader( "c", "c1" );
- h.addHeader( "c", "c1" );
+ h.addHeader({
+ { "a", "a1" },
+ { "a", "a2" },
+ { "b", "b1" },
+ { "b", "b2" },
+ { "c", "c1" },
+ { "c", "c1" }
+ });
BOOST_CHECK_EQUAL( h.headerSize(), 7 );
h.setHeader( "b", "b" ); // replaces existing 'b:" headers
using std::endl;
+#undef ZYPP_BASE_LOGGER_LOGGROUP
+#define ZYPP_BASE_LOGGER_LOGGROUP "zypp::plugin"
+
///////////////////////////////////////////////////////////////////
namespace zypp
{ /////////////////////////////////////////////////////////////////
Impl( const std::string & command_r )
{ setCommand( command_r ); }
- Impl( const std::string & command_r, const std::string body_r )
+ Impl( const std::string & command_r, const std::string & body_r )
: _body( body_r )
{ setCommand( command_r ); }
+ Impl( const std::string & command_r, HeaderInitializerList contents_r )
+ { setCommand( command_r ); addHeader( contents_r ); }
+
+ Impl( const std::string & command_r, const std::string & body_r, HeaderInitializerList contents_r )
+ : _body( body_r )
+ { setCommand( command_r ); addHeader( contents_r ); }
+
Impl( std::istream & stream_r );
public:
_header.insert( mkHeaderPair( key_r, value_r ) );
}
+ void addHeader( HeaderInitializerList contents_r )
+ {
+ for ( const auto & el : contents_r )
+ addHeader( el.first, el.second );
+ }
+
void clearHeader( const std::string & key_r )
{
_header.erase( key_r );
return _val;
}
+ const std::string & PluginFrame::enomethodCommand()
+ {
+ static std::string _val( "_ENOMETHOD" );
+ return _val;
+ }
+
PluginFrame::PluginFrame()
: _pimpl( Impl::nullimpl() )
{}
: _pimpl( new Impl( command_r ) )
{}
- PluginFrame::PluginFrame( const std::string & command_r, const std::string body_r )
+ PluginFrame::PluginFrame( const std::string & command_r, const std::string & body_r )
: _pimpl( new Impl( command_r, body_r ) )
{}
+ PluginFrame::PluginFrame( const std::string & command_r, HeaderInitializerList contents_r )
+ : _pimpl( new Impl( command_r, contents_r ) )
+ {}
+
+ PluginFrame::PluginFrame( const std::string & command_r, const std::string & body_r, HeaderInitializerList contents_r )
+ : _pimpl( new Impl( command_r, body_r, contents_r ) )
+ {}
+
PluginFrame::PluginFrame( std::istream & stream_r )
: _pimpl( new Impl( stream_r ) )
{}
void PluginFrame::addHeader( const std::string & key_r, const std::string & value_r )
{ _pimpl->addHeader( key_r, value_r ); }
+ void PluginFrame::addHeader( HeaderInitializerList contents_r )
+ { _pimpl->addHeader( contents_r ); }
+
void PluginFrame::clearHeader( const std::string & key_r )
{ _pimpl->clearHeader( key_r ); }
friend std::ostream & operator<<( std::ostream & str, const PluginFrame & obj );
friend bool operator==( const PluginFrame & lhs, const PluginFrame & rhs );
+ typedef const std::initializer_list<std::pair<std::string,std::string>> & HeaderInitializerList;
+
public:
/** "ACK" command. */
static const std::string & ackCommand();
/** "ERROR" command. */
static const std::string & errorCommand();
+ /** "_ENOMETHOD" command. */
+ static const std::string & enomethodCommand();
public:
/** Default exception type */
/** Ctor taking command and body
* \throw PluginFrameException If \ref setCommand throws
*/
- PluginFrame( const std::string & command_r, const std::string body_r );
+ PluginFrame( const std::string & command_r, const std::string & body_r );
+
+ /** Ctor taking the command and a HeaderInitializerList
+ * \throw PluginFrameException If \ref setCommand throws
+ */
+ PluginFrame( const std::string & command_r, HeaderInitializerList contents_r );
+
+ /** Ctor taking command, body and a HeaderInitializerList
+ * \throw PluginFrameException If \ref setCommand throws
+ */
+ PluginFrame( const std::string & command_r, const std::string & body_r, HeaderInitializerList contents_r );
/** Ctor reading frame data from a stream
* \throw PluginFrameException On error reading from stream
bool isErrorCommand() const
{return command() == errorCommand(); }
+ /** Convenience to identify an _ENOMETHOD command. */
+ bool isEnomethodCommand() const
+ {return command() == enomethodCommand(); }
+
/** Return the frame body. */
const std::string & body() const;
*/
void setHeader( const std::string & key_r, const std::string & value_r = std::string() );
+ /** Set a new header list
+ * \throw PluginFrameException If key contains illegal chars (\c NL or \c :)
+ * \throw PluginFrameException If value contains illegal chars (\c NL)
+ */
+ void setHeader( HeaderInitializerList contents_r )
+ { headerList().clear(); addHeader( contents_r ); }
+
/** Add header for \c key_r leaving already existing headers for \c key_r unchanged.
* \throw PluginFrameException If key contains illegal chars (\c NL or \c :)
* \throw PluginFrameException If value contains illegal chars (\c NL)
*/
void addHeader( const std::string & key_r, const std::string & value_r = std::string() );
+ /** \overload taking an initializer_list */
+ void addHeader( HeaderInitializerList contents_r );
/** Remove all headers for \c key_r. */
void clearHeader( const std::string & key_r );