Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. // snf_xci.hpp
  2. // Copyright (C) 2006 - 2009 ARM Research Labs, LLC
  3. // See www.armresearch.com for the copyright terms.
  4. //
  5. // SNF XML Command Interface
  6. // See snf_xci.hpp for details / notes.
  7. #include "snf_xci.hpp"
  8. namespace cd = codedweller;
  9. //// snf_xci Interpreter Object ////////////////////////////////////////////////
  10. snf_xci::snf_xci() : // Construcing a blank snf_xci.
  11. Reader("snf"), // The Reader looks for "snf"
  12. ReadWasGood(false) { // There has been no good read yet.
  13. SNFWasParsed.setup(ReadWasGood); // Link our configurator to that flag.
  14. SetupReader(); // Configure our reader.
  15. reset(); // and initialize our data.
  16. }
  17. snf_xci::snf_xci(const char* bfr, int len) : // Constructing with a full buffer.
  18. Reader("snf"), // Start with our blank construction.
  19. ReadWasGood(false) {
  20. SNFWasParsed.setup(ReadWasGood);
  21. SetupReader();
  22. reset();
  23. cd::ConfigurationData Data(bfr, len); // Then build ConfigurationData from
  24. Reader.interpret(Data); // the buffer and interpret it.
  25. }
  26. snf_xci::snf_xci(std::string& input) : // Constructing with a string.
  27. Reader("snf"), // Start with our blank construction.
  28. ReadWasGood(false) {
  29. SNFWasParsed.setup(ReadWasGood);
  30. SetupReader();
  31. reset();
  32. cd::ConfigurationData Data(input.c_str(), input.length()); // Then build ConfigurationData from
  33. Reader.interpret(Data); // the string and interpret it.
  34. }
  35. void snf_xci::SetupReader() { // Configure the reader to recognize
  36. Reader // the snf_xci protocol.
  37. .setInitOnInterpret()
  38. .atEndCall(SNFWasParsed) // Set flag to true when successful.
  39. .Element("<!-- SNFWasParsed -->", ReadWasGood, false).End() // Trick using impossible element name.
  40. .Element("xci")
  41. .Element("scanner")
  42. .Element("scan")
  43. .Attribute("file", scanner_scan_file,"")
  44. .Attribute("xhdr", scanner_scan_xhdr, false)
  45. .Attribute("log", scanner_scan_log, false)
  46. .Attribute("ip", scanner_scan_ip, "")
  47. .End("scan")
  48. .Element("result")
  49. .Attribute("code", scanner_result_code,0)
  50. .Element("xhdr", scanner_result_xhdr, "")
  51. .End("xhdr")
  52. .Element("log", scanner_result_log, "")
  53. .End("log")
  54. .End("result")
  55. .End("scanner")
  56. .Element("gbudb")
  57. .Element("set")
  58. .Attribute("ip", gbudb_set_ip, "")
  59. .Attribute("type", gbudb_set_type, "")
  60. .Attribute("b", gbudb_set_bad_count, -1)
  61. .Attribute("g", gbudb_set_good_count, -1)
  62. .End("set")
  63. .Element("good")
  64. .Attribute("ip", gbudb_good_ip, "")
  65. .End("good")
  66. .Element("bad")
  67. .Attribute("ip", gbudb_bad_ip, "")
  68. .End("bad")
  69. .Element("test")
  70. .Attribute("ip", gbudb_test_ip, "")
  71. .End("test")
  72. .Element("drop")
  73. .Attribute("ip", gbudb_drop_ip, "")
  74. .End("drop")
  75. .Element("result")
  76. .Attribute("ip", gbudb_result_ip, "")
  77. .Attribute("type", gbudb_result_type, "")
  78. .Attribute("p", gbudb_result_probability, 0.0)
  79. .Attribute("c", gbudb_result_confidence, 0.0)
  80. .Attribute("b", gbudb_result_bad_count, -1)
  81. .Attribute("g", gbudb_result_good_count, -1)
  82. .Attribute("range", gbudb_result_range, "")
  83. .Attribute("code", gbudb_result_code, 0)
  84. .End("result")
  85. .End("gbudb")
  86. .Element("report")
  87. .Element("request")
  88. .Element("status")
  89. .Attribute("class", report_request_status_class, "")
  90. .End("status")
  91. .End("request")
  92. .Element("response", report_response, "")
  93. .End("response")
  94. .End("report")
  95. .Element("server")
  96. .Element("command", xci_server_command_content, "")
  97. .Attribute("command", xci_server_command, "")
  98. .End("command")
  99. .Element("response")
  100. .Attribute("message", xci_server_response, "")
  101. .Attribute("code", xci_server_response_code, -1)
  102. .End("response")
  103. .End("server")
  104. .Element("error")
  105. .Attribute("message", xci_error_message, "")
  106. .End("error")
  107. .End("xci")
  108. .End("snf");
  109. }
  110. void snf_xci::reset() { // Reset the reader for new data.
  111. ReadWasGood = false; // There has been no read yet.
  112. Reader.initialize(); // Initialize to the defaults.
  113. };
  114. bool snf_xci::read(const char* bfr, int len) { // To read from a buffer we
  115. cd::ConfigurationData Data(bfr, len); // construct ConfigurationData from
  116. Reader.interpret(Data); // the buffer and interpret it.
  117. return good(); // Return true if it looked good.
  118. }
  119. bool snf_xci::read(std::string& input) { // To read from a string we
  120. return read(input.c_str(), input.length()); // get the strings buffer and hand off
  121. } // to our buffer read()
  122. bool snf_xci::good() { // True if the Reader finished the
  123. return (true == ReadWasGood); // snf element successfully.
  124. }
  125. bool snf_xci::bad() { // False if the Reader finished the
  126. return (false == ReadWasGood); // snf element successfully.
  127. }