Skip to content

Commit

Permalink
caldav: add support for more props on MKCOL and PROPFIND
Browse files Browse the repository at this point in the history
  • Loading branch information
DeepDiver1975 committed Apr 9, 2024
1 parent 381b8a3 commit 96422a0
Show file tree
Hide file tree
Showing 6 changed files with 361 additions and 25 deletions.
2 changes: 2 additions & 0 deletions caldav/caldav.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,10 @@ type Calendar struct {
Path string
Name string
Description string
Color string
MaxResourceSize int64
SupportedComponentSet []string
Timezone string
}

type CalendarCompRequest struct {
Expand Down
33 changes: 27 additions & 6 deletions caldav/elements.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,16 @@ var (
calendarQueryName = xml.Name{namespace, "calendar-query"}
calendarMultigetName = xml.Name{namespace, "calendar-multiget"}

calendarName = xml.Name{namespace, "calendar"}
calendarDataName = xml.Name{namespace, "calendar-data"}
calendarName = xml.Name{namespace, "calendar"}
calendarDataName = xml.Name{namespace, "calendar-data"}
calendarColorName = xml.Name{
Space: "http://apple.com/ns/ical/",
Local: "calendar-color",
}
calendarTimezoneName = xml.Name{
Space: namespace,
Local: "calendar-timezone",
}
)

// https://tools.ietf.org/html/rfc4791#section-6.2.1
Expand All @@ -41,6 +49,16 @@ type calendarDescription struct {
Description string `xml:",chardata"`
}

type calendarColor struct {
XMLName xml.Name `xml:"http://apple.com/ns/ical/ calendar-color"`
Color string `xml:",chardata"`
}

type calendarTimezone struct {
XMLName xml.Name `xml:"urn:ietf:params:xml:ns:caldav calendar-timezone"`
Timezone string `xml:",chardata"`
}

// https://tools.ietf.org/html/rfc4791#section-5.2.4
type supportedCalendarData struct {
XMLName xml.Name `xml:"urn:ietf:params:xml:ns:caldav supported-calendar-data"`
Expand Down Expand Up @@ -230,8 +248,11 @@ func (r *reportReq) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error {
}

type mkcolReq struct {
XMLName xml.Name `xml:"DAV: mkcol"`
ResourceType internal.ResourceType `xml:"set>prop>resourcetype"`
DisplayName string `xml:"set>prop>displayname"`
// TODO this could theoretically contain all addressbook properties?
XMLName xml.Name `xml:"DAV: mkcol"`
ResourceType internal.ResourceType `xml:"set>prop>resourcetype"`
DisplayName string `xml:"set>prop>displayname"`
Description string `xml:"set>prop>calendar-description"`
CalendarColor string `xml:"set>prop>calendar-color"`
CalendarTimeZone string `xml:"set>prop>calendar-timezone"`
SupportedCalendarComponentSet supportedCalendarComponentSet `xml:"set>prop>supported-calendar-component-set"`
}
23 changes: 22 additions & 1 deletion caldav/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -568,6 +568,20 @@ func (b *backend) propFindCalendar(ctx context.Context, propfind *internal.PropF
return &calendarDescription{Description: cal.Description}, nil
}
}
if cal.Color != "" {
props[calendarColorName] = func(*internal.RawXMLValue) (interface{}, error) {
return &calendarColor{
Color: cal.Color,
}, nil
}
}
if cal.Timezone != "" {
props[calendarTimezoneName] = func(*internal.RawXMLValue) (interface{}, error) {
return &calendarTimezone{
Timezone: cal.Timezone,
}, nil
}
}
if cal.MaxResourceSize > 0 {
props[maxResourceSizeName] = func(*internal.RawXMLValue) (interface{}, error) {
return &maxResourceSize{Size: cal.MaxResourceSize}, nil
Expand Down Expand Up @@ -737,7 +751,14 @@ func (b *backend) Mkcol(r *http.Request) error {
return internal.HTTPErrorf(http.StatusBadRequest, "carddav: unexpected resource type")
}
cal.Name = m.DisplayName
// TODO ...
cal.Description = m.Description
cal.Color = strings.TrimSpace(m.CalendarColor)
cal.Timezone = strings.TrimSpace(m.CalendarTimeZone)

cal.SupportedComponentSet = make([]string, len(m.SupportedCalendarComponentSet.Comp))
for i, v := range m.SupportedCalendarComponentSet.Comp {
cal.SupportedComponentSet[i] = v.Name
}
}

return b.Backend.CreateCalendar(r.Context(), &cal)
Expand Down
Loading

0 comments on commit 96422a0

Please sign in to comment.