summaryrefslogtreecommitdiffstats
path: root/src/bin/d2/tests/configured_library.cc
blob: 3aeb94d0866925992059878dc1ef6e08f745c740 (plain)
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
// Copyright (C) 2021 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/.

/// @brief d2_srv_configured callout testing library

#include <config.h>
#include <cc/data.h>
#include <hooks/hooks.h>

using namespace isc::data;
using namespace isc::hooks;
using namespace std;

namespace {

extern "C" {

// d2_srv_configured callout.
int
d2_srv_configured(CalloutHandle& handle) {
    // Get the parameters.
    ConstElementPtr cfg;
    string error;
    handle.getArgument("json_config", cfg);
    handle.getArgument("error", error);

    if (cfg) {
        ConstElementPtr uc = cfg->get("user-context");
        if (uc) {
            ConstElementPtr msg = uc->get("error");
            if (msg && (msg->getType() == Element::string)) {
                error += msg->stringValue();
            }
        }
    }

    if (!error.empty()) {
        handle.setArgument("error", error);
        handle.setStatus(CalloutHandle::NEXT_STEP_DROP);
    }
    return (0);
}

// Framework functions.
int
version() {
    return (KEA_HOOKS_VERSION);
}

// load() initializes the user library if the main image was statically linked.
int
load(isc::hooks::LibraryHandle&) {
#ifdef USE_STATIC_LINK
    hooksStaticLinkInit();
#endif
    return (0);
}

}
}