// No host. Fine, we'll use "localhost"
}
+ unsigned int port = 0;
+ string sport;
+ try {
+ sport = getParameter("port");
+ } catch (...) {
+ // No port parameter, we are going to use the default port.
+ sport = "";
+ }
+
+ if (sport.size() > 0) {
+ // Port was given, so try to convert it to an integer.
+
+ try {
+ port = boost::lexical_cast<unsigned int>(sport);
+ } catch (...) {
+ // Port given but could not be converted to an unsigned int.
+ // Just fall back to the default value.
+ port = 0;
+ }
+
+ // The port is only valid when it is in the 0..65535 range.
+ // Again fall back to the default when the given value is invalid.
+ if (port > numeric_limits<uint16_t>::max()) {
+ port = 0;
+ }
+ }
+
const char* user = NULL;
string suser;
try {
// because no row matching the WHERE clause was found, or because a
// row was found but no data was altered.
MYSQL* status = mysql_real_connect(mysql_, host, user, password, name,
- 0, NULL, CLIENT_FOUND_ROWS);
+ port, NULL, CLIENT_FOUND_ROWS);
if (status != mysql_) {
isc_throw(DbOpenError, mysql_error(mysql_));
}
int64_t lfc_interval = 0;
int64_t timeout = 0;
+ int64_t port = 0;
// 2. Update the copy with the passed keywords.
BOOST_FOREACH(ConfigPair param, database_config->mapValue()) {
try {
values_copy[param.first] =
boost::lexical_cast<std::string>(timeout);
+ } else if (param.first == "port") {
+ port = param.second->intValue();
+ values_copy[param.first] =
+ boost::lexical_cast<std::string>(port);
+
} else {
values_copy[param.first] = param.second->stringValue();
}
<< " (" << value->getPosition() << ")");
}
+ // e. Check that the port is within a reasonable range.
+ if ((port < 0) ||
+ (port > std::numeric_limits<uint16_t>::max())) {
+ ConstElementPtr value = database_config->get("port");
+ isc_throw(DhcpConfigError, "port value: " << port
+ << " is out of range, expected value: 0.."
+ << std::numeric_limits<uint16_t>::max()
+ << " (" << value->getPosition() << ")");
+ }
+
// 4. If all is OK, update the stored keyword/value pairs. We do this by
// swapping contents - values_copy is destroyed immediately after the
// operation (when the method exits), so we are not interested in its new
/// - "type" is "memfile", "mysql" or "postgresql"
/// - "lfc-interval" is a number from the range of 0 to 4294967295.
/// - "connect-timeout" is a number from the range of 0 to 4294967295.
+ /// - "port" is a number from the range of 0 to 65535.
///
/// Once all has been validated, constructs the database access string
/// expected by the lease manager.
/// @param database_config The configuration value for the "*-database"
/// identifier.
///
- /// @throw isc::BadValue The 'type' keyword contains an unknown database
- /// type.
- /// @throw isc::dhcp::MissingTypeKeyword The 'type' keyword is missing from
- /// the list of database access keywords.
+ /// @throw isc::dhcp::DhcpConfigError The 'type' keyword contains an
+ /// unknown database type or is missing from the list of
+ /// database access keywords.
void parse(isc::dhcp::CfgDbAccessPtr& cfg_db,
isc::data::ConstElementPtr database_config);
/// @return Database access string
std::string getDbAccessString() const;
-
private:
std::map<std::string, std::string> values_; ///< Stored parameter values