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