1 /******************************************************************************
4 * Copyright (c) 2021, longpanda <admin@ventoy.net>
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.
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.
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/>.
20 #ifndef __VENTOY_HTTP_H__
21 #define __VENTOY_HTTP_H__
25 #define MAX_LANGUAGE 256
32 typedef enum bios_mode
44 typedef enum plugin_type
46 plugin_type_control
= 0,
48 plugin_type_menu_alias
,
50 plugin_type_menu_class
,
51 plugin_type_auto_install
,
52 plugin_type_persistence
,
53 plugin_type_injection
,
54 plugin_type_conf_replace
,
56 plugin_type_image_list
,
57 plugin_type_auto_memdisk
,
63 typedef struct data_control
65 int default_menu_mode
;
67 int filter_dot_underscore
;
68 int sort_casesensitive
;
77 int win11_bypass_check
;
80 int secondary_menu_timeout
;
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];
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
95 typedef struct path_node
98 struct path_node
*next
;
101 typedef struct data_theme
109 char ventoy_left
[32];
111 char ventoy_color
[32];
112 char serial_param
[256];
114 path_node
*fontslist
;
117 #define path_type_file 0
118 #define path_type_dir 1
120 typedef struct data_alias_node
125 struct data_alias_node
*next
;
128 typedef struct data_alias
130 data_alias_node
*list
;
134 typedef struct data_tip_node
139 struct data_tip_node
*next
;
142 typedef struct data_tip
151 #define class_type_key 0
152 #define class_type_dir 1
153 #define class_type_parent 2
154 typedef struct data_class_node
159 struct data_class_node
*next
;
162 typedef struct data_class
164 data_class_node
*list
;
168 typedef struct data_auto_memdisk
173 typedef struct data_image_list
179 typedef struct menu_password
184 struct menu_password
*next
;
187 typedef struct data_password
200 typedef struct conf_replace_node
206 struct conf_replace_node
*next
;
208 typedef struct data_conf_replace
210 conf_replace_node
*list
;
213 typedef struct injection_node
217 char archive
[MAX_PATH
];
218 struct injection_node
*next
;
220 typedef struct data_injection
222 injection_node
*list
;
227 typedef struct dud_node
232 struct dud_node
*next
;
235 typedef struct data_dud
240 typedef struct auto_install_node
250 struct auto_install_node
*next
;
253 typedef struct data_auto_install
255 auto_install_node
*list
;
258 typedef struct persistence_node
268 struct persistence_node
*next
;
271 typedef struct data_persistence
273 persistence_node
*list
;
279 #define ventoy_save_plug(plug) \
281 for (i = 0; i < bios_max; i++) \
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))\
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);\
295 #define api_get_func(conn, json, name) \
302 VTOY_JSON_FMT_BEGIN(pos, JSON_BUFFER, JSON_BUF_MAX);\
303 VTOY_JSON_FMT_ARY_BEGIN();\
305 for (i = 0; i <= bios_max; i++)\
307 __uiCurPos += ventoy_data_json_##name(g_data_##name + i, JSON_BUFFER + __uiCurPos, JSON_BUF_MAX - __uiCurPos);\
308 VTOY_JSON_FMT_COMA();\
311 VTOY_JSON_FMT_ARY_END();\
312 VTOY_JSON_FMT_END(pos);\
314 ventoy_json_buffer(conn, JSON_BUFFER, pos);\
318 #define vtoy_list_free(type, list) \
320 type *__next = NULL;\
321 type *__node = list;\
324 __next = __node->next;\
331 #define vtoy_list_del(last, node, LIST, field) \
332 for (last = node = LIST; node; node = node->next) \
334 if (strcmp(node->field, field) == 0)\
342 last->next = node->next;\
352 #define vtoy_list_del_ex(last, node, LIST, field, cb) \
353 for (last = node = LIST; node; node = node->next) \
355 if (strcmp(node->field, field) == 0)\
363 last->next = node->next;\
373 #define vtoy_list_add(LIST, cur, node) \
377 while (cur && cur->next)\
390 #define ventoy_parse_json(name) \
393 int __len = (int)strlen(#name);\
394 if (strncmp(#name, node->pcName, __len) == 0)\
396 for (__loop = 0; __loop < bios_max; __loop++)\
398 if (strcmp(g_json_title_postfix[__loop], node->pcName + __len) == 0)\
400 vlog("json parse <%s>\n", node->pcName);\
401 ventoy_parse_##name(node, g_data_##name + __loop);\
408 #define CONTROL_PARSE_INT_DEF_0(node, val) \
409 if (node->unData.pcStrVal[0] == '1') val = 1
411 #define CONTROL_PARSE_INT_DEF_1(node, val) \
412 if (node->unData.pcStrVal[0] == '0') val = 0
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)
418 typedef int (*ventoy_json_callback
)(struct mg_connection
*conn
, VTOY_JSON
*json
);
419 typedef struct JSON_CB
422 ventoy_json_callback callback
;
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
);
432 #endif /* __VENTOY_HTTP_H__ */