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_xci.cpp 7.1KB

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