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