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