///
/// @throw BadValue if unsupported type is specified
static Type txtToType(const std::string& txt) {
- if (txt == "address") {
- return (Parameters::TYPE_ADDR);
- } else if (txt == "hw-address") {
+ if (txt == "hw-address") {
return (Parameters::TYPE_HWADDR);
} else if (txt == "duid") {
return (Parameters::TYPE_DUID);
} else {
isc_throw(BadValue, "Incorrect identifier type: "
<< txt << ", the only supported values are: "
- "address, hw-address, duid, client-id");
+ "hw-address, duid, client-id");
}
}
x.query_type = Parameters::txtToType(type->stringValue());
switch (x.query_type) {
- case Parameters::TYPE_HWADDR: {
- HWAddr hw = HWAddr::fromText(ident->stringValue());
- x.hwaddr = HWAddrPtr(new HWAddr(hw));
+ case Parameters::TYPE_HWADDR:
+ try {
+ HWAddr hw = HWAddr::fromText(ident->stringValue());
+ x.hwaddr = HWAddrPtr(new HWAddr(hw));
+ } catch (const std::exception& ex) {
+ isc_throw(BadValue, "Bad 'hw-address' identifier: " << ex.what());
+ }
break;
- }
- case Parameters::TYPE_CLIENT_ID: {
- x.client_id = ClientId::fromText(ident->stringValue());
+ case Parameters::TYPE_CLIENT_ID:
+ try {
+ x.client_id = ClientId::fromText(ident->stringValue());
+ } catch (const std::exception& ex) {
+ isc_throw(BadValue, "Bad 'client-id' identifier: " << ex.what());
+ }
break;
- }
- case Parameters::TYPE_DUID: {
- DUID duid = DUID::fromText(ident->stringValue());
- x.duid = DuidPtr(new DUID(duid));
+ case Parameters::TYPE_DUID:
+ try {
+ DUID duid = DUID::fromText(ident->stringValue());
+ x.duid = DuidPtr(new DUID(duid));
+ } catch (const std::exception& ex) {
+ isc_throw(BadValue, "Bad 'duid' identifier: " << ex.what());
+ }
break;
- }
- case Parameters::TYPE_ADDR: {
- // We should never get here. The address clause should have been caught
- // earlier.
- return (x);
- }
- default: {
+ default:
isc_throw(BadValue, "Identifier type " << type->stringValue() <<
" is not supported.");
}
- }
return (x);
}
isc_throw(BadValue, "'hw-address' parameter must not be empty");
}
- HWAddr hwaddr = HWAddr::fromText(hw_address->stringValue());
+ HWAddr hwaddr;
+ try {
+ hwaddr = HWAddr::fromText(hw_address->stringValue());
+ } catch (const std::exception& ex) {
+ isc_throw(BadValue, "bad 'hw-address' parameter: " << ex.what());
+ }
ElementPtr leases_json = Element::createList();
-
if (v4) {
Lease4Collection leases =
LeaseMgrFactory::instance().getLease4(hwaddr);
" }\n"
"}";
exp_rsp = "Incorrect identifier type: color, the only supported values are: "
- "address, hw-address, duid, client-id";
+ "hw-address, duid, client-id";
testCommand(cmd, CONTROL_RESULT_ERROR, exp_rsp);
// Query by DUID is not supported in v4. Sorry.
true,
"\"iaid\": 0",
"'iaid' parameter is specific to DHCPv6."
+ },
+ {
+ "Unknown identifier type",
+ true,
+ "\"identifier-type\": \"color\", \"identifier\": \"blue\"",
+ "Incorrect identifier type: color, the only supported values are: "
+ "hw-address, duid, client-id"
+ },
+ {
+ "Bad address identifier type",
+ true,
+ "\"identifier-type\": \"address\", \"identifier\": \"blue\"",
+ "Incorrect identifier type: address, the only supported values "
+ "are: hw-address, duid, client-id"
+ },
+ {
+ "Bad hw-address identifier",
+ true,
+ "\"identifier-type\": \"hw-address\", \"identifier\": \"01::\"",
+ "Bad 'hw-address' identifier: "
+ "two consecutive separators (':') specified in a decoded string '01::'"
+ },
+ {
+ "Bad client-id identifier",
+ true,
+ "\"identifier-type\": \"client-id\", \"identifier\": \"01\"",
+ "Bad 'client-id' identifier: "
+ "identifier is too short (1), at least 2 is required"
+ },
+ {
+ "Bad duid identifier",
+ true,
+ "\"identifier-type\": \"duid\", \"identifier\": \"01\"",
+ "Bad 'duid' identifier: "
+ "identifier is too short (1), at least 3 is required"
}
};
" \"hw-address\": \"00::01:00:bc:0d:67\"\n"
" }\n"
"}";
- exp_rsp = "two consecutive separators (':') specified in a decoded string";
+ exp_rsp = "bad 'hw-address' parameter: ";
+ exp_rsp += "two consecutive separators (':') specified in a decoded string";
exp_rsp += " '00::01:00:bc:0d:67'";
testCommand(cmd, CONTROL_RESULT_ERROR, exp_rsp);
}
" }\n"
"}";
exp_rsp = "Incorrect identifier type: color, the only supported values are: "
- "address, hw-address, duid, client-id";
+ "hw-address, duid, client-id";
testCommand(cmd, CONTROL_RESULT_ERROR, exp_rsp);
// Query by DUID is not supported in v4. Sorry.
" }\n"
"}";
exp_rsp = "Incorrect identifier type: color, the only supported values are: "
- "address, hw-address, duid, client-id";
+ "hw-address, duid, client-id";
testCommand(cmd, CONTROL_RESULT_ERROR, exp_rsp);
// Query by hw-address is not supported in v6. Sorry.
true,
"\"iaid\": 4294967297",
"'iaid' parameter is not a 32 bit unsigned integer."
+ },
+ {
+ "Unknown identifier type",
+ true,
+ "\"identifier-type\": \"color\", \"identifier\": \"blue\"",
+ "Incorrect identifier type: color, the only supported values are: "
+ "hw-address, duid, client-id"
+ },
+ {
+ "Bad address identifier type",
+ true,
+ "\"identifier-type\": \"address\", \"identifier\": \"blue\"",
+ "Incorrect identifier type: address, the only supported values "
+ "are: hw-address, duid, client-id"
+ },
+ {
+ "Bad hw-address identifier",
+ true,
+ "\"identifier-type\": \"hw-address\", \"identifier\": \"01::\"",
+ "Bad 'hw-address' identifier: "
+ "two consecutive separators (':') specified in a decoded string '01::'"
+ },
+ {
+ "Bad client-id identifier",
+ true,
+ "\"identifier-type\": \"client-id\", \"identifier\": \"01\"",
+ "Bad 'client-id' identifier: "
+ "identifier is too short (1), at least 2 is required"
+ },
+ {
+ "Bad duid identifier",
+ true,
+ "\"identifier-type\": \"duid\", \"identifier\": \"01\"",
+ "Bad 'duid' identifier: "
+ "identifier is too short (1), at least 3 is required"
}
};
" \"hw-address\": \"00::01:00:bc:0d:67\"\n"
" }\n"
"}";
- exp_rsp = "two consecutive separators (':') specified in a decoded string";
+ exp_rsp = "bad 'hw-address' parameter: ";
+ exp_rsp += "two consecutive separators (':') specified in a decoded string";
exp_rsp += " '00::01:00:bc:0d:67'";
testCommand(cmd, CONTROL_RESULT_ERROR, exp_rsp);
}
" }\n"
"}";
exp_rsp = "Incorrect identifier type: color, the only supported values are: "
- "address, hw-address, duid, client-id";
+ "hw-address, duid, client-id";
testCommand(cmd, CONTROL_RESULT_ERROR, exp_rsp);
// Query by hw-address is not supported in v6. Sorry.