107 Commits

Author SHA1 Message Date
Alex Dunmow
bcc2aea1d9 caldav: serve principal-URL and, through PrincipalNameBackend, displayname on the principal
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-26 23:51:22 +08:00
Alex Dunmow
089a0be495 caldav: sync-collection only on calendars, and review fixes
- sync-collection answers 403 unless the path is a calendar, and not a
  schedule inbox or outbox. A missing sync-level is level 1.
- DAV:sync-token is not returned for DAV:allprop (RFC 6578 section 4).
- schedule-response carries calendar-data only for a 2.x request-status.
- XML responses with a status other than 200 (207 and errors) set
  Content-Type before WriteHeader, so it is no longer dropped.
- Docs: sync-tokens are URIs; FreeBusyBackend advertises
  calendar-auto-schedule, so the backend owns scheduling.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-26 07:55:09 +08:00
Alex Dunmow
b044a6de1a caldav: getctag, sync-collection, scheduling properties and free/busy
Calendar gains CTag (CS:getctag), SyncToken (DAV:sync-token) and
Transparent (CALDAV:schedule-calendar-transp). Three optional Backend
interfaces, checked with type assertions:

- SyncBackend answers the sync-collection REPORT (RFC 6578) and adds
  DAV:supported-report-set to calendars. ErrInvalidSyncToken gives 403
  with DAV:valid-sync-token.
- PrincipalBackend serves calendar-user-address-set, schedule-inbox-URL
  and schedule-outbox-URL on the principal, and the inbox and outbox
  collections themselves (RFC 6638 section 2).
- FreeBusyBackend answers a VFREEBUSY POST to the outbox with a
  schedule-response (RFC 6638 section 10.3), and adds
  calendar-auto-schedule to the DAV header.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-26 07:49:40 +08:00
Jay Hemnani
1e38b14489 webdav: reject COPY and MOVE onto the same path
RFC 4918 sections 9.8.5 and 9.9.4 say the server should return 403 when
the source and destination are the same. Overwriting the destination
deletes the source, so LocalFileSystem lost the file.

Check this in the shared handler so every backend gets it.
2026-11-21 11:19:42 +01:00
Robin van der Vleuten
ad1766c2ef
caldav, carddav: fill ReadOnly from current-user-privilege-set in client 2026-11-13 13:54:26 +01:00
Anton Skorochod
1901d193ce caldav, carddav: derive current-user-privilege-set from a read-only flag
The server hard-coded DAV:read + DAV:write in current-user-privilege-set for
every collection (with a TODO). Add a ReadOnly field to Calendar and AddressBook
that the backend sets per request; report DAV:write only when it is false, so
clients (e.g. DAVx5, Apple) correctly mark read-only collections. Default
(false) keeps the previous read-write behavior.
2026-06-25 10:34:50 +02:00
Ruben Aleman
0463911636
internal: preserve trailing slashes in baseURL and principal path
Closes: https://github.com/emersion/go-webdav/issues/203
2026-04-11 12:38:55 +02:00
Simon Ser
9f9be606d3 internal: introduce HrefError
Holds the href value alongside the error.

References: https://github.com/emersion/go-webdav/issues/195
2025-11-16 18:41:10 +01:00
prasad83
a16253aa97 caldav, carddav: add current-user-privilege-set 2025-10-18 10:48:59 +02:00
prasad83
0e74e6df11 caldav, carddav: add principal to resourcetype 2025-10-18 10:48:16 +02:00
Noah Kleiner
80149e46a4
internal/server: handle "allprop" with empty request and XML content type
The previous code failed to properly handle PROPFIND with an empty request body
(RFC 4918 section 9.1) for XML content type requests.

Refactor the logic to always consider PROPFIND requests with empty request
bodies as "allprop" requests, regardless of content type.

There is no need to worry about the request's content type if the request body
is empty anyway, so only parse if we know it is not.
2025-10-03 22:18:30 +02:00
Timo Furrer
aba953c3b6 Implement context path discovery for CalDav/CardDav endpoint
This change set implements the "context path" discovery for the
CalDav/CardDav endpoints.

