From a3f9b6787dc21aef5c60404925029173023bd418 Mon Sep 17 00:00:00 2001 From: imWildCat Date: Thu, 9 Feb 2023 07:11:12 -0800 Subject: [PATCH] add list response --- src/services/webdav/list_response.rs | 133 +++++++++++++++++++++++++++ src/services/webdav/mod.rs | 1 + 2 files changed, 134 insertions(+) create mode 100644 src/services/webdav/list_response.rs diff --git a/src/services/webdav/list_response.rs b/src/services/webdav/list_response.rs new file mode 100644 index 000000000000..9a704520737d --- /dev/null +++ b/src/services/webdav/list_response.rs @@ -0,0 +1,133 @@ +use serde::Deserialize; + +#[derive(Deserialize, Debug)] +#[serde(rename_all = "PascalCase")] +struct Multistatus { + response: Vec, +} + +#[derive(Deserialize, Debug)] +#[serde(rename_all = "PascalCase")] +struct ListOpResponse { + href: String, + propstat: Propstat, +} + +#[derive(Deserialize, Debug)] +#[serde(rename_all = "PascalCase")] +struct Propstat { + prop: Prop, + status: String, +} + +#[derive(Deserialize, Debug)] +#[serde(rename_all = "PascalCase")] +struct Prop { + displayname: String, + getlastmodified: String, + resourcetype: ResourceType, + lockdiscovery: (), + supportedlock: SupportedLock, +} + +#[derive(Deserialize, Debug)] +#[serde(rename_all = "PascalCase")] +#[derive(PartialEq)] +enum ResourceType { + Collection, +} + +#[derive(Deserialize, Debug)] +#[serde(rename_all = "PascalCase")] +struct SupportedLock { + lockentry: LockEntry, +} + +#[derive(Deserialize, Debug)] +#[serde(rename_all = "PascalCase")] +struct LockEntry { + lockscope: LockScope, + locktype: LockType, +} + +#[derive(Deserialize, Debug)] +#[serde(rename_all = "PascalCase")] +#[derive(PartialEq)] +enum LockScope { + Exclusive, +} + +#[derive(Deserialize, Debug)] +#[serde(rename_all = "PascalCase")] +#[derive(PartialEq)] +enum LockType { + Write, +} + +#[cfg(test)] +mod tests { + use super::*; + use quick_xml::de::from_str; + + #[test] + fn test_lockentry() { + let xml = r#" + + + "#; + + let lockentry = from_str::(xml).unwrap(); + assert_eq!(lockentry.lockscope, LockScope::Exclusive); + assert_eq!(lockentry.locktype, LockType::Write); + } + + #[test] + fn test_supportedlock() { + let xml = r#" + + + + + "#; + + let supportedlock = from_str::(xml).unwrap(); + assert_eq!(supportedlock.lockentry.lockscope, LockScope::Exclusive); + assert_eq!(supportedlock.lockentry.locktype, LockType::Write); + } + + #[test] + fn test_propstat() { + let xml = r#" + + / + Tue, 07 Feb 2023 06:39:47 GMT + + + + + + + + + + HTTP/1.1 200 OK + "#; + + let propstat = from_str::(xml).unwrap(); + assert_eq!(propstat.prop.displayname, "/"); + assert_eq!( + propstat.prop.getlastmodified, + "Tue, 07 Feb 2023 06:39:47 GMT" + ); + assert_eq!(propstat.prop.resourcetype, ResourceType::Collection); + assert_eq!( + propstat.prop.supportedlock.lockentry.lockscope, + LockScope::Exclusive + ); + assert_eq!( + propstat.prop.supportedlock.lockentry.locktype, + LockType::Write + ); + assert_eq!(propstat.status, "HTTP/1.1 200 OK"); + } +} diff --git a/src/services/webdav/mod.rs b/src/services/webdav/mod.rs index ba8c6e5b3b39..1f44d4b5d9b2 100644 --- a/src/services/webdav/mod.rs +++ b/src/services/webdav/mod.rs @@ -16,3 +16,4 @@ mod backend; pub use backend::WebdavBuilder as Webdav; mod error; +mod list_response;