]> glassweightruler.freedombox.rocks Git - Ventoy.git/blob - Plugson/src/Web/ventoy_http.h
Fix the egrep warning. (#2083)
[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 256
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 typedef enum plugin_type
45 {
46 plugin_type_control = 0,
47 plugin_type_theme,
48 plugin_type_menu_alias,
49 plugin_type_menu_tip,
50 plugin_type_menu_class,
51 plugin_type_auto_install,
52 plugin_type_persistence,
53 plugin_type_injection,
54 plugin_type_conf_replace,
55 plugin_type_password,
56 plugin_type_image_list,
57 plugin_type_auto_memdisk,
58 plugin_type_dud,
59
60 plugin_type_max
61 }plugin_type;
62
63 typedef struct data_control
64 {
65 int default_menu_mode;
66 int treeview_style;
67 int filter_dot_underscore;
68 int sort_casesensitive;
69 int max_search_level;
70 int vhd_no_warning;
71 int filter_iso;
72 int filter_wim;
73 int filter_efi;
74 int filter_img;
75 int filter_vhd;
76 int filter_vtoy;
77 int win11_bypass_check;
78 int menu_timeout;
79 int secondary_menu_timeout;
80 int linux_remount;
81 int secondary_menu;
82 int password_asterisk;
83 char default_search_root[MAX_PATH];
84 char default_image[MAX_PATH];
85 char default_kbd_layout[32];
86 char menu_language[32];
87 }data_control;
88
89 #define display_mode_gui 0
90 #define display_mode_cli 1
91 #define display_mode_serial 2
92 #define display_mode_ser_console 3
93
94 typedef struct path_node
95 {
96 char path[MAX_PATH];
97 struct path_node *next;
98 }path_node;
99
100 typedef struct data_theme
101 {
102 int default_file;
103 path_node *filelist;
104 int display_mode;
105 char gfxmode[32];
106
107 char ventoy_left[32];
108 char ventoy_top[32];
109 char ventoy_color[32];
110 char serial_param[256];
111
112 path_node *fontslist;
113 }data_theme;
114
115 #define path_type_file 0
116 #define path_type_dir 1
117
118 typedef struct data_alias_node
119 {
120 int type;
121 char path[MAX_PATH];
122 char alias[256];
123 struct data_alias_node *next;
124 }data_alias_node;
125
126 typedef struct data_alias
127 {
128 data_alias_node *list;
129 }data_alias;
130
131
132 typedef struct data_tip_node
133 {
134 int type;
135 char path[MAX_PATH];
136 char tip[256];
137 struct data_tip_node *next;
138 }data_tip_node;
139
140 typedef struct data_tip
141 {
142 char left[32];
143 char top[32];
144 char color[32];
145 data_tip_node *list;
146 }data_tip;
147
148
149 #define class_type_key 0
150 #define class_type_dir 1
151 #define class_type_parent 2
152 typedef struct data_class_node
153 {
154 int type;
155 char path[MAX_PATH];
156 char class[256];
157 struct data_class_node *next;
158 }data_class_node;
159
160 typedef struct data_class
161 {
162 data_class_node *list;
163 }data_class;
164
165
166 typedef struct data_auto_memdisk
167 {
168 path_node *list;
169 }data_auto_memdisk;
170
171 typedef struct data_image_list
172 {
173 int type;
174 path_node *list;
175 }data_image_list;
176
177 typedef struct menu_password
178 {
179 int type;
180 char path[MAX_PATH];
181 char pwd[256];
182 struct menu_password *next;
183 }menu_password;
184
185 typedef struct data_password
186 {
187 char bootpwd[256];
188 char isopwd[256];
189 char wimpwd[256];
190 char vhdpwd[256];
191 char imgpwd[256];
192 char efipwd[256];
193 char vtoypwd[256];
194
195 menu_password *list;
196 }data_password;
197
198 typedef struct conf_replace_node
199 {
200 int image;
201 char path[MAX_PATH];
202 char org[256];
203 char new[MAX_PATH];
204 struct conf_replace_node *next;
205 }conf_replace_node;
206 typedef struct data_conf_replace
207 {
208 conf_replace_node *list;
209 }data_conf_replace;
210
211 typedef struct injection_node
212 {
213 int type;
214 char path[MAX_PATH];
215 char archive[MAX_PATH];
216 struct injection_node *next;
217 }injection_node;
218 typedef struct data_injection
219 {
220 injection_node *list;
221 }data_injection;
222
223
224
225 typedef struct dud_node
226 {
227 char path[MAX_PATH];
228 path_node *list;
229
230 struct dud_node *next;
231 }dud_node;
232
233 typedef struct data_dud
234 {
235 dud_node *list;
236 }data_dud;
237
238 typedef struct auto_install_node
239 {
240 int timeouten;
241 int timeout;
242 int autoselen;
243 int autosel;
244 int type;
245 char path[MAX_PATH];
246 path_node *list;
247
248 struct auto_install_node *next;
249 }auto_install_node;
250
251 typedef struct data_auto_install
252 {
253 auto_install_node *list;
254 }data_auto_install;
255
256 typedef struct persistence_node
257 {
258 int timeouten;
259 int timeout;
260 int autoselen;
261 int autosel;
262 int type;
263 char path[MAX_PATH];
264 path_node *list;
265
266 struct persistence_node *next;
267 }persistence_node;
268
269 typedef struct data_persistence
270 {
271 persistence_node *list;
272 }data_persistence;
273
274
275
276
277 #define ventoy_save_plug(plug) \
278 {\
279 for (i = 0; i < bios_max; i++) \
280 {\
281 scnprintf(title, sizeof(title), "%s%s", #plug, g_json_title_postfix[i]);\
282 g_json_exist[plugin_type_##plug][i] = 0;\
283 if (ventoy_data_cmp_##plug(g_data_##plug + i, g_data_##plug + bios_max))\
284 {\
285 g_json_exist[plugin_type_##plug][i] = 1;\
286 pos += ventoy_data_save_##plug(g_data_##plug + i, title, JSON_SAVE_BUFFER + pos, JSON_BUF_MAX - pos);\
287 }\
288 }\
289 }
290
291
292
293 #define api_get_func(conn, json, name) \
294 {\
295 int i = 0; \
296 int pos = 0; \
297 \
298 (void)json;\
299 \
300 VTOY_JSON_FMT_BEGIN(pos, JSON_BUFFER, JSON_BUF_MAX);\
301 VTOY_JSON_FMT_ARY_BEGIN();\
302 \
303 for (i = 0; i <= bios_max; i++)\
304 {\
305 __uiCurPos += ventoy_data_json_##name(g_data_##name + i, JSON_BUFFER + __uiCurPos, JSON_BUF_MAX - __uiCurPos);\
306 VTOY_JSON_FMT_COMA();\
307 }\
308 \
309 VTOY_JSON_FMT_ARY_END();\
310 VTOY_JSON_FMT_END(pos);\
311 \
312 ventoy_json_buffer(conn, JSON_BUFFER, pos);\
313 }
314
315
316 #define vtoy_list_free(type, list) \
317 {\
318 type *__next = NULL;\
319 type *__node = list;\
320 while (__node)\
321 {\
322 __next = __node->next;\
323 free(__node);\
324 __node = __next;\
325 }\
326 (list) = NULL;\
327 }
328
329 #define vtoy_list_del(last, node, LIST, field) \
330 for (last = node = LIST; node; node = node->next) \
331 {\
332 if (strcmp(node->field, field) == 0)\
333 {\
334 if (node == LIST)\
335 {\
336 LIST = LIST->next;\
337 }\
338 else\
339 {\
340 last->next = node->next;\
341 }\
342 free(node);\
343 break;\
344 }\
345 \
346 last = node;\
347 }
348
349
350 #define vtoy_list_del_ex(last, node, LIST, field, cb) \
351 for (last = node = LIST; node; node = node->next) \
352 {\
353 if (strcmp(node->field, field) == 0)\
354 {\
355 if (node == LIST)\
356 {\
357 LIST = LIST->next;\
358 }\
359 else\
360 {\
361 last->next = node->next;\
362 }\
363 cb(node->list);\
364 free(node);\
365 break;\
366 }\
367 \
368 last = node;\
369 }
370
371 #define vtoy_list_add(LIST, cur, node) \
372 if (LIST)\
373 {\
374 cur = LIST;\
375 while (cur && cur->next)\
376 {\
377 cur = cur->next;\
378 }\
379 cur->next = node;\
380 }\
381 else\
382 {\
383 LIST = node;\
384 }
385
386
387
388 #define ventoy_parse_json(name) \
389 {\
390 int __loop;\
391 int __len = (int)strlen(#name);\
392 if (strncmp(#name, node->pcName, __len) == 0)\
393 {\
394 for (__loop = 0; __loop < bios_max; __loop++)\
395 {\
396 if (strcmp(g_json_title_postfix[__loop], node->pcName + __len) == 0)\
397 {\
398 vlog("json parse <%s>\n", node->pcName);\
399 ventoy_parse_##name(node, g_data_##name + __loop);\
400 break;\
401 }\
402 }\
403 } \
404 }
405
406 #define CONTROL_PARSE_INT_DEF_0(node, val) \
407 if (node->unData.pcStrVal[0] == '1') val = 1
408
409 #define CONTROL_PARSE_INT_DEF_1(node, val) \
410 if (node->unData.pcStrVal[0] == '0') val = 0
411
412 #define VTOY_JSON_INT(key, val) vtoy_json_get_int(json, key, &val)
413 #define VTOY_JSON_STR(key, buf) vtoy_json_get_string(json, key, sizeof(buf), buf)
414 #define VTOY_JSON_STR_EX(key) vtoy_json_get_string_ex(json, key)
415
416 typedef int (*ventoy_json_callback)(struct mg_connection *conn, VTOY_JSON *json);
417 typedef struct JSON_CB
418 {
419 const char *method;
420 ventoy_json_callback callback;
421 }JSON_CB;
422
423 int ventoy_http_init(void);
424 void ventoy_http_exit(void);
425 int ventoy_http_start(const char *ip, const char *port);
426 int ventoy_http_stop(void);
427 int ventoy_data_save_all(void);
428 int ventoy_data_real_save_all(int apilock);
429
430 #endif /* __VENTOY_HTTP_H__ */
431