Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

ConfigurationEngine.hpp 5.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. // SNF4CGP/ConfigurationEngine.hpp
  2. // Copyright (C) 2009 ARM Research Labs, LLC
  3. // See www.armresearch.com for more information.
  4. //
  5. // This module parses the configuration and keeps track of it's generation.
  6. // When asked it can produce the appropriate configuration for a given Job
  7. // based on the scan result that was recieved. If it is asked and the current
  8. // configuration is out of date then the new configuration is parsed first.
  9. #ifndef IncludedConfigurationEngine
  10. #define IncludedConfigurationEngine
  11. #include <string>
  12. #include <vector>
  13. #include <set>
  14. using namespace std;
  15. class snf_RulebaseHandler;
  16. class InputGroup {
  17. public:
  18. static const int NotSet;
  19. static const int SetFalse;
  20. static const int SetTrue;
  21. int Code;
  22. int Action;
  23. int InjectHeaders;
  24. int EmitXMLLog;
  25. int EmitClassicLog;
  26. string LogComment;
  27. string RejectionReason;
  28. string HoldPath;
  29. InputGroup() :
  30. Code(NotSet),
  31. Action(NotSet),
  32. InjectHeaders(NotSet),
  33. EmitXMLLog(NotSet),
  34. EmitClassicLog(NotSet) {}
  35. void reset() {
  36. Code = NotSet;
  37. Action = NotSet;
  38. InjectHeaders = NotSet;
  39. EmitXMLLog = NotSet;
  40. EmitClassicLog = NotSet;
  41. LogComment.clear();
  42. RejectionReason.clear();
  43. HoldPath.clear();
  44. }
  45. bool isSet(int& I) { if(InputGroup::NotSet != I) return true; else return false; }
  46. bool isNotSet(int& I) { if(false == isSet(I)) return true; else return false; }
  47. bool isSet(string& S) { if(0 < S.length()) return true; else return false; }
  48. bool isNotSet(string& S) { if(false == isSet(S)) return true; else return false; }
  49. void applyDefaults(InputGroup& D) {
  50. if(isNotSet(Code) && isSet(D.Code)) Code = D.Code;
  51. if(isNotSet(Action) && isSet(D.Action)) Action = D.Action;
  52. if(isNotSet(InjectHeaders) && isSet(D.InjectHeaders)) InjectHeaders = D.InjectHeaders;
  53. if(isNotSet(EmitXMLLog) && isSet(D.EmitXMLLog)) EmitXMLLog = D.EmitXMLLog;
  54. if(isNotSet(EmitClassicLog) && isSet(D.EmitClassicLog)) EmitClassicLog = D.EmitClassicLog;
  55. if(isNotSet(LogComment) && isSet(D.LogComment)) LogComment = D.LogComment;
  56. if(isNotSet(RejectionReason) && isSet(D.RejectionReason)) RejectionReason = D.RejectionReason;
  57. if(isNotSet(HoldPath) && isSet(D.HoldPath)) HoldPath = D.HoldPath;
  58. }
  59. };
  60. class ResultConfiguration {
  61. public:
  62. enum ActionType {
  63. Bypass,
  64. Allow,
  65. Reject,
  66. Delete,
  67. Hold
  68. };
  69. int ResultCode;
  70. ActionType Action;
  71. bool InjectHeaders;
  72. bool EmitXMLLog;
  73. bool EmitClassicLog;
  74. string LogComment;
  75. string RejectionReason;
  76. string HoldPath;
  77. void clearSettings() {
  78. Action = Bypass;
  79. InjectHeaders = false;
  80. EmitXMLLog = false;
  81. EmitClassicLog = false;
  82. LogComment.clear();
  83. RejectionReason.clear();
  84. HoldPath.clear();
  85. }
  86. ResultConfiguration() :
  87. ResultCode(0),
  88. Action(Bypass),
  89. InjectHeaders(false),
  90. EmitXMLLog(false),
  91. EmitClassicLog(false),
  92. LogComment(""),
  93. RejectionReason(""),
  94. HoldPath("") {
  95. }
  96. ResultConfiguration(const ResultConfiguration& R) :
  97. ResultCode(R.ResultCode),
  98. Action(R.Action),
  99. InjectHeaders(R.InjectHeaders),
  100. EmitXMLLog(R.EmitXMLLog),
  101. EmitClassicLog(R.EmitClassicLog),
  102. LogComment(R.LogComment),
  103. RejectionReason(R.RejectionReason),
  104. HoldPath(R.HoldPath) {
  105. }
  106. ResultConfiguration& operator=(const ResultConfiguration& R) {
  107. ResultCode = R.ResultCode;
  108. Action = R.Action;
  109. InjectHeaders = R.InjectHeaders;
  110. EmitXMLLog = R.EmitXMLLog;
  111. EmitClassicLog = R.EmitClassicLog;
  112. LogComment = R.LogComment;
  113. RejectionReason = R.RejectionReason;
  114. HoldPath = R.HoldPath;
  115. return (*this);
  116. }
  117. ActionType asActionType(const int& I) {
  118. switch(I) {
  119. case Allow: return Allow; break;
  120. case Bypass: return Bypass; break;
  121. case Delete: return Delete; break;
  122. case Hold: return Hold; break;
  123. case Reject: return Reject; break;
  124. default: return Bypass; break;
  125. }
  126. }
  127. bool isSet(const int& I) { if(InputGroup::NotSet != I) return true; else return false; }
  128. bool isSet(const string& S) { if(0 < S.length()) return true; else return false; }
  129. bool asTrueFalse(const int& I) { if(0 < I) return true; else return false; }
  130. ResultConfiguration& operator=(const InputGroup& I) {
  131. if(isSet(I.Action)) Action = asActionType(I.Action);
  132. if(isSet(I.InjectHeaders)) InjectHeaders = asTrueFalse(I.InjectHeaders);
  133. if(isSet(I.EmitXMLLog)) EmitXMLLog = asTrueFalse(I.EmitXMLLog);
  134. if(isSet(I.EmitClassicLog)) EmitClassicLog = asTrueFalse(I.EmitClassicLog);
  135. if(isSet(I.LogComment)) LogComment = I.LogComment;
  136. if(isSet(I.RejectionReason)) RejectionReason = I.RejectionReason;
  137. if(isSet(I.HoldPath)) HoldPath = I.HoldPath;
  138. return (*this);
  139. }
  140. };
  141. const int HighestResultCode = 63;
  142. const int ResultConfigurationSize = HighestResultCode + 1;
  143. class ConfigurationManager {
  144. private:
  145. snf_RulebaseHandler& Rulebase;
  146. int Generation_;
  147. vector<ResultConfiguration> Configurations;
  148. set<int> ConfiguredCodes;
  149. bool hasNotBeenConfigured(int& C);
  150. public:
  151. ConfigurationManager(snf_RulebaseHandler& R);
  152. bool isOutOfDate();
  153. void update();
  154. ResultConfiguration& ConfigurationForResultCode(int Code);
  155. };
  156. #endif