Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

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