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
// Copyright (C) 2018-2024 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/adaptor_pool.h>
#include <yang/yang_models.h>

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

using namespace std;
using namespace isc::data;

namespace isc {
namespace yang {

void
AdaptorPool::canonizePool(ElementPtr pool) {
    const string& orig = pool->get("pool")->stringValue();
    vector<char> v;
    for (auto ch : orig) {
        if ((ch == ' ') || (ch == '\t') || (ch == '\n')) {
            continue;
        } else if (ch == '-') {
            v.push_back(' ');
            v.push_back(ch);
            v.push_back(' ');
        } else {
            v.push_back(ch);
        }
    }
    string canon;
    canon.assign(v.begin(), v.end());
    if (orig != canon) {
        pool->set("pool", Element::create(canon));
    }
}

void
AdaptorPool::fromSubnet(const string& model, ConstElementPtr subnet,
                        ConstElementPtr pools) {
    if (model == IETF_DHCPV6_SERVER) {
        fromSubnetIetf6(subnet, pools);
    } else if ((model != KEA_DHCP4_SERVER) &&
               (model != KEA_DHCP6_SERVER)) {
        isc_throw(NotImplemented,
                  "fromSubnet not implemented for the model: " << model);
    }
}

void
AdaptorPool::fromSubnetIetf6(ConstElementPtr subnet, ConstElementPtr pools) {
    Adaptor::fromParent("valid-lifetime", subnet, pools);
    Adaptor::fromParent("preferred-lifetime", subnet, pools);
    Adaptor::fromParent("renew-timer", subnet, pools);
    Adaptor::fromParent("rebind-timer", subnet, pools);
}

void
AdaptorPool::toSubnet(const string& model, ElementPtr subnet,
                      ConstElementPtr pools) {
    if (model == IETF_DHCPV6_SERVER) {
        toSubnetIetf6(subnet, pools);
    } else if ((model != KEA_DHCP4_SERVER) &&
               (model != KEA_DHCP6_SERVER)) {
        isc_throw(NotImplemented,
                  "toSubnet not implemented for the model: " << model);
    }
}

void
AdaptorPool::toSubnetIetf6(ElementPtr subnet, ConstElementPtr pools) {
    Adaptor::toParent("valid-lifetime", subnet, pools);
    Adaptor::toParent("preferred-lifetime", subnet, pools);
    Adaptor::toParent("renew-timer", subnet, pools);
    Adaptor::toParent("rebind-timer", subnet, pools);
}

}  // namespace yang
}  // namespace isc