Implement max syslog message length, as per RFC (1024 bytes total)
This commit is contained in:
@@ -28,11 +28,10 @@ SOFTWARE.
|
|||||||
using namespace boost::posix_time;
|
using namespace boost::posix_time;
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
static time_facet* f = new time_facet("%b %e %H:%M:%S");
|
static const time_facet* f = new time_facet("%b %e %H:%M:%S");
|
||||||
static stringstream ss;
|
|
||||||
|
|
||||||
std::string RFC3164FormattedSyslogMessage::operator()() {
|
std::string RFC3164FormattedSyslogMessage::operator()() {
|
||||||
ss.str("");
|
stringstream ss;
|
||||||
ss.imbue(locale(locale::classic(), f));
|
ss.imbue(locale(locale::classic(), f));
|
||||||
|
|
||||||
ss << "<" << to_string(_message.priority()) << ">";
|
ss << "<" << to_string(_message.priority()) << ">";
|
||||||
@@ -40,5 +39,9 @@ std::string RFC3164FormattedSyslogMessage::operator()() {
|
|||||||
ss << _message.source() << " ";
|
ss << _message.source() << " ";
|
||||||
ss << _message.message();
|
ss << _message.message();
|
||||||
|
|
||||||
return ss.str();
|
string ret = ss.str();
|
||||||
|
if (ret.size() > MAX_LEN) {
|
||||||
|
ret = ret.substr(0, MAX_LEN);
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -42,6 +42,7 @@ public:
|
|||||||
std::string operator()();
|
std::string operator()();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
static const size_t MAX_LEN = 1024;
|
||||||
const SyslogMessage& _message;
|
const SyslogMessage& _message;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -35,4 +35,12 @@ BOOST_AUTO_TEST_CASE(format) {
|
|||||||
RFC3164FormattedSyslogMessage f(m);
|
RFC3164FormattedSyslogMessage f(m);
|
||||||
string s = f();
|
string s = f();
|
||||||
BOOST_CHECK_EQUAL(s, "<162>Sep 2 13:33:11 192.168.0.1 test message");
|
BOOST_CHECK_EQUAL(s, "<162>Sep 2 13:33:11 192.168.0.1 test message");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
BOOST_AUTO_TEST_CASE(long_message_clipping) {
|
||||||
|
stringstream ss("2015-09-02 13:33:11 Local4.Critical 192.168.0.1 1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890");
|
||||||
|
SyslogMessage m(ss);
|
||||||
|
RFC3164FormattedSyslogMessage f(m);
|
||||||
|
string s = f();
|
||||||
|
BOOST_CHECK_EQUAL(s, "<162>Sep 2 13:33:11 192.168.0.1 1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901");
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user