diff --git a/Cargo.toml b/Cargo.toml index c87f807..e124238 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -4,3 +4,7 @@ version = "0.1.0" edition = "2021" [dependencies] +cvrf-xmlparser = { git = "https://git.culinux.net/jiachao2130/cvrf-xmlparser.git", version = "0.1.0" } +serde = { version = "1", features = ["serde_derive"] } +tracing = { version = "0.1" } +xml-rs = { version = "0.8" } diff --git a/src/lib.rs b/src/lib.rs index 7d12d9a..9922e78 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,14 +1,103 @@ -pub fn add(left: usize, right: usize) -> usize { - left + right +use cvrf_xmlparser::{Severity, XmlReader}; +use serde::{Serialize, Deserialize}; + +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct UpdateInfoDb { + db: Vec, } -#[cfg(test)] -mod tests { - use super::*; +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct UpdateInfo { + // sa id + id: String, - #[test] - fn it_works() { - let result = add(2, 2); - assert_eq!(result, 4); + // sa title + title: String, + + // sa severity + severity: Severity, + + // the product? openEuler/CULinux + release: String, + + // 用处不大,先不用 + //date: String, + + // cve ids,可能有多个 + cves: Vec, + + // 安全公告的描述 + description: String, + + // 此次更新包含的软件包列表 + pkglist: Vec, +} + +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct RpmInfo { + // 包名 + name: String, + // 可能为空 + epoch: String, + + version: String, + + release: String, + + arch: String, + + file: String, +} + +impl RpmInfo { + pub fn new() -> Self { + RpmInfo { + name: String::new(), + epoch: String::new(), + version: String::new(), + release: String::new(), + arch: String::new(), + file: String::new(), + } + } + + pub fn name(&self) -> &str { + &self.name + } + + pub fn epoch(&self) -> Option<&str> { + if self.epoch != "" { + Some(&self.epoch) + } else { + None + } + } + + pub fn version(&self) -> &str { + &self.version + } + + pub fn release(&self) -> &str { + &self.release + } + + pub fn arch(&self) -> &str { + &self.arch + } + + pub fn file(&self) -> &str { + &self.file + } + + pub fn evr(&self) -> String { + if self.epoch().is_some() { + format!("{}:{}-{}", self.epoch, self.version, self.release) + } else { + format!("{}-{}", self.version, self.release) + } + } + + pub fn nevra(&self) -> String { + format!("{}-{}-{}", self.name, self.evr(), self.arch) } }