增加参数校验

This commit is contained in:
lubeilin
2023-12-30 12:00:47 +08:00
parent 16f833ec72
commit 698e2531e8
4 changed files with 28 additions and 7 deletions
+12 -3
View File
@@ -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,
}
})
}
}