From 6478f4a1f3d3fb66a7fc25887135bdf3403538bd Mon Sep 17 00:00:00 2001 From: Jelte Jansen Date: Thu, 10 Jan 2013 12:18:25 +0100 Subject: [PATCH] [2498] Remove deprecated character_string files --- src/lib/dns/Makefile.am | 1 - src/lib/dns/character_string.cc | 145 ------------------ src/lib/dns/character_string.h | 60 -------- src/lib/dns/tests/Makefile.am | 1 - .../dns/tests/character_string_unittest.cc | 97 ------------ 5 files changed, 304 deletions(-) delete mode 100644 src/lib/dns/character_string.cc delete mode 100644 src/lib/dns/character_string.h delete mode 100644 src/lib/dns/tests/character_string_unittest.cc diff --git a/src/lib/dns/Makefile.am b/src/lib/dns/Makefile.am index 3f6ae6322..10d2f7251 100644 --- a/src/lib/dns/Makefile.am +++ b/src/lib/dns/Makefile.am @@ -125,7 +125,6 @@ libb10_dns___la_SOURCES += tsig.h tsig.cc libb10_dns___la_SOURCES += tsigerror.h tsigerror.cc libb10_dns___la_SOURCES += tsigkey.h tsigkey.cc libb10_dns___la_SOURCES += tsigrecord.h tsigrecord.cc -libb10_dns___la_SOURCES += character_string.h character_string.cc libb10_dns___la_SOURCES += master_loader_callbacks.h master_loader_callbacks.cc libb10_dns___la_SOURCES += master_loader.h libb10_dns___la_SOURCES += rrset_collection_base.h diff --git a/src/lib/dns/character_string.cc b/src/lib/dns/character_string.cc deleted file mode 100644 index 8b319483d..000000000 --- a/src/lib/dns/character_string.cc +++ /dev/null @@ -1,145 +0,0 @@ -// Copyright (C) 2011 Internet Systems Consortium, Inc. ("ISC") -// -// Permission to use, copy, modify, and/or distribute this software for any -// purpose with or without fee is hereby granted, provided that the above -// copyright notice and this permission notice appear in all copies. -// -// THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH -// REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY -// AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, -// INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM -// LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE -// OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR -// PERFORMANCE OF THIS SOFTWARE. - -#include "character_string.h" -#include "rdata.h" - -using namespace std; -using namespace isc::dns::rdata; - -namespace isc { -namespace dns { - -namespace { -bool isDigit(char c) { - return (('0' <= c) && (c <= '9')); -} -} - -std::string -characterstr::getNextCharacterString(const std::string& input_str, - std::string::const_iterator& input_iterator, - bool* quoted) -{ - string result; - - // If the input string only contains white-spaces, it is an invalid - // - if (input_iterator >= input_str.end()) { - isc_throw(InvalidRdataText, "Invalid text format, \ - field is missing."); - } - - // Whether the is separated with double quotes (") - bool quotes_separated = (*input_iterator == '"'); - // Whether the quotes are pared if the string is quotes separated - bool quotes_paired = false; - - if (quotes_separated) { - ++input_iterator; - } - - while(input_iterator < input_str.end()){ - // Escaped characters processing - if (*input_iterator == '\\') { - if (input_iterator + 1 == input_str.end()) { - isc_throw(InvalidRdataText, " ended \ - prematurely."); - } else { - if (isDigit(*(input_iterator + 1))) { - // \DDD where each D is a digit. It its the octet - // corresponding to the decimal number described by DDD - if (input_iterator + 3 >= input_str.end()) { - isc_throw(InvalidRdataText, " ended \ - prematurely."); - } else { - int n = 0; - ++input_iterator; - for (int i = 0; i < 3; ++i) { - if (isDigit(*input_iterator)) { - n = n*10 + (*input_iterator - '0'); - ++input_iterator; - } else { - isc_throw(InvalidRdataText, "Illegal decimal \ - escaping series"); - } - } - if (n > 255) { - isc_throw(InvalidRdataText, "Illegal octet \ - number"); - } - result.push_back(n); - continue; - } - } else { - ++input_iterator; - result.push_back(*input_iterator); - ++input_iterator; - continue; - } - } - } - - if (quotes_separated) { - // If the is seperated with quotes symbol and - // another quotes symbol is encountered, it is the end of the - // - if (*input_iterator == '"') { - quotes_paired = true; - ++input_iterator; - // Reach the end of character string - break; - } - } else if (*input_iterator == ' ') { - // If the is not seperated with quotes symbol, - // it is seperated with char - break; - } - - result.push_back(*input_iterator); - - ++input_iterator; - } - - if (result.size() > MAX_CHARSTRING_LEN) { - isc_throw(CharStringTooLong, " is too long"); - } - - if (quotes_separated && !quotes_paired) { - isc_throw(InvalidRdataText, "The quotes are not paired"); - } - - if (quoted != NULL) { - *quoted = quotes_separated; - } - - return (result); -} - -std::string -characterstr::getNextCharacterString(util::InputBuffer& buffer, size_t len) { - uint8_t str_len = buffer.readUint8(); - - size_t pos = buffer.getPosition(); - if (len - pos < str_len) { - isc_throw(InvalidRdataLength, "Invalid string length"); - } - - uint8_t buf[MAX_CHARSTRING_LEN]; - buffer.readData(buf, str_len); - return (string(buf, buf + str_len)); -} - -} // end of namespace dns -} // end of namespace isc diff --git a/src/lib/dns/character_string.h b/src/lib/dns/character_string.h deleted file mode 100644 index 0bfa38b8d..000000000 --- a/src/lib/dns/character_string.h +++ /dev/null @@ -1,60 +0,0 @@ -// Copyright (C) 2011 Internet Systems Consortium, Inc. ("ISC") -// -// Permission to use, copy, modify, and/or distribute this software for any -// purpose with or without fee is hereby granted, provided that the above -// copyright notice and this permission notice appear in all copies. -// -// THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH -// REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY -// AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, -// INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM -// LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE -// OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR -// PERFORMANCE OF THIS SOFTWARE. - -#ifndef CHARACTER_STRING_H -#define CHARACTER_STRING_H - -#include -#include -#include - -namespace isc { -namespace dns { - -// \brief Some utility functions to extract from string -// or InputBuffer -// -// is expressed in one or two ways: as a contiguous set -// of characters without interior spaces, or as a string beginning with a " -// and ending with a ". Inside a " delimited string any character can -// occur, except for a " itself, which must be quoted using \ (back slash). -// Ref. RFC1035 - - -namespace characterstr { - /// Get a from a string - /// - /// \param input_str The input string - /// \param input_iterator The iterator from which to start extracting, - /// the iterator will be updated to new position after the function - /// is returned - /// \param quoted If not \c NULL, returns \c true at this address if - /// the string is quoted, \cfalse otherwise - /// \return A std::string that contains the extracted - std::string getNextCharacterString(const std::string& input_str, - std::string::const_iterator& input_iterator, - bool* quoted = NULL); - - /// Get a from a input buffer - /// - /// \param buffer The input buffer - /// \param len The input buffer total length - /// \return A std::string that contains the extracted - std::string getNextCharacterString(util::InputBuffer& buffer, size_t len); - -} // namespace characterstr -} // namespace dns -} // namespace isc - -#endif // CHARACTER_STRING_H diff --git a/src/lib/dns/tests/Makefile.am b/src/lib/dns/tests/Makefile.am index 8d32b42ba..5029681a3 100644 --- a/src/lib/dns/tests/Makefile.am +++ b/src/lib/dns/tests/Makefile.am @@ -73,7 +73,6 @@ run_unittests_SOURCES += tsig_unittest.cc run_unittests_SOURCES += tsigerror_unittest.cc run_unittests_SOURCES += tsigkey_unittest.cc run_unittests_SOURCES += tsigrecord_unittest.cc -run_unittests_SOURCES += character_string_unittest.cc run_unittests_SOURCES += master_loader_callbacks_test.cc run_unittests_SOURCES += rrset_collection_unittest.cc run_unittests_SOURCES += zone_checker_unittest.cc diff --git a/src/lib/dns/tests/character_string_unittest.cc b/src/lib/dns/tests/character_string_unittest.cc deleted file mode 100644 index e8f58844a..000000000 --- a/src/lib/dns/tests/character_string_unittest.cc +++ /dev/null @@ -1,97 +0,0 @@ -// Copyright (C) 2011 Internet Systems Consortium, Inc. ("ISC") -// -// Permission to use, copy, modify, and/or distribute this software for any -// purpose with or without fee is hereby granted, provided that the above -// copyright notice and this permission notice appear in all copies. -// -// THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH -// REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY -// AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, -// INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM -// LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE -// OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR -// PERFORMANCE OF THIS SOFTWARE. - - -#include - -#include -#include -#include - -using isc::UnitTestUtil; - -using namespace std; -using namespace isc; -using namespace isc::dns; -using namespace isc::dns::characterstr; -using namespace isc::dns::rdata; - -namespace { - -class CharacterString { -public: - CharacterString(const string& str){ - string::const_iterator it = str.begin(); - characterStr_ = getNextCharacterString(str, it, &is_quoted_); - } - const string& str() const { return characterStr_; } - bool quoted() const { return (is_quoted_); } -private: - string characterStr_; - bool is_quoted_; -}; - -TEST(CharacterStringTest, testNormalCase) { - CharacterString cstr1("foo"); - EXPECT_EQ(string("foo"), cstr1.str()); - - // Test that separated by space - CharacterString cstr2("foo bar"); - EXPECT_EQ(string("foo"), cstr2.str()); - EXPECT_FALSE(cstr2.quoted()); - - // Test that separated by quotes - CharacterString cstr3("\"foo bar\""); - EXPECT_EQ(string("foo bar"), cstr3.str()); - EXPECT_TRUE(cstr3.quoted()); - - // Test that not separate by quotes but ended with quotes - CharacterString cstr4("foo\""); - EXPECT_EQ(string("foo\""), cstr4.str()); - EXPECT_FALSE(cstr4.quoted()); -} - -TEST(CharacterStringTest, testBadCase) { - // The that started with quotes should also be ended - // with quotes - EXPECT_THROW(CharacterString cstr("\"foo"), InvalidRdataText); - - // The string length cannot exceed 255 characters - string str; - for (int i = 0; i < 257; ++i) { - str += 'A'; - } - EXPECT_THROW(CharacterString cstr(str), CharStringTooLong); -} - -TEST(CharacterStringTest, testEscapeCharacter) { - CharacterString cstr1("foo\\bar"); - EXPECT_EQ(string("foobar"), cstr1.str()); - - CharacterString cstr2("foo\\\\bar"); - EXPECT_EQ(string("foo\\bar"), cstr2.str()); - - CharacterString cstr3("fo\\111bar"); - EXPECT_EQ(string("foobar"), cstr3.str()); - - CharacterString cstr4("fo\\1112bar"); - EXPECT_EQ(string("foo2bar"), cstr4.str()); - - // There must be at least 3 digits followed by '\' - EXPECT_THROW(CharacterString cstr("foo\\98ar"), InvalidRdataText); - EXPECT_THROW(CharacterString cstr("foo\\9ar"), InvalidRdataText); - EXPECT_THROW(CharacterString cstr("foo\\98"), InvalidRdataText); -} - -} // namespace -- GitLab