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

@ -17,12 +17,14 @@ type AddressBook struct {
} }
type AddressBookQuery struct { type AddressBookQuery struct {
Props []string Props []string
AllProp bool
} }
type AddressBookMultiGet struct { type AddressBookMultiGet struct {
Paths []string Paths []string
Props []string Props []string
AllProp bool
} }
type AddressObject struct { type AddressObject struct {

View File

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

View File

@ -82,9 +82,9 @@ func newProp(name string, noValue bool) *internal.RawXMLValue {
// https://tools.ietf.org/html/rfc6352#section-10.4 // https://tools.ietf.org/html/rfc6352#section-10.4
type addressDataReq struct { type addressDataReq struct {
XMLName xml.Name `xml:"urn:ietf:params:xml:ns:carddav address-data"` XMLName xml.Name `xml:"urn:ietf:params:xml:ns:carddav address-data"`
Props []prop `xml:"prop"` Props []prop `xml:"prop"`
// TODO: allprop Allprop *struct{} `xml:"allprop"`
} }
// https://tools.ietf.org/html/rfc6352#section-10.4.2 // 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) { if err := query.Prop.Decode(&addressData); err != nil && !internal.IsMissingProp(err) {
return 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 { for _, p := range addressData.Props {
q.Props = append(q.Props, p.Name) 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 { func (h *Handler) handleMultiget(w http.ResponseWriter, multiget *addressbookMultiget) error {
var resps []internal.Response var resps []internal.Response
for _, href := range multiget.Hrefs { 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) ao, err := h.Backend.GetAddressObject(href.Path)
if err != nil { if err != nil {
return err // TODO: create internal.Response with error return err // TODO: create internal.Response with error