mirror of
https://github.com/tun2proxy/tun2proxy.git
synced 2025-04-21 14:29:10 +00:00
TryFrom for ArgProxy
This commit is contained in:
parent
58364580f5
commit
7bee2e0968
4 changed files with 7 additions and 6 deletions
|
@ -35,7 +35,7 @@ pub unsafe extern "C" fn Java_com_github_shadowsocks_bg_Tun2proxy_run(
|
||||||
.with_filter(filter),
|
.with_filter(filter),
|
||||||
);
|
);
|
||||||
let proxy_url = get_java_string(&mut env, &proxy_url).unwrap();
|
let proxy_url = get_java_string(&mut env, &proxy_url).unwrap();
|
||||||
let proxy = ArgProxy::from_url(proxy_url).unwrap();
|
let proxy = ArgProxy::try_from(proxy_url).unwrap();
|
||||||
|
|
||||||
let mut args = Args::default();
|
let mut args = Args::default();
|
||||||
args.proxy(proxy).tun_fd(Some(tun_fd)).dns(dns).verbosity(verbosity);
|
args.proxy(proxy).tun_fd(Some(tun_fd)).dns(dns).verbosity(verbosity);
|
||||||
|
|
|
@ -31,7 +31,7 @@ pub unsafe extern "C" fn tun2proxy_with_fd_run(
|
||||||
}
|
}
|
||||||
|
|
||||||
let proxy_url = std::ffi::CStr::from_ptr(proxy_url).to_str().unwrap();
|
let proxy_url = std::ffi::CStr::from_ptr(proxy_url).to_str().unwrap();
|
||||||
let proxy = ArgProxy::from_url(proxy_url).unwrap();
|
let proxy = ArgProxy::try_from(proxy_url).unwrap();
|
||||||
|
|
||||||
let mut args = Args::default();
|
let mut args = Args::default();
|
||||||
args.proxy(proxy).tun_fd(Some(tun_fd)).dns(dns_strategy).verbosity(verbosity);
|
args.proxy(proxy).tun_fd(Some(tun_fd)).dns(dns_strategy).verbosity(verbosity);
|
||||||
|
|
|
@ -13,7 +13,7 @@ pub struct Args {
|
||||||
/// where proto is one of socks4, socks5, http.
|
/// where proto is one of socks4, socks5, http.
|
||||||
/// Username and password are encoded in percent encoding. For example:
|
/// Username and password are encoded in percent encoding. For example:
|
||||||
/// socks5://myname:pass%40word@127.0.0.1:1080
|
/// socks5://myname:pass%40word@127.0.0.1:1080
|
||||||
#[arg(short, long, value_parser = ArgProxy::from_url, value_name = "URL")]
|
#[arg(short, long, value_parser = |s: &str| ArgProxy::try_from(s), value_name = "URL")]
|
||||||
pub proxy: ArgProxy,
|
pub proxy: ArgProxy,
|
||||||
|
|
||||||
/// Name of the tun interface, such as tun0, utun4, etc.
|
/// Name of the tun interface, such as tun0, utun4, etc.
|
||||||
|
@ -297,8 +297,9 @@ impl std::fmt::Display for ArgProxy {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ArgProxy {
|
impl TryFrom<&str> for ArgProxy {
|
||||||
pub fn from_url(s: &str) -> Result<ArgProxy> {
|
type Error = Error;
|
||||||
|
fn try_from(s: &str) -> Result<Self> {
|
||||||
if s == "none" {
|
if s == "none" {
|
||||||
return Ok(ArgProxy {
|
return Ok(ArgProxy {
|
||||||
proxy_type: ProxyType::None,
|
proxy_type: ProxyType::None,
|
||||||
|
|
|
@ -47,7 +47,7 @@ pub unsafe extern "C" fn tun2proxy_with_name_run(
|
||||||
}
|
}
|
||||||
|
|
||||||
let proxy_url = std::ffi::CStr::from_ptr(proxy_url).to_str().unwrap();
|
let proxy_url = std::ffi::CStr::from_ptr(proxy_url).to_str().unwrap();
|
||||||
let proxy = ArgProxy::from_url(proxy_url).unwrap();
|
let proxy = ArgProxy::try_from(proxy_url).unwrap();
|
||||||
let tun = std::ffi::CStr::from_ptr(tun).to_str().unwrap().to_string();
|
let tun = std::ffi::CStr::from_ptr(tun).to_str().unwrap().to_string();
|
||||||
|
|
||||||
let mut args = Args::default();
|
let mut args = Args::default();
|
||||||
|
|
Loading…
Add table
Reference in a new issue