mirror of
https://github.com/lennart-k/rustical.git
synced 2025-12-13 20:32:48 +00:00
WIP: Complete work of propfind parsing
This commit is contained in:
@@ -10,7 +10,7 @@ use rustical_dav::{
|
||||
};
|
||||
use rustical_ical::AddressObject;
|
||||
use rustical_store::{AddressbookStore, auth::User};
|
||||
use rustical_xml::{EnumUnitVariants, EnumVariants, XmlDeserialize, XmlSerialize};
|
||||
use rustical_xml::{EnumVariants, PropName, XmlDeserialize, XmlSerialize};
|
||||
use serde::Deserialize;
|
||||
use std::sync::Arc;
|
||||
|
||||
@@ -21,7 +21,7 @@ pub struct AddressObjectResourceService<AS: AddressbookStore> {
|
||||
addr_store: Arc<AS>,
|
||||
}
|
||||
|
||||
#[derive(XmlDeserialize, XmlSerialize, PartialEq, Clone, EnumVariants, EnumUnitVariants)]
|
||||
#[derive(XmlDeserialize, XmlSerialize, PartialEq, Clone, EnumVariants, PropName)]
|
||||
#[xml(unit_variants_ident = "AddressObjectPropName")]
|
||||
pub enum AddressObjectProp {
|
||||
// WebDAV (RFC 2518)
|
||||
@@ -35,7 +35,7 @@ pub enum AddressObjectProp {
|
||||
AddressData(String),
|
||||
}
|
||||
|
||||
#[derive(XmlDeserialize, XmlSerialize, PartialEq, Clone, EnumVariants, EnumUnitVariants)]
|
||||
#[derive(XmlDeserialize, XmlSerialize, PartialEq, Clone, EnumVariants, PropName)]
|
||||
#[xml(unit_variants_ident = "AddressObjectPropWrapperName", untagged)]
|
||||
pub enum AddressObjectPropWrapper {
|
||||
AddressObject(AddressObjectProp),
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
use crate::{
|
||||
Error,
|
||||
address_object::resource::{AddressObjectPropWrapper, AddressObjectResource},
|
||||
address_object::resource::{
|
||||
AddressObjectPropWrapper, AddressObjectPropWrapperName, AddressObjectResource,
|
||||
},
|
||||
};
|
||||
use actix_web::{
|
||||
dev::{Path, ResourceDef},
|
||||
@@ -19,7 +21,7 @@ use rustical_xml::XmlDeserialize;
|
||||
#[xml(ns = "rustical_dav::namespace::NS_DAV")]
|
||||
pub struct AddressbookMultigetRequest {
|
||||
#[xml(ns = "rustical_dav::namespace::NS_DAV", ty = "untagged")]
|
||||
pub(crate) prop: PropfindType,
|
||||
pub(crate) prop: PropfindType<AddressObjectPropWrapperName>,
|
||||
#[xml(ns = "rustical_dav::namespace::NS_DAV", flatten)]
|
||||
pub(crate) href: Vec<String>,
|
||||
}
|
||||
@@ -59,7 +61,7 @@ pub async fn get_objects_addressbook_multiget<AS: AddressbookStore>(
|
||||
|
||||
pub async fn handle_addressbook_multiget<AS: AddressbookStore>(
|
||||
addr_multiget: &AddressbookMultigetRequest,
|
||||
props: &[&str],
|
||||
prop: &PropfindType<AddressObjectPropWrapperName>,
|
||||
path: &str,
|
||||
puri: &impl PrincipalUri,
|
||||
user: &User,
|
||||
@@ -79,7 +81,7 @@ pub async fn handle_addressbook_multiget<AS: AddressbookStore>(
|
||||
object,
|
||||
principal: principal.to_owned(),
|
||||
}
|
||||
.propfind(&path, props, puri, user)?,
|
||||
.propfind_typed(&path, prop, puri, user)?,
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
use crate::{CardDavPrincipalUri, Error};
|
||||
use crate::{CardDavPrincipalUri, Error, address_object::resource::AddressObjectPropWrapperName};
|
||||
use actix_web::{
|
||||
HttpRequest, Responder,
|
||||
web::{Data, Path},
|
||||
};
|
||||
use addressbook_multiget::{AddressbookMultigetRequest, handle_addressbook_multiget};
|
||||
use rustical_dav::xml::{PropElement, PropfindType, sync_collection::SyncCollectionRequest};
|
||||
use rustical_dav::xml::{PropfindType, sync_collection::SyncCollectionRequest};
|
||||
use rustical_store::{AddressbookStore, auth::User};
|
||||
use rustical_xml::{XmlDeserialize, XmlDocument};
|
||||
use sync_collection::handle_sync_collection;
|
||||
@@ -18,27 +18,14 @@ pub(crate) enum ReportRequest {
|
||||
#[xml(ns = "rustical_dav::namespace::NS_CARDDAV")]
|
||||
AddressbookMultiget(AddressbookMultigetRequest),
|
||||
#[xml(ns = "rustical_dav::namespace::NS_DAV")]
|
||||
SyncCollection(SyncCollectionRequest),
|
||||
SyncCollection(SyncCollectionRequest<AddressObjectPropWrapperName>),
|
||||
}
|
||||
|
||||
impl ReportRequest {
|
||||
fn props(&self) -> Vec<&str> {
|
||||
let prop_element = match self {
|
||||
fn props(&self) -> &PropfindType<AddressObjectPropWrapperName> {
|
||||
match self {
|
||||
ReportRequest::AddressbookMultiget(AddressbookMultigetRequest { prop, .. }) => prop,
|
||||
ReportRequest::SyncCollection(SyncCollectionRequest { prop, .. }) => prop,
|
||||
};
|
||||
|
||||
match prop_element {
|
||||
PropfindType::Allprop => {
|
||||
vec!["allprop"]
|
||||
}
|
||||
PropfindType::Propname => {
|
||||
vec!["propname"]
|
||||
}
|
||||
PropfindType::Prop(PropElement(prop_tags)) => prop_tags
|
||||
.iter()
|
||||
.map(|propname| propname.name.as_str())
|
||||
.collect(),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -58,13 +45,12 @@ pub async fn route_report_addressbook<AS: AddressbookStore>(
|
||||
}
|
||||
|
||||
let request = ReportRequest::parse_str(&body)?;
|
||||
let props = request.props();
|
||||
|
||||
Ok(match &request {
|
||||
ReportRequest::AddressbookMultiget(addr_multiget) => {
|
||||
handle_addressbook_multiget(
|
||||
addr_multiget,
|
||||
&props,
|
||||
request.props(),
|
||||
req.path(),
|
||||
puri.as_ref(),
|
||||
&user,
|
||||
@@ -77,7 +63,6 @@ pub async fn route_report_addressbook<AS: AddressbookStore>(
|
||||
ReportRequest::SyncCollection(sync_collection) => {
|
||||
handle_sync_collection(
|
||||
sync_collection,
|
||||
&props,
|
||||
req.path(),
|
||||
puri.as_ref(),
|
||||
&user,
|
||||
@@ -92,9 +77,9 @@ pub async fn route_report_addressbook<AS: AddressbookStore>(
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use rustical_dav::xml::{PropElement, Propname, sync_collection::SyncLevel};
|
||||
|
||||
use super::*;
|
||||
use crate::address_object::resource::AddressObjectPropName;
|
||||
use rustical_dav::xml::{PropElement, sync_collection::SyncLevel};
|
||||
|
||||
#[test]
|
||||
fn test_xml_sync_collection() {
|
||||
@@ -115,10 +100,12 @@ mod tests {
|
||||
ReportRequest::SyncCollection(SyncCollectionRequest {
|
||||
sync_token: "".to_owned(),
|
||||
sync_level: SyncLevel::One,
|
||||
prop: rustical_dav::xml::PropfindType::Prop(PropElement(vec![Propname {
|
||||
name: "getetag".to_owned(),
|
||||
ns: Some("DAV:".into())
|
||||
}])),
|
||||
prop: rustical_dav::xml::PropfindType::Prop(PropElement(
|
||||
vec![AddressObjectPropWrapperName::AddressObject(
|
||||
AddressObjectPropName::Getetag
|
||||
)],
|
||||
vec![]
|
||||
)),
|
||||
limit: None
|
||||
})
|
||||
)
|
||||
@@ -141,9 +128,13 @@ mod tests {
|
||||
report_request,
|
||||
ReportRequest::AddressbookMultiget(AddressbookMultigetRequest {
|
||||
prop: rustical_dav::xml::PropfindType::Prop(PropElement(vec![
|
||||
Propname{name: "getetag".to_owned(), ns: Some("DAV:".into())},
|
||||
Propname{name: "address-data".to_owned(), ns: Some("urn:ietf:params:xml:ns:carddav".into())}
|
||||
])),
|
||||
AddressObjectPropWrapperName::AddressObject(
|
||||
AddressObjectPropName::Getetag
|
||||
),
|
||||
AddressObjectPropWrapperName::AddressObject(
|
||||
AddressObjectPropName::AddressData
|
||||
),
|
||||
], vec![])),
|
||||
href: vec![
|
||||
"/carddav/user/user/6f787542-5256-401a-8db97003260da/ae7a998fdfd1d84a20391168962c62b".to_owned()
|
||||
]
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
use crate::{
|
||||
Error,
|
||||
address_object::resource::{AddressObjectPropWrapper, AddressObjectResource},
|
||||
address_object::resource::{
|
||||
AddressObjectPropWrapper, AddressObjectPropWrapperName, AddressObjectResource,
|
||||
},
|
||||
};
|
||||
use actix_web::http::StatusCode;
|
||||
use rustical_dav::{
|
||||
@@ -16,8 +18,7 @@ use rustical_store::{
|
||||
};
|
||||
|
||||
pub async fn handle_sync_collection<AS: AddressbookStore>(
|
||||
sync_collection: &SyncCollectionRequest,
|
||||
props: &[&str],
|
||||
sync_collection: &SyncCollectionRequest<AddressObjectPropWrapperName>,
|
||||
path: &str,
|
||||
puri: &impl PrincipalUri,
|
||||
user: &User,
|
||||
@@ -38,7 +39,7 @@ pub async fn handle_sync_collection<AS: AddressbookStore>(
|
||||
object,
|
||||
principal: principal.to_owned(),
|
||||
}
|
||||
.propfind(&path, props, puri, user)?,
|
||||
.propfind_typed(&path, &sync_collection.prop, puri, user)?,
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@ use rustical_dav::xml::{Resourcetype, ResourcetypeInner};
|
||||
use rustical_dav_push::{DavPushExtension, DavPushExtensionProp};
|
||||
use rustical_store::auth::User;
|
||||
use rustical_store::{Addressbook, AddressbookStore, SubscriptionStore};
|
||||
use rustical_xml::{EnumUnitVariants, EnumVariants, XmlDeserialize, XmlSerialize};
|
||||
use rustical_xml::{EnumVariants, PropName, XmlDeserialize, XmlSerialize};
|
||||
use std::str::FromStr;
|
||||
use std::sync::Arc;
|
||||
|
||||
@@ -35,7 +35,7 @@ impl<A: AddressbookStore, S: SubscriptionStore> AddressbookResourceService<A, S>
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(XmlDeserialize, XmlSerialize, PartialEq, Clone, EnumVariants, EnumUnitVariants)]
|
||||
#[derive(XmlDeserialize, XmlSerialize, PartialEq, Clone, EnumVariants, PropName)]
|
||||
#[xml(unit_variants_ident = "AddressbookPropName")]
|
||||
pub enum AddressbookProp {
|
||||
// WebDAV (RFC 2518)
|
||||
@@ -53,7 +53,7 @@ pub enum AddressbookProp {
|
||||
MaxResourceSize(i64),
|
||||
}
|
||||
|
||||
#[derive(XmlDeserialize, XmlSerialize, PartialEq, Clone, EnumVariants, EnumUnitVariants)]
|
||||
#[derive(XmlDeserialize, XmlSerialize, PartialEq, Clone, EnumVariants, PropName)]
|
||||
#[xml(unit_variants_ident = "AddressbookPropWrapperName", untagged)]
|
||||
pub enum AddressbookPropWrapper {
|
||||
Addressbook(AddressbookProp),
|
||||
|
||||
@@ -8,7 +8,7 @@ use rustical_dav::resource::{PrincipalUri, Resource, ResourceService};
|
||||
use rustical_dav::xml::{HrefElement, Resourcetype, ResourcetypeInner};
|
||||
use rustical_store::auth::{AuthenticationProvider, User};
|
||||
use rustical_store::{AddressbookStore, SubscriptionStore};
|
||||
use rustical_xml::{EnumUnitVariants, EnumVariants, XmlDeserialize, XmlSerialize};
|
||||
use rustical_xml::{EnumVariants, PropName, XmlDeserialize, XmlSerialize};
|
||||
use std::sync::Arc;
|
||||
|
||||
pub struct PrincipalResourceService<
|
||||
@@ -53,7 +53,7 @@ pub struct PrincipalResource {
|
||||
#[derive(XmlDeserialize, XmlSerialize, PartialEq, Clone)]
|
||||
pub struct AddressbookHomeSet(#[xml(ty = "untagged", flatten)] Vec<HrefElement>);
|
||||
|
||||
#[derive(XmlDeserialize, XmlSerialize, PartialEq, Clone, EnumVariants, EnumUnitVariants)]
|
||||
#[derive(XmlDeserialize, XmlSerialize, PartialEq, Clone, EnumVariants, PropName)]
|
||||
#[xml(unit_variants_ident = "PrincipalPropName")]
|
||||
pub enum PrincipalProp {
|
||||
#[xml(ns = "rustical_dav::namespace::NS_DAV")]
|
||||
@@ -71,7 +71,7 @@ pub enum PrincipalProp {
|
||||
PrincipalAddress(Option<HrefElement>),
|
||||
}
|
||||
|
||||
#[derive(XmlDeserialize, XmlSerialize, PartialEq, Clone, EnumVariants, EnumUnitVariants)]
|
||||
#[derive(XmlDeserialize, XmlSerialize, PartialEq, Clone, EnumVariants, PropName)]
|
||||
#[xml(unit_variants_ident = "PrincipalPropWrapperName", untagged)]
|
||||
pub enum PrincipalPropWrapper {
|
||||
Principal(PrincipalProp),
|
||||
|
||||
Reference in New Issue
Block a user