1 /*  Copyright (C) 2017 Farsight Security, Inc. <software@farsightsecurity.com>
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  * \brief Dnstap file reader.
19  */
20 
21 #pragma once
22 
23 #include <fstrm.h>
24 #include <protobuf-c/protobuf-c.h>
25 
26 #include "contrib/dnstap/dnstap.pb-c.h"
27 
28 /*! \brief Structure for dnstap file reader. */
29 typedef struct {
30 	/*!< Input reader. */
31 	struct fstrm_reader	*fr;
32 } dt_reader_t;
33 
34 /*!
35  * \brief Creates dnstap file reader structure.
36  *
37  * \param file_path		Name of file to read input from.
38  *
39  * \retval reader		if success.
40  * \retval NULL			if error.
41  */
42 dt_reader_t* dt_reader_create(const char *file_path);
43 
44 /*!
45  * \brief Close dnstap file reader.
46  *
47  * \param reader		dnstap file reader structure.
48  */
49 void dt_reader_free(dt_reader_t *reader);
50 
51 /*!
52  * \brief Read a dnstap protobuf from a dnstap file reader.
53  *
54  * Caller must deallocate the returned protobuf with the
55  * dnstap__dnstap__free_unpacked() function.
56  *
57  * \param[in]  reader		dnstap file reader structure.
58  * \param[out] d     		Unpacked dnstap protobuf.
59  *
60  * \retval KNOT_EOK
61  * \retval KNOT_ERROR
62  * \retval KNOT_EOF
63  * \retval KNOT_ENOMEM
64  */
65 int dt_reader_read(dt_reader_t *reader, Dnstap__Dnstap **d);
66 
67 /*!
68  * \brief free the frame allocated by dt_read_data.
69  *
70  * \param reader                Dnstap reader context.
71  * \param d                     The frame to be freed.
72  */
73 void dt_reader_free_frame(dt_reader_t *reader, Dnstap__Dnstap **d);
74