Browse Source

Fixed warnings in SNFMulti

master
Pete McNeil 4 years ago
parent
commit
6ecb537cb4
2 changed files with 27 additions and 25 deletions
  1. 26
    24
      SNFMulti.cpp
  2. 1
    1
      snf_sync.cpp

+ 26
- 24
SNFMulti.cpp View File

@@ -183,27 +183,27 @@ void snf_Reloader::myTask() {
MyRulebase.logThisInfo( // Log our success.
snfReloadContext, snf_SUCCESS, "Success");
}
catch(snf_RulebaseHandler::IgnoreListError) { // If we get an IgnoreListError - say so.
catch(const snf_RulebaseHandler::IgnoreListError&) { // If we get an IgnoreListError - say so.
MyRulebase.logThisError(
snfReloadContext, snf_ERROR_RULE_FILE, "IgnoreListError");
}
catch(snf_RulebaseHandler::ConfigurationError) { // If we get a ConfigurationError - say so.
catch(const snf_RulebaseHandler::ConfigurationError&) { // If we get a ConfigurationError - say so.
MyRulebase.logThisError(
snfReloadContext, snf_ERROR_RULE_FILE, "ConfigurationError");
}
catch(snf_RulebaseHandler::FileError x) { // If we get a FileError - say so.
catch(const snf_RulebaseHandler::FileError&) { // If we get a FileError - say so.
MyRulebase.logThisError(
snfReloadContext, snf_ERROR_RULE_FILE, "FileError");
}
catch(snf_RulebaseHandler::AuthenticationError x) { // If we get a Auth Error - say so.
catch(const snf_RulebaseHandler::AuthenticationError&) { // If we get a Auth Error - say so.
MyRulebase.logThisError(
snfReloadContext, snf_ERROR_RULE_AUTH, "AuthError");
}
catch(snf_RulebaseHandler::Busy x) { // If we get a Busy Exception - say so.
catch(const snf_RulebaseHandler::Busy&) { // If we get a Busy Exception - say so.
MyRulebase.logThisError(
snfReloadContext, snf_ERROR_UNKNOWN, "BusyError");
}
catch(snf_RulebaseHandler::Panic x) { // If we get a Panic - say so.
catch(const snf_RulebaseHandler::Panic&) { // If we get a Panic - say so.
MyRulebase.logThisError(
snfReloadContext, snf_ERROR_UNKNOWN, "PanicError");
}
@@ -284,18 +284,23 @@ int snf_RulebaseHandler::getRetiringCount(){

// FileUTC(FileName) - utility function for tagging the active rulebase

RuntimeCheck GoodTimestampLength("SNFMulti.cpp:FileUTC snprintf(...) != CorrectTimestampLength");

string FileUTC(string FileName) { // Gets a files UTC.
struct stat FileNameStat; // First we need a stat buffer.
string t; // We also need a Timestamp holder.
if(0 != stat(FileName.c_str(), &FileNameStat)) { // If we can't get the stat we
t.append("000000000000"); return t; // will return 000000000000 to
t.append("00000000000000"); return t; // will return all zeroz to
} // make sure we should get the file.
struct tm FileNameTime; // Allocate a time structure.
FileNameTime = *(gmtime(&FileNameStat.st_mtime)); // Copy the file time to it as UTC.

char TimestampBfr[20]; // Timestamp buffer.
const size_t TimestampBufferSize = 16;
char TimestampBfr[TimestampBufferSize]; // Timestamp buffer.

sprintf(TimestampBfr,"%04d%02d%02d%02d%02d%02d", // Format yyyymmddhhmmss
size_t l = snprintf( // Format yyyymmddhhmmss
TimestampBfr, TimestampBufferSize-1,
"%04d%02d%02d%02d%02d%02d",
FileNameTime.tm_year+1900,
FileNameTime.tm_mon+1,
FileNameTime.tm_mday,
@@ -304,6 +309,9 @@ string FileUTC(string FileName) {
FileNameTime.tm_sec
);

const size_t CorrectTimestampLength = 4+2+2+2+2+2;
GoodTimestampLength(l == CorrectTimestampLength);

t.append(TimestampBfr); // Append the timestamp to t
return t; // and return it to the caller.
}
@@ -393,21 +401,18 @@ void snf_RulebaseHandler::_snf_LoadNewRulebase(){
}
} // If nothing threw, we're golden!

catch (TokenMatrix::BadFile) { // BadFile translates to FileError
catch (const TokenMatrix::BadFile&) { // BadFile translates to FileError
throw FileError("_snf_LoadNewRulebase() TokenMatrix::BadFile");
}
catch (TokenMatrix::BadMatrix) { // BadMatrix translates to AuthenticationError
catch (const TokenMatrix::BadMatrix&) { // BadMatrix translates to AuthenticationError
throw AuthenticationError("_snf_LoadNewRulebase() TokenMatrix::BadMatrix");
}
catch (TokenMatrix::BadAllocation) { // BadAllocation translates to AllocationError
catch (const TokenMatrix::BadAllocation&) { // BadAllocation translates to AllocationError
throw AllocationError("_snf_LoadNewRulebase() TokenMatrix::BadAllocation");
}
catch (TokenMatrix::OutOfRange) { // OutOfRange should never happen so PANIC!
catch (const TokenMatrix::OutOfRange&) { // OutOfRange should never happen so PANIC!
throw Panic("_snf_LoadNewRulebase() TokenMatrix::OutOfRange");
}
catch (exception e) {
throw;
}
catch (...) { // Something unpredicted happens? PANIC!
throw Panic("_snf_LoadNewRulebase() TokenMatrix.load() ???");
}
@@ -1587,9 +1592,9 @@ int snf_EngineHandler::scanMessage(
MyScanData.FilteredData.clear(); // Clear the FilteredData buffer.
try { // Watch for exceptions and scan
for(int a = 0; a < snf_ScanHorizon; a++) // the message through the filter
MyScanData.FilteredData.push_back(xb=IZ.GetByte()); // chain into the FilteredData buffer.
MyScanData.FilteredData.push_back(xb=IZ.GetByte()); // chain into the FilteredData buffer.
} // When we run out of data we will
catch(FilterChain::Empty) {} // get the Empty exception and stop.
catch(const FilterChain::Empty&) {} // get the Empty exception and stop.

// Scan each byte in the file up to the horizon or the end of the message.
// If something goes wrong, an exception will be thrown.
@@ -1612,18 +1617,15 @@ int snf_EngineHandler::scanMessage(

DebugInfo = "scanMessage() Scan Data Complete"; // If we panic, here we are.
}
catch(EvaluationMatrix::BadAllocation) { // Check for bad allocation during scan.
catch(const EvaluationMatrix::BadAllocation&) { // Check for bad allocation during scan.
throw AllocationError("EvaluationMatrix::BadAllocation");
}
catch(EvaluationMatrix::MaxEvalsExceeded) { // Check for too many evaluators.
catch(const EvaluationMatrix::MaxEvalsExceeded&) { // Check for too many evaluators.
throw MaxEvals("EvaluationMatrix::MaxEvalsExceeded");
}
catch(EvaluationMatrix::OutOfRange) { // Check for out of range of (bad) matrix.
catch(const EvaluationMatrix::OutOfRange&) { // Check for out of range of (bad) matrix.
throw BadMatrix("EvaluationMatrix::OutOfRange");
}
catch(exception& e) { // Some other known exception?
throw; // rethrow.
}
catch(...){ // In order to prevent thread craziness
throw Panic(DebugInfo); // throw a Panic.
} // The mutex will unlock in the outer try.

+ 1
- 1
snf_sync.cpp View File

@@ -114,7 +114,7 @@ void GBUAlertHandler::operator()(
NewAlert.IP = IPAddress.getAddress(); // Put the IP into it's place.
NewAlert.R.Bad(Alert_b); // Set the bad count on the record.
NewAlert.R.Good(Alert_g); // Set the good count on the record.
strncpy(NewAlert.UTC, Alert_time.c_str(), UTCBufferSize); // Copy the timestamp.
strncpy(NewAlert.UTC, Alert_time.c_str(), UTCBufferSize-1); // Copy the timestamp.
switch(Alert_t.at(0)) { // Use the first byte to set the flag.
case 'U': { // U means Ugly.
NewAlert.R.Flag(Ugly);

Loading…
Cancel
Save