Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Adam Osuchowski
Kea
Commits
a8e4e867
Commit
a8e4e867
authored
Jan 09, 2013
by
JINMEI Tatuya
Browse files
[2500] extracted createName() from soa.cc so it can be commonly used.
parent
04273161
Changes
4
Hide whitespace changes
Inline
Side-by-side
src/lib/dns/Makefile.am
View file @
a8e4e867
...
...
@@ -23,6 +23,7 @@ EXTRA_DIST += rdata/generic/cname_5.cc
EXTRA_DIST
+=
rdata/generic/cname_5.h
EXTRA_DIST
+=
rdata/generic/detail/char_string.cc
EXTRA_DIST
+=
rdata/generic/detail/char_string.h
EXTRA_DIST
+=
rdata/generic/detail/lexer_util.h
EXTRA_DIST
+=
rdata/generic/detail/nsec_bitmap.cc
EXTRA_DIST
+=
rdata/generic/detail/nsec_bitmap.h
EXTRA_DIST
+=
rdata/generic/detail/nsec3param_common.cc
...
...
src/lib/dns/rdata/generic/detail/lexer_util.h
0 → 100644
View file @
a8e4e867
// Copyright (C) 2013 Internet Systems Consortium, Inc. ("ISC")
//
// Permission to use, copy, modify, and/or distribute this software for any
// purpose with or without fee is hereby granted, provided that the above
// copyright notice and this permission notice appear in all copies.
//
// THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
// REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
// AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
// INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
// LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
// OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
// PERFORMANCE OF THIS SOFTWARE.
#ifndef DNS_RDATA_LEXER_UTIL_H
#define DNS_RDATA_LEXER_UTIL_H 1
#include <dns/name.h>
#include <dns/master_lexer.h>
/// \file lexer_util.h
/// \brief Utilities for extracting RDATA fields from lexer.
///
/// This file intends to define convenient small routines that can be
/// commonly used in the RDATA implementation to build RDATA fields from
/// a \c MasterLexer.
namespace
isc
{
namespace
dns
{
namespace
rdata
{
namespace
generic
{
namespace
detail
{
/// \brief Construct a Name object using a master lexer and optional origin.
///
/// This is a convenient shortcut of commonly used code pattern that would
/// be used to build RDATA that contain a domain name field.
///
/// Note that this function throws an exception against invalid input.
/// The (direct or indirect) caller's responsibility needs to expect and
/// handle exceptions appropriately.
///
/// \throw MasterLexer::LexerError The next token from lexer is not string.
/// \throw Other Exceptions from the \c Name class constructor if the next
/// string token from the lexer does not represent a valid name.
///
/// \param lexer A \c MasterLexer object. Its next token is expected to be
/// a string that represent a domain name.
/// \param origin If non NULL, specifies the origin of the name to be
/// constructed.
///
/// \return A new Name object that corresponds to the next string token of
/// the \c lexer.
inline
Name
createNameFromLexer
(
MasterLexer
&
lexer
,
const
Name
*
origin
)
{
const
MasterToken
::
StringRegion
&
str_region
=
lexer
.
getNextToken
(
MasterToken
::
STRING
).
getStringRegion
();
return
(
Name
(
str_region
.
beg
,
str_region
.
len
,
origin
));
}
}
// namespace detail
}
// namespace generic
}
// namespace rdata
}
// namespace dns
}
// namespace isc
#endif // DNS_RDATA_LEXER_UTIL_H
// Local Variables:
// mode: c++
// End:
src/lib/dns/rdata/generic/soa_6.cc
View file @
a8e4e867
...
...
@@ -25,6 +25,8 @@
#include <dns/rdata.h>
#include <dns/rdataclass.h>
#include <dns/rdata/generic/detail/lexer_util.h>
#include <boost/static_assert.hpp>
#include <boost/lexical_cast.hpp>
...
...
@@ -34,6 +36,7 @@
using
namespace
std
;
using
boost
::
lexical_cast
;
using
namespace
isc
::
util
;
using
isc
::
dns
::
rdata
::
generic
::
detail
::
createNameFromLexer
;
// BEGIN_ISC_NAMESPACE
// BEGIN_RDATA_NAMESPACE
...
...
@@ -47,13 +50,6 @@ SOA::SOA(InputBuffer& buffer, size_t) :
}
namespace
{
Name
createName
(
MasterLexer
&
lexer
,
const
Name
*
origin
)
{
const
MasterToken
::
StringRegion
&
str_region
=
lexer
.
getNextToken
(
MasterToken
::
STRING
).
getStringRegion
();
return
(
Name
(
str_region
.
beg
,
str_region
.
len
,
origin
));
}
void
fillParameters
(
MasterLexer
&
lexer
,
uint8_t
numdata
[
20
])
{
// Copy serial, refresh, retry, expire, minimum. We accept the extended
...
...
@@ -84,6 +80,7 @@ fillParameters(MasterLexer& lexer, uint8_t numdata[20]) {
/// \throw Others Exception from the Name and RRTTL constructors.
/// \throw InvalidRdataText Other general syntax errors.
SOA
::
SOA
(
const
std
::
string
&
soastr
)
:
// Fill in dummy name and replace them soon below.
mname_
(
Name
::
ROOT_NAME
()),
rname_
(
Name
::
ROOT_NAME
())
{
try
{
...
...
@@ -91,8 +88,8 @@ SOA::SOA(const std::string& soastr) :
MasterLexer
lexer
;
lexer
.
pushSource
(
ss
);
mname_
=
createName
(
lexer
,
NULL
);
rname_
=
createName
(
lexer
,
NULL
);
mname_
=
createName
FromLexer
(
lexer
,
NULL
);
rname_
=
createName
FromLexer
(
lexer
,
NULL
);
fillParameters
(
lexer
,
numdata_
);
if
(
lexer
.
getNextToken
().
getType
()
!=
MasterToken
::
END_OF_FILE
)
{
...
...
@@ -126,7 +123,8 @@ SOA::SOA(const std::string& soastr) :
/// they are non absolute.
SOA
::
SOA
(
MasterLexer
&
lexer
,
const
Name
*
origin
,
MasterLoader
::
Options
,
MasterLoaderCallbacks
&
)
:
mname_
(
createName
(
lexer
,
origin
)),
rname_
(
createName
(
lexer
,
origin
))
mname_
(
createNameFromLexer
(
lexer
,
origin
)),
rname_
(
createNameFromLexer
(
lexer
,
origin
))
{
fillParameters
(
lexer
,
numdata_
);
}
...
...
src/lib/dns/tests/rdata_soa_unittest.cc
View file @
a8e4e867
...
...
@@ -106,6 +106,13 @@ TEST_F(Rdata_SOA_Test, createFromText) {
checkFromBadTexxt
<
EmptyLabel
,
EmptyLabel
>
(
". bad..example. 2010012601 1H 5M 1000H 20M"
);
// Names shouldn't be quoted. (Note: on completion of #2534, the resulting
// exception will be different).
checkFromBadTexxt
<
MissingNameOrigin
,
MissingNameOrigin
>
(
"
\"
.
\"
. 0 0 0 0 0"
);
checkFromBadTexxt
<
MissingNameOrigin
,
MissingNameOrigin
>
(
".
\"
.
\"
0 0 0 0 0"
);
// Missing MAME or RNAME: for the string version, the serial would be
// tried as RNAME and result in "not absolute". For the lexer version,
// it reaches the end-of-line, missing min TTL.
...
...
Write
Preview
Supports
Markdown
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