diff --git a/include/utils/assets.h b/include/utils/assets.h index d91b126..7f7eb1d 100644 --- a/include/utils/assets.h +++ b/include/utils/assets.h @@ -12,11 +12,8 @@ void assets_load(assets *info); void assets_extract(); -// RUST DEMO START +void assets_log_init(uint8_t verbose); -void rust_test_single(const char *ptr); -void rust_test_multi(char *const *ptr); - -// RUST DEMO END +uint8_t rust_assets_update(const char *file, char *const *sources, const char *assets_dir); #endif diff --git a/src/assets/src/ffi.rs b/src/assets/src/ffi.rs index 30817ce..4dfa13b 100644 --- a/src/assets/src/ffi.rs +++ b/src/assets/src/ffi.rs @@ -1,3 +1,5 @@ +use log::debug; +use std::env::set_var; use std::os::raw::c_char; use std::ffi::{CStr, CString}; @@ -20,22 +22,26 @@ unsafe fn load_c_string_list(ptr: *const *const c_char) -> Vec { } #[no_mangle] -pub unsafe extern "C" fn rust_test_single(ptr: *const c_char) { - println!("enter rust function"); - - let ret = load_c_string(ptr); - println!("ret: {:?}", ret); - - println!("exit rust function"); +pub unsafe extern "C" fn assets_log_init(verbose: u8) { + if verbose == 0 { // bool value `FALSE` + set_var("RUST_LOG", "info"); + } else { + set_var("RUST_LOG", "trace"); + } + env_logger::init(); } - #[no_mangle] -pub unsafe extern "C" fn rust_test_multi(ptr: *const *const c_char) { - println!("enter rust function"); +pub unsafe extern "C" fn rust_assets_update( + file: *const c_char, sources: *const *const c_char, assets_dir: *const c_char) -> u8 { + + let file = load_c_string(file); // import c-style string + let sources = load_c_string_list(sources); + let assets_dir = load_c_string(assets_dir); - let ret = load_c_string_list(ptr); - println!("ret: {:?}", ret); + debug!("file: {}", file); + debug!("source: {:?}", sources); + debug!("assets dir: {}", assets_dir); - println!("exit rust function"); + 0 } diff --git a/src/assets/src/lib.rs b/src/assets/src/lib.rs index 9097f4b..7b003b3 100644 --- a/src/assets/src/lib.rs +++ b/src/assets/src/lib.rs @@ -1,9 +1,3 @@ -// mod fetch; -// -// use std::env::set_var; -// -// use crate::fetch::Asset; - mod ffi; // use std::ffi::{c_char, CStr}; diff --git a/src/cleardns.c b/src/cleardns.c index 2e9fb62..a58d73d 100644 --- a/src/cleardns.c +++ b/src/cleardns.c @@ -130,22 +130,10 @@ int main(int argc, char *argv[]) { char *tmp = string_list_dump(demo); log_warn("dump -> %s", tmp); - log_info("string list -> %p -> %p", &demo, demo); - log_info("string list 1 -> %p -> %p -> `%s`", &demo[0], demo[0], demo[0]); - log_info("string list 2 -> %p -> %p -> `%s`", &demo[1], demo[1], demo[1]); - log_info("string list 3 -> %p -> %p -> `%s`", &demo[2], demo[2], demo[2]); - log_info("string list 4 -> %p -> %p -> `%s`", &demo[3], demo[3], demo[3]); - log_info("string list 5 -> %p -> %p -> `%s`", &demo[4], demo[4], demo[4]); - log_info("string list 6 -> %p -> %p -> `%s`", &demo[5], demo[5], demo[5]); - - rust_test_multi(demo); - - log_info("string list 1 -> %p -> %p -> `%s`", &demo[0], demo[0], demo[0]); - log_info("string list 2 -> %p -> %p -> `%s`", &demo[1], demo[1], demo[1]); - log_info("string list 3 -> %p -> %p -> `%s`", &demo[2], demo[2], demo[2]); - log_info("string list 4 -> %p -> %p -> `%s`", &demo[3], demo[3], demo[3]); - log_info("string list 5 -> %p -> %p -> `%s`", &demo[4], demo[4], demo[4]); - log_info("string list 6 -> %p -> %p -> `%s`", &demo[5], demo[5], demo[5]); +// assets_log_init(TRUE); + assets_log_init(FALSE); + + rust_assets_update("test.txt", demo, ASSETS_DIR); string_list_free(demo);