all: encode hrefs, replace hrefs with path in public API
Closes: https://github.com/emersion/go-webdav/issues/14 Closes: https://github.com/emersion/go-webdav/issues/16
This commit is contained in:
@@ -8,7 +8,7 @@ import (
|
||||
)
|
||||
|
||||
type AddressBook struct {
|
||||
Href string
|
||||
Path string
|
||||
Name string
|
||||
Description string
|
||||
MaxResourceSize int64
|
||||
@@ -19,11 +19,11 @@ type AddressBookQuery struct {
|
||||
}
|
||||
|
||||
type AddressBookMultiGet struct {
|
||||
Hrefs []string
|
||||
Paths []string
|
||||
Props []string
|
||||
}
|
||||
|
||||
type AddressObject struct {
|
||||
Href string
|
||||
Path string
|
||||
Card vcard.Card
|
||||
}
|
||||
|
@@ -81,7 +81,7 @@ func (c *Client) FindAddressBookHomeSet(principal string) (string, error) {
|
||||
return "", err
|
||||
}
|
||||
|
||||
return prop.Href, nil
|
||||
return prop.Href.Path, nil
|
||||
}
|
||||
|
||||
func (c *Client) FindAddressBooks(addressBookHomeSet string) ([]AddressBook, error) {
|
||||
@@ -98,7 +98,7 @@ func (c *Client) FindAddressBooks(addressBookHomeSet string) ([]AddressBook, err
|
||||
|
||||
l := make([]AddressBook, 0, len(ms.Responses))
|
||||
for _, resp := range ms.Responses {
|
||||
href, err := resp.Href()
|
||||
path, err := resp.Path()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -130,7 +130,7 @@ func (c *Client) FindAddressBooks(addressBookHomeSet string) ([]AddressBook, err
|
||||
}
|
||||
|
||||
l = append(l, AddressBook{
|
||||
Href: href,
|
||||
Path: path,
|
||||
Name: dispName.Name,
|
||||
Description: desc.Description,
|
||||
MaxResourceSize: maxResSize.Size,
|
||||
@@ -143,7 +143,7 @@ func (c *Client) FindAddressBooks(addressBookHomeSet string) ([]AddressBook, err
|
||||
func decodeAddressList(ms *internal.Multistatus) ([]AddressObject, error) {
|
||||
addrs := make([]AddressObject, 0, len(ms.Responses))
|
||||
for _, resp := range ms.Responses {
|
||||
href, err := resp.Href()
|
||||
path, err := resp.Path()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -160,7 +160,7 @@ func decodeAddressList(ms *internal.Multistatus) ([]AddressObject, error) {
|
||||
}
|
||||
|
||||
addrs = append(addrs, AddressObject{
|
||||
Href: href,
|
||||
Path: path,
|
||||
Card: card,
|
||||
})
|
||||
}
|
||||
@@ -198,7 +198,7 @@ func (c *Client) QueryAddressBook(addressBook string, query *AddressBookQuery) (
|
||||
return decodeAddressList(ms)
|
||||
}
|
||||
|
||||
func (c *Client) MultiGetAddressBook(href string, multiGet *AddressBookMultiGet) ([]AddressObject, error) {
|
||||
func (c *Client) MultiGetAddressBook(path string, multiGet *AddressBookMultiGet) ([]AddressObject, error) {
|
||||
var addrDataReq addressDataReq
|
||||
if multiGet != nil {
|
||||
for _, name := range multiGet.Props {
|
||||
@@ -213,13 +213,17 @@ func (c *Client) MultiGetAddressBook(href string, multiGet *AddressBookMultiGet)
|
||||
|
||||
addressbookMultiget := addressbookMultiget{Prop: propReq}
|
||||
|
||||
if multiGet == nil || len(multiGet.Hrefs) == 0 {
|
||||
addressbookMultiget.Hrefs = []string{href}
|
||||
if multiGet == nil || len(multiGet.Paths) == 0 {
|
||||
href := internal.Href{Path: path}
|
||||
addressbookMultiget.Hrefs = []internal.Href{href}
|
||||
} else {
|
||||
addressbookMultiget.Hrefs = multiGet.Hrefs
|
||||
addressbookMultiget.Hrefs = make([]internal.Href, len(multiGet.Paths))
|
||||
for i, p := range multiGet.Paths {
|
||||
addressbookMultiget.Hrefs[i] = internal.Href{Path: p}
|
||||
}
|
||||
}
|
||||
|
||||
req, err := c.ic.NewXMLRequest("REPORT", href, &addressbookMultiget)
|
||||
req, err := c.ic.NewXMLRequest("REPORT", path, &addressbookMultiget)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@@ -25,8 +25,8 @@ var (
|
||||
|
||||
// https://tools.ietf.org/html/rfc6352#section-6.2.3
|
||||
type addressbookHomeSet struct {
|
||||
XMLName xml.Name `xml:"urn:ietf:params:xml:ns:carddav addressbook-home-set"`
|
||||
Href string `xml:"href"`
|
||||
XMLName xml.Name `xml:"urn:ietf:params:xml:ns:carddav addressbook-home-set"`
|
||||
Href internal.Href `xml:"href"`
|
||||
}
|
||||
|
||||
type addressbookDescription struct {
|
||||
@@ -62,9 +62,9 @@ type addressbookQuery struct {
|
||||
|
||||
// https://tools.ietf.org/html/rfc6352#section-8.7
|
||||
type addressbookMultiget struct {
|
||||
XMLName xml.Name `xml:"urn:ietf:params:xml:ns:carddav addressbook-multiget"`
|
||||
Hrefs []string `xml:"DAV: href"`
|
||||
Prop *internal.Prop `xml:"DAV: prop,omitempty"`
|
||||
XMLName xml.Name `xml:"urn:ietf:params:xml:ns:carddav addressbook-multiget"`
|
||||
Hrefs []internal.Href `xml:"DAV: href"`
|
||||
Prop *internal.Prop `xml:"DAV: prop,omitempty"`
|
||||
// TODO: DAV:allprop | DAV:propname
|
||||
}
|
||||
|
||||
|
@@ -99,7 +99,7 @@ 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 {
|
||||
ao, err := h.Backend.GetAddressObject(href)
|
||||
ao, err := h.Backend.GetAddressObject(href.Path)
|
||||
if err != nil {
|
||||
return err // TODO: create internal.Response with error
|
||||
}
|
||||
@@ -225,11 +225,11 @@ func (b *backend) propfindAddressBook(propfind *internal.Propfind, ab *AddressBo
|
||||
},
|
||||
// TODO: this is a principal property
|
||||
addressBookHomeSetName: func(*internal.RawXMLValue) (interface{}, error) {
|
||||
return &addressbookHomeSet{Href: "/"}, nil
|
||||
return &addressbookHomeSet{Href: internal.Href{Path: "/"}}, nil
|
||||
},
|
||||
// TODO: this should be set on all resources
|
||||
internal.CurrentUserPrincipalName: func(*internal.RawXMLValue) (interface{}, error) {
|
||||
return &internal.CurrentUserPrincipal{Href: "/"}, nil
|
||||
return &internal.CurrentUserPrincipal{Href: internal.Href{Path: "/"}}, nil
|
||||
},
|
||||
}
|
||||
|
||||
@@ -258,7 +258,7 @@ func (b *backend) propfindAddressObject(propfind *internal.Propfind, ao *Address
|
||||
// TODO: getlastmodified, getetag
|
||||
}
|
||||
|
||||
return internal.NewPropfindResponse(ao.Href, propfind, props)
|
||||
return internal.NewPropfindResponse(ao.Path, propfind, props)
|
||||
}
|
||||
|
||||
func (b *backend) Proppatch(r *http.Request, update *internal.Propertyupdate) (*internal.Response, error) {
|
||||
|
Reference in New Issue
Block a user