aerogramme/aero-dav/src/acldecoder.rs

85 lines
2.4 KiB
Rust
Raw Normal View History

2024-03-19 16:36:32 +00:00
use super::acltypes::*;
use super::error::ParsingError;
2024-05-16 15:38:34 +00:00
use super::types as dav;
use super::xml::{IRead, QRead, Reader, DAV_URN};
2024-03-19 16:36:32 +00:00
impl QRead<Property> for Property {
async fn qread(xml: &mut Reader<impl IRead>) -> Result<Self, ParsingError> {
if xml.maybe_open_start(DAV_URN, "owner").await?.is_some() {
let href = xml.find().await?;
xml.close().await?;
2024-05-16 15:38:34 +00:00
return Ok(Self::Owner(href));
2024-03-19 16:36:32 +00:00
}
2024-05-16 15:38:34 +00:00
if xml
.maybe_open_start(DAV_URN, "current-user-principal")
.await?
.is_some()
{
2024-03-19 16:36:32 +00:00
let user = xml.find().await?;
xml.close().await?;
2024-05-16 15:38:34 +00:00
return Ok(Self::CurrentUserPrincipal(user));
2024-03-19 16:36:32 +00:00
}
2024-05-16 15:38:34 +00:00
if xml
.maybe_open_start(DAV_URN, "current-user-privilege-set")
.await?
.is_some()
{
2024-03-19 16:36:32 +00:00
xml.close().await?;
2024-05-16 15:38:34 +00:00
return Ok(Self::CurrentUserPrivilegeSet(vec![]));
2024-03-19 16:36:32 +00:00
}
Err(ParsingError::Recoverable)
}
}
impl QRead<PropertyRequest> for PropertyRequest {
async fn qread(xml: &mut Reader<impl IRead>) -> Result<Self, ParsingError> {
if xml.maybe_open(DAV_URN, "owner").await?.is_some() {
xml.close().await?;
2024-05-16 15:38:34 +00:00
return Ok(Self::Owner);
2024-03-19 16:36:32 +00:00
}
2024-05-16 15:38:34 +00:00
if xml
.maybe_open(DAV_URN, "current-user-principal")
.await?
.is_some()
{
2024-03-19 16:36:32 +00:00
xml.close().await?;
2024-05-16 15:38:34 +00:00
return Ok(Self::CurrentUserPrincipal);
2024-03-19 16:36:32 +00:00
}
2024-05-16 15:38:34 +00:00
if xml
.maybe_open(DAV_URN, "current-user-privilege-set")
.await?
.is_some()
{
2024-03-19 16:36:32 +00:00
xml.close().await?;
2024-05-16 15:38:34 +00:00
return Ok(Self::CurrentUserPrivilegeSet);
2024-03-19 16:36:32 +00:00
}
Err(ParsingError::Recoverable)
}
}
impl QRead<ResourceType> for ResourceType {
async fn qread(xml: &mut Reader<impl IRead>) -> Result<Self, ParsingError> {
if xml.maybe_open(DAV_URN, "principal").await?.is_some() {
xml.close().await?;
2024-05-16 15:38:34 +00:00
return Ok(Self::Principal);
2024-03-19 16:36:32 +00:00
}
Err(ParsingError::Recoverable)
}
}
// -----
impl QRead<User> for User {
async fn qread(xml: &mut Reader<impl IRead>) -> Result<Self, ParsingError> {
if xml.maybe_open(DAV_URN, "unauthenticated").await?.is_some() {
xml.close().await?;
2024-05-16 15:38:34 +00:00
return Ok(Self::Unauthenticated);
2024-03-19 16:36:32 +00:00
}
dav::Href::qread(xml).await.map(Self::Authenticated)
}
}