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