Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
7
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Open sidebar
Sebastian Schrader
Kea
Commits
8792cbac
Commit
8792cbac
authored
Dec 11, 2012
by
Tomek Mrugalski
🛰
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[2270] Changes after review.
parent
9c2193e3
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
23 additions
and
51 deletions
+23
-51
src/bin/dhcp4/config_parser.cc
src/bin/dhcp4/config_parser.cc
+21
-49
src/bin/dhcp4/tests/config_parser_unittest.cc
src/bin/dhcp4/tests/config_parser_unittest.cc
+2
-2
No files found.
src/bin/dhcp4/config_parser.cc
View file @
8792cbac
...
...
@@ -12,9 +12,6 @@
// OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
// PERFORMANCE OF THIS SOFTWARE.
// We want UINT32_MAX macro to be defined in stdint.h
#define __STDC_LIMIT_MACROS
#include <boost/foreach.hpp>
#include <boost/lexical_cast.hpp>
#include <boost/algorithm/string.hpp>
...
...
@@ -22,8 +19,7 @@
#include <dhcp/cfgmgr.h>
#include <dhcp4/config_parser.h>
#include <dhcp4/dhcp4_log.h>
#include <stdint.h>
#include <limits>
#include <iostream>
#include <vector>
#include <map>
...
...
@@ -150,7 +146,7 @@ public:
isc_throw
(
BadValue
,
"Failed to parse value "
<<
value
->
str
()
<<
" as unsigned 32-bit integer."
);
}
if
(
check
>
UINT32_MAX
)
{
if
(
check
>
std
::
numeric_limits
<
uint32_t
>::
max
()
)
{
isc_throw
(
BadValue
,
"Value "
<<
value
->
str
()
<<
"is too large"
<<
" for unsigned 32-bit integer."
);
}
...
...
@@ -162,9 +158,7 @@ public:
// value is small enough to fit
value_
=
static_cast
<
uint32_t
>
(
check
);
/// @todo: check if there is no such name in the map. Otherwise
/// the insert will fail silently
storage_
->
insert
(
pair
<
string
,
uint32_t
>
(
param_name_
,
value_
));
(
*
storage_
)[
param_name_
]
=
value_
;
}
/// @brief does nothing
...
...
@@ -194,7 +188,7 @@ public:
storage_
=
storage
;
}
pr
otec
te
d
:
pr
iva
te:
/// pointer to the storage, where parsed value will be stored
Uint32Storage
*
storage_
;
...
...
@@ -234,9 +228,8 @@ public:
virtual
void
build
(
ConstElementPtr
value
)
{
value_
=
value
->
str
();
boost
::
erase_all
(
value_
,
"
\"
"
);
/// @todo: check if there is no such name in the map. Otherwise
/// the insert will fail silently
storage_
->
insert
(
pair
<
string
,
string
>
(
param_name_
,
value_
));
(
*
storage_
)[
param_name_
]
=
value_
;
}
/// @brief does nothing
...
...
@@ -266,7 +259,7 @@ public:
storage_
=
storage
;
}
pr
otec
te
d
:
pr
iva
te:
/// pointer to the storage, where parsed value will be stored
StringStorage
*
storage_
;
...
...
@@ -328,7 +321,7 @@ public:
return
(
new
InterfaceListConfigParser
(
param_name
));
}
pr
otec
te
d
:
pr
iva
te:
/// contains list of network interfaces
vector
<
string
>
interfaces_
;
};
...
...
@@ -450,7 +443,7 @@ public:
return
(
new
PoolParser
(
param_name
));
}
pr
otec
te
d
:
pr
iva
te:
/// @brief pointer to the actual Pools storage
///
/// That is typically a storage somewhere in Subnet parser
...
...
@@ -555,7 +548,7 @@ public:
CfgMgr
::
instance
().
addSubnet4
(
subnet
);
}
pr
otec
te
d
:
pr
iva
te:
/// @brief creates parsers for entries in subnet definition
///
...
...
@@ -567,18 +560,11 @@ protected:
Dhcp4ConfigParser
*
createSubnet4ConfigParser
(
const
std
::
string
&
config_id
)
{
FactoryMap
factories
;
factories
.
insert
(
pair
<
string
,
ParserFactory
*>
(
"valid-lifetime"
,
Uint32Parser
::
Factory
));
factories
.
insert
(
pair
<
string
,
ParserFactory
*>
(
"renew-timer"
,
Uint32Parser
::
Factory
));
factories
.
insert
(
pair
<
string
,
ParserFactory
*>
(
"rebind-timer"
,
Uint32Parser
::
Factory
));
factories
.
insert
(
pair
<
string
,
ParserFactory
*>
(
"subnet"
,
StringParser
::
Factory
));
factories
.
insert
(
pair
<
string
,
ParserFactory
*>
(
"pool"
,
PoolParser
::
Factory
));
factories
[
"valid-lifetime"
]
=
Uint32Parser
::
Factory
;
factories
[
"renew-timer"
]
=
Uint32Parser
::
Factory
;
factories
[
"rebind-timer"
]
=
Uint32Parser
::
Factory
;
factories
[
"subnet"
]
=
StringParser
::
Factory
;
factories
[
"pool"
]
=
PoolParser
::
Factory
;
FactoryMap
::
iterator
f
=
factories
.
find
(
config_id
);
if
(
f
==
factories
.
end
())
{
...
...
@@ -711,20 +697,12 @@ public:
Dhcp4ConfigParser
*
createGlobalDhcp4ConfigParser
(
const
std
::
string
&
config_id
)
{
FactoryMap
factories
;
factories
.
insert
(
pair
<
string
,
ParserFactory
*>
(
"valid-lifetime"
,
Uint32Parser
::
Factory
));
factories
.
insert
(
pair
<
string
,
ParserFactory
*>
(
"renew-timer"
,
Uint32Parser
::
Factory
));
factories
.
insert
(
pair
<
string
,
ParserFactory
*>
(
"rebind-timer"
,
Uint32Parser
::
Factory
));
factories
.
insert
(
pair
<
string
,
ParserFactory
*>
(
"interface"
,
InterfaceListConfigParser
::
Factory
));
factories
.
insert
(
pair
<
string
,
ParserFactory
*>
(
"subnet4"
,
Subnets4ListConfigParser
::
Factory
));
factories
.
insert
(
pair
<
string
,
ParserFactory
*>
(
"version"
,
StringParser
::
Factory
));
factories
[
"valid-lifetime"
]
=
Uint32Parser
::
Factory
;
factories
[
"renew-timer"
]
=
Uint32Parser
::
Factory
;
factories
[
"rebind-timer"
]
=
Uint32Parser
::
Factory
;
factories
[
"interface"
]
=
InterfaceListConfigParser
::
Factory
;
factories
[
"subnet4"
]
=
Subnets4ListConfigParser
::
Factory
;
factories
[
"version"
]
=
StringParser
::
Factory
;
FactoryMap
::
iterator
f
=
factories
.
find
(
config_id
);
if
(
f
==
factories
.
end
())
{
...
...
@@ -738,8 +716,6 @@ Dhcp4ConfigParser* createGlobalDhcp4ConfigParser(const std::string& config_id) {
return
(
f
->
second
(
config_id
));
}
/// @brief configures DHCPv4 server
///
isc
::
data
::
ConstElementPtr
configureDhcp4Server
(
Dhcpv4Srv
&
,
ConstElementPtr
config_set
)
{
if
(
!
config_set
)
{
...
...
@@ -748,10 +724,6 @@ configureDhcp4Server(Dhcpv4Srv& , ConstElementPtr config_set) {
return
(
answer
);
}
/// Let's wipe previous configuration defaults
uint32_defaults
.
clear
();
string_defaults
.
clear
();
/// @todo: append most essential info here (like "2 new subnets configured")
string
config_details
;
...
...
src/bin/dhcp4/tests/config_parser_unittest.cc
View file @
8792cbac
...
...
@@ -98,7 +98,7 @@ TEST_F(Dhcp4ParserTest, version) {
/// The goal of this test is to verify that the code accepts only
/// valid commands and malformed or unsupported parameters are rejected.
TEST_F
(
Dhcp4ParserTest
,
bogus
_c
ommand
)
{
TEST_F
(
Dhcp4ParserTest
,
bogus
C
ommand
)
{
ConstElementPtr
x
;
...
...
@@ -133,7 +133,7 @@ TEST_F(Dhcp4ParserTest, emptySubnet) {
/// The goal of this test is to verify if defined subnet uses global
/// parameter timer definitions.
TEST_F
(
Dhcp4ParserTest
,
subnet
_g
lobal
_d
efaults
)
{
TEST_F
(
Dhcp4ParserTest
,
subnet
G
lobal
D
efaults
)
{
ConstElementPtr
status
;
...
...
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