1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
// Copyright (C) 2018-2022 Internet Systems Consortium, Inc. ("ISC")
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.

#include <config.h>

#include <yang/translator_control_socket.h>
#include <yang/yang_models.h>

#include <sstream><--- Include file:  not found. Please note: Cppcheck does not need standard library headers to get proper results.

using namespace std;
using namespace isc::data;
using namespace libyang;
using namespace sysrepo;

namespace isc {
namespace yang {

TranslatorControlSocket::TranslatorControlSocket(Session session,
                                                 const string& model)
    : Translator(session, model) {
}

ElementPtr
TranslatorControlSocket::getControlSocket(DataNode const& data_node) {
    try {
        if ((model_ == KEA_DHCP4_SERVER) ||
            (model_ == KEA_DHCP6_SERVER) ||
            (model_ == KEA_DHCP_DDNS) ||
            (model_ == KEA_CTRL_AGENT)) {
            return (getControlSocketKea(data_node));
        }
    } catch (Error const& ex) {
        isc_throw(NetconfError,
                  "getting control socket: " << ex.what());
    }
    isc_throw(NotImplemented,
              "getControlSocket not implemented for the model: " << model_);
}

ElementPtr
TranslatorControlSocket::getControlSocketKea(DataNode const& data_node) {
    ElementPtr result(Element::createMap());
    getMandatoryLeaf(result, data_node, "socket-name");
    getMandatoryLeaf(result, data_node, "socket-type");
    checkAndGetAndJsonifyLeaf(result, data_node, "user-context");
    return (result->empty() ? ElementPtr() : result);
}

ElementPtr
TranslatorControlSocket::getControlSocketFromAbsoluteXpath(string const& xpath) {
    try {
        return getControlSocket(findXPath(xpath));
    } catch (NetconfError const&) {
        return ElementPtr();
    }
}

void
TranslatorControlSocket::setControlSocket(string const& xpath,
                                          ConstElementPtr elem) {
    try {
        if ((model_ == KEA_DHCP4_SERVER) ||
            (model_ == KEA_DHCP6_SERVER) ||
            (model_ == KEA_DHCP_DDNS) ||
            (model_ == KEA_CTRL_AGENT)) {
            setControlSocketKea(xpath, elem);
        } else {
          isc_throw(NotImplemented,
                    "setControlSocket not implemented for the model: "
                    << model_);
        }
    } catch (Error const& ex) {
        isc_throw(NetconfError,
                  "setting control socket '" << elem->str()
                  << "' at '" << xpath << "': " << ex.what());
    }
}

void
TranslatorControlSocket::setControlSocketKea(string const& xpath,
                                             ConstElementPtr elem) {
    if (!elem) {
        deleteItem(xpath);
        return;
    }

    setMandatoryLeaf(elem, xpath, "socket-name", LeafBaseType::String);
    setMandatoryLeaf(elem, xpath, "socket-type", LeafBaseType::Enum);
    checkAndSetUserContext(elem, xpath);
}

}  // namespace yang
}  // namespace isc