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
1414dc61
Commit
1414dc61
authored
Jan 25, 2017
by
Francis Dupont
Browse files
[master] Finished merge of trac5097 (migrate pool config) use SimpleParser templates
parent
d2a71d82
Changes
3
Hide whitespace changes
Inline
Side-by-side
src/bin/dhcp6/json_config_parser.cc
View file @
1414dc61
...
...
@@ -199,9 +199,9 @@ public:
// Check the pool parameters. It will throw an exception if any
// of the required parameters are not present or invalid.
require
_
(
"prefix"
,
pd_pool_
);
require
_
(
"prefix-len"
,
pd_pool_
);
require
_
(
"delegated-len"
,
pd_pool_
);
require
Param
(
"prefix"
,
pd_pool_
);
require
Param
(
"prefix-len"
,
pd_pool_
);
require
Param
(
"delegated-len"
,
pd_pool_
);
try
{
// Attempt to construct the local pool.
pool_
.
reset
(
new
Pool6
(
IOAddress
(
addr_str
),
...
...
@@ -234,7 +234,7 @@ private:
/// @param name Entry name
/// @param config Pools configuration
/// @throw isc::dhcp::DhcpConfigError if not present
void
require
_
(
const
std
::
string
&
name
,
ConstElementPtr
config
)
const
{
void
require
Param
(
const
std
::
string
&
name
,
ConstElementPtr
config
)
const
{
if
(
!
config
->
contains
(
name
))
{
isc_throw
(
isc
::
dhcp
::
DhcpConfigError
,
"Missing parameter '"
<<
name
<<
"' ("
...
...
src/lib/dhcpsrv/parsers/dhcp_parsers.cc
View file @
1414dc61
...
...
@@ -1202,78 +1202,54 @@ SubnetConfigParser::getOptionalParam(const std::string& name) {
//**************************** D2ClientConfigParser **********************
namespace
{
template
<
typename
int_type
>
int_type
getInt
(
const
std
::
string
&
name
,
ConstElementPtr
value
)
{
int64_t
val_int
=
value
->
intValue
();
if
((
val_int
<
std
::
numeric_limits
<
int_type
>::
min
())
||
(
val_int
>
std
::
numeric_limits
<
int_type
>::
max
()))
{
isc_throw
(
DhcpConfigError
,
"out of range value ("
<<
val_int
<<
") specified for parameter '"
<<
name
<<
"' ("
<<
value
->
getPosition
()
<<
")"
);
}
return
(
static_cast
<
int_type
>
(
val_int
));
}
uint32_t
getUint32
(
const
std
::
string
&
name
,
ConstElementPtr
value
)
{
return
(
getInt
<
uint32_t
>
(
name
,
value
));
D2ClientConfigParser
::
getUint32
(
const
std
::
string
&
name
,
ConstElementPtr
value
)
const
{
return
(
extractInt
<
uint32_t
,
DhcpConfigError
>
(
name
,
value
));
}
namespace
{
IOAddress
buildIOAddress
(
const
std
::
string
&
str
)
{
return
(
IOAddress
(
str
));
}
};
IOAddress
getIOAddress
(
const
std
::
string
&
name
,
ConstElementPtr
value
)
{
std
::
string
str
=
value
->
stringValue
();
try
{
return
(
IOAddress
(
str
));
}
catch
(
const
std
::
exception
&
ex
)
{
isc_throw
(
DhcpConfigError
,
"invalid address ("
<<
str
<<
") specified for parameter '"
<<
name
<<
"' ("
<<
value
->
getPosition
()
<<
")"
);
}
D2ClientConfigParser
::
getIOAddress
(
const
std
::
string
&
name
,
ConstElementPtr
value
)
const
{
return
(
extractConvert
<
IOAddress
,
buildIOAddress
,
DhcpConfigError
>
(
name
,
"address"
,
value
));
}
dhcp_ddns
::
NameChangeProtocol
getProtocol
(
const
std
::
string
&
name
,
ConstElementPtr
value
)
{
std
::
string
str
=
value
->
stringValue
();
try
{
return
(
dhcp_ddns
::
stringToNcrProtocol
(
str
));
}
catch
(
const
std
::
exception
&
ex
)
{
isc_throw
(
DhcpConfigError
,
"invalid NameChangeRequest protocol ("
<<
str
<<
") specified for parameter '"
<<
name
<<
"' ("
<<
value
->
getPosition
()
<<
")"
);
}
D2ClientConfigParser
::
getProtocol
(
const
std
::
string
&
name
,
ConstElementPtr
value
)
const
{
return
(
extractConvert
<
dhcp_ddns
::
NameChangeProtocol
,
dhcp_ddns
::
stringToNcrProtocol
,
DhcpConfigError
>
(
name
,
"NameChangeRequest protocol"
,
value
));
}
dhcp_ddns
::
NameChangeFormat
getFormat
(
const
std
::
string
&
name
,
ConstElementPtr
value
)
{
std
::
string
str
=
value
->
stringValue
();
try
{
return
(
dhcp_ddns
::
stringToNcrFormat
(
str
));
}
catch
(
const
std
::
exception
&
ex
)
{
isc_throw
(
DhcpConfigError
,
"invalid NameChangeRequest format ("
<<
str
<<
") specified for parameter '"
<<
name
<<
"' ("
<<
value
->
getPosition
()
<<
")"
);
}
D2ClientConfigParser
::
getFormat
(
const
std
::
string
&
name
,
ConstElementPtr
value
)
const
{
return
(
extractConvert
<
dhcp_ddns
::
NameChangeFormat
,
dhcp_ddns
::
stringToNcrFormat
,
DhcpConfigError
>
(
name
,
"NameChangeRequest format"
,
value
));
}
D2ClientConfig
::
ReplaceClientNameMode
getMode
(
const
std
::
string
&
name
,
ConstElementPtr
value
)
{
std
::
string
str
=
value
->
stringValue
();
try
{
return
(
D2ClientConfig
::
stringToReplaceClientNameMode
(
str
));
}
catch
(
const
std
::
exception
&
ex
)
{
isc_throw
(
DhcpConfigError
,
"invalid ReplaceClientName mode ("
<<
str
<<
") specified for parameter '"
<<
name
<<
"' ("
<<
value
->
getPosition
()
<<
")"
);
}
D2ClientConfigParser
::
getMode
(
const
std
::
string
&
name
,
ConstElementPtr
value
)
const
{
return
(
extractConvert
<
D2ClientConfig
::
ReplaceClientNameMode
,
D2ClientConfig
::
stringToReplaceClientNameMode
,
DhcpConfigError
>
(
name
,
"ReplaceClientName mode"
,
value
));
}
};
D2ClientConfigPtr
D2ClientConfigParser
::
parse
(
isc
::
data
::
ConstElementPtr
client_config
)
{
D2ClientConfigPtr
new_config
;
...
...
src/lib/dhcpsrv/parsers/dhcp_parsers.h
View file @
1414dc61
...
...
@@ -986,6 +986,57 @@ public:
// to ElementPtr)
/// @return number of parameters inserted
static
size_t
setAllDefaults
(
isc
::
data
::
ConstElementPtr
d2_config
);
private:
/// @brief Returns a value converted to uint32_t
///
/// Instantiation of extractInt() to uint32_t
///
/// @param value value of the parameter
/// @return an uint32_t value
uint32_t
getUint32
(
const
std
::
string
&
name
,
isc
::
data
::
ConstElementPtr
value
)
const
;
/// @brief Returns a value converted to IOAddress
///
/// Instantiation of extractConvert() to IOAddress
///
/// @param value value of the parameter
/// @return an IOAddress value
isc
::
asiolink
::
IOAddress
getIOAddress
(
const
std
::
string
&
name
,
isc
::
data
::
ConstElementPtr
value
)
const
;
/// @brief Returns a value converted to NameChangeProtocol
///
/// Instantiation of extractInt() to NameChangeProtocol
///
/// @param value value of the parameter
/// @return a NameChangeProtocol value
dhcp_ddns
::
NameChangeProtocol
getProtocol
(
const
std
::
string
&
name
,
isc
::
data
::
ConstElementPtr
value
)
const
;
/// @brief Returns a value converted to NameChangeFormat
///
/// Instantiation of extractConvert() to NameChangeFormat
///
/// @param value value of the parameter
/// @return a NameChangeFormat value
dhcp_ddns
::
NameChangeFormat
getFormat
(
const
std
::
string
&
name
,
isc
::
data
::
ConstElementPtr
value
)
const
;
/// @brief Returns a value converted to ReplaceClientNameMode
///
/// Instantiation of extractConvert() to ReplaceClientNameMode
///
/// @param value value of the parameter
/// @return a NameChangeFormat value
D2ClientConfig
::
ReplaceClientNameMode
getMode
(
const
std
::
string
&
name
,
isc
::
data
::
ConstElementPtr
value
)
const
;
};
// Pointers to various parser objects.
...
...
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