Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
ISC Open Source Projects
Kea
Commits
de9c0a0b
Commit
de9c0a0b
authored
Jun 22, 2012
by
Mukund Sivaraman
Browse files
[1774] Use uint8_t for characters of Name data
parent
713e3482
Changes
6
Hide whitespace changes
Inline
Side-by-side
src/lib/dns/labelsequence.cc
View file @
de9c0a0b
...
...
@@ -23,7 +23,7 @@
namespace
isc
{
namespace
dns
{
const
char
*
const
unsigned
char
*
LabelSequence
::
getData
(
size_t
*
len
)
const
{
*
len
=
getDataLength
();
return
(
&
name_
.
ndata_
[
name_
.
offsets_
[
first_label_
]]);
...
...
@@ -47,14 +47,16 @@ LabelSequence::getDataLength() const {
bool
LabelSequence
::
equals
(
const
LabelSequence
&
other
,
bool
case_sensitive
)
const
{
size_t
len
,
other_len
;
const
char
*
data
=
getData
(
&
len
);
const
char
*
other_data
=
other
.
getData
(
&
other_len
);
const
unsigned
char
*
data
=
getData
(
&
len
);
const
unsigned
char
*
other_data
=
other
.
getData
(
&
other_len
);
if
(
len
!=
other_len
)
{
return
(
false
);
}
if
(
case_sensitive
)
{
return
(
std
::
strncmp
(
data
,
other_data
,
len
)
==
0
);
return
(
std
::
strncmp
((
const
char
*
)
data
,
(
const
char
*
)
other_data
,
len
)
==
0
);
}
// As long as the data was originally validated as (part of) a name,
...
...
@@ -97,7 +99,7 @@ LabelSequence::isAbsolute() const {
size_t
LabelSequence
::
getHash
(
bool
case_sensitive
)
const
{
size_t
length
;
const
char
*
s
=
getData
(
&
length
);
const
unsigned
char
*
s
=
getData
(
&
length
);
if
(
length
>
16
)
{
length
=
16
;
}
...
...
src/lib/dns/labelsequence.h
View file @
de9c0a0b
...
...
@@ -67,7 +67,7 @@ public:
/// \param len Pointer to a size_t where the length of the data
/// will be stored (in number of octets)
/// \return Pointer to the wire-format data of this label sequence
const
char
*
getData
(
size_t
*
len
)
const
;
const
unsigned
char
*
getData
(
size_t
*
len
)
const
;
/// \brief Return the length of the wire-format data of this LabelSequence
///
...
...
src/lib/dns/messagerenderer.cc
View file @
de9c0a0b
...
...
@@ -293,7 +293,7 @@ MessageRenderer::writeName(const Name& name, const bool compress) {
LabelSequence
sequence
(
name
);
const
size_t
nlabels
=
sequence
.
getLabelCount
();
size_t
data_len
;
const
char
*
data
;
const
unsigned
char
*
data
;
// Find the offset in the offset table whose name gives the longest
// match against the name to be rendered.
...
...
src/lib/dns/name.cc
View file @
de9c0a0b
...
...
@@ -151,7 +151,7 @@ Name::Name(const std::string &namestring, bool downcase) {
offsets
.
reserve
(
Name
::
MAX_LABELS
);
offsets
.
push_back
(
0
);
std
::
string
ndata
;
std
::
basic_string
<
uint8_t
>
ndata
;
ndata
.
reserve
(
Name
::
MAX_WIRE
);
// should we refactor this code using, e.g, the state pattern? Probably
...
...
@@ -436,8 +436,8 @@ Name::toText(bool omit_final_dot) const {
return
(
"."
);
}
std
::
string
::
const_iterator
np
=
ndata_
.
begin
();
std
::
string
::
const_iterator
np_end
=
ndata_
.
end
();
std
::
basic_string
<
uint8_t
>
::
const_iterator
np
=
ndata_
.
begin
();
std
::
basic_string
<
uint8_t
>
::
const_iterator
np_end
=
ndata_
.
end
();
unsigned
int
labels
=
labelcount_
;
// use for integrity check
// init with an impossible value to catch error cases in the end:
unsigned
int
count
=
MAX_LABELLEN
+
1
;
...
...
@@ -665,7 +665,7 @@ Name::reverse() const {
// Copy the original name, label by label, from tail to head.
vector
<
unsigned
char
>::
const_reverse_iterator
rit0
=
offsets_
.
rbegin
();
vector
<
unsigned
char
>::
const_reverse_iterator
rit1
=
rit0
+
1
;
string
::
const_iterator
n0
=
ndata_
.
begin
();
basic_string
<
uint8_t
>
::
const_iterator
n0
=
ndata_
.
begin
();
retname
.
offsets_
.
push_back
(
0
);
while
(
rit1
!=
offsets_
.
rend
())
{
retname
.
ndata_
.
append
(
n0
+
*
rit1
,
n0
+
*
rit0
);
...
...
src/lib/dns/name.h
View file @
de9c0a0b
...
...
@@ -679,7 +679,7 @@ public:
//@}
private:
std
::
string
ndata_
;
std
::
basic_string
<
uint8_t
>
ndata_
;
std
::
vector
<
unsigned
char
>
offsets_
;
unsigned
int
length_
;
unsigned
int
labelcount_
;
...
...
src/lib/dns/tests/labelsequence_unittest.cc
View file @
de9c0a0b
...
...
@@ -130,18 +130,16 @@ getDataCheck(const char* expected_data, size_t expected_len,
const
LabelSequence
&
ls
)
{
size_t
len
;
const
char
*
data
=
ls
.
getData
(
&
len
);
const
unsigned
char
*
data
=
ls
.
getData
(
&
len
);
ASSERT_EQ
(
expected_len
,
len
)
<<
"Expected data: "
<<
expected_data
<<
" name: "
<<
ls
.
getName
().
toText
();
EXPECT_EQ
(
expected_len
,
ls
.
getDataLength
())
<<
"Expected data: "
<<
expected_data
<<
" name: "
<<
ls
.
getName
().
toText
();
for
(
size_t
i
=
0
;
i
<
len
;
++
i
)
{
EXPECT_EQ
(
expected_data
[
i
],
data
[
i
])
<<
"Difference at pos "
<<
i
<<
": Expected data: "
<<
expected_data
<<
" name: "
<<
ls
.
getName
().
toText
();;
EXPECT_EQ
((
const
unsigned
char
)
expected_data
[
i
],
data
[
i
])
<<
"Difference at pos "
<<
i
<<
": Expected data: "
<<
expected_data
<<
" name: "
<<
ls
.
getName
().
toText
();;
}
}
...
...
@@ -243,8 +241,8 @@ TEST_F(LabelSequenceTest, comparePart) {
// Data comparison
size_t
len
;
const
char
*
data
=
ls1
.
getData
(
&
len
);
getDataCheck
(
data
,
len
,
ls8
);
const
unsigned
char
*
data
=
ls1
.
getData
(
&
len
);
getDataCheck
(
(
const
char
*
)
data
,
len
,
ls8
);
}
TEST_F
(
LabelSequenceTest
,
isAbsolute
)
{
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new 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