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