Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Kea
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
Operations
Operations
Incidents
Packages & Registries
Packages & Registries
Container Registry
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Adam Osuchowski
Kea
Commits
392e7502
Commit
392e7502
authored
Aug 04, 2017
by
Tomek Mrugalski
🛰
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[5272] getAddress moved to SimpleParser
parent
1300562b
Changes
9
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
65 additions
and
72 deletions
+65
-72
src/hooks/dhcp/lease_cmds/lease_parser.cc
src/hooks/dhcp/lease_cmds/lease_parser.cc
+2
-14
src/hooks/dhcp/lease_cmds/lease_parser.h
src/hooks/dhcp/lease_cmds/lease_parser.h
+2
-15
src/lib/cc/Makefile.am
src/lib/cc/Makefile.am
+1
-0
src/lib/cc/simple_parser.cc
src/lib/cc/simple_parser.cc
+15
-0
src/lib/cc/simple_parser.h
src/lib/cc/simple_parser.h
+17
-2
src/lib/cc/tests/Makefile.am
src/lib/cc/tests/Makefile.am
+1
-0
src/lib/cc/tests/simple_parser_unittest.cc
src/lib/cc/tests/simple_parser_unittest.cc
+25
-0
src/lib/dhcpsrv/parsers/dhcp_parsers.cc
src/lib/dhcpsrv/parsers/dhcp_parsers.cc
+2
-21
src/lib/dhcpsrv/parsers/dhcp_parsers.h
src/lib/dhcpsrv/parsers/dhcp_parsers.h
+0
-20
No files found.
src/hooks/dhcp/lease_cmds/lease_parser.cc
View file @
392e7502
...
...
@@ -17,21 +17,9 @@ using namespace isc::dhcp;
using
namespace
isc
::
data
;
using
namespace
isc
::
asiolink
;
// Can't use a constructor as a function
namespace
{
IOAddress
buildIOAddress
(
const
std
::
string
&
str
)
{
return
(
IOAddress
(
str
));
}
};
namespace
isc
{
namespace
lease_cmds
{
IOAddress
LeaseParser
::
getIOAddress
(
const
ConstElementPtr
&
scope
,
const
std
::
string
&
name
)
{
return
(
getAndConvert
<
IOAddress
,
buildIOAddress
>
(
scope
,
name
,
"address"
));
}
Lease4Ptr
Lease4Parser
::
parse
(
ConstSrvConfigPtr
&
cfg
,
const
ConstElementPtr
&
lease_info
)
{
...
...
@@ -40,7 +28,7 @@ Lease4Parser::parse(ConstSrvConfigPtr& cfg,
}
// These are mandatory parameters.
IOAddress
addr
=
get
IO
Address
(
lease_info
,
"ip-address"
);
IOAddress
addr
=
getAddress
(
lease_info
,
"ip-address"
);
SubnetID
subnet_id
=
getUint32
(
lease_info
,
"subnet-id"
);
if
(
!
addr
.
isV4
())
{
...
...
@@ -134,7 +122,7 @@ Lease6Parser::parse(ConstSrvConfigPtr& cfg,
}
// These are mandatory parameters.
IOAddress
addr
=
get
IO
Address
(
lease_info
,
"ip-address"
);
IOAddress
addr
=
getAddress
(
lease_info
,
"ip-address"
);
SubnetID
subnet_id
=
getUint32
(
lease_info
,
"subnet-id"
);
if
(
addr
.
isV4
())
{
...
...
src/hooks/dhcp/lease_cmds/lease_parser.h
View file @
392e7502
...
...
@@ -15,19 +15,6 @@
namespace
isc
{
namespace
lease_cmds
{
/// @brief Base class for Lease4 and Lease6 parsers
class
LeaseParser
:
public
isc
::
data
::
SimpleParser
{
protected:
/// @brief Returns an address from JSON structure
///
/// @param scope a map the element will be searched at
/// @param name key name to be searched for
/// @return IOAddress representation
isc
::
asiolink
::
IOAddress
getIOAddress
(
const
isc
::
data
::
ConstElementPtr
&
scope
,
const
std
::
string
&
name
);
};
/// @brief Parser for Lease4 structure
///
/// It expects the data in the following format:
...
...
@@ -44,7 +31,7 @@ protected:
/// "hostname": "myhost.example.org",
/// "state": 0
/// }
class
Lease4Parser
:
public
Leas
eParser
{
class
Lease4Parser
:
public
isc
::
data
::
Simpl
eParser
{
public:
/// @brief Parses Element tree and tries to convert to Lease4
...
...
@@ -81,7 +68,7 @@ public:
/// }
/// It expects the input data to use the following format:
class
Lease6Parser
:
public
Leas
eParser
{
class
Lease6Parser
:
public
isc
::
data
::
Simpl
eParser
{
public:
/// @brief Parses Element tree and tries to convert to Lease4
///
...
...
src/lib/cc/Makefile.am
View file @
392e7502
...
...
@@ -12,6 +12,7 @@ libkea_cc_la_SOURCES += json_feed.cc json_feed.h
libkea_cc_la_SOURCES
+=
simple_parser.cc simple_parser.h
libkea_cc_la_LIBADD
=
$(top_builddir)
/src/lib/util/libkea-util.la
libkea_cc_la_LIBADD
+=
$(top_builddir)
/src/lib/asiolink/libkea-asiolink.la
libkea_cc_la_LIBADD
+=
$(top_builddir)
/src/lib/exceptions/libkea-exceptions.la
libkea_cc_la_LIBADD
+=
$(BOOST_LIBS)
...
...
src/lib/cc/simple_parser.cc
View file @
392e7502
...
...
@@ -5,12 +5,14 @@
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
#include <cc/simple_parser.h>
#include <asiolink/io_address.h>
#include <boost/foreach.hpp>
#include <boost/lexical_cast.hpp>
#include <cc/data.h>
#include <string>
using
namespace
std
;
using
namespace
isc
::
asiolink
;
using
isc
::
dhcp
::
DhcpConfigError
;
namespace
isc
{
...
...
@@ -67,6 +69,19 @@ SimpleParser::getBoolean(isc::data::ConstElementPtr scope, const std::string& na
return
(
x
->
boolValue
());
}
IOAddress
SimpleParser
::
getAddress
(
const
ConstElementPtr
&
scope
,
const
std
::
string
&
name
)
{
std
::
string
str
=
getString
(
scope
,
name
);
try
{
return
(
IOAddress
(
str
));
}
catch
(
const
std
::
exception
&
e
)
{
isc_throw
(
DhcpConfigError
,
"Failed to convert '"
<<
str
<<
"' to address: "
<<
e
.
what
()
<<
"("
<<
getPosition
(
name
,
scope
)
<<
")"
);
}
}
const
data
::
Element
::
Position
&
SimpleParser
::
getPosition
(
const
std
::
string
&
name
,
const
data
::
ConstElementPtr
parent
)
{
if
(
!
parent
)
{
...
...
src/lib/cc/simple_parser.h
View file @
392e7502
...
...
@@ -7,6 +7,7 @@
#ifndef SIMPLE_PARSER_H
#define SIMPLE_PARSER_H
#include <asiolink/io_address.h>
#include <cc/data.h>
#include <cc/dhcp_config_error.h>
#include <vector>
...
...
@@ -114,8 +115,6 @@ class SimpleParser {
static
const
data
::
Element
::
Position
&
getPosition
(
const
std
::
string
&
name
,
const
data
::
ConstElementPtr
parent
);
protected:
/// @brief Returns a string parameter from a scope
///
/// Unconditionally returns a parameter.
...
...
@@ -152,6 +151,22 @@ protected:
static
bool
getBoolean
(
isc
::
data
::
ConstElementPtr
scope
,
const
std
::
string
&
name
);
/// @brief Returns a IOAddress parameter from a scope
///
/// Unconditionally returns a parameter.
///
/// @param scope specified parameter will be extracted from this scope
/// @param name name of the parameter
/// @return an IOAddress representing the value of the parameter
/// @throw DhcpConfigError if the parameter is not there or is not of
/// appropriate type (or its conversion to IOAddress fails due to not
/// being a proper address).
static
isc
::
asiolink
::
IOAddress
getAddress
(
const
ConstElementPtr
&
scope
,
const
std
::
string
&
name
);
protected:
/// @brief Returns an integer value with range checking from a scope
///
/// This template should be instantiated in parsers when useful
...
...
src/lib/cc/tests/Makefile.am
View file @
392e7502
...
...
@@ -24,6 +24,7 @@ run_unittests_LDFLAGS = $(AM_LDFLAGS) $(GTEST_LDFLAGS)
run_unittests_LDADD
=
$(top_builddir)
/src/lib/cc/libkea-cc.la
run_unittests_LDADD
+=
$(top_builddir)
/src/lib/log/libkea-log.la
run_unittests_LDADD
+=
$(top_builddir)
/src/lib/asiolink/libkea-asiolink.la
run_unittests_LDADD
+=
$(top_builddir)
/src/lib/util/threads/libkea-threads.la
run_unittests_LDADD
+=
$(top_builddir)
/src/lib/util/unittests/libutil_unittests.la
run_unittests_LDADD
+=
$(top_builddir)
/src/lib/util/libkea-util.la
...
...
src/lib/cc/tests/simple_parser_unittest.cc
View file @
392e7502
...
...
@@ -9,6 +9,7 @@
#include <gtest/gtest.h>
using
namespace
isc
::
data
;
using
namespace
isc
::
asiolink
;
using
isc
::
dhcp
::
DhcpConfigError
;
/// This table defines sample default values. Although these are DHCPv6
...
...
@@ -210,3 +211,27 @@ TEST_F(SimpleParserTest, getAndConvert) {
EXPECT_THROW
(
parser
.
getAsBool
(
bad_bool
,
"bar"
),
DhcpConfigError
);
}
// This test exercises the getIOAddress
TEST_F
(
SimpleParserTest
,
getIOAddress
)
{
SimpleParserClassTest
parser
;
// getAddress checks it can be found
ElementPtr
not_found
=
Element
::
fromJSON
(
"{
\"
bar
\"
: 1 }"
);
EXPECT_THROW
(
parser
.
getAddress
(
not_found
,
"foo"
),
DhcpConfigError
);
// getAddress checks if it is a string
ElementPtr
not_addr
=
Element
::
fromJSON
(
"{
\"
foo
\"
: 1234 }"
);
EXPECT_THROW
(
parser
.
getAddress
(
not_addr
,
"foo"
),
DhcpConfigError
);
// checks if getAddress can return the expected value of v4 address
ElementPtr
v4
=
Element
::
fromJSON
(
"{
\"
foo
\"
:
\"
192.0.2.1
\"
}"
);
IOAddress
val
(
"::"
);
EXPECT_NO_THROW
(
val
=
parser
.
getAddress
(
v4
,
"foo"
));
EXPECT_EQ
(
"192.0.2.1"
,
val
.
toText
());
// checks if getAddress can return the expected value of v4 address
ElementPtr
v6
=
Element
::
fromJSON
(
"{
\"
foo
\"
:
\"
2001:db8::1
\"
}"
);
EXPECT_NO_THROW
(
val
=
parser
.
getAddress
(
v6
,
"foo"
));
EXPECT_EQ
(
"2001:db8::1"
,
val
.
toText
());
}
src/lib/dhcpsrv/parsers/dhcp_parsers.cc
View file @
392e7502
...
...
@@ -601,23 +601,11 @@ RelayInfoParser::RelayInfoParser(const Option::Universe& family)
:
family_
(
family
)
{
};
// Can't use a constructor as a function
namespace
{
IOAddress
buildIOAddress
(
const
std
::
string
&
str
)
{
return
(
IOAddress
(
str
));
}
};
IOAddress
RelayInfoParser
::
getIOAddress
(
ConstElementPtr
scope
,
const
std
::
string
&
name
)
{
return
(
getAndConvert
<
IOAddress
,
buildIOAddress
>
(
scope
,
name
,
"address"
));
}
void
RelayInfoParser
::
parse
(
const
isc
::
dhcp
::
Subnet
::
RelayInfoPtr
&
cfg
,
ConstElementPtr
relay_info
)
{
// There is only one parameter which is mandatory
IOAddress
ip
=
get
IO
Address
(
relay_info
,
"ip-address"
);
IOAddress
ip
=
getAddress
(
relay_info
,
"ip-address"
);
// Check if the address family matches.
if
((
ip
.
isV4
()
&&
family_
!=
Option
::
V4
)
||
...
...
@@ -905,13 +893,6 @@ SubnetConfigParser::createSubnet(ConstElementPtr params) {
//**************************** D2ClientConfigParser **********************
IOAddress
D2ClientConfigParser
::
getIOAddress
(
ConstElementPtr
scope
,
const
std
::
string
&
name
)
{
return
(
getAndConvert
<
IOAddress
,
buildIOAddress
>
(
scope
,
name
,
"address"
));
}
dhcp_ddns
::
NameChangeProtocol
D2ClientConfigParser
::
getProtocol
(
ConstElementPtr
scope
,
const
std
::
string
&
name
)
{
...
...
@@ -943,7 +924,7 @@ D2ClientConfigParser::parse(isc::data::ConstElementPtr client_config) {
// Get all parameters that are needed to create the D2ClientConfig.
bool
enable_updates
=
getBoolean
(
client_config
,
"enable-updates"
);
IOAddress
server_ip
=
get
IO
Address
(
client_config
,
"server-ip"
);
IOAddress
server_ip
=
getAddress
(
client_config
,
"server-ip"
);
uint32_t
server_port
=
getUint32
(
client_config
,
"server-port"
);
...
...
src/lib/dhcpsrv/parsers/dhcp_parsers.h
View file @
392e7502
...
...
@@ -634,16 +634,6 @@ public:
private:
/// @brief Returns a value converted to IOAddress
///
/// Instantiation of getAndConvert() to IOAddress
///
/// @param scope specified parameter will be extracted from this scope
/// @param name name of the parameter
/// @return an IOAddress value
isc
::
asiolink
::
IOAddress
getIOAddress
(
isc
::
data
::
ConstElementPtr
scope
,
const
std
::
string
&
name
);
/// Protocol family (IPv4 or IPv6)
Option
::
Universe
family_
;
};
...
...
@@ -787,16 +777,6 @@ public:
private:
/// @brief Returns a value converted to IOAddress
///
/// Instantiation of getAndConvert() to IOAddress
///
/// @param scope specified parameter will be extracted from this scope
/// @param name name of the parameter
/// @return an IOAddress value
isc
::
asiolink
::
IOAddress
getIOAddress
(
isc
::
data
::
ConstElementPtr
scope
,
const
std
::
string
&
name
);
/// @brief Returns a value converted to NameChangeProtocol
///
/// Instantiation of getAndConvert() to NameChangeProtocol
...
...
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