mirror of
https://github.com/1f349/go-webdav.git
synced 2024-12-22 16:24:14 +00:00
carddav: add displayname and addressbook-description to server
This commit is contained in:
parent
797b2f8fc5
commit
edfc2804b5
@ -6,6 +6,7 @@ import (
|
|||||||
|
|
||||||
type AddressBook struct {
|
type AddressBook struct {
|
||||||
Href string
|
Href string
|
||||||
|
Name string
|
||||||
Description string
|
Description string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -76,7 +76,7 @@ func (c *Client) FindAddressBooks(addressBookHomeSet string) ([]AddressBook, err
|
|||||||
|
|
||||||
l = append(l, AddressBook{
|
l = append(l, AddressBook{
|
||||||
Href: href,
|
Href: href,
|
||||||
Description: descProp.Data,
|
Description: descProp.Description,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -26,7 +26,7 @@ type addressbookHomeSet struct {
|
|||||||
|
|
||||||
type addressbookDescription struct {
|
type addressbookDescription struct {
|
||||||
XMLName xml.Name `xml:"urn:ietf:params:xml:ns:carddav addressbook-description"`
|
XMLName xml.Name `xml:"urn:ietf:params:xml:ns:carddav addressbook-description"`
|
||||||
Data string `xml:",chardata"`
|
Description string `xml:",chardata"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://tools.ietf.org/html/rfc6352#section-10.3
|
// https://tools.ietf.org/html/rfc6352#section-10.3
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package carddav
|
package carddav
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bytes"
|
||||||
"encoding/xml"
|
"encoding/xml"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
@ -11,6 +12,7 @@ import (
|
|||||||
// TODO: add support for multiple address books
|
// TODO: add support for multiple address books
|
||||||
|
|
||||||
type Backend interface {
|
type Backend interface {
|
||||||
|
AddressBook() (*AddressBook, error)
|
||||||
GetAddressObject(href string) (*AddressObject, error)
|
GetAddressObject(href string) (*AddressObject, error)
|
||||||
ListAddressObjects() ([]AddressObject, error)
|
ListAddressObjects() ([]AddressObject, error)
|
||||||
QueryAddressObjects(query *AddressBookQuery) ([]AddressObject, error)
|
QueryAddressObjects(query *AddressBookQuery) ([]AddressObject, error)
|
||||||
@ -157,7 +159,12 @@ func (b *backend) HeadGet(w http.ResponseWriter, r *http.Request) error {
|
|||||||
func (b *backend) Propfind(r *http.Request, propfind *internal.Propfind, depth internal.Depth) (*internal.Multistatus, error) {
|
func (b *backend) Propfind(r *http.Request, propfind *internal.Propfind, depth internal.Depth) (*internal.Multistatus, error) {
|
||||||
var resps []internal.Response
|
var resps []internal.Response
|
||||||
if r.URL.Path == "/" {
|
if r.URL.Path == "/" {
|
||||||
resp, err := b.propfindAddressBook(propfind)
|
ab, err := b.Backend.AddressBook()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
resp, err := b.propfindAddressBook(propfind, ab)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -193,12 +200,18 @@ func (b *backend) Propfind(r *http.Request, propfind *internal.Propfind, depth i
|
|||||||
return internal.NewMultistatus(resps...), nil
|
return internal.NewMultistatus(resps...), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *backend) propfindAddressBook(propfind *internal.Propfind) (*internal.Response, error) {
|
func (b *backend) propfindAddressBook(propfind *internal.Propfind, ab *AddressBook) (*internal.Response, error) {
|
||||||
props := map[xml.Name]internal.PropfindFunc{
|
props := map[xml.Name]internal.PropfindFunc{
|
||||||
internal.ResourceTypeName: func(*internal.RawXMLValue) (interface{}, error) {
|
internal.ResourceTypeName: func(*internal.RawXMLValue) (interface{}, error) {
|
||||||
return internal.NewResourceType(internal.CollectionName, addressBookName), nil
|
return internal.NewResourceType(internal.CollectionName, addressBookName), nil
|
||||||
},
|
},
|
||||||
// TODO: displayname, addressbook-description, addressbook-supported-address-data, addressbook-max-resource-size, addressbook-home-set
|
internal.DisplayNameName: func(*internal.RawXMLValue) (interface{}, error) {
|
||||||
|
return &internal.DisplayName{Name: ab.Name}, nil
|
||||||
|
},
|
||||||
|
addressBookDescriptionName: func(*internal.RawXMLValue) (interface{}, error) {
|
||||||
|
return &addressbookDescription{Description: ab.Description}, nil
|
||||||
|
},
|
||||||
|
// TODO: addressbook-supported-address-data, addressbook-max-resource-size, addressbook-home-set
|
||||||
}
|
}
|
||||||
|
|
||||||
return internal.NewPropfindResponse("/", propfind, props)
|
return internal.NewPropfindResponse("/", propfind, props)
|
||||||
@ -209,7 +222,7 @@ func (b *backend) propfindAddressObject(propfind *internal.Propfind, ao *Address
|
|||||||
internal.GetContentTypeName: func(*internal.RawXMLValue) (interface{}, error) {
|
internal.GetContentTypeName: func(*internal.RawXMLValue) (interface{}, error) {
|
||||||
return &internal.GetContentType{Type: vcard.MIMEType}, nil
|
return &internal.GetContentType{Type: vcard.MIMEType}, nil
|
||||||
},
|
},
|
||||||
addressBookDataName: func(*internal.RawXMLValue) (interface{}, error) {
|
addressDataName: func(*internal.RawXMLValue) (interface{}, error) {
|
||||||
var buf bytes.Buffer
|
var buf bytes.Buffer
|
||||||
if err := vcard.NewEncoder(&buf).Encode(ao.Card); err != nil {
|
if err := vcard.NewEncoder(&buf).Encode(ao.Card); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -303,6 +303,7 @@ type GetLastModified struct {
|
|||||||
|
|
||||||
var (
|
var (
|
||||||
ResourceTypeName = xml.Name{"DAV:", "resourcetype"}
|
ResourceTypeName = xml.Name{"DAV:", "resourcetype"}
|
||||||
|
DisplayNameName = xml.Name{"DAV:", "displayname"}
|
||||||
GetContentLengthName = xml.Name{"DAV:", "getcontentlength"}
|
GetContentLengthName = xml.Name{"DAV:", "getcontentlength"}
|
||||||
GetContentTypeName = xml.Name{"DAV:", "getcontenttype"}
|
GetContentTypeName = xml.Name{"DAV:", "getcontenttype"}
|
||||||
GetLastModifiedName = xml.Name{"DAV:", "getlastmodified"}
|
GetLastModifiedName = xml.Name{"DAV:", "getlastmodified"}
|
||||||
@ -314,3 +315,9 @@ type Error struct {
|
|||||||
XMLName xml.Name `xml:"DAV: error"`
|
XMLName xml.Name `xml:"DAV: error"`
|
||||||
Raw []RawXMLValue `xml:",any"`
|
Raw []RawXMLValue `xml:",any"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// https://tools.ietf.org/html/rfc4918#section-15.2
|
||||||
|
type DisplayName struct {
|
||||||
|
XMLName xml.Name `xml:"DAV: displayname"`
|
||||||
|
Name string `xml:",chardata"`
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user