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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
|
/* Copyright (C) 2018 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#pragma once
#include <stdbool.h>
#include <stdint.h>
#include "knot/conf/conf.h"
#include "libknot/libknot.h"
#include "libknot/yparser/ypschema.h"
/*! Current version of the configuration database structure. */
#define CONF_DB_VERSION 2
/*! Minimum length of a database key ([category_id, item_id]. */
#define CONF_MIN_KEY_LEN (2 * sizeof(uint8_t))
/*! Maximum length of a database key ([category_id, item_id, identifier]. */
#define CONF_MAX_KEY_LEN (CONF_MIN_KEY_LEN + YP_MAX_ID_LEN)
/*! Maximum size of database data. */
#define CONF_MAX_DATA_LEN 65536
/*!
* Initializes the configuration DB if empty.
*
* \param[in] conf Configuration.
* \param[in] txn Configuration DB transaction.
* \param[in] purge Purge the DB indicator.
*
* \return Error code, KNOT_EOK if success.
*/
int conf_db_init(
conf_t *conf,
knot_db_txn_t *txn,
bool purge
);
/*!
* Checks the configuration DB and returns the number of items.
*
* \param[in] conf Configuration.
* \param[in] txn Configuration DB transaction.
*
* \return Error code, KNOT_EOK if ok and empty, > 0 number of records.
*/
int conf_db_check(
conf_t *conf,
knot_db_txn_t *txn
);
/*!
* Sets the item with data in the configuration DB.
*
* Singlevalued data is rewritten, multivalued data is appended.
*
* \note Setting of key0 without key1 has no effect.
*
* \param[in] conf Configuration.
* \param[in] txn Configuration DB transaction.
* \param[in] key0 Section name.
* \param[in] key1 Item name.
* \param[in] id Section identifier.
* \param[in] id_len Length of the section identifier.
* \param[in] data Item data.
* \param[in] data_len Length of the item data.
*
* \return Error code, KNOT_EOK if success.
*/
int conf_db_set(
conf_t *conf,
knot_db_txn_t *txn,
const yp_name_t *key0,
const yp_name_t *key1,
const uint8_t *id,
size_t id_len,
const uint8_t *data,
size_t data_len
);
/*!
* Unsets the item data in the configuration DB.
*
* If no data is provided, the whole item is remove.
*
* \param[in] conf Configuration.
* \param[in] txn Configuration DB transaction.
* \param[in] key0 Section name.
* \param[in] key1 Item name.
* \param[in] id Section identifier.
* \param[in] id_len Length of the section identifier.
* \param[in] data Item data.
* \param[in] data_len Length of the item data.
* \param[in] delete_key1 Set to unregister the item from the DB.
*
* \return Error code, KNOT_EOK if success.
*/
int conf_db_unset(
conf_t *conf,
knot_db_txn_t *txn,
const yp_name_t *key0,
const yp_name_t *key1,
const uint8_t *id,
size_t id_len,
const uint8_t *data,
size_t data_len,
bool delete_key1
);
/*!
* Gets the item data from the configuration DB.
*
* \param[in] conf Configuration.
* \param[in] txn Configuration DB transaction.
* \param[in] key0 Section name.
* \param[in] key1 Item name.
* \param[in] id Section identifier.
* \param[in] id_len Length of the section identifier.
* \param[out] data Item data.
*
* \return Error code, KNOT_EOK if success.
*/
int conf_db_get(
conf_t *conf,
knot_db_txn_t *txn,
const yp_name_t *key0,
const yp_name_t *key1,
const uint8_t *id,
size_t id_len,
conf_val_t *data
);
/*!
* Gets a configuration DB section iterator.
*
* \param[in] conf Configuration.
* \param[in] txn Configuration DB transaction.
* \param[in] key0 Section name.
* \param[out] iter Section iterator.
*
* \return Error code, KNOT_EOK if success.
*/
int conf_db_iter_begin(
conf_t *conf,
knot_db_txn_t *txn,
const yp_name_t *key0,
conf_iter_t *iter
);
/*!
* Moves the section iterator to the next identifier.
*
* \param[in] conf Configuration.
* \param[in,out] iter Section iterator.
*
* \return Error code, KNOT_EOK if success.
*/
int conf_db_iter_next(
conf_t *conf,
conf_iter_t *iter
);
/*!
* Gets the current section iterator value (identifier).
*
* \param[in] conf Configuration.
* \param[in] iter Section iterator.
* \param[out] data Identifier.
* \param[out] data_len Length of the identifier.
*
* \return Error code, KNOT_EOK if success.
*/
int conf_db_iter_id(
conf_t *conf,
conf_iter_t *iter,
const uint8_t **data,
size_t *data_len
);
/*!
* Deletes the current section iterator value (identifier).
*
* \param[in] conf Configuration.
* \param[in,out] iter Section iterator.
*
* \return Error code, KNOT_EOK if success.
*/
int conf_db_iter_del(
conf_t *conf,
conf_iter_t *iter
);
/*!
* Deletes the section iterator.
*
* \param[in] conf Configuration.
* \param[in,out] iter Section iterator.
*/
void conf_db_iter_finish(
conf_t *conf,
conf_iter_t *iter
);
/*!
* Dumps the configuration DB in the textual form.
*
* \note This function is intended for debugging.
*
* \param[in] conf Configuration.
* \param[in] txn Configuration DB transaction.
* \param[in] file_name File name to dump to (NULL to dump to stdout).
*
* \return Error code, KNOT_EOK if success.
*/
int conf_db_raw_dump(
conf_t *conf,
knot_db_txn_t *txn,
const char *file_name
);
|