Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Adam Osuchowski
Kea
Commits
59903362
Commit
59903362
authored
Dec 03, 2012
by
Marcin Siodelski
Browse files
[2491] Added a function to write fqdn into a buffer.
parent
1dc0f087
Changes
4
Hide whitespace changes
Inline
Side-by-side
src/lib/dhcp/option_custom.cc
View file @
59903362
...
...
@@ -101,7 +101,7 @@ OptionCustom::createBuffers() {
if
(
data_size
==
0
&&
*
field
==
OPT_FQDN_TYPE
)
{
OptionDataTypeUtil
::
writeFqdn
(
"."
,
buf
);
OptionDataTypeUtil
::
writeFqdn
(
"."
,
buf
);
}
else
{
buf
.
resize
(
data_size
);
}
...
...
@@ -114,8 +114,9 @@ OptionCustom::createBuffers() {
if
(
data_size
==
0
&&
data_type
==
OPT_FQDN_TYPE
)
{
OptionDataTypeUtil
::
writeFqdn
(
"."
,
buf
);
}
else
{
buf
.
resize
(
data_size
);
}
buf
.
resize
(
data_size
);
buffers
.
push_back
(
buf
);
}
std
::
swap
(
buffers
,
buffers_
);
...
...
@@ -414,12 +415,16 @@ OptionCustom::writeBoolean(const bool value, const uint32_t index) {
std
::
string
OptionCustom
::
readFqdn
(
const
uint32_t
index
)
const
{
checkIndex
(
index
);
try
{
size_t
len
=
0
;
return
(
OptionDataTypeUtil
::
readFqdn
(
buffers_
[
index
],
len
));
}
catch
(
const
Exception
&
ex
)
{
isc_throw
(
BadDataTypeCast
,
ex
.
what
());
}
size_t
len
=
0
;
return
(
OptionDataTypeUtil
::
readFqdn
(
buffers_
[
index
],
len
));
}
void
OptionCustom
::
writeFqdn
(
const
std
::
string
&
fqdn
,
const
uint32_t
index
)
{
checkIndex
(
index
);
buffers_
[
index
].
clear
();
OptionDataTypeUtil
::
writeFqdn
(
fqdn
,
buffers_
[
index
]);
}
std
::
string
...
...
src/lib/dhcp/option_custom.h
View file @
59903362
...
...
@@ -151,6 +151,14 @@ public:
/// @return string representation if FQDN.
std
::
string
readFqdn
(
const
uint32_t
index
=
0
)
const
;
/// @brief Write an FQDN into a buffer.
///
/// @param fqdn text representation of FQDN.
/// @param index buffer index.
///
/// @throw isc::OutOfRange if index is out of range.
void
writeFqdn
(
const
std
::
string
&
fqdn
,
const
uint32_t
index
=
0
);
/// @brief Read a buffer as integer value.
///
/// @param index buffer index.
...
...
src/lib/dhcp/option_data_types.cc
View file @
59903362
...
...
@@ -216,7 +216,7 @@ OptionDataTypeUtil::readFqdn(const std::vector<uint8_t>& buf,
// If buffer is empty emit an error.
if
(
buf
.
empty
())
{
isc_throw
(
BadDataTypeCast
,
"unable to read FQDN from a buffer."
<<
" The buffer is empty"
);
<<
" The buffer is empty
.
"
);
}
// Copy the data from a buffer to InputBuffer so as we can use
// isc::dns::Name object to get the FQDN. This is not the most
...
...
src/lib/dhcp/tests/option_custom_unittest.cc
View file @
59903362
...
...
@@ -944,12 +944,36 @@ TEST_F(OptionCustomTest, setStringData) {
// By default the string data field is empty.
EXPECT_TRUE
(
value
.
empty
());
// Write some text to this field.
EXPEC
T_NO_THROW
(
option
->
writeString
(
"hello world"
));
ASSER
T_NO_THROW
(
option
->
writeString
(
"hello world"
));
// Check that it has been actually written.
EXPECT_NO_THROW
(
value
=
option
->
readString
());
EXPECT_EQ
(
"hello world"
,
value
);
}
/// The purpose of this test is to verify that an option comprising
/// a default FQDN value can be created and that this value can be
/// overriden after the option has been created.
TEST_F
(
OptionCustomTest
,
setFqdnData
)
{
OptionDefinition
opt_def
(
"OPTION_FOO"
,
1000
,
"fqdn"
);
// Create an option and let the data field be initialized
// to default value (do not provide any data buffer).
boost
::
scoped_ptr
<
OptionCustom
>
option
;
ASSERT_NO_THROW
(
option
.
reset
(
new
OptionCustom
(
opt_def
,
Option
::
V6
));
);
ASSERT_TRUE
(
option
);
// Read a default FQDN value from the option.
std
::
string
fqdn
;
ASSERT_NO_THROW
(
fqdn
=
option
->
readFqdn
());
EXPECT_EQ
(
"."
,
fqdn
);
// Try override the default FQDN value.
ASSERT_NO_THROW
(
option
->
writeFqdn
(
"example.com"
));
// Check that the value has been actually overriden.
ASSERT_NO_THROW
(
fqdn
=
option
->
readFqdn
());
EXPECT_EQ
(
"example.com."
,
fqdn
);
}
// The purpose of this test is to verify that pack function for
// DHCPv4 custom option works correctly.
TEST_F
(
OptionCustomTest
,
pack4
)
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment