增加参数校验
This commit is contained in:
@@ -158,7 +158,8 @@ pub fn read_config(file_path: &str) -> io::Result<(Config, bool)> {
|
||||
punch_model,
|
||||
file_conf.port,
|
||||
file_conf.first_latency,
|
||||
);
|
||||
)
|
||||
.unwrap();
|
||||
Ok((config, file_conf.cmd))
|
||||
}
|
||||
|
||||
|
||||
+2
-1
@@ -288,7 +288,8 @@ fn main() {
|
||||
punch_model,
|
||||
port,
|
||||
first_latency,
|
||||
);
|
||||
)
|
||||
.unwrap();
|
||||
(config, cmd)
|
||||
};
|
||||
println!("version {}", vnt::VNT_VERSION);
|
||||
|
||||
+12
-2
@@ -130,7 +130,7 @@ fn new_sync(env: &mut JNIEnv, config: JObject) -> Result<VntUtilSync, Error> {
|
||||
for addr in stun_server_str.split(",") {
|
||||
stun_server.push(addr.trim().to_string());
|
||||
}
|
||||
let config = Config::new(
|
||||
let config = match Config::new(
|
||||
false,
|
||||
token,
|
||||
device_id,
|
||||
@@ -154,7 +154,17 @@ fn new_sync(env: &mut JNIEnv, config: JObject) -> Result<VntUtilSync, Error> {
|
||||
PunchModel::All,
|
||||
port,
|
||||
first_latency,
|
||||
);
|
||||
) {
|
||||
Ok(config) => config,
|
||||
Err(e) => {
|
||||
env.throw_new(
|
||||
"java/lang/RuntimeException",
|
||||
format!("vnt start error {}", e),
|
||||
)
|
||||
.expect("throw");
|
||||
return Err(Error::JavaException);
|
||||
}
|
||||
};
|
||||
match VntUtilSync::new(config) {
|
||||
Ok(vnt_util) => Ok(vnt_util),
|
||||
Err(e) => {
|
||||
|
||||
+12
-3
@@ -600,13 +600,22 @@ impl Config {
|
||||
punch_model: PunchModel,
|
||||
port: u16,
|
||||
first_latency: bool,
|
||||
) -> Self {
|
||||
) -> Result<Self, Error> {
|
||||
for x in stun_server.iter_mut() {
|
||||
if !x.contains(":") {
|
||||
x.push_str(":3478");
|
||||
}
|
||||
}
|
||||
Self {
|
||||
if token.is_empty() || token.len() > 128 {
|
||||
return Err(Error::Stop(String::from("token too long")));
|
||||
}
|
||||
if device_id.is_empty() || device_id.len() > 128 {
|
||||
return Err(Error::Stop(String::from("device_id too long")));
|
||||
}
|
||||
if name.is_empty() || name.len() > 128 {
|
||||
return Err(Error::Stop(String::from("name too long")));
|
||||
}
|
||||
Ok(Self {
|
||||
tap,
|
||||
token,
|
||||
device_id,
|
||||
@@ -631,6 +640,6 @@ impl Config {
|
||||
punch_model,
|
||||
port,
|
||||
first_latency,
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user