Struct libdav::CalDavClient

source ·
pub struct CalDavClient<C>
where C: Connect + Clone + Sync + Send + 'static,
{ pub webdav_client: WebDavClient<C>, }
Expand description

Client to communicate with a caldav server.

Instances are usually created via CalDavClient::new.

use http::Uri;
use libdav::auth::{Auth, Password};
use hyper_rustls::HttpsConnectorBuilder;

let uri = Uri::try_from("https://example.com").unwrap();
let auth = Auth::Basic {
    username: String::from("user"),
    password: Some(Password::from("secret")),
};

let https = HttpsConnectorBuilder::new()
    .with_native_roots()
    .unwrap()
    .https_or_http()
    .enable_http1()
    .build();
let webdav = WebDavClient::new(uri, auth, https);
// Optionally, perform bootstrap sequence here.
let client = CalDavClient::new(webdav);

If the real CalDav server needs to be resolved via bootstrapping, see find_context_url.

Fields§

§webdav_client: WebDavClient<C>

A WebDav client used to send requests.

Implementations§

source§

impl<C> CalDavClient<C>
where C: Connect + Clone + Sync + Send,

source

pub fn new(webdav_client: WebDavClient<C>) -> CalDavClient<C>

Create a new client instance.

source

pub async fn new_via_bootstrap( webdav_client: WebDavClient<C>, ) -> Result<CalDavClient<C>, BootstrapError>

Create a new client instance.

Creates a new client, with its base_url set to the context path automatically discovered via find_context_url.

§Errors

Returns an error if:

  • The URL has an invalid schema.
  • The underlying call to find_context_url returns an error.
source

pub async fn find_calendar_home_set( &self, principal: &Uri, ) -> Result<Vec<Uri>, FindHomeSetError>
where C: Connect + Clone + Sync + Send,

Queries the server for the calendar home set.

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

§Errors

If there are any network errors or the response could not be parsed.

source

pub async fn find_calendars( &self, calendar_home_set: &Uri, ) -> Result<Vec<FoundCollection>, WebDavError>

Find calendars collections under the given url.

If url is not specified, this client’s calendar home set is used instead. If no calendar home set has been found, then the server’s context path will be used. When using a client bootstrapped via automatic discovery, passing None will usually yield the expected results.

§Errors

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

source

pub async fn get_calendar_resources( &self, calendar_href: impl AsRef<str>, hrefs: impl IntoIterator<Item = impl AsRef<str>>, ) -> Result<Vec<FetchedResource>, WebDavError>

Fetches existing icalendar resources.

If the getetag property is missing for an item, it will be reported as http::StatusCode::NOT_FOUND. This should not be an actual issue with in practice, since support for getetag is mandatory for CalDav implementations.

§Errors

If there are any network errors or the response could not be parsed.

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.

source

pub async fn create_calendar( &self, href: impl AsRef<str>, ) -> Result<(), WebDavError>

Create an calendar collection.

§Errors

Returns an error in case of network errors or if the server returns a failure status code.

Methods from Deref<Target = WebDavClient<C>>§

source

pub fn base_url(&self) -> &Uri

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

source

