"ALLOW FILTERING "
}},
+ {DELETE_HOST,
+ {DELETE_HOST,
+ "DELETE FROM host_reservations WHERE id = ? "
+ "IF EXISTS "
+ }}
};
- CqlHostExchange::CqlHostExchange(CqlConnection& connection)
- : host_(NULL), connection_(connection), id_(0), host_identifier_type_(0),
- host_ipv4_subnet_id_(0), host_ipv6_subnet_id_(0), host_ipv4_address_(0),
- host_ipv4_next_server_(0),
+ CqlHostExchange::CqlHostExchange()
+ : host_(NULL), id_(0), host_identifier_type_(0), host_ipv4_subnet_id_(0),
- host_ipv6_subnet_id_(0), host_ipv4_address_(0),
++ host_ipv6_subnet_id_(0), host_ipv4_address_(0), host_ipv4_next_server_(0),
+ host_ipv4_server_hostname_(NULL_DHCP4_SERVER_HOSTNAME),
+ host_ipv4_boot_file_name_(NULL_DHCP4_BOOT_FILE_NAME),
+ user_context_(NULL_USER_CONTEXT),
reserved_ipv6_prefix_length_(NULL_RESERVED_IPV6_PREFIX_LENGTH),
reserved_ipv6_prefix_address_type_(NULL_RESERVED_IPV6_PREFIX_ADDRESS_TYPE),
iaid_(NULL_IAID), option_universe_(NULL_OPTION_UNIVERSE),
}
}
- uint64_t
- md5Hash(const std::string& input) {
-
- /// @todo: Convert this code to cryptolink calls and replace the
- /// direct use fromn md5.
-
- // Prepare structures for MD5().
- const size_t word_size = MD5_DIGEST_LENGTH / sizeof(uint64_t);
- uint64_t hash[word_size];
- unsigned char* digest = reinterpret_cast<unsigned char*>(hash);
- unsigned char* string = reinterpret_cast<unsigned char*>(const_cast<char*>(input.c_str()));
- std::fill(hash, hash + word_size, 0);
-
- // Get MD5 hash value.
- MD5(string, input.size(), digest);
-
- // Return the first part of the hash value which still retains all
- // properties of the full hash value.
- return (hash[0]);
- }
-
+void
+CqlHostExchange::createBindForDelete(const HostPtr& host,
+ const OptionalValue<SubnetID>& subnet_id,
+ const IPv6Resrv* const reservation,
+ const std::string& option_space,
+ const OptionDescriptor& option_descriptor,
+ StatementTag statement_tag, AnyArray& data) {
+ prepareExchange(host, subnet_id, reservation, option_space, option_descriptor);
+
+ try {
+ // Add all parameters to bind array.
+ data.clear();
+
+ if (statement_tag == CqlHostExchange::DELETE_HOST) {
+ data.add(&id_);
+ }
+
+ } catch (const Exception& ex) {
+ isc_throw(DbOperationError,
+ "CqlHostExchange::createBindForDelete(): "
+ "could not create bind array from host "
+ << host->getHostname() << ", reason: " << ex.what());
+ }
+}
+
cass_int64_t
CqlHostExchange::hashIntoId() const {
- // Allocates a fixed maximum length in the stringstream for each
- // aggregated field to avoid collisions between distinct entries.
+ // Add a separator between aggregated field to avoid collisions
+ // between distinct entries.
// Get key.
std::stringstream key_stream;
- key_stream << host_ipv4_subnet_id_ << "-";
- key_stream << host_ipv6_subnet_id_ << "-";
- key_stream << host_ipv4_address_ << "-";
- key_stream << reserved_ipv6_prefix_address_ << "/";
- key_stream << reserved_ipv6_prefix_length_ << "-";
- key_stream << option_code_ << "-";
- key_stream << option_space_;
+ if (host_ipv4_address_) {
+ key_stream << std::setw(3 * DUID::MAX_DUID_LEN - 1) << std::setfill('-')
+ << "-";
+ key_stream << std::setw(10) << std::setfill('-') << "-";
+ } else {
+ key_stream << std::setw(3 * DUID::MAX_DUID_LEN - 1) << std::setfill('-')
+ << DUID(host_identifier_).toText();
+ key_stream << std::setw(10) << std::setfill('-') << host_identifier_type_;
+ }
+ key_stream << std::setw(10) << std::setfill('-') << host_ipv4_subnet_id_;
+ key_stream << std::setw(10) << std::setfill('-') << host_ipv6_subnet_id_;
+ key_stream << std::setw(V4ADDRESS_TEXT_MAX_LEN) << std::setfill('-')
+ << host_ipv4_address_;
+ key_stream << std::setw(V6ADDRESS_TEXT_MAX_LEN) << std::setfill('-')
+ << reserved_ipv6_prefix_address_;
+ key_stream << std::setw(4) << std::setfill('-')
+ << reserved_ipv6_prefix_length_;
+ key_stream << std::setw(4) << std::setfill('-') << option_code_;
+ key_stream << std::setw(OPTION_SPACE_MAX_LENGTH) << std::setfill('-')
+ << option_space_;
const std::string key = key_stream.str();
- const cass_int64_t md5 = static_cast<cass_int64_t>(md5Hash(key));
+ const cass_int64_t hash = static_cast<cass_int64_t>(Hash64::hash(key));
- return (md5);
+ return (hash);
}
boost::any
return (result_collection);
}
-void
-CqlHostDataSourceImpl::insertHost(const HostPtr& host,
- const OptionalValue<SubnetID>& subnet_id,
- const IPv6Resrv* const reservation,
- const std::string& option_space,
- const OptionDescriptor& option_descriptor) {
+bool
+CqlHostDataSourceImpl::insertOrDeleteHost(bool insert,
+ const HostPtr& host,
+ const OptionalValue<SubnetID>& subnet_id,
+ const IPv6Resrv* const reservation,
+ const std::string& option_space,
+ const OptionDescriptor& option_descriptor) {
AnyArray assigned_values;
- std::unique_ptr<CqlHostExchange> host_exchange(new CqlHostExchange(dbconn_));
+ std::unique_ptr<CqlHostExchange> host_exchange(new CqlHostExchange());
try {
- host_exchange->createBindForMutation(
- host, subnet_id, reservation, option_space, option_descriptor,
- CqlHostExchange::INSERT_HOST, assigned_values);
+ if (insert) {
+ host_exchange->createBindForMutation(
+ host, subnet_id, reservation, option_space, option_descriptor,
+ CqlHostExchange::INSERT_HOST, assigned_values);
- host_exchange->executeMutation(dbconn_, assigned_values,
- CqlHostExchange::INSERT_HOST);
+ host_exchange->executeMutation(dbconn_, assigned_values, CqlHostExchange::INSERT_HOST);
+ } else {
+ host_exchange->createBindForDelete(
+ host, subnet_id, reservation, option_space, option_descriptor,
+ CqlHostExchange::DELETE_HOST, assigned_values);
+
+
+ host_exchange->executeMutation(dbconn_, assigned_values, CqlHostExchange::DELETE_HOST);
+ }
} catch (const StatementNotApplied& exception) {
- isc_throw(DuplicateEntry, exception.what());
+ if (insert) {
+ isc_throw(DuplicateEntry, exception.what());
+ } else {
+ return (false);
+ }
}
+
+ return (true);
}
void