This basically implements the bootstrapping process as defined in
RFC6764 section 6, point 2 and 3.

What's missing in this implementation is the fallback that is described
in point 3, subpoint 3, which says that if the context path discovered
in the TXT RR is not reachable the .well-known URI should be used
instead.

I propose to implement this in a future iteration.
2025-02-21 10:50:48 +01:00
Simon Ser
3cc7466ac9 internal: add PropFindValue
NewPropFindResponse uses callbacks to lazily build the response.
However, some props are static: they don't require any processing
to generate. Add a small helper to reduce boilerplate a bit.
2025-01-13 23:00:32 +01:00
Thomas Müller
948f33c2fc internal: use application/xml instead of text/xml which is deprecated 2024-04-11 17:16:25 +02:00
Thomas Müller
3ed9a4f052 carddav, caldav: add missing headers on PUT
ETag and Last-Modified should be set to the new calendar object or
address object properties.
2024-03-28 11:22:46 +01:00
Conrad Hoffmann
25f1014ef2 internal: no status element in propstat responses
Responses that contain propstat elements do not contain their own
top-level status element, only the status elements inside the propstat
element.

See https://datatracker.ietf.org/doc/html/rfc4918#section-14.24 or any
of the examples for PROPFIND/PROPPATCH, starting e.g. here:
https://datatracker.ietf.org/doc/html/rfc4918#section-9.1.3
2024-02-08 23:12:59 +01:00
Simon Ser
f1d56f2437 internal: add IsRequestEmpty 2024-02-07 17:23:17 +01:00
Simon Ser
b043bbd965 internal/server: handle PROPFIND without body
See RFC 4918 section 9.1.
2024-01-08 14:58:24 +01:00
Simon Ser
7e076258d6 caldav: add DiscoverContextURL 2023-12-27 23:16:49 +01:00
Simon Ser
379a418130 Add context for clients 2023-12-19 21:29:37 +01:00
Sebastien Binet
7d337ac048 internal: fix always-true interface comparison
This CL corrects the following bug uncovered by staticcheck:

```
  internal/elements.go:148:6: this comparison is always true (SA4023)
    internal/elements.go:146:18: the lhs of the comparison gets its value from here and has a concrete type
```

Signed-off-by: Sebastien Binet <binet@cern.ch>
2023-12-15 15:07:59 +01:00
Simon Ser
d7891ce50c internal: fix XML element struct naming
We were sometimes using TitleCase, sometimes Lowercase. Let's align
on the idiomatic Go naming and pick TitleCase everywhere.
2022-05-31 23:04:42 +02:00
Simon Ser
55a9274ba6 internal: use Namespace instead of "DAV:" 2022-05-31 17:10:30 +02:00
Simon Ser
1c71a7a1c4 internal: add more context to Response.DecodeProp errors 2022-05-31 17:04:44 +02:00
Simon Ser
d0fc22a428 internal: use errors.As in IsNotFound
Allows it to work properly with wrapped errors.
2022-05-31 16:58:45 +02:00
Simon Ser
9bc7a8f15b internal: drop Multistatus.Get
This is now unused.
2022-05-31 16:11:08 +02:00
Conrad Hoffmann
03633121d9 client: support redirects in PropfindFlat()
One common method for CalDAV or CardDAV clients to find the current user
principal URL is to request the `/.well-known` URL (see [RFC 6764,
section 6][1]), expecting a redirect. Such URL is for example a valid
result of the discovery phase described in that RFC. The expectation is
that a client, given such URL, is able to find the principal URL by
following a redirect when sending a PROPFIND request.

This change makes `PropfindFlat()` (and, by extension,
`FindCurrentUserPrincipal()`) handle such a redirect and correctly
return the requested properties, even if their HREF is different from
the original request path.

