carddav: add AddressBook.Info

This commit is contained in:
emersion 2017-09-09 16:45:31 +02:00
parent 8d4a1ede86
commit 1152b72a07
No known key found for this signature in database
GPG Key ID: 0FDE7BE0E88F5E48
2 changed files with 18 additions and 4 deletions

View File

@ -13,6 +13,12 @@ var (
ErrNotFound = errors.New("carddav: not found") ErrNotFound = errors.New("carddav: not found")
) )
type AddressBookInfo struct {
Name string
Description string
MaxResourceSize int
}
type AddressObject interface { type AddressObject interface {
ID() string ID() string
Card() (vcard.Card, error) Card() (vcard.Card, error)
@ -20,6 +26,7 @@ type AddressObject interface {
} }
type AddressBook interface { type AddressBook interface {
Info() (*AddressBookInfo, error)
GetAddressObject(id string) (AddressObject, error) GetAddressObject(id string) (AddressObject, error)
ListAddressObjects() ([]AddressObject, error) ListAddressObjects() ([]AddressObject, error)
} }

View File

@ -6,6 +6,7 @@ import (
"errors" "errors"
"net/http" "net/http"
"os" "os"
"strconv"
"strings" "strings"
"time" "time"
@ -202,6 +203,11 @@ func (d *dir) Stat() (os.FileInfo, error) {
} }
func (d *dir) DeadProps() (map[xml.Name]webdav.Property, error) { func (d *dir) DeadProps() (map[xml.Name]webdav.Property, error) {
info, err := d.fs.ab.Info()
if err != nil {
return nil, err
}
return map[xml.Name]webdav.Property{ return map[xml.Name]webdav.Property{
resourcetype: webdav.Property{ resourcetype: webdav.Property{
XMLName: resourcetype, XMLName: resourcetype,
@ -209,19 +215,20 @@ func (d *dir) DeadProps() (map[xml.Name]webdav.Property, error) {
}, },
displayname: webdav.Property{ displayname: webdav.Property{
XMLName: displayname, XMLName: displayname,
InnerXML: []byte("Test"), InnerXML: []byte(info.Name),
}, },
addressBookDescription: webdav.Property{ addressBookDescription: webdav.Property{
XMLName: addressBookDescription, XMLName: addressBookDescription,
InnerXML: []byte("C'est juste un test mdr."), InnerXML: []byte(info.Description),
}, },
addressBookSupportedAddressData: webdav.Property{ addressBookSupportedAddressData: webdav.Property{
XMLName: addressBookSupportedAddressData, XMLName: addressBookSupportedAddressData,
InnerXML: []byte(`<address-data-type xmlns="urn:ietf:params:xml:ns:carddav" content-type="text/vcard" version="3.0"/>`), InnerXML: []byte(`<address-data-type xmlns="urn:ietf:params:xml:ns:carddav" content-type="text/vcard" version="3.0"/>` +
`<address-data-type xmlns="urn:ietf:params:xml:ns:carddav" content-type="text/vcard" version="4.0"/>`),
}, },
addressBookMaxResourceSize: webdav.Property{ addressBookMaxResourceSize: webdav.Property{
XMLName: addressBookMaxResourceSize, XMLName: addressBookMaxResourceSize,
InnerXML: []byte("102400"), InnerXML: []byte(strconv.Itoa(info.MaxResourceSize)),
}, },
addressBookHomeSet: webdav.Property{ addressBookHomeSet: webdav.Property{
XMLName: addressBookHomeSet, XMLName: addressBookHomeSet,