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