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

scanner.hpp 2.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. // scanner.hpp
  2. //
  3. // (C) 2002-2009 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. #ifndef _MN_Scanner
  26. #define _MN_Scanner
  27. #include "FilterChain.hpp"
  28. #include "snf_engine.hpp"
  29. const int ScanHorizon = 32768; // Maximum length of message to check.
  30. class Scanner {
  31. private:
  32. TokenMatrix RuleBase; // The RuleBase for this scanner.
  33. EvaluationMatrix* myEvaluationMatrix; // Evaluation Matrix for current scan.
  34. public:
  35. class BadMatrixAllocation {}; // Exception for failed allocation.
  36. Scanner() {myEvaluationMatrix=NULL;} // Construct with empty matrix.
  37. ~Scanner() {Reset();} // Destructor now cleans up.
  38. void Reset() { // Reset safely deletes the eval
  39. if(myEvaluationMatrix!=NULL){ // matrix and nulls it's pointer.
  40. delete myEvaluationMatrix;
  41. myEvaluationMatrix=NULL;
  42. }
  43. }
  44. void LoadRuleBase(string& RuleFileName, string& SecurityKey); // Load & Validate RuleBase.
  45. EvaluationMatrix* ScanMessage(unsigned char* MessageBuffer); // Scan with filter chain.
  46. EvaluationMatrix* ScanText(unsigned char* TextBuffer); // Scan without filter chain.
  47. inline EvaluationMatrix* GetMatrix(){return myEvaluationMatrix;} // Return the latest matrix.
  48. };
  49. #endif