Parcourir la source

Completed ConfigurationEngine

Cleaned up for production testing


git-svn-id: https://svn.microneil.com/svn/SNF4CGP/trunk@31 59e8e3e7-56fa-483b-b4b4-fa6ab0af3dfc
master
madscientist il y a 15 ans
Parent
révision
14e9da2854
3 fichiers modifiés avec 333 ajouts et 8 suppressions
  1. 241
    6
      SNF4CGP/ConfigurationEngine.cpp
  2. 90
    0
      SNF4CGP/ConfigurationEngine.hpp
  3. 2
    2
      SNF4CGP/JobPool.cpp

+ 241
- 6
SNF4CGP/ConfigurationEngine.cpp Voir le fichier

@@ -4,23 +4,258 @@
#include "ConfigurationEngine.hpp"
#include "..\SNFMulti\SNFMulti.hpp"
#include "..\CodeDweller\configuration.hpp"
using namespace std;
const int InputGroup::NotSet = -1;
const int InputGroup::SetFalse = 0;
const int InputGroup::SetTrue = 1;
ConfigurationManager::ConfigurationManager(snf_RulebaseHandler& R) :
Rulebase(R),
Generation_(0),
Configurations(ResultConfigurationSize) {
for(size_t i = 0; i < Configurations.size(); i++) {
Configurations[i].ResultCode = i;
}
Rulebase(R),
Generation_(0),
Configurations(ResultConfigurationSize) {
for(size_t i = 0; i < Configurations.size(); i++) {
Configurations[i].ResultCode = i;
}
}
bool ConfigurationManager::isOutOfDate() {
return (Generation_ != Rulebase.Generation());
}
class ResultActionHandler : public Configurator {
private:
vector<ResultConfiguration>& Configurations;
InputGroup& Defaults;
InputGroup& Inputs;
set<int>& ConfiguredCodes;
bool isValidCode(int I) {
if(
0 <= I &&
I < (int) Configurations.size()
) return true;
else return false;
}
public:
ResultActionHandler( // ResultHanlder Constructed with...
vector<ResultConfiguration>& C, // Reference to the configuration vector,
InputGroup& D, // Defaults InputGroup,
InputGroup& I, // Code specific InputGroup,
set<int>& T) : // Configured Codes Tracker.
Configurations(C),
Defaults(D),
Inputs(I),
ConfiguredCodes(T) {}
void operator()(ConfigurationElement& E, ConfigurationData& D) {
Inputs.applyDefaults(Defaults);
if(isValidCode(Inputs.Code)) {
Configurations[Inputs.Code] = Inputs;
ConfiguredCodes.insert(Inputs.Code);
}
Inputs.reset();
}
};
string IntAsString(int I) {
ostringstream O;
O << I;
return O.str();
}
bool isHamResultCode(int& I) {
return (
0 == I ||
1 == I
);
}
bool ConfigurationManager::hasNotBeenConfigured(int& Code) {
return (
ConfiguredCodes.end() == ConfiguredCodes.find(Code)
);
}
void ConfigurationManager::update() {
for(size_t i = 0; i < Configurations.size(); i++) Configurations[i].clearSettings();
InputGroup HamInputDefaults;
InputGroup SpamInputDefaults;
InputGroup CurrentInputs;
ConfiguredCodes.clear();
ResultActionHandler HamResultHandler(Configurations, HamInputDefaults, CurrentInputs, ConfiguredCodes);
ResultActionHandler SpamResultHandler(Configurations, SpamInputDefaults, CurrentInputs, ConfiguredCodes);
const string AllowMnemonic = IntAsString(ResultConfiguration::Allow);
const string BypassMnemonic = IntAsString(ResultConfiguration::Bypass);
const string DeleteMnemonic = IntAsString(ResultConfiguration::Delete);
const string HoldMnemonic = IntAsString(ResultConfiguration::Hold);
const string RejectMnemonic = IntAsString(ResultConfiguration::Reject);
const string SetTrueMnemonic = IntAsString(InputGroup::SetTrue);
const string SetFalseMnemonic = IntAsString(InputGroup::SetFalse);
const string NotSetMnemonic = IntAsString(InputGroup::NotSet);
ConfigurationElement Reader("snf4cgp");
Reader
.Element("ham")
.Attribute("code", HamInputDefaults.Code , InputGroup::NotSet)
.Attribute("action", HamInputDefaults.Action, InputGroup::NotSet)
.Mnemonic("Allow", AllowMnemonic)
.Mnemonic("Bypass", BypassMnemonic)
.Mnemonic("Delete", DeleteMnemonic)
.Mnemonic("Hold", HoldMnemonic)
.Mnemonic("Reject", RejectMnemonic)
.Mnemonic("allow", AllowMnemonic)
.Mnemonic("bypass", BypassMnemonic)
.Mnemonic("delete", DeleteMnemonic)
.Mnemonic("hold", HoldMnemonic)
.Mnemonic("reject", RejectMnemonic)
.Attribute("headers", HamInputDefaults.InjectHeaders, InputGroup::NotSet)
.Mnemonic("Yes", SetTrueMnemonic)
.Mnemonic("No", SetFalseMnemonic)
.Mnemonic("yes", SetTrueMnemonic)
.Mnemonic("no", SetFalseMnemonic)
.Attribute("classic", HamInputDefaults.EmitClassicLog, InputGroup::NotSet)
.Mnemonic("Yes", SetTrueMnemonic)
.Mnemonic("No", SetFalseMnemonic)
.Mnemonic("yes", SetTrueMnemonic)
.Mnemonic("no", SetFalseMnemonic)
.Attribute("xml", HamInputDefaults.EmitXMLLog, InputGroup::NotSet)
.Mnemonic("Yes", SetTrueMnemonic)
.Mnemonic("No", SetFalseMnemonic)
.Mnemonic("yes", SetTrueMnemonic)
.Mnemonic("no", SetFalseMnemonic)
.Attribute("comment", HamInputDefaults.LogComment, "")
.Attribute("reason", HamInputDefaults.RejectionReason, "")
.Attribute("hold-path", HamInputDefaults.HoldPath, "")
.Element("result")
.atEndCall(HamResultHandler)
.Attribute("code", CurrentInputs.Code, InputGroup::NotSet)
.Attribute("action", CurrentInputs.Action, InputGroup::NotSet)
.Mnemonic("Allow", AllowMnemonic)
.Mnemonic("Bypass", BypassMnemonic)
.Mnemonic("Delete", DeleteMnemonic)
.Mnemonic("Hold", HoldMnemonic)
.Mnemonic("Reject", RejectMnemonic)
.Mnemonic("allow", AllowMnemonic)
.Mnemonic("bypass", BypassMnemonic)
.Mnemonic("delete", DeleteMnemonic)
.Mnemonic("hold", HoldMnemonic)
.Mnemonic("reject", RejectMnemonic)
.Attribute("headers", CurrentInputs.InjectHeaders, InputGroup::NotSet)
.Mnemonic("Yes", SetTrueMnemonic)
.Mnemonic("No", SetFalseMnemonic)
.Mnemonic("yes", SetTrueMnemonic)
.Mnemonic("no", SetFalseMnemonic)
.Attribute("classic", CurrentInputs.EmitClassicLog, InputGroup::NotSet)
.Mnemonic("Yes", SetTrueMnemonic)
.Mnemonic("No", SetFalseMnemonic)
.Mnemonic("yes", SetTrueMnemonic)
.Mnemonic("no", SetFalseMnemonic)
.Attribute("xml", CurrentInputs.EmitXMLLog, InputGroup::NotSet)
.Mnemonic("Yes", SetTrueMnemonic)
.Mnemonic("No", SetFalseMnemonic)
.Mnemonic("yes", SetTrueMnemonic)
.Mnemonic("no", SetFalseMnemonic)
.Attribute("comment", CurrentInputs.LogComment, "")
.Attribute("reason", CurrentInputs.RejectionReason, "")
.Attribute("hold-path", CurrentInputs.HoldPath, "")
.End("result")
.End("ham")
.Element("spam")
.Attribute("code", SpamInputDefaults.Code , InputGroup::NotSet)
.Attribute("action", SpamInputDefaults.Action, InputGroup::NotSet)
.Mnemonic("Allow", AllowMnemonic)
.Mnemonic("Bypass", BypassMnemonic)
.Mnemonic("Delete", DeleteMnemonic)
.Mnemonic("Hold", HoldMnemonic)
.Mnemonic("Reject", RejectMnemonic)
.Mnemonic("allow", AllowMnemonic)
.Mnemonic("bypass", BypassMnemonic)
.Mnemonic("delete", DeleteMnemonic)
.Mnemonic("hold", HoldMnemonic)
.Mnemonic("reject", RejectMnemonic)
.Attribute("headers", SpamInputDefaults.InjectHeaders, InputGroup::NotSet)
.Mnemonic("Yes", SetTrueMnemonic)
.Mnemonic("No", SetFalseMnemonic)
.Mnemonic("yes", SetTrueMnemonic)
.Mnemonic("no", SetFalseMnemonic)
.Attribute("classic", SpamInputDefaults.EmitClassicLog, InputGroup::NotSet)
.Mnemonic("Yes", SetTrueMnemonic)
.Mnemonic("No", SetFalseMnemonic)
.Mnemonic("yes", SetTrueMnemonic)
.Mnemonic("no", SetFalseMnemonic)
.Attribute("xml", SpamInputDefaults.EmitXMLLog, InputGroup::NotSet)
.Mnemonic("Yes", SetTrueMnemonic)
.Mnemonic("No", SetFalseMnemonic)
.Mnemonic("yes", SetTrueMnemonic)
.Mnemonic("no", SetFalseMnemonic)
.Attribute("comment", SpamInputDefaults.LogComment, "")
.Attribute("reason", SpamInputDefaults.RejectionReason, "")
.Attribute("hold-path", SpamInputDefaults.HoldPath, "")
.Element("result")
.atEndCall(SpamResultHandler)
.Attribute("code", CurrentInputs.Code , InputGroup::NotSet)
.Attribute("action", CurrentInputs.Action, InputGroup::NotSet)
.Mnemonic("Allow", AllowMnemonic)
.Mnemonic("Bypass", BypassMnemonic)
.Mnemonic("Delete", DeleteMnemonic)
.Mnemonic("Hold", HoldMnemonic)
.Mnemonic("Reject", RejectMnemonic)
.Mnemonic("allow", AllowMnemonic)
.Mnemonic("bypass", BypassMnemonic)
.Mnemonic("delete", DeleteMnemonic)
.Mnemonic("hold", HoldMnemonic)
.Mnemonic("reject", RejectMnemonic)
.Attribute("headers", CurrentInputs.InjectHeaders, InputGroup::NotSet)
.Mnemonic("Yes", SetTrueMnemonic)
.Mnemonic("No", SetFalseMnemonic)
.Mnemonic("yes", SetTrueMnemonic)
.Mnemonic("no", SetFalseMnemonic)
.Attribute("classic", CurrentInputs.EmitClassicLog, InputGroup::NotSet)
.Mnemonic("Yes", SetTrueMnemonic)
.Mnemonic("No", SetFalseMnemonic)
.Mnemonic("yes", SetTrueMnemonic)
.Mnemonic("no", SetFalseMnemonic)
.Attribute("xml", CurrentInputs.EmitXMLLog, InputGroup::NotSet)
.Mnemonic("Yes", SetTrueMnemonic)
.Mnemonic("No", SetFalseMnemonic)
.Mnemonic("yes", SetTrueMnemonic)
.Mnemonic("no", SetFalseMnemonic)
.Attribute("comment", CurrentInputs.LogComment, "")
.Attribute("reason", CurrentInputs.RejectionReason, "")
.Attribute("hold-path", CurrentInputs.HoldPath, "")
.End("result")
.End("spam")
.End("snf4cgp");
string CFG = Rulebase.PlatformConfiguration();
ConfigurationData Data(CFG.c_str(), CFG.length());
Reader.initialize();
Reader.interpret(Data);
//// Establish appropriate defaults for any codes that weren't explicitly configured.
for(size_t i = 0; i < Configurations.size(); i++) {
ResultConfiguration& M = Configurations[i];
if(hasNotBeenConfigured(M.ResultCode)) {
if(isHamResultCode(M.ResultCode)) {
M = HamInputDefaults;
} else {
M = SpamInputDefaults;
}
}
}
Generation_ = Rulebase.Generation();
}
const int OutOfRangeDefaultCode = 0;

+ 90
- 0
SNF4CGP/ConfigurationEngine.hpp Voir le fichier

@@ -12,11 +12,63 @@
#include <string>
#include <vector>
#include <set>
using namespace std;
class snf_RulebaseHandler;
class InputGroup {
public:
static const int NotSet;
static const int SetFalse;
static const int SetTrue;
int Code;
int Action;
int InjectHeaders;
int EmitXMLLog;
int EmitClassicLog;
string LogComment;
string RejectionReason;
string HoldPath;
InputGroup() :
Code(NotSet),
Action(NotSet),
InjectHeaders(NotSet),
EmitXMLLog(NotSet),
EmitClassicLog(NotSet) {}
void reset() {
Code = NotSet;
Action = NotSet;
InjectHeaders = NotSet;
EmitXMLLog = NotSet;
EmitClassicLog = NotSet;
LogComment.clear();
RejectionReason.clear();
HoldPath.clear();
}
bool isSet(int& I) { if(InputGroup::NotSet != I) return true; else return false; }
bool isNotSet(int& I) { if(false == isSet(I)) return true; else return false; }
bool isSet(string& S) { if(0 < S.length()) return true; else return false; }
bool isNotSet(string& S) { if(false == isSet(S)) return true; else return false; }
void applyDefaults(InputGroup& D) {
if(isNotSet(Code) && isSet(D.Code)) Code = D.Code;
if(isNotSet(Action) && isSet(D.Action)) Action = D.Action;
if(isNotSet(InjectHeaders) && isSet(D.InjectHeaders)) InjectHeaders = D.InjectHeaders;
if(isNotSet(EmitXMLLog) && isSet(D.EmitXMLLog)) EmitXMLLog = D.EmitXMLLog;
if(isNotSet(EmitClassicLog) && isSet(D.EmitClassicLog)) EmitClassicLog = D.EmitClassicLog;
if(isNotSet(LogComment) && isSet(D.LogComment)) LogComment = D.LogComment;
if(isNotSet(RejectionReason) && isSet(D.RejectionReason)) RejectionReason = D.RejectionReason;
if(isNotSet(HoldPath) && isSet(D.HoldPath)) HoldPath = D.HoldPath;
}
};
class ResultConfiguration {
public:
enum ActionType {
@@ -36,6 +88,16 @@ class ResultConfiguration {
string RejectionReason;
string HoldPath;
void clearSettings() {
Action = Bypass;
InjectHeaders = false;
EmitXMLLog = false;
EmitClassicLog = false;
LogComment.clear();
RejectionReason.clear();
HoldPath.clear();
}
ResultConfiguration() :
ResultCode(0),
Action(Bypass),
@@ -69,6 +131,32 @@ class ResultConfiguration {
HoldPath = R.HoldPath;
return (*this);
}
ActionType asActionType(const int& I) {
switch(I) {
case Allow: return Allow; break;
case Bypass: return Bypass; break;
case Delete: return Delete; break;
case Hold: return Hold; break;
case Reject: return Reject; break;
default: return Bypass; break;
}
}
bool isSet(const int& I) { if(InputGroup::NotSet != I) return true; else return false; }
bool isSet(const string& S) { if(0 < S.length()) return true; else return false; }
bool asTrueFalse(const int& I) { if(0 < I) return true; else return false; }
ResultConfiguration& operator=(const InputGroup& I) {
if(isSet(I.Action)) Action = asActionType(I.Action);
if(isSet(I.InjectHeaders)) InjectHeaders = asTrueFalse(I.InjectHeaders);
if(isSet(I.EmitXMLLog)) EmitXMLLog = asTrueFalse(I.EmitXMLLog);
if(isSet(I.EmitClassicLog)) EmitClassicLog = asTrueFalse(I.EmitClassicLog);
if(isSet(I.LogComment)) LogComment = I.LogComment;
if(isSet(I.RejectionReason)) RejectionReason = I.RejectionReason;
if(isSet(I.HoldPath)) HoldPath = I.HoldPath;
return (*this);
}
};
const int HighestResultCode = 63;
@@ -79,6 +167,8 @@ class ConfigurationManager {
snf_RulebaseHandler& Rulebase;
int Generation_;
vector<ResultConfiguration> Configurations;
set<int> ConfiguredCodes;
bool hasNotBeenConfigured(int& C);
public:
ConfigurationManager(snf_RulebaseHandler& R);

+ 2
- 2
SNF4CGP/JobPool.cpp Voir le fichier

@@ -195,7 +195,7 @@ void Job::setConfigurationFromScanResult(ScopeScanner& myScanner) {
FaultIfSettingScanResultConfigBeforeScan(NoScanYet == ScanResultCode);
ScanResultConfiguration = Scanners.ConfigurationForResultCode(ScanResultCode);
//// Testing -- forcing scan results
/*//// Testing -- forcing scan results
ScanResultConfiguration.Action = ResultConfiguration::Hold;
ScanResultConfiguration.HoldPath = "C:\\M\\Projects\\MessageSniffer\\SNF4CGP_Work\\TestEnvironment\\hold\\";
@@ -205,7 +205,7 @@ void Job::setConfigurationFromScanResult(ScopeScanner& myScanner) {
ScanResultConfiguration.EmitClassicLog = false;
ScanResultConfiguration.InjectHeaders = true;
///////////////////////////////////////////////////////////////////////
*///////////////////////////////////////////////////////////////////////
if(ScanResultConfiguration.InjectHeaders) HeadersToInject = myScanner.Engine().getXHDRs();
if(ScanResultConfiguration.EmitXMLLog) XMLLogData = myScanner.Engine().getXMLLog();

Chargement…
Annuler
Enregistrer