carddav

package
v0.0.0-...-c4abd28 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 29, 2023 License: MIT Imports: 15 Imported by: 0

Documentation

Overview

Package carddav provides a client and server CardDAV implementation.

CardDAV is defined in RFC 6352.

Index

Constants

This section is empty.

Variables

View Source
var CapabilityAddressBook = webdav.Capability("addressbook")

Functions

func Discover

func Discover(domain string) (string, error)

Discover performs a DNS-based CardDAV service discovery as described in RFC 6352 section 11. It returns the URL to the CardDAV server.

func Match

func Match(query *AddressBookQuery, ao *AddressObject) (matched bool, err error)

Match reports whether the provided AddressObject matches the query.

func NewAddressBookHomeSet

func NewAddressBookHomeSet(path string) webdav.BackendSuppliedHomeSet

func NewPreconditionError

func NewPreconditionError(err PreconditionType) error

Types

type AddressBook

type AddressBook struct {
	Path                 string
	Name                 string
	Description          string
	MaxResourceSize      int64
	SupportedAddressData []AddressDataType
}

func (*AddressBook) SupportsAddressData

func (ab *AddressBook) SupportsAddressData(contentType, version string) bool

type AddressBookMultiGet

type AddressBookMultiGet struct {
	Paths       []string
	DataRequest AddressDataRequest
}

type AddressBookQuery

type AddressBookQuery struct {
	DataRequest AddressDataRequest

	PropFilters []PropFilter
	FilterTest  FilterTest // defaults to FilterAnyOf

	Limit int // <= 0 means unlimited
}

type AddressDataRequest

type AddressDataRequest struct {
	Props   []string
	AllProp bool
}

type AddressDataType

type AddressDataType struct {
	ContentType string
	Version     string
}

type AddressObject

type AddressObject struct {
	Path          string
	ModTime       time.Time
	ContentLength int64
	ETag          string
	Card          vcard.Card
}

func Filter

func Filter(query *AddressBookQuery, aos []AddressObject) ([]AddressObject, error)

Filter returns the filtered list of address objects matching the provided query. A nil query will return the full list of address objects.

type Backend

type Backend interface {
	AddressbookHomeSetPath(ctx context.Context) (string, error)
	AddressBook(ctx context.Context) (*AddressBook, error)
	GetAddressObject(ctx context.Context, path string, req *AddressDataRequest) (*AddressObject, error)
	ListAddressObjects(ctx context.Context, req *AddressDataRequest) ([]AddressObject, error)
	QueryAddressObjects(ctx context.Context, query *AddressBookQuery) ([]AddressObject, error)
	PutAddressObject(ctx context.Context, path string, card vcard.Card, opts *PutAddressObjectOptions) (loc string, err error)
	DeleteAddressObject(ctx context.Context, path string) error

	webdav.UserPrincipalBackend
}

Backend is a CardDAV server backend.

type Client

type Client struct {
	*webdav.Client
	// contains filtered or unexported fields
}

Client provides access to a remote CardDAV server.

func NewClient

func NewClient(c webdav.HTTPClient, endpoint string) (*Client, error)

func (*Client) FindAddressBookHomeSet

func (c *Client) FindAddressBookHomeSet(principal string) (string, error)

func (*Client) FindAddressBooks

func (c *Client) FindAddressBooks(addressBookHomeSet string) ([]AddressBook, error)

func (*Client) GetAddressObject

func (c *Client) GetAddressObject(path string) (*AddressObject, error)

func (*Client) HasSupport

func (c *Client) HasSupport() error

func (*Client) MultiGetAddressBook

func (c *Client) MultiGetAddressBook(path string, multiGet *AddressBookMultiGet) ([]AddressObject, error)

func (*Client) PutAddressObject

func (c *Client) PutAddressObject(path string, card vcard.Card) (*AddressObject, error)

func (*Client) QueryAddressBook

func (c *Client) QueryAddressBook(addressBook string, query *AddressBookQuery) ([]AddressObject, error)

func (*Client) SyncCollection

func (c *Client) SyncCollection(path string, query *SyncQuery) (*SyncResponse, error)

SyncCollection performs a collection synchronization operation on the specified resource, as defined in RFC 6578.

type FilterTest

type FilterTest string
const (
	FilterAnyOf FilterTest = "anyof"
	FilterAllOf FilterTest = "allof"
)

type Handler

type Handler struct {
	Backend Backend
	Prefix  string
}

Handler handles CardDAV HTTP requests. It can be used to create a CardDAV server.

func (*Handler) ServeHTTP

func (h *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP implements http.Handler.

type MatchType

type MatchType string
const (
	MatchEquals     MatchType = "equals"
	MatchContains   MatchType = "contains"
	MatchStartsWith MatchType = "starts-with"
	MatchEndsWith   MatchType = "ends-with"
)

type ParamFilter

type ParamFilter struct {
	Name string

	// if IsNotDefined is set, TextMatch needs to be unset
	IsNotDefined bool
	TextMatch    *TextMatch
}

type PreconditionType

type PreconditionType string

https://tools.ietf.org/rfcmarkup?doc=6352#section-6.3.2.1

const (
	PreconditionNoUIDConflict        PreconditionType = "no-uid-conflict"
	PreconditionSupportedAddressData PreconditionType = "supported-address-data"
	PreconditionValidAddressData     PreconditionType = "valid-address-data"
	PreconditionMaxResourceSize      PreconditionType = "max-resource-size"
)

type PropFilter

type PropFilter struct {
	Name string
	Test FilterTest // defaults to FilterAnyOf

	// if IsNotDefined is set, TextMatches and Params need to be unset
	IsNotDefined bool
	TextMatches  []TextMatch
	Params       []ParamFilter
}

type PutAddressObjectOptions

type PutAddressObjectOptions struct {
	// IfNoneMatch indicates that the client does not want to overwrite
	// an existing resource.
	IfNoneMatch webdav.ConditionalMatch
	// IfMatch provides the ETag of the resource that the client intends
	// to overwrite, can be ""
	IfMatch webdav.ConditionalMatch
}

type SyncQuery

type SyncQuery struct {
	DataRequest AddressDataRequest
	SyncToken   string
	Limit       int // <= 0 means unlimited
}

SyncQuery is the query struct represents a sync-collection request

type SyncResponse

type SyncResponse struct {
	SyncToken string
	Updated   []AddressObject
	Deleted   []string
}

SyncResponse contains the returned sync-token for next time

type TextMatch

type TextMatch struct {
	Text            string
	NegateCondition bool
	MatchType       MatchType // defaults to MatchContains
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL