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.

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