1 /******************************************************************************
2 * ventoy_http.c ---- ventoy http
3 * Copyright (c) 2021, longpanda <admin@ventoy.net>
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License as
7 * published by the Free Software Foundation; either version 3 of the
8 * License, or (at your option) any later version.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, see <http://www.gnu.org/licenses/>.
27 #if defined(_MSC_VER) || defined(WIN32)
31 #include <sys/types.h>
32 #include <sys/ioctl.h>
34 #include <sys/types.h>
35 #include <sys/mount.h>
37 #include <linux/limits.h>
42 #include <ventoy_define.h>
43 #include <ventoy_json.h>
44 #include <ventoy_util.h>
45 #include <ventoy_disk.h>
46 #include <ventoy_http.h>
47 #include "fat_filelib.h"
49 static const char *g_json_title_postfix
[bios_max
+ 1] =
51 "", "_legacy", "_uefi", "_ia32", "_aa64", "_mips", ""
54 static const char *g_ventoy_kbd_layout
[] =
56 "QWERTY_USA", "AZERTY", "CZECH_QWERTY", "CZECH_QWERTZ", "DANISH",
57 "DVORAK_USA", "FRENCH", "GERMAN", "ITALIANO", "JAPAN_106", "LATIN_USA",
58 "PORTU_BRAZIL", "QWERTY_UK", "QWERTZ", "QWERTZ_HUN", "QWERTZ_SLOV_CROAT",
59 "SPANISH", "SWEDISH", "TURKISH_Q", "VIETNAMESE",
63 #define VTOY_DEL_ALL_PATH "4119ae33-98ea-448e-b9c0-569aafcf1fb4"
65 static int g_json_exist
[plugin_type_max
][bios_max
];
66 static const char *g_plugin_name
[plugin_type_max
] =
68 "control", "theme", "menu_alias", "menu_tip",
69 "menu_class", "auto_install", "persistence", "injection",
70 "conf_replace", "password", "image_list",
74 static char g_ventoy_help_lang
[MAX_LANGUAGE
][8];
76 static char g_pub_path
[2 * MAX_PATH
];
77 static data_control g_data_control
[bios_max
+ 1];
78 static data_theme g_data_theme
[bios_max
+ 1];
79 static data_alias g_data_menu_alias
[bios_max
+ 1];
80 static data_tip g_data_menu_tip
[bios_max
+ 1];
81 static data_class g_data_menu_class
[bios_max
+ 1];
82 static data_image_list g_data_image_list
[bios_max
+ 1];
83 static data_image_list
*g_data_image_blacklist
= g_data_image_list
;
84 static data_auto_memdisk g_data_auto_memdisk
[bios_max
+ 1];
85 static data_password g_data_password
[bios_max
+ 1];
86 static data_conf_replace g_data_conf_replace
[bios_max
+ 1];
87 static data_injection g_data_injection
[bios_max
+ 1];
88 static data_auto_install g_data_auto_install
[bios_max
+ 1];
89 static data_persistence g_data_persistence
[bios_max
+ 1];
90 static data_dud g_data_dud
[bios_max
+ 1];
92 static char *g_pub_json_buffer
= NULL
;
93 static char *g_pub_save_buffer
= NULL
;
94 #define JSON_BUFFER g_pub_json_buffer
95 #define JSON_SAVE_BUFFER g_pub_save_buffer
97 static pthread_mutex_t g_api_mutex
;
98 static struct mg_context
*g_ventoy_http_ctx
= NULL
;
100 static int ventoy_is_kbd_valid(const char *key
)
104 for (i
= 0; g_ventoy_kbd_layout
[i
]; i
++)
106 if (strcmp(g_ventoy_kbd_layout
[i
], key
) == 0)
115 static const char * ventoy_real_path(const char *org
)
119 if (g_sysinfo
.pathcase
)
121 scnprintf(g_pub_path
, MAX_PATH
, "%s", org
);
122 count
= ventoy_path_case(g_pub_path
+ 1, 1);
136 static int ventoy_json_result(struct mg_connection
*conn
, const char *err
)
139 "HTTP/1.1 200 OK \r\n"
140 "Content-Type: application/json\r\n"
141 "Content-Length: %d\r\n"
143 (int)strlen(err
), err
);
148 static int ventoy_json_buffer(struct mg_connection
*conn
, const char *json_buf
, int json_len
)
151 "HTTP/1.1 200 OK \r\n"
152 "Content-Type: application/json\r\n"
153 "Content-Length: %d\r\n"
160 static void ventoy_free_path_node_list(path_node
*list
)
162 path_node
*next
= NULL
;
163 path_node
*node
= list
;
173 static path_node
* ventoy_path_node_add_array(VTOY_JSON
*array
)
175 path_node
*head
= NULL
;
176 path_node
*node
= NULL
;
177 path_node
*cur
= NULL
;
178 VTOY_JSON
*item
= NULL
;
180 for (item
= array
->pstChild
; item
; item
= item
->pstNext
)
182 node
= zalloc(sizeof(path_node
));
185 scnprintf(node
->path
, sizeof(node
->path
), "%s", item
->unData
.pcStrVal
);
186 vtoy_list_add(head
, cur
, node
);
193 static int ventoy_check_fuzzy_path(char *path
, int prefix
)
205 pos
= strchr(path
, '*');
208 for (cur
= pos
; *cur
; cur
++)
233 rc
= ventoy_is_directory_exist("%s%s", g_cur_dir
, path
);
237 rc
= ventoy_is_directory_exist("%s", path
);
258 return ventoy_is_file_exist("%s%s", g_cur_dir
, path
);
262 return ventoy_is_file_exist("%s", path
);
267 static int ventoy_path_list_cmp(path_node
*list1
, path_node
*list2
)
269 if (NULL
== list1
&& NULL
== list2
)
273 else if (list1
&& list2
)
275 while (list1
&& list2
)
277 if (strcmp(list1
->path
, list2
->path
))
286 if (list1
== NULL
&& list2
== NULL
)
299 static int ventoy_api_device_info(struct mg_connection
*conn
, VTOY_JSON
*json
)
305 VTOY_JSON_FMT_BEGIN(pos
, JSON_BUFFER
, JSON_BUF_MAX
);
306 VTOY_JSON_FMT_OBJ_BEGIN();
308 VTOY_JSON_FMT_STRN("dev_name", g_sysinfo
.cur_model
);
309 VTOY_JSON_FMT_STRN("dev_capacity", g_sysinfo
.cur_capacity
);
310 VTOY_JSON_FMT_STRN("dev_fs", g_sysinfo
.cur_fsname
);
311 VTOY_JSON_FMT_STRN("ventoy_ver", g_sysinfo
.cur_ventoy_ver
);
312 VTOY_JSON_FMT_SINT("part_style", g_sysinfo
.cur_part_style
);
313 VTOY_JSON_FMT_SINT("secure_boot", g_sysinfo
.cur_secureboot
);
315 VTOY_JSON_FMT_OBJ_END();
316 VTOY_JSON_FMT_END(pos
);
318 ventoy_json_buffer(conn
, JSON_BUFFER
, pos
);
322 static int ventoy_api_sysinfo(struct mg_connection
*conn
, VTOY_JSON
*json
)
328 VTOY_JSON_FMT_BEGIN(pos
, JSON_BUFFER
, JSON_BUF_MAX
);
329 VTOY_JSON_FMT_OBJ_BEGIN();
330 VTOY_JSON_FMT_STRN("language", ventoy_get_os_language());
331 VTOY_JSON_FMT_STRN("curdir", g_cur_dir
);
334 VTOY_JSON_FMT_SINT("syntax_error", g_sysinfo
.syntax_error
);
335 g_sysinfo
.syntax_error
= 0;
337 VTOY_JSON_FMT_SINT("invalid_config", g_sysinfo
.invalid_config
);
338 g_sysinfo
.invalid_config
= 0;
340 #if defined(_MSC_VER) || defined(WIN32)
341 VTOY_JSON_FMT_STRN("os", "windows");
343 VTOY_JSON_FMT_STRN("os", "linux");
346 VTOY_JSON_FMT_OBJ_END();
347 VTOY_JSON_FMT_END(pos
);
349 ventoy_json_buffer(conn
, JSON_BUFFER
, pos
);
353 static int ventoy_api_handshake(struct mg_connection
*conn
, VTOY_JSON
*json
)
362 VTOY_JSON_FMT_BEGIN(pos
, JSON_BUFFER
, JSON_BUF_MAX
);
363 VTOY_JSON_FMT_OBJ_BEGIN();
364 VTOY_JSON_FMT_SINT("status", 0);
365 VTOY_JSON_FMT_SINT("save_error", g_sysinfo
.config_save_error
);
366 g_sysinfo
.config_save_error
= 0;
368 for (i
= 0; i
< plugin_type_max
; i
++)
370 scnprintf(key
, sizeof(key
), "exist_%s", g_plugin_name
[i
]);
371 VTOY_JSON_FMT_KEY(key
);
372 VTOY_JSON_FMT_ARY_BEGIN();
373 for (j
= 0; j
< bios_max
; j
++)
375 VTOY_JSON_FMT_ITEM_INT(g_json_exist
[i
][j
]);
377 VTOY_JSON_FMT_ARY_ENDEX();
380 VTOY_JSON_FMT_OBJ_END();
381 VTOY_JSON_FMT_END(pos
);
383 ventoy_json_buffer(conn
, JSON_BUFFER
, pos
);
387 static int ventoy_api_check_exist(struct mg_connection
*conn
, VTOY_JSON
*json
)
392 const char *path
= NULL
;
394 path
= vtoy_json_get_string_ex(json
, "path");
395 vtoy_json_get_int(json
, "dir", &dir
);
401 exist
= ventoy_is_directory_exist("%s", path
);
405 exist
= ventoy_is_file_exist("%s", path
);
409 VTOY_JSON_FMT_BEGIN(pos
, JSON_BUFFER
, JSON_BUF_MAX
);
410 VTOY_JSON_FMT_OBJ_BEGIN();
411 VTOY_JSON_FMT_SINT("exist", exist
);
412 VTOY_JSON_FMT_OBJ_END();
413 VTOY_JSON_FMT_END(pos
);
415 ventoy_json_buffer(conn
, JSON_BUFFER
, pos
);
419 static int ventoy_api_check_exist2(struct mg_connection
*conn
, VTOY_JSON
*json
)
428 const char *path1
= NULL
;
429 const char *path2
= NULL
;
431 path1
= vtoy_json_get_string_ex(json
, "path1");
432 path2
= vtoy_json_get_string_ex(json
, "path2");
433 vtoy_json_get_int(json
, "dir1", &dir1
);
434 vtoy_json_get_int(json
, "dir2", &dir2
);
435 vtoy_json_get_int(json
, "fuzzy1", &fuzzy1
);
436 vtoy_json_get_int(json
, "fuzzy2", &fuzzy2
);
442 exist1
= ventoy_is_directory_exist("%s", path1
);
448 exist1
= ventoy_check_fuzzy_path((char *)path1
, 0);
452 exist1
= ventoy_is_file_exist("%s", path1
);
461 exist2
= ventoy_is_directory_exist("%s", path2
);
467 exist2
= ventoy_check_fuzzy_path((char *)path2
, 0);
471 exist2
= ventoy_is_file_exist("%s", path2
);
476 VTOY_JSON_FMT_BEGIN(pos
, JSON_BUFFER
, JSON_BUF_MAX
);
477 VTOY_JSON_FMT_OBJ_BEGIN();
478 VTOY_JSON_FMT_SINT("exist1", exist1
);
479 VTOY_JSON_FMT_SINT("exist2", exist2
);
480 VTOY_JSON_FMT_OBJ_END();
481 VTOY_JSON_FMT_END(pos
);
483 ventoy_json_buffer(conn
, JSON_BUFFER
, pos
);
487 static int ventoy_api_check_fuzzy(struct mg_connection
*conn
, VTOY_JSON
*json
)
491 const char *path
= NULL
;
493 path
= vtoy_json_get_string_ex(json
, "path");
496 exist
= ventoy_check_fuzzy_path((char *)path
, 0);
499 VTOY_JSON_FMT_BEGIN(pos
, JSON_BUFFER
, JSON_BUF_MAX
);
500 VTOY_JSON_FMT_OBJ_BEGIN();
501 VTOY_JSON_FMT_SINT("exist", exist
);
502 VTOY_JSON_FMT_OBJ_END();
503 VTOY_JSON_FMT_END(pos
);
505 ventoy_json_buffer(conn
, JSON_BUFFER
, pos
);
512 void ventoy_data_default_control(data_control
*data
)
514 memset(data
, 0, sizeof(data_control
));
516 data
->secondary_menu
= 1;
517 data
->filter_dot_underscore
= 1;
518 data
->max_search_level
= -1;
519 data
->menu_timeout
= 0;
520 data
->secondary_menu_timeout
= 0;
522 strlcpy(data
->default_kbd_layout
, "QWERTY_USA");
523 strlcpy(data
->help_text_language
, "en_US");
526 int ventoy_data_cmp_control(data_control
*data1
, data_control
*data2
)
528 if (data1
->default_menu_mode
!= data2
->default_menu_mode
||
529 data1
->treeview_style
!= data2
->treeview_style
||
530 data1
->filter_dot_underscore
!= data2
->filter_dot_underscore
||
531 data1
->sort_casesensitive
!= data2
->sort_casesensitive
||
532 data1
->max_search_level
!= data2
->max_search_level
||
533 data1
->vhd_no_warning
!= data2
->vhd_no_warning
||
534 data1
->filter_iso
!= data2
->filter_iso
||
535 data1
->filter_wim
!= data2
->filter_wim
||
536 data1
->filter_efi
!= data2
->filter_efi
||
537 data1
->filter_img
!= data2
->filter_img
||
538 data1
->filter_vhd
!= data2
->filter_vhd
||
539 data1
->filter_vtoy
!= data2
->filter_vtoy
||
540 data1
->win11_bypass_check
!= data2
->win11_bypass_check
||
541 data1
->linux_remount
!= data2
->linux_remount
||
542 data1
->secondary_menu
!= data2
->secondary_menu
||
543 data1
->menu_timeout
!= data2
->menu_timeout
||
544 data1
->secondary_menu_timeout
!= data2
->secondary_menu_timeout
)
549 if (strcmp(data1
->default_search_root
, data2
->default_search_root
) ||
550 strcmp(data1
->default_image
, data2
->default_image
) ||
551 strcmp(data1
->default_kbd_layout
, data2
->default_kbd_layout
) ||
552 strcmp(data1
->help_text_language
, data2
->help_text_language
))
560 int ventoy_data_save_control(data_control
*data
, const char *title
, char *buf
, int buflen
)
563 data_control
*def
= g_data_control
+ bios_max
;
565 VTOY_JSON_FMT_BEGIN(pos
, buf
, buflen
);
567 VTOY_JSON_FMT_KEY_L(L1
, title
);
568 VTOY_JSON_FMT_ARY_BEGIN_N();
570 VTOY_JSON_FMT_CTRL_INT(L2
, "VTOY_DEFAULT_MENU_MODE", default_menu_mode
);
571 VTOY_JSON_FMT_CTRL_INT(L2
, "VTOY_TREE_VIEW_MENU_STYLE", treeview_style
);
572 VTOY_JSON_FMT_CTRL_INT(L2
, "VTOY_FILT_DOT_UNDERSCORE_FILE", filter_dot_underscore
);
573 VTOY_JSON_FMT_CTRL_INT(L2
, "VTOY_SORT_CASE_SENSITIVE", sort_casesensitive
);
575 if (data
->max_search_level
>= 0)
577 VTOY_JSON_FMT_CTRL_INT(L2
, "VTOY_MAX_SEARCH_LEVEL", max_search_level
);
580 VTOY_JSON_FMT_CTRL_INT(L2
, "VTOY_VHD_NO_WARNING", vhd_no_warning
);
581 VTOY_JSON_FMT_CTRL_INT(L2
, "VTOY_FILE_FLT_ISO", filter_iso
);
582 VTOY_JSON_FMT_CTRL_INT(L2
, "VTOY_FILE_FLT_WIM", filter_wim
);
583 VTOY_JSON_FMT_CTRL_INT(L2
, "VTOY_FILE_FLT_EFI", filter_efi
);
584 VTOY_JSON_FMT_CTRL_INT(L2
, "VTOY_FILE_FLT_IMG", filter_img
);
585 VTOY_JSON_FMT_CTRL_INT(L2
, "VTOY_FILE_FLT_VHD", filter_vhd
);
586 VTOY_JSON_FMT_CTRL_INT(L2
, "VTOY_FILE_FLT_VTOY", filter_vtoy
);
587 VTOY_JSON_FMT_CTRL_INT(L2
, "VTOY_WIN11_BYPASS_CHECK", win11_bypass_check
);
588 VTOY_JSON_FMT_CTRL_INT(L2
, "VTOY_LINUX_REMOUNT", linux_remount
);
589 VTOY_JSON_FMT_CTRL_INT(L2
, "VTOY_SECONDARY_BOOT_MENU", secondary_menu
);
590 VTOY_JSON_FMT_CTRL_INT(L2
, "VTOY_MENU_TIMEOUT", menu_timeout
);
591 VTOY_JSON_FMT_CTRL_INT(L2
, "VTOY_SECONDARY_TIMEOUT", secondary_menu_timeout
);
593 VTOY_JSON_FMT_CTRL_STRN(L2
, "VTOY_DEFAULT_KBD_LAYOUT", default_kbd_layout
);
594 VTOY_JSON_FMT_CTRL_STRN(L2
, "VTOY_HELP_TXT_LANGUAGE", help_text_language
);
596 if (strcmp(def
->default_search_root
, data
->default_search_root
))
598 VTOY_JSON_FMT_CTRL_STRN_STR(L2
, "VTOY_DEFAULT_SEARCH_ROOT", ventoy_real_path(data
->default_search_root
));
601 if (strcmp(def
->default_image
, data
->default_image
))
603 VTOY_JSON_FMT_CTRL_STRN_STR(L2
, "VTOY_DEFAULT_IMAGE", ventoy_real_path(data
->default_image
));
606 VTOY_JSON_FMT_ARY_ENDEX_LN(L1
);
607 VTOY_JSON_FMT_END(pos
);
612 int ventoy_data_json_control(data_control
*ctrl
, char *buf
, int buflen
)
618 VTOY_JSON_FMT_BEGIN(pos
, buf
, buflen
);
619 VTOY_JSON_FMT_OBJ_BEGIN();
621 VTOY_JSON_FMT_SINT("default_menu_mode", ctrl
->default_menu_mode
);
622 VTOY_JSON_FMT_SINT("treeview_style", ctrl
->treeview_style
);
623 VTOY_JSON_FMT_SINT("filter_dot_underscore", ctrl
->filter_dot_underscore
);
624 VTOY_JSON_FMT_SINT("sort_casesensitive", ctrl
->sort_casesensitive
);
625 VTOY_JSON_FMT_SINT("max_search_level", ctrl
->max_search_level
);
626 VTOY_JSON_FMT_SINT("vhd_no_warning", ctrl
->vhd_no_warning
);
628 VTOY_JSON_FMT_SINT("filter_iso", ctrl
->filter_iso
);
629 VTOY_JSON_FMT_SINT("filter_wim", ctrl
->filter_wim
);
630 VTOY_JSON_FMT_SINT("filter_efi", ctrl
->filter_efi
);
631 VTOY_JSON_FMT_SINT("filter_img", ctrl
->filter_img
);
632 VTOY_JSON_FMT_SINT("filter_vhd", ctrl
->filter_vhd
);
633 VTOY_JSON_FMT_SINT("filter_vtoy", ctrl
->filter_vtoy
);
634 VTOY_JSON_FMT_SINT("win11_bypass_check", ctrl
->win11_bypass_check
);
635 VTOY_JSON_FMT_SINT("linux_remount", ctrl
->linux_remount
);
636 VTOY_JSON_FMT_SINT("secondary_menu", ctrl
->secondary_menu
);
637 VTOY_JSON_FMT_SINT("menu_timeout", ctrl
->menu_timeout
);
638 VTOY_JSON_FMT_SINT("secondary_menu_timeout", ctrl
->secondary_menu_timeout
);
639 VTOY_JSON_FMT_STRN("default_kbd_layout", ctrl
->default_kbd_layout
);
640 VTOY_JSON_FMT_STRN("help_text_language", ctrl
->help_text_language
);
643 if (ctrl
->default_search_root
[0] && ventoy_is_directory_exist("%s%s", g_cur_dir
, ctrl
->default_search_root
))
647 VTOY_JSON_FMT_STRN("default_search_root", ctrl
->default_search_root
);
648 VTOY_JSON_FMT_SINT("default_search_root_valid", valid
);
652 if (ctrl
->default_image
[0] && ventoy_is_file_exist("%s%s", g_cur_dir
, ctrl
->default_image
))
656 VTOY_JSON_FMT_STRN("default_image", ctrl
->default_image
);
657 VTOY_JSON_FMT_SINT("default_image_valid", valid
);
659 VTOY_JSON_FMT_KEY("help_list");
660 VTOY_JSON_FMT_ARY_BEGIN();
662 for (i
= 0; g_ventoy_help_lang
[i
][0]; i
++)
664 VTOY_JSON_FMT_ITEM(g_ventoy_help_lang
[i
]);
666 VTOY_JSON_FMT_ARY_ENDEX();
669 VTOY_JSON_FMT_OBJ_END();
670 VTOY_JSON_FMT_END(pos
);
675 static int ventoy_api_get_control(struct mg_connection
*conn
, VTOY_JSON
*json
)
677 api_get_func(conn
, json
, control
);
681 static int ventoy_api_save_control(struct mg_connection
*conn
, VTOY_JSON
*json
)
685 data_control
*ctrl
= NULL
;
687 vtoy_json_get_int(json
, "index", &index
);
688 ctrl
= g_data_control
+ index
;
690 VTOY_JSON_INT("default_menu_mode", ctrl
->default_menu_mode
);
691 VTOY_JSON_INT("treeview_style", ctrl
->treeview_style
);
692 VTOY_JSON_INT("filter_dot_underscore", ctrl
->filter_dot_underscore
);
693 VTOY_JSON_INT("sort_casesensitive", ctrl
->sort_casesensitive
);
694 VTOY_JSON_INT("max_search_level", ctrl
->max_search_level
);
695 VTOY_JSON_INT("vhd_no_warning", ctrl
->vhd_no_warning
);
696 VTOY_JSON_INT("filter_iso", ctrl
->filter_iso
);
697 VTOY_JSON_INT("filter_wim", ctrl
->filter_wim
);
698 VTOY_JSON_INT("filter_efi", ctrl
->filter_efi
);
699 VTOY_JSON_INT("filter_img", ctrl
->filter_img
);
700 VTOY_JSON_INT("filter_vhd", ctrl
->filter_vhd
);
701 VTOY_JSON_INT("filter_vtoy", ctrl
->filter_vtoy
);
702 VTOY_JSON_INT("win11_bypass_check", ctrl
->win11_bypass_check
);
703 VTOY_JSON_INT("linux_remount", ctrl
->linux_remount
);
704 VTOY_JSON_INT("secondary_menu", ctrl
->secondary_menu
);
705 VTOY_JSON_INT("menu_timeout", ctrl
->menu_timeout
);
706 VTOY_JSON_INT("secondary_menu_timeout", ctrl
->secondary_menu_timeout
);
708 VTOY_JSON_STR("default_image", ctrl
->default_image
);
709 VTOY_JSON_STR("default_search_root", ctrl
->default_search_root
);
710 VTOY_JSON_STR("help_text_language", ctrl
->help_text_language
);
711 VTOY_JSON_STR("default_kbd_layout", ctrl
->default_kbd_layout
);
713 ret
= ventoy_data_save_all();
715 ventoy_json_result(conn
, ret
== 0 ? VTOY_JSON_SUCCESS_RET
: VTOY_JSON_FAILED_RET
);
723 void ventoy_data_default_theme(data_theme
*data
)
725 memset(data
, 0, sizeof(data_theme
));
726 strlcpy(data
->gfxmode
, "1024x768");
727 scnprintf(data
->ventoy_left
, sizeof(data
->ventoy_left
), "5%%");
728 scnprintf(data
->ventoy_top
, sizeof(data
->ventoy_top
), "95%%");
729 scnprintf(data
->ventoy_color
, sizeof(data
->ventoy_color
), "%s", "#0000ff");
732 int ventoy_data_cmp_theme(data_theme
*data1
, data_theme
*data2
)
734 if (data1
->display_mode
!= data2
->display_mode
||
735 strcmp(data1
->ventoy_left
, data2
->ventoy_left
) ||
736 strcmp(data1
->ventoy_top
, data2
->ventoy_top
) ||
737 strcmp(data1
->gfxmode
, data2
->gfxmode
) ||
738 strcmp(data1
->ventoy_color
, data2
->ventoy_color
)
744 if (ventoy_path_list_cmp(data1
->filelist
, data2
->filelist
))
749 if (ventoy_path_list_cmp(data1
->fontslist
, data2
->fontslist
))
758 int ventoy_data_save_theme(data_theme
*data
, const char *title
, char *buf
, int buflen
)
761 path_node
*node
= NULL
;
762 data_theme
*def
= g_data_theme
+ bios_max
;
764 VTOY_JSON_FMT_BEGIN(pos
, buf
, buflen
);
766 VTOY_JSON_FMT_KEY_L(L1
, title
);
767 VTOY_JSON_FMT_OBJ_BEGIN_N();
771 if (data
->filelist
->next
)
773 VTOY_JSON_FMT_KEY_L(L2
, "file");
774 VTOY_JSON_FMT_ARY_BEGIN_N();
776 for (node
= data
->filelist
; node
; node
= node
->next
)
778 VTOY_JSON_FMT_ITEM_PATH_LN(L3
, node
->path
);
781 VTOY_JSON_FMT_ARY_ENDEX_LN(L2
);
783 if (def
->default_file
!= data
->default_file
)
785 VTOY_JSON_FMT_SINT_LN(L2
, "default_file", data
->default_file
);
790 VTOY_JSON_FMT_STRN_PATH_LN(L2
, "file", data
->filelist
->path
);
794 if (data
->display_mode
!= def
->display_mode
)
796 if (display_mode_cli
== data
->display_mode
)
798 VTOY_JSON_FMT_STRN_LN(L2
, "display_mode", "CLI");
800 else if (display_mode_serial
== data
->display_mode
)
802 VTOY_JSON_FMT_STRN_LN(L2
, "display_mode", "serial");
804 else if (display_mode_ser_console
== data
->display_mode
)
806 VTOY_JSON_FMT_STRN_LN(L2
, "display_mode", "serial_console");
810 VTOY_JSON_FMT_STRN_LN(L2
, "display_mode", "GUI");
814 VTOY_JSON_FMT_DIFF_STRN(L2
, "gfxmode", gfxmode
);
816 VTOY_JSON_FMT_DIFF_STRN(L2
, "ventoy_left", ventoy_left
);
817 VTOY_JSON_FMT_DIFF_STRN(L2
, "ventoy_top", ventoy_top
);
818 VTOY_JSON_FMT_DIFF_STRN(L2
, "ventoy_color", ventoy_color
);
822 VTOY_JSON_FMT_KEY_L(L2
, "fonts");
823 VTOY_JSON_FMT_ARY_BEGIN_N();
825 for (node
= data
->fontslist
; node
; node
= node
->next
)
827 VTOY_JSON_FMT_ITEM_PATH_LN(L3
, node
->path
);
830 VTOY_JSON_FMT_ARY_ENDEX_LN(L2
);
833 VTOY_JSON_FMT_OBJ_ENDEX_LN(L1
);
834 VTOY_JSON_FMT_END(pos
);
840 int ventoy_data_json_theme(data_theme
*data
, char *buf
, int buflen
)
843 path_node
*node
= NULL
;
845 VTOY_JSON_FMT_BEGIN(pos
, buf
, buflen
);
846 VTOY_JSON_FMT_OBJ_BEGIN();
848 VTOY_JSON_FMT_SINT("default_file", data
->default_file
);
849 VTOY_JSON_FMT_SINT("display_mode", data
->display_mode
);
850 VTOY_JSON_FMT_STRN("gfxmode", data
->gfxmode
);
852 VTOY_JSON_FMT_STRN("ventoy_color", data
->ventoy_color
);
853 VTOY_JSON_FMT_STRN("ventoy_left", data
->ventoy_left
);
854 VTOY_JSON_FMT_STRN("ventoy_top", data
->ventoy_top
);
856 VTOY_JSON_FMT_KEY("filelist");
857 VTOY_JSON_FMT_ARY_BEGIN();
858 for (node
= data
->filelist
; node
; node
= node
->next
)
860 VTOY_JSON_FMT_OBJ_BEGIN();
861 VTOY_JSON_FMT_STRN("path", node
->path
);
862 VTOY_JSON_FMT_SINT("valid", ventoy_is_file_exist("%s%s", g_cur_dir
, node
->path
));
863 VTOY_JSON_FMT_OBJ_ENDEX();
865 VTOY_JSON_FMT_ARY_ENDEX();
867 VTOY_JSON_FMT_KEY("fontslist");
868 VTOY_JSON_FMT_ARY_BEGIN();
869 for (node
= data
->fontslist
; node
; node
= node
->next
)
871 VTOY_JSON_FMT_OBJ_BEGIN();
872 VTOY_JSON_FMT_STRN("path", node
->path
);
873 VTOY_JSON_FMT_SINT("valid", ventoy_is_file_exist("%s%s", g_cur_dir
, node
->path
));
874 VTOY_JSON_FMT_OBJ_ENDEX();
876 VTOY_JSON_FMT_ARY_ENDEX();
878 VTOY_JSON_FMT_OBJ_END();
879 VTOY_JSON_FMT_END(pos
);
884 static int ventoy_api_get_theme(struct mg_connection
*conn
, VTOY_JSON
*json
)
886 api_get_func(conn
, json
, theme
);
890 static int ventoy_api_save_theme(struct mg_connection
*conn
, VTOY_JSON
*json
)
894 data_theme
*data
= NULL
;
896 vtoy_json_get_int(json
, "index", &index
);
897 data
= g_data_theme
+ index
;
899 VTOY_JSON_INT("default_file", data
->default_file
);
900 VTOY_JSON_INT("display_mode", data
->display_mode
);
901 VTOY_JSON_STR("gfxmode", data
->gfxmode
);
902 VTOY_JSON_STR("ventoy_left", data
->ventoy_left
);
903 VTOY_JSON_STR("ventoy_top", data
->ventoy_top
);
904 VTOY_JSON_STR("ventoy_color", data
->ventoy_color
);
906 ret
= ventoy_data_save_all();
908 ventoy_json_result(conn
, ret
== 0 ? VTOY_JSON_SUCCESS_RET
: VTOY_JSON_FAILED_RET
);
912 static int ventoy_api_theme_add_file(struct mg_connection
*conn
, VTOY_JSON
*json
)
916 const char *path
= NULL
;
917 path_node
*node
= NULL
;
918 path_node
*cur
= NULL
;
919 data_theme
*data
= NULL
;
921 vtoy_json_get_int(json
, "index", &index
);
922 data
= g_data_theme
+ index
;
924 path
= VTOY_JSON_STR_EX("path");
927 node
= zalloc(sizeof(path_node
));
930 scnprintf(node
->path
, sizeof(node
->path
), "%s", path
);
932 vtoy_list_add(data
->filelist
, cur
, node
);
936 ret
= ventoy_data_save_all();
938 ventoy_json_result(conn
, ret
== 0 ? VTOY_JSON_SUCCESS_RET
: VTOY_JSON_FAILED_RET
);
942 static int ventoy_api_theme_del_file(struct mg_connection
*conn
, VTOY_JSON
*json
)
946 const char *path
= NULL
;
947 path_node
*node
= NULL
;
948 path_node
*last
= NULL
;
949 data_theme
*data
= NULL
;
951 vtoy_json_get_int(json
, "index", &index
);
952 data
= g_data_theme
+ index
;
954 path
= VTOY_JSON_STR_EX("path");
957 if (strcmp(path
, VTOY_DEL_ALL_PATH
) == 0)
959 vtoy_list_free(path_node
, data
->filelist
);
963 vtoy_list_del(last
, node
, data
->filelist
, path
);
967 ret
= ventoy_data_save_all();
969 ventoy_json_result(conn
, ret
== 0 ? VTOY_JSON_SUCCESS_RET
: VTOY_JSON_FAILED_RET
);
974 static int ventoy_api_theme_add_font(struct mg_connection
*conn
, VTOY_JSON
*json
)
978 const char *path
= NULL
;
979 path_node
*node
= NULL
;
980 path_node
*cur
= NULL
;
981 data_theme
*data
= NULL
;
983 vtoy_json_get_int(json
, "index", &index
);
984 data
= g_data_theme
+ index
;
986 path
= VTOY_JSON_STR_EX("path");
989 node
= zalloc(sizeof(path_node
));
992 scnprintf(node
->path
, sizeof(node
->path
), "%s", path
);
993 vtoy_list_add(data
->fontslist
, cur
, node
);
997 ret
= ventoy_data_save_all();
999 ventoy_json_result(conn
, ret
== 0 ? VTOY_JSON_SUCCESS_RET
: VTOY_JSON_FAILED_RET
);
1004 static int ventoy_api_theme_del_font(struct mg_connection
*conn
, VTOY_JSON
*json
)
1008 const char *path
= NULL
;
1009 path_node
*node
= NULL
;
1010 path_node
*last
= NULL
;
1011 data_theme
*data
= NULL
;
1013 vtoy_json_get_int(json
, "index", &index
);
1014 data
= g_data_theme
+ index
;
1016 path
= VTOY_JSON_STR_EX("path");
1019 if (strcmp(path
, VTOY_DEL_ALL_PATH
) == 0)
1021 vtoy_list_free(path_node
, data
->fontslist
);
1025 vtoy_list_del(last
, node
, data
->fontslist
, path
);
1029 ret
= ventoy_data_save_all();
1031 ventoy_json_result(conn
, ret
== 0 ? VTOY_JSON_SUCCESS_RET
: VTOY_JSON_FAILED_RET
);
1038 void ventoy_data_default_menu_alias(data_alias
*data
)
1040 memset(data
, 0, sizeof(data_alias
));
1043 int ventoy_data_cmp_menu_alias(data_alias
*data1
, data_alias
*data2
)
1045 data_alias_node
*list1
= NULL
;
1046 data_alias_node
*list2
= NULL
;
1048 if (NULL
== data1
->list
&& NULL
== data2
->list
)
1052 else if (data1
->list
&& data2
->list
)
1054 list1
= data1
->list
;
1055 list2
= data2
->list
;
1057 while (list1
&& list2
)
1059 if ((list1
->type
!= list2
->type
) ||
1060 strcmp(list1
->path
, list2
->path
) ||
1061 strcmp(list1
->alias
, list2
->alias
))
1066 list1
= list1
->next
;
1067 list2
= list2
->next
;
1070 if (list1
== NULL
&& list2
== NULL
)
1085 int ventoy_data_save_menu_alias(data_alias
*data
, const char *title
, char *buf
, int buflen
)
1088 data_alias_node
*node
= NULL
;
1090 VTOY_JSON_FMT_BEGIN(pos
, buf
, buflen
);
1092 VTOY_JSON_FMT_KEY_L(L1
, title
);
1093 VTOY_JSON_FMT_ARY_BEGIN_N();
1095 for (node
= data
->list
; node
; node
= node
->next
)
1097 VTOY_JSON_FMT_OBJ_BEGIN_LN(L2
);
1099 if (node
->type
== path_type_file
)
1101 VTOY_JSON_FMT_STRN_PATH_LN(L3
, "image", node
->path
);
1105 VTOY_JSON_FMT_STRN_PATH_LN(L3
, "dir", node
->path
);
1108 VTOY_JSON_FMT_STRN_EX_LN(L3
, "alias", node
->alias
);
1110 VTOY_JSON_FMT_OBJ_ENDEX_LN(L2
);
1113 VTOY_JSON_FMT_ARY_ENDEX_LN(L1
);
1114 VTOY_JSON_FMT_END(pos
);
1120 int ventoy_data_json_menu_alias(data_alias
*data
, char *buf
, int buflen
)
1124 data_alias_node
*node
= NULL
;
1126 VTOY_JSON_FMT_BEGIN(pos
, buf
, buflen
);
1127 VTOY_JSON_FMT_ARY_BEGIN();
1129 for (node
= data
->list
; node
; node
= node
->next
)
1131 VTOY_JSON_FMT_OBJ_BEGIN();
1133 VTOY_JSON_FMT_UINT("type", node
->type
);
1134 VTOY_JSON_FMT_STRN("path", node
->path
);
1135 if (node
->type
== path_type_file
)
1137 valid
= ventoy_check_fuzzy_path(node
->path
, 1);
1141 valid
= ventoy_is_directory_exist("%s%s", g_cur_dir
, node
->path
);
1144 VTOY_JSON_FMT_SINT("valid", valid
);
1145 VTOY_JSON_FMT_STRN("alias", node
->alias
);
1147 VTOY_JSON_FMT_OBJ_ENDEX();
1150 VTOY_JSON_FMT_ARY_END();
1151 VTOY_JSON_FMT_END(pos
);
1156 static int ventoy_api_get_alias(struct mg_connection
*conn
, VTOY_JSON
*json
)
1158 api_get_func(conn
, json
, menu_alias
);
1162 static int ventoy_api_save_alias(struct mg_connection
*conn
, VTOY_JSON
*json
)
1165 ret
= ventoy_data_save_all();
1167 ventoy_json_result(conn
, ret
== 0 ? VTOY_JSON_SUCCESS_RET
: VTOY_JSON_FAILED_RET
);
1171 static int ventoy_api_alias_add(struct mg_connection
*conn
, VTOY_JSON
*json
)
1175 int type
= path_type_file
;
1176 const char *path
= NULL
;
1177 const char *alias
= NULL
;
1178 data_alias_node
*node
= NULL
;
1179 data_alias_node
*cur
= NULL
;
1180 data_alias
*data
= NULL
;
1182 vtoy_json_get_int(json
, "index", &index
);
1183 data
= g_data_menu_alias
+ index
;
1185 vtoy_json_get_int(json
, "type", &type
);
1187 path
= VTOY_JSON_STR_EX("path");
1188 alias
= VTOY_JSON_STR_EX("alias");
1191 node
= zalloc(sizeof(data_alias_node
));
1195 scnprintf(node
->path
, sizeof(node
->path
), "%s", path
);
1196 scnprintf(node
->alias
, sizeof(node
->alias
), "%s", alias
);
1198 vtoy_list_add(data
->list
, cur
, node
);
1202 ret
= ventoy_data_save_all();
1204 ventoy_json_result(conn
, ret
== 0 ? VTOY_JSON_SUCCESS_RET
: VTOY_JSON_FAILED_RET
);
1208 static int ventoy_api_alias_del(struct mg_connection
*conn
, VTOY_JSON
*json
)
1212 const char *path
= NULL
;
1213 data_alias_node
*last
= NULL
;
1214 data_alias_node
*node
= NULL
;
1215 data_alias
*data
= NULL
;
1217 vtoy_json_get_int(json
, "index", &index
);
1218 data
= g_data_menu_alias
+ index
;
1220 path
= VTOY_JSON_STR_EX("path");
1223 if (strcmp(path
, VTOY_DEL_ALL_PATH
) == 0)
1225 vtoy_list_free(data_alias_node
, data
->list
);
1229 vtoy_list_del(last
, node
, data
->list
, path
);
1233 ret
= ventoy_data_save_all();
1235 ventoy_json_result(conn
, ret
== 0 ? VTOY_JSON_SUCCESS_RET
: VTOY_JSON_FAILED_RET
);
1242 void ventoy_data_default_menu_tip(data_tip
*data
)
1244 memset(data
, 0, sizeof(data_tip
));
1246 scnprintf(data
->left
, sizeof(data
->left
), "10%%");
1247 scnprintf(data
->top
, sizeof(data
->top
), "81%%");
1248 scnprintf(data
->color
, sizeof(data
->color
), "%s", "blue");
1251 int ventoy_data_cmp_menu_tip(data_tip
*data1
, data_tip
*data2
)
1253 data_tip_node
*list1
= NULL
;
1254 data_tip_node
*list2
= NULL
;
1256 if (strcmp(data1
->left
, data2
->left
) || strcmp(data1
->top
, data2
->top
) || strcmp(data1
->color
, data2
->color
))
1261 if (NULL
== data1
->list
&& NULL
== data2
->list
)
1265 else if (data1
->list
&& data2
->list
)
1267 list1
= data1
->list
;
1268 list2
= data2
->list
;
1270 while (list1
&& list2
)
1272 if ((list1
->type
!= list2
->type
) ||
1273 strcmp(list1
->path
, list2
->path
) ||
1274 strcmp(list1
->tip
, list2
->tip
))
1279 list1
= list1
->next
;
1280 list2
= list2
->next
;
1283 if (list1
== NULL
&& list2
== NULL
)
1298 int ventoy_data_save_menu_tip(data_tip
*data
, const char *title
, char *buf
, int buflen
)
1301 data_tip_node
*node
= NULL
;
1302 data_tip
*def
= g_data_menu_tip
+ bios_max
;
1304 VTOY_JSON_FMT_BEGIN(pos
, buf
, buflen
);
1305 VTOY_JSON_FMT_KEY_L(L1
, title
);
1306 VTOY_JSON_FMT_OBJ_BEGIN_N();
1308 VTOY_JSON_FMT_DIFF_STRN(L2
, "left", left
);
1309 VTOY_JSON_FMT_DIFF_STRN(L2
, "top", top
);
1310 VTOY_JSON_FMT_DIFF_STRN(L2
, "color", color
);
1314 VTOY_JSON_FMT_KEY_L(L2
, "tips");
1315 VTOY_JSON_FMT_ARY_BEGIN_N();
1317 for (node
= data
->list
; node
; node
= node
->next
)
1319 VTOY_JSON_FMT_OBJ_BEGIN_LN(L3
);
1321 if (node
->type
== path_type_file
)
1323 VTOY_JSON_FMT_STRN_PATH_LN(L4
, "image", node
->path
);
1327 VTOY_JSON_FMT_STRN_PATH_LN(L4
, "dir", node
->path
);
1329 VTOY_JSON_FMT_STRN_EX_LN(L4
, "tip", node
->tip
);
1331 VTOY_JSON_FMT_OBJ_ENDEX_LN(L3
);
1334 VTOY_JSON_FMT_ARY_ENDEX_LN(L2
);
1337 VTOY_JSON_FMT_OBJ_ENDEX_LN(L1
);
1339 VTOY_JSON_FMT_END(pos
);
1345 int ventoy_data_json_menu_tip(data_tip
*data
, char *buf
, int buflen
)
1349 data_tip_node
*node
= NULL
;
1351 VTOY_JSON_FMT_BEGIN(pos
, buf
, buflen
);
1353 VTOY_JSON_FMT_OBJ_BEGIN();
1355 VTOY_JSON_FMT_STRN("left", data
->left
);
1356 VTOY_JSON_FMT_STRN("top", data
->top
);
1357 VTOY_JSON_FMT_STRN("color", data
->color
);
1359 VTOY_JSON_FMT_KEY("tips");
1360 VTOY_JSON_FMT_ARY_BEGIN();
1362 for (node
= data
->list
; node
; node
= node
->next
)
1364 VTOY_JSON_FMT_OBJ_BEGIN();
1366 VTOY_JSON_FMT_UINT("type", node
->type
);
1367 VTOY_JSON_FMT_STRN("path", node
->path
);
1368 if (node
->type
== path_type_file
)
1370 valid
= ventoy_check_fuzzy_path(node
->path
, 1);
1374 valid
= ventoy_is_directory_exist("%s%s", g_cur_dir
, node
->path
);
1377 VTOY_JSON_FMT_SINT("valid", valid
);
1378 VTOY_JSON_FMT_STRN("tip", node
->tip
);
1380 VTOY_JSON_FMT_OBJ_ENDEX();
1383 VTOY_JSON_FMT_ARY_ENDEX();
1385 VTOY_JSON_FMT_OBJ_END();
1386 VTOY_JSON_FMT_END(pos
);
1391 static int ventoy_api_get_tip(struct mg_connection
*conn
, VTOY_JSON
*json
)
1393 api_get_func(conn
, json
, menu_tip
);
1397 static int ventoy_api_save_tip(struct mg_connection
*conn
, VTOY_JSON
*json
)
1401 data_tip
*data
= NULL
;
1403 vtoy_json_get_int(json
, "index", &index
);
1404 data
= g_data_menu_tip
+ index
;
1406 VTOY_JSON_STR("left", data
->left
);
1407 VTOY_JSON_STR("top", data
->top
);
1408 VTOY_JSON_STR("color", data
->color
);
1410 ret
= ventoy_data_save_all();
1412 ventoy_json_result(conn
, ret
== 0 ? VTOY_JSON_SUCCESS_RET
: VTOY_JSON_FAILED_RET
);
1416 static int ventoy_api_tip_add(struct mg_connection
*conn
, VTOY_JSON
*json
)
1420 int type
= path_type_file
;
1421 const char *path
= NULL
;
1422 const char *tip
= NULL
;
1423 data_tip_node
*node
= NULL
;
1424 data_tip_node
*cur
= NULL
;
1425 data_tip
*data
= NULL
;
1427 vtoy_json_get_int(json
, "index", &index
);
1428 data
= g_data_menu_tip
+ index
;
1430 vtoy_json_get_int(json
, "type", &type
);
1432 path
= VTOY_JSON_STR_EX("path");
1433 tip
= VTOY_JSON_STR_EX("tip");
1436 node
= zalloc(sizeof(data_tip_node
));
1440 scnprintf(node
->path
, sizeof(node
->path
), "%s", path
);
1441 scnprintf(node
->tip
, sizeof(node
->tip
), "%s", tip
);
1443 vtoy_list_add(data
->list
, cur
, node
);
1447 ret
= ventoy_data_save_all();
1449 ventoy_json_result(conn
, ret
== 0 ? VTOY_JSON_SUCCESS_RET
: VTOY_JSON_FAILED_RET
);
1453 static int ventoy_api_tip_del(struct mg_connection
*conn
, VTOY_JSON
*json
)
1457 const char *path
= NULL
;
1458 data_tip_node
*last
= NULL
;
1459 data_tip_node
*node
= NULL
;
1460 data_tip
*data
= NULL
;
1462 vtoy_json_get_int(json
, "index", &index
);
1463 data
= g_data_menu_tip
+ index
;
1465 path
= VTOY_JSON_STR_EX("path");
1468 if (strcmp(path
, VTOY_DEL_ALL_PATH
) == 0)
1470 vtoy_list_free(data_tip_node
, data
->list
);
1474 vtoy_list_del(last
, node
, data
->list
, path
);
1478 ret
= ventoy_data_save_all();
1480 ventoy_json_result(conn
, ret
== 0 ? VTOY_JSON_SUCCESS_RET
: VTOY_JSON_FAILED_RET
);
1487 void ventoy_data_default_menu_class(data_class
*data
)
1489 memset(data
, 0, sizeof(data_class
));
1492 int ventoy_data_cmp_menu_class(data_class
*data1
, data_class
*data2
)
1494 data_class_node
*list1
= NULL
;
1495 data_class_node
*list2
= NULL
;
1497 if (NULL
== data1
->list
&& NULL
== data2
->list
)
1501 else if (data1
->list
&& data2
->list
)
1503 list1
= data1
->list
;
1504 list2
= data2
->list
;
1506 while (list1
&& list2
)
1508 if ((list1
->type
!= list2
->type
) ||
1509 strcmp(list1
->path
, list2
->path
) ||
1510 strcmp(list1
->class, list2
->class))
1515 list1
= list1
->next
;
1516 list2
= list2
->next
;
1519 if (list1
== NULL
&& list2
== NULL
)
1534 int ventoy_data_save_menu_class(data_class
*data
, const char *title
, char *buf
, int buflen
)
1537 data_class_node
*node
= NULL
;
1539 VTOY_JSON_FMT_BEGIN(pos
, buf
, buflen
);
1541 VTOY_JSON_FMT_KEY_L(L1
, title
);
1542 VTOY_JSON_FMT_ARY_BEGIN_N();
1544 for (node
= data
->list
; node
; node
= node
->next
)
1546 VTOY_JSON_FMT_OBJ_BEGIN_LN(L2
);
1548 if (node
->type
== class_type_key
)
1550 VTOY_JSON_FMT_STRN_LN(L3
, "key", node
->path
);
1552 else if (node
->type
== class_type_dir
)
1554 VTOY_JSON_FMT_STRN_PATH_LN(L3
, "dir", node
->path
);
1558 VTOY_JSON_FMT_STRN_PATH_LN(L3
, "parent", node
->path
);
1560 VTOY_JSON_FMT_STRN_LN(L3
, "class", node
->class);
1562 VTOY_JSON_FMT_OBJ_ENDEX_LN(L2
);
1565 VTOY_JSON_FMT_ARY_ENDEX_LN(L1
);
1566 VTOY_JSON_FMT_END(pos
);
1572 int ventoy_data_json_menu_class(data_class
*data
, char *buf
, int buflen
)
1576 data_class_node
*node
= NULL
;
1578 VTOY_JSON_FMT_BEGIN(pos
, buf
, buflen
);
1579 VTOY_JSON_FMT_ARY_BEGIN();
1581 for (node
= data
->list
; node
; node
= node
->next
)
1583 VTOY_JSON_FMT_OBJ_BEGIN();
1585 VTOY_JSON_FMT_UINT("type", node
->type
);
1586 VTOY_JSON_FMT_STRN("path", node
->path
);
1588 if (node
->type
== class_type_key
)
1594 valid
= ventoy_is_directory_exist("%s%s", g_cur_dir
, node
->path
);
1596 VTOY_JSON_FMT_SINT("valid", valid
);
1598 VTOY_JSON_FMT_STRN("class", node
->class);
1600 VTOY_JSON_FMT_OBJ_ENDEX();
1603 VTOY_JSON_FMT_ARY_END();
1604 VTOY_JSON_FMT_END(pos
);
1610 static int ventoy_api_get_class(struct mg_connection
*conn
, VTOY_JSON
*json
)
1612 api_get_func(conn
, json
, menu_class
);
1616 static int ventoy_api_save_class(struct mg_connection
*conn
, VTOY_JSON
*json
)
1619 ret
= ventoy_data_save_all();
1621 ventoy_json_result(conn
, ret
== 0 ? VTOY_JSON_SUCCESS_RET
: VTOY_JSON_FAILED_RET
);
1625 static int ventoy_api_class_add(struct mg_connection
*conn
, VTOY_JSON
*json
)
1629 int type
= class_type_key
;
1630 const char *path
= NULL
;
1631 const char *class = NULL
;
1632 data_class_node
*node
= NULL
;
1633 data_class_node
*cur
= NULL
;
1634 data_class
*data
= NULL
;
1636 vtoy_json_get_int(json
, "index", &index
);
1637 data
= g_data_menu_class
+ index
;
1639 vtoy_json_get_int(json
, "type", &type
);
1641 path
= VTOY_JSON_STR_EX("path");
1642 class = VTOY_JSON_STR_EX("class");
1645 node
= zalloc(sizeof(data_class_node
));
1650 scnprintf(node
->path
, sizeof(node
->path
), "%s", path
);
1651 scnprintf(node
->class, sizeof(node
->class), "%s", class);
1653 vtoy_list_add(data
->list
, cur
, node
);
1657 ret
= ventoy_data_save_all();
1659 ventoy_json_result(conn
, ret
== 0 ? VTOY_JSON_SUCCESS_RET
: VTOY_JSON_FAILED_RET
);
1663 static int ventoy_api_class_del(struct mg_connection
*conn
, VTOY_JSON
*json
)
1667 const char *path
= NULL
;
1668 data_class_node
*last
= NULL
;
1669 data_class_node
*node
= NULL
;
1670 data_class
*data
= NULL
;
1672 vtoy_json_get_int(json
, "index", &index
);
1673 data
= g_data_menu_class
+ index
;
1675 path
= VTOY_JSON_STR_EX("path");
1678 if (strcmp(path
, VTOY_DEL_ALL_PATH
) == 0)
1680 vtoy_list_free(data_class_node
, data
->list
);
1684 vtoy_list_del(last
, node
, data
->list
, path
);
1688 ret
= ventoy_data_save_all();
1690 ventoy_json_result(conn
, ret
== 0 ? VTOY_JSON_SUCCESS_RET
: VTOY_JSON_FAILED_RET
);
1697 void ventoy_data_default_auto_memdisk(data_auto_memdisk
*data
)
1699 memset(data
, 0, sizeof(data_auto_memdisk
));
1702 int ventoy_data_cmp_auto_memdisk(data_auto_memdisk
*data1
, data_auto_memdisk
*data2
)
1704 return ventoy_path_list_cmp(data1
->list
, data2
->list
);
1707 int ventoy_data_save_auto_memdisk(data_auto_memdisk
*data
, const char *title
, char *buf
, int buflen
)
1710 path_node
*node
= NULL
;
1712 VTOY_JSON_FMT_BEGIN(pos
, buf
, buflen
);
1714 VTOY_JSON_FMT_KEY_L(L1
, title
);
1715 VTOY_JSON_FMT_ARY_BEGIN_N();
1717 for (node
= data
->list
; node
; node
= node
->next
)
1719 VTOY_JSON_FMT_ITEM_PATH_LN(L2
, node
->path
);
1722 VTOY_JSON_FMT_ARY_ENDEX_LN(L1
);
1723 VTOY_JSON_FMT_END(pos
);
1728 int ventoy_data_json_auto_memdisk(data_auto_memdisk
*data
, char *buf
, int buflen
)
1732 path_node
*node
= NULL
;
1734 VTOY_JSON_FMT_BEGIN(pos
, buf
, buflen
);
1735 VTOY_JSON_FMT_ARY_BEGIN();
1737 for (node
= data
->list
; node
; node
= node
->next
)
1739 VTOY_JSON_FMT_OBJ_BEGIN();
1741 VTOY_JSON_FMT_STRN("path", node
->path
);
1742 valid
= ventoy_check_fuzzy_path(node
->path
, 1);
1743 VTOY_JSON_FMT_SINT("valid", valid
);
1745 VTOY_JSON_FMT_OBJ_ENDEX();
1748 VTOY_JSON_FMT_ARY_END();
1749 VTOY_JSON_FMT_END(pos
);
1754 static int ventoy_api_get_auto_memdisk(struct mg_connection
*conn
, VTOY_JSON
*json
)
1756 api_get_func(conn
, json
, auto_memdisk
);
1760 static int ventoy_api_save_auto_memdisk(struct mg_connection
*conn
, VTOY_JSON
*json
)
1764 ret
= ventoy_data_save_all();
1766 ventoy_json_result(conn
, ret
== 0 ? VTOY_JSON_SUCCESS_RET
: VTOY_JSON_FAILED_RET
);
1770 static int ventoy_api_auto_memdisk_add(struct mg_connection
*conn
, VTOY_JSON
*json
)
1774 const char *path
= NULL
;
1775 path_node
*node
= NULL
;
1776 path_node
*cur
= NULL
;
1777 data_auto_memdisk
*data
= NULL
;
1779 vtoy_json_get_int(json
, "index", &index
);
1780 data
= g_data_auto_memdisk
+ index
;
1782 path
= VTOY_JSON_STR_EX("path");
1785 node
= zalloc(sizeof(path_node
));
1788 scnprintf(node
->path
, sizeof(node
->path
), "%s", path
);
1789 vtoy_list_add(data
->list
, cur
, node
);
1793 ret
= ventoy_data_save_all();
1795 ventoy_json_result(conn
, ret
== 0 ? VTOY_JSON_SUCCESS_RET
: VTOY_JSON_FAILED_RET
);
1799 static int ventoy_api_auto_memdisk_del(struct mg_connection
*conn
, VTOY_JSON
*json
)
1803 const char *path
= NULL
;
1804 path_node
*last
= NULL
;
1805 path_node
*node
= NULL
;
1806 data_auto_memdisk
*data
= NULL
;
1808 vtoy_json_get_int(json
, "index", &index
);
1809 data
= g_data_auto_memdisk
+ index
;
1811 path
= VTOY_JSON_STR_EX("path");
1814 if (strcmp(path
, VTOY_DEL_ALL_PATH
) == 0)
1816 vtoy_list_free(path_node
, data
->list
);
1820 vtoy_list_del(last
, node
, data
->list
, path
);
1824 ret
= ventoy_data_save_all();
1826 ventoy_json_result(conn
, ret
== 0 ? VTOY_JSON_SUCCESS_RET
: VTOY_JSON_FAILED_RET
);
1833 void ventoy_data_default_image_list(data_image_list
*data
)
1835 memset(data
, 0, sizeof(data_image_list
));
1838 int ventoy_data_cmp_image_list(data_image_list
*data1
, data_image_list
*data2
)
1840 if (data1
->type
!= data2
->type
)
1842 if (data1
->list
|| data2
->list
)
1852 return ventoy_path_list_cmp(data1
->list
, data2
->list
);
1855 int ventoy_data_save_image_list(data_image_list
*data
, const char *title
, char *buf
, int buflen
)
1859 path_node
*node
= NULL
;
1869 prelen
= (int)strlen("image_list");
1871 VTOY_JSON_FMT_BEGIN(pos
, buf
, buflen
);
1873 if (data
->type
== 0)
1875 scnprintf(newtitle
, sizeof(newtitle
), "image_list%s", title
+ prelen
);
1879 scnprintf(newtitle
, sizeof(newtitle
), "image_blacklist%s", title
+ prelen
);
1881 VTOY_JSON_FMT_KEY_L(L1
, newtitle
);
1883 VTOY_JSON_FMT_ARY_BEGIN_N();
1885 for (node
= data
->list
; node
; node
= node
->next
)
1887 VTOY_JSON_FMT_ITEM_PATH_LN(L2
, node
->path
);
1890 VTOY_JSON_FMT_ARY_ENDEX_LN(L1
);
1891 VTOY_JSON_FMT_END(pos
);
1896 int ventoy_data_json_image_list(data_image_list
*data
, char *buf
, int buflen
)
1900 path_node
*node
= NULL
;
1902 VTOY_JSON_FMT_BEGIN(pos
, buf
, buflen
);
1904 VTOY_JSON_FMT_OBJ_BEGIN();
1905 VTOY_JSON_FMT_SINT("type", data
->type
);
1907 VTOY_JSON_FMT_KEY("list");
1908 VTOY_JSON_FMT_ARY_BEGIN();
1910 for (node
= data
->list
; node
; node
= node
->next
)
1912 VTOY_JSON_FMT_OBJ_BEGIN();
1914 VTOY_JSON_FMT_STRN("path", node
->path
);
1915 valid
= ventoy_check_fuzzy_path(node
->path
, 1);
1916 VTOY_JSON_FMT_SINT("valid", valid
);
1918 VTOY_JSON_FMT_OBJ_ENDEX();
1921 VTOY_JSON_FMT_ARY_ENDEX();
1922 VTOY_JSON_FMT_OBJ_END();
1924 VTOY_JSON_FMT_END(pos
);
1929 static int ventoy_api_get_image_list(struct mg_connection
*conn
, VTOY_JSON
*json
)
1931 api_get_func(conn
, json
, image_list
);
1935 static int ventoy_api_save_image_list(struct mg_connection
*conn
, VTOY_JSON
*json
)
1939 data_image_list
*data
= NULL
;
1941 vtoy_json_get_int(json
, "index", &index
);
1942 data
= g_data_image_list
+ index
;
1944 VTOY_JSON_INT("type", data
->type
);
1946 ret
= ventoy_data_save_all();
1948 ventoy_json_result(conn
, ret
== 0 ? VTOY_JSON_SUCCESS_RET
: VTOY_JSON_FAILED_RET
);
1952 static int ventoy_api_image_list_add(struct mg_connection
*conn
, VTOY_JSON
*json
)
1956 const char *path
= NULL
;
1957 path_node
*node
= NULL
;
1958 path_node
*cur
= NULL
;
1959 data_image_list
*data
= NULL
;
1961 vtoy_json_get_int(json
, "index", &index
);
1962 data
= g_data_image_list
+ index
;
1964 path
= VTOY_JSON_STR_EX("path");
1967 node
= zalloc(sizeof(path_node
));
1970 scnprintf(node
->path
, sizeof(node
->path
), "%s", path
);
1971 vtoy_list_add(data
->list
, cur
, node
);
1975 ret
= ventoy_data_save_all();
1977 ventoy_json_result(conn
, ret
== 0 ? VTOY_JSON_SUCCESS_RET
: VTOY_JSON_FAILED_RET
);
1981 static int ventoy_api_image_list_del(struct mg_connection
*conn
, VTOY_JSON
*json
)
1985 const char *path
= NULL
;
1986 path_node
*last
= NULL
;
1987 path_node
*node
= NULL
;
1988 data_image_list
*data
= NULL
;
1990 vtoy_json_get_int(json
, "index", &index
);
1991 data
= g_data_image_list
+ index
;
1993 path
= VTOY_JSON_STR_EX("path");
1996 if (strcmp(path
, VTOY_DEL_ALL_PATH
) == 0)
1998 vtoy_list_free(path_node
, data
->list
);
2002 vtoy_list_del(last
, node
, data
->list
, path
);
2006 ret
= ventoy_data_save_all();
2008 ventoy_json_result(conn
, ret
== 0 ? VTOY_JSON_SUCCESS_RET
: VTOY_JSON_FAILED_RET
);
2015 void ventoy_data_default_password(data_password
*data
)
2017 memset(data
, 0, sizeof(data_password
));
2020 int ventoy_data_cmp_password(data_password
*data1
, data_password
*data2
)
2022 menu_password
*list1
= NULL
;
2023 menu_password
*list2
= NULL
;
2025 if (strcmp(data1
->bootpwd
, data2
->bootpwd
) ||
2026 strcmp(data1
->isopwd
, data2
->isopwd
) ||
2027 strcmp(data1
->wimpwd
, data2
->wimpwd
) ||
2028 strcmp(data1
->vhdpwd
, data2
->vhdpwd
) ||
2029 strcmp(data1
->imgpwd
, data2
->imgpwd
) ||
2030 strcmp(data1
->efipwd
, data2
->efipwd
) ||
2031 strcmp(data1
->vtoypwd
, data2
->vtoypwd
)
2037 if (NULL
== data1
->list
&& NULL
== data2
->list
)
2041 else if (data1
->list
&& data2
->list
)
2043 list1
= data1
->list
;
2044 list2
= data2
->list
;
2046 while (list1
&& list2
)
2048 if ((list1
->type
!= list2
->type
) || strcmp(list1
->path
, list2
->path
))
2053 list1
= list1
->next
;
2054 list2
= list2
->next
;
2057 if (list1
== NULL
&& list2
== NULL
)
2072 int ventoy_data_save_password(data_password
*data
, const char *title
, char *buf
, int buflen
)
2075 menu_password
*node
= NULL
;
2076 data_password
*def
= g_data_password
+ bios_max
;
2078 VTOY_JSON_FMT_BEGIN(pos
, buf
, buflen
);
2079 VTOY_JSON_FMT_KEY_L(L1
, title
);
2080 VTOY_JSON_FMT_OBJ_BEGIN_N();
2082 VTOY_JSON_FMT_DIFF_STRN(L2
, "bootpwd", bootpwd
);
2083 VTOY_JSON_FMT_DIFF_STRN(L2
, "isopwd", isopwd
);
2084 VTOY_JSON_FMT_DIFF_STRN(L2
, "wimpwd", wimpwd
);
2085 VTOY_JSON_FMT_DIFF_STRN(L2
, "vhdpwd", vhdpwd
);
2086 VTOY_JSON_FMT_DIFF_STRN(L2
, "imgpwd", imgpwd
);
2087 VTOY_JSON_FMT_DIFF_STRN(L2
, "efipwd", efipwd
);
2088 VTOY_JSON_FMT_DIFF_STRN(L2
, "vtoypwd", vtoypwd
);
2092 VTOY_JSON_FMT_KEY_L(L2
, "menupwd");
2093 VTOY_JSON_FMT_ARY_BEGIN_N();
2095 for (node
= data
->list
; node
; node
= node
->next
)
2097 VTOY_JSON_FMT_OBJ_BEGIN_LN(L3
);
2099 if (node
->type
== 0)
2101 VTOY_JSON_FMT_STRN_PATH_LN(L4
, "file", node
->path
);
2105 VTOY_JSON_FMT_STRN_PATH_LN(L4
, "parent", node
->path
);
2107 VTOY_JSON_FMT_STRN_LN(L4
, "pwd", node
->pwd
);
2109 VTOY_JSON_FMT_OBJ_ENDEX_LN(L3
);
2112 VTOY_JSON_FMT_ARY_ENDEX_LN(L2
);
2115 VTOY_JSON_FMT_OBJ_ENDEX_LN(L1
);
2117 VTOY_JSON_FMT_END(pos
);
2123 int ventoy_data_json_password(data_password
*data
, char *buf
, int buflen
)
2127 menu_password
*node
= NULL
;
2129 VTOY_JSON_FMT_BEGIN(pos
, buf
, buflen
);
2131 VTOY_JSON_FMT_OBJ_BEGIN();
2133 VTOY_JSON_FMT_STRN("bootpwd", data
->bootpwd
);
2134 VTOY_JSON_FMT_STRN("isopwd", data
->isopwd
);
2135 VTOY_JSON_FMT_STRN("wimpwd", data
->wimpwd
);
2136 VTOY_JSON_FMT_STRN("vhdpwd", data
->vhdpwd
);
2137 VTOY_JSON_FMT_STRN("imgpwd", data
->imgpwd
);
2138 VTOY_JSON_FMT_STRN("efipwd", data
->efipwd
);
2139 VTOY_JSON_FMT_STRN("vtoypwd", data
->vtoypwd
);
2141 VTOY_JSON_FMT_KEY("list");
2142 VTOY_JSON_FMT_ARY_BEGIN();
2144 for (node
= data
->list
; node
; node
= node
->next
)
2146 VTOY_JSON_FMT_OBJ_BEGIN();
2148 VTOY_JSON_FMT_SINT("type", node
->type
);
2149 VTOY_JSON_FMT_STRN("path", node
->path
);
2150 if (node
->type
== path_type_file
)
2152 valid
= ventoy_check_fuzzy_path(node
->path
, 1);
2156 valid
= ventoy_is_directory_exist("%s%s", g_cur_dir
, node
->path
);
2159 VTOY_JSON_FMT_SINT("valid", valid
);
2160 VTOY_JSON_FMT_STRN("pwd", node
->pwd
);
2162 VTOY_JSON_FMT_OBJ_ENDEX();
2165 VTOY_JSON_FMT_ARY_ENDEX();
2167 VTOY_JSON_FMT_OBJ_END();
2168 VTOY_JSON_FMT_END(pos
);
2173 static int ventoy_api_get_password(struct mg_connection
*conn
, VTOY_JSON
*json
)
2175 api_get_func(conn
, json
, password
);
2179 static int ventoy_api_save_password(struct mg_connection
*conn
, VTOY_JSON
*json
)
2183 data_password
*data
= NULL
;
2185 vtoy_json_get_int(json
, "index", &index
);
2186 data
= g_data_password
+ index
;
2188 VTOY_JSON_STR("bootpwd", data
->bootpwd
);
2189 VTOY_JSON_STR("isopwd", data
->isopwd
);
2190 VTOY_JSON_STR("wimpwd", data
->wimpwd
);
2191 VTOY_JSON_STR("vhdpwd", data
->vhdpwd
);
2192 VTOY_JSON_STR("imgpwd", data
->imgpwd
);
2193 VTOY_JSON_STR("efipwd", data
->efipwd
);
2194 VTOY_JSON_STR("vtoypwd", data
->vtoypwd
);
2196 ret
= ventoy_data_save_all();
2198 ventoy_json_result(conn
, ret
== 0 ? VTOY_JSON_SUCCESS_RET
: VTOY_JSON_FAILED_RET
);
2202 static int ventoy_api_password_add(struct mg_connection
*conn
, VTOY_JSON
*json
)
2207 const char *path
= NULL
;
2208 const char *pwd
= NULL
;
2209 menu_password
*node
= NULL
;
2210 menu_password
*cur
= NULL
;
2211 data_password
*data
= NULL
;
2213 vtoy_json_get_int(json
, "index", &index
);
2214 data
= g_data_password
+ index
;
2216 vtoy_json_get_int(json
, "type", &type
);
2218 path
= VTOY_JSON_STR_EX("path");
2219 pwd
= VTOY_JSON_STR_EX("pwd");
2222 node
= zalloc(sizeof(menu_password
));
2226 scnprintf(node
->path
, sizeof(node
->path
), "%s", path
);
2227 scnprintf(node
->pwd
, sizeof(node
->pwd
), "%s", pwd
);
2229 vtoy_list_add(data
->list
, cur
, node
);
2233 ret
= ventoy_data_save_all();
2235 ventoy_json_result(conn
, ret
== 0 ? VTOY_JSON_SUCCESS_RET
: VTOY_JSON_FAILED_RET
);
2239 static int ventoy_api_password_del(struct mg_connection
*conn
, VTOY_JSON
*json
)
2243 const char *path
= NULL
;
2244 menu_password
*last
= NULL
;
2245 menu_password
*node
= NULL
;
2246 data_password
*data
= NULL
;
2248 vtoy_json_get_int(json
, "index", &index
);
2249 data
= g_data_password
+ index
;
2251 path
= VTOY_JSON_STR_EX("path");
2254 if (strcmp(path
, VTOY_DEL_ALL_PATH
) == 0)
2256 vtoy_list_free(menu_password
, data
->list
);
2260 vtoy_list_del(last
, node
, data
->list
, path
);
2264 ret
= ventoy_data_save_all();
2266 ventoy_json_result(conn
, ret
== 0 ? VTOY_JSON_SUCCESS_RET
: VTOY_JSON_FAILED_RET
);
2273 void ventoy_data_default_conf_replace(data_conf_replace
*data
)
2275 memset(data
, 0, sizeof(data_conf_replace
));
2278 int ventoy_data_cmp_conf_replace(data_conf_replace
*data1
, data_conf_replace
*data2
)
2280 conf_replace_node
*list1
= NULL
;
2281 conf_replace_node
*list2
= NULL
;
2283 if (NULL
== data1
->list
&& NULL
== data2
->list
)
2287 else if (data1
->list
&& data2
->list
)
2289 list1
= data1
->list
;
2290 list2
= data2
->list
;
2292 while (list1
&& list2
)
2294 if (list1
->image
!= list2
->image
||
2295 strcmp(list1
->path
, list2
->path
) ||
2296 strcmp(list1
->org
, list2
->org
) ||
2297 strcmp(list1
->new, list2
->new)
2303 list1
= list1
->next
;
2304 list2
= list2
->next
;
2307 if (list1
== NULL
&& list2
== NULL
)
2322 int ventoy_data_save_conf_replace(data_conf_replace
*data
, const char *title
, char *buf
, int buflen
)
2325 conf_replace_node
*node
= NULL
;
2327 VTOY_JSON_FMT_BEGIN(pos
, buf
, buflen
);
2329 VTOY_JSON_FMT_KEY_L(L1
, title
);
2330 VTOY_JSON_FMT_ARY_BEGIN_N();
2332 for (node
= data
->list
; node
; node
= node
->next
)
2334 VTOY_JSON_FMT_OBJ_BEGIN_LN(L2
);
2336 VTOY_JSON_FMT_STRN_PATH_LN(L3
, "iso", node
->path
);
2337 VTOY_JSON_FMT_STRN_LN(L3
, "org", node
->org
);
2338 VTOY_JSON_FMT_STRN_PATH_LN(L3
, "new", node
->new);
2341 VTOY_JSON_FMT_SINT_LN(L3
, "img", node
->image
);
2344 VTOY_JSON_FMT_OBJ_ENDEX_LN(L2
);
2347 VTOY_JSON_FMT_ARY_ENDEX_LN(L1
);
2348 VTOY_JSON_FMT_END(pos
);
2354 int ventoy_data_json_conf_replace(data_conf_replace
*data
, char *buf
, int buflen
)
2357 conf_replace_node
*node
= NULL
;
2359 VTOY_JSON_FMT_BEGIN(pos
, buf
, buflen
);
2360 VTOY_JSON_FMT_ARY_BEGIN();
2362 for (node
= data
->list
; node
; node
= node
->next
)
2364 VTOY_JSON_FMT_OBJ_BEGIN();
2366 VTOY_JSON_FMT_STRN("path", node
->path
);
2367 VTOY_JSON_FMT_SINT("valid", ventoy_check_fuzzy_path(node
->path
, 1));
2368 VTOY_JSON_FMT_STRN("org", node
->org
);
2369 VTOY_JSON_FMT_STRN("new", node
->new);
2370 VTOY_JSON_FMT_SINT("new_valid", ventoy_is_file_exist("%s%s", g_cur_dir
, node
->new));
2371 VTOY_JSON_FMT_SINT("img", node
->image
);
2373 VTOY_JSON_FMT_OBJ_ENDEX();
2376 VTOY_JSON_FMT_ARY_END();
2377 VTOY_JSON_FMT_END(pos
);
2382 static int ventoy_api_get_conf_replace(struct mg_connection
*conn
, VTOY_JSON
*json
)
2384 api_get_func(conn
, json
, conf_replace
);
2388 static int ventoy_api_save_conf_replace(struct mg_connection
*conn
, VTOY_JSON
*json
)
2391 ret
= ventoy_data_save_all();
2393 ventoy_json_result(conn
, ret
== 0 ? VTOY_JSON_SUCCESS_RET
: VTOY_JSON_FAILED_RET
);
2397 static int ventoy_api_conf_replace_add(struct mg_connection
*conn
, VTOY_JSON
*json
)
2402 const char *path
= NULL
;
2403 const char *org
= NULL
;
2404 const char *new = NULL
;
2405 conf_replace_node
*node
= NULL
;
2406 conf_replace_node
*cur
= NULL
;
2407 data_conf_replace
*data
= NULL
;
2409 vtoy_json_get_int(json
, "img", &image
);
2411 vtoy_json_get_int(json
, "index", &index
);
2412 data
= g_data_conf_replace
+ index
;
2414 path
= VTOY_JSON_STR_EX("path");
2415 org
= VTOY_JSON_STR_EX("org");
2416 new = VTOY_JSON_STR_EX("new");
2417 if (path
&& org
&& new)
2419 node
= zalloc(sizeof(conf_replace_node
));
2422 node
->image
= image
;
2423 scnprintf(node
->path
, sizeof(node
->path
), "%s", path
);
2424 scnprintf(node
->org
, sizeof(node
->org
), "%s", org
);
2425 scnprintf(node
->new, sizeof(node
->new), "%s", new);
2427 vtoy_list_add(data
->list
, cur
, node
);
2431 ret
= ventoy_data_save_all();
2433 ventoy_json_result(conn
, ret
== 0 ? VTOY_JSON_SUCCESS_RET
: VTOY_JSON_FAILED_RET
);
2437 static int ventoy_api_conf_replace_del(struct mg_connection
*conn
, VTOY_JSON
*json
)
2441 const char *path
= NULL
;
2442 conf_replace_node
*last
= NULL
;
2443 conf_replace_node
*node
= NULL
;
2444 data_conf_replace
*data
= NULL
;
2446 vtoy_json_get_int(json
, "index", &index
);
2447 data
= g_data_conf_replace
+ index
;
2449 path
= VTOY_JSON_STR_EX("path");
2452 if (strcmp(path
, VTOY_DEL_ALL_PATH
) == 0)
2454 vtoy_list_free(conf_replace_node
, data
->list
);
2458 vtoy_list_del(last
, node
, data
->list
, path
);
2462 ret
= ventoy_data_save_all();
2464 ventoy_json_result(conn
, ret
== 0 ? VTOY_JSON_SUCCESS_RET
: VTOY_JSON_FAILED_RET
);
2472 void ventoy_data_default_dud(data_dud
*data
)
2474 memset(data
, 0, sizeof(data_dud
));
2477 int ventoy_data_cmp_dud(data_dud
*data1
, data_dud
*data2
)
2479 dud_node
*list1
= NULL
;
2480 dud_node
*list2
= NULL
;
2482 if (NULL
== data1
->list
&& NULL
== data2
->list
)
2486 else if (data1
->list
&& data2
->list
)
2488 list1
= data1
->list
;
2489 list2
= data2
->list
;
2491 while (list1
&& list2
)
2493 if (strcmp(list1
->path
, list2
->path
))
2498 /* no need to compare dud list with default */
2499 list1
= list1
->next
;
2500 list2
= list2
->next
;
2503 if (list1
== NULL
&& list2
== NULL
)
2518 int ventoy_data_save_dud(data_dud
*data
, const char *title
, char *buf
, int buflen
)
2521 dud_node
*node
= NULL
;
2522 path_node
*pathnode
= NULL
;
2524 VTOY_JSON_FMT_BEGIN(pos
, buf
, buflen
);
2526 VTOY_JSON_FMT_KEY_L(L1
, title
);
2527 VTOY_JSON_FMT_ARY_BEGIN_N();
2529 for (node
= data
->list
; node
; node
= node
->next
)
2531 VTOY_JSON_FMT_OBJ_BEGIN_LN(L2
);
2532 VTOY_JSON_FMT_STRN_PATH_LN(L3
, "image", node
->path
);
2534 VTOY_JSON_FMT_KEY_L(L3
, "dud");
2535 VTOY_JSON_FMT_ARY_BEGIN_N();
2536 for (pathnode
= node
->list
; pathnode
; pathnode
= pathnode
->next
)
2538 VTOY_JSON_FMT_ITEM_PATH_LN(L4
, pathnode
->path
);
2540 VTOY_JSON_FMT_ARY_ENDEX_LN(L3
);
2542 VTOY_JSON_FMT_OBJ_ENDEX_LN(L2
);
2545 VTOY_JSON_FMT_ARY_ENDEX_LN(L1
);
2546 VTOY_JSON_FMT_END(pos
);
2552 int ventoy_data_json_dud(data_dud
*data
, char *buf
, int buflen
)
2556 dud_node
*node
= NULL
;
2557 path_node
*pathnode
= NULL
;
2559 VTOY_JSON_FMT_BEGIN(pos
, buf
, buflen
);
2560 VTOY_JSON_FMT_ARY_BEGIN();
2562 for (node
= data
->list
; node
; node
= node
->next
)
2564 VTOY_JSON_FMT_OBJ_BEGIN();
2566 VTOY_JSON_FMT_STRN("path", node
->path
);
2567 valid
= ventoy_check_fuzzy_path(node
->path
, 1);
2568 VTOY_JSON_FMT_SINT("valid", valid
);
2571 VTOY_JSON_FMT_KEY("list");
2572 VTOY_JSON_FMT_ARY_BEGIN();
2573 for (pathnode
= node
->list
; pathnode
; pathnode
= pathnode
->next
)
2575 VTOY_JSON_FMT_OBJ_BEGIN();
2576 VTOY_JSON_FMT_STRN("path", pathnode
->path
);
2578 valid
= ventoy_is_file_exist("%s%s", g_cur_dir
, pathnode
->path
);
2579 VTOY_JSON_FMT_SINT("valid", valid
);
2580 VTOY_JSON_FMT_OBJ_ENDEX();
2582 VTOY_JSON_FMT_ARY_ENDEX();
2585 VTOY_JSON_FMT_OBJ_ENDEX();
2588 VTOY_JSON_FMT_ARY_END();
2589 VTOY_JSON_FMT_END(pos
);
2594 static int ventoy_api_get_dud(struct mg_connection
*conn
, VTOY_JSON
*json
)
2596 api_get_func(conn
, json
, dud
);
2600 static int ventoy_api_save_dud(struct mg_connection
*conn
, VTOY_JSON
*json
)
2603 ret
= ventoy_data_save_all();
2605 ventoy_json_result(conn
, ret
== 0 ? VTOY_JSON_SUCCESS_RET
: VTOY_JSON_FAILED_RET
);
2610 static int ventoy_api_dud_add(struct mg_connection
*conn
, VTOY_JSON
*json
)
2614 const char *path
= NULL
;
2615 dud_node
*node
= NULL
;
2616 dud_node
*cur
= NULL
;
2617 data_dud
*data
= NULL
;
2618 VTOY_JSON
*array
= NULL
;
2620 vtoy_json_get_int(json
, "index", &index
);
2621 data
= g_data_dud
+ index
;
2623 array
= vtoy_json_find_item(json
, JSON_TYPE_ARRAY
, "dud");
2624 path
= VTOY_JSON_STR_EX("path");
2627 node
= zalloc(sizeof(dud_node
));
2630 scnprintf(node
->path
, sizeof(node
->path
), "%s", path
);
2631 node
->list
= ventoy_path_node_add_array(array
);
2633 vtoy_list_add(data
->list
, cur
, node
);
2637 ret
= ventoy_data_save_all();
2639 ventoy_json_result(conn
, ret
== 0 ? VTOY_JSON_SUCCESS_RET
: VTOY_JSON_FAILED_RET
);
2643 static int ventoy_api_dud_del(struct mg_connection
*conn
, VTOY_JSON
*json
)
2647 const char *path
= NULL
;
2648 dud_node
*next
= NULL
;
2649 dud_node
*last
= NULL
;
2650 dud_node
*node
= NULL
;
2651 data_dud
*data
= NULL
;
2653 vtoy_json_get_int(json
, "index", &index
);
2654 data
= g_data_dud
+ index
;
2656 path
= VTOY_JSON_STR_EX("path");
2659 if (strcmp(path
, VTOY_DEL_ALL_PATH
) == 0)
2661 for (node
= data
->list
; node
; node
= next
)
2664 ventoy_free_path_node_list(node
->list
);
2671 vtoy_list_del_ex(last
, node
, data
->list
, path
, ventoy_free_path_node_list
);
2675 ret
= ventoy_data_save_all();
2677 ventoy_json_result(conn
, ret
== 0 ? VTOY_JSON_SUCCESS_RET
: VTOY_JSON_FAILED_RET
);
2682 static int ventoy_api_dud_add_inner(struct mg_connection
*conn
, VTOY_JSON
*json
)
2686 const char *path
= NULL
;
2687 const char *outpath
= NULL
;
2688 path_node
*pcur
= NULL
;
2689 path_node
*pnode
= NULL
;
2690 dud_node
*node
= NULL
;
2691 data_dud
*data
= NULL
;
2693 vtoy_json_get_int(json
, "index", &index
);
2694 data
= g_data_dud
+ index
;
2696 path
= VTOY_JSON_STR_EX("path");
2697 outpath
= VTOY_JSON_STR_EX("outpath");
2698 if (path
&& outpath
)
2700 for (node
= data
->list
; node
; node
= node
->next
)
2702 if (strcmp(outpath
, node
->path
) == 0)
2704 pnode
= zalloc(sizeof(path_node
));
2707 scnprintf(pnode
->path
, sizeof(pnode
->path
), "%s", path
);
2708 vtoy_list_add(node
->list
, pcur
, pnode
);
2716 ret
= ventoy_data_save_all();
2718 ventoy_json_result(conn
, ret
== 0 ? VTOY_JSON_SUCCESS_RET
: VTOY_JSON_FAILED_RET
);
2722 static int ventoy_api_dud_del_inner(struct mg_connection
*conn
, VTOY_JSON
*json
)
2726 const char *path
= NULL
;
2727 const char *outpath
= NULL
;
2728 path_node
*plast
= NULL
;
2729 path_node
*pnode
= NULL
;
2730 dud_node
*node
= NULL
;
2731 data_dud
*data
= NULL
;
2733 vtoy_json_get_int(json
, "index", &index
);
2734 data
= g_data_dud
+ index
;
2736 path
= VTOY_JSON_STR_EX("path");
2737 outpath
= VTOY_JSON_STR_EX("outpath");
2738 if (path
&& outpath
)
2740 for (node
= data
->list
; node
; node
= node
->next
)
2742 if (strcmp(outpath
, node
->path
) == 0)
2744 vtoy_list_del(plast
, pnode
, node
->list
, path
);
2750 ret
= ventoy_data_save_all();
2752 ventoy_json_result(conn
, ret
== 0 ? VTOY_JSON_SUCCESS_RET
: VTOY_JSON_FAILED_RET
);
2760 void ventoy_data_default_auto_install(data_auto_install
*data
)
2762 memset(data
, 0, sizeof(data_auto_install
));
2765 int ventoy_data_cmp_auto_install(data_auto_install
*data1
, data_auto_install
*data2
)
2767 auto_install_node
*list1
= NULL
;
2768 auto_install_node
*list2
= NULL
;
2770 if (NULL
== data1
->list
&& NULL
== data2
->list
)
2774 else if (data1
->list
&& data2
->list
)
2776 list1
= data1
->list
;
2777 list2
= data2
->list
;
2779 while (list1
&& list2
)
2781 if (list1
->timeout
!= list2
->timeout
||
2782 list1
->autosel
!= list2
->autosel
||
2783 strcmp(list1
->path
, list2
->path
))
2788 /* no need to compare auto install list with default */
2789 list1
= list1
->next
;
2790 list2
= list2
->next
;
2793 if (list1
== NULL
&& list2
== NULL
)
2808 int ventoy_data_save_auto_install(data_auto_install
*data
, const char *title
, char *buf
, int buflen
)
2811 auto_install_node
*node
= NULL
;
2812 path_node
*pathnode
= NULL
;
2814 VTOY_JSON_FMT_BEGIN(pos
, buf
, buflen
);
2816 VTOY_JSON_FMT_KEY_L(L1
, title
);
2817 VTOY_JSON_FMT_ARY_BEGIN_N();
2819 for (node
= data
->list
; node
; node
= node
->next
)
2821 VTOY_JSON_FMT_OBJ_BEGIN_LN(L2
);
2822 if (node
->type
== 0)
2824 VTOY_JSON_FMT_STRN_PATH_LN(L3
, "image", node
->path
);
2828 VTOY_JSON_FMT_STRN_PATH_LN(L3
, "parent", node
->path
);
2832 VTOY_JSON_FMT_KEY_L(L3
, "template");
2833 VTOY_JSON_FMT_ARY_BEGIN_N();
2834 for (pathnode
= node
->list
; pathnode
; pathnode
= pathnode
->next
)
2836 VTOY_JSON_FMT_ITEM_PATH_LN(L4
, pathnode
->path
);
2838 VTOY_JSON_FMT_ARY_ENDEX_LN(L3
);
2840 if (node
->timeouten
)
2842 VTOY_JSON_FMT_SINT_LN(L3
, "timeout", node
->timeout
);
2845 if (node
->autoselen
)
2847 VTOY_JSON_FMT_SINT_LN(L3
, "autosel", node
->autosel
);
2850 VTOY_JSON_FMT_OBJ_ENDEX_LN(L2
);
2853 VTOY_JSON_FMT_ARY_ENDEX_LN(L1
);
2854 VTOY_JSON_FMT_END(pos
);
2860 int ventoy_data_json_auto_install(data_auto_install
*data
, char *buf
, int buflen
)
2864 auto_install_node
*node
= NULL
;
2865 path_node
*pathnode
= NULL
;
2867 VTOY_JSON_FMT_BEGIN(pos
, buf
, buflen
);
2868 VTOY_JSON_FMT_ARY_BEGIN();
2870 for (node
= data
->list
; node
; node
= node
->next
)
2872 VTOY_JSON_FMT_OBJ_BEGIN();
2874 VTOY_JSON_FMT_STRN("path", node
->path
);
2876 if (node
->type
== 0)
2878 valid
= ventoy_check_fuzzy_path(node
->path
, 1);
2882 valid
= ventoy_is_directory_exist("%s%s", g_cur_dir
, node
->path
);
2884 VTOY_JSON_FMT_SINT("valid", valid
);
2885 VTOY_JSON_FMT_SINT("type", node
->type
);
2887 VTOY_JSON_FMT_BOOL("timeouten", node
->timeouten
);
2888 VTOY_JSON_FMT_BOOL("autoselen", node
->autoselen
);
2890 VTOY_JSON_FMT_SINT("autosel", node
->autosel
);
2891 VTOY_JSON_FMT_SINT("timeout", node
->timeout
);
2893 VTOY_JSON_FMT_KEY("list");
2894 VTOY_JSON_FMT_ARY_BEGIN();
2895 for (pathnode
= node
->list
; pathnode
; pathnode
= pathnode
->next
)
2897 VTOY_JSON_FMT_OBJ_BEGIN();
2898 VTOY_JSON_FMT_STRN("path", pathnode
->path
);
2900 valid
= ventoy_is_file_exist("%s%s", g_cur_dir
, pathnode
->path
);
2901 VTOY_JSON_FMT_SINT("valid", valid
);
2902 VTOY_JSON_FMT_OBJ_ENDEX();
2904 VTOY_JSON_FMT_ARY_ENDEX();
2907 VTOY_JSON_FMT_OBJ_ENDEX();
2910 VTOY_JSON_FMT_ARY_END();
2911 VTOY_JSON_FMT_END(pos
);
2916 static int ventoy_api_get_auto_install(struct mg_connection
*conn
, VTOY_JSON
*json
)
2918 api_get_func(conn
, json
, auto_install
);
2922 static int ventoy_api_save_auto_install(struct mg_connection
*conn
, VTOY_JSON
*json
)
2928 uint8_t timeouten
= 0;
2929 uint8_t autoselen
= 0;
2930 auto_install_node
*node
= NULL
;
2931 data_auto_install
*data
= NULL
;
2933 vtoy_json_get_int(json
, "index", &index
);
2934 vtoy_json_get_int(json
, "id", &id
);
2936 vtoy_json_get_bool(json
, "timeouten", &timeouten
);
2937 vtoy_json_get_bool(json
, "autoselen", &autoselen
);
2939 data
= g_data_auto_install
+ index
;
2943 for (node
= data
->list
; node
; node
= node
->next
)
2947 node
->timeouten
= (int)timeouten
;
2948 node
->autoselen
= (int)autoselen
;
2949 VTOY_JSON_INT("timeout", node
->timeout
);
2950 VTOY_JSON_INT("autosel", node
->autosel
);
2956 ret
= ventoy_data_save_all();
2958 ventoy_json_result(conn
, ret
== 0 ? VTOY_JSON_SUCCESS_RET
: VTOY_JSON_FAILED_RET
);
2963 static int ventoy_api_auto_install_add(struct mg_connection
*conn
, VTOY_JSON
*json
)
2968 const char *path
= NULL
;
2969 auto_install_node
*node
= NULL
;
2970 auto_install_node
*cur
= NULL
;
2971 data_auto_install
*data
= NULL
;
2972 VTOY_JSON
*array
= NULL
;
2974 vtoy_json_get_int(json
, "type", &type
);
2975 vtoy_json_get_int(json
, "index", &index
);
2976 data
= g_data_auto_install
+ index
;
2978 array
= vtoy_json_find_item(json
, JSON_TYPE_ARRAY
, "template");
2979 path
= VTOY_JSON_STR_EX("path");
2982 node
= zalloc(sizeof(auto_install_node
));
2986 node
->timeouten
= 0;
2987 node
->autoselen
= 0;
2990 scnprintf(node
->path
, sizeof(node
->path
), "%s", path
);
2991 node
->list
= ventoy_path_node_add_array(array
);
2993 vtoy_list_add(data
->list
, cur
, node
);
2997 ret
= ventoy_data_save_all();
2999 ventoy_json_result(conn
, ret
== 0 ? VTOY_JSON_SUCCESS_RET
: VTOY_JSON_FAILED_RET
);
3003 static int ventoy_api_auto_install_del(struct mg_connection
*conn
, VTOY_JSON
*json
)
3007 const char *path
= NULL
;
3008 auto_install_node
*last
= NULL
;
3009 auto_install_node
*next
= NULL
;
3010 auto_install_node
*node
= NULL
;
3011 data_auto_install
*data
= NULL
;
3013 vtoy_json_get_int(json
, "index", &index
);
3014 data
= g_data_auto_install
+ index
;
3016 path
= VTOY_JSON_STR_EX("path");
3019 if (strcmp(path
, VTOY_DEL_ALL_PATH
) == 0)
3021 for (node
= data
->list
; node
; node
= next
)
3024 ventoy_free_path_node_list(node
->list
);
3031 vtoy_list_del_ex(last
, node
, data
->list
, path
, ventoy_free_path_node_list
);
3035 ret
= ventoy_data_save_all();
3037 ventoy_json_result(conn
, ret
== 0 ? VTOY_JSON_SUCCESS_RET
: VTOY_JSON_FAILED_RET
);
3041 static int ventoy_api_auto_install_add_inner(struct mg_connection
*conn
, VTOY_JSON
*json
)
3045 const char *path
= NULL
;
3046 const char *outpath
= NULL
;
3047 path_node
*pcur
= NULL
;
3048 path_node
*pnode
= NULL
;
3049 auto_install_node
*node
= NULL
;
3050 data_auto_install
*data
= NULL
;
3052 vtoy_json_get_int(json
, "index", &index
);
3053 data
= g_data_auto_install
+ index
;
3055 path
= VTOY_JSON_STR_EX("path");
3056 outpath
= VTOY_JSON_STR_EX("outpath");
3057 if (path
&& outpath
)
3059 for (node
= data
->list
; node
; node
= node
->next
)
3061 if (strcmp(outpath
, node
->path
) == 0)
3063 pnode
= zalloc(sizeof(path_node
));
3066 scnprintf(pnode
->path
, sizeof(pnode
->path
), "%s", path
);
3067 vtoy_list_add(node
->list
, pcur
, pnode
);
3075 ret
= ventoy_data_save_all();
3077 ventoy_json_result(conn
, ret
== 0 ? VTOY_JSON_SUCCESS_RET
: VTOY_JSON_FAILED_RET
);
3081 static int ventoy_api_auto_install_del_inner(struct mg_connection
*conn
, VTOY_JSON
*json
)
3085 const char *path
= NULL
;
3086 const char *outpath
= NULL
;
3087 path_node
*plast
= NULL
;
3088 path_node
*pnode
= NULL
;
3089 auto_install_node
*node
= NULL
;
3090 data_auto_install
*data
= NULL
;
3092 vtoy_json_get_int(json
, "index", &index
);
3093 data
= g_data_auto_install
+ index
;
3095 path
= VTOY_JSON_STR_EX("path");
3096 outpath
= VTOY_JSON_STR_EX("outpath");
3097 if (path
&& outpath
)
3099 for (node
= data
->list
; node
; node
= node
->next
)
3101 if (strcmp(outpath
, node
->path
) == 0)
3103 vtoy_list_del(plast
, pnode
, node
->list
, path
);
3109 ret
= ventoy_data_save_all();
3111 ventoy_json_result(conn
, ret
== 0 ? VTOY_JSON_SUCCESS_RET
: VTOY_JSON_FAILED_RET
);
3120 void ventoy_data_default_persistence(data_persistence
*data
)
3122 memset(data
, 0, sizeof(data_persistence
));
3125 int ventoy_data_cmp_persistence(data_persistence
*data1
, data_persistence
*data2
)
3127 persistence_node
*list1
= NULL
;
3128 persistence_node
*list2
= NULL
;
3130 if (NULL
== data1
->list
&& NULL
== data2
->list
)
3134 else if (data1
->list
&& data2
->list
)
3136 list1
= data1
->list
;
3137 list2
= data2
->list
;
3139 while (list1
&& list2
)
3141 if (list1
->timeout
!= list2
->timeout
||
3142 list1
->autosel
!= list2
->autosel
||
3143 strcmp(list1
->path
, list2
->path
))
3148 /* no need to compare auto install list with default */
3149 list1
= list1
->next
;
3150 list2
= list2
->next
;
3153 if (list1
== NULL
&& list2
== NULL
)
3168 int ventoy_data_save_persistence(data_persistence
*data
, const char *title
, char *buf
, int buflen
)
3171 persistence_node
*node
= NULL
;
3172 path_node
*pathnode
= NULL
;
3174 VTOY_JSON_FMT_BEGIN(pos
, buf
, buflen
);
3176 VTOY_JSON_FMT_KEY_L(L1
, title
);
3177 VTOY_JSON_FMT_ARY_BEGIN_N();
3179 for (node
= data
->list
; node
; node
= node
->next
)
3181 VTOY_JSON_FMT_OBJ_BEGIN_LN(L2
);
3182 VTOY_JSON_FMT_STRN_PATH_LN(L3
, "image", node
->path
);
3183 VTOY_JSON_FMT_KEY_L(L3
, "backend");
3184 VTOY_JSON_FMT_ARY_BEGIN_N();
3185 for (pathnode
= node
->list
; pathnode
; pathnode
= pathnode
->next
)
3187 VTOY_JSON_FMT_ITEM_PATH_LN(L4
, pathnode
->path
);
3189 VTOY_JSON_FMT_ARY_ENDEX_LN(L3
);
3191 if (node
->timeouten
)
3193 VTOY_JSON_FMT_SINT_LN(L3
, "timeout", node
->timeout
);
3196 if (node
->autoselen
)
3198 VTOY_JSON_FMT_SINT_LN(L3
, "autosel", node
->autosel
);
3201 VTOY_JSON_FMT_OBJ_ENDEX_LN(L2
);
3204 VTOY_JSON_FMT_ARY_ENDEX_LN(L1
);
3205 VTOY_JSON_FMT_END(pos
);
3211 int ventoy_data_json_persistence(data_persistence
*data
, char *buf
, int buflen
)
3215 persistence_node
*node
= NULL
;
3216 path_node
*pathnode
= NULL
;
3218 VTOY_JSON_FMT_BEGIN(pos
, buf
, buflen
);
3219 VTOY_JSON_FMT_ARY_BEGIN();
3221 for (node
= data
->list
; node
; node
= node
->next
)
3223 VTOY_JSON_FMT_OBJ_BEGIN();
3225 VTOY_JSON_FMT_STRN("path", node
->path
);
3227 valid
= ventoy_check_fuzzy_path(node
->path
, 1);
3228 VTOY_JSON_FMT_SINT("valid", valid
);
3229 VTOY_JSON_FMT_SINT("type", node
->type
);
3231 VTOY_JSON_FMT_BOOL("timeouten", node
->timeouten
);
3232 VTOY_JSON_FMT_BOOL("autoselen", node
->autoselen
);
3234 VTOY_JSON_FMT_SINT("autosel", node
->autosel
);
3235 VTOY_JSON_FMT_SINT("timeout", node
->timeout
);
3237 VTOY_JSON_FMT_KEY("list");
3238 VTOY_JSON_FMT_ARY_BEGIN();
3239 for (pathnode
= node
->list
; pathnode
; pathnode
= pathnode
->next
)
3241 VTOY_JSON_FMT_OBJ_BEGIN();
3242 VTOY_JSON_FMT_STRN("path", pathnode
->path
);
3244 valid
= ventoy_is_file_exist("%s%s", g_cur_dir
, pathnode
->path
);
3245 VTOY_JSON_FMT_SINT("valid", valid
);
3246 VTOY_JSON_FMT_OBJ_ENDEX();
3248 VTOY_JSON_FMT_ARY_ENDEX();
3251 VTOY_JSON_FMT_OBJ_ENDEX();
3254 VTOY_JSON_FMT_ARY_END();
3255 VTOY_JSON_FMT_END(pos
);
3260 static int ventoy_api_get_persistence(struct mg_connection
*conn
, VTOY_JSON
*json
)
3262 api_get_func(conn
, json
, persistence
);
3266 static int ventoy_api_save_persistence(struct mg_connection
*conn
, VTOY_JSON
*json
)
3272 uint8_t timeouten
= 0;
3273 uint8_t autoselen
= 0;
3274 persistence_node
*node
= NULL
;
3275 data_persistence
*data
= NULL
;
3277 vtoy_json_get_int(json
, "index", &index
);
3278 vtoy_json_get_int(json
, "id", &id
);
3280 vtoy_json_get_bool(json
, "timeouten", &timeouten
);
3281 vtoy_json_get_bool(json
, "autoselen", &autoselen
);
3283 data
= g_data_persistence
+ index
;
3287 for (node
= data
->list
; node
; node
= node
->next
)
3291 node
->timeouten
= (int)timeouten
;
3292 node
->autoselen
= (int)autoselen
;
3293 VTOY_JSON_INT("timeout", node
->timeout
);
3294 VTOY_JSON_INT("autosel", node
->autosel
);
3300 ret
= ventoy_data_save_all();
3302 ventoy_json_result(conn
, ret
== 0 ? VTOY_JSON_SUCCESS_RET
: VTOY_JSON_FAILED_RET
);
3307 static int ventoy_api_persistence_add(struct mg_connection
*conn
, VTOY_JSON
*json
)
3311 const char *path
= NULL
;
3312 persistence_node
*node
= NULL
;
3313 persistence_node
*cur
= NULL
;
3314 data_persistence
*data
= NULL
;
3315 VTOY_JSON
*array
= NULL
;
3317 vtoy_json_get_int(json
, "index", &index
);
3318 data
= g_data_persistence
+ index
;
3320 array
= vtoy_json_find_item(json
, JSON_TYPE_ARRAY
, "backend");
3321 path
= VTOY_JSON_STR_EX("path");
3324 node
= zalloc(sizeof(persistence_node
));
3327 node
->timeouten
= 0;
3328 node
->autoselen
= 0;
3331 scnprintf(node
->path
, sizeof(node
->path
), "%s", path
);
3332 node
->list
= ventoy_path_node_add_array(array
);
3334 vtoy_list_add(data
->list
, cur
, node
);
3338 ret
= ventoy_data_save_all();
3340 ventoy_json_result(conn
, ret
== 0 ? VTOY_JSON_SUCCESS_RET
: VTOY_JSON_FAILED_RET
);
3344 static int ventoy_api_persistence_del(struct mg_connection
*conn
, VTOY_JSON
*json
)
3348 const char *path
= NULL
;
3349 persistence_node
*last
= NULL
;
3350 persistence_node
*next
= NULL
;
3351 persistence_node
*node
= NULL
;
3352 data_persistence
*data
= NULL
;
3354 vtoy_json_get_int(json
, "index", &index
);
3355 data
= g_data_persistence
+ index
;
3357 path
= VTOY_JSON_STR_EX("path");
3360 if (strcmp(path
, VTOY_DEL_ALL_PATH
) == 0)
3362 for (node
= data
->list
; node
; node
= next
)
3365 ventoy_free_path_node_list(node
->list
);
3372 vtoy_list_del_ex(last
, node
, data
->list
, path
, ventoy_free_path_node_list
);
3376 ret
= ventoy_data_save_all();
3378 ventoy_json_result(conn
, ret
== 0 ? VTOY_JSON_SUCCESS_RET
: VTOY_JSON_FAILED_RET
);
3382 static int ventoy_api_persistence_add_inner(struct mg_connection
*conn
, VTOY_JSON
*json
)
3386 const char *path
= NULL
;
3387 const char *outpath
= NULL
;
3388 path_node
*pcur
= NULL
;
3389 path_node
*pnode
= NULL
;
3390 persistence_node
*node
= NULL
;
3391 data_persistence
*data
= NULL
;
3393 vtoy_json_get_int(json
, "index", &index
);
3394 data
= g_data_persistence
+ index
;
3396 path
= VTOY_JSON_STR_EX("path");
3397 outpath
= VTOY_JSON_STR_EX("outpath");
3398 if (path
&& outpath
)
3400 for (node
= data
->list
; node
; node
= node
->next
)
3402 if (strcmp(outpath
, node
->path
) == 0)
3404 pnode
= zalloc(sizeof(path_node
));
3407 scnprintf(pnode
->path
, sizeof(pnode
->path
), "%s", path
);
3408 vtoy_list_add(node
->list
, pcur
, pnode
);
3416 ret
= ventoy_data_save_all();
3418 ventoy_json_result(conn
, ret
== 0 ? VTOY_JSON_SUCCESS_RET
: VTOY_JSON_FAILED_RET
);
3422 static int ventoy_api_persistence_del_inner(struct mg_connection
*conn
, VTOY_JSON
*json
)
3426 const char *path
= NULL
;
3427 const char *outpath
= NULL
;
3428 path_node
*plast
= NULL
;
3429 path_node
*pnode
= NULL
;
3430 persistence_node
*node
= NULL
;
3431 data_persistence
*data
= NULL
;
3433 vtoy_json_get_int(json
, "index", &index
);
3434 data
= g_data_persistence
+ index
;
3436 path
= VTOY_JSON_STR_EX("path");
3437 outpath
= VTOY_JSON_STR_EX("outpath");
3438 if (path
&& outpath
)
3440 for (node
= data
->list
; node
; node
= node
->next
)
3442 if (strcmp(outpath
, node
->path
) == 0)
3444 vtoy_list_del(plast
, pnode
, node
->list
, path
);
3450 ret
= ventoy_data_save_all();
3452 ventoy_json_result(conn
, ret
== 0 ? VTOY_JSON_SUCCESS_RET
: VTOY_JSON_FAILED_RET
);
3460 void ventoy_data_default_injection(data_injection
*data
)
3462 memset(data
, 0, sizeof(data_injection
));
3465 int ventoy_data_cmp_injection(data_injection
*data1
, data_injection
*data2
)
3467 injection_node
*list1
= NULL
;
3468 injection_node
*list2
= NULL
;
3470 if (NULL
== data1
->list
&& NULL
== data2
->list
)
3474 else if (data1
->list
&& data2
->list
)
3476 list1
= data1
->list
;
3477 list2
= data2
->list
;
3479 while (list1
&& list2
)
3481 if ((list1
->type
!= list2
->type
) ||
3482 strcmp(list1
->path
, list2
->path
) ||
3483 strcmp(list1
->archive
, list2
->archive
))
3488 list1
= list1
->next
;
3489 list2
= list2
->next
;
3492 if (list1
== NULL
&& list2
== NULL
)
3507 int ventoy_data_save_injection(data_injection
*data
, const char *title
, char *buf
, int buflen
)
3510 injection_node
*node
= NULL
;
3512 VTOY_JSON_FMT_BEGIN(pos
, buf
, buflen
);
3514 VTOY_JSON_FMT_KEY_L(L1
, title
);
3515 VTOY_JSON_FMT_ARY_BEGIN_N();
3517 for (node
= data
->list
; node
; node
= node
->next
)
3519 VTOY_JSON_FMT_OBJ_BEGIN_LN(L2
);
3521 if (node
->type
== 0)
3523 VTOY_JSON_FMT_STRN_PATH_LN(L3
, "image", node
->path
);
3527 VTOY_JSON_FMT_STRN_PATH_LN(L3
, "parent", node
->path
);
3529 VTOY_JSON_FMT_STRN_PATH_LN(L3
, "archive", node
->archive
);
3531 VTOY_JSON_FMT_OBJ_ENDEX_LN(L2
);
3534 VTOY_JSON_FMT_ARY_ENDEX_LN(L1
);
3535 VTOY_JSON_FMT_END(pos
);
3541 int ventoy_data_json_injection(data_injection
*data
, char *buf
, int buflen
)
3545 injection_node
*node
= NULL
;
3547 VTOY_JSON_FMT_BEGIN(pos
, buf
, buflen
);
3548 VTOY_JSON_FMT_ARY_BEGIN();
3550 for (node
= data
->list
; node
; node
= node
->next
)
3552 VTOY_JSON_FMT_OBJ_BEGIN();
3554 VTOY_JSON_FMT_UINT("type", node
->type
);
3555 VTOY_JSON_FMT_STRN("path", node
->path
);
3557 if (node
->type
== 0)
3559 valid
= ventoy_check_fuzzy_path(node
->path
, 1);
3563 valid
= ventoy_is_directory_exist("%s%s", g_cur_dir
, node
->path
);
3565 VTOY_JSON_FMT_SINT("valid", valid
);
3567 VTOY_JSON_FMT_STRN("archive", node
->archive
);
3569 valid
= ventoy_is_file_exist("%s%s", g_cur_dir
, node
->archive
);
3570 VTOY_JSON_FMT_SINT("archive_valid", valid
);
3572 VTOY_JSON_FMT_OBJ_ENDEX();
3575 VTOY_JSON_FMT_ARY_END();
3576 VTOY_JSON_FMT_END(pos
);
3582 static int ventoy_api_get_injection(struct mg_connection
*conn
, VTOY_JSON
*json
)
3584 api_get_func(conn
, json
, injection
);
3588 static int ventoy_api_save_injection(struct mg_connection
*conn
, VTOY_JSON
*json
)
3591 ret
= ventoy_data_save_all();
3593 ventoy_json_result(conn
, ret
== 0 ? VTOY_JSON_SUCCESS_RET
: VTOY_JSON_FAILED_RET
);
3597 static int ventoy_api_injection_add(struct mg_connection
*conn
, VTOY_JSON
*json
)
3602 const char *path
= NULL
;
3603 const char *archive
= NULL
;
3604 injection_node
*node
= NULL
;
3605 injection_node
*cur
= NULL
;
3606 data_injection
*data
= NULL
;
3608 vtoy_json_get_int(json
, "index", &index
);
3609 data
= g_data_injection
+ index
;
3611 vtoy_json_get_int(json
, "type", &type
);
3613 path
= VTOY_JSON_STR_EX("path");
3614 archive
= VTOY_JSON_STR_EX("archive");
3615 if (path
&& archive
)
3617 node
= zalloc(sizeof(injection_node
));
3622 scnprintf(node
->path
, sizeof(node
->path
), "%s", path
);
3623 scnprintf(node
->archive
, sizeof(node
->archive
), "%s", archive
);
3625 vtoy_list_add(data
->list
, cur
, node
);
3629 ret
= ventoy_data_save_all();
3631 ventoy_json_result(conn
, ret
== 0 ? VTOY_JSON_SUCCESS_RET
: VTOY_JSON_FAILED_RET
);
3635 static int ventoy_api_injection_del(struct mg_connection
*conn
, VTOY_JSON
*json
)
3639 const char *path
= NULL
;
3640 injection_node
*last
= NULL
;
3641 injection_node
*node
= NULL
;
3642 data_injection
*data
= NULL
;
3644 vtoy_json_get_int(json
, "index", &index
);
3645 data
= g_data_injection
+ index
;
3647 path
= VTOY_JSON_STR_EX("path");
3650 if (strcmp(path
, VTOY_DEL_ALL_PATH
) == 0)
3652 vtoy_list_free(injection_node
, data
->list
);
3656 vtoy_list_del(last
, node
, data
->list
, path
);
3660 ret
= ventoy_data_save_all();
3662 ventoy_json_result(conn
, ret
== 0 ? VTOY_JSON_SUCCESS_RET
: VTOY_JSON_FAILED_RET
);
3669 static int ventoy_api_preview_json(struct mg_connection
*conn
, VTOY_JSON
*json
)
3674 char *encodebuf
= NULL
;
3678 len
= ventoy_data_real_save_all(0);
3679 encodebuf
= ventoy_base64_encode(JSON_SAVE_BUFFER
, len
, &encodelen
);
3680 encodebuf
[encodelen
] = 0;
3682 VTOY_JSON_FMT_BEGIN(pos
, JSON_BUFFER
, JSON_BUF_MAX
);
3683 VTOY_JSON_FMT_OBJ_BEGIN();
3684 VTOY_JSON_FMT_STRN("json", encodebuf
);
3685 VTOY_JSON_FMT_OBJ_END();
3686 VTOY_JSON_FMT_END(pos
);
3690 ventoy_json_buffer(conn
, JSON_BUFFER
, pos
);
3698 int ventoy_data_save_all(void)
3700 ventoy_set_writeback_event();
3704 int ventoy_data_real_save_all(int apilock
)
3712 pthread_mutex_lock(&g_api_mutex
);
3715 ssprintf(pos
, JSON_SAVE_BUFFER
, JSON_BUF_MAX
, "{\n");
3717 ventoy_save_plug(control
);
3718 ventoy_save_plug(theme
);
3719 ventoy_save_plug(menu_alias
);
3720 ventoy_save_plug(menu_tip
);
3721 ventoy_save_plug(menu_class
);
3722 ventoy_save_plug(auto_install
);
3723 ventoy_save_plug(persistence
);
3724 ventoy_save_plug(injection
);
3725 ventoy_save_plug(conf_replace
);
3726 ventoy_save_plug(password
);
3727 ventoy_save_plug(image_list
);
3728 ventoy_save_plug(auto_memdisk
);
3729 ventoy_save_plug(dud
);
3731 if (JSON_SAVE_BUFFER
[pos
- 1] == '\n' && JSON_SAVE_BUFFER
[pos
- 2] == ',')
3733 JSON_SAVE_BUFFER
[pos
- 2] = '\n';
3736 ssprintf(pos
, JSON_SAVE_BUFFER
, JSON_BUF_MAX
, "}\n");
3740 pthread_mutex_unlock(&g_api_mutex
);
3746 int ventoy_http_writeback(void)
3752 ventoy_get_json_path(filename
, NULL
);
3754 pos
= ventoy_data_real_save_all(1);
3757 printf("%s", JSON_SAVE_BUFFER
);
3760 ret
= ventoy_write_buf_to_file(filename
, JSON_SAVE_BUFFER
, pos
);
3763 vlog("Failed to write ventoy.json file.\n");
3764 g_sysinfo
.config_save_error
= 1;
3771 static JSON_CB g_ventoy_json_cb
[] =
3773 { "sysinfo", ventoy_api_sysinfo
},
3774 { "handshake", ventoy_api_handshake
},
3775 { "check_path", ventoy_api_check_exist
},
3776 { "check_path2", ventoy_api_check_exist2
},
3777 { "check_fuzzy", ventoy_api_check_fuzzy
},
3779 { "device_info", ventoy_api_device_info
},
3781 { "get_control", ventoy_api_get_control
},
3782 { "save_control", ventoy_api_save_control
},
3784 { "get_theme", ventoy_api_get_theme
},
3785 { "save_theme", ventoy_api_save_theme
},
3786 { "theme_add_file", ventoy_api_theme_add_file
},
3787 { "theme_del_file", ventoy_api_theme_del_file
},
3788 { "theme_add_font", ventoy_api_theme_add_font
},
3789 { "theme_del_font", ventoy_api_theme_del_font
},
3791 { "get_alias", ventoy_api_get_alias
},
3792 { "save_alias", ventoy_api_save_alias
},
3793 { "alias_add", ventoy_api_alias_add
},
3794 { "alias_del", ventoy_api_alias_del
},
3796 { "get_tip", ventoy_api_get_tip
},
3797 { "save_tip", ventoy_api_save_tip
},
3798 { "tip_add", ventoy_api_tip_add
},
3799 { "tip_del", ventoy_api_tip_del
},
3801 { "get_class", ventoy_api_get_class
},
3802 { "save_class", ventoy_api_save_class
},
3803 { "class_add", ventoy_api_class_add
},
3804 { "class_del", ventoy_api_class_del
},
3806 { "get_auto_memdisk", ventoy_api_get_auto_memdisk
},
3807 { "save_auto_memdisk", ventoy_api_save_auto_memdisk
},
3808 { "auto_memdisk_add", ventoy_api_auto_memdisk_add
},
3809 { "auto_memdisk_del", ventoy_api_auto_memdisk_del
},
3811 { "get_image_list", ventoy_api_get_image_list
},
3812 { "save_image_list", ventoy_api_save_image_list
},
3813 { "image_list_add", ventoy_api_image_list_add
},
3814 { "image_list_del", ventoy_api_image_list_del
},
3816 { "get_conf_replace", ventoy_api_get_conf_replace
},
3817 { "save_conf_replace", ventoy_api_save_conf_replace
},
3818 { "conf_replace_add", ventoy_api_conf_replace_add
},
3819 { "conf_replace_del", ventoy_api_conf_replace_del
},
3821 { "get_dud", ventoy_api_get_dud
},
3822 { "save_dud", ventoy_api_save_dud
},
3823 { "dud_add", ventoy_api_dud_add
},
3824 { "dud_del", ventoy_api_dud_del
},
3825 { "dud_add_inner", ventoy_api_dud_add_inner
},
3826 { "dud_del_inner", ventoy_api_dud_del_inner
},
3828 { "get_auto_install", ventoy_api_get_auto_install
},
3829 { "save_auto_install", ventoy_api_save_auto_install
},
3830 { "auto_install_add", ventoy_api_auto_install_add
},
3831 { "auto_install_del", ventoy_api_auto_install_del
},
3832 { "auto_install_add_inner", ventoy_api_auto_install_add_inner
},
3833 { "auto_install_del_inner", ventoy_api_auto_install_del_inner
},
3835 { "get_persistence", ventoy_api_get_persistence
},
3836 { "save_persistence", ventoy_api_save_persistence
},
3837 { "persistence_add", ventoy_api_persistence_add
},
3838 { "persistence_del", ventoy_api_persistence_del
},
3839 { "persistence_add_inner", ventoy_api_persistence_add_inner
},
3840 { "persistence_del_inner", ventoy_api_persistence_del_inner
},
3842 { "get_password", ventoy_api_get_password
},
3843 { "save_password", ventoy_api_save_password
},
3844 { "password_add", ventoy_api_password_add
},
3845 { "password_del", ventoy_api_password_del
},
3847 { "get_injection", ventoy_api_get_injection
},
3848 { "save_injection", ventoy_api_save_injection
},
3849 { "injection_add", ventoy_api_injection_add
},
3850 { "injection_del", ventoy_api_injection_del
},
3851 { "preview_json", ventoy_api_preview_json
},
3855 static int ventoy_json_handler(struct mg_connection
*conn
, VTOY_JSON
*json
, char *jsonstr
)
3858 const char *method
= NULL
;
3860 method
= vtoy_json_get_string_ex(json
, "method");
3863 ventoy_json_result(conn
, VTOY_JSON_SUCCESS_RET
);
3867 if (strcmp(method
, "handshake") == 0)
3869 ventoy_api_handshake(conn
, json
);
3873 for (i
= 0; i
< (int)(sizeof(g_ventoy_json_cb
) / sizeof(g_ventoy_json_cb
[0])); i
++)
3875 if (strcmp(method
, g_ventoy_json_cb
[i
].method
) == 0)
3877 g_ventoy_json_cb
[i
].callback(conn
, json
);
3885 static int ventoy_request_handler(struct mg_connection
*conn
)
3889 VTOY_JSON
*json
= NULL
;
3890 char *post_data_buf
= NULL
;
3891 const struct mg_request_info
*ri
= NULL
;
3892 char stack_buf
[512];
3894 ri
= mg_get_request_info(conn
);
3896 if (strcmp(ri
->uri
, "/vtoy/json") == 0)
3898 if (ri
->content_length
> 500)
3900 post_data_buf
= malloc((int)(ri
->content_length
+ 4));
3901 post_buf_len
= (int)(ri
->content_length
+ 1);
3905 post_data_buf
= stack_buf
;
3906 post_buf_len
= sizeof(stack_buf
);
3909 post_data_len
= mg_read(conn
, post_data_buf
, post_buf_len
);
3910 post_data_buf
[post_data_len
] = 0;
3912 json
= vtoy_json_create();
3913 if (JSON_SUCCESS
== vtoy_json_parse(json
, post_data_buf
))
3915 pthread_mutex_lock(&g_api_mutex
);
3916 ventoy_json_handler(conn
, json
->pstChild
, post_data_buf
);
3917 pthread_mutex_unlock(&g_api_mutex
);
3921 ventoy_json_result(conn
, VTOY_JSON_INVALID_RET
);
3924 vtoy_json_destroy(json
);
3926 if (post_data_buf
!= stack_buf
)
3928 free(post_data_buf
);
3938 const char *ventoy_web_openfile(const struct mg_connection
*conn
, const char *path
, size_t *data_len
)
3940 ventoy_file
*node
= NULL
;
3949 node
= ventoy_tar_find_file(path
);
3952 *data_len
= node
->size
;
3964 static int ventoy_parse_control(VTOY_JSON
*json
, void *p
)
3967 VTOY_JSON
*node
= NULL
;
3968 VTOY_JSON
*child
= NULL
;
3969 data_control
*data
= (data_control
*)p
;
3971 if (json
->enDataType
!= JSON_TYPE_ARRAY
)
3976 for (node
= json
->pstChild
; node
; node
= node
->pstNext
)
3978 if (node
->enDataType
== JSON_TYPE_OBJECT
)
3980 child
= node
->pstChild
;
3982 if (strcmp(child
->pcName
, "VTOY_DEFAULT_MENU_MODE") == 0)
3984 CONTROL_PARSE_INT(child
, data
->default_menu_mode
);
3986 else if (strcmp(child
->pcName
, "VTOY_WIN11_BYPASS_CHECK") == 0)
3988 CONTROL_PARSE_INT(child
, data
->win11_bypass_check
);
3990 else if (strcmp(child
->pcName
, "VTOY_LINUX_REMOUNT") == 0)
3992 CONTROL_PARSE_INT(child
, data
->linux_remount
);
3994 else if (strcmp(child
->pcName
, "VTOY_SECONDARY_BOOT_MENU") == 0)
3996 CONTROL_PARSE_INT(child
, data
->secondary_menu
);
3998 else if (strcmp(child
->pcName
, "VTOY_TREE_VIEW_MENU_STYLE") == 0)
4000 CONTROL_PARSE_INT(child
, data
->treeview_style
);
4002 else if (strcmp(child
->pcName
, "VTOY_FILT_DOT_UNDERSCORE_FILE") == 0)
4004 CONTROL_PARSE_INT(child
, data
->filter_dot_underscore
);
4006 else if (strcmp(child
->pcName
, "VTOY_SORT_CASE_SENSITIVE") == 0)
4008 CONTROL_PARSE_INT(child
, data
->sort_casesensitive
);
4010 else if (strcmp(child
->pcName
, "VTOY_MAX_SEARCH_LEVEL") == 0)
4012 if (strcmp(child
->unData
.pcStrVal
, "max") == 0)
4014 data
->max_search_level
= -1;
4018 data
->max_search_level
= (int)strtol(child
->unData
.pcStrVal
, NULL
, 10);
4021 else if (strcmp(child
->pcName
, "VTOY_DEFAULT_SEARCH_ROOT") == 0)
4023 strlcpy(data
->default_search_root
, child
->unData
.pcStrVal
);
4025 else if (strcmp(child
->pcName
, "VTOY_DEFAULT_IMAGE") == 0)
4027 strlcpy(data
->default_image
, child
->unData
.pcStrVal
);
4029 else if (strcmp(child
->pcName
, "VTOY_DEFAULT_KBD_LAYOUT") == 0)
4031 for (i
= 0; g_ventoy_kbd_layout
[i
]; i
++)
4033 if (strcmp(child
->unData
.pcStrVal
, g_ventoy_kbd_layout
[i
]) == 0)
4035 strlcpy(data
->default_kbd_layout
, child
->unData
.pcStrVal
);
4040 else if (strcmp(child
->pcName
, "VTOY_HELP_TXT_LANGUAGE") == 0)
4042 for (i
= 0; g_ventoy_help_lang
[i
][0]; i
++)
4044 if (strcmp(child
->unData
.pcStrVal
, g_ventoy_help_lang
[i
]) == 0)
4046 strlcpy(data
->help_text_language
, child
->unData
.pcStrVal
);
4051 else if (strcmp(child
->pcName
, "VTOY_MENU_TIMEOUT") == 0)
4053 data
->menu_timeout
= (int)strtol(child
->unData
.pcStrVal
, NULL
, 10);
4055 else if (strcmp(child
->pcName
, "VTOY_SECONDARY_TIMEOUT") == 0)
4057 data
->secondary_menu_timeout
= (int)strtol(child
->unData
.pcStrVal
, NULL
, 10);
4059 else if (strcmp(child
->pcName
, "VTOY_VHD_NO_WARNING") == 0)
4061 CONTROL_PARSE_INT(child
, data
->vhd_no_warning
);
4063 else if (strcmp(child
->pcName
, "VTOY_FILE_FLT_ISO") == 0)
4065 CONTROL_PARSE_INT(child
, data
->filter_iso
);
4067 else if (strcmp(child
->pcName
, "VTOY_FILE_FLT_IMG") == 0)
4069 CONTROL_PARSE_INT(child
, data
->filter_img
);
4071 else if (strcmp(child
->pcName
, "VTOY_FILE_FLT_EFI") == 0)
4073 CONTROL_PARSE_INT(child
, data
->filter_efi
);
4075 else if (strcmp(child
->pcName
, "VTOY_FILE_FLT_WIM") == 0)
4077 CONTROL_PARSE_INT(child
, data
->filter_wim
);
4079 else if (strcmp(child
->pcName
, "VTOY_FILE_FLT_VHD") == 0)
4081 CONTROL_PARSE_INT(child
, data
->filter_vhd
);
4083 else if (strcmp(child
->pcName
, "VTOY_FILE_FLT_VTOY") == 0)
4085 CONTROL_PARSE_INT(child
, data
->filter_vtoy
);
4093 static int ventoy_parse_theme(VTOY_JSON
*json
, void *p
)
4095 const char *dismode
= NULL
;
4096 VTOY_JSON
*child
= NULL
;
4097 VTOY_JSON
*node
= NULL
;
4098 path_node
*tail
= NULL
;
4099 path_node
*pnode
= NULL
;
4100 data_theme
*data
= (data_theme
*)p
;
4102 if (json
->enDataType
!= JSON_TYPE_OBJECT
)
4107 child
= json
->pstChild
;
4109 dismode
= vtoy_json_get_string_ex(child
, "display_mode");
4110 vtoy_json_get_string(child
, "ventoy_left", sizeof(data
->ventoy_left
), data
->ventoy_left
);
4111 vtoy_json_get_string(child
, "ventoy_top", sizeof(data
->ventoy_top
), data
->ventoy_top
);
4112 vtoy_json_get_string(child
, "ventoy_color", sizeof(data
->ventoy_color
), data
->ventoy_color
);
4114 vtoy_json_get_int(child
, "default_file", &(data
->default_file
));
4115 vtoy_json_get_string(child
, "gfxmode", sizeof(data
->gfxmode
), data
->gfxmode
);
4116 vtoy_json_get_string(child
, "serial_param", sizeof(data
->serial_param
), data
->serial_param
);
4120 if (strcmp(dismode
, "CLI") == 0)
4122 data
->display_mode
= display_mode_cli
;
4124 else if (strcmp(dismode
, "serial") == 0)
4126 data
->display_mode
= display_mode_serial
;
4128 else if (strcmp(dismode
, "serial_console") == 0)
4130 data
->display_mode
= display_mode_ser_console
;
4134 data
->display_mode
= display_mode_gui
;
4138 node
= vtoy_json_find_item(child
, JSON_TYPE_STRING
, "file");
4141 data
->default_file
= 0;
4143 pnode
= zalloc(sizeof(path_node
));
4146 strlcpy(pnode
->path
, node
->unData
.pcStrVal
);
4147 data
->filelist
= pnode
;
4152 node
= vtoy_json_find_item(child
, JSON_TYPE_ARRAY
, "file");
4155 for (node
= node
->pstChild
; node
; node
= node
->pstNext
)
4157 if (node
->enDataType
== JSON_TYPE_STRING
)
4159 pnode
= zalloc(sizeof(path_node
));
4162 strlcpy(pnode
->path
, node
->unData
.pcStrVal
);
4170 data
->filelist
= tail
= pnode
;
4179 node
= vtoy_json_find_item(child
, JSON_TYPE_ARRAY
, "fonts");
4182 for (node
= node
->pstChild
; node
; node
= node
->pstNext
)
4184 if (node
->enDataType
== JSON_TYPE_STRING
)
4186 pnode
= zalloc(sizeof(path_node
));
4189 strlcpy(pnode
->path
, node
->unData
.pcStrVal
);
4190 if (data
->fontslist
)
4197 data
->fontslist
= tail
= pnode
;
4206 static int ventoy_parse_menu_alias(VTOY_JSON
*json
, void *p
)
4209 const char *path
= NULL
;
4210 const char *alias
= NULL
;
4211 data_alias
*data
= (data_alias
*)p
;
4212 data_alias_node
*tail
= NULL
;
4213 data_alias_node
*pnode
= NULL
;
4214 VTOY_JSON
*node
= NULL
;
4216 if (json
->enDataType
!= JSON_TYPE_ARRAY
)
4221 for (node
= json
->pstChild
; node
; node
= node
->pstNext
)
4223 if (node
->enDataType
!= JSON_TYPE_OBJECT
)
4228 type
= path_type_file
;
4229 path
= vtoy_json_get_string_ex(node
->pstChild
, "image");
4232 path
= vtoy_json_get_string_ex(node
->pstChild
, "dir");
4233 type
= path_type_dir
;
4235 alias
= vtoy_json_get_string_ex(node
->pstChild
, "alias");
4239 pnode
= zalloc(sizeof(data_alias_node
));
4243 strlcpy(pnode
->path
, path
);
4244 strlcpy(pnode
->alias
, alias
);
4253 data
->list
= tail
= pnode
;
4262 static int ventoy_parse_menu_tip(VTOY_JSON
*json
, void *p
)
4265 const char *path
= NULL
;
4266 const char *tip
= NULL
;
4267 data_tip
*data
= (data_tip
*)p
;
4268 data_tip_node
*tail
= NULL
;
4269 data_tip_node
*pnode
= NULL
;
4270 VTOY_JSON
*node
= NULL
;
4271 VTOY_JSON
*tips
= NULL
;
4273 if (json
->enDataType
!= JSON_TYPE_OBJECT
)
4278 vtoy_json_get_string(json
->pstChild
, "left", sizeof(data
->left
), data
->left
);
4279 vtoy_json_get_string(json
->pstChild
, "top", sizeof(data
->top
), data
->top
);
4280 vtoy_json_get_string(json
->pstChild
, "color", sizeof(data
->color
), data
->color
);
4282 tips
= vtoy_json_find_item(json
->pstChild
, JSON_TYPE_ARRAY
, "tips");
4288 for (node
= tips
->pstChild
; node
; node
= node
->pstNext
)
4290 if (node
->enDataType
!= JSON_TYPE_OBJECT
)
4295 type
= path_type_file
;
4296 path
= vtoy_json_get_string_ex(node
->pstChild
, "image");
4299 path
= vtoy_json_get_string_ex(node
->pstChild
, "dir");
4300 type
= path_type_dir
;
4302 tip
= vtoy_json_get_string_ex(node
->pstChild
, "tip");
4306 pnode
= zalloc(sizeof(data_tip_node
));
4310 strlcpy(pnode
->path
, path
);
4311 strlcpy(pnode
->tip
, tip
);
4320 data
->list
= tail
= pnode
;
4328 static int ventoy_parse_menu_class(VTOY_JSON
*json
, void *p
)
4331 const char *path
= NULL
;
4332 const char *class = NULL
;
4333 data_class
*data
= (data_class
*)p
;
4334 data_class_node
*tail
= NULL
;
4335 data_class_node
*pnode
= NULL
;
4336 VTOY_JSON
*node
= NULL
;
4338 if (json
->enDataType
!= JSON_TYPE_ARRAY
)
4343 for (node
= json
->pstChild
; node
; node
= node
->pstNext
)
4345 if (node
->enDataType
!= JSON_TYPE_OBJECT
)
4350 type
= class_type_key
;
4351 path
= vtoy_json_get_string_ex(node
->pstChild
, "key");
4354 type
= class_type_dir
;
4355 path
= vtoy_json_get_string_ex(node
->pstChild
, "dir");
4358 type
= class_type_parent
;
4359 path
= vtoy_json_get_string_ex(node
->pstChild
, "parent");
4362 class = vtoy_json_get_string_ex(node
->pstChild
, "class");
4366 pnode
= zalloc(sizeof(data_class_node
));
4370 strlcpy(pnode
->path
, path
);
4371 strlcpy(pnode
->class, class);
4380 data
->list
= tail
= pnode
;
4388 static int ventoy_parse_auto_install(VTOY_JSON
*json
, void *p
)
4396 const char *path
= NULL
;
4397 const char *file
= NULL
;
4398 data_auto_install
*data
= (data_auto_install
*)p
;
4399 auto_install_node
*tail
= NULL
;
4400 auto_install_node
*pnode
= NULL
;
4401 path_node
*pathnode
= NULL
;
4402 path_node
*pathtail
= NULL
;
4403 VTOY_JSON
*node
= NULL
;
4404 VTOY_JSON
*filelist
= NULL
;
4405 VTOY_JSON
*filenode
= NULL
;
4407 if (json
->enDataType
!= JSON_TYPE_ARRAY
)
4412 for (node
= json
->pstChild
; node
; node
= node
->pstNext
)
4414 if (node
->enDataType
!= JSON_TYPE_OBJECT
)
4420 path
= vtoy_json_get_string_ex(node
->pstChild
, "image");
4423 path
= vtoy_json_get_string_ex(node
->pstChild
, "parent");
4431 file
= vtoy_json_get_string_ex(node
->pstChild
, "template");
4434 pnode
= zalloc(sizeof(auto_install_node
));
4439 strlcpy(pnode
->path
, path
);
4441 pathnode
= zalloc(sizeof(path_node
));
4444 strlcpy(pathnode
->path
, file
);
4445 pnode
->list
= pathnode
;
4459 data
->list
= tail
= pnode
;
4467 timeouten
= autoselen
= 0;
4468 if (JSON_SUCCESS
== vtoy_json_get_int(node
->pstChild
, "timeout", &timeout
))
4472 if (JSON_SUCCESS
== vtoy_json_get_int(node
->pstChild
, "autosel", &autosel
))
4477 filelist
= vtoy_json_find_item(node
->pstChild
, JSON_TYPE_ARRAY
, "template");
4483 pnode
= zalloc(sizeof(auto_install_node
));
4490 pnode
->autoselen
= autoselen
;
4491 pnode
->timeouten
= timeouten
;
4492 pnode
->timeout
= timeout
;
4493 pnode
->autosel
= autosel
;
4494 strlcpy(pnode
->path
, path
);
4497 for (filenode
= filelist
->pstChild
; filenode
; filenode
= filenode
->pstNext
)
4499 if (filenode
->enDataType
!= JSON_TYPE_STRING
)
4504 pathnode
= zalloc(sizeof(path_node
));
4508 strlcpy(pathnode
->path
, filenode
->unData
.pcStrVal
);
4512 pathtail
->next
= pathnode
;
4513 pathtail
= pathnode
;
4517 pnode
->list
= pathtail
= pathnode
;
4528 if (pnode
->autoselen
&& pnode
->autosel
> count
)
4540 data
->list
= tail
= pnode
;
4547 static int ventoy_parse_persistence(VTOY_JSON
*json
, void *p
)
4554 const char *path
= NULL
;
4555 const char *file
= NULL
;
4556 data_persistence
*data
= (data_persistence
*)p
;
4557 persistence_node
*tail
= NULL
;
4558 persistence_node
*pnode
= NULL
;
4559 path_node
*pathnode
= NULL
;
4560 path_node
*pathtail
= NULL
;
4561 VTOY_JSON
*node
= NULL
;
4562 VTOY_JSON
*filelist
= NULL
;
4563 VTOY_JSON
*filenode
= NULL
;
4565 if (json
->enDataType
!= JSON_TYPE_ARRAY
)
4570 for (node
= json
->pstChild
; node
; node
= node
->pstNext
)
4572 if (node
->enDataType
!= JSON_TYPE_OBJECT
)
4577 path
= vtoy_json_get_string_ex(node
->pstChild
, "image");
4583 file
= vtoy_json_get_string_ex(node
->pstChild
, "backend");
4586 pnode
= zalloc(sizeof(persistence_node
));
4591 strlcpy(pnode
->path
, path
);
4593 pathnode
= zalloc(sizeof(path_node
));
4596 strlcpy(pathnode
->path
, file
);
4597 pnode
->list
= pathnode
;
4611 data
->list
= tail
= pnode
;
4619 timeouten
= autoselen
= 0;
4620 if (JSON_SUCCESS
== vtoy_json_get_int(node
->pstChild
, "timeout", &timeout
))
4624 if (JSON_SUCCESS
== vtoy_json_get_int(node
->pstChild
, "autosel", &autosel
))
4629 filelist
= vtoy_json_find_item(node
->pstChild
, JSON_TYPE_ARRAY
, "backend");
4635 pnode
= zalloc(sizeof(persistence_node
));
4642 pnode
->autoselen
= autoselen
;
4643 pnode
->timeouten
= timeouten
;
4644 pnode
->timeout
= timeout
;
4645 pnode
->autosel
= autosel
;
4646 strlcpy(pnode
->path
, path
);
4649 for (filenode
= filelist
->pstChild
; filenode
; filenode
= filenode
->pstNext
)
4651 if (filenode
->enDataType
!= JSON_TYPE_STRING
)
4656 pathnode
= zalloc(sizeof(path_node
));
4660 strlcpy(pathnode
->path
, filenode
->unData
.pcStrVal
);
4664 pathtail
->next
= pathnode
;
4665 pathtail
= pathnode
;
4669 pnode
->list
= pathtail
= pathnode
;
4680 if (pnode
->autoselen
&& pnode
->autosel
> count
)
4692 data
->list
= tail
= pnode
;
4699 static int ventoy_parse_injection(VTOY_JSON
*json
, void *p
)
4702 const char *path
= NULL
;
4703 const char *archive
= NULL
;
4704 data_injection
*data
= (data_injection
*)p
;
4705 injection_node
*tail
= NULL
;
4706 injection_node
*pnode
= NULL
;
4707 VTOY_JSON
*node
= NULL
;
4709 if (json
->enDataType
!= JSON_TYPE_ARRAY
)
4714 for (node
= json
->pstChild
; node
; node
= node
->pstNext
)
4716 if (node
->enDataType
!= JSON_TYPE_OBJECT
)
4722 path
= vtoy_json_get_string_ex(node
->pstChild
, "image");
4725 path
= vtoy_json_get_string_ex(node
->pstChild
, "parent");
4728 archive
= vtoy_json_get_string_ex(node
->pstChild
, "archive");
4730 if (path
&& archive
)
4732 pnode
= zalloc(sizeof(injection_node
));
4736 strlcpy(pnode
->path
, path
);
4737 strlcpy(pnode
->archive
, archive
);
4746 data
->list
= tail
= pnode
;
4754 static int ventoy_parse_conf_replace(VTOY_JSON
*json
, void *p
)
4757 const char *path
= NULL
;
4758 const char *org
= NULL
;
4759 const char *new = NULL
;
4760 data_conf_replace
*data
= (data_conf_replace
*)p
;
4761 conf_replace_node
*tail
= NULL
;
4762 conf_replace_node
*pnode
= NULL
;
4763 VTOY_JSON
*node
= NULL
;
4765 if (json
->enDataType
!= JSON_TYPE_ARRAY
)
4770 for (node
= json
->pstChild
; node
; node
= node
->pstNext
)
4772 if (node
->enDataType
!= JSON_TYPE_OBJECT
)
4777 path
= vtoy_json_get_string_ex(node
->pstChild
, "iso");
4778 org
= vtoy_json_get_string_ex(node
->pstChild
, "org");
4779 new = vtoy_json_get_string_ex(node
->pstChild
, "new");
4782 vtoy_json_get_int(node
->pstChild
, "img", &img
);
4784 if (path
&& org
&& new)
4786 pnode
= zalloc(sizeof(conf_replace_node
));
4789 strlcpy(pnode
->path
, path
);
4790 strlcpy(pnode
->org
, org
);
4791 strlcpy(pnode
->new, new);
4804 data
->list
= tail
= pnode
;
4812 static int ventoy_parse_password(VTOY_JSON
*json
, void *p
)
4815 const char *bootpwd
= NULL
;
4816 const char *isopwd
= NULL
;
4817 const char *wimpwd
= NULL
;
4818 const char *imgpwd
= NULL
;
4819 const char *efipwd
= NULL
;
4820 const char *vhdpwd
= NULL
;
4821 const char *vtoypwd
= NULL
;
4822 const char *path
= NULL
;
4823 const char *pwd
= NULL
;
4824 data_password
*data
= (data_password
*)p
;
4825 menu_password
*tail
= NULL
;
4826 menu_password
*pnode
= NULL
;
4827 VTOY_JSON
*node
= NULL
;
4828 VTOY_JSON
*menupwd
= NULL
;
4830 if (json
->enDataType
!= JSON_TYPE_OBJECT
)
4835 bootpwd
= vtoy_json_get_string_ex(json
->pstChild
, "bootpwd");
4836 isopwd
= vtoy_json_get_string_ex(json
->pstChild
, "isopwd");
4837 wimpwd
= vtoy_json_get_string_ex(json
->pstChild
, "wimpwd");
4838 imgpwd
= vtoy_json_get_string_ex(json
->pstChild
, "imgpwd");
4839 efipwd
= vtoy_json_get_string_ex(json
->pstChild
, "efipwd");
4840 vhdpwd
= vtoy_json_get_string_ex(json
->pstChild
, "vhdpwd");
4841 vtoypwd
= vtoy_json_get_string_ex(json
->pstChild
, "vtoypwd");
4844 if (bootpwd
) strlcpy(data
->bootpwd
, bootpwd
);
4845 if (isopwd
) strlcpy(data
->isopwd
, isopwd
);
4846 if (wimpwd
) strlcpy(data
->wimpwd
, wimpwd
);
4847 if (imgpwd
) strlcpy(data
->imgpwd
, imgpwd
);
4848 if (efipwd
) strlcpy(data
->efipwd
, efipwd
);
4849 if (vhdpwd
) strlcpy(data
->vhdpwd
, vhdpwd
);
4850 if (vtoypwd
) strlcpy(data
->vtoypwd
, vtoypwd
);
4853 menupwd
= vtoy_json_find_item(json
->pstChild
, JSON_TYPE_ARRAY
, "menupwd");
4859 for (node
= menupwd
->pstChild
; node
; node
= node
->pstNext
)
4861 if (node
->enDataType
!= JSON_TYPE_OBJECT
)
4867 path
= vtoy_json_get_string_ex(node
->pstChild
, "file");
4870 path
= vtoy_json_get_string_ex(node
->pstChild
, "parent");
4873 pwd
= vtoy_json_get_string_ex(node
->pstChild
, "pwd");
4877 pnode
= zalloc(sizeof(menu_password
));
4881 strlcpy(pnode
->path
, path
);
4882 strlcpy(pnode
->pwd
, pwd
);
4891 data
->list
= tail
= pnode
;
4900 static int ventoy_parse_image_list_real(VTOY_JSON
*json
, int type
, void *p
)
4902 VTOY_JSON
*node
= NULL
;
4903 data_image_list
*data
= (data_image_list
*)p
;
4904 path_node
*tail
= NULL
;
4905 path_node
*pnode
= NULL
;
4907 if (json
->enDataType
!= JSON_TYPE_ARRAY
)
4914 for (node
= json
->pstChild
; node
; node
= node
->pstNext
)
4916 if (node
->enDataType
== JSON_TYPE_STRING
)
4918 pnode
= zalloc(sizeof(path_node
));
4921 strlcpy(pnode
->path
, node
->unData
.pcStrVal
);
4929 data
->list
= tail
= pnode
;
4937 static int ventoy_parse_image_blacklist(VTOY_JSON
*json
, void *p
)
4939 return ventoy_parse_image_list_real(json
, 1, p
);
4941 static int ventoy_parse_image_list(VTOY_JSON
*json
, void *p
)
4943 return ventoy_parse_image_list_real(json
, 0, p
);
4946 static int ventoy_parse_auto_memdisk(VTOY_JSON
*json
, void *p
)
4948 VTOY_JSON
*node
= NULL
;
4949 data_auto_memdisk
*data
= (data_auto_memdisk
*)p
;
4950 path_node
*tail
= NULL
;
4951 path_node
*pnode
= NULL
;
4953 if (json
->enDataType
!= JSON_TYPE_ARRAY
)
4958 for (node
= json
->pstChild
; node
; node
= node
->pstNext
)
4960 if (node
->enDataType
== JSON_TYPE_STRING
)
4962 pnode
= zalloc(sizeof(path_node
));
4965 strlcpy(pnode
->path
, node
->unData
.pcStrVal
);
4973 data
->list
= tail
= pnode
;
4981 static int ventoy_parse_dud(VTOY_JSON
*json
, void *p
)
4984 const char *path
= NULL
;
4985 const char *file
= NULL
;
4986 data_dud
*data
= (data_dud
*)p
;
4987 dud_node
*tail
= NULL
;
4988 dud_node
*pnode
= NULL
;
4989 path_node
*pathnode
= NULL
;
4990 path_node
*pathtail
= NULL
;
4991 VTOY_JSON
*node
= NULL
;
4992 VTOY_JSON
*filelist
= NULL
;
4993 VTOY_JSON
*filenode
= NULL
;
4995 if (json
->enDataType
!= JSON_TYPE_ARRAY
)
5000 for (node
= json
->pstChild
; node
; node
= node
->pstNext
)
5002 if (node
->enDataType
!= JSON_TYPE_OBJECT
)
5007 path
= vtoy_json_get_string_ex(node
->pstChild
, "image");
5013 file
= vtoy_json_get_string_ex(node
->pstChild
, "dud");
5016 pnode
= zalloc(sizeof(dud_node
));
5019 strlcpy(pnode
->path
, path
);
5021 pathnode
= zalloc(sizeof(path_node
));
5024 strlcpy(pathnode
->path
, file
);
5025 pnode
->list
= pathnode
;
5039 data
->list
= tail
= pnode
;
5046 filelist
= vtoy_json_find_item(node
->pstChild
, JSON_TYPE_ARRAY
, "dud");
5052 pnode
= zalloc(sizeof(dud_node
));
5058 strlcpy(pnode
->path
, path
);
5060 for (filenode
= filelist
->pstChild
; filenode
; filenode
= filenode
->pstNext
)
5062 if (filenode
->enDataType
!= JSON_TYPE_STRING
)
5067 pathnode
= zalloc(sizeof(path_node
));
5070 strlcpy(pathnode
->path
, filenode
->unData
.pcStrVal
);
5075 pathtail
->next
= pathnode
;
5076 pathtail
= pathnode
;
5080 pnode
->list
= pathtail
= pathnode
;
5098 data
->list
= tail
= pnode
;
5112 static int ventoy_load_old_json(const char *filename
)
5117 char *buffer
= NULL
;
5118 unsigned char *start
= NULL
;
5119 VTOY_JSON
*json
= NULL
;
5120 VTOY_JSON
*node
= NULL
;
5121 VTOY_JSON
*next
= NULL
;
5123 ret
= ventoy_read_file_to_buf(filename
, 4, (void **)&buffer
, &buflen
);
5126 vlog("Failed to read old ventoy.json file.\n");
5131 start
= (unsigned char *)buffer
;
5133 if (start
[0] == 0xef && start
[1] == 0xbb && start
[2] == 0xbf)
5137 else if ((start
[0] == 0xff && start
[1] == 0xfe) || (start
[0] == 0xfe && start
[1] == 0xff))
5139 vlog("ventoy.json is in UCS-2 encoding, ignore it.\n");
5144 json
= vtoy_json_create();
5151 if (vtoy_json_parse_ex(json
, buffer
+ offset
, buflen
- offset
) == JSON_SUCCESS
)
5153 vlog("parse ventoy.json success\n");
5155 for (node
= json
->pstChild
; node
; node
= node
->pstNext
)
5156 for (next
= node
->pstNext
; next
; next
= next
->pstNext
)
5158 if (node
->pcName
&& next
->pcName
&& strcmp(node
->pcName
, next
->pcName
) == 0)
5160 vlog("ventoy.json contains duplicate key <%s>.\n", node
->pcName
);
5161 g_sysinfo
.invalid_config
= 1;
5167 for (node
= json
->pstChild
; node
; node
= node
->pstNext
)
5169 ventoy_parse_json(control
);
5170 ventoy_parse_json(theme
);
5171 ventoy_parse_json(menu_alias
);
5172 ventoy_parse_json(menu_tip
);
5173 ventoy_parse_json(menu_class
);
5174 ventoy_parse_json(auto_install
);
5175 ventoy_parse_json(persistence
);
5176 ventoy_parse_json(injection
);
5177 ventoy_parse_json(conf_replace
);
5178 ventoy_parse_json(password
);
5179 ventoy_parse_json(image_list
);
5180 ventoy_parse_json(image_blacklist
);
5181 ventoy_parse_json(auto_memdisk
);
5182 ventoy_parse_json(dud
);
5187 vlog("ventoy.json has syntax error.\n");
5188 g_sysinfo
.syntax_error
= 1;
5193 vtoy_json_destroy(json
);
5200 int ventoy_http_start(const char *ip
, const char *port
)
5206 char backupname
[128];
5207 struct mg_callbacks callbacks
;
5208 const char *options
[] =
5210 "listening_ports", "24681",
5211 "document_root", "www",
5212 "index_files", "index.html",
5213 "num_threads", "16",
5214 "error_log_file", LOG_FILE
,
5215 "request_timeout_ms", "10000",
5219 for (i
= 0; i
<= bios_max
; i
++)
5221 ventoy_data_default_control(g_data_control
+ i
);
5222 ventoy_data_default_theme(g_data_theme
+ i
);
5223 ventoy_data_default_menu_alias(g_data_menu_alias
+ i
);
5224 ventoy_data_default_menu_class(g_data_menu_class
+ i
);
5225 ventoy_data_default_menu_tip(g_data_menu_tip
+ i
);
5226 ventoy_data_default_auto_install(g_data_auto_install
+ i
);
5227 ventoy_data_default_persistence(g_data_persistence
+ i
);
5228 ventoy_data_default_injection(g_data_injection
+ i
);
5229 ventoy_data_default_conf_replace(g_data_conf_replace
+ i
);
5230 ventoy_data_default_password(g_data_password
+ i
);
5231 ventoy_data_default_image_list(g_data_image_list
+ i
);
5232 ventoy_data_default_auto_memdisk(g_data_auto_memdisk
+ i
);
5233 ventoy_data_default_dud(g_data_dud
+ i
);
5236 ventoy_get_json_path(filename
, backupname
);
5237 if (ventoy_is_file_exist("%s", filename
))
5239 ventoy_copy_file(filename
, backupname
);
5240 ret
= ventoy_load_old_json(filename
);
5243 ventoy_data_real_save_all(0);
5248 scnprintf(addr
, sizeof(addr
), "%s:%s", ip
, port
);
5251 memset(&callbacks
, 0, sizeof(callbacks
));
5252 callbacks
.begin_request
= ventoy_request_handler
;
5254 callbacks
.open_file
= ventoy_web_openfile
;
5256 g_ventoy_http_ctx
= mg_start(&callbacks
, NULL
, options
);
5258 ventoy_start_writeback_thread(ventoy_http_writeback
);
5260 return g_ventoy_http_ctx
? 0 : 1;
5263 int ventoy_http_stop(void)
5265 if (g_ventoy_http_ctx
)
5267 mg_stop(g_ventoy_http_ctx
);
5270 ventoy_stop_writeback_thread();
5274 int ventoy_http_init(void)
5279 char *Buffer
= NULL
;
5282 ventoy_read_file_to_buf("www/helplist", 4, (void **)&Buffer
, &BufLen
);
5285 for (i
= 0; i
< BufLen
/ 5; i
++)
5287 memcpy(g_ventoy_help_lang
[i
], Buffer
+ i
* 5, 5);
5288 g_ventoy_help_lang
[i
][5] = 0;
5294 file
= ventoy_tar_find_file("www/helplist");
5297 for (i
= 0; i
< file
->size
/ 5; i
++)
5299 memcpy(g_ventoy_help_lang
[i
], (char *)(file
->addr
) + i
* 5, 5);
5300 g_ventoy_help_lang
[i
][5] = 0;
5305 if (!g_pub_json_buffer
)
5307 g_pub_json_buffer
= malloc(JSON_BUF_MAX
* 2);
5308 g_pub_save_buffer
= g_pub_json_buffer
+ JSON_BUF_MAX
;
5312 pthread_mutex_init(&g_api_mutex
, NULL
);
5316 void ventoy_http_exit(void)
5318 check_free(g_pub_json_buffer
);
5319 g_pub_json_buffer
= NULL
;
5320 g_pub_save_buffer
= NULL
;
5322 pthread_mutex_destroy(&g_api_mutex
);