Compare commits

..

16 Commits

Author SHA1 Message Date
Lennart K
200d5e7170 Update ical-rs 2026-01-13 16:01:59 +01:00
Lennart K
5cb538d3fb build MVP for birthday calendar 2026-01-13 12:41:03 +01:00
Lennart K
d9da123ff4 Remove calendar-query integration test for now 2026-01-12 14:06:23 +01:00
Lennart K
eba2f0da9f update ical-rs 2026-01-12 14:04:35 +01:00
Lennart K
291bd967da Re-add get_last_occurence for sqlite store 2026-01-09 10:32:50 +01:00
Lennart K
002814a564 Remove unused code 2026-01-08 23:24:47 +01:00
Lennart K
ba13aaa703 Re-implement calendar imports 2026-01-08 23:17:39 +01:00
Lennart K
7a02bfeffc Calendar export: Fix PRODID 2026-01-08 16:17:39 +01:00
Lennart K
1b69148d6f Re-implement calendar export 2026-01-08 15:36:02 +01:00
Lennart K
f4de80c6b9 clean up ical-related stuff 2026-01-08 14:31:28 +01:00
Lennart K
7a1ec3e351 make calendar object id extrinsic 2026-01-07 13:14:50 +01:00
Lennart K
eb7bdd0018 Make AddressObject object_id an extrinsic property 2026-01-07 12:19:30 +01:00
Lennart K
8e583e24cb small fixes 2026-01-07 11:58:02 +01:00
Lennart K
5e5017a185 Decrease folder nesting 2026-01-07 11:46:28 +01:00
Lennart K
3c87191f69 incorporate get_first_occurenec 2026-01-07 11:44:55 +01:00
Lennart K
d1947a159b migrate to new ical-rs version 2026-01-07 11:32:53 +01:00
71 changed files with 446 additions and 1029 deletions

View File

