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.

snf_sync.hpp 4.3KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. // snf_sync.hpp
  2. // Copyright (C) 2006 - 2009 ARM Research Labs, LLC.
  3. // See www.armresearch.com for the copyright terms.
  4. //
  5. // SNF engine communications protocol interpreter.
  6. // Communications are well formed xml snippets.
  7. // See snf_sync.xml for examples.
  8. #ifndef snf_sync_included
  9. #define snf_sync_included
  10. #include <list>
  11. #include <cstring>
  12. #include "SNFMulti/GBUdb.hpp"
  13. #include "CodeDweller/networking.hpp"
  14. #include "CodeDweller/XMLReader.hpp"
  15. namespace SNFMulti {
  16. class GBUAlertHandler : public CodeDweller::Configurator {
  17. public:
  18. virtual void operator()(CodeDweller::ConfigurationElement& E,
  19. CodeDweller::ConfigurationData& D); // Add an alert handler :-)
  20. void reset(); // Resets the list for a new run.
  21. std::list<GBUdbAlert> AlertList; // Our list of alerts.
  22. // Input variables.
  23. std::string Alert_time; // time='YYYYMMDDhhmmss'
  24. std::string Alert_ip; // ip='12.34.56.78'
  25. std::string Alert_t; // t='Ugly', Good, Bad, Ignore
  26. int Alert_b; // b='0'
  27. int Alert_g; // g='0'
  28. };
  29. class GBUAlertInitializer : public CodeDweller::Configurator {
  30. private:
  31. GBUAlertHandler* MyHandler; // Handler to reset.
  32. public:
  33. GBUAlertInitializer() { MyHandler = NULL; } // Init safely with null.
  34. void link(GBUAlertHandler& H) { MyHandler = &H; } // Link to my handler.
  35. virtual void operator()(CodeDweller::ConfigurationElement& E,
  36. CodeDweller::ConfigurationData& D) { // Add an alert handler :-)
  37. if(NULL != MyHandler) { // If I know where it is
  38. MyHandler->reset(); // I hit the reset button.
  39. }
  40. }
  41. };
  42. class snf_sync {
  43. private:
  44. CodeDweller::ConfigurationElement Reader; // Our reader.
  45. void SetupReader(); // Configure the reader.
  46. CodeDweller::ConfiguratorSetTrueOnComplete SNFWasParsed; // Configurator sets the ReadWasGood
  47. bool ReadWasGood; // flag at the end of the snf element.
  48. void construct(); // Encapsulate the initial construction.
  49. void reset(); // Reset/initialize for the next read.
  50. public:
  51. snf_sync(); // Construct empty.
  52. snf_sync(const char* bfr, int len); // Construct from buffer.
  53. snf_sync(std::string& input); // Construct from string.
  54. bool read(const char* bfr, int len); // Read from buffer.
  55. bool read(std::string& input); // Read from string.
  56. //// And now the interpreted results ////
  57. bool good(); // True if read was good.
  58. bool bad(); // True if read was not good.
  59. std::string snf_sync_challenge_txt;
  60. std::string snf_sync_response_nodeid;
  61. std::string snf_sync_response_text;
  62. std::string snf_sync_error_message;
  63. int snf_sync_error_code;
  64. std::string snf_sync_rulebase_utc;
  65. int snf_sync_server_resync_secs;
  66. GBUAlertHandler ClientGBUAlertHandler; // GBU Alerts received from client
  67. GBUAlertInitializer ClientGBUAlertInitializer;
  68. GBUAlertHandler ServerGBUAlertHandler; // GBU Alerts received from server
  69. GBUAlertInitializer ServerGBUAlertInitializer;
  70. };
  71. } // namespace SNFMulti
  72. #endif