mirror of
https://github.com/lennart-k/rustical.git
synced 2025-12-14 08:12:24 +00:00
Migrate DAV props to serde. Big clusterfuck right now but it'll hopefully pay off
This commit is contained in:
@@ -1,13 +1,16 @@
|
||||
use std::{io::Write, str::FromStr};
|
||||
|
||||
use actix_web::{http::StatusCode, HttpRequest};
|
||||
use anyhow::{anyhow, Result};
|
||||
use async_trait::async_trait;
|
||||
use quick_xml::Writer;
|
||||
use rustical_auth::AuthInfo;
|
||||
use strum::VariantNames;
|
||||
use serde::Serialize;
|
||||
use std::str::FromStr;
|
||||
use strum::{EnumProperty, VariantNames};
|
||||
|
||||
use crate::xml_snippets::{write_invalid_props_response, write_propstat_response};
|
||||
use crate::{
|
||||
tagname::TagName,
|
||||
xml_snippets::{write_invalid_props_response, write_propstat_response},
|
||||
};
|
||||
|
||||
// A resource is identified by a URI and has properties
|
||||
// A resource can also be a collection
|
||||
@@ -17,7 +20,8 @@ use crate::xml_snippets::{write_invalid_props_response, write_propstat_response}
|
||||
pub trait Resource: Sized {
|
||||
type MemberType: Resource;
|
||||
type UriComponents: Sized; // defines how the resource URI maps to parameters, i.e. /{principal}/{calendar} -> (String, String)
|
||||
type PropType: FromStr + VariantNames;
|
||||
type PropType: FromStr + VariantNames + Into<&'static str> + EnumProperty + Clone;
|
||||
type PropResponse: Serialize;
|
||||
|
||||
async fn acquire_from_request(
|
||||
req: HttpRequest,
|
||||
@@ -32,7 +36,7 @@ pub trait Resource: Sized {
|
||||
fn list_dead_props() -> &'static [&'static str] {
|
||||
Self::PropType::VARIANTS
|
||||
}
|
||||
fn write_prop<W: Write>(&self, writer: &mut Writer<W>, prop: Self::PropType) -> Result<()>;
|
||||
fn get_prop(&self, prop: Self::PropType) -> Result<Self::PropResponse>;
|
||||
}
|
||||
|
||||
pub trait HandlePropfind {
|
||||
@@ -59,13 +63,12 @@ impl<R: Resource> HandlePropfind for R {
|
||||
for prop in props {
|
||||
if let Ok(valid_prop) = R::PropType::from_str(prop) {
|
||||
// TODO: Fix error types
|
||||
match self
|
||||
.write_prop(writer, valid_prop)
|
||||
.map_err(|_e| quick_xml::Error::TextNotFound)
|
||||
{
|
||||
// TODO: clean this mess up
|
||||
Ok(_) => {}
|
||||
// not really an invalid prop, but some error happened
|
||||
match self.get_prop(valid_prop.clone()) {
|
||||
Ok(response) => {
|
||||
writer
|
||||
.write_serializable(valid_prop.tagname(), &response)
|
||||
.map_err(|_e| quick_xml::Error::TextNotFound)?;
|
||||
}
|
||||
Err(_) => invalid_props.push(prop),
|
||||
};
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user