@@ -2,10 +2,7 @@ name: Docker
on: on:
push: push:
branches: branches: ["main"]
- main
- dev
- feat/*
release: release:
types: ["published"] types: ["published"]
@@ -48,8 +45,7 @@ jobs:
with: with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: | tags: |
${{ github.ref_name == 'main' && 'type=ref,event=branch' || '' }} type=ref,event=branch
type=ref,event=branch,prefix=br-
type=ref,event=pr type=ref,event=pr
type=semver,pattern={{version}} type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}} type=semver,pattern={{major}}.{{minor}}

View File

@@ -1,12 +0,0 @@
{
"db_name": "SQLite",
"query": "DELETE FROM calendarobjectchangelog WHERE (principal, cal_id, object_id) = (?, ?, ?);",
"describe": {
"columns": [],
"parameters": {
"Right": 3
},
"nullable": []
},
"hash": "146e23ae4e0eaae4d65ac7563c67d4f295ccc2534dcc4b3bd710de773ed137f9"
}

View File

@@ -1,12 +0,0 @@
{
"db_name": "SQLite",
"query": "UPDATE calendarobjects SET ics = ? WHERE (principal, cal_id, id) = (?, ?, ?);",
"describe": {
"columns": [],
"parameters": {
"Right": 4
},
"nullable": []
},
"hash": "354decac84758c88280f60fbf0f93dddc6c7ff92ac7b8ba44049d31df3c680e3"
}

View File

@@ -1,38 +0,0 @@
{
"db_name": "SQLite",
"query": "SELECT principal, cal_id, id, ics FROM calendarobjects WHERE ics LIKE '%VERSION:4.0%';",
"describe": {
"columns": [
{
"name": "principal",
"ordinal": 0,
"type_info": "Text"
},
{
"name": "cal_id",
"ordinal": 1,
"type_info": "Text"
},
{
"name": "id",
"ordinal": 2,
"type_info": "Text"
},
{
"name": "ics",
"ordinal": 3,
"type_info": "Text"
}
],
"parameters": {
"Right": 0
},
"nullable": [
false,
false,
false,
false
]
},
"hash": "bdaa4bee8b01d0e3773e34672ed4805d1e71d24888f2227045afd90bf080fc23"
}

274
Cargo.lock generated
View File

@@ -181,9 +181,9 @@ dependencies = [
[[package]] [[package]]
name = "askama_web" name = "askama_web"
version = "0.15.1" version = "0.15.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5911a65ac3916ef133167a855d52978f9fbf54680a093e0ef29e20b7e94a4523" checksum = "c0d6576f8e59513752a3e2673ca602fb403be7d0d0aacba5cd8b219838ab58fe"
dependencies = [ dependencies = [
"askama", "askama",
"askama_web_derive", "askama_web_derive",
@@ -565,24 +565,6 @@ version = "1.11.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b35204fbdc0b3f4446b89fc1ac2cf84a8a68971995d0bf2e925ec7cd960f9cb3" checksum = "b35204fbdc0b3f4446b89fc1ac2cf84a8a68971995d0bf2e925ec7cd960f9cb3"
[[package]]
name = "caldata"
version = "0.13.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5549ae654c8e80ff922297ad06c49be64668cf947cb6ce45a2069985d21a2135"
dependencies = [
"chrono",
"chrono-tz",
"derive_more",
"itertools 0.14.0",
"lazy_static",
"phf 0.13.1",
"regex",
"rrule",
"thiserror 2.0.18",
"vtimezones-rs",
]
[[package]] [[package]]
name = "cast" name = "cast"
version = "0.3.0" version = "0.3.0"
@@ -591,9 +573,9 @@ checksum = "37b2a672a2cb129a2e41c10b1224bb368f9f37a2b16b612598138befd7b37eb5"
[[package]] [[package]]
name = "cc" name = "cc"
version = "1.2.54" version = "1.2.52"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6354c81bbfd62d9cfa9cb3c773c2b7b2a3a482d569de977fd0e961f6e7c00583" checksum = "cd4932aefd12402b36c60956a4fe0035421f544799057659ff86f923657aada3"
dependencies = [ dependencies = [
"find-msvc-tools", "find-msvc-tools",
"shlex", "shlex",
@@ -613,9 +595,9 @@ checksum = "613afe47fcd5fac7ccf1db93babcb082c5994d996f20b8b159f2ad1658eb5724"
[[package]] [[package]]
name = "chrono" name = "chrono"
version = "0.4.43" version = "0.4.42"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fac4744fb15ae8337dc853fee7fb3f4e48c0fbaa23d0afe49c447b4fab126118" checksum = "145052bdd345b87320e369255277e3fb5152762ad123a901ef5c262dd38fe8d2"
dependencies = [ dependencies = [
"iana-time-zone", "iana-time-zone",
"js-sys", "js-sys",
@@ -1259,9 +1241,9 @@ dependencies = [
[[package]] [[package]]
name = "find-msvc-tools" name = "find-msvc-tools"
version = "0.1.8" version = "0.1.7"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8591b0bcc8a98a64310a2fae1bb3e9b8564dd10e381e6e28010fde8e8e8568db" checksum = "f449e6c6c08c865631d4890cfacf252b3d396c9bcc83adb6623cdb02a8336c41"
[[package]] [[package]]
name = "flume" name = "flume"
@@ -1786,6 +1768,22 @@ dependencies = [
"cc", "cc",
] ]
[[package]]
name = "ical"
version = "0.11.0"
source = "git+https://github.com/lennart-k/ical-rs?branch=dev#ece5b95ddc20f89d14e162aba3a49038f9989701"
dependencies = [
"chrono",
"chrono-tz",
"derive_more",
"itertools 0.14.0",
"lazy_static",
"phf 0.13.1",
"regex",
"rrule",
"thiserror 2.0.17",
]
[[package]] [[package]]
name = "icu_collections" name = "icu_collections"
version = "2.1.1" version = "2.1.1"
@@ -1925,9 +1923,9 @@ checksum = "c8fae54786f62fb2918dcfae3d568594e50eb9b5c25bf04371af6fe7516452fb"
[[package]] [[package]]
name = "insta" name = "insta"
version = "1.46.1" version = "1.46.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "248b42847813a1550dafd15296fd9748c651d0c32194559dbc05d804d54b21e8" checksum = "1b66886d14d18d420ab5052cbff544fc5d34d0b2cdd35eb5976aaa10a4a472e5"
dependencies = [ dependencies = [
"console", "console",
"once_cell", "once_cell",
@@ -1993,9 +1991,9 @@ checksum = "92ecc6618181def0457392ccd0ee51198e065e016d1d527a7ac1b6dc7c1f09d2"
[[package]] [[package]]
name = "js-sys" name = "js-sys"
version = "0.3.85" version = "0.3.83"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8c942ebf8e95485ca0d52d97da7c5a2c387d0e7f0ba4c35e93bfcaee045955b3" checksum = "464a3709c7f55f1f721e5389aa6ea4e3bc6aba669353300af094b29ffbdde1d8"
dependencies = [ dependencies = [
"once_cell", "once_cell",
"wasm-bindgen", "wasm-bindgen",
@@ -2027,9 +2025,9 @@ checksum = "bcc35a38544a891a5f7c865aca548a982ccb3b8650a5b06d0fd33a10283c56fc"
[[package]] [[package]]
name = "libm" name = "libm"
version = "0.2.16" version = "0.2.15"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b6d2cec3eae94f9f509c767b45932f1ada8350c4bdb85af2fcab4a3c14807981" checksum = "f9fbbcab51052fe104eb5e5d351cf728d30a5be1fe14d9be8a3b097481fb97de"
[[package]] [[package]]
name = "libredox" name = "libredox"
@@ -2120,7 +2118,7 @@ dependencies = [
"matchit 0.9.1", "matchit 0.9.1",
"percent-encoding", "percent-encoding",
"serde", "serde",
"thiserror 2.0.18", "thiserror 2.0.17",
] ]
[[package]] [[package]]
@@ -2202,9 +2200,9 @@ dependencies = [
[[package]] [[package]]
name = "num-conv" name = "num-conv"
version = "0.2.0" version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cf97ec579c3c42f953ef76dbf8d55ac91fb219dde70e49aa4a6b7d74e9919050" checksum = "51d515d32fb182ee37cda2ccdcb92950d6a3c2893aa280e540671c2cd0f3b1d9"
[[package]] [[package]]
name = "num-integer" name = "num-integer"
@@ -2372,7 +2370,7 @@ dependencies = [
"futures-sink", "futures-sink",
"js-sys", "js-sys",
"pin-project-lite", "pin-project-lite",
"thiserror 2.0.18", "thiserror 2.0.17",
"tracing", "tracing",
] ]
@@ -2402,7 +2400,7 @@ dependencies = [
"opentelemetry_sdk", "opentelemetry_sdk",
"prost", "prost",
"reqwest", "reqwest",
"thiserror 2.0.18", "thiserror 2.0.17",
"tokio", "tokio",
"tonic", "tonic",
"tracing", "tracing",
@@ -2439,7 +2437,7 @@ dependencies = [
"opentelemetry", "opentelemetry",
"percent-encoding", "percent-encoding",
"rand 0.9.2", "rand 0.9.2",
"thiserror 2.0.18", "thiserror 2.0.17",
"tokio", "tokio",
"tokio-stream", "tokio-stream",
] ]
@@ -2612,12 +2610,22 @@ dependencies = [
[[package]] [[package]]
name = "phf_codegen" name = "phf_codegen"
version = "0.13.1" version = "0.12.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "49aa7f9d80421bca176ca8dbfebe668cc7a2684708594ec9f3c0db0805d5d6e1" checksum = "efbdcb6f01d193b17f0b9c3360fa7e0e620991b193ff08702f78b3ce365d7e61"
dependencies = [ dependencies = [
"phf_generator", "phf_generator 0.12.1",
"phf_shared 0.13.1", "phf_shared 0.12.1",
]
[[package]]
name = "phf_generator"
version = "0.12.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2cbb1126afed61dd6368748dae63b1ee7dc480191c6262a3b4ff1e29d86a6c5b"
dependencies = [
"fastrand",
"phf_shared 0.12.1",
] ]
[[package]] [[package]]
@@ -2636,7 +2644,7 @@ version = "0.13.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "812f032b54b1e759ccd5f8b6677695d5268c588701effba24601f6932f8269ef" checksum = "812f032b54b1e759ccd5f8b6677695d5268c588701effba24601f6932f8269ef"
dependencies = [ dependencies = [
"phf_generator", "phf_generator 0.13.1",
"phf_shared 0.13.1", "phf_shared 0.13.1",
"proc-macro2", "proc-macro2",
"quote", "quote",
@@ -2817,9 +2825,9 @@ dependencies = [
[[package]] [[package]]
name = "proc-macro2" name = "proc-macro2"
version = "1.0.106" version = "1.0.105"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8fd00f0bb2e90d81d1044c2b32617f68fcb9fa3bb7640c23e9c748e53fb30934" checksum = "535d180e0ecab6268a3e718bb9fd44db66bbbc256257165fc699dadf70d16fe7"
dependencies = [ dependencies = [
"unicode-ident", "unicode-ident",
] ]
@@ -2862,9 +2870,9 @@ dependencies = [
[[package]] [[package]]
name = "quick-xml" name = "quick-xml"
version = "0.39.0" version = "0.38.4"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f2e3bf4aa9d243beeb01a7b3bc30b77cfe2c44e24ec02d751a7104a53c2c49a1" checksum = "b66c2058c55a409d601666cffe35f04333cf1013010882cec174a7467cd4e21c"
dependencies = [ dependencies = [
"memchr", "memchr",
] ]
@@ -2883,7 +2891,7 @@ dependencies = [
"rustc-hash", "rustc-hash",
"rustls", "rustls",
"socket2", "socket2",
"thiserror 2.0.18", "thiserror 2.0.17",
"tokio", "tokio",
"tracing", "tracing",
"web-time", "web-time",
@@ -2904,7 +2912,7 @@ dependencies = [
"rustls", "rustls",
"rustls-pki-types", "rustls-pki-types",
"slab", "slab",
"thiserror 2.0.18", "thiserror 2.0.17",
"tinyvec", "tinyvec",
"tracing", "tracing",
"web-time", "web-time",
@@ -2926,9 +2934,9 @@ dependencies = [
[[package]] [[package]]
name = "quote" name = "quote"
version = "1.0.44" version = "1.0.43"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "21b2ebcf727b7760c461f091f9f0f539b77b8e87f2fd88131e7f1b433b3cece4" checksum = "dc74d9a594b72ae6656596548f56f667211f8a97b3d4c3d467150794690dc40a"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
] ]
@@ -3179,7 +3187,7 @@ dependencies = [
"chrono-tz", "chrono-tz",
"log", "log",
"regex", "regex",
"thiserror 2.0.18", "thiserror 2.0.17",
] ]
[[package]] [[package]]
@@ -3254,9 +3262,9 @@ dependencies = [
[[package]] [[package]]
name = "rust-embed" name = "rust-embed"
version = "8.11.0" version = "8.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "04113cb9355a377d83f06ef1f0a45b8ab8cd7d8b1288160717d66df5c7988d27" checksum = "947d7f3fad52b283d261c4c99a084937e2fe492248cb9a68a8435a861b8798ca"
dependencies = [ dependencies = [
"rust-embed-impl", "rust-embed-impl",
"rust-embed-utils", "rust-embed-utils",
@@ -3265,9 +3273,9 @@ dependencies = [
[[package]] [[package]]
name = "rust-embed-impl" name = "rust-embed-impl"
version = "8.11.0" version = "8.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "da0902e4c7c8e997159ab384e6d0fc91c221375f6894346ae107f47dd0f3ccaa" checksum = "5fa2c8c9e8711e10f9c4fd2d64317ef13feaab820a4c51541f1a8c8e2e851ab2"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
@@ -3278,9 +3286,9 @@ dependencies = [
[[package]] [[package]]
name = "rust-embed-utils" name = "rust-embed-utils"
version = "8.11.0" version = "8.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5bcdef0be6fe7f6fa333b1073c949729274b05f123a0ad7efcb8efd878e5c3b1" checksum = "60b161f275cb337fe0a44d924a5f4df0ed69c2c39519858f931ce61c779d3475"
dependencies = [ dependencies = [
"sha2", "sha2",
"walkdir", "walkdir",
@@ -3288,9 +3296,9 @@ dependencies = [
[[package]] [[package]]
name = "rustc-demangle" name = "rustc-demangle"
version = "0.1.27" version = "0.1.26"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b50b8869d9fc858ce7266cce0194bd74df58b9d0e3f6df3a9fc8eb470d95c09d" checksum = "56f7d92ca342cea22a06f2121d944b4fd82af56988c270852495420f961d4ace"
[[package]] [[package]]
name = "rustc-hash" name = "rustc-hash"
@@ -3309,14 +3317,13 @@ dependencies = [
[[package]] [[package]]
name = "rustical" name = "rustical"
version = "0.12.2" version = "0.11.10"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"argon2", "argon2",
"async-trait", "async-trait",
"axum", "axum",
"axum-extra", "axum-extra",
"caldata",
"clap", "clap",
"figment", "figment",
"headers", "headers",
@@ -3341,7 +3348,6 @@ dependencies = [
"rustical_store", "rustical_store",
"rustical_store_sqlite", "rustical_store_sqlite",
"serde", "serde",
"similar-asserts",
"sqlx", "sqlx",
"tokio", "tokio",
"toml 0.9.11+spec-1.1.0", "toml 0.9.11+spec-1.1.0",
@@ -3356,20 +3362,20 @@ dependencies = [
[[package]] [[package]]
name = "rustical_caldav" name = "rustical_caldav"
version = "0.12.2" version = "0.11.10"
dependencies = [ dependencies = [
"async-std", "async-std",
"async-trait", "async-trait",
"axum", "axum",
"axum-extra", "axum-extra",
"base64 0.22.1", "base64 0.22.1",
"caldata",
"chrono", "chrono",
"chrono-tz", "chrono-tz",
"derive_more", "derive_more",
"futures-util", "futures-util",
"headers", "headers",
"http", "http",
"ical",
"insta", "insta",
"percent-encoding", "percent-encoding",
"quick-xml", "quick-xml",
@@ -3386,7 +3392,7 @@ dependencies = [
"similar-asserts", "similar-asserts",
"strum", "strum",
"strum_macros", "strum_macros",
"thiserror 2.0.18", "thiserror 2.0.17",
"tokio", "tokio",
"tower", "tower",
"tower-http", "tower-http",
@@ -3398,17 +3404,17 @@ dependencies = [
[[package]] [[package]]
name = "rustical_carddav" name = "rustical_carddav"
version = "0.12.2" version = "0.11.10"
dependencies = [ dependencies = [
"async-trait", "async-trait",
"axum", "axum",
"axum-extra", "axum-extra",
"base64 0.22.1", "base64 0.22.1",
"caldata",
"chrono", "chrono",
"derive_more", "derive_more",
"futures-util", "futures-util",
"http", "http",
"ical",
"insta", "insta",
"percent-encoding", "percent-encoding",
"quick-xml", "quick-xml",
@@ -3421,7 +3427,7 @@ dependencies = [
"serde", "serde",
"strum", "strum",
"strum_macros", "strum_macros",
"thiserror 2.0.18", "thiserror 2.0.17",
"tokio", "tokio",
"tower", "tower",
"tower-http", "tower-http",
@@ -3432,16 +3438,16 @@ dependencies = [
[[package]] [[package]]
name = "rustical_dav" name = "rustical_dav"
version = "0.12.2" version = "0.11.10"
dependencies = [ dependencies = [
"async-trait", "async-trait",
"axum", "axum",
"axum-extra", "axum-extra",
"caldata",
"derive_more", "derive_more",
"futures-util", "futures-util",
"headers", "headers",
"http", "http",
"ical",
"itertools 0.14.0", "itertools 0.14.0",
"log", "log",
"matchit 0.9.1", "matchit 0.9.1",
@@ -3450,7 +3456,7 @@ dependencies = [
"rustical_xml", "rustical_xml",
"serde", "serde",
"strum", "strum",
"thiserror 2.0.18", "thiserror 2.0.17",
"tokio", "tokio",
"tower", "tower",
"tracing", "tracing",
@@ -3458,7 +3464,7 @@ dependencies = [
[[package]] [[package]]
name = "rustical_dav_push" name = "rustical_dav_push"
version = "0.12.2" version = "0.11.10"
dependencies = [ dependencies = [
"async-trait", "async-trait",
"axum", "axum",
@@ -3476,14 +3482,14 @@ dependencies = [
"rustical_store", "rustical_store",
"rustical_xml", "rustical_xml",
"serde", "serde",
"thiserror 2.0.18", "thiserror 2.0.17",
"tokio", "tokio",
"tracing", "tracing",
] ]
[[package]] [[package]]
name = "rustical_frontend" name = "rustical_frontend"
version = "0.12.2" version = "0.11.10"
dependencies = [ dependencies = [
"askama", "askama",
"askama_web", "askama_web",
@@ -3506,7 +3512,7 @@ dependencies = [
"rustical_store", "rustical_store",
"serde", "serde",
"serde_json", "serde_json",
"thiserror 2.0.18", "thiserror 2.0.17",
"tokio", "tokio",
"tower", "tower",
"tower-http", "tower-http",
@@ -3519,13 +3525,13 @@ dependencies = [
[[package]] [[package]]
name = "rustical_ical" name = "rustical_ical"
version = "0.12.2" version = "0.11.10"
dependencies = [ dependencies = [
"axum", "axum",
"caldata",
"chrono", "chrono",
"chrono-tz", "chrono-tz",
"derive_more", "derive_more",
"ical",
"regex", "regex",
"rrule", "rrule",
"rstest", "rstest",
@@ -3533,12 +3539,12 @@ dependencies = [
"serde", "serde",
"sha2", "sha2",
"similar-asserts", "similar-asserts",
"thiserror 2.0.18", "thiserror 2.0.17",
] ]
[[package]] [[package]]
name = "rustical_oidc" name = "rustical_oidc"
version = "0.12.2" version = "0.11.10"
dependencies = [ dependencies = [
"async-trait", "async-trait",
"axum", "axum",
@@ -3547,19 +3553,18 @@ dependencies = [
"openidconnect", "openidconnect",
"reqwest", "reqwest",
"serde", "serde",
"thiserror 2.0.18", "thiserror 2.0.17",
"tower-sessions", "tower-sessions",
"tracing", "tracing",
] ]
[[package]] [[package]]
name = "rustical_store" name = "rustical_store"
version = "0.12.2" version = "0.11.10"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"async-trait", "async-trait",
"axum", "axum",
"caldata",
"chrono", "chrono",
"chrono-tz", "chrono-tz",
"clap", "clap",
@@ -3567,6 +3572,7 @@ dependencies = [
"futures-core", "futures-core",
"headers", "headers",
"http", "http",
"ical",
"regex", "regex",
"rrule", "rrule",
"rstest", "rstest",
@@ -3577,7 +3583,7 @@ dependencies = [
"rustical_xml", "rustical_xml",
"serde", "serde",
"sha2", "sha2",
"thiserror 2.0.18", "thiserror 2.0.17",
"tokio", "tokio",
"tower", "tower",
"tower-sessions", "tower-sessions",
@@ -3587,24 +3593,23 @@ dependencies = [
[[package]] [[package]]
name = "rustical_store_sqlite" name = "rustical_store_sqlite"
version = "0.12.2" version = "0.11.10"
dependencies = [ dependencies = [
"async-trait", "async-trait",
"caldata",
"chrono", "chrono",
"criterion", "criterion",
"derive_more", "derive_more",
"ical",
"password-auth", "password-auth",
"password-hash", "password-hash",
"pbkdf2", "pbkdf2",
"regex",
"rstest", "rstest",
"rustical_ical", "rustical_ical",
"rustical_store", "rustical_store",
"serde", "serde",
"sha2", "sha2",
"sqlx", "sqlx",
"thiserror 2.0.18", "thiserror 2.0.17",
"tokio", "tokio",
"tracing", "tracing",
"uuid", "uuid",
@@ -3612,10 +3617,10 @@ dependencies = [
[[package]] [[package]]
name = "rustical_xml" name = "rustical_xml"
version = "0.12.2" version = "0.11.10"
dependencies = [ dependencies = [
"quick-xml", "quick-xml",
"thiserror 2.0.18", "thiserror 2.0.17",
"xml_derive", "xml_derive",
] ]
@@ -3648,9 +3653,9 @@ dependencies = [
[[package]] [[package]]
name = "rustls-pki-types" name = "rustls-pki-types"
version = "1.14.0" version = "1.13.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "be040f8b0a225e40375822a563fa9524378b9d63112f53e19ffff34df5d33fdd" checksum = "21e6f2ab2928ca4291b86736a8bd920a277a399bba1589409d72154ff87c1282"
dependencies = [ dependencies = [
"web-time", "web-time",
"zeroize", "zeroize",
@@ -3658,9 +3663,9 @@ dependencies = [
[[package]] [[package]]
name = "rustls-webpki" name = "rustls-webpki"
version = "0.103.9" version = "0.103.8"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d7df23109aa6c1567d1c575b9952556388da57401e4ace1d15f79eedad0d8f53" checksum = "2ffdfa2f5286e2247234e03f680868ac2815974dc39e00ea15adc445d0aafe52"
dependencies = [ dependencies = [
"ring", "ring",
"rustls-pki-types", "rustls-pki-types",
@@ -3972,9 +3977,9 @@ dependencies = [
[[package]] [[package]]
name = "socket2" name = "socket2"
version = "0.6.2" version = "0.6.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "86f4aa3ad99f2088c990dfa82d367e19cb29268ed67c574d10d0a4bfe71f07e0" checksum = "17129e116933cf371d018bb80ae557e889637989d8638274fb25622827b03881"
dependencies = [ dependencies = [
"libc", "libc",
"windows-sys 0.60.2", "windows-sys 0.60.2",
@@ -4040,7 +4045,7 @@ dependencies = [
"serde_json", "serde_json",
"sha2", "sha2",
"smallvec", "smallvec",
"thiserror 2.0.18", "thiserror 2.0.17",
"tokio", "tokio",
"tokio-stream", "tokio-stream",
"tracing", "tracing",
@@ -4124,7 +4129,7 @@ dependencies = [
"smallvec", "smallvec",
"sqlx-core", "sqlx-core",
"stringprep", "stringprep",
"thiserror 2.0.18", "thiserror 2.0.17",
"tracing", "tracing",
"uuid", "uuid",
"whoami", "whoami",
@@ -4163,7 +4168,7 @@ dependencies = [
"smallvec", "smallvec",
"sqlx-core", "sqlx-core",
"stringprep", "stringprep",
"thiserror 2.0.18", "thiserror 2.0.17",
"tracing", "tracing",
"uuid", "uuid",
"whoami", "whoami",
@@ -4189,7 +4194,7 @@ dependencies = [
"serde", "serde",
"serde_urlencoded", "serde_urlencoded",
"sqlx-core", "sqlx-core",
"thiserror 2.0.18", "thiserror 2.0.17",
"tracing", "tracing",
"url", "url",
"uuid", "uuid",
@@ -4308,11 +4313,11 @@ dependencies = [
[[package]] [[package]]
name = "thiserror" name = "thiserror"
version = "2.0.18" version = "2.0.17"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4288b5bcbc7920c07a1149a35cf9590a2aa808e0bc1eafaade0b80947865fbc4" checksum = "f63587ca0f12b72a0600bcba1d40081f830876000bb46dd2337a3051618f4fc8"
dependencies = [ dependencies = [
"thiserror-impl 2.0.18", "thiserror-impl 2.0.17",
] ]
[[package]] [[package]]
@@ -4328,9 +4333,9 @@ dependencies = [
[[package]] [[package]]
name = "thiserror-impl" name = "thiserror-impl"
version = "2.0.18" version = "2.0.17"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ebc4ee7f67670e9b64d05fa4253e753e016c6c95ff35b89b7941d6b856dec1d5" checksum = "3ff15c8ecd7de3849db632e14d18d2571fa09dfc5ed93479bc4485c7a517c913"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
@@ -4348,9 +4353,9 @@ dependencies = [
[[package]] [[package]]
name = "time" name = "time"
version = "0.3.46" version = "0.3.45"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9da98b7d9b7dad93488a84b8248efc35352b0b2657397d4167e7ad67e5d535e5" checksum = "f9e442fc33d7fdb45aa9bfeb312c095964abdf596f7567261062b2a7107aaabd"
dependencies = [ dependencies = [
"deranged", "deranged",
"itoa", "itoa",
@@ -4363,15 +4368,15 @@ dependencies = [
[[package]] [[package]]
name = "time-core" name = "time-core"
version = "0.1.8" version = "0.1.7"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7694e1cfe791f8d31026952abf09c69ca6f6fa4e1a1229e18988f06a04a12dca" checksum = "8b36ee98fd31ec7426d599183e8fe26932a8dc1fb76ddb6214d05493377d34ca"
[[package]] [[package]]
name = "time-macros" name = "time-macros"
version = "0.2.26" version = "0.2.25"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "78cc610bac2dcee56805c99642447d4c5dbde4d01f752ffea0199aee1f601dc4" checksum = "71e552d1249bf61ac2a52db88179fd0673def1e1ad8243a00d9ec9ed71fee3dd"
dependencies = [ dependencies = [
"num-conv", "num-conv",
"time-core", "time-core",
@@ -4712,7 +4717,7 @@ dependencies = [
"rand 0.8.5", "rand 0.8.5",
"serde", "serde",
"serde_json", "serde_json",
"thiserror 2.0.18", "thiserror 2.0.17",
"time", "time",
"tokio", "tokio",
"tracing", "tracing",
@@ -4943,12 +4948,12 @@ checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a"
[[package]] [[package]]
name = "vtimezones-rs" name = "vtimezones-rs"
version = "0.3.1" version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1e4e9cf6888a927b6cec4aa2416f379885b92dd2aa4476bc83718fe58051f67e" checksum = "f6728de8767c8dea44f41b88115a205ed23adc3302e1b4342be59d922934dae5"
dependencies = [ dependencies = [
"glob", "glob",
"phf 0.13.1", "phf 0.12.1",
"phf_codegen", "phf_codegen",
] ]
@@ -4979,9 +4984,9 @@ checksum = "ccf3ec651a847eb01de73ccad15eb7d99f80485de043efb2f370cd654f4ea44b"
[[package]] [[package]]
name = "wasip2" name = "wasip2"
version = "1.0.2+wasi-0.2.9" version = "1.0.1+wasi-0.2.4"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9517f9239f02c069db75e65f174b3da828fe5f5b945c4dd26bd25d89c03ebcf5" checksum = "0562428422c63773dad2c345a1882263bbf4d65cf3f42e90921f787ef5ad58e7"
dependencies = [ dependencies = [
"wit-bindgen", "wit-bindgen",
] ]
@@ -4994,9 +4999,9 @@ checksum = "b8dad83b4f25e74f184f64c43b150b91efe7647395b42289f38e50566d82855b"
[[package]] [[package]]
name = "wasm-bindgen" name = "wasm-bindgen"
version = "0.2.108" version = "0.2.106"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "64024a30ec1e37399cf85a7ffefebdb72205ca1c972291c51512360d90bd8566" checksum = "0d759f433fa64a2d763d1340820e46e111a7a5ab75f993d1852d70b03dbb80fd"
dependencies = [ dependencies = [
"cfg-if", "cfg-if",
"once_cell", "once_cell",
@@ -5007,12 +5012,11 @@ dependencies = [
[[package]] [[package]]
name = "wasm-bindgen-futures" name = "wasm-bindgen-futures"
version = "0.4.58" version = "0.4.56"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "70a6e77fd0ae8029c9ea0063f87c46fde723e7d887703d74ad2616d792e51e6f" checksum = "836d9622d604feee9e5de25ac10e3ea5f2d65b41eac0d9ce72eb5deae707ce7c"
dependencies = [ dependencies = [
"cfg-if", "cfg-if",
"futures-util",
"js-sys", "js-sys",
"once_cell", "once_cell",
"wasm-bindgen", "wasm-bindgen",
@@ -5021,9 +5025,9 @@ dependencies = [
[[package]] [[package]]
name = "wasm-bindgen-macro" name = "wasm-bindgen-macro"
version = "0.2.108" version = "0.2.106"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "008b239d9c740232e71bd39e8ef6429d27097518b6b30bdf9086833bd5b6d608" checksum = "48cb0d2638f8baedbc542ed444afc0644a29166f1595371af4fecf8ce1e7eeb3"
dependencies = [ dependencies = [
"quote", "quote",
"wasm-bindgen-macro-support", "wasm-bindgen-macro-support",
@@ -5031,9 +5035,9 @@ dependencies = [
[[package]] [[package]]
name = "wasm-bindgen-macro-support" name = "wasm-bindgen-macro-support"
version = "0.2.108" version = "0.2.106"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5256bae2d58f54820e6490f9839c49780dff84c65aeab9e772f15d5f0e913a55" checksum = "cefb59d5cd5f92d9dcf80e4683949f15ca4b511f4ac0a6e14d4e1ac60c6ecd40"
dependencies = [ dependencies = [
"bumpalo", "bumpalo",
"proc-macro2", "proc-macro2",
@@ -5044,18 +5048,18 @@ dependencies = [
[[package]] [[package]]
name = "wasm-bindgen-shared" name = "wasm-bindgen-shared"
version = "0.2.108" version = "0.2.106"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1f01b580c9ac74c8d8f0c0e4afb04eeef2acf145458e52c03845ee9cd23e3d12" checksum = "cbc538057e648b67f72a982e708d485b2efa771e1ac05fec311f9f63e5800db4"
dependencies = [ dependencies = [
"unicode-ident", "unicode-ident",
] ]
[[package]] [[package]]
name = "web-sys" name = "web-sys"
version = "0.3.85" version = "0.3.83"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "312e32e551d92129218ea9a2452120f4aabc03529ef03e4d0d82fb2780608598" checksum = "9b32828d774c412041098d182a8b38b16ea816958e07cf40eec2bc080ae137ac"
dependencies = [ dependencies = [
"js-sys", "js-sys",
"wasm-bindgen", "wasm-bindgen",
@@ -5422,9 +5426,9 @@ dependencies = [
[[package]] [[package]]
name = "wit-bindgen" name = "wit-bindgen"
version = "0.51.0" version = "0.46.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d7249219f66ced02969388cf2bb044a09756a083d0fab1e566056b04d9fbcaa5" checksum = "f17a85883d4e6d00e8a97c586de764dabcc06133f7f1d55dce5cdc070ad7fe59"
[[package]] [[package]]
name = "writeable" name = "writeable"
@@ -5434,7 +5438,7 @@ checksum = "9edde0db4769d2dc68579893f2306b26c6ecfbe0ef499b013d731b7b9247e0b9"
[[package]] [[package]]
name = "xml_derive" name = "xml_derive"
version = "0.12.2" version = "0.11.10"
dependencies = [ dependencies = [
"darling 0.23.0", "darling 0.23.0",
"heck", "heck",
@@ -5555,6 +5559,6 @@ dependencies = [
[[package]] [[package]]
name = "zmij" name = "zmij"
version = "1.0.16" version = "1.0.14"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dfcd145825aace48cff44a8844de64bf75feec3080e0aa5cdbde72961ae51a65" checksum = "bd8f3f50b848df28f887acb68e41201b5aea6bc8a8dacc00fb40635ff9a72fea"

View File

@@ -2,7 +2,7 @@
members = ["crates/*"] members = ["crates/*"]
[workspace.package] [workspace.package]
version = "0.12.2" version = "0.11.10"
rust-version = "1.92" rust-version = "1.92"
edition = "2024" edition = "2024"
description = "A CalDAV server" description = "A CalDAV server"
@@ -73,7 +73,7 @@ tokio = { version = "1.48", features = [
url = "2.5" url = "2.5"
base64 = "0.22" base64 = "0.22"
thiserror = "2.0" thiserror = "2.0"
quick-xml = { version = "0.39" } quick-xml = { version = "0.38" }
rust-embed = "8.9" rust-embed = "8.9"
tower-sessions = "0.14" tower-sessions = "0.14"
futures-core = "0.3" futures-core = "0.3"
@@ -107,7 +107,9 @@ strum = "0.27"
strum_macros = "0.27" strum_macros = "0.27"
serde_json = { version = "1.0", features = ["raw_value"] } serde_json = { version = "1.0", features = ["raw_value"] }
sqlx-sqlite = { version = "0.8", features = ["bundled"] } sqlx-sqlite = { version = "0.8", features = ["bundled"] }
caldata = { version = "0.13.0", features = ["chrono-tz", "vtimezones-rs"] } ical = { git = "https://github.com/lennart-k/ical-rs", branch = "dev", features = [
"chrono-tz",
] }
toml = "0.9" toml = "0.9"
tower = "0.5" tower = "0.5"
tower-http = { version = "0.6", features = [ tower-http = { version = "0.6", features = [
@@ -137,7 +139,7 @@ reqwest = { version = "0.12", features = [
openidconnect = "4.0" openidconnect = "4.0"
clap = { version = "4.5", features = ["derive", "env"] } clap = { version = "4.5", features = ["derive", "env"] }
matchit-serde = { git = "https://github.com/lennart-k/matchit-serde", rev = "e18e65d7" } matchit-serde = { git = "https://github.com/lennart-k/matchit-serde", rev = "e18e65d7" }
vtimezones-rs = "0.3" vtimezones-rs = "0.2"
ece = { version = "2.3", default-features = false, features = [ ece = { version = "2.3", default-features = false, features = [
"backend-openssl", "backend-openssl",
] } ] }
@@ -151,7 +153,6 @@ criterion = { version = "0.8", features = ["async_tokio"] }
rstest.workspace = true rstest.workspace = true
rustical_store_sqlite = { workspace = true, features = ["test"] } rustical_store_sqlite = { workspace = true, features = ["test"] }
insta.workspace = true insta.workspace = true
similar-asserts.workspace = true
[dependencies] [dependencies]
rustical_store.workspace = true rustical_store.workspace = true
@@ -159,7 +160,6 @@ rustical_store_sqlite.workspace = true
rustical_caldav.workspace = true rustical_caldav.workspace = true
rustical_carddav.workspace = true rustical_carddav.workspace = true
rustical_frontend.workspace = true rustical_frontend.workspace = true
caldata.workspace = true
toml.workspace = true toml.workspace = true
serde.workspace = true serde.workspace = true
tokio.workspace = true tokio.workspace = true

View File

@@ -36,7 +36,7 @@ COPY --from=planner /rustical/recipe.json recipe.json
RUN cargo chef cook --release --target "$(cat /tmp/rust_target)" RUN cargo chef cook --release --target "$(cat /tmp/rust_target)"
COPY . . COPY . .
RUN cargo install --locked --target "$(cat /tmp/rust_target)" --path . RUN cargo install --target "$(cat /tmp/rust_target)" --path .
FROM scratch FROM scratch
COPY --from=builder /usr/local/cargo/bin/rustical /usr/local/bin/rustical COPY --from=builder /usr/local/cargo/bin/rustical /usr/local/bin/rustical

View File

@@ -34,7 +34,7 @@ rustical_store.workspace = true
chrono.workspace = true chrono.workspace = true
chrono-tz.workspace = true chrono-tz.workspace = true
sha2.workspace = true sha2.workspace = true
caldata.workspace = true ical.workspace = true
percent-encoding.workspace = true percent-encoding.workspace = true
rustical_xml.workspace = true rustical_xml.workspace = true
uuid.workspace = true uuid.workspace = true

View File

@@ -3,11 +3,11 @@ use crate::calendar::CalendarResourceService;
use axum::body::Body; use axum::body::Body;
use axum::extract::State; use axum::extract::State;
use axum::{extract::Path, response::Response}; use axum::{extract::Path, response::Response};
use caldata::component::IcalCalendar;
use caldata::generator::Emitter;
use caldata::parser::ContentLine;
use headers::{ContentType, HeaderMapExt}; use headers::{ContentType, HeaderMapExt};
use http::{HeaderValue, Method, StatusCode, header}; use http::{HeaderValue, Method, StatusCode, header};
use ical::component::IcalCalendar;
use ical::generator::Emitter;
use ical::property::ContentLine;
use percent_encoding::{CONTROLS, utf8_percent_encode}; use percent_encoding::{CONTROLS, utf8_percent_encode};
use rustical_store::{CalendarStore, SubscriptionStore, auth::Principal}; use rustical_store::{CalendarStore, SubscriptionStore, auth::Principal};
use std::str::FromStr; use std::str::FromStr;

View File

@@ -4,9 +4,8 @@ use axum::{
extract::{Path, State}, extract::{Path, State},
response::{IntoResponse, Response}, response::{IntoResponse, Response},
}; };
use caldata::IcalParser;
use caldata::component::{Component, ComponentMut};
use http::StatusCode; use http::StatusCode;
use ical::parser::{Component, ComponentMut};
use rustical_dav::header::Overwrite; use rustical_dav::header::Overwrite;
use rustical_ical::CalendarObjectType; use rustical_ical::CalendarObjectType;
use rustical_store::{ use rustical_store::{
@@ -26,11 +25,11 @@ pub async fn route_import<C: CalendarStore, S: SubscriptionStore>(
return Err(Error::Unauthorized); return Err(Error::Unauthorized);
} }
let parser = IcalParser::from_slice(body.as_bytes()); let parser = ical::IcalParser::from_slice(body.as_bytes());
let mut cal = match parser.expect_one() { let mut cal = parser
Ok(cal) => cal.mutable(), .expect_one()
Err(err) => return Ok((StatusCode::BAD_REQUEST, err.to_string()).into_response()), .map_err(rustical_ical::Error::ParserError)?
}; .mutable();
// Extract calendar metadata // Extract calendar metadata
let displayname = cal let displayname = cal
@@ -71,10 +70,12 @@ pub async fn route_import<C: CalendarStore, S: SubscriptionStore>(
cal_components.push(CalendarObjectType::Todo); cal_components.push(CalendarObjectType::Todo);
} }
let objects = match cal.into_objects() { let objects = cal
Ok(objects) => objects.into_iter().map(Into::into).collect(), .into_objects()
Err(err) => return Ok((StatusCode::BAD_REQUEST, err.to_string()).into_response()), .map_err(rustical_ical::Error::ParserError)?
}; .into_iter()
.map(Into::into)
.collect();
let new_cal = Calendar { let new_cal = Calendar {
principal, principal,
id: cal_id, id: cal_id,

View File

@@ -1,13 +1,10 @@
use std::str::FromStr;
use crate::Error; use crate::Error;
use crate::calendar::CalendarResourceService; use crate::calendar::CalendarResourceService;
use crate::calendar::prop::SupportedCalendarComponentSet; use crate::calendar::prop::SupportedCalendarComponentSet;
use crate::error::Precondition;
use axum::extract::{Path, State}; use axum::extract::{Path, State};
use axum::response::{IntoResponse, Response}; use axum::response::{IntoResponse, Response};
use caldata::IcalParser;
use http::{Method, StatusCode}; use http::{Method, StatusCode};
use ical::IcalParser;
use rustical_dav::xml::HrefElement; use rustical_dav::xml::HrefElement;
use rustical_ical::CalendarObjectType; use rustical_ical::CalendarObjectType;
use rustical_store::auth::Principal; use rustical_store::auth::Principal;
@@ -87,33 +84,21 @@ pub async fn route_mkcalendar<C: CalendarStore, S: SubscriptionStore>(
} }
let timezone_id = if let Some(tzid) = request.calendar_timezone_id { let timezone_id = if let Some(tzid) = request.calendar_timezone_id {
if chrono_tz::Tz::from_str(&tzid).is_err() {
return Err(Error::PreconditionFailed(Precondition::CalendarTimezone(
"Invalid timezone ID in calendar-timezone-id",
)));
}
Some(tzid) Some(tzid)
} else if let Some(tz) = request.calendar_timezone { } else if let Some(tz) = request.calendar_timezone {
// TODO: Proper error (calendar-timezone precondition)
let calendar = IcalParser::from_slice(tz.as_bytes()) let calendar = IcalParser::from_slice(tz.as_bytes())
.next() .next()
.ok_or(Error::PreconditionFailed(Precondition::CalendarTimezone( .ok_or_else(|| rustical_dav::Error::BadRequest("No timezone data provided".to_owned()))?
"No timezone data provided", .map_err(|_| rustical_dav::Error::BadRequest("Error parsing timezone".to_owned()))?;
)))?
.map_err(|_| {
Error::PreconditionFailed(Precondition::CalendarTimezone("Error parsing timezone"))
})?;
let timezone = calendar let timezone = calendar.vtimezones.values().next().ok_or_else(|| {
.vtimezones rustical_dav::Error::BadRequest("No timezone data provided".to_owned())
.values() })?;
.next()
.ok_or(Error::PreconditionFailed(Precondition::CalendarTimezone(
"No timezone data provided",
)))?;
let timezone: Option<chrono_tz::Tz> = timezone.into(); let timezone: Option<chrono_tz::Tz> = timezone.into();
let timezone = timezone.ok_or(Error::PreconditionFailed( let timezone = timezone.ok_or_else(|| {
Precondition::CalendarTimezone("No timezone data provided"), rustical_dav::Error::BadRequest("Cannot translate VTIMEZONE into IANA TZID".to_owned())
))?; })?;
Some(timezone.name().to_owned()) Some(timezone.name().to_owned())
} else { } else {

View File

@@ -1,13 +1,9 @@
use crate::calendar::methods::report::calendar_query::{ use crate::calendar::methods::report::calendar_query::{
TimeRangeElement, TimeRangeElement, prop_filter::PropFilterElement,
prop_filter::{PropFilterElement, PropFilterable},
}; };
use caldata::{ use ical::{
component::{ component::IcalCalendarObject,
CalendarInnerData, Component, IcalAlarm, IcalCalendarObject, IcalEvent, IcalTimeZone, parser::{Component, ical::component::IcalTimeZone},
IcalTodo,
},
parser::ContentLine,
}; };
use rustical_xml::XmlDeserialize; use rustical_xml::XmlDeserialize;
@@ -29,9 +25,7 @@ pub struct CompFilterElement {
pub(crate) name: String, pub(crate) name: String,
} }
pub trait CompFilterable: PropFilterable + Sized { pub trait CompFilterable: Component + Sized {
fn get_comp_name(&self) -> &'static str;
fn match_time_range(&self, time_range: &TimeRangeElement) -> bool; fn match_time_range(&self, time_range: &TimeRangeElement) -> bool;
fn match_subcomponents(&self, comp_filter: &CompFilterElement) -> bool; fn match_subcomponents(&self, comp_filter: &CompFilterElement) -> bool;
@@ -73,94 +67,7 @@ pub trait CompFilterable: PropFilterable + Sized {
} }
} }
impl CompFilterable for CalendarInnerData {
fn get_comp_name(&self) -> &'static str {
match self {
Self::Event(main, _) => main.get_comp_name(),
Self::Journal(main, _) => main.get_comp_name(),
Self::Todo(main, _) => main.get_comp_name(),
}
}
fn match_time_range(&self, time_range: &TimeRangeElement) -> bool {
if let Some(start) = &time_range.start
&& let Some(last_end) = self.get_last_occurence()
&& start.to_utc() > last_end.utc()
{
return false;
}
if let Some(end) = &time_range.end
&& let Some(first_start) = self.get_first_occurence()
&& end.to_utc() < first_start.utc()
{
return false;
}
true
}
fn match_subcomponents(&self, comp_filter: &CompFilterElement) -> bool {
match self {
Self::Event(main, overrides) => std::iter::once(main)
.chain(overrides.iter())
.flat_map(IcalEvent::get_alarms)
.any(|alarm| alarm.matches(comp_filter)),
Self::Todo(main, overrides) => std::iter::once(main)
.chain(overrides.iter())
.flat_map(IcalTodo::get_alarms)
.any(|alarm| alarm.matches(comp_filter)),
// VJOURNAL has no subcomponents
Self::Journal(_, _) => comp_filter.is_not_defined.is_some(),
}
}
}
impl PropFilterable for IcalAlarm {
fn get_named_properties<'a>(&'a self, name: &'a str) -> impl Iterator<Item = &'a ContentLine> {
Component::get_named_properties(self, name)
}
}
impl CompFilterable for IcalAlarm {
fn get_comp_name(&self) -> &'static str {
Component::get_comp_name(self)
}
fn match_time_range(&self, _time_range: &TimeRangeElement) -> bool {
true
}
fn match_subcomponents(&self, comp_filter: &CompFilterElement) -> bool {
comp_filter.is_not_defined.is_some()
}
}
impl PropFilterable for CalendarInnerData {
#[allow(refining_impl_trait)]
fn get_named_properties<'a>(
&'a self,
name: &'a str,
) -> Box<dyn Iterator<Item = &'a ContentLine> + 'a> {
// TODO: If we were pedantic, we would have to do recurrence expansion first
// and take into account the overrides :(
match self {
Self::Event(main, _) => Box::new(main.get_named_properties(name)),
Self::Todo(main, _) => Box::new(main.get_named_properties(name)),
Self::Journal(main, _) => Box::new(main.get_named_properties(name)),
}
}
}
impl PropFilterable for IcalCalendarObject {
fn get_named_properties<'a>(&'a self, name: &'a str) -> impl Iterator<Item = &'a ContentLine> {
Component::get_named_properties(self, name)
}
}
impl CompFilterable for IcalCalendarObject { impl CompFilterable for IcalCalendarObject {
fn get_comp_name(&self) -> &'static str {
Component::get_comp_name(self)
}
fn match_time_range(&self, _time_range: &TimeRangeElement) -> bool { fn match_time_range(&self, _time_range: &TimeRangeElement) -> bool {
// VCALENDAR has no concept of time range // VCALENDAR has no concept of time range
false false
@@ -171,33 +78,23 @@ impl CompFilterable for IcalCalendarObject {
.get_vtimezones() .get_vtimezones()
.values() .values()
.map(|tz| tz.matches(comp_filter)) .map(|tz| tz.matches(comp_filter))
.chain([self.get_inner().matches(comp_filter)]); .chain([self.matches(comp_filter)]);
if comp_filter.is_not_defined.is_some() { if comp_filter.is_not_defined.is_some() {
matches.all(|x| !x) matches.all(|x| x)
} else { } else {
matches.any(|x| x) matches.any(|x| x)
} }
} }
} }
impl PropFilterable for IcalTimeZone {
fn get_named_properties<'a>(&'a self, name: &'a str) -> impl Iterator<Item = &'a ContentLine> {
Component::get_named_properties(self, name)
}
}
impl CompFilterable for IcalTimeZone { impl CompFilterable for IcalTimeZone {
fn get_comp_name(&self) -> &'static str {
Component::get_comp_name(self)
}
fn match_time_range(&self, _time_range: &TimeRangeElement) -> bool { fn match_time_range(&self, _time_range: &TimeRangeElement) -> bool {
false false
} }
fn match_subcomponents(&self, comp_filter: &CompFilterElement) -> bool { fn match_subcomponents(&self, _comp_filter: &CompFilterElement) -> bool {
// VTIMEZONE has no subcomponents true
comp_filter.is_not_defined.is_some()
} }
} }
@@ -214,7 +111,6 @@ mod tests {
const ICS: &str = r"BEGIN:VCALENDAR const ICS: &str = r"BEGIN:VCALENDAR
CALSCALE:GREGORIAN CALSCALE:GREGORIAN
VERSION:2.0 VERSION:2.0
PRODID:me
BEGIN:VTIMEZONE BEGIN:VTIMEZONE
TZID:Europe/Berlin TZID:Europe/Berlin
X-LIC-LOCATION:Europe/Berlin X-LIC-LOCATION:Europe/Berlin

View File

@@ -1,6 +1,6 @@
use super::comp_filter::{CompFilterElement, CompFilterable}; use super::comp_filter::{CompFilterElement, CompFilterable};
use crate::calendar_object::CalendarObjectPropWrapperName; use crate::calendar_object::CalendarObjectPropWrapperName;
use caldata::{component::IcalCalendarObject, parser::ContentLine}; use ical::{component::IcalCalendarObject, property::ContentLine};
use rustical_dav::xml::{PropfindType, TextMatchElement}; use rustical_dav::xml::{PropfindType, TextMatchElement};
use rustical_ical::UtcDateTime; use rustical_ical::UtcDateTime;
use rustical_store::calendar_store::CalendarQuery; use rustical_store::calendar_store::CalendarQuery;

View File

@@ -1,5 +1,5 @@
use super::{ParamFilterElement, TimeRangeElement}; use super::{ParamFilterElement, TimeRangeElement};
use caldata::{parser::ContentLine, types::CalDateTime}; use ical::{parser::Component, property::ContentLine, types::CalDateTime};
use rustical_dav::xml::TextMatchElement; use rustical_dav::xml::TextMatchElement;
use rustical_ical::UtcDateTime; use rustical_ical::UtcDateTime;
use rustical_xml::XmlDeserialize; use rustical_xml::XmlDeserialize;
@@ -21,10 +21,6 @@ pub struct PropFilterElement {
pub(crate) name: String, pub(crate) name: String,
} }
pub trait PropFilterable {
fn get_named_properties<'a>(&'a self, name: &'a str) -> impl Iterator<Item = &'a ContentLine>;
}
impl PropFilterElement { impl PropFilterElement {
#[must_use] #[must_use]
pub fn match_property(&self, property: &ContentLine) -> bool { pub fn match_property(&self, property: &ContentLine) -> bool {
@@ -64,7 +60,7 @@ impl PropFilterElement {
true true
} }
pub fn match_component(&self, comp: &impl PropFilterable) -> bool { pub fn match_component(&self, comp: &impl Component) -> bool {
let mut properties = comp.get_named_properties(&self.name); let mut properties = comp.get_named_properties(&self.name);
if self.is_not_defined.is_some() { if self.is_not_defined.is_some() {
return properties.next().is_none(); return properties.next().is_none();

View File

@@ -1,10 +1,10 @@
use super::prop::{SupportedCalendarComponentSet, SupportedCalendarData}; use super::prop::{SupportedCalendarComponentSet, SupportedCalendarData};
use crate::Error; use crate::Error;
use crate::calendar::prop::{ReportMethod, SupportedCollationSet}; use crate::calendar::prop::{ReportMethod, SupportedCollationSet};
use caldata::IcalParser;
use caldata::types::CalDateTime;
use chrono::{DateTime, Utc}; use chrono::{DateTime, Utc};
use derive_more::derive::{From, Into}; use derive_more::derive::{From, Into};
use ical::IcalParser;
use ical::types::CalDateTime;
use rustical_dav::extensions::{ use rustical_dav::extensions::{
CommonPropertiesExtension, CommonPropertiesProp, SyncTokenExtension, SyncTokenExtensionProp, CommonPropertiesExtension, CommonPropertiesProp, SyncTokenExtension, SyncTokenExtensionProp,
}; };

View File

@@ -6,7 +6,7 @@ use crate::calendar::methods::report::route_report_calendar;
use crate::calendar::resource::CalendarResource; use crate::calendar::resource::CalendarResource;
use crate::calendar_object::CalendarObjectResourceService; use crate::calendar_object::CalendarObjectResourceService;
use crate::calendar_object::resource::CalendarObjectResource; use crate::calendar_object::resource::CalendarObjectResource;
use crate::{CalDavConfig, CalDavPrincipalUri, Error}; use crate::{CalDavPrincipalUri, Error};
use async_trait::async_trait; use async_trait::async_trait;
use axum::Router; use axum::Router;
use axum::extract::Request; use axum::extract::Request;
@@ -23,7 +23,6 @@ use tower::Service;
pub struct CalendarResourceService<C: CalendarStore, S: SubscriptionStore> { pub struct CalendarResourceService<C: CalendarStore, S: SubscriptionStore> {
pub(crate) cal_store: Arc<C>, pub(crate) cal_store: Arc<C>,
pub(crate) sub_store: Arc<S>, pub(crate) sub_store: Arc<S>,
pub(crate) config: Arc<CalDavConfig>,
} }
impl<C: CalendarStore, S: SubscriptionStore> Clone for CalendarResourceService<C, S> { impl<C: CalendarStore, S: SubscriptionStore> Clone for CalendarResourceService<C, S> {
@@ -31,17 +30,15 @@ impl<C: CalendarStore, S: SubscriptionStore> Clone for CalendarResourceService<C
Self { Self {
cal_store: self.cal_store.clone(), cal_store: self.cal_store.clone(),
sub_store: self.sub_store.clone(), sub_store: self.sub_store.clone(),
config: self.config.clone(),
} }
} }
} }
impl<C: CalendarStore, S: SubscriptionStore> CalendarResourceService<C, S> { impl<C: CalendarStore, S: SubscriptionStore> CalendarResourceService<C, S> {
pub const fn new(cal_store: Arc<C>, sub_store: Arc<S>, config: Arc<CalDavConfig>) -> Self { pub const fn new(cal_store: Arc<C>, sub_store: Arc<S>) -> Self {
Self { Self {
cal_store, cal_store,
sub_store, sub_store,
config,
} }
} }
} }
@@ -115,8 +112,7 @@ impl<C: CalendarStore, S: SubscriptionStore> ResourceService for CalendarResourc
Router::new() Router::new()
.nest( .nest(
"/{object_id}", "/{object_id}",
CalendarObjectResourceService::new(self.cal_store.clone(), self.config.clone()) CalendarObjectResourceService::new(self.cal_store.clone()).axum_router(),
.axum_router(),
) )
.route_service("/", self.axum_service()) .route_service("/", self.axum_service())
} }

View File

@@ -12,7 +12,7 @@ PRODID:-//github.com/lennart-k/vzic-rs//RustiCal Calendar server//EN
VERSION:2.0 VERSION:2.0
BEGIN:VTIMEZONE BEGIN:VTIMEZONE
TZID:Europe/Berlin TZID:Europe/Berlin
LAST-MODIFIED:20260124T185655Z LAST-MODIFIED:20250723T190331Z
X-LIC-LOCATION:Europe/Berlin X-LIC-LOCATION:Europe/Berlin
X-PROLEPTIC-TZNAME:LMT X-PROLEPTIC-TZNAME:LMT
BEGIN:STANDARD BEGIN:STANDARD

View File

@@ -5,14 +5,13 @@ use axum::body::Body;
use axum::extract::{Path, State}; use axum::extract::{Path, State};
use axum::response::{IntoResponse, Response}; use axum::response::{IntoResponse, Response};
use axum_extra::TypedHeader; use axum_extra::TypedHeader;
use caldata::parser::ParserOptions;
use headers::{ContentType, ETag, HeaderMapExt, IfNoneMatch}; use headers::{ContentType, ETag, HeaderMapExt, IfNoneMatch};
use http::{HeaderMap, HeaderValue, Method, StatusCode}; use http::{HeaderMap, HeaderValue, Method, StatusCode};
use rustical_ical::CalendarObject; use rustical_ical::CalendarObject;
use rustical_store::CalendarStore; use rustical_store::CalendarStore;
use rustical_store::auth::Principal; use rustical_store::auth::Principal;
use std::str::FromStr; use std::str::FromStr;
use tracing::{instrument, warn}; use tracing::{debug, instrument};
#[instrument(skip(cal_store))] #[instrument(skip(cal_store))]
pub async fn get_event<C: CalendarStore>( pub async fn get_event<C: CalendarStore>(
@@ -21,10 +20,7 @@ pub async fn get_event<C: CalendarStore>(
calendar_id, calendar_id,
object_id, object_id,
}): Path<CalendarObjectPathComponents>, }): Path<CalendarObjectPathComponents>,
State(CalendarObjectResourceService { State(CalendarObjectResourceService { cal_store }): State<CalendarObjectResourceService<C>>,
cal_store,
config: _,
}): State<CalendarObjectResourceService<C>>,
user: Principal, user: Principal,
method: Method, method: Method,
) -> Result<Response, Error> { ) -> Result<Response, Error> {
@@ -61,9 +57,7 @@ pub async fn put_event<C: CalendarStore>(
calendar_id, calendar_id,
object_id, object_id,
}): Path<CalendarObjectPathComponents>, }): Path<CalendarObjectPathComponents>,
State(CalendarObjectResourceService { cal_store, config }): State< State(CalendarObjectResourceService { cal_store }): State<CalendarObjectResourceService<C>>,
CalendarObjectResourceService<C>,
>,
user: Principal, user: Principal,
mut if_none_match: Option<TypedHeader<IfNoneMatch>>, mut if_none_match: Option<TypedHeader<IfNoneMatch>>,
header_map: HeaderMap, header_map: HeaderMap,
@@ -100,18 +94,9 @@ pub async fn put_event<C: CalendarStore>(
true true
}; };
let object = match CalendarObject::import( let Ok(object) = CalendarObject::from_ics(body.clone()) else {
&body, debug!("invalid calendar data:\n{body}");
Some(ParserOptions { return Err(Error::PreconditionFailed(Precondition::ValidCalendarData));
rfc7809: config.rfc7809,
}),
) {
Ok(object) => object,
Err(err) => {
warn!("invalid calendar data:\n{body}");
warn!("{err}");
return Err(Error::PreconditionFailed(Precondition::ValidCalendarData));
}
}; };
let etag = object.get_etag(); let etag = object.get_etag();
cal_store cal_store

View File

@@ -3,8 +3,8 @@ use super::prop::{
CalendarObjectPropWrapperName, CalendarObjectPropWrapperName,
}; };
use crate::Error; use crate::Error;
use caldata::generator::Emitter;
use derive_more::derive::{From, Into}; use derive_more::derive::{From, Into};
use ical::generator::Emitter;
use rustical_dav::{ use rustical_dav::{
extensions::CommonPropertiesExtension, extensions::CommonPropertiesExtension,
privileges::UserPrivilegeSet, privileges::UserPrivilegeSet,

View File

@@ -1,5 +1,5 @@
use crate::{ use crate::{
CalDavConfig, CalDavPrincipalUri, Error, CalDavPrincipalUri, Error,
calendar_object::{ calendar_object::{
methods::{get_event, put_event}, methods::{get_event, put_event},
resource::CalendarObjectResource, resource::CalendarObjectResource,
@@ -24,21 +24,19 @@ pub struct CalendarObjectPathComponents {
pub struct CalendarObjectResourceService<C: CalendarStore> { pub struct CalendarObjectResourceService<C: CalendarStore> {
pub(crate) cal_store: Arc<C>, pub(crate) cal_store: Arc<C>,
pub(crate) config: Arc<CalDavConfig>,
} }
impl<C: CalendarStore> Clone for CalendarObjectResourceService<C> { impl<C: CalendarStore> Clone for CalendarObjectResourceService<C> {
fn clone(&self) -> Self { fn clone(&self) -> Self {
Self { Self {
cal_store: self.cal_store.clone(), cal_store: self.cal_store.clone(),
config: self.config.clone(),
} }
} }
} }
impl<C: CalendarStore> CalendarObjectResourceService<C> { impl<C: CalendarStore> CalendarObjectResourceService<C> {
pub const fn new(cal_store: Arc<C>, config: Arc<CalDavConfig>) -> Self { pub const fn new(cal_store: Arc<C>) -> Self {
Self { cal_store, config } Self { cal_store }
} }
} }

View File

@@ -12,9 +12,6 @@ pub enum Precondition {
#[error("valid-calendar-data")] #[error("valid-calendar-data")]
#[xml(ns = "rustical_dav::namespace::NS_CALDAV")] #[xml(ns = "rustical_dav::namespace::NS_CALDAV")]
ValidCalendarData, ValidCalendarData,
#[error("calendar-timezone")]
#[xml(ns = "rustical_dav::namespace::NS_CALDAV")]
CalendarTimezone(&'static str),
} }
impl IntoResponse for Precondition { impl IntoResponse for Precondition {
@@ -26,7 +23,7 @@ impl IntoResponse for Precondition {
if let Err(err) = error.serialize_root(&mut writer) { if let Err(err) = error.serialize_root(&mut writer) {
return rustical_dav::Error::from(err).into_response(); return rustical_dav::Error::from(err).into_response();
} }
let mut res = Response::builder().status(StatusCode::FORBIDDEN); let mut res = Response::builder().status(StatusCode::PRECONDITION_FAILED);
res.headers_mut().unwrap().typed_insert(ContentType::xml()); res.headers_mut().unwrap().typed_insert(ContentType::xml());
res.body(Body::from(output)).unwrap() res.body(Body::from(output)).unwrap()
} }
@@ -55,6 +52,9 @@ pub enum Error {
#[error(transparent)] #[error(transparent)]
XmlDecodeError(#[from] rustical_xml::XmlError), XmlDecodeError(#[from] rustical_xml::XmlError),
#[error(transparent)]
IcalError(#[from] rustical_ical::Error),
#[error(transparent)] #[error(transparent)]
PreconditionFailed(Precondition), PreconditionFailed(Precondition),
} }
@@ -75,20 +75,18 @@ impl Error {
Self::XmlDecodeError(_) => StatusCode::BAD_REQUEST, Self::XmlDecodeError(_) => StatusCode::BAD_REQUEST,
Self::ChronoParseError(_) | Self::NotImplemented => StatusCode::INTERNAL_SERVER_ERROR, Self::ChronoParseError(_) | Self::NotImplemented => StatusCode::INTERNAL_SERVER_ERROR,
Self::NotFound => StatusCode::NOT_FOUND, Self::NotFound => StatusCode::NOT_FOUND,
// The correct status code for a failed precondition is not PreconditionFailed but Self::IcalError(err) => err.status_code(),
// Forbidden (or Conflict): Self::PreconditionFailed(_err) => StatusCode::PRECONDITION_FAILED,
// https://datatracker.ietf.org/doc/html/rfc4791#section-1.3
Self::PreconditionFailed(_err) => StatusCode::FORBIDDEN,
} }
} }
} }
impl IntoResponse for Error { impl IntoResponse for Error {
fn into_response(self) -> axum::response::Response { fn into_response(self) -> axum::response::Response {
if let Self::PreconditionFailed(precondition) = self { if matches!(
return precondition.into_response(); self.status_code(),
} StatusCode::INTERNAL_SERVER_ERROR | StatusCode::PRECONDITION_FAILED
if matches!(self.status_code(), StatusCode::INTERNAL_SERVER_ERROR) { ) {
error!("{self}"); error!("{self}");
} }
(self.status_code(), self.to_string()).into_response() (self.status_code(), self.to_string()).into_response()

View File

@@ -8,7 +8,6 @@ use rustical_dav::resources::RootResourceService;
use rustical_store::auth::middleware::AuthenticationLayer; use rustical_store::auth::middleware::AuthenticationLayer;
use rustical_store::auth::{AuthenticationProvider, Principal}; use rustical_store::auth::{AuthenticationProvider, Principal};
use rustical_store::{CalendarStore, SubscriptionStore}; use rustical_store::{CalendarStore, SubscriptionStore};
use serde::{Deserialize, Serialize};
use std::sync::Arc; use std::sync::Arc;
pub mod calendar; pub mod calendar;
@@ -35,7 +34,6 @@ pub fn caldav_router<AP: AuthenticationProvider, C: CalendarStore, S: Subscripti
store: Arc<C>, store: Arc<C>,
subscription_store: Arc<S>, subscription_store: Arc<S>,
simplified_home_set: bool, simplified_home_set: bool,
config: Arc<CalDavConfig>,
) -> Router { ) -> Router {
Router::new().nest( Router::new().nest(
prefix, prefix,
@@ -44,27 +42,9 @@ pub fn caldav_router<AP: AuthenticationProvider, C: CalendarStore, S: Subscripti
sub_store: subscription_store, sub_store: subscription_store,
cal_store: store, cal_store: store,
simplified_home_set, simplified_home_set,
config,
}) })
.axum_router() .axum_router()
.layer(AuthenticationLayer::new(auth_provider)) .layer(AuthenticationLayer::new(auth_provider))
.layer(Extension(CalDavPrincipalUri(prefix))), .layer(Extension(CalDavPrincipalUri(prefix))),
) )
} }
const fn default_true() -> bool {
true
}
#[derive(Debug, Clone, Deserialize, Serialize)]
#[serde(deny_unknown_fields, default)]
pub struct CalDavConfig {
#[serde(default = "default_true")]
rfc7809: bool,
}
impl Default for CalDavConfig {
fn default() -> Self {
Self { rfc7809: true }
}
}

View File

@@ -1,7 +1,7 @@
use crate::calendar::CalendarResourceService; use crate::calendar::CalendarResourceService;
use crate::calendar::resource::CalendarResource; use crate::calendar::resource::CalendarResource;
use crate::principal::PrincipalResource; use crate::principal::PrincipalResource;
use crate::{CalDavConfig, CalDavPrincipalUri, Error}; use crate::{CalDavPrincipalUri, Error};
use async_trait::async_trait; use async_trait::async_trait;
use axum::Router; use axum::Router;
use rustical_dav::resource::{AxumMethods, ResourceService}; use rustical_dav::resource::{AxumMethods, ResourceService};
@@ -20,7 +20,6 @@ pub struct PrincipalResourceService<
pub(crate) cal_store: Arc<CS>, pub(crate) cal_store: Arc<CS>,
// If true only return the principal as the calendar home set, otherwise also groups // If true only return the principal as the calendar home set, otherwise also groups
pub(crate) simplified_home_set: bool, pub(crate) simplified_home_set: bool,
pub(crate) config: Arc<CalDavConfig>,
} }
impl<AP: AuthenticationProvider, S: SubscriptionStore, CS: CalendarStore> Clone impl<AP: AuthenticationProvider, S: SubscriptionStore, CS: CalendarStore> Clone
@@ -32,7 +31,6 @@ impl<AP: AuthenticationProvider, S: SubscriptionStore, CS: CalendarStore> Clone
sub_store: self.sub_store.clone(), sub_store: self.sub_store.clone(),
cal_store: self.cal_store.clone(), cal_store: self.cal_store.clone(),
simplified_home_set: self.simplified_home_set, simplified_home_set: self.simplified_home_set,
config: self.config.clone(),
} }
} }
} }
@@ -86,12 +84,8 @@ impl<AP: AuthenticationProvider, S: SubscriptionStore, CS: CalendarStore> Resour
Router::new() Router::new()
.nest( .nest(
"/{calendar_id}", "/{calendar_id}",
CalendarResourceService::new( CalendarResourceService::new(self.cal_store.clone(), self.sub_store.clone())
self.cal_store.clone(), .axum_router(),
self.sub_store.clone(),
self.config.clone(),
)
.axum_router(),
) )
.route_service("/", self.axum_service()) .route_service("/", self.axum_service())
} }

View File

@@ -27,7 +27,6 @@ async fn test_principal_resource(
sub_store: Arc::new(sub_store), sub_store: Arc::new(sub_store),
auth_provider: Arc::new(auth_provider), auth_provider: Arc::new(auth_provider),
simplified_home_set: false, simplified_home_set: false,
config: Default::default(),
}; };
// We don't have any calendars here // We don't have any calendars here

View File

@@ -32,7 +32,7 @@ rustical_ical.workspace = true
http.workspace = true http.workspace = true
tower-http.workspace = true tower-http.workspace = true
percent-encoding.workspace = true percent-encoding.workspace = true
caldata.workspace = true ical.workspace = true
strum.workspace = true strum.workspace = true
strum_macros.workspace = true strum_macros.workspace = true
rstest.workspace = true rstest.workspace = true

View File

@@ -103,10 +103,7 @@ pub async fn put_object<AS: AddressbookStore>(
true true
}; };
let object = match AddressObject::from_vcf(body) { let object = AddressObject::from_vcf(body)?;
Ok(object) => object,
Err(err) => return Ok((StatusCode::BAD_REQUEST, err.to_string()).into_response()),
};
let etag = object.get_etag(); let etag = object.get_etag();
addr_store addr_store
.put_object(&principal, &addressbook_id, &object_id, object, overwrite) .put_object(&principal, &addressbook_id, &object_id, object, overwrite)

View File

@@ -7,7 +7,6 @@ use crate::{
AddressObjectPropWrapperName, AddressObjectPropWrapperName,
}, },
}; };
use caldata::property::VcardFNProperty;
use derive_more::derive::{From, Into}; use derive_more::derive::{From, Into};
use rustical_dav::{ use rustical_dav::{
extensions::CommonPropertiesExtension, extensions::CommonPropertiesExtension,
@@ -71,11 +70,8 @@ impl Resource for AddressObjectResource {
} }
fn get_displayname(&self) -> Option<&str> { fn get_displayname(&self) -> Option<&str> {
self.object todo!()
.get_vcard() // self.object.get_full_name()
.full_name
.first()
.map(|VcardFNProperty(name, _)| name.as_str())
} }
fn get_owner(&self) -> Option<&str> { fn get_owner(&self) -> Option<&str> {

View File

@@ -4,12 +4,11 @@ use axum::{
extract::{Path, State}, extract::{Path, State},
response::{IntoResponse, Response}, response::{IntoResponse, Response},
}; };
use caldata::{
VcardParser,
component::{Component, ComponentMut},
parser::ContentLine,
};
use http::StatusCode; use http::StatusCode;
use ical::{
parser::{Component, ComponentMut, vcard},
property::ContentLine,
};
use rustical_store::{Addressbook, AddressbookStore, SubscriptionStore, auth::Principal}; use rustical_store::{Addressbook, AddressbookStore, SubscriptionStore, auth::Principal};
use tracing::instrument; use tracing::instrument;
@@ -24,7 +23,7 @@ pub async fn route_import<AS: AddressbookStore, S: SubscriptionStore>(
return Err(Error::Unauthorized); return Err(Error::Unauthorized);
} }
let parser = VcardParser::from_slice(body.as_bytes()); let parser = vcard::VcardParser::from_slice(body.as_bytes());
let mut objects = vec![]; let mut objects = vec![];
for res in parser { for res in parser {

View File

@@ -2,8 +2,8 @@ use crate::{
address_object::AddressObjectPropWrapperName, address_object::AddressObjectPropWrapperName,
addressbook::methods::report::addressbook_query::PropFilterElement, addressbook::methods::report::addressbook_query::PropFilterElement,
}; };
use caldata::parser::ContentLine;
use derive_more::{From, Into}; use derive_more::{From, Into};
use ical::property::ContentLine;
use rustical_dav::xml::{PropfindType, TextMatchElement}; use rustical_dav::xml::{PropfindType, TextMatchElement};
use rustical_ical::{AddressObject, UtcDateTime}; use rustical_ical::{AddressObject, UtcDateTime};
use rustical_xml::{ValueDeserialize, XmlDeserialize, XmlRootTag}; use rustical_xml::{ValueDeserialize, XmlDeserialize, XmlRootTag};

View File

@@ -1,5 +1,5 @@
use super::{Allof, ParamFilterElement}; use super::{Allof, ParamFilterElement};
use caldata::{component::Component, parser::ContentLine}; use ical::{parser::Component, property::ContentLine};
use rustical_dav::xml::TextMatchElement; use rustical_dav::xml::TextMatchElement;
use rustical_ical::AddressObject; use rustical_ical::AddressObject;
use rustical_xml::XmlDeserialize; use rustical_xml::XmlDeserialize;

View File

@@ -23,6 +23,9 @@ pub enum Error {
#[error(transparent)] #[error(transparent)]
XmlDecodeError(#[from] rustical_xml::XmlError), XmlDecodeError(#[from] rustical_xml::XmlError),
#[error(transparent)]
IcalError(#[from] rustical_ical::Error),
} }
impl Error { impl Error {
@@ -40,6 +43,7 @@ impl Error {
Self::XmlDecodeError(_) => StatusCode::BAD_REQUEST, Self::XmlDecodeError(_) => StatusCode::BAD_REQUEST,
Self::ChronoParseError(_) | Self::NotImplemented => StatusCode::INTERNAL_SERVER_ERROR, Self::ChronoParseError(_) | Self::NotImplemented => StatusCode::INTERNAL_SERVER_ERROR,
Self::NotFound => StatusCode::NOT_FOUND, Self::NotFound => StatusCode::NOT_FOUND,
Self::IcalError(err) => err.status_code(),
} }
} }
} }

View File

@@ -28,7 +28,7 @@ headers.workspace = true
strum.workspace = true strum.workspace = true
matchit.workspace = true matchit.workspace = true
matchit-serde.workspace = true matchit-serde.workspace = true
caldata = { workspace = true, optional = true } ical = { workspace = true, optional = true }
[features] [features]
ical = ["dep:caldata"] ical = ["dep:ical"]

View File

@@ -51,18 +51,19 @@ impl Error {
_ => StatusCode::BAD_REQUEST, _ => StatusCode::BAD_REQUEST,
}, },
Self::PropReadOnly => StatusCode::CONFLICT, Self::PropReadOnly => StatusCode::CONFLICT,
Self::PreconditionFailed => StatusCode::PRECONDITION_FAILED,
Self::InternalError | Self::IOError(_) => StatusCode::INTERNAL_SERVER_ERROR, Self::InternalError | Self::IOError(_) => StatusCode::INTERNAL_SERVER_ERROR,
// The correct status code for a failed precondition is not PreconditionFailed but Self::Forbidden => StatusCode::FORBIDDEN,
// Forbidden (or Conflict):
// https://datatracker.ietf.org/doc/html/rfc4791#section-1.3
Self::PreconditionFailed | Self::Forbidden => StatusCode::FORBIDDEN,
} }
} }
} }
impl axum::response::IntoResponse for Error { impl axum::response::IntoResponse for Error {
fn into_response(self) -> axum::response::Response { fn into_response(self) -> axum::response::Response {
if matches!(self.status_code(), StatusCode::INTERNAL_SERVER_ERROR) { if matches!(
self.status_code(),
StatusCode::INTERNAL_SERVER_ERROR | StatusCode::PRECONDITION_FAILED
) {
error!("{self}"); error!("{self}");
} }

View File

@@ -6,15 +6,12 @@ use axum::{
extract::{MatchedPath, Path, State}, extract::{MatchedPath, Path, State},
response::{IntoResponse, Response}, response::{IntoResponse, Response},
}; };
use axum_extra::TypedHeader;
use headers::Host;
use http::{HeaderMap, StatusCode, Uri}; use http::{HeaderMap, StatusCode, Uri};
use matchit_serde::ParamsDeserializer; use matchit_serde::ParamsDeserializer;
use serde::Deserialize; use serde::Deserialize;
use tracing::instrument; use tracing::instrument;
#[instrument(skip(path, resource_service,))] #[instrument(skip(path, resource_service,))]
#[allow(clippy::too_many_arguments)]
pub async fn axum_route_copy<R: ResourceService>( pub async fn axum_route_copy<R: ResourceService>(
Path(path): Path<R::PathComponents>, Path(path): Path<R::PathComponents>,
State(resource_service): State<R>, State(resource_service): State<R>,
@@ -23,7 +20,6 @@ pub async fn axum_route_copy<R: ResourceService>(
Overwrite(overwrite): Overwrite, Overwrite(overwrite): Overwrite,
matched_path: MatchedPath, matched_path: MatchedPath,
header_map: HeaderMap, header_map: HeaderMap,
TypedHeader(host): TypedHeader<Host>,
) -> Result<Response, R::Error> { ) -> Result<Response, R::Error> {
let destination = header_map let destination = header_map
.get("Destination") .get("Destination")
@@ -31,11 +27,7 @@ pub async fn axum_route_copy<R: ResourceService>(
.to_str() .to_str()
.map_err(|_| crate::Error::Forbidden)?; .map_err(|_| crate::Error::Forbidden)?;
let destination_uri: Uri = destination.parse().map_err(|_| crate::Error::Forbidden)?; let destination_uri: Uri = destination.parse().map_err(|_| crate::Error::Forbidden)?;
if let Some(authority) = destination_uri.authority() // TODO: Check that host also matches
&& host != authority.clone().into()
{
return Err(crate::Error::Forbidden.into());
}
let destination = destination_uri.path(); let destination = destination_uri.path();
let mut router = matchit::Router::new(); let mut router = matchit::Router::new();

View File

@@ -6,15 +6,12 @@ use axum::{
extract::{MatchedPath, Path, State}, extract::{MatchedPath, Path, State},
response::{IntoResponse, Response}, response::{IntoResponse, Response},
}; };
use axum_extra::TypedHeader;
use headers::Host;
use http::{HeaderMap, StatusCode, Uri}; use http::{HeaderMap, StatusCode, Uri};
use matchit_serde::ParamsDeserializer; use matchit_serde::ParamsDeserializer;
use serde::Deserialize; use serde::Deserialize;
use tracing::instrument; use tracing::instrument;
#[instrument(skip(path, resource_service,))] #[instrument(skip(path, resource_service,))]
#[allow(clippy::too_many_arguments)]
pub async fn axum_route_move<R: ResourceService>( pub async fn axum_route_move<R: ResourceService>(
Path(path): Path<R::PathComponents>, Path(path): Path<R::PathComponents>,
State(resource_service): State<R>, State(resource_service): State<R>,
@@ -23,7 +20,6 @@ pub async fn axum_route_move<R: ResourceService>(
Overwrite(overwrite): Overwrite, Overwrite(overwrite): Overwrite,
matched_path: MatchedPath, matched_path: MatchedPath,
header_map: HeaderMap, header_map: HeaderMap,
TypedHeader(host): TypedHeader<Host>,
) -> Result<Response, R::Error> { ) -> Result<Response, R::Error> {
let destination = header_map let destination = header_map
.get("Destination") .get("Destination")
@@ -31,11 +27,7 @@ pub async fn axum_route_move<R: ResourceService>(
.to_str() .to_str()
.map_err(|_| crate::Error::Forbidden)?; .map_err(|_| crate::Error::Forbidden)?;
let destination_uri: Uri = destination.parse().map_err(|_| crate::Error::Forbidden)?; let destination_uri: Uri = destination.parse().map_err(|_| crate::Error::Forbidden)?;
if let Some(authority) = destination_uri.authority() // TODO: Check that host also matches
&& host != authority.clone().into()
{
return Err(crate::Error::Forbidden.into());
}
let destination = destination_uri.path(); let destination = destination_uri.path();
let mut router = matchit::Router::new(); let mut router = matchit::Router::new();

View File

@@ -71,7 +71,6 @@ pub async fn axum_route_proppatch<R: ResourceService>(
route_proppatch(&path, uri.path(), &body, &principal, &resource_service).await route_proppatch(&path, uri.path(), &body, &principal, &resource_service).await
} }
#[allow(clippy::too_many_lines)]
pub async fn route_proppatch<R: ResourceService>( pub async fn route_proppatch<R: ResourceService>(
path_components: &R::PathComponents, path_components: &R::PathComponents,
path: &str, path: &str,
@@ -117,14 +116,12 @@ pub async fn route_proppatch<R: ResourceService>(
} }
} }
SetPropertyPropWrapper::Invalid(invalid) => { SetPropertyPropWrapper::Invalid(invalid) => {
let Unparsed(propns, propname) = invalid; let propname = invalid.tag_name();
if let Some(full_propname) = <R::Resource as Resource>::list_props() if let Some(full_propname) = <R::Resource as Resource>::list_props()
.into_iter() .into_iter()
.find_map(|(ns, tag)| { .find_map(|(ns, tag)| {
if (ns, tag) if tag == propname.as_str() {
== (propns.as_ref().map(NamespaceOwned::as_ref), &propname)
{
Some((ns.map(NamespaceOwned::from), tag.to_owned())) Some((ns.map(NamespaceOwned::from), tag.to_owned()))
} else { } else {
None None
@@ -136,7 +133,7 @@ pub async fn route_proppatch<R: ResourceService>(
// - internal properties // - internal properties
props_conflict.push(full_propname); props_conflict.push(full_propname);
} else { } else {
props_not_found.push((propns, propname)); props_not_found.push((None, propname));
} }
} }
} }

View File

@@ -45,7 +45,7 @@ impl<PN: XmlDeserialize> XmlDeserialize for PropElement<PN> {
// start of a child element // start of a child element
Event::Start(start) | Event::Empty(start) => { Event::Start(start) | Event::Empty(start) => {
let empty = matches!(event, Event::Empty(_)); let empty = matches!(event, Event::Empty(_));
let (ns, name) = reader.resolver().resolve_element(start.name()); let (ns, name) = reader.resolve_element(start.name());
let ns = match ns { let ns = match ns {
ResolveResult::Bound(ns) => Some(NamespaceOwned::from(ns)), ResolveResult::Bound(ns) => Some(NamespaceOwned::from(ns)),
ResolveResult::Unknown(_ns) => todo!("handle error"), ResolveResult::Unknown(_ns) => todo!("handle error"),

View File

@@ -1,4 +1,4 @@
use caldata::parser::ContentLine; use ical::property::ContentLine;
use rustical_xml::{ValueDeserialize, XmlDeserialize}; use rustical_xml::{ValueDeserialize, XmlDeserialize};
use std::borrow::Cow; use std::borrow::Cow;

View File

@@ -15,7 +15,7 @@ chrono-tz.workspace = true
thiserror.workspace = true thiserror.workspace = true
derive_more.workspace = true derive_more.workspace = true
rustical_xml.workspace = true rustical_xml.workspace = true
caldata.workspace = true ical.workspace = true
regex.workspace = true regex.workspace = true
rrule.workspace = true rrule.workspace = true
serde.workspace = true serde.workspace = true

View File

@@ -1,23 +1,20 @@
use crate::{CalendarObject, Error}; use crate::{CalendarObject, Error};
use caldata::{
VcardParser,
component::{
CalendarInnerDataBuilder, ComponentMut, IcalAlarmBuilder, IcalCalendarObjectBuilder,
IcalEventBuilder, VcardContact,
},
generator::Emitter,
parser::ContentLine,
property::{
Calscale, IcalCALSCALEProperty, IcalDTENDProperty, IcalDTSTAMPProperty,
IcalDTSTARTProperty, IcalPRODIDProperty, IcalRRULEProperty, IcalSUMMARYProperty,
IcalUIDProperty, IcalVERSIONProperty, IcalVersion, VcardANNIVERSARYProperty,
VcardBDAYProperty, VcardFNProperty,
},
types::{CalDate, PartialDate, Timezone},
};
use chrono::{NaiveDate, Utc}; use chrono::{NaiveDate, Utc};
use ical::component::{
CalendarInnerDataBuilder, IcalAlarmBuilder, IcalCalendarObjectBuilder, IcalEventBuilder,
};
use ical::generator::Emitter;
use ical::parser::vcard::{self, component::VcardContact};
use ical::parser::{
Calscale, ComponentMut, IcalCALSCALEProperty, IcalDTENDProperty, IcalDTSTAMPProperty,
IcalDTSTARTProperty, IcalPRODIDProperty, IcalRRULEProperty, IcalSUMMARYProperty,
IcalUIDProperty, IcalVERSIONProperty, IcalVersion, VcardANNIVERSARYProperty, VcardBDAYProperty,
VcardFNProperty,
};
use ical::property::ContentLine;
use ical::types::{CalDate, PartialDate};
use sha2::{Digest, Sha256}; use sha2::{Digest, Sha256};
use std::collections::BTreeMap; use std::collections::HashMap;
use std::str::FromStr; use std::str::FromStr;
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
@@ -35,7 +32,7 @@ impl From<VcardContact> for AddressObject {
impl AddressObject { impl AddressObject {
pub fn from_vcf(vcf: String) -> Result<Self, Error> { pub fn from_vcf(vcf: String) -> Result<Self, Error> {
let parser = VcardParser::from_slice(vcf.as_bytes()); let parser = vcard::VcardParser::from_slice(vcf.as_bytes());
let vcard = parser.expect_one()?; let vcard = parser.expect_one()?;
Ok(Self { vcf, vcard }) Ok(Self { vcf, vcard })
} }
@@ -73,7 +70,7 @@ impl AddressObject {
let Some(dtstart) = NaiveDate::from_ymd_opt(year.unwrap_or(1900), month, day) else { let Some(dtstart) = NaiveDate::from_ymd_opt(year.unwrap_or(1900), month, day) else {
return Ok(None); return Ok(None);
}; };
let start_date = CalDate(dtstart, Timezone::Local); let start_date = CalDate(dtstart, ical::types::Timezone::Local);
let Some(end_date) = start_date.succ_opt() else { let Some(end_date) = start_date.succ_opt() else {
// start_date is MAX_DATE, this should never happen but FAPP also not raise an error // start_date is MAX_DATE, this should never happen but FAPP also not raise an error
return Ok(None); return Ok(None);
@@ -134,7 +131,7 @@ impl AddressObject {
.into(), .into(),
], ],
inner: Some(CalendarInnerDataBuilder::Event(vec![event])), inner: Some(CalendarInnerDataBuilder::Event(vec![event])),
vtimezones: BTreeMap::default(), vtimezones: HashMap::default(),
} }
.build(None)? .build(None)?
.into(), .into(),

View File

@@ -1,13 +1,9 @@
use std::sync::OnceLock;
use crate::Error; use crate::Error;
use caldata::{
IcalObjectParser,
component::{CalendarInnerData, IcalCalendarObject},
generator::Emitter,
parser::ParserOptions,
};
use derive_more::Display; use derive_more::Display;
use ical::IcalObjectParser;
use ical::component::CalendarInnerData;
use ical::component::IcalCalendarObject;
use ical::generator::Emitter;
use serde::Deserialize; use serde::Deserialize;
use serde::Serialize; use serde::Serialize;
use sha2::{Digest, Sha256}; use sha2::{Digest, Sha256};
@@ -68,35 +64,15 @@ impl rustical_xml::ValueDeserialize for CalendarObjectType {
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
pub struct CalendarObject { pub struct CalendarObject {
inner: IcalCalendarObject, inner: IcalCalendarObject,
ics: OnceLock<String>, ics: String,
} }
impl CalendarObject { impl CalendarObject {
// This function parses iCalendar data but doesn't cache it
// This is meant for iCalendar data coming from outside that might need to be normalised.
// For example if timezones are omitted this can be fixed by this function.
pub fn import(ics: &str, options: Option<ParserOptions>) -> Result<Self, Error> {
let parser =
IcalObjectParser::from_slice(ics.as_bytes()).with_options(options.unwrap_or_default());
let inner = parser.expect_one()?;
Ok(Self {
inner,
ics: OnceLock::new(),
})
}
// This function parses iCalendar data and then caches the parsed iCalendar data.
// This function is only meant for loading data from a data store where we know the iCalendar
// is already in the desired form.
pub fn from_ics(ics: String) -> Result<Self, Error> { pub fn from_ics(ics: String) -> Result<Self, Error> {
let parser = IcalObjectParser::from_slice(ics.as_bytes()); let parser = IcalObjectParser::from_slice(ics.as_bytes());
let inner = parser.expect_one()?; let inner = parser.expect_one()?;
Ok(Self { Ok(Self { inner, ics })
inner,
ics: ics.into(),
})
} }
#[must_use] #[must_use]
@@ -119,7 +95,7 @@ impl CalendarObject {
#[must_use] #[must_use]
pub fn get_ics(&self) -> &str { pub fn get_ics(&self) -> &str {
self.ics.get_or_init(|| self.inner.generate()) &self.ics
} }
#[must_use] #[must_use]
@@ -137,7 +113,7 @@ impl From<CalendarObject> for IcalCalendarObject {
impl From<IcalCalendarObject> for CalendarObject { impl From<IcalCalendarObject> for CalendarObject {
fn from(value: IcalCalendarObject) -> Self { fn from(value: IcalCalendarObject) -> Self {
Self { Self {
ics: value.generate().into(), ics: value.generate(),
inner: value, inner: value,
} }
} }

34
crates/ical/src/error.rs Normal file
View File

@@ -0,0 +1,34 @@
use axum::{http::StatusCode, response::IntoResponse};
#[derive(Debug, thiserror::Error, PartialEq, Eq)]
pub enum Error {
#[error("Invalid ics/vcf input: {0}")]
InvalidData(String),
#[error("Missing calendar")]
MissingCalendar,
#[error("Missing contact")]
MissingContact,
#[error(transparent)]
ParserError(#[from] ical::parser::ParserError),
}
impl Error {
#[must_use]
pub const fn status_code(&self) -> StatusCode {
match self {
Self::InvalidData(_) | Self::MissingCalendar | Self::MissingContact => {
StatusCode::BAD_REQUEST
}
Self::ParserError(_) => StatusCode::INTERNAL_SERVER_ERROR,
}
}
}
impl IntoResponse for Error {
fn into_response(self) -> axum::response::Response {
(self.status_code(), self.to_string()).into_response()
}
}

View File

@@ -1,13 +1,13 @@
#![warn(clippy::all, clippy::pedantic, clippy::nursery)] #![warn(clippy::all, clippy::pedantic, clippy::nursery)]
#![allow(clippy::missing_errors_doc, clippy::missing_panics_doc)] #![allow(clippy::missing_errors_doc, clippy::missing_panics_doc)]
mod timestamp; mod timestamp;
use caldata::parser::ParserError;
pub use timestamp::*; pub use timestamp::*;
mod calendar_object; mod calendar_object;
pub use calendar_object::*; pub use calendar_object::*;
mod error;
pub use error::Error;
mod address_object; mod address_object;
pub use address_object::AddressObject; pub use address_object::AddressObject;
pub type Error = ParserError;

View File

@@ -13,7 +13,7 @@ anyhow.workspace = true
async-trait.workspace = true async-trait.workspace = true
serde.workspace = true serde.workspace = true
sha2.workspace = true sha2.workspace = true
caldata.workspace = true ical.workspace = true
chrono.workspace = true chrono.workspace = true
regex.workspace = true regex.workspace = true
thiserror.workspace = true thiserror.workspace = true

View File

@@ -26,7 +26,7 @@ pub enum Error {
Other(#[from] anyhow::Error), Other(#[from] anyhow::Error),
#[error(transparent)] #[error(transparent)]
IcalError(#[from] caldata::parser::ParserError), IcalError(#[from] rustical_ical::Error),
} }
impl Error { impl Error {
@@ -36,7 +36,7 @@ impl Error {
Self::NotFound => StatusCode::NOT_FOUND, Self::NotFound => StatusCode::NOT_FOUND,
Self::AlreadyExists => StatusCode::CONFLICT, Self::AlreadyExists => StatusCode::CONFLICT,
Self::ReadOnly => StatusCode::FORBIDDEN, Self::ReadOnly => StatusCode::FORBIDDEN,
Self::IcalError(_err) => StatusCode::INTERNAL_SERVER_ERROR, Self::IcalError(err) => err.status_code(),
Self::InvalidPrincipalType(_) => StatusCode::BAD_REQUEST, Self::InvalidPrincipalType(_) => StatusCode::BAD_REQUEST,
_ => StatusCode::INTERNAL_SERVER_ERROR, _ => StatusCode::INTERNAL_SERVER_ERROR,
} }
@@ -52,7 +52,9 @@ impl IntoResponse for Error {
fn into_response(self) -> axum::response::Response { fn into_response(self) -> axum::response::Response {
if matches!( if matches!(
self.status_code(), self.status_code(),
StatusCode::INTERNAL_SERVER_ERROR | StatusCode::CONFLICT StatusCode::INTERNAL_SERVER_ERROR
| StatusCode::PRECONDITION_FAILED
| StatusCode::CONFLICT
) { ) {
error!("{self}"); error!("{self}");
} }

View File

@@ -20,7 +20,7 @@ rstest.workspace = true
criterion.workspace = true criterion.workspace = true
[dependencies] [dependencies]
caldata.workspace = true ical.workspace = true
tokio.workspace = true tokio.workspace = true
rustical_store.workspace = true rustical_store.workspace = true
async-trait.workspace = true async-trait.workspace = true
@@ -37,4 +37,3 @@ pbkdf2.workspace = true
rustical_ical.workspace = true rustical_ical.workspace = true
rstest = { workspace = true, optional = true } rstest = { workspace = true, optional = true }
sha2.workspace = true sha2.workspace = true
regex.workspace = true

View File

@@ -338,7 +338,7 @@ impl CalendarStore for SqliteAddressbookStore {
out_objects.push((format!("{object_id}-birthday"), birthday)); out_objects.push((format!("{object_id}-birthday"), birthday));
} }
if let Some(anniversary) = object.get_anniversary_object()? { if let Some(anniversary) = object.get_anniversary_object()? {
out_objects.push((format!("{object_id}-anniversary"), anniversary)); out_objects.push((format!("{object_id}-anniversayr"), anniversary));
} }
} }
@@ -382,7 +382,7 @@ impl CalendarStore for SqliteAddressbookStore {
objects.push((format!("{object_id}-birthday"), birthday)); objects.push((format!("{object_id}-birthday"), birthday));
} }
if let Some(anniversary) = object.get_anniversary_object()? { if let Some(anniversary) = object.get_anniversary_object()? {
objects.push((format!("{object_id}-anniversary"), anniversary)); objects.push((format!("{object_id}-anniversayr"), anniversary));
} }
} }
Ok(objects) Ok(objects)

View File

@@ -1,7 +1,6 @@
use super::ChangeOperation; use super::ChangeOperation;
use crate::BEGIN_IMMEDIATE; use crate::BEGIN_IMMEDIATE;
use async_trait::async_trait; use async_trait::async_trait;
use caldata::parser::ParserError;
use derive_more::derive::Constructor; use derive_more::derive::Constructor;
use rustical_ical::AddressObject; use rustical_ical::AddressObject;
use rustical_store::{ use rustical_store::{
@@ -10,7 +9,7 @@ use rustical_store::{
}; };
use sqlx::{Acquire, Executor, Sqlite, SqlitePool, Transaction}; use sqlx::{Acquire, Executor, Sqlite, SqlitePool, Transaction};
use tokio::sync::mpsc::Sender; use tokio::sync::mpsc::Sender;
use tracing::{error, error_span, instrument, warn}; use tracing::{error_span, instrument, warn};
pub mod birthday_calendar; pub mod birthday_calendar;
@@ -19,12 +18,6 @@ struct AddressObjectRow {
id: String, id: String,
vcf: String, vcf: String,
} }
impl From<AddressObjectRow> for (String, Result<AddressObject, ParserError>) {
fn from(row: AddressObjectRow) -> Self {
let result = AddressObject::from_vcf(row.vcf);
(row.id, result)
}
}
impl TryFrom<AddressObjectRow> for (String, AddressObject) { impl TryFrom<AddressObjectRow> for (String, AddressObject) {
type Error = rustical_store::Error; type Error = rustical_store::Error;
@@ -38,7 +31,6 @@ impl TryFrom<AddressObjectRow> for (String, AddressObject) {
pub struct SqliteAddressbookStore { pub struct SqliteAddressbookStore {
db: SqlitePool, db: SqlitePool,
sender: Sender<CollectionOperation>, sender: Sender<CollectionOperation>,
skip_broken: bool,
} }
impl SqliteAddressbookStore { impl SqliteAddressbookStore {
@@ -96,36 +88,6 @@ impl SqliteAddressbookStore {
Ok(()) Ok(())
} }
#[allow(clippy::missing_panics_doc)]
pub async fn validate_objects(&self, principal: &str) -> Result<(), Error> {
let mut success = true;
for addressbook in self.get_addressbooks(principal).await? {
for (object_id, res) in Self::_get_objects(&self.db, principal, &addressbook.id).await?
{
if let Err(err) = res {
warn!(
"Invalid address object found at {principal}/{addr_id}/{object_id}.vcf. Error: {err}",
addr_id = addressbook.id
);
success = false;
}
}
}
if !success {
if self.skip_broken {
error!(
"Not all address objects are valid. Since data_store.sqlite.skip_broken=true they will be hidden. You are still advised to manually remove or repair the object. If you need help feel free to open up an issue on GitHub."
);
} else {
error!(
"Not all address objects are valid. Since data_store.sqlite.skip_broken=false this causes a panic. Remove or repair the broken objects manually or set data_store.sqlite.skip_broken=false as a temporary solution to ignore the error. If you need help feel free to open up an issue on GitHub."
);
panic!();
}
}
Ok(())
}
// Logs an operation to an address object // Logs an operation to an address object
async fn log_object_operation( async fn log_object_operation(
tx: &mut Transaction<'_, Sqlite>, tx: &mut Transaction<'_, Sqlite>,
@@ -172,7 +134,7 @@ impl SqliteAddressbookStore {
if let Err(err) = self.sender.try_send(CollectionOperation { topic, data }) { if let Err(err) = self.sender.try_send(CollectionOperation { topic, data }) {
error_span!( error_span!(
"Error trying to send addressbook update notification:", "Error trying to send addressbook update notification:",
err = format!("{err}"), err = format!("{err:?}"),
); );
} }
} }
@@ -391,8 +353,8 @@ impl SqliteAddressbookStore {
executor: E, executor: E,
principal: &str, principal: &str,
addressbook_id: &str, addressbook_id: &str,
) -> Result<impl Iterator<Item = (String, Result<AddressObject, ParserError>)>, Error> { ) -> Result<Vec<(String, AddressObject)>, rustical_store::Error> {
Ok(sqlx::query_as!( sqlx::query_as!(
AddressObjectRow, AddressObjectRow,
"SELECT id, vcf FROM addressobjects WHERE principal = ? AND addressbook_id = ? AND deleted_at IS NULL", "SELECT id, vcf FROM addressobjects WHERE principal = ? AND addressbook_id = ? AND deleted_at IS NULL",
principal, principal,
@@ -401,8 +363,8 @@ impl SqliteAddressbookStore {
.fetch_all(executor) .fetch_all(executor)
.await.map_err(crate::Error::from)? .await.map_err(crate::Error::from)?
.into_iter() .into_iter()
.map(Into::into) .map(std::convert::TryInto::try_into)
) .collect()
} }
async fn _get_object<'e, E: Executor<'e, Database = Sqlite>>( async fn _get_object<'e, E: Executor<'e, Database = Sqlite>>(
@@ -645,16 +607,7 @@ impl AddressbookStore for SqliteAddressbookStore {
principal: &str, principal: &str,
addressbook_id: &str, addressbook_id: &str,
) -> Result<Vec<(String, AddressObject)>, rustical_store::Error> { ) -> Result<Vec<(String, AddressObject)>, rustical_store::Error> {
let objects = Self::_get_objects(&self.db, principal, addressbook_id).await?; Self::_get_objects(&self.db, principal, addressbook_id).await
if self.skip_broken {
Ok(objects
.filter_map(|(id, res)| Some((id, res.ok()?)))
.collect())
} else {
Ok(objects
.map(|(id, res)| res.map(|obj| (id, obj)))
.collect::<Result<Vec<_>, _>>()?)
}
} }
#[instrument] #[instrument]

View File

@@ -1,11 +1,9 @@
use super::ChangeOperation; use super::ChangeOperation;
use crate::BEGIN_IMMEDIATE; use crate::BEGIN_IMMEDIATE;
use async_trait::async_trait; use async_trait::async_trait;
use caldata::parser::ParserError;
use caldata::types::CalDateTime;
use chrono::TimeDelta; use chrono::TimeDelta;
use derive_more::derive::Constructor; use derive_more::derive::Constructor;
use regex::Regex; use ical::types::CalDateTime;
use rustical_ical::{CalendarObject, CalendarObjectType}; use rustical_ical::{CalendarObject, CalendarObjectType};
use rustical_store::calendar_store::CalendarQuery; use rustical_store::calendar_store::CalendarQuery;
use rustical_store::synctoken::format_synctoken; use rustical_store::synctoken::format_synctoken;
@@ -14,7 +12,7 @@ use rustical_store::{CollectionOperation, CollectionOperationInfo};
use sqlx::types::chrono::NaiveDateTime; use sqlx::types::chrono::NaiveDateTime;
use sqlx::{Acquire, Executor, Sqlite, SqlitePool, Transaction}; use sqlx::{Acquire, Executor, Sqlite, SqlitePool, Transaction};
use tokio::sync::mpsc::Sender; use tokio::sync::mpsc::Sender;
use tracing::{error, error_span, instrument, warn}; use tracing::{error_span, instrument, warn};
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
struct CalendarObjectRow { struct CalendarObjectRow {
@@ -23,37 +21,21 @@ struct CalendarObjectRow {
uid: String, uid: String,
} }
impl From<CalendarObjectRow> for (String, Result<CalendarObject, ParserError>) {
fn from(row: CalendarObjectRow) -> Self {
let result = CalendarObject::from_ics(row.ics).inspect(|object| {
if object.get_uid() != row.uid {
warn!(
"Calendar object {}.ics: UID={} and row uid={} do not match",
row.id,
object.get_uid(),
row.uid
);
}
});
(row.id, result)
}
}
impl TryFrom<CalendarObjectRow> for (String, CalendarObject) { impl TryFrom<CalendarObjectRow> for (String, CalendarObject) {
type Error = rustical_store::Error; type Error = rustical_store::Error;
fn try_from(row: CalendarObjectRow) -> Result<Self, Self::Error> { fn try_from(value: CalendarObjectRow) -> Result<Self, Self::Error> {
let object = CalendarObject::from_ics(row.ics)?; let object = CalendarObject::from_ics(value.ics)?;
if object.get_uid() != row.uid { if object.get_uid() != value.uid {
warn!( return Err(rustical_store::Error::IcalError(
"Calendar object {}.ics: UID={} and row uid={} do not match", rustical_ical::Error::InvalidData(format!(
row.id, "uid={} and UID={} don't match",
object.get_uid(), value.uid,
row.uid object.get_uid()
); )),
));
} }
Ok((row.id, object)) Ok((value.id, object))
} }
} }
@@ -110,7 +92,6 @@ impl From<CalendarRow> for Calendar {
pub struct SqliteCalendarStore { pub struct SqliteCalendarStore {
db: SqlitePool, db: SqlitePool,
sender: Sender<CollectionOperation>, sender: Sender<CollectionOperation>,
skip_broken: bool,
} }
impl SqliteCalendarStore { impl SqliteCalendarStore {
@@ -160,117 +141,11 @@ impl SqliteCalendarStore {
if let Err(err) = self.sender.try_send(CollectionOperation { topic, data }) { if let Err(err) = self.sender.try_send(CollectionOperation { topic, data }) {
error_span!( error_span!(
"Error trying to send calendar update notification:", "Error trying to send calendar update notification:",
err = format!("{err}"), err = format!("{err:?}"),
); );
} }
} }
#[allow(clippy::missing_panics_doc)]
pub async fn validate_objects(&self, principal: &str) -> Result<(), Error> {
let mut success = true;
for calendar in self.get_calendars(principal).await? {
for (object_id, res) in Self::_get_objects(&self.db, principal, &calendar.id).await? {
if let Err(err) = res {
warn!(
"Invalid calendar object found at {principal}/{cal_id}/{object_id}.ics. Error: {err}",
cal_id = calendar.id
);
success = false;
}
}
}
if !success {
if self.skip_broken {
error!(
"Not all calendar objects are valid. Since data_store.sqlite.skip_broken=true they will be hidden. You are still advised to manually remove or repair the object. If you need help feel free to open up an issue on GitHub."
);
} else {
error!(
"Not all calendar objects are valid. Since data_store.sqlite.skip_broken=false this causes a panic. Remove or repair the broken objects manually or set data_store.sqlite.skip_broken=false as a temporary solution to ignore the error. If you need help feel free to open up an issue on GitHub."
);
panic!();
}
}
Ok(())
}
/// In the past exports generated objects with invalid VERSION:4.0
/// This repair sets them to VERSION:2.0
#[allow(clippy::missing_panics_doc)]
pub async fn repair_invalid_version_4_0(&self) -> Result<(), Error> {
struct Row {
principal: String,
cal_id: String,
id: String,
ics: String,
}
let mut tx = self
.db
.begin_with(BEGIN_IMMEDIATE)
.await
.map_err(crate::Error::from)?;
#[allow(clippy::missing_panics_doc)]
let version_pattern = Regex::new(r"(?mi)^VERSION:4.0").unwrap();
let repairs: Vec<Row> = sqlx::query_as!(
Row,
r#"SELECT principal, cal_id, id, ics FROM calendarobjects WHERE ics LIKE '%VERSION:4.0%';"#
)
.fetch_all(&mut *tx)
.await
.map_err(crate::Error::from)?
.into_iter()
.filter_map(|mut row| {
version_pattern.find(&row.ics)?;
let new_ics = version_pattern.replace(&row.ics, "VERSION:2.0");
// Safeguard that we really only changed the version
assert_eq!(row.ics.len(), new_ics.len());
row.ics = new_ics.to_string();
Some(row)
})
.collect();
if repairs.is_empty() {
return Ok(());
}
warn!(
"Found {} calendar objects with invalid VERSION:4.0. Repairing by setting to VERSION:2.0",
repairs.len()
);
for repair in &repairs {
// calendarobjectchangelog is used by sync-collection to fetch changes
// By deleting entries we will later regenerate new entries such that clients will notice
// the objects have changed
warn!(
"Repairing VERSION for {}/{}/{}.ics",
repair.principal, repair.cal_id, repair.id
);
sqlx::query!(
"DELETE FROM calendarobjectchangelog WHERE (principal, cal_id, object_id) = (?, ?, ?);",
repair.principal, repair.cal_id, repair.id
).execute(&mut *tx).await
.map_err(crate::Error::from)?;
sqlx::query!(
"UPDATE calendarobjects SET ics = ? WHERE (principal, cal_id, id) = (?, ?, ?);",
repair.ics,
repair.principal,
repair.cal_id,
repair.id
)
.execute(&mut *tx)
.await
.map_err(crate::Error::from)?;
}
tx.commit().await.map_err(crate::Error::from)?;
Ok(())
}
// Commit "orphaned" objects to the changelog table // Commit "orphaned" objects to the changelog table
pub async fn repair_orphans(&self) -> Result<(), Error> { pub async fn repair_orphans(&self) -> Result<(), Error> {
struct Row { struct Row {
@@ -504,8 +379,8 @@ impl SqliteCalendarStore {
executor: E, executor: E,
principal: &str, principal: &str,
cal_id: &str, cal_id: &str,
) -> Result<impl Iterator<Item = (String, Result<CalendarObject, ParserError>)>, Error> { ) -> Result<Vec<(String, CalendarObject)>, Error> {
Ok(sqlx::query_as!( sqlx::query_as!(
CalendarObjectRow, CalendarObjectRow,
"SELECT id, uid, ics FROM calendarobjects WHERE principal = ? AND cal_id = ? AND deleted_at IS NULL", "SELECT id, uid, ics FROM calendarobjects WHERE principal = ? AND cal_id = ? AND deleted_at IS NULL",
principal, principal,
@@ -514,8 +389,8 @@ impl SqliteCalendarStore {
.fetch_all(executor) .fetch_all(executor)
.await.map_err(crate::Error::from)? .await.map_err(crate::Error::from)?
.into_iter() .into_iter()
.map(Into::into) .map(std::convert::TryInto::try_into)
) .collect()
} }
async fn _calendar_query<'e, E: Executor<'e, Database = Sqlite>>( async fn _calendar_query<'e, E: Executor<'e, Database = Sqlite>>(
@@ -523,14 +398,14 @@ impl SqliteCalendarStore {
principal: &str, principal: &str,
cal_id: &str, cal_id: &str,
query: CalendarQuery, query: CalendarQuery,
) -> Result<impl Iterator<Item = (String, Result<CalendarObject, ParserError>)>, Error> { ) -> Result<Vec<(String, CalendarObject)>, Error> {
// We extend our query interval by one day in each direction since we really don't want to // We extend our query interval by one day in each direction since we really don't want to
// miss any objects because of timezone differences // miss any objects because of timezone differences
// I've previously tried NaiveDate::MIN,MAX, but it seems like sqlite cannot handle these // I've previously tried NaiveDate::MIN,MAX, but it seems like sqlite cannot handle these
let start = query.time_start.map(|start| start - TimeDelta::days(1)); let start = query.time_start.map(|start| start - TimeDelta::days(1));
let end = query.time_end.map(|end| end + TimeDelta::days(1)); let end = query.time_end.map(|end| end + TimeDelta::days(1));
Ok(sqlx::query_as!( sqlx::query_as!(
CalendarObjectRow, CalendarObjectRow,
r"SELECT id, uid, ics FROM calendarobjects r"SELECT id, uid, ics FROM calendarobjects
WHERE principal = ? AND cal_id = ? AND deleted_at IS NULL WHERE principal = ? AND cal_id = ? AND deleted_at IS NULL
@@ -548,7 +423,8 @@ impl SqliteCalendarStore {
.await .await
.map_err(crate::Error::from)? .map_err(crate::Error::from)?
.into_iter() .into_iter()
.map(Into::into)) .map(std::convert::TryInto::try_into)
.collect()
} }
async fn _get_object<'e, E: Executor<'e, Database = Sqlite>>( async fn _get_object<'e, E: Executor<'e, Database = Sqlite>>(
@@ -688,7 +564,6 @@ impl SqliteCalendarStore {
principal: &str, principal: &str,
cal_id: &str, cal_id: &str,
synctoken: i64, synctoken: i64,
skip_broken: bool,
) -> Result<(Vec<(String, CalendarObject)>, Vec<String>, i64), Error> { ) -> Result<(Vec<(String, CalendarObject)>, Vec<String>, i64), Error> {
struct Row { struct Row {
object_id: String, object_id: String,
@@ -718,8 +593,6 @@ impl SqliteCalendarStore {
match Self::_get_object(&mut *conn, principal, cal_id, &object_id, false).await { match Self::_get_object(&mut *conn, principal, cal_id, &object_id, false).await {
Ok(object) => objects.push((object_id, object)), Ok(object) => objects.push((object_id, object)),
Err(rustical_store::Error::NotFound) => deleted_objects.push(object_id), Err(rustical_store::Error::NotFound) => deleted_objects.push(object_id),
// Skip broken object
Err(rustical_store::Error::IcalError(_)) if skip_broken => (),
Err(err) => return Err(err), Err(err) => return Err(err),
} }
} }
@@ -870,16 +743,7 @@ impl CalendarStore for SqliteCalendarStore {
cal_id: &str, cal_id: &str,
query: CalendarQuery, query: CalendarQuery,
) -> Result<Vec<(String, CalendarObject)>, Error> { ) -> Result<Vec<(String, CalendarObject)>, Error> {
let objects = Self::_calendar_query(&self.db, principal, cal_id, query).await?; Self::_calendar_query(&self.db, principal, cal_id, query).await
if self.skip_broken {
Ok(objects
.filter_map(|(id, res)| Some((id, res.ok()?)))
.collect())
} else {
Ok(objects
.map(|(id, res)| res.map(|obj| (id, obj)))
.collect::<Result<Vec<_>, _>>()?)
}
} }
async fn calendar_metadata( async fn calendar_metadata(
@@ -910,16 +774,7 @@ impl CalendarStore for SqliteCalendarStore {
principal: &str, principal: &str,
cal_id: &str, cal_id: &str,
) -> Result<Vec<(String, CalendarObject)>, Error> { ) -> Result<Vec<(String, CalendarObject)>, Error> {
let objects = Self::_get_objects(&self.db, principal, cal_id).await?; Self::_get_objects(&self.db, principal, cal_id).await
if self.skip_broken {
Ok(objects
.filter_map(|(id, res)| Some((id, res.ok()?)))
.collect())
} else {
Ok(objects
.map(|(id, res)| res.map(|obj| (id, obj)))
.collect::<Result<Vec<_>, _>>()?)
}
} }
#[instrument] #[instrument]
@@ -1042,7 +897,7 @@ impl CalendarStore for SqliteCalendarStore {
cal_id: &str, cal_id: &str,
synctoken: i64, synctoken: i64,
) -> Result<(Vec<(String, CalendarObject)>, Vec<String>, i64), Error> { ) -> Result<(Vec<(String, CalendarObject)>, Vec<String>, i64), Error> {
Self::_sync_changes(&self.db, principal, cal_id, synctoken, self.skip_broken).await Self::_sync_changes(&self.db, principal, cal_id, synctoken).await
} }
fn is_read_only(&self, _cal_id: &str) -> bool { fn is_read_only(&self, _cal_id: &str) -> bool {

View File

@@ -18,7 +18,7 @@ impl From<sqlx::Error> for Error {
sqlx::Error::RowNotFound => Self::StoreError(rustical_store::Error::NotFound), sqlx::Error::RowNotFound => Self::StoreError(rustical_store::Error::NotFound),
sqlx::Error::Database(err) => { sqlx::Error::Database(err) => {
if err.is_unique_violation() { if err.is_unique_violation() {
warn!("{err}"); warn!("{err:?}");
Self::StoreError(rustical_store::Error::AlreadyExists) Self::StoreError(rustical_store::Error::AlreadyExists)
} else { } else {
Self::SqlxError(sqlx::Error::Database(err)) Self::SqlxError(sqlx::Error::Database(err))

View File

@@ -52,8 +52,8 @@ pub async fn test_store_context() -> TestStoreContext {
let db = get_test_db().await; let db = get_test_db().await;
TestStoreContext { TestStoreContext {
db: db.clone(), db: db.clone(),
addr_store: SqliteAddressbookStore::new(db.clone(), send_addr, false), addr_store: SqliteAddressbookStore::new(db.clone(), send_addr),
cal_store: SqliteCalendarStore::new(db.clone(), send_cal, false), cal_store: SqliteCalendarStore::new(db.clone(), send_cal),
principal_store: SqlitePrincipalStore::new(db.clone()), principal_store: SqlitePrincipalStore::new(db.clone()),
sub_store: SqliteStore::new(db), sub_store: SqliteStore::new(db),
} }

View File

@@ -136,7 +136,7 @@ impl NamedStruct {
#(#builder_field_inits),* #(#builder_field_inits),*
}; };
let (ns, name) = reader.resolver().resolve_element(start.name()); let (ns, name) = reader.resolve_element(start.name());
#(#tagname_field_branches);* #(#tagname_field_branches);*
#(#namespace_field_branches);* #(#namespace_field_branches);*
@@ -161,7 +161,7 @@ impl NamedStruct {
// start of a child element // start of a child element
Event::Start(start) | Event::Empty(start) => { Event::Start(start) | Event::Empty(start) => {
let empty = matches!(event, Event::Empty(_)); let empty = matches!(event, Event::Empty(_));
let (ns, name) = reader.resolver().resolve_element(start.name()); let (ns, name) = reader.resolve_element(start.name());
match (ns, name.as_ref()) { match (ns, name.as_ref()) {
#(#named_field_branches),* #(#named_field_branches),*
#(#untagged_field_branches),* #(#untagged_field_branches),*

View File

@@ -42,7 +42,7 @@ impl<T: XmlRootTag + XmlDeserialize> XmlDocument for T {
match event { match event {
Event::Decl(_) | Event::Comment(_) => { /* ignore this */ } Event::Decl(_) | Event::Comment(_) => { /* ignore this */ }
Event::Start(start) | Event::Empty(start) => { Event::Start(start) | Event::Empty(start) => {
let (ns, name) = reader.resolver().resolve_element(start.name()); let (ns, name) = reader.resolve_element(start.name());
let matches = match (Self::root_ns(), &ns, name) { let matches = match (Self::root_ns(), &ns, name) {
// Wrong tag // Wrong tag
(_, _, name) if name.as_ref() != Self::root_tag().as_bytes() => false, (_, _, name) if name.as_ref() != Self::root_tag().as_bytes() => false,

View File

@@ -1,6 +1,6 @@
use quick_xml::name::Namespace; use quick_xml::name::Namespace;
#[derive(Debug, Clone, Default, PartialEq, Eq, Hash)] #[derive(Debug, Clone, Default, PartialEq, Eq)]
pub struct NamespaceOwned(pub Vec<u8>); pub struct NamespaceOwned(pub Vec<u8>);
impl<'a> From<Namespace<'a>> for NamespaceOwned { impl<'a> From<Namespace<'a>> for NamespaceOwned {

View File

@@ -1,21 +1,18 @@
use std::io::BufRead; use std::io::BufRead;
use quick_xml::{events::BytesStart, name::ResolveResult}; use quick_xml::events::BytesStart;
use crate::{NamespaceOwned, XmlDeserialize, XmlError}; use crate::{XmlDeserialize, XmlError};
// TODO: actually implement
#[derive(Debug, Clone, PartialEq, Eq, Hash)] #[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct Unparsed(pub Option<NamespaceOwned>, pub String); pub struct Unparsed(String);
impl Unparsed { impl Unparsed {
#[must_use] #[must_use]
pub const fn ns(&self) -> Option<&NamespaceOwned> { pub fn tag_name(&self) -> String {
self.0.as_ref() // TODO: respect namespace?
} self.0.clone()
#[must_use]
pub const fn tag_name(&self) -> &str {
self.1.as_str()
} }
} }
@@ -30,12 +27,7 @@ impl XmlDeserialize for Unparsed {
let mut buf = vec![]; let mut buf = vec![];
reader.read_to_end_into(start.name(), &mut buf)?; reader.read_to_end_into(start.name(), &mut buf)?;
} }
let (ns, tag_name) = reader.resolver().resolve_element(start.name()); let tag_name = String::from_utf8_lossy(start.local_name().as_ref()).to_string();
let ns: Option<NamespaceOwned> = match ns { Ok(Self(tag_name))
ResolveResult::Bound(ns) => Some(ns.into()),
ResolveResult::Unbound | ResolveResult::Unknown(_) => None,
};
let tag_name = String::from_utf8_lossy(tag_name.as_ref()).to_string();
Ok(Self(ns, tag_name))
} }
} }

View File

@@ -9,7 +9,7 @@ use axum_extra::TypedHeader;
use headers::{HeaderMapExt, UserAgent}; use headers::{HeaderMapExt, UserAgent};
use http::header::CONNECTION; use http::header::CONNECTION;
use http::{HeaderValue, StatusCode}; use http::{HeaderValue, StatusCode};
use rustical_caldav::{CalDavConfig, caldav_router}; use rustical_caldav::caldav_router;
use rustical_carddav::carddav_router; use rustical_carddav::carddav_router;
use rustical_frontend::nextcloud_login::nextcloud_login_router; use rustical_frontend::nextcloud_login::nextcloud_login_router;
use rustical_frontend::{FrontendConfig, frontend_router}; use rustical_frontend::{FrontendConfig, frontend_router};
@@ -45,7 +45,6 @@ pub fn make_app<
auth_provider: Arc<impl AuthenticationProvider>, auth_provider: Arc<impl AuthenticationProvider>,
frontend_config: FrontendConfig, frontend_config: FrontendConfig,
oidc_config: Option<OidcConfig>, oidc_config: Option<OidcConfig>,
caldav_config: CalDavConfig,
nextcloud_login_config: &NextcloudLoginConfig, nextcloud_login_config: &NextcloudLoginConfig,
dav_push_enabled: bool, dav_push_enabled: bool,
session_cookie_samesite_strict: bool, session_cookie_samesite_strict: bool,
@@ -55,8 +54,6 @@ pub fn make_app<
let combined_cal_store = let combined_cal_store =
Arc::new(CombinedCalendarStore::new(cal_store).with_store(birthday_store)); Arc::new(CombinedCalendarStore::new(cal_store).with_store(birthday_store));
let caldav_config = Arc::new(caldav_config);
let mut router = Router::new() let mut router = Router::new()
// endpoint to be used by healthcheck to see if rustical is online // endpoint to be used by healthcheck to see if rustical is online
.route("/ping", axum::routing::get(async || "Pong!")) .route("/ping", axum::routing::get(async || "Pong!"))
@@ -66,7 +63,6 @@ pub fn make_app<
combined_cal_store.clone(), combined_cal_store.clone(),
subscription_store.clone(), subscription_store.clone(),
false, false,
caldav_config.clone(),
)) ))
.merge(caldav_router( .merge(caldav_router(
"/caldav-compat", "/caldav-compat",
@@ -74,7 +70,6 @@ pub fn make_app<
combined_cal_store.clone(), combined_cal_store.clone(),
subscription_store.clone(), subscription_store.clone(),
true, true,
caldav_config,
)) ))
.route( .route(
"/.well-known/caldav", "/.well-known/caldav",

View File

@@ -3,7 +3,6 @@ use crate::config::{
SqliteDataStoreConfig, TracingConfig, SqliteDataStoreConfig, TracingConfig,
}; };
use clap::Parser; use clap::Parser;
use rustical_caldav::CalDavConfig;
use rustical_frontend::FrontendConfig; use rustical_frontend::FrontendConfig;
pub mod health; pub mod health;
@@ -16,11 +15,8 @@ pub struct GenConfigArgs {}
pub fn cmd_gen_config(_args: GenConfigArgs) -> anyhow::Result<()> { pub fn cmd_gen_config(_args: GenConfigArgs) -> anyhow::Result<()> {
let config = Config { let config = Config {
http: HttpConfig::default(), http: HttpConfig::default(),
caldav: CalDavConfig::default(),
data_store: DataStoreConfig::Sqlite(SqliteDataStoreConfig { data_store: DataStoreConfig::Sqlite(SqliteDataStoreConfig {
db_url: "/var/lib/rustical/db.sqlite3".to_owned(), db_url: "/var/lib/rustical/db.sqlite3".to_owned(),
run_repairs: true,
skip_broken: true,
}), }),
tracing: TracingConfig::default(), tracing: TracingConfig::default(),
frontend: FrontendConfig { frontend: FrontendConfig {

View File

@@ -1,4 +1,3 @@
use rustical_caldav::CalDavConfig;
use rustical_frontend::FrontendConfig; use rustical_frontend::FrontendConfig;
use rustical_oidc::OidcConfig; use rustical_oidc::OidcConfig;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
@@ -27,10 +26,6 @@ impl Default for HttpConfig {
#[serde(deny_unknown_fields)] #[serde(deny_unknown_fields)]
pub struct SqliteDataStoreConfig { pub struct SqliteDataStoreConfig {
pub db_url: String, pub db_url: String,
#[serde(default = "default_true")]
pub run_repairs: bool,
#[serde(default = "default_true")]
pub skip_broken: bool,
} }
#[derive(Debug, Deserialize, Serialize)] #[derive(Debug, Deserialize, Serialize)]
@@ -98,6 +93,4 @@ pub struct Config {
pub dav_push: DavPushConfig, pub dav_push: DavPushConfig,
#[serde(default)] #[serde(default)]
pub nextcloud_login: NextcloudLoginConfig, pub nextcloud_login: NextcloudLoginConfig,
#[serde(default)]
pub caldav: CalDavConfig,
} }

View File

@@ -8,7 +8,7 @@ use rustical_store::{CalendarMetadata, CalendarStore};
use rustical_store_sqlite::tests::{TestStoreContext, test_store_context}; use rustical_store_sqlite::tests::{TestStoreContext, test_store_context};
use tower::ServiceExt; use tower::ServiceExt;
pub fn mkcalendar_template( fn mkcalendar_template(
CalendarMetadata { CalendarMetadata {
displayname, displayname,
order: _order, order: _order,

View File

@@ -1,77 +0,0 @@
use axum::body::Body;
use headers::{Authorization, HeaderMapExt};
use http::{Request, StatusCode};
use rstest::rstest;
use rustical_store::CalendarMetadata;
use rustical_store_sqlite::tests::{TestStoreContext, test_store_context};
use tower::ServiceExt;
use crate::integration_tests::{
ResponseExtractString, caldav::calendar::mkcalendar_template, get_app,
};
#[rstest]
#[tokio::test]
async fn test_put_invalid(
#[from(test_store_context)]
#[future]
context: TestStoreContext,
) {
let context = context.await;
let app = get_app(context.clone());
let calendar_meta = CalendarMetadata {
displayname: Some("Calendar".to_string()),
description: Some("Description".to_string()),
color: Some("#00FF00".to_string()),
order: 0,
};
let (principal, cal_id) = ("user", "calendar");
let url = format!("/caldav/principal/{principal}/{cal_id}");
let mut request = Request::builder()
.method("MKCALENDAR")
.uri(&url)
.body(Body::from(mkcalendar_template(&calendar_meta)))
.unwrap();
request
.headers_mut()
.typed_insert(Authorization::basic("user", "pass"));
let response = app.clone().oneshot(request).await.unwrap();
assert_eq!(response.status(), StatusCode::CREATED);
// Invalid calendar data
let ical = r"BEGIN:VCALENDAR
VERSION:2.0
PRODID:-//Example Corp.//CalDAV Client//EN
BEGIN:VEVENT
UID:20010712T182145Z-123401@example.com
DTSTAMP:20060712T182145Z
DTSTART:20060714T170000Z
RRULE:UNTIL=123
DTEND:20060715T040000Z
SUMMARY:Bastille Day Party
END:VEVENT
END:VCALENDAR";
let mut request = Request::builder()
.method("PUT")
.uri(format!("{url}/qwue23489.ics"))
.header("If-None-Match", "*")
.header("Content-Type", "text/calendar")
.body(Body::from(ical))
.unwrap();
request
.headers_mut()
.typed_insert(Authorization::basic("user", "pass"));
let response = app.clone().oneshot(request).await.unwrap();
assert_eq!(response.status(), StatusCode::FORBIDDEN);
let body = response.extract_string().await;
insta::assert_snapshot!(body, @r#"
<?xml version="1.0" encoding="utf-8"?>
<error xmlns="DAV:" xmlns:CAL="urn:ietf:params:xml:ns:caldav" xmlns:CARD="urn:ietf:params:xml:ns:carddav" xmlns:CS="http://calendarserver.org/ns/" xmlns:PUSH="https://bitfire.at/webdav-push">
<CAL:valid-calendar-data/>
</error>
"#);
}

View File

@@ -87,79 +87,70 @@ const REPORT_7_8_3: &str = r#"
</C:calendar-query> </C:calendar-query>
"#; "#;
// Adapted from Example 7.8.3 of RFC 4791 const OUTPUT_7_8_3: &str = r#"
// In the RFC the output is wrong since it returns DTSTART in UTC as local time, e.g. <D:response>
// DTSTART:20060103T170000 <D:href>http://cal.example.com/bernard/work/abcd2.ics</D:href>
// instead of <D:propstat>
// DTSTART:20060103T170000Z <D:prop>
// In https://datatracker.ietf.org/doc/html/rfc4791#section-9.6.5 <D:getetag>"fffff-abcd2"</D:getetag>
// it is clearly stated that times with timezone information MUST be returned in UTC. <C:calendar-data>BEGIN:VCALENDAR
// Also, the RECURRENCE-ID needs to include the TIMEZONE, which is fixed here by converting it to VERSION:2.0
// UTC PRODID:-//Example Corp.//CalDAV Client//EN
const OUTPUT_7_8_3: &str = r#"<?xml version="1.0" encoding="utf-8"?> BEGIN:VEVENT
<multistatus xmlns="DAV:" xmlns:CAL="urn:ietf:params:xml:ns:caldav" xmlns:CARD="urn:ietf:params:xml:ns:carddav" xmlns:CS="http://calendarserver.org/ns/" xmlns:PUSH="https://bitfire.at/webdav-push"> DTSTAMP:20060206T001121Z
<response> DTSTART:20060103T170000
<href>/caldav/principal/user/calendar/abcd2.ics</href> DURATION:PT1H
<propstat> RECURRENCE-ID:20060103T170000
<prop> SUMMARY:Event #2
<CAL:calendar-data>BEGIN:VCALENDAR UID:00959BC664CA650E933C892C@example.com
VERSION:2.0 END:VEVENT
PRODID:-//Example Corp.//CalDAV Client//EN BEGIN:VEVENT
BEGIN:VEVENT DTSTAMP:20060206T001121Z
DTSTAMP:20060206T001121Z DTSTART:20060104T190000
DTSTART:20060103T170000Z DURATION:PT1H
DURATION:PT1H RECURRENCE-ID:20060104T170000
SUMMARY:Event #2 SUMMARY:Event #2 bis
UID:abcd2 UID:00959BC664CA650E933C892C@example.com
RECURRENCE-ID:20060103T170000Z END:VEVENT
END:VEVENT END:VCALENDAR
BEGIN:VEVENT </C:calendar-data>
DTSTAMP:20060206T001121Z </D:prop>
DTSTART:20060104T190000Z <D:status>HTTP/1.1 200 OK</D:status>
DURATION:PT1H </D:propstat>
RECURRENCE-ID:20060104T170000Z </D:response>
SUMMARY:Event #2 bis <D:response>
UID:abcd2 <D:href>http://cal.example.com/bernard/work/abcd3.ics</D:href>
END:VEVENT <D:propstat>
END:VCALENDAR <D:prop>
</CAL:calendar-data> <D:getetag>"fffff-abcd3"</D:getetag>
</prop> <C:calendar-data>BEGIN:VCALENDAR
<status>HTTP/1.1 200 OK</status> VERSION:2.0
</propstat> PRODID:-//Example Corp.//CalDAV Client//EN
</response> BEGIN:VEVENT
<response> ATTENDEE;PARTSTAT=ACCEPTED;ROLE=CHAIR:mailto:cyrus@example.com
<href>/caldav/principal/user/calendar/abcd3.ics</href> ATTENDEE;PARTSTAT=NEEDS-ACTION:mailto:lisa@example.com
<propstat> DTSTAMP:20060206T001220Z
<prop> DTSTART:20060104T150000
<CAL:calendar-data>BEGIN:VCALENDAR DURATION:PT1H
VERSION:2.0 LAST-MODIFIED:20060206T001330Z
PRODID:-//Example Corp.//CalDAV Client//EN ORGANIZER:mailto:cyrus@example.com
BEGIN:VEVENT SEQUENCE:1
ATTENDEE;PARTSTAT=ACCEPTED;ROLE=CHAIR:mailto:cyrus@example.com STATUS:TENTATIVE
ATTENDEE;PARTSTAT=NEEDS-ACTION:mailto:lisa@example.com SUMMARY:Event #3
DTSTAMP:20060206T001220Z UID:DC6C50A017428C5216A2F1CD@example.com
DTSTART:20060104T150000Z X-ABC-GUID:E1CX5Dr-0007ym-Hz@example.com
DURATION:PT1H END:VEVENT
LAST-MODIFIED:20060206T001330Z END:VCALENDAR
ORGANIZER:mailto:cyrus@example.com </C:calendar-data>
SEQUENCE:1 </D:prop>
STATUS:TENTATIVE <D:status>HTTP/1.1 200 OK</D:status>
SUMMARY:Event #3 </D:propstat>
UID:abcd3 "#;
X-ABC-GUID:E1CX5Dr-0007ym-Hz@example.com
END:VEVENT
END:VCALENDAR
</CAL:calendar-data>
</prop>
<status>HTTP/1.1 200 OK</status>
</propstat>
</response>
</multistatus>"#;
#[rstest] #[rstest]
#[case(0, ICS_1, REPORT_7_8_1, None)] #[case(0, ICS_1, REPORT_7_8_1)]
#[case(1, ICS_1, REPORT_7_8_2, None)] #[case(1, ICS_1, REPORT_7_8_2)]
#[case(2, ICS_1, REPORT_7_8_3, Some(OUTPUT_7_8_3))] #[case(2, ICS_1, REPORT_7_8_3)]
#[tokio::test] #[tokio::test]
async fn test_report( async fn test_report(
#[from(test_store_context)] #[from(test_store_context)]
@@ -168,7 +159,6 @@ async fn test_report(
#[case] case: usize, #[case] case: usize,
#[case] ics: &'static str, #[case] ics: &'static str,
#[case] report: &'static str, #[case] report: &'static str,
#[case] output: Option<&'static str>,
) { ) {
let context = context.await; let context = context.await;
let app = get_app(context.clone()); let app = get_app(context.clone());
@@ -203,7 +193,4 @@ async fn test_report(
assert_eq!(response.status(), StatusCode::MULTI_STATUS); assert_eq!(response.status(), StatusCode::MULTI_STATUS);
let body = response.extract_string().await; let body = response.extract_string().await;
insta::assert_snapshot!(format!("{case}_report_body"), body); insta::assert_snapshot!(format!("{case}_report_body"), body);
if let Some(output) = output {
similar_asserts::assert_eq!(output, body.replace('\r', ""));
}
} }

View File

@@ -9,8 +9,7 @@ use tower::ServiceExt;
mod calendar; mod calendar;
mod calendar_import; mod calendar_import;
mod calendar_put; // mod calendar_report;
mod calendar_report;
#[rstest] #[rstest]
#[tokio::test] #[tokio::test]

View File

@@ -55,7 +55,6 @@ SEQUENCE:1
STATUS:TENTATIVE STATUS:TENTATIVE
SUMMARY:Event #3 SUMMARY:Event #3
UID:abcd3 UID:abcd3
X-ABC-GUID:E1CX5Dr-0007ym-Hz@example.com
END:VEVENT END:VEVENT
BEGIN:VTODO BEGIN:VTODO
DTSTAMP:20060205T235335Z DTSTAMP:20060205T235335Z

View File

@@ -8,7 +8,7 @@ expression: body
<href>/caldav/principal/user/calendar/qwue23489.ics</href> <href>/caldav/principal/user/calendar/qwue23489.ics</href>
<propstat> <propstat>
<prop> <prop>
<getetag>&quot;f781224669f0db2674e9e45a9be2b01774c02136e3fb72792ef217bccf49fafa&quot;</getetag> <getetag>&quot;aea50382a7775bb9742bfec277382e3a260b6066f503b5f5ae34548d7215ee46&quot;</getetag>
</prop> </prop>
<status>HTTP/1.1 200 OK</status> <status>HTTP/1.1 200 OK</status>
</propstat> </propstat>

View File

@@ -14,10 +14,9 @@ expression: body
PRODID:-//github.com/lennart-k/vzic-rs//RustiCal Calendar server//EN PRODID:-//github.com/lennart-k/vzic-rs//RustiCal Calendar server//EN
VERSION:2.0 VERSION:2.0
BEGIN:VTIMEZONE BEGIN:VTIMEZONE
TZID:US/Eastern TZID:America/New_York
TZID-ALIAS-OF:America/New_York LAST-MODIFIED:20250723T190331Z
LAST-MODIFIED:20260124T185655Z X-LIC-LOCATION:America/New_York
X-LIC-LOCATION:US/Eastern
X-PROLEPTIC-TZNAME:LMT X-PROLEPTIC-TZNAME:LMT
BEGIN:STANDARD BEGIN:STANDARD
TZNAME:EST TZNAME:EST

View File

@@ -60,7 +60,6 @@ SEQUENCE:1
STATUS:TENTATIVE STATUS:TENTATIVE
SUMMARY:Event #3 SUMMARY:Event #3
UID:[UID] UID:[UID]
X-ABC-GUID:[UID]
END:VEVENT END:VEVENT
BEGIN:VTODO BEGIN:VTODO
DTSTAMP:20060205T235335Z DTSTAMP:20060205T235335Z

View File

@@ -56,7 +56,7 @@ END:VCALENDAR
<href>/caldav/principal/user/calendar/abcd3.ics</href> <href>/caldav/principal/user/calendar/abcd3.ics</href>
<propstat> <propstat>
<prop> <prop>
<getetag>&quot;a84fd022dfc742bf8f17ac04fca3aad687e9ae724180185e8e0df11e432dae30&quot;</getetag> <getetag>&quot;c6a5b1cf6985805686df99e7f2e1cf286567dcb3383fc6fa1b12ce42d3fbc01c&quot;</getetag>
<CAL:calendar-data>BEGIN:VCALENDAR <CAL:calendar-data>BEGIN:VCALENDAR
VERSION:2.0 VERSION:2.0
PRODID:-//Example Corp.//CalDAV Client//EN PRODID:-//Example Corp.//CalDAV Client//EN
@@ -90,7 +90,6 @@ SEQUENCE:1
STATUS:TENTATIVE STATUS:TENTATIVE
SUMMARY:Event #3 SUMMARY:Event #3
UID:abcd3 UID:abcd3
X-ABC-GUID:E1CX5Dr-0007ym-Hz@example.com
END:VEVENT END:VEVENT
END:VCALENDAR END:VCALENDAR
</CAL:calendar-data> </CAL:calendar-data>

View File

@@ -88,7 +88,6 @@ SEQUENCE:1
STATUS:TENTATIVE STATUS:TENTATIVE
SUMMARY:Event #3 SUMMARY:Event #3
UID:abcd3 UID:abcd3
X-ABC-GUID:E1CX5Dr-0007ym-Hz@example.com
END:VEVENT END:VEVENT
END:VCALENDAR END:VCALENDAR
</CAL:calendar-data> </CAL:calendar-data>

View File

@@ -13,19 +13,19 @@ VERSION:2.0
PRODID:-//Example Corp.//CalDAV Client//EN PRODID:-//Example Corp.//CalDAV Client//EN
BEGIN:VEVENT BEGIN:VEVENT
DTSTAMP:20060206T001121Z DTSTAMP:20060206T001121Z
DTSTART:20060103T170000Z
DURATION:PT1H DURATION:PT1H
SUMMARY:Event #2 SUMMARY:Event #2
UID:abcd2 UID:abcd2
RECURRENCE-ID:20060103T170000Z RECURRENCE-ID:20060103T170000Z
DTSTART:20060103T170000Z
END:VEVENT END:VEVENT
BEGIN:VEVENT BEGIN:VEVENT
DTSTAMP:20060206T001121Z DTSTAMP:20060206T001121Z
DTSTART:20060104T190000Z
DURATION:PT1H DURATION:PT1H
RECURRENCE-ID:20060104T170000Z SUMMARY:Event #2
SUMMARY:Event #2 bis
UID:abcd2 UID:abcd2
RECURRENCE-ID:20060104T170000Z
DTSTART:20060104T170000Z
END:VEVENT END:VEVENT
END:VCALENDAR END:VCALENDAR
</CAL:calendar-data> </CAL:calendar-data>
@@ -44,7 +44,7 @@ BEGIN:VEVENT
ATTENDEE;PARTSTAT=ACCEPTED;ROLE=CHAIR:mailto:cyrus@example.com ATTENDEE;PARTSTAT=ACCEPTED;ROLE=CHAIR:mailto:cyrus@example.com
ATTENDEE;PARTSTAT=NEEDS-ACTION:mailto:lisa@example.com ATTENDEE;PARTSTAT=NEEDS-ACTION:mailto:lisa@example.com
DTSTAMP:20060206T001220Z DTSTAMP:20060206T001220Z
DTSTART:20060104T150000Z DTSTART;TZID=US/Eastern:20060104T100000
DURATION:PT1H DURATION:PT1H
LAST-MODIFIED:20060206T001330Z LAST-MODIFIED:20060206T001330Z
ORGANIZER:mailto:cyrus@example.com ORGANIZER:mailto:cyrus@example.com
@@ -52,7 +52,6 @@ SEQUENCE:1
STATUS:TENTATIVE STATUS:TENTATIVE
SUMMARY:Event #3 SUMMARY:Event #3
UID:abcd3 UID:abcd3
X-ABC-GUID:E1CX5Dr-0007ym-Hz@example.com
END:VEVENT END:VEVENT
END:VCALENDAR END:VCALENDAR
</CAL:calendar-data> </CAL:calendar-data>

View File

@@ -2,7 +2,6 @@ use crate::{app::make_app, config::NextcloudLoginConfig};
use axum::extract::Request; use axum::extract::Request;
use axum::{body::Body, response::Response}; use axum::{body::Body, response::Response};
use rstest::rstest; use rstest::rstest;
use rustical_caldav::CalDavConfig;
use rustical_frontend::FrontendConfig; use rustical_frontend::FrontendConfig;
use rustical_store_sqlite::tests::{TestStoreContext, test_store_context}; use rustical_store_sqlite::tests::{TestStoreContext, test_store_context};
use std::sync::Arc; use std::sync::Arc;
@@ -27,7 +26,6 @@ pub fn get_app(context: TestStoreContext) -> axum::Router {
allow_password_login: true, allow_password_login: true,
}, },
None, None,
CalDavConfig::default(),
&NextcloudLoginConfig { enabled: false }, &NextcloudLoginConfig { enabled: false },
false, false,
true, true,

View File

@@ -25,7 +25,7 @@ use std::sync::Arc;
use tokio::sync::mpsc::Receiver; use tokio::sync::mpsc::Receiver;
use tower::Layer; use tower::Layer;
use tower_http::normalize_path::NormalizePathLayer; use tower_http::normalize_path::NormalizePathLayer;
use tracing::{info, warn}; use tracing::info;
mod app; mod app;
mod commands; mod commands;
@@ -67,36 +67,17 @@ async fn get_data_stores(
Receiver<CollectionOperation>, Receiver<CollectionOperation>,
)> { )> {
Ok(match &config { Ok(match &config {
DataStoreConfig::Sqlite(SqliteDataStoreConfig { DataStoreConfig::Sqlite(SqliteDataStoreConfig { db_url }) => {
db_url,
run_repairs,
skip_broken,
}) => {
let db = create_db_pool(db_url, migrate).await?; let db = create_db_pool(db_url, migrate).await?;
// Channel to watch for changes (for DAV Push) // Channel to watch for changes (for DAV Push)
let (send, recv) = tokio::sync::mpsc::channel(1000); let (send, recv) = tokio::sync::mpsc::channel(1000);
let addressbook_store = Arc::new(SqliteAddressbookStore::new( let addressbook_store = Arc::new(SqliteAddressbookStore::new(db.clone(), send.clone()));
db.clone(), addressbook_store.repair_orphans().await?;
send.clone(), let cal_store = Arc::new(SqliteCalendarStore::new(db.clone(), send));
*skip_broken, cal_store.repair_orphans().await?;
));
let cal_store = Arc::new(SqliteCalendarStore::new(db.clone(), send, *skip_broken));
if *run_repairs {
info!("Running repair tasks");
addressbook_store.repair_orphans().await?;
cal_store.repair_invalid_version_4_0().await?;
cal_store.repair_orphans().await?;
}
let subscription_store = Arc::new(SqliteStore::new(db.clone())); let subscription_store = Arc::new(SqliteStore::new(db.clone()));
let principal_store = Arc::new(SqlitePrincipalStore::new(db)); let principal_store = Arc::new(SqlitePrincipalStore::new(db));
// Validate all calendar objects
for principal in principal_store.get_principals().await? {
cal_store.validate_objects(&principal.id).await?;
addressbook_store.validate_objects(&principal.id).await?;
}
( (
addressbook_store, addressbook_store,
cal_store, cal_store,
@@ -153,7 +134,6 @@ async fn main() -> Result<()> {
principal_store.clone(), principal_store.clone(),
config.frontend.clone(), config.frontend.clone(),
config.oidc.clone(), config.oidc.clone(),
config.caldav,
&config.nextcloud_login, &config.nextcloud_login,
config.dav_push.enabled, config.dav_push.enabled,
config.http.session_cookie_samesite_strict, config.http.session_cookie_samesite_strict,