|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146 |
-
-
-
-
-
- #include "snf_sync.hpp"
-
- void snf_sync::construct() {
- ClientGBUAlertInitializer.link(ClientGBUAlertHandler);
- ServerGBUAlertInitializer.link(ServerGBUAlertHandler);
- SNFWasParsed.setup(ReadWasGood);
- SetupReader();
- reset();
- }
-
- snf_sync::snf_sync() :
- Reader("snf"),
- ReadWasGood(false) {
- construct();
- }
-
- snf_sync::snf_sync(const char* bfr, int len) :
- Reader("snf"),
- ReadWasGood(false) {
- construct();
- ConfigurationData Data(bfr, len);
- Reader.interpret(Data);
- }
-
- snf_sync::snf_sync(string& input) :
- Reader("snf"),
- ReadWasGood(false) {
- construct();
- ConfigurationData Data(input.c_str(), input.length());
- Reader.interpret(Data);
- }
-
- void snf_sync::SetupReader() {
- Reader
- .atEndCall(SNFWasParsed)
- .Element("<!-- SNFWasParsed -->", ReadWasGood, false).End()
- .Element("sync")
- .Element("challenge")
- .Attribute("text", snf_sync_challenge_txt, "")
- .End("challenge")
- .Element("response")
- .Attribute("nodeid", snf_sync_response_nodeid, "")
- .Attribute("text", snf_sync_response_text, "")
- .End("response")
- .Element("error")
- .Attribute("message", snf_sync_error_message, "")
- .Attribute("code", snf_sync_error_code, 0)
- .End("error")
- .Element("rulebase")
- .Attribute("utc", snf_sync_rulebase_utc, "")
- .End("rulebase")
- .Element("client")
- .atStartCall(ClientGBUAlertInitializer)
- .Element("gbu")
- .atEndCall(ClientGBUAlertHandler)
- .Attribute("time", ClientGBUAlertHandler.Alert_time, "")
- .Attribute("ip", ClientGBUAlertHandler.Alert_ip, "")
- .Attribute("t", ClientGBUAlertHandler.Alert_t, "Ignore")
- .Attribute("b", ClientGBUAlertHandler.Alert_b, 0)
- .Attribute("g", ClientGBUAlertHandler.Alert_g, 0)
- .End("gbu")
- .End("client")
- .Element("server")
- .atStartCall(ServerGBUAlertInitializer)
- .Element("gbu")
- .atEndCall(ServerGBUAlertHandler)
- .Attribute("time", ServerGBUAlertHandler.Alert_time, "")
- .Attribute("ip", ServerGBUAlertHandler.Alert_ip, "")
- .Attribute("t", ServerGBUAlertHandler.Alert_t, "Ignore")
- .Attribute("b", ServerGBUAlertHandler.Alert_b, 0)
- .Attribute("g", ServerGBUAlertHandler.Alert_g, 0)
- .End("gbu")
- .Element("resync")
- .Attribute("secs", snf_sync_server_resync_secs, -1)
- .End("resync")
- .End("server")
- .End("sync")
- .End("snf");
- }
-
- void snf_sync::reset() {
- ReadWasGood = false;
- Reader.initialize();
- };
-
- bool snf_sync::read(const char* bfr, int len) {
- ConfigurationData Data(bfr, len);
- Reader.interpret(Data);
- return good();
- }
-
- bool snf_sync::read(string& input) {
- return read(input.c_str(), input.length());
- }
-
- bool snf_sync::good() {
- return (true == ReadWasGood);
- }
-
- bool snf_sync::bad() {
- return (false == ReadWasGood);
- }
-
- void GBUAlertHandler::operator()(
- ConfigurationElement& E, ConfigurationData& D) {
- GBUdbAlert NewAlert;
- SocketAddress IPAddress;
- IPAddress.setAddress(const_cast<char*>(Alert_ip.c_str()));
- NewAlert.IP = IPAddress.getAddress();
- NewAlert.R.Bad(Alert_b);
- NewAlert.R.Good(Alert_g);
- strncpy(NewAlert.UTC, Alert_time.c_str(), UTCBufferSize);
- switch(Alert_t.at(0)) {
- case 'U': {
- NewAlert.R.Flag(Ugly);
- break;
- }
- case 'I': {
- NewAlert.R.Flag(Ignore);
- break;
- }
- case 'G': {
- NewAlert.R.Flag(Good);
- break;
- }
- case 'B': {
- NewAlert.R.Flag(Bad);
- break;
- }
- }
- AlertList.push_back(NewAlert);
- }
-
- void GBUAlertHandler::reset() {
- Alert_time = "";
- Alert_ip = "";
- Alert_t = "";
- Alert_b = 0;
- Alert_g = 0;
- AlertList.clear();
- }
|