]> glassweightruler.freedombox.rocks Git - Ventoy.git/blob - Plugson/src/Web/ventoy_http.h
1. Add check for invalid characters in menu_class plugin.
[Ventoy.git] / Plugson / src / Web / ventoy_http.h
1 /******************************************************************************
2 * ventoy_http.h
3 *
4 * Copyright (c) 2021, longpanda <admin@ventoy.net>
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License as
8 * published by the Free Software Foundation; either version 3 of the
9 * License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, see <http://www.gnu.org/licenses/>.
18 *
19 */
20 #ifndef __VENTOY_HTTP_H__
21 #define __VENTOY_HTTP_H__
22
23 #include <civetweb.h>
24
25 #define MAX_LANGUAGE 128
26
27 #define L1 " "
28 #define L2 " "
29 #define L3 " "
30 #define L4 " "
31
32 typedef enum bios_mode
33 {
34 bios_common = 0,
35 bios_legacy,
36 bios_uefi,
37 bios_ia32,
38 bios_aa64,
39 bios_mips,
40
41 bios_max
42 }bios_mode;
43
44
45 typedef struct data_control
46 {
47 int default_menu_mode;
48 int treeview_style;
49 int filter_dot_underscore;
50 int sort_casesensitive;
51 int max_search_level;
52 int vhd_no_warning;
53 int filter_iso;
54 int filter_wim;
55 int filter_efi;
56 int filter_img;
57 int filter_vhd;
58 int filter_vtoy;
59 int win11_bypass_check;
60 int menu_timeout;
61 char default_search_root[MAX_PATH];
62 char default_image[MAX_PATH];
63 char default_kbd_layout[32];
64 char help_text_language[32];
65 }data_control;
66
67 #define display_mode_gui 0
68 #define display_mode_cli 1
69 #define display_mode_serial 2
70 #define display_mode_ser_console 3
71
72 typedef struct path_node
73 {
74 char path[MAX_PATH];
75 struct path_node *next;
76 }path_node;
77
78 typedef struct data_theme
79 {
80 int default_file;
81 path_node *filelist;
82 int display_mode;
83 char gfxmode[32];
84
85 char ventoy_left[32];
86 char ventoy_top[32];
87 char ventoy_color[32];
88 char serial_param[256];
89
90 path_node *fontslist;
91 }data_theme;
92
93 #define path_type_file 0
94 #define path_type_dir 1
95
96 typedef struct data_alias_node
97 {
98 int type;
99 char path[MAX_PATH];
100 char alias[256];
101 struct data_alias_node *next;
102 }data_alias_node;
103
104 typedef struct data_alias
105 {
106 data_alias_node *list;
107 }data_alias;
108
109
110 typedef struct data_tip_node
111 {
112 int type;
113 char path[MAX_PATH];
114 char tip[256];
115 struct data_tip_node *next;
116 }data_tip_node;
117
118 typedef struct data_tip
119 {
120 char left[32];
121 char top[32];
122 char color[32];
123 data_tip_node *list;
124 }data_tip;
125
126
127 #define class_type_key 0
128 #define class_type_dir 1
129 #define class_type_parent 2
130 typedef struct data_class_node
131 {
132 int type;
133 char path[MAX_PATH];
134 char class[256];
135 struct data_class_node *next;
136 }data_class_node;
137
138 typedef struct data_class
139 {
140 data_class_node *list;
141 }data_class;
142
143
144 typedef struct data_auto_memdisk
145 {
146 path_node *list;
147 }data_auto_memdisk;
148
149 typedef struct data_image_list
150 {
151 int type;
152 path_node *list;
153 }data_image_list;
154
155 typedef struct menu_password
156 {
157 int type;
158 char path[MAX_PATH];
159 char pwd[256];
160 struct menu_password *next;
161 }menu_password;
162
163 typedef struct data_password
164 {
165 char bootpwd[256];
166 char isopwd[256];
167 char wimpwd[256];
168 char vhdpwd[256];
169 char imgpwd[256];
170 char efipwd[256];
171 char vtoypwd[256];
172
173 menu_password *list;
174 }data_password;
175
176 typedef struct conf_replace_node
177 {
178 int image;
179 char path[MAX_PATH];
180 char org[256];
181 char new[MAX_PATH];
182 struct conf_replace_node *next;
183 }conf_replace_node;
184 typedef struct data_conf_replace
185 {
186 conf_replace_node *list;
187 }data_conf_replace;
188
189 typedef struct injection_node
190 {
191 int type;
192 char path[MAX_PATH];
193 char archive[MAX_PATH];
194 struct injection_node *next;
195 }injection_node;
196 typedef struct data_injection
197 {
198 injection_node *list;
199 }data_injection;
200
201
202
203 typedef struct dud_node
204 {
205 char path[MAX_PATH];
206 path_node *list;
207
208 struct dud_node *next;
209 }dud_node;
210
211 typedef struct data_dud
212 {
213 dud_node *list;
214 }data_dud;
215
216 typedef struct auto_install_node
217 {
218 int timeouten;
219 int timeout;
220 int autoselen;
221 int autosel;
222 int type;
223 char path[MAX_PATH];
224 path_node *list;
225
226 struct auto_install_node *next;
227 }auto_install_node;
228
229 typedef struct data_auto_install
230 {
231 auto_install_node *list;
232 }data_auto_install;
233
234 typedef struct persistence_node
235 {
236 int timeouten;
237 int timeout;
238 int autoselen;
239 int autosel;
240 int type;
241 char path[MAX_PATH];
242 path_node *list;
243
244 struct persistence_node *next;
245 }persistence_node;
246
247 typedef struct data_persistence
248 {
249 persistence_node *list;
250 }data_persistence;
251
252
253
254
255 #define ventoy_save_plug(plug) \
256 {\
257 for (i = 0; i < bios_max; i++) \
258 {\
259 scnprintf(title, sizeof(title), "%s%s", #plug, g_json_title_postfix[i]);\
260 if (ventoy_data_cmp_##plug(g_data_##plug + i, g_data_##plug + bios_max))\
261 {\
262 pos += ventoy_data_save_##plug(g_data_##plug + i, title, JSON_SAVE_BUFFER + pos, JSON_BUF_MAX - pos);\
263 }\
264 }\
265 }
266
267
268
269 #define api_get_func(conn, json, name) \
270 {\
271 int i = 0; \
272 int pos = 0; \
273 \
274 (void)json;\
275 \
276 VTOY_JSON_FMT_BEGIN(pos, JSON_BUFFER, JSON_BUF_MAX);\
277 VTOY_JSON_FMT_ARY_BEGIN();\
278 \
279 for (i = 0; i <= bios_max; i++)\
280 {\
281 __uiCurPos += ventoy_data_json_##name(g_data_##name + i, JSON_BUFFER + __uiCurPos, JSON_BUF_MAX - __uiCurPos);\
282 VTOY_JSON_FMT_COMA();\
283 }\
284 \
285 VTOY_JSON_FMT_ARY_END();\
286 VTOY_JSON_FMT_END(pos);\
287 \
288 ventoy_json_buffer(conn, JSON_BUFFER, pos);\
289 }
290
291
292 #define vtoy_list_free(type, list) \
293 {\
294 type *__next = NULL;\
295 type *__node = list;\
296 while (__node)\
297 {\
298 __next = __node->next;\
299 free(__node);\
300 __node = __next;\
301 }\
302 }
303
304 #define vtoy_list_del(last, node, LIST, field) \
305 for (last = node = LIST; node; node = node->next) \
306 {\
307 if (strcmp(node->field, field) == 0)\
308 {\
309 if (node == LIST)\
310 {\
311 LIST = LIST->next;\
312 }\
313 else\
314 {\
315 last->next = node->next;\
316 }\
317 free(node);\
318 break;\
319 }\
320 \
321 last = node;\
322 }
323
324
325 #define vtoy_list_del_ex(last, node, LIST, field, cb) \
326 for (last = node = LIST; node; node = node->next) \
327 {\
328 if (strcmp(node->field, field) == 0)\
329 {\
330 if (node == LIST)\
331 {\
332 LIST = LIST->next;\
333 }\
334 else\
335 {\
336 last->next = node->next;\
337 }\
338 cb(node->list);\
339 free(node);\
340 break;\
341 }\
342 \
343 last = node;\
344 }
345
346 #define vtoy_list_add(LIST, cur, node) \
347 if (LIST)\
348 {\
349 cur = LIST;\
350 while (cur && cur->next)\
351 {\
352 cur = cur->next;\
353 }\
354 cur->next = node;\
355 }\
356 else\
357 {\
358 LIST = node;\
359 }
360
361
362
363 #define ventoy_parse_json(name) \
364 {\
365 int __loop;\
366 int __len = strlen(#name);\
367 if (strncmp(#name, node->pcName, __len) == 0)\
368 {\
369 for (__loop = 0; __loop < bios_max; __loop++)\
370 {\
371 if (strcmp(g_json_title_postfix[__loop], node->pcName + __len) == 0)\
372 {\
373 vlog("json parse <%s>\n", node->pcName);\
374 ventoy_parse_##name(node, g_data_##name + __loop);\
375 break;\
376 }\
377 }\
378 } \
379 }
380
381 #define CONTROL_PARSE_INT(node, val) \
382 if (node->unData.pcStrVal[0] == '1') val = 1
383
384
385 #define VTOY_JSON_INT(key, val) vtoy_json_get_int(json, key, &val)
386 #define VTOY_JSON_STR(key, buf) vtoy_json_get_string(json, key, sizeof(buf), buf)
387 #define VTOY_JSON_STR_EX(key) vtoy_json_get_string_ex(json, key)
388
389 typedef int (*ventoy_json_callback)(struct mg_connection *conn, VTOY_JSON *json);
390 typedef struct JSON_CB
391 {
392 const char *method;
393 ventoy_json_callback callback;
394 }JSON_CB;
395
396 int ventoy_http_init(void);
397 void ventoy_http_exit(void);
398 int ventoy_http_start(const char *ip, const char *port);
399 int ventoy_http_stop(void);
400 int ventoy_data_save_all(void);
401
402 #endif /* __VENTOY_HTTP_H__ */
403