15#include <zypp-core/zyppng/base/AutoDisconnect>
39 const auto &parseError = [
this](){
55 while (
_ioDev->bytesAvailable ( ) ) {
60 if ( d.front () ==
'\0' ){
73 const auto ba =
_ioDev->readBufferCount();
74 if ( !
_ioDev->canReadLine() ) {
76 ERR <<
"Received malformed message from peer, CMD line exceeds: " <<
MAX_CMDLEN <<
" bytes" << std::endl;
85 if ( command.empty() ) {
88 WAR <<
"Received empty line before command, ignoring" << std::endl;
101 const auto ba =
_ioDev->readBufferCount();
102 if ( !
_ioDev->canReadLine() ) {
104 ERR <<
"Received malformed message from peer, header line exceeds: " <<
MAX_HDRLEN <<
" bytes" << std::endl;
113 if ( header.empty () ) {
120 std::optional<uint64_t> cLen;
121 if ( !contentLen.empty() ) {
144 ERR <<
"Received malformed message from peer, header format invalid: " << header.asStringView() <<
" (" << e <<
")" << std::endl;
157 const auto reqBytes = (*_pendingBodyLen) + 1;
158 if (
_ioDev->bytesAvailable() < reqBytes )
161 body =
_ioDev->read( reqBytes );
162 if ( body.back () !=
'\0' ) {
163 ERR <<
"Received malformed message from peer: Body was not terminated with \\0" << std::endl;
172 const auto ba =
_ioDev->readBufferCount();
173 if ( !
_ioDev->canReadUntil(
_ioDev->currentReadChannel (),
'\0' ) ) {
182 body =
_ioDev->channelReadUntil(
_ioDev->currentReadChannel (),
'\0' );
234 std::optional<zypp::PluginFrame> res;
236 if( msgName.empty() ) {
242 return msg.command() == msgName;
267 bool receivedInvalidMsg =
false;
269 receivedInvalidMsg =
true;
272 const bool hasMsgName = msgName.size();
273 while ( !receivedInvalidMsg &&
_ioDev->isOpen() &&
_ioDev->canRead() ) {
276 std::optional<zypp::PluginFrame> msg =
nextMessage(msgName);
277 if ( msg )
return msg;
284 if ( !
_ioDev->waitForReadyRead ( -1 ) ) {
294 if ( !
_ioDev->canWrite () )
299 std::ostream output(&ostrbuf);
300 env.writeTo ( output );
303 ERR <<
"Failed to serialize message to stream" << std::endl;
323 while ( cont &&
_ioDev->bytesAvailable() ) {
std::string asString() const
Store and operate with byte count.
Base class for Exception.
const std::string & msg() const
Return the message string provided to the ctor.
Command frame for communication with PluginScript.
static const std::string & contentLengthHeader()
"content-lenght" header name
static auto connectFunc(typename internal::MemberFunction< SenderFunc >::ClassType &s, SenderFunc &&sFun, ReceiverFunc &&rFunc, const Tracker &...trackers)
static auto connect(typename internal::MemberFunction< SenderFunc >::ClassType &s, SenderFunc &&sFun, typename internal::MemberFunction< ReceiverFunc >::ClassType &recv, ReceiverFunc &&rFunc)
SignalProxy< void()> sigReadyRead()
std::shared_ptr< IODevice > Ptr
InvalidMessageReceivedException(const std::string &msg={})
SignalProxy< void()> sigInvalidMessageReceived()
std::optional< int64_t > _pendingBodyLen
Signal< void()> _sigNextMessage
std::optional< zypp::PluginFrame > nextMessage(const std::string &msgName="")
void timeout(const zyppng::Timer &)
std::deque< zypp::PluginFrame > _messages
StompFrameStream(IODevice::Ptr iostr)
std::optional< zypp::PluginFrame > _pendingMessage
SignalProxy< void()> sigMessageReceived()
std::optional< zypp::PluginFrame > nextMessageWait(const std::string &msgName="")
enum zyppng::StompFrameStream::ParserState _parserState
Signal< void()> _sigInvalidMessageReceived
Timer::Ptr _nextMessageTimer
bool sendFrame(const zypp::PluginFrame &message)
The Timer class provides repetitive and single-shot timers.
SignalProxy< void(Timer &t)> sigExpired()
This signal is always emitted when the timer expires.
String related utilities and Regular expression matching.
Namespace intended to collect all environment variables we use.
Iostream related utilities.
Easy-to use interface to the ZYPP dependency resolver.
AutoDispose< void > OnScopeExit
std::optional< T > safe_strtonum(const std::string_view &val)
constexpr auto MAX_HDRLEN
constexpr auto MAX_CMDLEN
constexpr auto MAX_BODYLEN
#define ZYPP_CAUGHT(EXCPT)
Drops a logline telling the Exception was caught (in order to handle it).