[1]: https://datatracker.ietf.org/doc/html/rfc6764#section-6
2022-05-31 16:05:54 +02:00
Simon Ser
d8a8af0448 internal: don't send an empty error element
According to RFC 4918 section 14.5, the error element can't be empty.
2022-05-02 20:41:33 +02:00
Simon Ser
3f8b212b0d internal: add Response.Err
Builds a detailed HTTPError + Error if the Response is a failure.
It contains more context than just the HTTPError.
2022-05-02 15:43:43 +02:00
Simon Ser
46ebe58ac2 internal: introduce NewErrorResponse
Same as NewOKResponse but for errors.
2022-05-02 15:43:43 +02:00
Simon Ser
4e8c5effe3 Replace DAVError with HTTPError + Error
That way we can avoid having different ways of representing the
same error value.
2022-05-02 15:43:43 +02:00
Simon Ser
8738a105fc internal: add HTTPError.Unwrap
This allows callers to access the underlying error via errors.Unwrap.
2022-05-02 15:43:43 +02:00
Conrad Hoffmann
85d2b222bb Add error type representing DAV/XML errors
Backends will need some way to signal that a precondition error occurred
(and specifying which one) without causing the server to return a 500.
This commit adds an exported function to create a specific error for
this. The existing error handling routine is slightly adapted to handle
this error in such a way that it returns the desired result.

Usage would be something like:

```
return "", carddav.NewPreconditionError(carddav.PreconditionNoUIDConflict)
```

which triggers the following HTTP response:

```
HTTP/1.1 409 Conflict.
Content-Type: text/xml; charset=utf-8.
Date: Thu, 10 Mar 2022 10:28:56 GMT.
Content-Length: 141.
Connection: close.

<?xml version="1.0" encoding="UTF-8"?>
<error xmlns="DAV:"><no-uid-conflict
xmlns="urn:ietf:params:xml:ns:carddav"></no-uid-conflict></error>
```

This response gets correctly recognized by e.g. Evolution (though it's
handling is not great).

The added error type is generic enough to be used for other stuff also.
As it is not exported (internal package), new functions for creating
such errors would have to be added.
2022-03-10 16:48:11 +01:00
Sebastien Binet
8efde26ef9
internal: use http.TimeFormat to marshal Time values 2021-03-16 18:42:55 +01:00
Apehaenger
ed52608852
Make Response.Path return the path on error 2021-01-12 12:57:28 +01:00
proletarius101
9cd3bb51b9 fix: deprecrated conversion from int64 to string 2020-09-09 16:00:38 +02:00
AlmogBaku
9e23289610 sync-collection for client 2020-05-25 18:28:24 +02:00
Simon Ser
25df841e2b
internal: move HTTPError to common file
This is used by both clients and servers now.
2020-05-13 18:24:29 +02:00
Simon Ser
4c0dc5d900
internal: parse WebDAV toplevel <error> elements 2020-05-13 15:02:52 +02:00
Simon Ser
f4e3fe8c0a
internal: add Multistatus.Get test with HTTP error
References: https://github.com/emersion/go-webdav/issues/39
2020-04-05 14:37:17 +02:00
AlmogBaku
1b725cb0b9 fixes #33, remove missingPropError error 2020-04-02 16:48:13 +02:00
Simon Ser
ddf2a85958
Introduce HTTPClient, remove Client.SetBasicAuth 2020-02-19 16:02:49 +01:00
Simon Ser
a81a7014c6
internal: remove outdated TODO 2020-02-12 20:06:06 +01:00
Simon Ser
7d0d522fa7
internal: prevent empty endpoint path from resulting in "." sub-paths 2020-02-12 20:04:31 +01:00
Simon Ser
30eac28d2b
internal: read response body on error 2020-02-12 19:46:05 +01:00
Simon Ser
a892cc58df
internal: only handle relative paths in Client.ResolveHref
Don't prepend the endpoint path in front of absolute paths.
2020-02-12 17:13:12 +01:00
Simon Ser
0b2d0a706c
internal: accomodate for trailign slashes in Multistatus.Get 2020-02-12 17:12:21 +01:00
Simon Ser
7f285fdf83
internal: fix Client.PropfindFlat when endpoint has a non-empty path 2020-02-12 16:40:30 +01:00
Simon Ser
9afa59dc22
internal: fix trailing slash getting removed in Client.ResolveHref 2020-02-12 16:40:03 +01:00
Simon Ser
57df6bf316
caldav: add filter XML definition 2020-02-05 17:07:35 +01:00