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 128
32 typedef enum bios_mode
45 typedef struct data_control
47 int default_menu_mode
;
49 int filter_dot_underscore
;
50 int sort_casesensitive
;
59 int win11_bypass_check
;
61 int secondary_menu_timeout
;
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];
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
75 typedef struct path_node
78 struct path_node
*next
;
81 typedef struct data_theme
90 char ventoy_color
[32];
91 char serial_param
[256];
96 #define path_type_file 0
97 #define path_type_dir 1
99 typedef struct data_alias_node
104 struct data_alias_node
*next
;
107 typedef struct data_alias
109 data_alias_node
*list
;
113 typedef struct data_tip_node
118 struct data_tip_node
*next
;
121 typedef struct data_tip
130 #define class_type_key 0
131 #define class_type_dir 1
132 #define class_type_parent 2
133 typedef struct data_class_node
138 struct data_class_node
*next
;
141 typedef struct data_class
143 data_class_node
*list
;
147 typedef struct data_auto_memdisk
152 typedef struct data_image_list
158 typedef struct menu_password
163 struct menu_password
*next
;
166 typedef struct data_password
179 typedef struct conf_replace_node
185 struct conf_replace_node
*next
;
187 typedef struct data_conf_replace
189 conf_replace_node
*list
;
192 typedef struct injection_node
196 char archive
[MAX_PATH
];
197 struct injection_node
*next
;
199 typedef struct data_injection
201 injection_node
*list
;
206 typedef struct dud_node
211 struct dud_node
*next
;
214 typedef struct data_dud
219 typedef struct auto_install_node
229 struct auto_install_node
*next
;
232 typedef struct data_auto_install
234 auto_install_node
*list
;
237 typedef struct persistence_node
247 struct persistence_node
*next
;
250 typedef struct data_persistence
252 persistence_node
*list
;
258 #define ventoy_save_plug(plug) \
260 for (i = 0; i < bios_max; i++) \
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))\
265 pos += ventoy_data_save_##plug(g_data_##plug + i, title, JSON_SAVE_BUFFER + pos, JSON_BUF_MAX - pos);\
272 #define api_get_func(conn, json, name) \
279 VTOY_JSON_FMT_BEGIN(pos, JSON_BUFFER, JSON_BUF_MAX);\
280 VTOY_JSON_FMT_ARY_BEGIN();\
282 for (i = 0; i <= bios_max; i++)\
284 __uiCurPos += ventoy_data_json_##name(g_data_##name + i, JSON_BUFFER + __uiCurPos, JSON_BUF_MAX - __uiCurPos);\
285 VTOY_JSON_FMT_COMA();\
288 VTOY_JSON_FMT_ARY_END();\
289 VTOY_JSON_FMT_END(pos);\
291 ventoy_json_buffer(conn, JSON_BUFFER, pos);\
295 #define vtoy_list_free(type, list) \
297 type *__next = NULL;\
298 type *__node = list;\
301 __next = __node->next;\
307 #define vtoy_list_del(last, node, LIST, field) \
308 for (last = node = LIST; node; node = node->next) \
310 if (strcmp(node->field, field) == 0)\
318 last->next = node->next;\
328 #define vtoy_list_del_ex(last, node, LIST, field, cb) \
329 for (last = node = LIST; node; node = node->next) \
331 if (strcmp(node->field, field) == 0)\
339 last->next = node->next;\
349 #define vtoy_list_add(LIST, cur, node) \
353 while (cur && cur->next)\
366 #define ventoy_parse_json(name) \
369 int __len = strlen(#name);\
370 if (strncmp(#name, node->pcName, __len) == 0)\
372 for (__loop = 0; __loop < bios_max; __loop++)\
374 if (strcmp(g_json_title_postfix[__loop], node->pcName + __len) == 0)\
376 vlog("json parse <%s>\n", node->pcName);\
377 ventoy_parse_##name(node, g_data_##name + __loop);\
384 #define CONTROL_PARSE_INT(node, val) \
385 if (node->unData.pcStrVal[0] == '1') val = 1
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)
392 typedef int (*ventoy_json_callback
)(struct mg_connection
*conn
, VTOY_JSON
*json
);
393 typedef struct JSON_CB
396 ventoy_json_callback callback
;
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);
405 #endif /* __VENTOY_HTTP_H__ */