Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. // snf_sync.cpp
  2. // Copyright (C) 2006 - 2009 ARM Research Labs, LLC.
  3. // See www.armresearch.com for the copyright terms.
  4. // See snf_sync.hpp for details.
  5. #include "snf_sync.hpp"
  6. void snf_sync::construct() { // Encapsulate initial construction.
  7. ClientGBUAlertInitializer.link(ClientGBUAlertHandler); // Link the alert configurators.
  8. ServerGBUAlertInitializer.link(ServerGBUAlertHandler);
  9. SNFWasParsed.setup(ReadWasGood); // Link our configurator to that flag.
  10. SetupReader(); // Configure our reader.
  11. reset(); // and initialize our data.
  12. }
  13. snf_sync::snf_sync() : // Construcing a blank snf_sync.
  14. Reader("snf"), // The Reader looks for "snf"
  15. ReadWasGood(false) { // There has been no good read yet.
  16. construct(); // Internal wiring & initialization.
  17. }
  18. snf_sync::snf_sync(const char* bfr, int len) : // Constructing with a full buffer.
  19. Reader("snf"), // Start with our blank construction.
  20. ReadWasGood(false) {
  21. construct(); // Internal wiring & initialization.
  22. ConfigurationData Data(bfr, len); // Then build ConfigurationData from
  23. Reader.interpret(Data); // the buffer and interpret it.
  24. }
  25. snf_sync::snf_sync(string& input) : // Constructing with a string.
  26. Reader("snf"), // Start with our blank construction.
  27. ReadWasGood(false) {
  28. construct(); // Internal wiring & initialization.
  29. ConfigurationData Data(input.c_str(), input.length()); // Then build ConfigurationData from
  30. Reader.interpret(Data); // the string and interpret it.
  31. }
  32. void snf_sync::SetupReader() { // Configure the reader to recognize
  33. Reader // the snf_sync protocol.
  34. .atEndCall(SNFWasParsed) // Set flag to true when successful.
  35. .Element("<!-- SNFWasParsed -->", ReadWasGood, false).End() // Trick using impossible element name.
  36. .Element("sync")
  37. .Element("challenge")
  38. .Attribute("text", snf_sync_challenge_txt, "")
  39. .End("challenge")
  40. .Element("response")
  41. .Attribute("nodeid", snf_sync_response_nodeid, "")
  42. .Attribute("text", snf_sync_response_text, "")
  43. .End("response")
  44. .Element("error")
  45. .Attribute("message", snf_sync_error_message, "")
  46. .Attribute("code", snf_sync_error_code, 0)
  47. .End("error")
  48. .Element("rulebase")
  49. .Attribute("utc", snf_sync_rulebase_utc, "")
  50. .End("rulebase")
  51. .Element("client")
  52. .atStartCall(ClientGBUAlertInitializer)
  53. .Element("gbu")
  54. .atEndCall(ClientGBUAlertHandler)
  55. .Attribute("time", ClientGBUAlertHandler.Alert_time, "")
  56. .Attribute("ip", ClientGBUAlertHandler.Alert_ip, "")
  57. .Attribute("t", ClientGBUAlertHandler.Alert_t, "Ignore")
  58. .Attribute("b", ClientGBUAlertHandler.Alert_b, 0)
  59. .Attribute("g", ClientGBUAlertHandler.Alert_g, 0)
  60. .End("gbu")
  61. .End("client")
  62. .Element("server")
  63. .atStartCall(ServerGBUAlertInitializer)
  64. .Element("gbu")
  65. .atEndCall(ServerGBUAlertHandler)
  66. .Attribute("time", ServerGBUAlertHandler.Alert_time, "")
  67. .Attribute("ip", ServerGBUAlertHandler.Alert_ip, "")
  68. .Attribute("t", ServerGBUAlertHandler.Alert_t, "Ignore")
  69. .Attribute("b", ServerGBUAlertHandler.Alert_b, 0)
  70. .Attribute("g", ServerGBUAlertHandler.Alert_g, 0)
  71. .End("gbu")
  72. .Element("resync")
  73. .Attribute("secs", snf_sync_server_resync_secs, -1)
  74. .End("resync")
  75. .End("server")
  76. .End("sync")
  77. .End("snf");
  78. }
  79. void snf_sync::reset() { // Reset the reader for new data.
  80. ReadWasGood = false; // There has been no read yet.
  81. Reader.initialize(); // Initialize to the defaults.
  82. };
  83. bool snf_sync::read(const char* bfr, int len) { // To read from a buffer we
  84. ConfigurationData Data(bfr, len); // construct ConfigurationData from
  85. Reader.interpret(Data); // the buffer and interpret it.
  86. return good(); // Return true if it looked good.
  87. }
  88. bool snf_sync::read(string& input) { // To read from a string we
  89. return read(input.c_str(), input.length()); // get the strings buffer and hand off
  90. } // to our buffer read()
  91. bool snf_sync::good() { // True if the Reader finished the
  92. return (true == ReadWasGood); // snf element successfully.
  93. }
  94. bool snf_sync::bad() { // False if the Reader finished the
  95. return (false == ReadWasGood); // snf element successfully.
  96. }
  97. void GBUAlertHandler::operator()(
  98. ConfigurationElement& E, ConfigurationData& D) { // Add an alert.
  99. GBUdbAlert NewAlert; // Create an alert object.
  100. SocketAddress IPAddress; // Grab one of these for a converter.
  101. IPAddress.setAddress(const_cast<char*>(Alert_ip.c_str())); // Conver the IP address to an int.
  102. NewAlert.IP = IPAddress.getAddress(); // Put the IP into it's place.
  103. NewAlert.R.Bad(Alert_b); // Set the bad count on the record.
  104. NewAlert.R.Good(Alert_g); // Set the good count on the record.
  105. strncpy(NewAlert.UTC, Alert_time.c_str(), UTCBufferSize); // Copy the timestamp.
  106. switch(Alert_t.at(0)) { // Use the first byte to set the flag.
  107. case 'U': { // U means Ugly.
  108. NewAlert.R.Flag(Ugly);
  109. break;
  110. }
  111. case 'I': { // I means Ignore.
  112. NewAlert.R.Flag(Ignore);
  113. break;
  114. }
  115. case 'G': { // G means Good.
  116. NewAlert.R.Flag(Good);
  117. break;
  118. }
  119. case 'B': { // B means Bad.
  120. NewAlert.R.Flag(Bad);
  121. break;
  122. }
  123. }
  124. AlertList.push_back(NewAlert); // Push back the new alert.
  125. }
  126. void GBUAlertHandler::reset() { // To reset the handler,
  127. Alert_time = ""; // clear all of the input strings
  128. Alert_ip = ""; // to the empty string and all of
  129. Alert_t = ""; // the input counts to zero.
  130. Alert_b = 0;
  131. Alert_g = 0;
  132. AlertList.clear(); // Clear out the list.
  133. }