16using namespace libyang;
 
   17using namespace sysrepo;
 
   29        if ((
model_ == KEA_DHCP4_SERVER) ||
 
   30            (
model_ == KEA_DHCP6_SERVER) ||
 
   31            (
model_ == KEA_DHCP_DDNS)) {
 
   33        } 
else if (
model_ == KEA_CTRL_AGENT) {
 
   36    } 
catch (Error 
const& ex) {
 
   38                  "getting control socket: " << ex.
what());
 
   41              "getControlSocket not implemented for the model: " << 
model_);
 
 
   47        if ((
model_ == KEA_DHCP4_SERVER) ||
 
   48            (
model_ == KEA_DHCP6_SERVER) ||
 
   49            (
model_ == KEA_DHCP_DDNS) ||
 
   50            (
model_ == KEA_CTRL_AGENT)) {
 
   53    } 
catch (Error 
const& ex) {
 
   55                  "getting control socket: " << ex.
what());
 
   58              "getControlSocket not implemented for the model: " << 
model_);
 
 
   71    if (
model_ != KEA_CTRL_AGENT) {
 
   79                    [&](DataNode 
const& node) -> 
ElementPtr const {
 
   83                        if (const_authentication) {
 
   84                            authentication = 
copy(const_authentication);
 
   95                            authentication->set(
"clients", clients);
 
   97                        return (authentication);
 
  100        if (headers && !headers->empty()) {
 
  101            result->set(
"http-headers", headers);
 
  105    return (result->empty() ? 
ElementPtr() : result);
 
 
  110    return getList(data_node, 
"http-headers", *
this,
 
 
  120    return (result->empty() ? 
ElementPtr() : result);
 
 
  125    return getList(data_node, 
"clients", *
this,
 
 
  137    if (result->get(
"user") && result->get(
"user")->stringValue().empty()) {
 
  138        result->remove(
"user");
 
  140    if (result->get(
"password") && result->get(
"password")->stringValue().empty()) {
 
  141        result->remove(
"password");
 
  143    if (result->get(
"user-file") && result->get(
"user-file")->stringValue().empty()) {
 
  144        result->remove(
"user-file");
 
  146    if (result->get(
"password-file") && result->get(
"password-file")->stringValue().empty()) {
 
  147        result->remove(
"password-file");
 
  149    return (result->empty() ? 
ElementPtr() : result);
 
 
  165        if ((
model_ == KEA_DHCP4_SERVER) ||
 
  166            (
model_ == KEA_DHCP6_SERVER) ||
 
  167            (
model_ == KEA_DHCP_DDNS)) {
 
  169        } 
else if (
model_ == KEA_CTRL_AGENT) {
 
  173                    "setControlSocket not implemented for the model: " 
  176    } 
catch (Error 
const& ex) {
 
  178                  "setting control socket '" << elem->str()
 
  179                  << 
"' at '" << xpath << 
"': " << ex.what());
 
 
  187        if ((
model_ == KEA_DHCP4_SERVER) ||
 
  188            (
model_ == KEA_DHCP6_SERVER) ||
 
  189            (
model_ == KEA_DHCP_DDNS) ||
 
  190            (
model_ == KEA_CTRL_AGENT)) {
 
  194                    "setControlSocket not implemented for the model: " 
  197    } 
catch (Error 
const& ex) {
 
  199                  "setting control socket '" << elem->str()
 
  200                  << 
"' at '" << xpath << 
"': " << ex.what());
 
 
  211    for (
size_t i = 0; i < elem->size(); ++i) {
 
  212        ElementPtr control_socket = elem->getNonConst(i);
 
  213        if (!control_socket->contains(
"socket-type")) {
 
  214            isc_throw(
BadValue, 
"control-socket without socket-type: " << control_socket->str());
 
  216        string type = control_socket->get(
"socket-type")->stringValue();
 
  218        key << xpath << 
"[socket-type='" << type << 
"']";
 
 
  226                                             bool has_mandatory_key) {
 
  232    if (has_mandatory_key) {
 
  240    if (
model_ != KEA_CTRL_AGENT) {
 
  248        if (authentication && !authentication->empty()) {
 
  250            checkAndSetLeaf(authentication, xpath + 
"/authentication", 
"realm", LeafBaseType::String);
 
  251            checkAndSetLeaf(authentication, xpath + 
"/authentication", 
"directory", LeafBaseType::String);
 
  257        if (http_headers && !http_headers->empty()) {
 
 
  271    for (
size_t i = 0; i < elem->size(); ++i) {
 
  273        auto user = client->get(
"user");
 
  276            user_str = user->stringValue();
 
  278        auto password = client->get(
"password");
 
  281            password_str = password->stringValue();
 
  283        auto user_file = client->get(
"user-file");
 
  284        string user_file_str;
 
  286            user_file_str = user_file->stringValue();
 
  288        auto password_file = client->get(
"password-file");
 
  289        string password_file_str;
 
  291            password_file_str = password_file->stringValue();
 
  294        key << xpath << 
"[user='" << user_str << 
"'][password='" << password_str
 
  295                     << 
"'][user-file='" << user_file_str << 
"'][password-file='" 
  296                     << password_file_str << 
"']";
 
 
  321        key << xpath << 
"[name='" << name->stringValue() << 
"']";
 
 
static ElementPtr createMap(const Position &pos=ZERO_POSITION())
Creates an empty MapElement type ElementPtr.
A generic exception that is thrown if a parameter given to a method is considered invalid in that con...
virtual const char * what() const
Returns a C-style character string of the cause of the exception.
A generic exception that is thrown when a function is not implemented.
void setControlSocket(const std::string &xpath, isc::data::ConstElementPtr elem)
Translate and set control socket from JSON to YANG.
TranslatorControlSocket(sysrepo::Session session, const std::string &model)
Constructor.
void setControlSockets(const std::string &xpath, isc::data::ConstElementPtr elem)
Translate and set control sockets from JSON to YANG.
isc::data::ElementPtr getControlSocketAuthenticationClients(libyang::DataNode const &data_node)
getControlSocketsAuthenticationClients JSON for kea models.
isc::data::ElementPtr getControlSocket(libyang::DataNode const &data_node)
Translate a control socket from YANG to JSON.
isc::data::ElementPtr getControlSocketAuthenticationClient(libyang::DataNode const &data_node)
getControlSocketsAuthenticationClients JSON for kea models.
isc::data::ElementPtr getControlSocketKea(libyang::DataNode const &data_node)
getControlSocket JSON for kea models.
isc::data::ElementPtr getControlSockets(libyang::DataNode const &data_node)
Translate a control socket from YANG to JSON.
isc::data::ElementPtr getControlSocketFromAbsoluteXpath(std::string const &xpath)
Translate a control socket from YANG to JSON.
isc::data::ElementPtr getControlSocketsKea(libyang::DataNode const &data_node)
getControlSocket JSON for kea models.
void setControlSocketHttpHeader(const std::string &xpath, isc::data::ConstElementPtr elem)
setControlSocketHttpHeader for kea models.
void setControlSocketAuthenticationClients(const std::string &xpath, isc::data::ConstElementPtr elem)
setControlSocketAuthenticationClients for kea models.
void setControlSocketKea(const std::string &xpath, isc::data::ConstElementPtr elem, bool has_mandatory_key)
setControlSocket for kea models.
isc::data::ElementPtr getControlSocketHttpHeader(libyang::DataNode const &data_node)
getControlSocketsAuthenticationClients JSON for kea models.
isc::data::ElementPtr getControlSocketHttpHeaders(libyang::DataNode const &data_node)
getControlSocketsAuthenticationClients JSON for kea models.
void setControlSocketsKea(const std::string &xpath, isc::data::ConstElementPtr elem)
setControlSocket for kea models.
void setControlSocketAuthenticationClient(const std::string &xpath, isc::data::ConstElementPtr elem)
setControlSocketAuthenticationClient for kea models.
void setControlSocketHttpHeaders(const std::string &xpath, isc::data::ConstElementPtr elem)
setControlSocketHttpHeaders for kea models.
isc::data::ElementPtr getList(libyang::DataNode const &data_node, std::string const &xpath, T &t, isc::data::ElementPtr(T::*f)(libyang::DataNode const &)) const
Retrieve a list as ElementPtr from sysrepo from a certain xpath.
void checkAndSetLeaf(isc::data::ConstElementPtr const &from, std::string const &xpath, std::string const &name, libyang::LeafBaseType const type)
Get an element from given ElementPtr node and set it in sysrepo at given xpath.
void checkAndGet(isc::data::ElementPtr const &storage, libyang::DataNode const &data_node, std::string const &xpath, T translate) const
Calls {translate} for the element found at {xpath} relative to {data_node} and sets the result in {st...
void setMandatoryDivergingLeaf(isc::data::ConstElementPtr const &from, std::string const &xpath, std::string const &name, std::string const &yang_name, libyang::LeafBaseType const type)
Get an element from given ElementPtr node and set it in sysrepo at given xpath.
libyang::DataNode findXPath(std::string const &xpath) const
Retrieves a YANG data node by xpath.
void getMandatoryLeaf(isc::data::ElementPtr &storage, libyang::DataNode const &data_node, std::string const &name) const
Retrieves a child YANG data node identified by name from the given parent YANG container node and sto...
void checkAndGetLeaf(isc::data::ElementPtr &storage, libyang::DataNode const &data_node, std::string const &name) const
Retrieves a child YANG data node identified by name from the given parent YANG container node and sto...
void checkAndSetUserContext(isc::data::ConstElementPtr const &from, std::string const &xpath)
Get an element from given ElementPtr node and set it in sysrepo at given xpath.
void deleteItem(const std::string &xpath)
Delete basic value from YANG.
void checkAndGetDivergingLeaf(isc::data::ElementPtr &storage, libyang::DataNode const &data_node, std::string const &name, std::string const &yang_name) const
Retrieves a child YANG data node identified by name from the given parent YANG container node and sto...
void setItem(const std::string &xpath, isc::data::ConstElementPtr const elem, libyang::LeafBaseType const type)
Translate and set basic value from JSON to YANG.
std::string model_
The model.
void checkAndGetAndJsonifyLeaf(isc::data::ElementPtr &storage, libyang::DataNode const &data_node, const std::string &name) const
Retrieves a child YANG data node identified by name from the given parent YANG container node,...
Translator(sysrepo::Session session, const std::string &model)
Constructor.
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
ElementPtr copy(ConstElementPtr from, int level)
Copy the data up to a nesting level.
boost::shared_ptr< const Element > ConstElementPtr
boost::shared_ptr< Element > ElementPtr
Defines the logger used by the top-level component of kea-lfc.