Implement Knowledge City platform, organizer and DAV integration
Capture accumulated application, UI, CLI, regression tests and design documentation changes, including task project mapping and default CalDAV list naming. Keep deployment data, backups, local credentials and build artifacts out of Git. Move the Compose enrollment token to an ignored local environment file.
This commit is contained in:
1 parent
288e6e94ac
commit
c1175d389f
699 files changed
+110197
-4117
No files matched your search
@@ -0,0 +1,544 @@
|
||||
package server
|
||||
|
||||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
"encoding/xml"
|
||||
"errors"
|
||||
"io"
|
||||
"mime"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/google/uuid"
|
||||
mw "pageswiki/internal/server/middleware"
|
||||
"pageswiki/internal/store"
|
||||
)
|
||||
|
||||
const taskDAVRoot = calendarDAV + "tasks/"
|
||||
const taskDAVCollection = taskDAVRoot + "default/"
|
||||
|
||||
func taskDAVName(item store.TaskRecord) string {
|
||||
if item.CalDAV != nil {
|
||||
return item.CalDAV.Name
|
||||
}
|
||||
return item.UUID + ".ics"
|
||||
}
|
||||
func taskDAVError(w http.ResponseWriter, status int, condition, message string) {
|
||||
w.Header().Set("Content-Type", "application/xml; charset=utf-8")
|
||||
w.WriteHeader(status)
|
||||
io.WriteString(w, `<?xml version="1.0"?><d:error xmlns:d="DAV:" xmlns:c="urn:ietf:params:xml:ns:caldav"><c:`+condition+`/><d:responsedescription>`+xmlText(message)+`</d:responsedescription></d:error>`)
|
||||
}
|
||||
func taskDAVCollectionRow() davResponse {
|
||||
return davResponse{href: taskDAVCollection, props: map[xml.Name]string{
|
||||
{Space: davNS, Local: "displayname"}: store.DefaultTaskDAVTitle,
|
||||
{Space: davNS, Local: "resourcetype"}: "<d:collection/><c:calendar/>",
|
||||
{Space: calNS, Local: "supported-calendar-component-set"}: `<c:comp name="VTODO"/>`,
|
||||
{Space: calNS, Local: "supported-calendar-data"}: `<c:calendar-data content-type="text/calendar" version="2.0"/>`,
|
||||
{Space: calNS, Local: "max-resource-size"}: "32768",
|
||||
{Space: davNS, Local: "supported-report-set"}: `<d:supported-report><d:report><c:calendar-query/></d:report></d:supported-report><d:supported-report><d:report><c:calendar-multiget/></d:report></d:supported-report>`,
|
||||
}}
|
||||
}
|
||||
func taskDAVRow(item store.TaskRecord, prefixes ...string) (davResponse, error) {
|
||||
prefix := taskDAVCollection
|
||||
if len(prefixes) == 1 {
|
||||
prefix = prefixes[0]
|
||||
}
|
||||
data, tag, e := taskICAL(item)
|
||||
return davResponse{href: prefix + taskDAVName(item), props: map[xml.Name]string{
|
||||
{Space: davNS, Local: "resourcetype"}: "", {Space: davNS, Local: "getetag"}: xmlText(tag), {Space: davNS, Local: "getcontenttype"}: "text/calendar; charset=utf-8", {Space: calNS, Local: "calendar-data"}: xmlText(data),
|
||||
{Space: davNS, Local: "getlastmodified"}: time.UnixMilli(item.UpdatedMS).UTC().Format(http.TimeFormat),
|
||||
}}, e
|
||||
}
|
||||
|
||||
func (s *Server) handleTaskDAV(w http.ResponseWriter, r *http.Request) {
|
||||
if rest, ok := strings.CutPrefix(r.URL.Path, taskDAVRoot+"projects/"); ok {
|
||||
id := strings.Split(rest, "/")[0]
|
||||
parsed, err := uuid.Parse(id)
|
||||
if err != nil || parsed.String() != id {
|
||||
http.NotFound(w, r)
|
||||
return
|
||||
}
|
||||
s.handleTaskDAVAt(w, r, "tasks/projects/"+id)
|
||||
return
|
||||
}
|
||||
s.handleTaskDAVAt(w, r, "")
|
||||
}
|
||||
|
||||
func (s *Server) handleTaskDAVAt(w http.ResponseWriter, r *http.Request, collectionPath string) {
|
||||
if collectionPath != "" {
|
||||
mw.SetDAVTaskTarget(r, strings.TrimSuffix(r.URL.Path, "/") != calendarDAV+collectionPath)
|
||||
}
|
||||
w.Header().Set("Cache-Control", "private, no-store")
|
||||
domain := s.domainUUIDForRequest(r)
|
||||
if !s.systemExtensionEnabled(domain, "organizer.tasks") {
|
||||
http.NotFound(w, r)
|
||||
return
|
||||
}
|
||||
ctx, cancel := context.WithTimeout(r.Context(), 10*time.Second)
|
||||
defer cancel()
|
||||
r = r.WithContext(ctx)
|
||||
actor, write, credential := "", false, ""
|
||||
if len(r.Header.Values("Authorization")) == 1 {
|
||||
if user, pass, ok := r.BasicAuth(); ok {
|
||||
var err error
|
||||
actor, write, err = s.store.AuthenticateTaskDAV(ctx, domain, user, pass)
|
||||
if err != nil {
|
||||
actor = ""
|
||||
mw.SetDAVAuthOutcome(r, "basic_rejected")
|
||||
} else {
|
||||
mw.SetDAVAuthOutcome(r, "basic_accepted")
|
||||
}
|
||||
credential = user
|
||||
} else {
|
||||
actor, write = s.calendarActor(r)
|
||||
mw.SetDAVAuthOutcome(r, "invalid_authorization")
|
||||
if actor != "" {
|
||||
mw.SetDAVAuthOutcome(r, "session_accepted")
|
||||
}
|
||||
}
|
||||
} else if len(r.Header.Values("Authorization")) == 0 {
|
||||
actor, write = s.calendarActor(r)
|
||||
mw.SetDAVAuthOutcome(r, "missing")
|
||||
if actor != "" {
|
||||
mw.SetDAVAuthOutcome(r, "session_accepted")
|
||||
}
|
||||
} else {
|
||||
mw.SetDAVAuthOutcome(r, "multiple_authorization")
|
||||
}
|
||||
if actor == "" {
|
||||
w.Header().Set("WWW-Authenticate", `Basic realm="PagesWiki task CalDAV", charset="UTF-8"`)
|
||||
w.WriteHeader(401)
|
||||
return
|
||||
}
|
||||
s.setDAVCapabilities(w, r, actor, credential)
|
||||
prefix, project, title := taskDAVCollection, "", store.DefaultTaskDAVTitle
|
||||
if collectionPath != "" {
|
||||
v, err := s.store.TaskDAVCollection(ctx, domain, actor, collectionPath)
|
||||
if err != nil {
|
||||
taskError(w, err)
|
||||
return
|
||||
}
|
||||
prefix, project, title = calendarDAV+collectionPath+"/", v.UUID, v.Title
|
||||
} else {
|
||||
var err error
|
||||
title, err = s.store.TaskDAVDefaultTitle(ctx, domain, actor)
|
||||
if err != nil {
|
||||
taskError(w, err)
|
||||
return
|
||||
}
|
||||
}
|
||||
w.Header().Set("Allow", "OPTIONS, PROPFIND, REPORT, GET, HEAD, PUT, DELETE")
|
||||
if collectionPath == "" && strings.TrimSuffix(r.URL.Path, "/") == strings.TrimSuffix(taskDAVCollection, "/") {
|
||||
w.Header().Set("Allow", "OPTIONS, PROPFIND, PROPPATCH, REPORT, GET, HEAD, PUT, DELETE")
|
||||
}
|
||||
if r.Method == "OPTIONS" {
|
||||
w.WriteHeader(204)
|
||||
return
|
||||
}
|
||||
root := collectionPath == "" && strings.TrimSuffix(r.URL.Path, "/") == strings.TrimSuffix(taskDAVRoot, "/")
|
||||
collection := strings.TrimSuffix(r.URL.Path, "/") == strings.TrimSuffix(prefix, "/")
|
||||
name := strings.TrimPrefix(r.URL.Path, prefix)
|
||||
if !root && !collection && (!strings.HasPrefix(r.URL.Path, prefix) || !store.ValidTaskDAVName(name)) {
|
||||
http.NotFound(w, r)
|
||||
return
|
||||
}
|
||||
if r.Method == "PROPFIND" || r.Method == "REPORT" {
|
||||
s.handleTaskDAVListing(w, r, domain, actor, root, collection, name, write, prefix, project, title)
|
||||
return
|
||||
}
|
||||
if r.Method == "PROPPATCH" && collection && project == "" {
|
||||
if !write {
|
||||
taskError(w, store.ErrAccessDenied)
|
||||
return
|
||||
}
|
||||
s.handleTaskDAVDefaultProperties(w, r, domain, actor, credential)
|
||||
return
|
||||
}
|
||||
if root || collection {
|
||||
w.WriteHeader(405)
|
||||
return
|
||||
}
|
||||
item, err := s.store.TaskDAVByName(ctx, domain, actor, name, project)
|
||||
exists := err == nil && !item.Archived
|
||||
if err != nil && !errors.Is(err, sql.ErrNoRows) {
|
||||
taskError(w, err)
|
||||
return
|
||||
}
|
||||
if r.Method == "GET" || r.Method == "HEAD" {
|
||||
if !exists {
|
||||
http.NotFound(w, r)
|
||||
return
|
||||
}
|
||||
data, tag, e := taskICAL(item)
|
||||
if e != nil {
|
||||
taskError(w, e)
|
||||
return
|
||||
}
|
||||
w.Header().Set("ETag", tag)
|
||||
w.Header().Set("Content-Type", "text/calendar; charset=utf-8")
|
||||
if r.Header.Get("If-None-Match") == tag || r.Header.Get("If-None-Match") == "*" {
|
||||
w.WriteHeader(304)
|
||||
return
|
||||
}
|
||||
if r.Method == "GET" {
|
||||
io.WriteString(w, data)
|
||||
}
|
||||
return
|
||||
}
|
||||
if r.Method != "PUT" && r.Method != "DELETE" {
|
||||
w.WriteHeader(405)
|
||||
return
|
||||
}
|
||||
if !write {
|
||||
taskError(w, store.ErrAccessDenied)
|
||||
return
|
||||
}
|
||||
mutate := func(v store.TaskRecord) store.TaskRecord { v.Archived = true; return v }
|
||||
var data *store.TaskDAVData
|
||||
if r.Method == "PUT" {
|
||||
contentType, _, e := mime.ParseMediaType(r.Header.Get("Content-Type"))
|
||||
if e != nil || contentType != "text/calendar" {
|
||||
w.WriteHeader(415)
|
||||
return
|
||||
}
|
||||
raw, e := io.ReadAll(http.MaxBytesReader(w, r.Body, 32768))
|
||||
if e != nil {
|
||||
w.WriteHeader(413)
|
||||
return
|
||||
}
|
||||
cal, e := parseTaskICAL(string(raw))
|
||||
if e != nil {
|
||||
taskDAVError(w, 403, "valid-calendar-data", e.Error())
|
||||
return
|
||||
}
|
||||
uid, _ := cal.Children[0].Props.Text("UID")
|
||||
encoded, e := encodeTaskICAL(cal)
|
||||
if e != nil {
|
||||
taskError(w, e)
|
||||
return
|
||||
}
|
||||
data = &store.TaskDAVData{Name: name, UID: uid, Data: encoded}
|
||||
mutate = func(v store.TaskRecord) store.TaskRecord {
|
||||
v = taskFromICAL(cal, v)
|
||||
v.Archived = false
|
||||
return v
|
||||
}
|
||||
}
|
||||
unconditional := r.Header.Get("If-Match") == "" && r.Header.Get("If-None-Match") == ""
|
||||
// Accept unconditional client writes as last-committed-writer-wins, without
|
||||
// weakening the store's CAS transaction. Rebase only DAV fields on each
|
||||
// retry; never overwrite newer Web-only metadata with a stale task record.
|
||||
originalID := item.UUID
|
||||
for attempt := 0; attempt < 8; attempt++ {
|
||||
if !taskDAVWritePreconditions(w, r, item, exists) {
|
||||
return
|
||||
}
|
||||
if r.Method == "DELETE" && !exists {
|
||||
http.NotFound(w, r)
|
||||
return
|
||||
}
|
||||
candidate := item
|
||||
if candidate.UUID == "" {
|
||||
candidate = store.TaskRecord{UUID: uuid.NewString(), Kind: "task", Bucket: "inbox", ProjectUUID: project}
|
||||
}
|
||||
saved, e := s.store.SaveTaskDAV(ctx, domain, actor, mutate(candidate), item.Version, data, credential, project)
|
||||
if e == nil {
|
||||
if r.Method == "PUT" {
|
||||
w.Header().Set("Location", prefix+taskDAVName(saved))
|
||||
}
|
||||
// The representation is normalized: no PUT ETag (RFC 9110).
|
||||
if r.Method == "PUT" && !exists {
|
||||
w.WriteHeader(201)
|
||||
} else {
|
||||
w.WriteHeader(204)
|
||||
}
|
||||
return
|
||||
}
|
||||
if unconditional && (errors.Is(e, store.ErrTaskConflict) || item.UUID == "" && errors.Is(e, store.ErrTaskDAVIdentity)) {
|
||||
fresh, readErr := s.store.TaskDAVByName(ctx, domain, actor, name, project)
|
||||
if readErr == nil && (originalID == "" || fresh.UUID == originalID) {
|
||||
item, exists = fresh, !fresh.Archived
|
||||
originalID = fresh.UUID
|
||||
continue
|
||||
}
|
||||
if readErr != nil && !errors.Is(readErr, sql.ErrNoRows) {
|
||||
taskError(w, readErr)
|
||||
return
|
||||
}
|
||||
// A concurrent move must not recreate a task in its old collection.
|
||||
}
|
||||
if errors.Is(e, store.ErrTaskDAVIdentity) {
|
||||
taskDAVError(w, 403, "no-uid-conflict", "UID and resource identity must be unique and immutable")
|
||||
return
|
||||
}
|
||||
taskError(w, e)
|
||||
return
|
||||
}
|
||||
http.Error(w, "concurrent task updates; retry synchronization", http.StatusConflict)
|
||||
}
|
||||
|
||||
func taskDAVWritePreconditions(w http.ResponseWriter, r *http.Request, item store.TaskRecord, exists bool) bool {
|
||||
match, none := r.Header.Get("If-Match"), r.Header.Get("If-None-Match")
|
||||
if match == "" && none == "" {
|
||||
return true
|
||||
}
|
||||
tag := ""
|
||||
if exists {
|
||||
var err error
|
||||
_, tag, err = taskICAL(item)
|
||||
if err != nil {
|
||||
taskError(w, err)
|
||||
return false
|
||||
}
|
||||
}
|
||||
matches := func(value string, weak bool) bool {
|
||||
for _, v := range strings.Split(value, ",") {
|
||||
v = strings.TrimSpace(v)
|
||||
if weak {
|
||||
v = strings.TrimPrefix(v, "W/")
|
||||
}
|
||||
if exists && (v == "*" || v == tag) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
if match != "" && !matches(match, false) || none != "" && matches(none, true) {
|
||||
w.WriteHeader(http.StatusPreconditionFailed)
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
func (s *Server) handleTaskDAVListing(w http.ResponseWriter, r *http.Request, domain, actor string, root, collection bool, name string, writable bool, prefix, project, title string) {
|
||||
depth := r.Header.Get("Depth")
|
||||
if r.Method == "REPORT" && depth == "" {
|
||||
depth = "0"
|
||||
}
|
||||
if depth != "0" && depth != "1" {
|
||||
taskDAVError(w, 403, "supported-filter", "Depth 0 or 1 required")
|
||||
return
|
||||
}
|
||||
n, e := readDAV(w, r)
|
||||
if e != nil {
|
||||
http.Error(w, "invalid XML", 400)
|
||||
return
|
||||
}
|
||||
var req []davNode
|
||||
if p := n.child(davNS, "prop"); p != nil {
|
||||
req = p.Children
|
||||
}
|
||||
for _, p := range req {
|
||||
if !taskDAVFullProperty(p) {
|
||||
taskDAVError(w, 403, "supported-calendar-data", "property projections unsupported")
|
||||
return
|
||||
}
|
||||
}
|
||||
rows := []davResponse{}
|
||||
collectionRow := taskDAVCollectionRow()
|
||||
collectionRow.href = prefix
|
||||
collectionRow.props[xml.Name{Space: davNS, Local: "displayname"}] = xmlText(title)
|
||||
collectionRow.props[xml.Name{Space: davNS, Local: "current-user-privilege-set"}] = davPrivileges(writable)
|
||||
collectionRow.props[xml.Name{Space: davNS, Local: "current-user-principal"}] = "<d:href>" + taskDAVRoot + "</d:href>"
|
||||
if r.Method == "PROPFIND" {
|
||||
if n.XMLName.Local != "" && (n.XMLName.Space != davNS || n.XMLName.Local != "propfind") {
|
||||
w.WriteHeader(400)
|
||||
return
|
||||
}
|
||||
if root {
|
||||
rows = append(rows, davResponse{href: taskDAVRoot, props: map[xml.Name]string{
|
||||
{Space: davNS, Local: "displayname"}: "PagesWiki Task Home", {Space: davNS, Local: "resourcetype"}: "<d:collection/><d:principal/>",
|
||||
{Space: davNS, Local: "current-user-principal"}: "<d:href>" + taskDAVRoot + "</d:href>", {Space: davNS, Local: "principal-URL"}: "<d:href>" + taskDAVRoot + "</d:href>", {Space: calNS, Local: "calendar-home-set"}: "<d:href>" + taskDAVRoot + "</d:href>",
|
||||
}})
|
||||
if depth == "1" {
|
||||
rows = append(rows, collectionRow)
|
||||
if !s.appendTaskDAVCollections(w, r, domain, actor, writable, &rows) {
|
||||
return
|
||||
}
|
||||
}
|
||||
} else if collection {
|
||||
rows = append(rows, collectionRow)
|
||||
if depth == "1" {
|
||||
items, err := s.store.TaskDAVList(r.Context(), domain, actor, project)
|
||||
if err != nil {
|
||||
taskError(w, err)
|
||||
return
|
||||
}
|
||||
for _, item := range items {
|
||||
if err := r.Context().Err(); err != nil {
|
||||
taskError(w, err)
|
||||
return
|
||||
}
|
||||
row, err := taskDAVRow(item, prefix)
|
||||
if err != nil {
|
||||
taskError(w, err)
|
||||
return
|
||||
}
|
||||
rows = append(rows, row)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
item, err := s.store.TaskDAVByName(r.Context(), domain, actor, name, project)
|
||||
if err != nil {
|
||||
taskError(w, err)
|
||||
return
|
||||
}
|
||||
if item.Archived {
|
||||
http.NotFound(w, r)
|
||||
return
|
||||
}
|
||||
row, err := taskDAVRow(item, prefix)
|
||||
if err != nil {
|
||||
taskError(w, err)
|
||||
return
|
||||
}
|
||||
rows = append(rows, row)
|
||||
}
|
||||
writeDAV(w, rows, req)
|
||||
return
|
||||
}
|
||||
if !collection || n.XMLName.Space != calNS {
|
||||
w.WriteHeader(405)
|
||||
return
|
||||
}
|
||||
if len(req) == 0 {
|
||||
http.Error(w, "explicit properties required", 400)
|
||||
return
|
||||
}
|
||||
seen := map[xml.Name]int{}
|
||||
for _, child := range n.Children {
|
||||
seen[child.XMLName]++
|
||||
allowed := child.XMLName.Space == davNS && child.XMLName.Local == "prop" || n.XMLName.Local == "calendar-query" && child.XMLName.Space == calNS && child.XMLName.Local == "filter" || n.XMLName.Local == "calendar-multiget" && child.XMLName.Space == davNS && child.XMLName.Local == "href"
|
||||
if !allowed || child.XMLName.Local != "href" && seen[child.XMLName] > 1 {
|
||||
taskDAVError(w, 403, "supported-filter", "unsupported report element")
|
||||
return
|
||||
}
|
||||
}
|
||||
switch n.XMLName.Local {
|
||||
case "calendar-query":
|
||||
filter := n.child(calNS, "filter")
|
||||
if !taskDAVSimpleFilter(filter) {
|
||||
taskDAVError(w, 403, "supported-filter", "only VCALENDAR/VTODO component filters supported; time-range and property filters are not supported")
|
||||
return
|
||||
}
|
||||
items, err := s.store.TaskDAVList(r.Context(), domain, actor, project)
|
||||
if err != nil {
|
||||
taskError(w, err)
|
||||
return
|
||||
}
|
||||
for _, item := range items {
|
||||
if err := r.Context().Err(); err != nil {
|
||||
taskError(w, err)
|
||||
return
|
||||
}
|
||||
row, err := taskDAVRow(item, prefix)
|
||||
if err != nil {
|
||||
taskError(w, err)
|
||||
return
|
||||
}
|
||||
rows = append(rows, row)
|
||||
}
|
||||
case "calendar-multiget":
|
||||
count := 0
|
||||
for _, child := range n.Children {
|
||||
if child.XMLName.Space != davNS || child.XMLName.Local != "href" {
|
||||
continue
|
||||
}
|
||||
count++
|
||||
if count > 200 {
|
||||
taskError(w, store.ErrTaskDAVLimit)
|
||||
return
|
||||
}
|
||||
href := strings.TrimSpace(child.Text)
|
||||
u, err := url.Parse(href)
|
||||
if err != nil || u.User != nil || u.RawQuery != "" || u.Fragment != "" || (u.Host != "" && !strings.EqualFold(u.Host, r.Host)) || !strings.HasPrefix(u.Path, prefix) || !store.ValidTaskDAVName(strings.TrimPrefix(u.Path, prefix)) {
|
||||
rows = append(rows, davResponse{href: href, status: 404})
|
||||
continue
|
||||
}
|
||||
item, err := s.store.TaskDAVByName(r.Context(), domain, actor, strings.TrimPrefix(u.Path, prefix), project)
|
||||
if errors.Is(err, sql.ErrNoRows) || err == nil && item.Archived {
|
||||
rows = append(rows, davResponse{href: u.Path, status: 404})
|
||||
continue
|
||||
}
|
||||
if err != nil {
|
||||
taskError(w, err)
|
||||
return
|
||||
}
|
||||
row, err := taskDAVRow(item, prefix)
|
||||
if err != nil {
|
||||
taskError(w, err)
|
||||
return
|
||||
}
|
||||
rows = append(rows, row)
|
||||
}
|
||||
default:
|
||||
taskDAVError(w, 403, "supported-filter", "unsupported report")
|
||||
return
|
||||
}
|
||||
writeDAV(w, rows, req)
|
||||
}
|
||||
|
||||
// An explicit VCALENDAR/allprop/allcomp request is the complete resource, not
|
||||
// a partial projection. go-webdav (including chroncal) uses this representation.
|
||||
// Keep partial property selection, expansion and recurrence limits unsupported.
|
||||
func taskDAVFullProperty(p davNode) bool {
|
||||
if p.XMLName.Space != calNS || p.XMLName.Local != "calendar-data" {
|
||||
return len(p.Children) == 0 && taskDAVAttrCount(p) == 0
|
||||
}
|
||||
for _, a := range p.Attrs {
|
||||
if a.Name.Space == "xmlns" || a.Name.Space == "" && a.Name.Local == "xmlns" {
|
||||
continue
|
||||
}
|
||||
if a.Name.Space != "" || !(a.Name.Local == "content-type" && a.Value == "text/calendar" || a.Name.Local == "version" && a.Value == "2.0") {
|
||||
return false
|
||||
}
|
||||
}
|
||||
if len(p.Children) == 0 {
|
||||
return true
|
||||
}
|
||||
if len(p.Children) != 1 {
|
||||
return false
|
||||
}
|
||||
c := p.Children[0]
|
||||
if c.XMLName.Space != calNS || c.XMLName.Local != "comp" || c.attr("name") != "VCALENDAR" || taskDAVAttrCount(c) != 1 || len(c.Children) != 2 {
|
||||
return false
|
||||
}
|
||||
seen := map[string]bool{}
|
||||
for _, n := range c.Children {
|
||||
if n.XMLName.Space != calNS || (n.XMLName.Local != "allprop" && n.XMLName.Local != "allcomp") || len(n.Children) != 0 || taskDAVAttrCount(n) != 0 || seen[n.XMLName.Local] {
|
||||
return false
|
||||
}
|
||||
seen[n.XMLName.Local] = true
|
||||
}
|
||||
return true
|
||||
}
|
||||
func taskDAVSimpleFilter(n *davNode) bool {
|
||||
if n == nil || len(n.Children) != 1 || taskDAVAttrCount(*n) != 0 {
|
||||
return false
|
||||
}
|
||||
c := n.Children[0]
|
||||
if c.XMLName.Space != calNS || c.XMLName.Local != "comp-filter" || c.attr("name") != "VCALENDAR" || taskDAVAttrCount(c) != 1 {
|
||||
return false
|
||||
}
|
||||
if len(c.Children) == 0 {
|
||||
return true
|
||||
}
|
||||
if len(c.Children) != 1 {
|
||||
return false
|
||||
}
|
||||
v := c.Children[0]
|
||||
return v.XMLName.Space == calNS && v.XMLName.Local == "comp-filter" && v.attr("name") == "VTODO" && taskDAVAttrCount(v) == 1 && len(v.Children) == 0
|
||||
}
|
||||
|
||||
func taskDAVAttrCount(n davNode) int {
|
||||
count := 0
|
||||
for _, a := range n.Attrs {
|
||||
if a.Name.Space != "xmlns" && !(a.Name.Space == "" && a.Name.Local == "xmlns") {
|
||||
count++
|
||||
}
|
||||
}
|
||||
return count
|
||||
}
|
||||
Reference in new issue
Block a user