caldav: add Client.MultiGetCalendar

This commit is contained in:
Simon Ser 2020-05-13 16:45:10 +02:00
parent 5328b4c493
commit a4e0e81003
No known key found for this signature in database
GPG Key ID: 0FDE7BE0E88F5E48
3 changed files with 46 additions and 0 deletions

View File

@ -47,6 +47,11 @@ type CalendarQuery struct {
CompFilter CompFilter CompFilter CompFilter
} }
type CalendarMultiGet struct {
Paths []string
CompRequest CalendarCompRequest
}
type CalendarObject struct { type CalendarObject struct {
Path string Path string
ModTime time.Time ModTime time.Time

View File

@ -218,6 +218,38 @@ func (c *Client) QueryCalendar(calendar string, query *CalendarQuery) ([]Calenda
return decodeCalendarObjectList(ms) return decodeCalendarObjectList(ms)
} }
func (c *Client) MultiGetCalendar(path string, multiGet *CalendarMultiGet) ([]CalendarObject, error) {
propReq, err := encodeCalendarReq(&multiGet.CompRequest)
if err != nil {
return nil, err
}
calendarMultiget := calendarMultiget{Prop: propReq}
if multiGet == nil || len(multiGet.Paths) == 0 {
href := internal.Href{Path: path}
calendarMultiget.Hrefs = []internal.Href{href}
} else {
calendarMultiget.Hrefs = make([]internal.Href, len(multiGet.Paths))
for i, p := range multiGet.Paths {
calendarMultiget.Hrefs[i] = internal.Href{Path: p}
}
}
req, err := c.ic.NewXMLRequest("REPORT", path, &calendarMultiget)
if err != nil {
return nil, err
}
req.Header.Add("Depth", "1")
ms, err := c.ic.DoMultiStatus(req)
if err != nil {
return nil, err
}
return decodeCalendarObjectList(ms)
}
func populateCalendarObject(co *CalendarObject, resp *http.Response) error { func populateCalendarObject(co *CalendarObject, resp *http.Response) error {
if loc := resp.Header.Get("Location"); loc != "" { if loc := resp.Header.Get("Location"); loc != "" {
u, err := url.Parse(loc) u, err := url.Parse(loc)

View File

@ -60,6 +60,15 @@ type calendarQuery struct {
// TODO: timezone // TODO: timezone
} }
// https://tools.ietf.org/html/rfc4791#section-9.10
type calendarMultiget struct {
XMLName xml.Name `xml:"urn:ietf:params:xml:ns:caldav calendar-multiget"`
Hrefs []internal.Href `xml:"DAV: href"`
Prop *internal.Prop `xml:"DAV: prop,omitempty"`
AllProp *struct{} `xml:"DAV: allprop,omitempty"`
PropName *struct{} `xml:"DAV: propname,omitempty"`
}
// https://tools.ietf.org/html/rfc4791#section-9.7 // https://tools.ietf.org/html/rfc4791#section-9.7
type filter struct { type filter struct {
XMLName xml.Name `xml:"urn:ietf:params:xml:ns:caldav filter"` XMLName xml.Name `xml:"urn:ietf:params:xml:ns:caldav filter"`