選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

scanner.hpp 2.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. // scanner.hpp
  2. //
  3. // (C) 2002-2020 MicroNeil Research Corporation
  4. // 20040113 _M - Added Reset() to the scanner object to more completely handle
  5. // cleanup after processing a message. Where previously the calling code would
  6. // need to be sure it deleted the evaulation matrix when it was done, now it
  7. // should call Reset. Reset is also included now in the destructor for this
  8. // object.
  9. // 20030928 _M - Moving toward the peer-server architecture and V3. The message
  10. // scanning component has been moved into it's own object called "scanner". From
  11. // now on, a message, or text will be passed to the scanner and the scanner will
  12. // return an evaulation matrix. As always, if something goes wrong it will throw.
  13. // This allows us to separate the creation of a scanner, and it's use, from any
  14. // other nifty logic. So, if I'm in a server mode, I can take my scanner and throw
  15. // messages at it as often as I like. Each message I pump in one side comes out the
  16. // other side as an evaluation matrix. This will work well for SMTP based engines
  17. // as well as peer-server, or any other "service pipeline".
  18. //
  19. // Note that the scanner object has two ways it will accept data. One way is as a
  20. // message via .ScanMessage(c_str). This method employs the filter chain system and
  21. // expects to see an SMTP message. The second way is as plain text via .ScanText(c_str).
  22. // This method is useful for "internal" purposes such as secondary scans used to
  23. // locate compound rules or parameter scans used to pick up tuning data from the
  24. // rulebase.
  25. #pragma once
  26. #include "FilterChain.hpp"
  27. #include "snf_engine.hpp"
  28. const int ScanHorizon = 32768; // Maximum length of message to check.
  29. class Scanner {
  30. private:
  31. TokenMatrix RuleBase; // The RuleBase for this scanner.
  32. EvaluationMatrix* myEvaluationMatrix; // Evaluation Matrix for current scan.
  33. public:
  34. class BadMatrixAllocation {}; // Exception for failed allocation.
  35. Scanner() {myEvaluationMatrix=NULL;} // Construct with empty matrix.
  36. ~Scanner() {Reset();} // Destructor now cleans up.
  37. void Reset() { // Reset safely deletes the eval
  38. if(myEvaluationMatrix!=NULL){ // matrix and nulls it's pointer.
  39. delete myEvaluationMatrix;
  40. myEvaluationMatrix=NULL;
  41. }
  42. }
  43. void LoadRuleBase(std::string& RuleFileName, std::string& SecurityKey); // Load & Validate RuleBase.
  44. EvaluationMatrix* ScanMessage(unsigned char* MessageBuffer); // Scan with filter chain.
  45. EvaluationMatrix* ScanText(unsigned char* TextBuffer); // Scan without filter chain.
  46. inline EvaluationMatrix* GetMatrix(){return myEvaluationMatrix;} // Return the latest matrix.
  47. };