pub fn relative_uri(&self, path: impl AsRef<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( &self, url: &Uri, properties: &[&PropertyName<'_, '_>], depth: u8, ) -> Result<(Parts, Bytes), WebDavError>

Sends a PROPFIND request.

This is a shortcut for simple PROPFIND requests.

§Errors

If there are any network errors.

source

pub async fn request( &self, request: Request<String>, ) -> Result<(Parts, Bytes), RequestError>

Send a request to the server.

Sends a request, applying any necessary authentication and logging the response.

§Errors

Returns an error if the underlying http request fails or if streaming the response fails.

source

pub async fn get_property( &self, href: &str, property: &PropertyName<'_, '_>, ) -> Result<Option<String>, WebDavError>

Fetch a single property.

§Common properties
§Quirks

The namespace of the value in the response from the server is ignored. This is a workaround for an issue in cyrus-imapd.

§Errors
  • If there are any network errors or the response could not be parsed.
  • If the requested property is missing in the response.
§See also
source

pub async fn get_properties<'p>( &self, href: &str, properties: &[&PropertyName<'p, 'p>], ) -> Result<Vec<(PropertyName<'p, 'p>, Option<String>)>, WebDavError>

Fetch multiple properties for a single resource.

Values in the returned Vec are in the same order as the properties parameter.

§Quirks

Same as WebDavClient::get_property.

§Errors
  • If there are any network errors or the response could not be parsed.
  • If the requested property is missing in the response.
§See also
source

pub async fn set_property( &self, href: &str, property: &PropertyName<'_, '_>, value: Option<&str>, ) -> Result<Option<String>, WebDavError>

Sends a PROPUPDATE query to the server.

Setting the value to None will remove the property. Returns the new value as returned by the server.

§Quirks

Same as WebDavClient::get_property.

§Errors

If there are any network errors or the response could not be parsed.

§See also
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. Returns Ok(None) if the well-known path does not redirect to another location.

§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>, WebDavError>

Enumerates resources in a collection

§Errors

If there are any network errors or the response could not be parsed.

source

pub async fn create_resource( &self, href: impl AsRef<str>, data: Vec<u8>, mime_type: impl AsRef<[u8]>, ) -> Result<Option<String>, WebDavError>

Creates a new resource

Returns an Etag if present in the response. If the Etag is not included, it must be requested in a follow-up request, and cannot be obtained race-free.

§Errors

If there are any network errors or the response could not be parsed.

source

pub async fn update_resource( &self, href: impl AsRef<str>, data: Vec<u8>, etag: impl AsRef<str>, mime_type: impl AsRef<[u8]>, ) -> Result<Option<String>, WebDavError>

Updates an existing resource

Returns an Etag if present in the response. If the Etag is not included, it must be requested in a follow-up request, and cannot be obtained race-free.

§Errors

If there are any network errors or the response could not be parsed.

source

pub async fn create_collection( &self, href: impl AsRef<str>, resourcetypes: &[&PropertyName<'_, '_>], ) -> Result<(), WebDavError>

Creates a collection under path href.

This function executes an Extended MKCOL.

Additional resource types may be specified via the resourcetypes argument. The DAV:collection resource type is implied and MUST NOT be specified.

§Errors

If there are any network errors or the response could not be parsed.

source

pub async fn delete( &self, href: impl AsRef<str>, etag: impl AsRef<str>, ) -> Result<(), WebDavError>

Deletes the resource at href.

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

If the Etag does not match (i.e.: if the resource has been altered), the operation will fail and return an Error.

§Errors

If there are any network errors or the response could not be parsed.

source

pub async fn force_delete( &self, href: impl AsRef<str>, ) -> Result<(), WebDavError>

Force deletion of the resource at href.

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

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

§Errors

If there are any network errors or the response could not be parsed.

Trait Implementations§

source§

impl<C> Clone for CalDavClient<C>
where C: Connect + Clone + Sync + Send + 'static + Clone,

source§

fn clone(&self) -> CalDavClient<C>

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<C> Debug for CalDavClient<C>
where C: Connect + Clone + Sync + Send + 'static + Debug,

source§

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

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

impl<C> Deref for CalDavClient<C>
where C: Connect + Clone + Sync + Send,

§

type Target = WebDavClient<C>

The resulting type after dereferencing.
source§

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

Dereferences the value.

Auto Trait Implementations§

§

impl<C> !Freeze for CalDavClient<C>

§

impl<C> !RefUnwindSafe for CalDavClient<C>

§

impl<C> Send for CalDavClient<C>

§

impl<C> Sync for CalDavClient<C>

§

impl<C> Unpin for CalDavClient<C>
where C: Unpin,

§

impl<C> !UnwindSafe for CalDavClient<C>

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

source§

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

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

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 T
where U: From<T>,

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 Source
where Target: OctetsFrom<Source>,

§

type Error = <Target as OctetsFrom<Source>>::Error

source§

fn try_octets_into( self, ) -> Result<Target, <Source as OctetsInto<Target>>::Error>

Performs the conversion.
source§

fn octets_into(self) -> Target
where Self::Error: Into<Infallible>,

Performs an infallible conversion.
source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

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

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

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

Performs the conversion.
source§

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

§

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

The type returned in the event of a conversion error.
source§

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

Performs the conversion.
source§

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

source§

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