forked from selectel/kea-hook-remote_options
-
Notifications
You must be signed in to change notification settings - Fork 0
/
remopts_callouts.cc
84 lines (72 loc) · 2.29 KB
/
remopts_callouts.cc
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
// load_unload.cc
#include "remopts_callouts.h"
#include "remopts_log.h"
#include <cc/data.h>
#include <config.h>
#include <exceptions/exceptions.h>
#include <hooks/hooks.h>
using namespace isc;
using namespace isc::hooks;
using namespace isc::log;
using namespace isc::remopts;
using namespace isc::data;
// Kea has reversed boolean values...
int KEA_SUCCESS = 0;
int KEA_FAILURE = 1;
std::string conf_url;
std::string conf_user_class;
std::string conf_machine_guid;
extern "C" {
int load(LibraryHandle &handle) {
try {
ConstElementPtr param_url = handle.getParameter("url");
ConstElementPtr param_user_class = handle.getParameter("user_class");
ConstElementPtr param_machine_guid = handle.getParameter("machine_guid");
if (param_url) {
if (param_url->getType() != Element::string) {
isc_throw(BadValue, "Parameter 'url' should be a string!");
}
conf_url = param_url->stringValue();
LOG_DEBUG(remopts_logger, DBGLVL_TRACE_BASIC, REMOPTS_PARAM_VALUE)
.arg("url")
.arg(conf_url);
} else {
// parameter is mandatory
isc_throw(NotFound, "Parameter 'url' is mandatory!");
}
if (param_user_class) {
if (param_user_class->getType() != Element::string) {
isc_throw(BadValue, "Parameter 'user_class' should be a string!");
}
conf_user_class = param_user_class->stringValue();
LOG_DEBUG(remopts_logger, DBGLVL_TRACE_BASIC, REMOPTS_PARAM_VALUE)
.arg("user_class")
.arg(conf_user_class);
}
if (param_machine_guid) {
if (param_machine_guid->getType() != Element::string) {
isc_throw(BadValue, "Parameter 'machine_guid' should be a string!");
}
conf_machine_guid = param_machine_guid->stringValue();
LOG_DEBUG(remopts_logger, DBGLVL_TRACE_BASIC, REMOPTS_PARAM_VALUE)
.arg("machine_guid")
.arg(conf_machine_guid);
}
LOG_INFO(remopts_logger, REMOPTS_LOAD);
return KEA_SUCCESS;
} catch (const std::exception &ex) {
LOG_ERROR(remopts_logger, REMOPTS_LOAD_FAIL).arg(ex.what());
return KEA_FAILURE;
}
}
int unload() {
LOG_INFO(remopts_logger, REMOPTS_UNLOAD);
return (0);
}
// hook doesn't support multi-threading by now
int multi_threading_compatible() {
// 1 - compatible
// 0 - non compatible
return (0);
}
}