mirror of
https://github.com/1f349/go-webdav.git
synced 2024-12-23 00:34:23 +00:00
carddav: add AddressBook{Query,MultiGet}.AllProp
This commit is contained in:
parent
7e29f37bd8
commit
cd5945aace
@ -18,11 +18,13 @@ 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 {
|
||||||
|
@ -142,11 +142,15 @@ 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
|
||||||
|
if allProp {
|
||||||
|
addrDataReq.Allprop = &struct{}{}
|
||||||
|
} else {
|
||||||
for _, name := range props {
|
for _, name := range props {
|
||||||
addrDataReq.Props = append(addrDataReq.Props, prop{Name: name})
|
addrDataReq.Props = append(addrDataReq.Props, prop{Name: name})
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
getLastModReq := internal.NewRawXMLElement(internal.GetLastModifiedName, nil, nil)
|
getLastModReq := internal.NewRawXMLElement(internal.GetLastModifiedName, nil, nil)
|
||||||
getETagReq := internal.NewRawXMLElement(internal.GetETagName, 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) {
|
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
|
||||||
}
|
}
|
||||||
|
@ -84,7 +84,7 @@ func newProp(name string, noValue bool) *internal.RawXMLValue {
|
|||||||
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
|
||||||
|
@ -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
|
||||||
|
Loading…
Reference in New Issue
Block a user