From 3cbfcbee9beacae891403d07a3c1f503ecba0f6d Mon Sep 17 00:00:00 2001 From: rfc2822 Date: Sat, 30 Nov 2013 00:06:16 +0100 Subject: [PATCH] CalDAV: ignore collections without VEVENT support (for instance, VTODO collections) --- .../QueryServerDialogFragment.java | 9 +++++ src/at/bitfire/davdroid/webdav/DavProp.java | 19 +++++++++++ .../bitfire/davdroid/webdav/HttpPropfind.java | 1 + .../davdroid/webdav/WebDavResource.java | 33 ++++++++++++------- 4 files changed, 50 insertions(+), 12 deletions(-) diff --git a/src/at/bitfire/davdroid/syncadapter/QueryServerDialogFragment.java b/src/at/bitfire/davdroid/syncadapter/QueryServerDialogFragment.java index 96fe7fe1..0d199859 100644 --- a/src/at/bitfire/davdroid/syncadapter/QueryServerDialogFragment.java +++ b/src/at/bitfire/davdroid/syncadapter/QueryServerDialogFragment.java @@ -182,6 +182,15 @@ public class QueryServerDialogFragment extends DialogFragment implements LoaderC for (WebDavResource resource : homeSetCalendars.getMembers()) if (resource.isCalendar()) { Log.i(TAG, "Found calendar: " + resource.getLocation().getRawPath()); + if (resource.getSupportedComponents() != null) { + // CALDAV:supported-calendar-component-set available + boolean supportsEvents = false; + for (String supportedComponent : resource.getSupportedComponents()) + if (supportedComponent.equalsIgnoreCase("VEVENT")) + supportsEvents = true; + if (!supportsEvents) // ignore collections without VEVENT support + continue; + } ServerInfo.ResourceInfo info = new ServerInfo.ResourceInfo( ServerInfo.ResourceInfo.Type.CALENDAR, resource.getLocation().getRawPath(), diff --git a/src/at/bitfire/davdroid/webdav/DavProp.java b/src/at/bitfire/davdroid/webdav/DavProp.java index 12c9d3c6..fc0c7156 100644 --- a/src/at/bitfire/davdroid/webdav/DavProp.java +++ b/src/at/bitfire/davdroid/webdav/DavProp.java @@ -7,9 +7,13 @@ ******************************************************************************/ package at.bitfire.davdroid.webdav; +import java.util.List; + import lombok.Getter; +import org.simpleframework.xml.Attribute; import org.simpleframework.xml.Element; +import org.simpleframework.xml.ElementList; import org.simpleframework.xml.Namespace; import org.simpleframework.xml.Root; import org.simpleframework.xml.Text; @@ -44,6 +48,9 @@ public class DavProp { @Element(required=false,name="calendar-timezone") DavPropCalendarTimezone calendarTimezone; + @Element(required=false,name="supported-calendar-component-set") + DavPropSupportedCalendarComponentSet supportedCalendarComponentSet; + @Element(required=false) DavPropGetCTag getctag; @@ -117,6 +124,18 @@ public class DavProp { @Getter private String timezone; } + @Namespace(prefix="C",reference="urn:ietf:params:xml:ns:caldav") + public static class DavPropSupportedCalendarComponentSet { + @ElementList(inline=true,entry="comp",required=false) + List components; + } + + @Namespace(prefix="C",reference="urn:ietf:params:xml:ns:caldav") + public static class DavPropComp { + @Attribute + @Getter String name; + } + @Namespace(prefix="CS",reference="http://calendarserver.org/ns/") public static class DavPropGetCTag { @Text(required=false) diff --git a/src/at/bitfire/davdroid/webdav/HttpPropfind.java b/src/at/bitfire/davdroid/webdav/HttpPropfind.java index 2c86863b..779dcbce 100644 --- a/src/at/bitfire/davdroid/webdav/HttpPropfind.java +++ b/src/at/bitfire/davdroid/webdav/HttpPropfind.java @@ -55,6 +55,7 @@ public class HttpPropfind extends HttpEntityEnclosingRequestBase { propfind.prop.calendarDescription = new DavProp.DavPropCalendarDescription(); propfind.prop.calendarColor = new DavProp.DavPropCalendarColor(); propfind.prop.calendarTimezone = new DavProp.DavPropCalendarTimezone(); + propfind.prop.supportedCalendarComponentSet = new DavProp.DavPropSupportedCalendarComponentSet(); break; case COLLECTION_CTAG: depth = 0; diff --git a/src/at/bitfire/davdroid/webdav/WebDavResource.java b/src/at/bitfire/davdroid/webdav/WebDavResource.java index 3504c31b..470d74dd 100644 --- a/src/at/bitfire/davdroid/webdav/WebDavResource.java +++ b/src/at/bitfire/davdroid/webdav/WebDavResource.java @@ -48,6 +48,7 @@ import org.simpleframework.xml.core.Persister; import android.util.Log; import at.bitfire.davdroid.URIUtils; import at.bitfire.davdroid.resource.Event; +import at.bitfire.davdroid.webdav.DavProp.DavPropComp; @ToString @@ -57,7 +58,7 @@ public class WebDavResource { public enum Property { CURRENT_USER_PRINCIPAL, DISPLAY_NAME, DESCRIPTION, COLOR, - TIMEZONE, + TIMEZONE, SUPPORTED_COMPONENTS, ADDRESSBOOK_HOMESET, CALENDAR_HOMESET, IS_ADDRESSBOOK, IS_CALENDAR, CTAG, ETAG, @@ -81,6 +82,7 @@ public class WebDavResource { // DAV properties protected HashMap properties = new HashMap(); + @Getter protected List supportedComponents; // list of members (only for collections) @Getter protected List members; @@ -415,39 +417,46 @@ public class WebDavResource { continue; DavProp prop = singlePropstat.prop; + HashMap properties = referenced.properties; if (prop.currentUserPrincipal != null && prop.currentUserPrincipal.getHref() != null) - referenced.properties.put(Property.CURRENT_USER_PRINCIPAL, prop.currentUserPrincipal.getHref().href); + properties.put(Property.CURRENT_USER_PRINCIPAL, prop.currentUserPrincipal.getHref().href); if (prop.addressbookHomeSet != null && prop.addressbookHomeSet.getHref() != null) - referenced.properties.put(Property.ADDRESSBOOK_HOMESET, prop.addressbookHomeSet.getHref().href); + properties.put(Property.ADDRESSBOOK_HOMESET, prop.addressbookHomeSet.getHref().href); if (singlePropstat.prop.calendarHomeSet != null && prop.calendarHomeSet.getHref() != null) - referenced.properties.put(Property.CALENDAR_HOMESET, prop.calendarHomeSet.getHref().href); + properties.put(Property.CALENDAR_HOMESET, prop.calendarHomeSet.getHref().href); if (prop.displayname != null) - referenced.properties.put(Property.DISPLAY_NAME, prop.displayname.getDisplayName()); + properties.put(Property.DISPLAY_NAME, prop.displayname.getDisplayName()); if (prop.resourcetype != null) { if (prop.resourcetype.getAddressbook() != null) { - referenced.properties.put(Property.IS_ADDRESSBOOK, "1"); + properties.put(Property.IS_ADDRESSBOOK, "1"); if (prop.addressbookDescription != null) - referenced.properties.put(Property.DESCRIPTION, prop.addressbookDescription.getDescription()); + properties.put(Property.DESCRIPTION, prop.addressbookDescription.getDescription()); } else - referenced.properties.remove(Property.IS_ADDRESSBOOK); + properties.remove(Property.IS_ADDRESSBOOK); if (prop.resourcetype.getCalendar() != null) { - referenced.properties.put(Property.IS_CALENDAR, "1"); + properties.put(Property.IS_CALENDAR, "1"); if (prop.calendarDescription != null) - referenced.properties.put(Property.DESCRIPTION, prop.calendarDescription.getDescription()); + properties.put(Property.DESCRIPTION, prop.calendarDescription.getDescription()); if (prop.calendarColor != null) - referenced.properties.put(Property.COLOR, prop.calendarColor.getColor()); + properties.put(Property.COLOR, prop.calendarColor.getColor()); if (prop.calendarTimezone != null) - referenced.properties.put(Property.TIMEZONE, Event.TimezoneDefToTzId(prop.calendarTimezone.getTimezone())); + properties.put(Property.TIMEZONE, Event.TimezoneDefToTzId(prop.calendarTimezone.getTimezone())); + + if (prop.supportedCalendarComponentSet != null && prop.supportedCalendarComponentSet.components != null) { + referenced.supportedComponents = new LinkedList(); + for (DavPropComp component : prop.supportedCalendarComponentSet.components) + referenced.supportedComponents.add(component.getName()); + } } else referenced.properties.remove(Property.IS_CALENDAR); }