mirror of
https://github.com/1f349/go-webdav.git
synced 2024-12-22 08:14:15 +00:00
wip: caldav: add support for reports
This commit is contained in:
parent
373663f9ee
commit
0afce10e07
@ -2,6 +2,7 @@ package caldav
|
||||
|
||||
import (
|
||||
"encoding/xml"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/emersion/go-webdav/internal"
|
||||
@ -14,8 +15,12 @@ var (
|
||||
|
||||
calendarDescriptionName = xml.Name{namespace, "calendar-description"}
|
||||
supportedCalendarDataName = xml.Name{namespace, "supported-calendar-data"}
|
||||
supportedCalendarComponentSetName = xml.Name{namespace, "supported-calendar-component-set"}
|
||||
maxResourceSizeName = xml.Name{namespace, "max-resource-size"}
|
||||
|
||||
calendarQueryName = xml.Name{namespace, "calendar-query"}
|
||||
calendarMultigetName = xml.Name{namespace, "calendar-multiget"}
|
||||
|
||||
calendarName = xml.Name{namespace, "calendar"}
|
||||
)
|
||||
|
||||
@ -37,6 +42,12 @@ type supportedCalendarData struct {
|
||||
Types []calendarDataType `xml:"calendar-data"`
|
||||
}
|
||||
|
||||
// https://tools.ietf.org/html/rfc4791#section-5.2.3
|
||||
type supportedCalendarComponentSet struct {
|
||||
XMLName xml.Name `xml:"urn:ietf:params:xml:ns:caldav supported-calendar-component-set"`
|
||||
Comp []comp `xml:"comp"`
|
||||
}
|
||||
|
||||
// https://tools.ietf.org/html/rfc4791#section-9.6
|
||||
type calendarDataType struct {
|
||||
XMLName xml.Name `xml:"urn:ietf:params:xml:ns:caldav calendar-data"`
|
||||
@ -160,3 +171,25 @@ type calendarDataResp struct {
|
||||
XMLName xml.Name `xml:"urn:ietf:params:xml:ns:caldav calendar-data"`
|
||||
Data []byte `xml:",chardata"`
|
||||
}
|
||||
|
||||
type reportReq struct {
|
||||
Query *calendarQuery
|
||||
Multiget *calendarMultiget
|
||||
// TODO: CALDAV:free-busy-query
|
||||
}
|
||||
|
||||
func (r *reportReq) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error {
|
||||
var v interface{}
|
||||
switch start.Name {
|
||||
case calendarQueryName:
|
||||
r.Query = &calendarQuery{}
|
||||
v = r.Query
|
||||
case calendarMultigetName:
|
||||
r.Multiget = &calendarMultiget{}
|
||||
v = r.Multiget
|
||||
default:
|
||||
return fmt.Errorf("caldav: unsupported REPORT root %q %q", start.Name.Space, start.Name.Local)
|
||||
}
|
||||
|
||||
return d.DecodeElement(v, &start)
|
||||
}
|
||||
|
@ -7,6 +7,9 @@ import (
|
||||
"net/http"
|
||||
"net/url"
|
||||
"strings"
|
||||
|
||||
"bytes"
|
||||
"log"
|
||||
)
|
||||
|
||||
func ServeError(w http.ResponseWriter, err error) {
|
||||
@ -38,6 +41,13 @@ func ServeXML(w http.ResponseWriter) *xml.Encoder {
|
||||
func ServeMultistatus(w http.ResponseWriter, ms *Multistatus) error {
|
||||
// TODO: streaming
|
||||
w.WriteHeader(http.StatusMultiStatus)
|
||||
|
||||
var buf bytes.Buffer
|
||||
enc := xml.NewEncoder(&buf)
|
||||
enc.Indent(" ", " ")
|
||||
enc.Encode(&ms)
|
||||
log.Println(">>", buf.String())
|
||||
|
||||
return ServeXML(w).Encode(ms)
|
||||
}
|
||||
|
||||
@ -129,6 +139,12 @@ func (h *Handler) handlePropfind(w http.ResponseWriter, r *http.Request) error {
|
||||
return err
|
||||
}
|
||||
|
||||
var buf bytes.Buffer
|
||||
enc := xml.NewEncoder(&buf)
|
||||
enc.Indent(" ", " ")
|
||||
enc.Encode(&propfind)
|
||||
log.Println("<< PROPFIND", r.URL, buf.String())
|
||||
|
||||
depth := DepthInfinity
|
||||
if s := r.Header.Get("Depth"); s != "" {
|
||||
var err error
|
||||
|
Loading…
Reference in New Issue
Block a user