Improve syslog parsing; Implement basic main loop.
This commit is contained in:
+1
-3
@@ -32,9 +32,7 @@ const std::string Facility::readFromStream(std::istream& src) {
|
||||
if (c == '.') {
|
||||
break;
|
||||
} else {
|
||||
if (c != ' ' && c != '\t') {
|
||||
ret.push_back(c);
|
||||
}
|
||||
ret.push_back(c);
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
|
||||
+3
-8
@@ -28,16 +28,11 @@ SOFTWARE.
|
||||
#include <memory>
|
||||
#include <boost/noncopyable.hpp>
|
||||
|
||||
class Reader : boost::noncopyable {
|
||||
class SyslogMessage;
|
||||
|
||||
class Reader : private boost::noncopyable {
|
||||
public:
|
||||
|
||||
virtual ~Reader() {
|
||||
};
|
||||
|
||||
virtual std::shared_ptr<SyslogMessage> nextMessage() = 0;
|
||||
|
||||
private:
|
||||
|
||||
};
|
||||
|
||||
#endif /* READER_H */
|
||||
|
||||
+2
-2
@@ -30,10 +30,10 @@ SOFTWARE.
|
||||
class Severity {
|
||||
public:
|
||||
|
||||
Severity(const char* src) : Severity(std::string(src)) {
|
||||
Severity(const std::string& src) : _value(readFromString(src)) {
|
||||
};
|
||||
|
||||
Severity(const std::string& src) : _value(readFromString(src)) {
|
||||
Severity(const char* src) : Severity(std::string(src)) {
|
||||
};
|
||||
|
||||
Severity(std::istream& source) : Severity(readFromStream(source)) {
|
||||
|
||||
@@ -23,8 +23,11 @@ SOFTWARE.
|
||||
*/
|
||||
|
||||
#include "SyslogBulkUploader.h"
|
||||
#include "Reader.h"
|
||||
#include "Writer.h"
|
||||
|
||||
SyslogBulkUploader::SyslogBulkUploader() {
|
||||
void SyslogBulkUploader::run() {
|
||||
while (auto msg = _reader.nextMessage()) {
|
||||
_writer.sendMessage(msg);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -27,11 +27,19 @@ SOFTWARE.
|
||||
|
||||
#include <boost/noncopyable.hpp>
|
||||
|
||||
class Reader;
|
||||
class Writer;
|
||||
|
||||
class SyslogBulkUploader : boost::noncopyable {
|
||||
public:
|
||||
SyslogBulkUploader();
|
||||
private:
|
||||
|
||||
SyslogBulkUploader(Reader& reader, Writer& writer) : _reader(reader), _writer(writer) {
|
||||
};
|
||||
void run();
|
||||
|
||||
private:
|
||||
Reader& _reader;
|
||||
Writer& _writer;
|
||||
};
|
||||
|
||||
#endif /* SYSLOGBULKUPLOADER_H */
|
||||
|
||||
@@ -25,14 +25,13 @@ SOFTWARE.
|
||||
#include "SyslogMessage.h"
|
||||
|
||||
void skipWhitespace(std::istream& src) {
|
||||
bool whitespace = true;
|
||||
while (src && whitespace) {
|
||||
while (src) {
|
||||
std::istream::char_type c = src.peek();
|
||||
if (c == ' ' || c == '\t') {
|
||||
src.get();
|
||||
continue;
|
||||
} else {
|
||||
whitespace = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -55,6 +54,7 @@ const boost::posix_time::ptime SyslogMessage::readTimestamp(std::istream& src) {
|
||||
};
|
||||
|
||||
const Facility SyslogMessage::readFacility(std::istream& src) {
|
||||
skipWhitespace(src);
|
||||
return Facility(src);
|
||||
};
|
||||
|
||||
|
||||
@@ -45,22 +45,18 @@ public:
|
||||
};
|
||||
|
||||
const Facility facility() const {
|
||||
|
||||
return _facility;
|
||||
}
|
||||
|
||||
const std::string message() const {
|
||||
|
||||
return _message;
|
||||
}
|
||||
|
||||
const Severity severity() const {
|
||||
|
||||
return _severity;
|
||||
}
|
||||
|
||||
const std::string source() const {
|
||||
|
||||
return _source;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
/*
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2015 Marko Živanović
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
|
||||
|
||||
#ifndef WRITER_H
|
||||
#define WRITER_H
|
||||
|
||||
#include "SyslogMessage.h"
|
||||
|
||||
class Writer : private boost::noncopyable {
|
||||
public:
|
||||
virtual void sendMessage(std::shared_ptr<SyslogMessage>) = 0;
|
||||
};
|
||||
|
||||
#endif /* WRITER_H */
|
||||
|
||||
Reference in New Issue
Block a user