Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes to build with both Edition 2024 and Edition 2021 #78

Merged
merged 3 commits into from
Feb 21, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,4 @@ android_logger = "0.14"
jni = { version = "0.21", default-features = false }

[target.'cfg(target_os = "windows")'.dependencies]
windows-service = "0.7"
windows-service = "0.8"
4 changes: 2 additions & 2 deletions src/android.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ static EXITING_FLAG: std::sync::Mutex<Option<crate::CancellationToken>> = std::s
/// # Safety
///
/// Run the overtls client with config file.
#[no_mangle]
#[unsafe(no_mangle)]
pub unsafe extern "C" fn Java_com_github_shadowsocks_bg_OverTlsWrapper_runClient(
mut env: JNIEnv,
_: JClass,
Expand Down Expand Up @@ -116,7 +116,7 @@ fn _protect_socket(env: &mut JNIEnv, vpn_service: &JObject, socket: i32) -> Resu
/// # Safety
///
/// Shutdown the client.
#[no_mangle]
#[unsafe(no_mangle)]
pub unsafe extern "C" fn Java_com_github_shadowsocks_bg_OverTlsWrapper_stopClient(_: JNIEnv, _: JClass) -> jint {
if let Ok(mut token) = EXITING_FLAG.lock() {
if let Some(token) = token.take() {
Expand Down
26 changes: 13 additions & 13 deletions src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ struct CCallback(Option<unsafe extern "C" fn(c_int, *mut c_void)>, *mut c_void);
impl CCallback {
unsafe fn call(self, arg: c_int) {
if let Some(cb) = self.0 {
cb(arg, self.1);
unsafe { cb(arg, self.1) };
}
}
}
Expand All @@ -30,7 +30,7 @@ static EXITING_FLAG: std::sync::Mutex<Option<crate::CancellationToken>> = std::s
/// The callback function will be called when the client is listening on a port.
/// It should be thread-safe and will be called with the port number and should be called only once.
///
#[no_mangle]
#[unsafe(no_mangle)]
pub unsafe extern "C" fn over_tls_client_run(
config_path: *const c_char,
verbosity: ArgVerbosity,
Expand All @@ -47,7 +47,7 @@ pub unsafe extern "C" fn over_tls_client_run(
if config_path.is_null() {
return Err("config_path is null".into());
}
let config_path = std::ffi::CStr::from_ptr(config_path).to_str()?;
let config_path = unsafe { std::ffi::CStr::from_ptr(config_path).to_str()? };
let mut config = Config::from_config_file(config_path)?;
config.check_correctness(false)?;
_over_tls_client_run(config, callback, ctx)
Expand All @@ -72,7 +72,7 @@ pub unsafe extern "C" fn over_tls_client_run(
/// It should be thread-safe and will be called with the port number and should be called only once.
/// - `ctx`: The context pointer to be passed to the callback function.
///
#[no_mangle]
#[unsafe(no_mangle)]
pub unsafe extern "C" fn over_tls_client_run_with_ssr_url(
url: *const c_char,
listen_addr: *const c_char,
Expand All @@ -88,11 +88,11 @@ pub unsafe extern "C" fn over_tls_client_run_with_ssr_url(
}

let result = || {
let url = std::ffi::CStr::from_ptr(url).to_str()?;
let url = unsafe { std::ffi::CStr::from_ptr(url).to_str()? };
let listen_addr = if listen_addr.is_null() {
std::net::SocketAddr::from(([127, 0, 0, 1], 1080))
} else {
std::ffi::CStr::from_ptr(listen_addr).to_str()?.parse()?
unsafe { std::ffi::CStr::from_ptr(listen_addr) }.to_str()?.parse()?
};

let mut config = Config::from_ssr_url(url)?;
Expand Down Expand Up @@ -121,8 +121,8 @@ fn _over_tls_client_run(config: Config, callback: Option<unsafe extern "C" fn(c_

let ccb = CCallback(callback, ctx);

let cb = |addr: SocketAddr| unsafe {
ccb.call(addr.port() as _);
let cb = |addr: SocketAddr| {
unsafe { ccb.call(addr.port() as _) };
};

let rt = tokio::runtime::Builder::new_multi_thread().enable_all().build()?;
Expand All @@ -136,7 +136,7 @@ fn _over_tls_client_run(config: Config, callback: Option<unsafe extern "C" fn(c_
/// # Safety
///
/// Shutdown the client.
#[no_mangle]
#[unsafe(no_mangle)]
pub unsafe extern "C" fn over_tls_client_stop() -> c_int {
if let Ok(mut token) = EXITING_FLAG.lock() {
if let Some(token) = token.take() {
Expand All @@ -149,9 +149,9 @@ pub unsafe extern "C" fn over_tls_client_stop() -> c_int {
/// # Safety
///
/// Create a SSR URL from the config file.
#[no_mangle]
#[unsafe(no_mangle)]
pub unsafe extern "C" fn overtls_generate_url(cfg_path: *const c_char) -> *mut c_char {
let cfg_path = std::ffi::CStr::from_ptr(cfg_path);
let cfg_path = unsafe { std::ffi::CStr::from_ptr(cfg_path) };
let cfg_path = match cfg_path.to_str() {
Ok(s) => s,
Err(_) => return std::ptr::null_mut(),
Expand All @@ -170,10 +170,10 @@ pub unsafe extern "C" fn overtls_generate_url(cfg_path: *const c_char) -> *mut c
/// # Safety
///
/// Free the string returned by `overtls_generate_url`.
#[no_mangle]
#[unsafe(no_mangle)]
pub unsafe extern "C" fn overtls_free_string(s: *mut c_char) {
if s.is_null() {
return;
}
drop(std::ffi::CString::from_raw(s));
drop(unsafe { std::ffi::CString::from_raw(s) });
}
4 changes: 2 additions & 2 deletions src/dump_logger.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ pub(crate) fn check_logger() -> bool {
/// # Safety
///
/// set dump log info callback.
#[no_mangle]
#[unsafe(no_mangle)]
pub unsafe extern "C" fn overtls_set_log_callback(
set_logger: bool,
callback: Option<unsafe extern "C" fn(ArgVerbosity, *const c_char, *mut c_void)>,
Expand All @@ -41,7 +41,7 @@ struct DumpCallback(Option<unsafe extern "C" fn(ArgVerbosity, *const c_char, *mu
impl DumpCallback {
unsafe fn call(self, dump_level: ArgVerbosity, info: *const c_char) {
if let Some(cb) = self.0 {
cb(dump_level, info, self.1);
unsafe { cb(dump_level, info, self.1) };
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/traffic_status.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use std::{
/// # Safety
///
/// set traffic status callback.
#[no_mangle]
#[unsafe(no_mangle)]
pub unsafe extern "C" fn overtls_set_traffic_status_callback(
send_interval_secs: u32,
callback: Option<unsafe extern "C" fn(*const TrafficStatus, *mut c_void)>,
Expand Down Expand Up @@ -36,7 +36,7 @@ struct TrafficStatusCallback(Option<unsafe extern "C" fn(*const TrafficStatus, *
impl TrafficStatusCallback {
unsafe fn call(self, info: &TrafficStatus) {
if let Some(cb) = self.0 {
cb(info, self.1);
unsafe { cb(info, self.1) };
}
}
}
Expand Down
Loading