From 5f194bbeb410f1f9a43e83acae8ec64e9a7c95da Mon Sep 17 00:00:00 2001 From: Lennart <18233294+lennart-k@users.noreply.github.com> Date: Wed, 29 May 2024 17:00:19 +0200 Subject: [PATCH] Preparation of a carddav crate --- Cargo.lock | 24 ++++++++++++++++++++++++ Cargo.toml | 1 + crates/carddav/Cargo.toml | 27 +++++++++++++++++++++++++++ crates/carddav/src/lib.rs | 24 ++++++++++++++++++++++++ src/app.rs | 16 +++++++++++++--- 5 files changed, 89 insertions(+), 3 deletions(-) create mode 100644 crates/carddav/Cargo.toml create mode 100644 crates/carddav/src/lib.rs diff --git a/Cargo.lock b/Cargo.lock index 876fc7e..0fab189 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1718,6 +1718,7 @@ dependencies = [ "env_logger", "rustical_auth", "rustical_caldav", + "rustical_carddav", "rustical_store", "serde", "sqlx", @@ -1761,6 +1762,29 @@ dependencies = [ "tokio", ] +[[package]] +name = "rustical_carddav" +version = "0.1.0" +dependencies = [ + "actix-web", + "actix-web-httpauth", + "anyhow", + "async-trait", + "base64 0.22.1", + "derive_more", + "futures-util", + "quick-xml", + "roxmltree", + "rustical_auth", + "rustical_dav", + "rustical_store", + "serde", + "serde_json", + "strum", + "thiserror", + "tokio", +] + [[package]] name = "rustical_dav" version = "0.1.0" diff --git a/Cargo.toml b/Cargo.toml index 6305ee8..878cc44 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,6 +11,7 @@ members = ["crates/*"] rustical_store = { path = "./crates/store/" } rustical_auth = { path = "./crates/auth/" } rustical_caldav = { path = "./crates/caldav/" } +rustical_carddav = { path = "./crates/carddav/" } serde = { version = "1.0", features = ["derive"] } tokio = { version = "1.35", features = [ "net", diff --git a/crates/carddav/Cargo.toml b/crates/carddav/Cargo.toml new file mode 100644 index 0000000..fb07c09 --- /dev/null +++ b/crates/carddav/Cargo.toml @@ -0,0 +1,27 @@ +[package] +name = "rustical_carddav" +version = "0.1.0" +edition = "2021" + +[dependencies] +actix-web = "4.4" +actix-web-httpauth = "0.8" +anyhow = { version = "1.0", features = ["backtrace"] } +base64 = "0.22" +derive_more = "0.99" +futures-util = "0.3" +quick-xml = { version = "0.31", features = [ + "serde", + "serde-types", + "serialize", +] } +roxmltree = "0.20" +rustical_store = { path = "../store/" } +rustical_dav = { path = "../dav/" } +rustical_auth = { path = "../auth/" } +serde = { version = "1.0", features = ["serde_derive", "derive"] } +serde_json = "1.0" +tokio = { version = "1.35", features = ["sync", "full"] } +async-trait = "0.1" +thiserror = "1.0" +strum = { version = "0.26.2", features = ["strum_macros", "derive"] } diff --git a/crates/carddav/src/lib.rs b/crates/carddav/src/lib.rs new file mode 100644 index 0000000..60987ea --- /dev/null +++ b/crates/carddav/src/lib.rs @@ -0,0 +1,24 @@ +use actix_web::{web, HttpResponse, Responder}; +use rustical_auth::CheckAuthentication; +use std::sync::Arc; + +pub fn configure_well_known(cfg: &mut web::ServiceConfig, carddav_root: String) { + cfg.service(web::redirect("/carddav", carddav_root).permanent()); +} + +pub fn configure_dav( + cfg: &mut web::ServiceConfig, + prefix: String, + auth: Arc, +) { +} + +async fn options_handler() -> impl Responder { + HttpResponse::Ok() + .insert_header(( + "Allow", + "OPTIONS, GET, HEAD, POST, PUT, REPORT, PROPFIND, PROPPATCH, MKCOL", + )) + .insert_header(("DAV", "1, 2, 3, addressbook, extended-mkcol")) + .body("options") +} diff --git a/src/app.rs b/src/app.rs index 8f1bd59..1c99074 100644 --- a/src/app.rs +++ b/src/app.rs @@ -5,7 +5,6 @@ use actix_web::dev::{ServiceFactory, ServiceRequest, ServiceResponse}; use actix_web::middleware::{Logger, NormalizePath}; use actix_web::{web, App}; use rustical_auth::CheckAuthentication; -use rustical_caldav::{configure_dav, configure_well_known}; use rustical_store::calendar::CalendarStore; use tokio::sync::RwLock; @@ -25,10 +24,21 @@ pub fn make_app( .wrap(Logger::new("[%s] %r")) .wrap(NormalizePath::trim()) .service(web::scope("/caldav").configure(|cfg| { - configure_dav(cfg, "/caldav".to_string(), auth.clone(), cal_store.clone()) + rustical_caldav::configure_dav( + cfg, + "/caldav".to_string(), + auth.clone(), + cal_store.clone(), + ) + })) + .service(web::scope("/carddav").configure(|cfg| { + rustical_carddav::configure_dav(cfg, "/carddav".to_string(), auth.clone()) })) .service( web::scope("/.well-known") - .configure(|cfg| configure_well_known(cfg, "/caldav".to_string())), + .configure(|cfg| rustical_caldav::configure_well_known(cfg, "/caldav".to_string())) + .configure(|cfg| { + rustical_carddav::configure_well_known(cfg, "/carddav".to_string()) + }), ) }