1 /*  Copyright (C) 2021 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
2 
3     This program is free software: you can redistribute it and/or modify
4     it under the terms of the GNU General Public License as published by
5     the Free Software Foundation, either version 3 of the License, or
6     (at your option) any later version.
7 
8     This program is distributed in the hope that it will be useful,
9     but WITHOUT ANY WARRANTY; without even the implied warranty of
10     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11     GNU General Public License for more details.
12 
13     You should have received a copy of the GNU General Public License
14     along with this program.  If not, see <https://www.gnu.org/licenses/>.
15  */
16 
17 #pragma once
18 
19 #include "utils/knotc/commands.h"
20 
21 #define DEFAULT_CTL_TIMEOUT_MS	(60 * 1000)
22 
23 /*! Utility command line parameters. */
24 typedef struct {
25 	const char *config;
26 	const char *confdb;
27 	size_t max_conf_size;
28 	const char *socket;
29 	bool verbose;
30 	bool force;
31 	bool blocking;
32 	int timeout;
33 } params_t;
34 
35 /*!
36  * Prepares a proper configuration according to the specified command.
37  *
38  * \param[in] desc    Utility command descriptor.
39  * \param[in] params  Utility parameters.
40  *
41  * \return Error code, KNOT_EOK if successful.
42  */
43 int set_config(const cmd_desc_t *desc, params_t *params);
44 
45 /*!
46  * Estabilishes a control interface if necessary.
47  *
48  * \param[in] ctl      Control context.
49  * \param[in] socket   Control socket path.
50  * \param[in] timeout  Control socket timeout.
51  * \param[in] desc     Utility command descriptor.
52  *
53  * \return Error code, KNOT_EOK if successful.
54  */
55 int set_ctl(knot_ctl_t **ctl, const char *socket, int timeout, const cmd_desc_t *desc);
56 
57 /*!
58  * Cleans up the control context.
59  *
60  * \param[in] ctl     Control context.
61  */
62 void unset_ctl(knot_ctl_t *ctl);
63 
64 /*!
65  * Processes the given utility command.
66  *
67  * \param[in] argc    Number of command arguments.
68  * \param[in] argv    Command arguments.
69  * \param[in] params  Utility parameters.
70  *
71  * \return Error code, KNOT_EOK if successful.
72  */
73 int process_cmd(int argc, const char **argv, params_t *params);
74