You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

scanner.hpp 3.0KB

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