Struct libdav::CalDavClient

source ·
pub struct CalDavClient {
    pub calendar_home_set: Option<Uri>,
    /* private fields */
}
Expand description

A client to communicate with a caldav server.

Wraps around a WebDavClient, which provides the underlying functionality.

Fields§

§calendar_home_set: Option<Uri>

URL of collections that are either calendar collections or ordinary collections that have child or descendant calendar collections owned by the principal. See: https://www.rfc-editor.org/rfc/rfc4791#section-6.2.1

Implementations§

source§

impl CalDavClient

source

pub fn raw_client(base_url: Uri, auth: Auth) -> Self

Returns a client without any automatic bootstrapping.

It is generally advised to use CalDavClient::auto_bootstrap instead.

source

pub async fn auto_bootstrap( base_url: Uri, auth: Auth ) -> Result<Self, BootstrapError>

Auto-bootstrap a new client.

Determines the caldav server’s real host and the context path of the resources for a server, following the discovery mechanism described in rfc6764.

Errors

If any of the underlying DNS or HTTP requests fail, or if any of the responses fail to parse.

Does not return an error if DNS records as missing, only if they contain invalid data.

source

pub async fn find_calendars( &self, url: &Uri ) -> Result<Vec<(String, Option<String>)>, DavError>

Find calendars collections under the given url.

Returns absolute paths to each calendar and their respective etag, if any. This method should be called with the calendar_home_set URL to find the current user’s calendars.

Errors

If the HTTP call fails or parsing the XML response fails.

source

pub async fn get_calendar_colour( &self, href: &str ) -> Result<Option<String>, DavError>

Returns the colour for the calendar at path href.

This is not a formally standardised property, but is relatively widespread.

Errors

If the network request fails, or if the response cannot be parsed.

source

pub async fn get_resources<Href>( &self, calendar_href: Href, hrefs: Vec<Href> ) -> Result<Vec<FetchedResource>, GetResourceError>where Href: AsRef<str>,

Fetches existing icalendar resources.

Errors

See request_multistatus.

source

pub async fn check_support(&self, url: &Uri) -> Result<(), CheckSupportError>

Checks that the given URI advertises caldav support.

See: https://www.rfc-editor.org/rfc/rfc4791#section-5.1

Known Issues
  • This is currently broken on Nextcloud. Bug report.
Errors

If there are any network issues or if the server does not explicitly advertise caldav support.

Methods from Deref<Target = WebDavClient>§

source

pub fn context_path(&self) -> &Uri

Returns a URL pointing to the server’s context path.

source

pub fn relative_uri(&self, path: &str) -> Result<Uri, Error>

Returns a new URI relative to the server’s root.

Errors

If this client’s base_url is invalid or the provided path is not an acceptable path.

source

pub async fn find_current_user_principal( &self ) -> Result<Option<Uri>, FindCurrentUserPrincipalError>

Resolves the current user’s principal resource.

Returns None if the response’s status code is 404 or if no principal was found.

Errors
  • If the underlying HTTP request fails.
  • If the response status code is neither success nor 404.
  • If parsing the XML response fails.
  • If the href cannot be parsed into a valid Uri
See also
source

pub async fn propfind<T: FromXml>( &self, url: &Uri, prop: &str, depth: u8, data: &T::Data ) -> Result<Vec<Response<T>>, DavError>

Sends a PROPFIND request and parses the result.

This is a shortcut for simple PROPFIND requests.

Errors

See request_multistatus.

source

pub async fn request_multistatus<T: FromXml>( &self, request: Request<Body>, data: &T::Data ) -> Result<Multistatus<T>, DavError>

Send a request which expects a multistatus response and parse it as T.

Errors
  • If a network error occurs executing the underlying HTTP request.
  • If the server returns an error status code.
  • If the response is not a valid XML document.
  • If the response’s XML schema does not match the expected type.
source

pub async fn get_collection_displayname( &self, href: &str ) -> Result<Option<String>, DavError>

Returns the displayname for the collection at path href.

From rfc3744#section-4:

A principal MUST have a non-empty DAV:displayname property

Errors

See request_multistatus.

source

pub async fn find_context_path( &self, service: DiscoverableService, host: &str, port: u16 ) -> Result<Option<Uri>, ResolveContextPathError>

Resolve the default context path using a well-known path.

This only applies for servers supporting webdav extensions like caldav or carddav.

Errors
  • If the provided scheme, host and port cannot be used to construct a valid URL.
  • If there are any network errors.
  • If the response is not an HTTP redirection.
  • If the Location header in the response is missing or invalid.
See also
source

pub async fn list_resources( &self, collection_href: &str ) -> Result<Vec<ListedResource>, DavError>

Enumerates resources in a collection

Returns an array of results.

Errors

See request_multistatus.

source

pub async fn create_resource<Href, MimeType>( &self, href: Href, data: Vec<u8>, mime_type: MimeType ) -> Result<Option<Vec<u8>>, CreateResourceError>where Href: AsRef<str>, MimeType: AsRef<[u8]>,

Creates a new resource

Returns an Etag if present in the server’s response.

Errors

See request_multistatus.

source

pub async fn update_resource<Href, Etag, MimeType>( &self, href: Href, data: Vec<u8>, etag: Etag, mime_type: MimeType ) -> Result<Option<Vec<u8>>, UpdateResourceError>where Href: AsRef<str>, Etag: AsRef<[u8]>, MimeType: AsRef<[u8]>,

Updates an existing resource

Returns an Etag if present in the server’s response.

Errors

See request_multistatus.

source

pub async fn create_collection<Href: AsRef<str>>( &self, href: Href, resourcetype: CollectionType ) -> Result<(), CreateCollectionError>

Creates a collection under path href.

Caveats

Because servers commonly don’t return an Etag for this operation, it needs to be fetched in a separate operation.

Errors

See request_multistatus.

source

pub async fn delete<Href, Etag>( &self, href: Href, etag: Etag ) -> Result<(), DeleteError>where Href: AsRef<str>, Etag: AsRef<[u8]>,

Deletes the resource at href.

The resource MAY be a collection. Because the implementation for deleting resources and collections is identical, this same method covers both cases.

Errors

See request_multistatus.

source

pub async fn force_delete<Href>(&self, href: Href) -> Result<(), DeleteError>where Href: AsRef<str>,

Force deletion of the resource at href.

This function cannot guarantee that a resource or collection has not been modified since it was last read. Use this function with great care.

The resource MAY be a collection. Because the implementation for deleting resources and collections is identical, this same method covers both cases.

Errors

See request_multistatus.

Trait Implementations§

source§

impl Debug for CalDavClient

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Deref for CalDavClient

§

type Target = WebDavClient

The resulting type after dereferencing.
source§

fn deref(&self) -> &Self::Target

Dereferences the value.
source§

impl DerefMut for CalDavClient

source§

fn deref_mut(&mut self) -> &mut WebDavClient

Mutably dereferences the value.

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T> Instrument for T

source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
source§

impl<T, U> Into<U> for Twhere U: From<T>,

const: unstable · source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<Source, Target> OctetsInto<Target> for Sourcewhere Target: OctetsFrom<Source>,

source§

fn octets_into(self) -> Result<Target, ShortBuf>

Performs the conversion.
source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
const: unstable · source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for Twhere V: MultiLane<T>,

§

fn vzip(self) -> V

source§

impl<T> WithSubscriber for T

source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more