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