1 /* Copyright (C) 2020 Greenbone Networks GmbH
2  *
3  * SPDX-License-Identifier: AGPL-3.0-or-later
4  *
5  * This program is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU Affero General Public License as
7  * published by the Free Software Foundation, either version 3 of the
8  * License, or (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU Affero General Public License for more details.
14  *
15  * You should have received a copy of the GNU Affero General Public License
16  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
17  */
18 
19 #ifndef _GVMD_MANAGE_REPORT_FORMATS_H
20 #define _GVMD_MANAGE_REPORT_FORMATS_H
21 
22 #include "manage.h"
23 
24 #include <glib.h>
25 
26 gboolean
27 find_report_format_with_permission (const char*, report_format_t*,
28                                     const char *);
29 
30 /**
31  * @brief Struct for defining a report format param.
32  */
33 typedef struct
34 {
35   gchar *fallback;  ///< Fallback value.
36   gchar *name;      ///< Name.
37   gchar *type;      ///< Type (boolean, string, integer, ...).
38   gchar *type_max;  ///< Maximum value for integer type.
39   gchar *type_min;  ///< Minimum value for integer type.
40   gchar *value;     ///< Value of param.
41 } create_report_format_param_t;
42 
43 int
44 create_report_format (const char *, const char *, const char *, const char *,
45                       const char *, const char *, array_t *, array_t *,
46                       array_t *, const char *, report_format_t *);
47 
48 int
49 copy_report_format (const char *, const char *, report_format_t*);
50 
51 int
52 modify_report_format (const char *, const char *, const char *, const char *,
53                       const char *, const char *);
54 
55 int
56 delete_report_format (const char *, int);
57 
58 int
59 verify_report_format (const char *);
60 
61 char *
62 report_format_uuid (report_format_t);
63 
64 char *
65 report_format_owner_uuid (report_format_t);
66 
67 char *
68 report_format_name (report_format_t);
69 
70 char *
71 report_format_content_type (report_format_t);
72 
73 char *
74 report_format_extension (report_format_t);
75 
76 int
77 report_format_global (report_format_t);
78 
79 int
80 trash_report_format_global (report_format_t);
81 
82 int
83 report_format_predefined (report_format_t);
84 
85 int
86 trash_report_format_predefined (report_format_t);
87 
88 int
89 report_format_active (report_format_t);
90 
91 int
92 report_format_trust (report_format_t);
93 
94 int
95 report_format_in_use (report_format_t);
96 
97 int
98 trash_report_format_in_use (report_format_t);
99 
100 int
101 trash_report_format_writable (report_format_t);
102 
103 int
104 report_format_writable (report_format_t);
105 
106 int
107 report_format_count (const get_data_t *);
108 
109 int
110 init_report_format_iterator (iterator_t*, const get_data_t *);
111 
112 const char*
113 report_format_iterator_extension (iterator_t *);
114 
115 const char*
116 report_format_iterator_content_type (iterator_t *);
117 
118 const char*
119 report_format_iterator_description (iterator_t *);
120 
121 int
122 report_format_iterator_active (iterator_t *);
123 
124 const char*
125 report_format_iterator_signature (iterator_t *);
126 
127 const char*
128 report_format_iterator_trust (iterator_t *);
129 
130 const char*
131 report_format_iterator_summary (iterator_t *);
132 
133 time_t
134 report_format_iterator_trust_time (iterator_t *);
135 
136 void
137 init_report_format_alert_iterator (iterator_t*, report_format_t);
138 
139 const char*
140 report_format_alert_iterator_name (iterator_t*);
141 
142 const char*
143 report_format_alert_iterator_uuid (iterator_t*);
144 
145 int
146 report_format_alert_iterator_readable (iterator_t*);
147 
148 /**
149  * @brief A report format file iterator.
150  */
151 typedef struct
152 {
153   GPtrArray *start;    ///< Array of files.
154   gpointer *current;   ///< Current file.
155   gchar *dir_name;     ///< Dir holding files.
156 } file_iterator_t;
157 
158 int
159 init_report_format_file_iterator (file_iterator_t*, report_format_t);
160 
161 void
162 cleanup_file_iterator (file_iterator_t*);
163 
164 gboolean
165 next_file (file_iterator_t*);
166 
167 const char*
168 file_iterator_name (file_iterator_t*);
169 
170 gchar*
171 file_iterator_content_64 (file_iterator_t*);
172 
173 /**
174  * @brief Report format param types.
175  *
176  * These numbers are used in the database, so if the number associated with
177  * any symbol changes then a migrator must be added to update existing data.
178  */
179 typedef enum
180 {
181   REPORT_FORMAT_PARAM_TYPE_BOOLEAN = 0,
182   REPORT_FORMAT_PARAM_TYPE_INTEGER = 1,
183   REPORT_FORMAT_PARAM_TYPE_SELECTION = 2,
184   REPORT_FORMAT_PARAM_TYPE_STRING = 3,
185   REPORT_FORMAT_PARAM_TYPE_TEXT = 4,
186   REPORT_FORMAT_PARAM_TYPE_REPORT_FORMAT_LIST = 5,
187   REPORT_FORMAT_PARAM_TYPE_ERROR = 100
188 } report_format_param_type_t;
189 
190 const char *
191 report_format_param_type_name (report_format_param_type_t);
192 
193 report_format_param_type_t
194 report_format_param_type_from_name (const char *);
195 
196 void
197 init_report_format_param_iterator (iterator_t*, report_format_t, int,
198                                    int, const char*);
199 
200 report_format_param_t
201 report_format_param_iterator_param (iterator_t*);
202 
203 const char*
204 report_format_param_iterator_name (iterator_t *);
205 
206 const char*
207 report_format_param_iterator_value (iterator_t *);
208 
209 const char*
210 report_format_param_iterator_type_name (iterator_t *);
211 
212 report_format_param_type_t
213 report_format_param_iterator_type (iterator_t *);
214 
215 long long int
216 report_format_param_iterator_type_min (iterator_t *);
217 
218 long long int
219 report_format_param_iterator_type_max (iterator_t *);
220 
221 const char*
222 report_format_param_iterator_fallback (iterator_t *);
223 
224 void
225 init_param_option_iterator (iterator_t*, report_format_param_t, int,
226                             const char *);
227 
228 const char*
229 param_option_iterator_value (iterator_t *);
230 
231 gboolean
232 report_formats_feed_dir_exists ();
233 
234 void
235 manage_sync_report_formats ();
236 
237 int
238 manage_rebuild_report_formats ();
239 
240 gboolean
241 should_sync_report_formats ();
242 
243 #endif /* not _GVMD_MANAGE_REPORT_FORMATS_H */
244