1 /*  Copyright (C) 2017 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 /*!
18  * \file
19  *
20  * \brief Tools for Yparser format creation.
21  *
22  * \addtogroup yparser
23  * @{
24  */
25 
26 #pragma once
27 
28 #include "libknot/yparser/ypschema.h"
29 
30 /*!
31  * Formats key0 item.
32  *
33  * \param[in] item Schema item to format.
34  * \param[in] data Data to format.
35  * \param[in] data_len Data length.
36  * \param[out] out Output buffer.
37  * \param[in, out] out_len Output buffer length, output length.
38  * \param[in] style Value style.
39  * \param[in] first_value First value indication (multivalued support).
40  * \param[in] last_value Last value indication (multivalued support).
41  *
42  * \return Error code, KNOT_EOK if success.
43  */
44 int yp_format_key0(
45 	const yp_item_t *item,
46 	const uint8_t *data,
47 	size_t data_len,
48 	char *out,
49 	size_t out_len,
50 	yp_style_t style,
51 	bool first_value,
52 	bool last_value
53 );
54 
55 /*!
56  * Formats identifier item.
57  *
58  * \param[in] item Schema item to format.
59  * \param[in] data Data to format.
60  * \param[in] data_len Data length.
61  * \param[out] out Output buffer.
62  * \param[in, out] out_len Output buffer length, output length.
63  * \param[in] style Value style.
64  *
65  * \return Error code, KNOT_EOK if success.
66  */
67 int yp_format_id(
68 	const yp_item_t *item,
69 	const uint8_t *data,
70 	size_t data_len,
71 	char *out,
72 	size_t out_len,
73 	yp_style_t style
74 );
75 
76 /*!
77  * Formats key1 item.
78  *
79  * \param[in] item Schema item to format.
80  * \param[in] data Data to format.
81  * \param[in] data_len Data length.
82  * \param[out] out Output buffer.
83  * \param[in, out] out_len Output buffer length, output length.
84  * \param[in] style Value style.
85  * \param[in] first_value First value indication (multivalued support).
86  * \param[in] last_value Last value indication (multivalued support).
87  *
88  * \return Error code, KNOT_EOK if success.
89  */
90 int yp_format_key1(
91 	const yp_item_t *item,
92 	const uint8_t *data,
93 	size_t data_len,
94 	char *out,
95 	size_t out_len,
96 	yp_style_t style,
97 	bool first_value,
98 	bool last_value
99 );
100 
101 /*! @} */
102