123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180 |
- // SNF4CGP/ConfigurationEngine.hpp
- // Copyright (C) 2009 ARM Research Labs, LLC
- // See www.armresearch.com for more information.
- //
- // This module parses the configuration and keeps track of it's generation.
- // When asked it can produce the appropriate configuration for a given Job
- // based on the scan result that was recieved. If it is asked and the current
- // configuration is out of date then the new configuration is parsed first.
-
- #ifndef IncludedConfigurationEngine
- #define IncludedConfigurationEngine
-
- #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 {
- Bypass,
- Allow,
- Reject,
- Delete,
- Hold
- };
-
- int ResultCode;
- ActionType Action;
- bool InjectHeaders;
- bool EmitXMLLog;
- bool EmitClassicLog;
- string LogComment;
- 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),
- InjectHeaders(false),
- EmitXMLLog(false),
- EmitClassicLog(false),
- LogComment(""),
- RejectionReason(""),
- HoldPath("") {
- }
-
- ResultConfiguration(const ResultConfiguration& R) :
- ResultCode(R.ResultCode),
- Action(R.Action),
- InjectHeaders(R.InjectHeaders),
- EmitXMLLog(R.EmitXMLLog),
- EmitClassicLog(R.EmitClassicLog),
- LogComment(R.LogComment),
- RejectionReason(R.RejectionReason),
- HoldPath(R.HoldPath) {
- }
-
- ResultConfiguration& operator=(const ResultConfiguration& R) {
- ResultCode = R.ResultCode;
- Action = R.Action;
- InjectHeaders = R.InjectHeaders;
- EmitXMLLog = R.EmitXMLLog;
- EmitClassicLog = R.EmitClassicLog;
- LogComment = R.LogComment;
- RejectionReason = R.RejectionReason;
- 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;
- const int ResultConfigurationSize = HighestResultCode + 1;
-
- class ConfigurationManager {
- private:
- snf_RulebaseHandler& Rulebase;
- int Generation_;
- vector<ResultConfiguration> Configurations;
- set<int> ConfiguredCodes;
- bool hasNotBeenConfigured(int& C);
-
- public:
- ConfigurationManager(snf_RulebaseHandler& R);
- bool isOutOfDate();
- void update();
- ResultConfiguration& ConfigurationForResultCode(int Code);
- };
-
- #endif
|