Add initial carddav support

This commit is contained in:
Lennart
2024-10-27 14:10:01 +01:00
parent 30a795b816
commit 86feb4e189
30 changed files with 2094 additions and 94 deletions

View File

@@ -0,0 +1,68 @@
use crate::Error;
use actix_web::{
web::{Data, Path},
HttpRequest, Responder,
};
use addressbook_multiget::{handle_addressbook_multiget, AddressbookMultigetRequest};
use rustical_store::{auth::User, AddressbookStore};
use serde::{Deserialize, Serialize};
use sync_collection::{handle_sync_collection, SyncCollectionRequest};
use tokio::sync::RwLock;
use tracing::instrument;
mod addressbook_multiget;
mod sync_collection;
#[derive(Deserialize, Serialize, Clone, Debug)]
#[serde(rename_all = "kebab-case")]
pub enum PropQuery {
Allprop,
Prop,
Propname,
}
#[derive(Deserialize, Clone, Debug)]
#[serde(rename_all = "kebab-case")]
pub enum ReportRequest {
AddressbookMultiget(AddressbookMultigetRequest),
SyncCollection(SyncCollectionRequest),
}
#[instrument(skip(req, addr_store))]
pub async fn route_report_addressbook<AS: AddressbookStore + ?Sized>(
path: Path<(String, String)>,
body: String,
user: User,
req: HttpRequest,
addr_store: Data<RwLock<AS>>,
) -> Result<impl Responder, Error> {
let (principal, addressbook_id) = path.into_inner();
if principal != user.id {
return Err(Error::Unauthorized);
}
let request: ReportRequest = quick_xml::de::from_str(&body)?;
Ok(match request.clone() {
ReportRequest::AddressbookMultiget(addr_multiget) => {
handle_addressbook_multiget(
addr_multiget,
req,
&principal,
&addressbook_id,
&addr_store,
)
.await?
}
ReportRequest::SyncCollection(sync_collection) => {
handle_sync_collection(
sync_collection,
req,
&principal,
&addressbook_id,
&addr_store,
)
.await?
}
})
}