carddav: add AddressBook{Query,MultiGet}.AllProp

This commit is contained in:
Simon Ser 2020-01-22 19:18:58 +01:00
parent 7e29f37bd8
commit cd5945aace
No known key found for this signature in database
GPG Key ID: 0FDE7BE0E88F5E48
4 changed files with 27 additions and 11 deletions

View File

@ -18,11 +18,13 @@ type AddressBook struct {
type AddressBookQuery struct {
Props []string
AllProp bool
}
type AddressBookMultiGet struct {
Paths []string
Props []string
AllProp bool
}
type AddressObject struct {

View File

@ -142,11 +142,15 @@ func (c *Client) FindAddressBooks(addressBookHomeSet string) ([]AddressBook, err
return l, nil
}
func encodeAddressPropReq(props []string) (*internal.Prop, error) {
func encodeAddressPropReq(props []string, allProp bool) (*internal.Prop, error) {
var addrDataReq addressDataReq
if allProp {
addrDataReq.Allprop = &struct{}{}
} else {
for _, name := range props {
addrDataReq.Props = append(addrDataReq.Props, prop{Name: name})
}
}
getLastModReq := internal.NewRawXMLElement(internal.GetLastModifiedName, nil, nil)
getETagReq := internal.NewRawXMLElement(internal.GetETagName, nil, nil)
@ -199,11 +203,13 @@ func decodeAddressList(ms *internal.Multistatus) ([]AddressObject, error) {
func (c *Client) QueryAddressBook(addressBook string, query *AddressBookQuery) ([]AddressObject, error) {
var props []string
var allProp bool
if query != nil {
props = query.Props
allProp = query.AllProp
}
propReq, err := encodeAddressPropReq(props)
propReq, err := encodeAddressPropReq(props, allProp)
if err != nil {
return nil, err
}
@ -227,11 +233,13 @@ func (c *Client) QueryAddressBook(addressBook string, query *AddressBookQuery) (
func (c *Client) MultiGetAddressBook(path string, multiGet *AddressBookMultiGet) ([]AddressObject, error) {
var props []string
var allProp bool
if multiGet != nil {
props = multiGet.Props
allProp = multiGet.AllProp
}
propReq, err := encodeAddressPropReq(props)
propReq, err := encodeAddressPropReq(props, allProp)
if err != nil {
return nil, err
}

View File

@ -84,7 +84,7 @@ func newProp(name string, noValue bool) *internal.RawXMLValue {
type addressDataReq struct {
XMLName xml.Name `xml:"urn:ietf:params:xml:ns:carddav address-data"`
Props []prop `xml:"prop"`
// TODO: allprop
Allprop *struct{} `xml:"allprop"`
}
// https://tools.ietf.org/html/rfc6352#section-10.4.2

View File

@ -72,6 +72,10 @@ func (h *Handler) handleQuery(w http.ResponseWriter, query *addressbookQuery) er
if err := query.Prop.Decode(&addressData); err != nil && !internal.IsMissingProp(err) {
return err
}
if addressData.Allprop != nil && len(addressData.Props) > 0 {
return internal.HTTPErrorf(http.StatusBadRequest, "carddav: only one of allprop or prop can be specified in address-data")
}
q.AllProp = addressData.Allprop != nil
for _, p := range addressData.Props {
q.Props = append(q.Props, p.Name)
}
@ -104,6 +108,8 @@ func (h *Handler) handleQuery(w http.ResponseWriter, query *addressbookQuery) er
func (h *Handler) handleMultiget(w http.ResponseWriter, multiget *addressbookMultiget) error {
var resps []internal.Response
for _, href := range multiget.Hrefs {
// TODO: only get a subset of the vCard fields, depending on the
// multiget query
ao, err := h.Backend.GetAddressObject(href.Path)
if err != nil {
return err // TODO: create internal.Response with error