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__
31 typedef enum bios_mode
44 typedef struct data_control
46 int default_menu_mode
;
48 int filter_dot_underscore
;
49 int sort_casesensitive
;
58 int win11_bypass_check
;
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];
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
71 typedef struct path_node
74 struct path_node
*next
;
77 typedef struct data_theme
86 char ventoy_color
[32];
87 char serial_param
[256];
92 #define path_type_file 0
93 #define path_type_dir 1
95 typedef struct data_alias_node
100 struct data_alias_node
*next
;
103 typedef struct data_alias
105 data_alias_node
*list
;
109 typedef struct data_tip_node
114 struct data_tip_node
*next
;
117 typedef struct data_tip
126 #define class_type_key 0
127 #define class_type_dir 1
128 #define class_type_parent 2
129 typedef struct data_class_node
134 struct data_class_node
*next
;
137 typedef struct data_class
139 data_class_node
*list
;
143 typedef struct data_auto_memdisk
148 typedef struct data_image_list
154 typedef struct menu_password
159 struct menu_password
*next
;
162 typedef struct data_password
175 typedef struct conf_replace_node
181 struct conf_replace_node
*next
;
183 typedef struct data_conf_replace
185 conf_replace_node
*list
;
188 typedef struct injection_node
192 char archive
[MAX_PATH
];
193 struct injection_node
*next
;
195 typedef struct data_injection
197 injection_node
*list
;
202 typedef struct dud_node
207 struct dud_node
*next
;
210 typedef struct data_dud
215 typedef struct auto_install_node
225 struct auto_install_node
*next
;
228 typedef struct data_auto_install
230 auto_install_node
*list
;
233 typedef struct persistence_node
243 struct persistence_node
*next
;
246 typedef struct data_persistence
248 persistence_node
*list
;
254 #define ventoy_save_plug(plug) \
256 for (i = 0; i < bios_max; i++) \
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))\
261 pos += ventoy_data_save_##plug(g_data_##plug + i, title, JSON_SAVE_BUFFER + pos, JSON_BUF_MAX - pos);\
268 #define api_get_func(conn, json, name) \
275 VTOY_JSON_FMT_BEGIN(pos, JSON_BUFFER, JSON_BUF_MAX);\
276 VTOY_JSON_FMT_ARY_BEGIN();\
278 for (i = 0; i <= bios_max; i++)\
280 __uiCurPos += ventoy_data_json_##name(g_data_##name + i, JSON_BUFFER + __uiCurPos, JSON_BUF_MAX - __uiCurPos);\
281 VTOY_JSON_FMT_COMA();\
284 VTOY_JSON_FMT_ARY_END();\
285 VTOY_JSON_FMT_END(pos);\
287 ventoy_json_buffer(conn, JSON_BUFFER, pos);\
291 #define vtoy_list_free(type, list) \
293 type *__next = NULL;\
294 type *__node = list;\
297 __next = __node->next;\
303 #define vtoy_list_del(last, node, LIST, field) \
304 for (last = node = LIST; node; node = node->next) \
306 if (strcmp(node->field, field) == 0)\
314 last->next = node->next;\
324 #define vtoy_list_del_ex(last, node, LIST, field, cb) \
325 for (last = node = LIST; node; node = node->next) \
327 if (strcmp(node->field, field) == 0)\
335 last->next = node->next;\
345 #define vtoy_list_add(LIST, cur, node) \
349 while (cur && cur->next)\
362 #define ventoy_parse_json(name) \
365 int __len = strlen(#name);\
366 if (strncmp(#name, node->pcName, __len) == 0)\
368 for (__loop = 0; __loop < bios_max; __loop++)\
370 if (strcmp(g_json_title_postfix[__loop], node->pcName + __len) == 0)\
372 vlog("json parse <%s>\n", node->pcName);\
373 ventoy_parse_##name(node, g_data_##name + __loop);\
380 #define CONTROL_PARSE_INT(node, val) \
381 if (node->unData.pcStrVal[0] == '1') val = 1
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)
388 typedef int (*ventoy_json_callback
)(struct mg_connection
*conn
, VTOY_JSON
*json
);
389 typedef struct JSON_CB
392 ventoy_json_callback callback
;
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);
401 #endif /* __VENTOY_HTTP_H__ */