Preparation of a carddav crate

This commit is contained in:
Lennart
2024-05-29 17:00:19 +02:00
parent 3e1e289350
commit 5f194bbeb4
5 changed files with 89 additions and 3 deletions

24
Cargo.lock generated
View File

@@ -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"

View File

@@ -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",

27
crates/carddav/Cargo.toml Normal file
View File

@@ -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"] }

24
crates/carddav/src/lib.rs Normal file
View File

@@ -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<A: CheckAuthentication>(
cfg: &mut web::ServiceConfig,
prefix: String,
auth: Arc<A>,
) {
}
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")
}

View File

@@ -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<CS: CalendarStore + ?Sized, A: CheckAuthentication>(
.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())
}),
)
}