1 /*
2  * DNS Reply Tool (drool)
3  *
4  * Copyright (c) 2017-2018, OARC, Inc.
5  * Copyright (c) 2017, Comcast Corporation
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  *
12  * 1. Redistributions of source code must retain the above copyright
13  *    notice, this list of conditions and the following disclaimer.
14  *
15  * 2. Redistributions in binary form must reproduce the above copyright
16  *    notice, this list of conditions and the following disclaimer in
17  *    the documentation and/or other materials provided with the
18  *    distribution.
19  *
20  * 3. Neither the name of the copyright holder nor the names of its
21  *    contributors may be used to endorse or promote products derived
22  *    from this software without specific prior written permission.
23  *
24  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
25  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
26  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
27  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
28  * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
29  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
30  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
31  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
32  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
33  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
34  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35  * POSSIBILITY OF SUCH DAMAGE.
36  */
37 
38 #ifndef __drool_conf_h
39 #define __drool_conf_h
40 
41 #include "log.h"
42 #include "timing.h"
43 #include "conf_file.h"
44 #include "conf_interface.h"
45 #include "conf_client_pool.h"
46 
47 #include <stddef.h>
48 
49 /* clang-format off */
50 
51 #define CONF_EEXIST     -4
52 #define CONF_ENOMEM     -3
53 #define CONF_EINVAL     -2
54 #define CONF_ERROR      -1
55 #define CONF_OK         0
56 #define CONF_LAST       1
57 #define CONF_COMMENT    2
58 #define CONF_EMPTY      3
59 
60 #define CONF_EEXIST_STR "Already exists"
61 #define CONF_ENOMEM_STR "Out of memory"
62 #define CONF_EINVAL_STR "Invalid arguments"
63 #define CONF_ERROR_STR  "Generic error"
64 
65 /* clang-format on */
66 
67 typedef enum drool_conf_read_mode drool_conf_read_mode_t;
68 enum drool_conf_read_mode {
69     CONF_READ_MODE_NONE = 0,
70     CONF_READ_MODE_LOOP,
71     CONF_READ_MODE_ITER
72 };
73 
74 /* clang-format off */
75 #define CONF_T_INIT { \
76     0, 0, 0, 0, /*0, 0,*/ 0, \
77     0, 0, \
78     0, 0, \
79     0, 0, \
80     /* CONF_FILE_T_INIT, CONF_INTERFACE_T_INIT,*/ \
81     LOG_T_INIT, \
82     TIMING_MODE_KEEP, 0, 0, 0.0, \
83     CONF_CLIENT_POOL_T_INIT, \
84     1 \
85 }
86 /* clang-format on */
87 typedef struct drool_conf drool_conf_t;
88 struct drool_conf {
89     unsigned short have_filter : 1;
90     unsigned short have_read : 1;
91     unsigned short have_input : 1;
92     unsigned short have_read_mode : 1;
93     /*
94     unsigned short  have_write : 1;
95     unsigned short  have_output : 1;
96     */
97     unsigned short is_dry_run : 1;
98 
99     char*  filter;
100     size_t filter_length;
101 
102     drool_conf_file_t*      read;
103     drool_conf_interface_t* input;
104 
105     drool_conf_read_mode_t read_mode;
106     size_t                 read_iter;
107 
108     /*
109     drool_conf_file_t       write;
110     drool_conf_interface_t  output;
111     */
112 
113     drool_log_t log;
114 
115     drool_timing_mode_t timing_mode;
116     unsigned long int   timing_increase;
117     unsigned long int   timing_reduce;
118     long double         timing_multiply;
119 
120     drool_conf_client_pool_t client_pool;
121 
122     size_t context_client_pools;
123 };
124 
125 drool_conf_t* conf_new(void);
126 void conf_free(drool_conf_t* conf);
127 void conf_release(drool_conf_t* conf);
128 int conf_have_filter(const drool_conf_t* conf);
129 int conf_have_read(const drool_conf_t* conf);
130 int conf_have_input(const drool_conf_t* conf);
131 int conf_have_read_mode(const drool_conf_t* conf);
132 /*
133 int conf_have_write(const drool_conf_t* conf);
134 int conf_have_output(const drool_conf_t* conf);
135 */
136 int conf_is_dry_run(const drool_conf_t* conf);
137 const char* conf_filter(const drool_conf_t* conf);
138 int conf_set_filter(drool_conf_t* conf, const char* filter, size_t length);
139 size_t conf_filter_length(const drool_conf_t* conf);
140 const drool_conf_file_t* conf_read(const drool_conf_t* conf);
141 const drool_conf_interface_t* conf_input(const drool_conf_t* conf);
142 drool_conf_read_mode_t conf_read_mode(const drool_conf_t* conf);
143 size_t conf_read_iter(const drool_conf_t* conf);
144 /*
145 const drool_conf_file_t* conf_write(const drool_conf_t* conf);
146 const drool_conf_interface_t* conf_output(const drool_conf_t* conf);
147 */
148 drool_timing_mode_t conf_timing_mode(const drool_conf_t* conf);
149 unsigned long int conf_timing_increase(const drool_conf_t* conf);
150 unsigned long int conf_timing_reduce(const drool_conf_t* conf);
151 long double conf_timing_multiply(const drool_conf_t* conf);
152 size_t conf_context_client_pools(const drool_conf_t* conf);
153 int conf_add_read(drool_conf_t* conf, const char* file, size_t length);
154 int conf_add_input(drool_conf_t* conf, const char* interface, size_t length);
155 int conf_set_read_mode(drool_conf_t* conf, drool_conf_read_mode_t read_mode);
156 int conf_set_read_iter(drool_conf_t* conf, size_t read_iter);
157 /*
158 int conf_set_write(drool_conf_t* conf, const char* file, size_t length);
159 int conf_set_output(drool_conf_t* conf, const char* interface, size_t length);
160 */
161 int conf_set_dry_run(drool_conf_t* conf, int dry_run);
162 int conf_set_context_client_pools(drool_conf_t* conf, size_t context_client_pools);
163 const drool_log_t* conf_log(const drool_conf_t* conf);
164 drool_log_t* conf_log_rw(drool_conf_t* conf);
165 const drool_conf_client_pool_t* conf_client_pool(const drool_conf_t* conf);
166 
167 int conf_parse_file(drool_conf_t* conf, const char* file);
168 int conf_parse_text(drool_conf_t* conf, const char* text, const size_t length);
169 
170 const char* conf_strerr(int errnum);
171 
172 #endif /* __drool_conf_h */
173