2019-02-25 08:48:22 -05:00
|
|
|
/* Icinga 2 | (c) 2012 Icinga GmbH | GPLv2+ */
|
2012-05-10 06:06:41 -04:00
|
|
|
|
2012-04-02 02:56:30 -04:00
|
|
|
#ifndef NETSTRING_H
|
|
|
|
|
#define NETSTRING_H
|
2012-03-28 07:24:49 -04:00
|
|
|
|
2014-05-25 10:23:35 -04:00
|
|
|
#include "base/i2-base.hpp"
|
|
|
|
|
#include "base/stream.hpp"
|
2019-02-18 09:21:50 -05:00
|
|
|
#include "base/tlsstream.hpp"
|
|
|
|
|
#include <memory>
|
|
|
|
|
#include <boost/asio/spawn.hpp>
|
2013-03-16 16:18:53 -04:00
|
|
|
|
2012-03-28 07:24:49 -04:00
|
|
|
namespace icinga
|
|
|
|
|
{
|
|
|
|
|
|
2014-12-15 04:16:06 -05:00
|
|
|
class String;
|
|
|
|
|
|
2012-05-18 16:21:28 -04:00
|
|
|
/**
|
2012-09-19 06:32:39 -04:00
|
|
|
* Helper functions for reading/writing messages in the netstring format.
|
2012-05-19 05:04:52 -04:00
|
|
|
*
|
2017-04-06 16:20:20 -04:00
|
|
|
* @see https://cr.yp.to/proto/netstrings.txt
|
2012-05-18 16:21:28 -04:00
|
|
|
*
|
2012-07-24 07:13:02 -04:00
|
|
|
* @ingroup base
|
2012-05-18 16:21:28 -04:00
|
|
|
*/
|
2017-12-31 01:22:16 -05:00
|
|
|
class NetString
|
2012-03-28 07:24:49 -04:00
|
|
|
{
|
2012-05-18 05:32:30 -04:00
|
|
|
public:
|
2018-03-01 03:47:29 -05:00
|
|
|
static StreamReadStatus ReadStringFromStream(const Stream::Ptr& stream, String *message, StreamReadContext& context,
|
|
|
|
|
bool may_wait = false, ssize_t maxMessageLength = -1);
|
2019-07-25 08:34:29 -04:00
|
|
|
static String ReadStringFromStream(const Shared<AsioTlsStream>::Ptr& stream, ssize_t maxMessageLength = -1);
|
|
|
|
|
static String ReadStringFromStream(const Shared<AsioTlsStream>::Ptr& stream,
|
2019-02-19 05:20:39 -05:00
|
|
|
boost::asio::yield_context yc, ssize_t maxMessageLength = -1);
|
2017-11-13 10:26:21 -05:00
|
|
|
static size_t WriteStringToStream(const Stream::Ptr& stream, const String& message);
|
2019-07-25 08:34:29 -04:00
|
|
|
static size_t WriteStringToStream(const Shared<AsioTlsStream>::Ptr& stream, const String& message);
|
|
|
|
|
static size_t WriteStringToStream(const Shared<AsioTlsStream>::Ptr& stream, const String& message, boost::asio::yield_context yc);
|
2016-08-20 17:46:44 -04:00
|
|
|
static void WriteStringToStream(std::ostream& stream, const String& message);
|
2012-05-21 17:42:54 -04:00
|
|
|
|
|
|
|
|
private:
|
2018-01-03 22:25:35 -05:00
|
|
|
NetString();
|
2012-03-28 07:24:49 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2012-04-02 02:56:30 -04:00
|
|
|
#endif /* NETSTRING_H */
|