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
|
// Copyright (C) 2013-2018 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/.
/// @file
/// @brief Marker file callout library
///
/// This is the source of a test library for the DHCP parser and configuration
/// tests.
///
/// To check that they libraries are loaded and unloaded correctly, the load
/// and unload functions in this library maintain two marker files - the load
/// marker file and the unload marker file. The functions append a single
/// line to the file, creating the file if need be. In this way, the test code
/// can determine whether the load/unload functions have been run and, if so,
/// in what order.
///
/// The additional marker file is created for the dhcp4_srv_configured hook
/// point. It records the library number and the names of the parameters
/// provided to the callout.
///
/// This file is the common library file for the tests. It will not compile
/// by itself - it is included into each callout library which specifies the
/// missing constant LIBRARY_NUMBER before the inclusion.
#include <config.h>
#include <hooks/hooks.h>
#include "marker_file.h"
#include <fstream>
extern "C" {
/// @brief Append digit to marker file
///
/// If the marker file does not exist, create it. Then append the single
/// digit (given by the constant LIBRARY_NUMBER) defined earlier to it and
/// close the file.
///
/// @param name Name of the file to open
///
/// @return 0 on success, non-zero on error.
int
appendDigit(const char* name) {
// Open the file and check if successful.
std::fstream file(name, std::fstream::out | std::fstream::app);
if (!file.good()) {
return (1);
}
// Add the library number to it and close.
file << LIBRARY_NUMBER;
file.close();
return (0);
}
/// @brief Append argument name passed to the callout to a marker file.
///
/// @param file_name Name of the file to open.
/// @param parameter Parameter name.
///
/// @return 0 on success, non-zero on error.
int appendArgument(const char* file_name, const char* argument) {
// Open the file and check if successful.
std::fstream file(file_name, std::fstream::out | std::fstream::app);
if (!file.good()) {
return (1);
}
// Add the library number to it and close.
file << argument;
file.close();
return (0);
}
// Framework functions
int
version() {
return (KEA_HOOKS_VERSION);
}
int
load(isc::hooks::LibraryHandle&) {
return (appendDigit(LOAD_MARKER_FILE));
}
int
unload() {
return (appendDigit(UNLOAD_MARKER_FILE));
}
};
|