hinfo_13.cc 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. // Copyright (C) 2011 Internet Systems Consortium, Inc. ("ISC")
  2. //
  3. // Permission to use, copy, modify, and/or distribute this software for any
  4. // purpose with or without fee is hereby granted, provided that the above
  5. // copyright notice and this permission notice appear in all copies.
  6. //
  7. // THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
  8. // REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
  9. // AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
  10. // INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
  11. // LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
  12. // OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  13. // PERFORMANCE OF THIS SOFTWARE.
  14. #include <config.h>
  15. #include <string>
  16. #include <boost/lexical_cast.hpp>
  17. #include <exceptions/exceptions.h>
  18. #include <dns/name.h>
  19. #include <dns/messagerenderer.h>
  20. #include <dns/rdata.h>
  21. #include <dns/rdataclass.h>
  22. #include <dns/character_string.h>
  23. #include <util/strutil.h>
  24. using namespace std;
  25. using namespace boost;
  26. using namespace isc::util;
  27. using namespace isc::dns;
  28. using namespace isc::dns::characterstr;
  29. // BEGIN_ISC_NAMESPACE
  30. // BEGIN_RDATA_NAMESPACE
  31. HINFO::HINFO(const std::string& hinfo_str) {
  32. string::const_iterator input_iterator = hinfo_str.begin();
  33. cpu_ = getNextCharacterString(hinfo_str, input_iterator);
  34. skipLeftSpaces(hinfo_str, input_iterator);
  35. os_ = getNextCharacterString(hinfo_str, input_iterator);
  36. }
  37. HINFO::HINFO(InputBuffer& buffer, size_t rdata_len) {
  38. cpu_ = getNextCharacterString(buffer, rdata_len);
  39. os_ = getNextCharacterString(buffer, rdata_len);
  40. }
  41. HINFO::HINFO(const HINFO& source):
  42. Rdata(), cpu_(source.cpu_), os_(source.os_)
  43. {
  44. }
  45. std::string
  46. HINFO::toText() const {
  47. string result;
  48. result += "\"";
  49. result += cpu_;
  50. result += "\" \"";
  51. result += os_;
  52. result += "\"";
  53. return (result);
  54. }
  55. void
  56. HINFO::toWire(OutputBuffer& buffer) const {
  57. toWireHelper(buffer);
  58. }
  59. void
  60. HINFO::toWire(AbstractMessageRenderer& renderer) const {
  61. toWireHelper(renderer);
  62. }
  63. int
  64. HINFO::compare(const Rdata& other) const {
  65. const HINFO& other_hinfo = dynamic_cast<const HINFO&>(other);
  66. if (cpu_ < other_hinfo.cpu_) {
  67. return (-1);
  68. } else if (cpu_ > other_hinfo.cpu_) {
  69. return (1);
  70. }
  71. if (os_ < other_hinfo.os_) {
  72. return (-1);
  73. } else if (os_ > other_hinfo.os_) {
  74. return (1);
  75. }
  76. return (0);
  77. }
  78. const std::string&
  79. HINFO::getCPU() const {
  80. return (cpu_);
  81. }
  82. const std::string&
  83. HINFO::getOS() const {
  84. return (os_);
  85. }
  86. void
  87. HINFO::skipLeftSpaces(const std::string& input_str,
  88. std::string::const_iterator& input_iterator)
  89. {
  90. if (input_iterator >= input_str.end()) {
  91. isc_throw(InvalidRdataText,
  92. "Invalid HINFO text format, field is missing.");
  93. }
  94. if (!isspace(*input_iterator)) {
  95. isc_throw(InvalidRdataText,
  96. "Invalid HINFO text format, fields are not separated by space.");
  97. }
  98. // Skip white spaces
  99. while (input_iterator < input_str.end() && isspace(*input_iterator)) {
  100. ++input_iterator;
  101. }
  102. }
  103. // END_RDATA_NAMESPACE
  104. // END_ISC_NAMESPACE