Documentation
¶
Overview ¶
Package davx is Frostmail's WebDAV client for CardDAV (RFC 6352) and CalDAV (RFC 4791): discovery, collections, sync-collection (RFC 6578), multiget, and conditional writes of raw objects (ADR-0017). Objects are bytes with ETags; parsing them is the caller's business (ADR-0018).
A Client talks to one origin, the home set's. Credentials go only there, to origins Options.Trusted accepts, and never over plain HTTP unless Options.AllowHTTP is set.
Index ¶
- Variables
- func Discover(ctx context.Context, start string, kind Kind, opts Options) (string, error)
- type Change
- type Client
- func (c *Client) Collections(ctx context.Context, kind Kind) ([]Collection, error)
- func (c *Client) DefaultCalendar(ctx context.Context) (string, error)
- func (c *Client) Delete(ctx context.Context, href, ifMatch string) error
- func (c *Client) Get(ctx context.Context, href string) (Object, error)
- func (c *Client) List(ctx context.Context, coll string) ([]Change, error)
- func (c *Client) Multiget(ctx context.Context, kind Kind, coll string, hrefList []string) (objs []Object, missing []string, err error)
- func (c *Client) Put(ctx context.Context, href string, data []byte, kind Kind, ifMatch string) (Written, error)
- func (c *Client) Sync(ctx context.Context, coll, token string) (Delta, error)
- func (c *Client) URL() string
- type Collection
- type Delta
- type Kind
- type Object
- type Options
- type StatusError
- type Written
Constants ¶
This section is empty.
Variables ¶
var ( ErrUnauthorized = errors.New("davx: the server refused the credentials") // ErrPrecondition means a conditional write failed (412): the object // changed on the server, or one exists where a new one was to go. ErrPrecondition = errors.New("davx: the object on the server is not the one expected") // ErrInvalidToken means the server no longer accepts a sync token; the // collection must be compared in full. ErrInvalidToken = errors.New("davx: the sync token is no longer valid") // ErrNotFound means the resource does not exist (404, 410). ErrNotFound = errors.New("davx: not found") // ErrUntrusted means the server sent the client to an origin that // Options.Trusted does not accept, or to plain HTTP. ErrUntrusted = errors.New("davx: the server points to an untrusted location") )
Functions ¶
func Discover ¶
Discover finds the home set of kind for the user that opts signs in as. It asks start for the user's principal (first at /.well-known/carddav or caldav when start has no path), then the principal for its home set, following redirects. start's origin is trusted; every other origin it is sent to must pass opts.Trusted. It returns the home set's absolute URL.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client talks to one DAV origin.
func New ¶
New returns a client for base, an absolute URL whose origin every request goes to (normally a home set from Discover).
func (*Client) Collections ¶
Collections lists the address books or calendars in the client's home set.
func (*Client) DefaultCalendar ¶
DefaultCalendar asks the server for the user's default calendar (RFC 6638 §9.2): from the calendar home this client is for, its principal, the principal's scheduling inbox, and the inbox's schedule-default-calendar-URL. It returns that calendar's path, or "" when the server names none or names one on another origin.
func (*Client) Delete ¶
Delete removes an object if it still has the ETag ifMatch (any ETag when ifMatch is empty). An object already gone is not an error.
func (*Client) List ¶
List returns every object of a collection with its ETag (PROPFIND at depth 1), for servers without sync-collection and for verify.
func (*Client) Multiget ¶
func (c *Client) Multiget(ctx context.Context, kind Kind, coll string, hrefList []string) (objs []Object, missing []string, err error)
Multiget fetches objects of a collection by href (addressbook-multiget or calendar-multiget). Objects come back under the hrefs the caller gave; hrefs the server does not have are returned in missing. An XML parser turns CRLF into LF (XML 1.0 §2.11), so data without any CR gets its CRLFs back.
func (*Client) Put ¶
func (c *Client) Put(ctx context.Context, href string, data []byte, kind Kind, ifMatch string) (Written, error)
Put writes an object. ifMatch is the ETag the change was made on; an empty ifMatch creates the object and fails with ErrPrecondition if one exists.
type Collection ¶
type Collection struct {
Href string // its path, as the server wrote it
Name string
Description string
Color string // #rrggbb, or "" when the server has none
Components []string // a calendar's component types (VEVENT, VTODO); nil when the server does not say
SyncToken string
CTag string
ReadOnly bool // the user may not change its objects
// Sync is whether the collection answers sync-collection: it says so in
// supported-report-set or, when it lists no reports, has a sync token.
Sync bool
}
Collection is an address book or calendar.
type Delta ¶
type Delta struct {
Changed []Change // new or changed objects
Deleted []string // hrefs of removed objects
Token string // the token to ask from next time
// More means the server cut the answer short (507): ask again from
// Token for the rest.
More bool
}
Delta is what changed in a collection since a sync token.
type Kind ¶
type Kind int
Kind is the kind of collection a client works with.
func (Kind) ContentType ¶
ContentType is the media type of the kind's objects.
type Object ¶
type Object struct {
Href string // as the caller named it, or as the server wrote it
ETag string
Data []byte
}
Object is a contact or calendar object as the server holds it.
type Options ¶
type Options struct {
// Authorization returns the Authorization header for a request, such
// as "Basic …" or "Bearer …"; nil sends none.
Authorization func(ctx context.Context) (string, error)
// HTTP sends the requests; nil uses one with a 60-second timeout. The
// client never lets it follow redirects.
HTTP *http.Client
// Trusted reports whether credentials may go to u, an origin other
// than the one a client or discovery started from (a redirect, a
// principal or a home set on another host). Nil trusts none.
Trusted func(u *url.URL) bool
// AllowHTTP permits plain http:// URLs, for local test servers only.
AllowHTTP bool
// UserAgent is sent with every request.
UserAgent string
}
Options configure a client.
type StatusError ¶
type StatusError struct {
Method, URL string
Code int
Body string // the start of the response body
}
StatusError is an HTTP status the client did not expect.
func (*StatusError) Error ¶
func (e *StatusError) Error() string
type Written ¶
type Written struct {
// Href is where the object is: the href written, or for a new object
// a server named itself (Google's CalDAV names it from its UID), the
// Location it answered with.
Href string
// ETag is the new ETag, or "" when the server sent none (the caller
// then fetches the object).
ETag string
}
Written is what a PUT left on the server.