1
0
mirror of https://github.com/etesync/android synced 2025-01-11 00:01:12 +00:00

Don't check capabilities on principal URL but on calendar/address book home set (fixes #286)

This commit is contained in:
rfc2822 2014-07-24 23:41:48 +02:00
parent 02d72e4f51
commit 75e5a59948

View File

@ -119,77 +119,81 @@ public class QueryServerDialogFragment extends DialogFragment implements LoaderC
serverInfo.getPassword(), serverInfo.isAuthPreemptive());
// CardDAV
WebDavResource principal = getCurrentUserPrincipal(base, "carddav", "addressbook");
WebDavResource principal = getCurrentUserPrincipal(base, "carddav");
if (principal != null) {
serverInfo.setCardDAV(true);
principal.propfind(Mode.HOME_SETS);
String pathAddressBooks = principal.getAddressbookHomeSet();
if (pathAddressBooks != null)
if (pathAddressBooks != null) {
Log.i(TAG, "Found address book home set: " + pathAddressBooks);
else
throw new DavIncapableException(getContext().getString(R.string.error_home_set_address_books));
WebDavResource homeSetAddressBooks = new WebDavResource(principal, pathAddressBooks);
homeSetAddressBooks.propfind(Mode.MEMBERS_COLLECTIONS);
List<ServerInfo.ResourceInfo> addressBooks = new LinkedList<ServerInfo.ResourceInfo>();
if (homeSetAddressBooks.getMembers() != null)
for (WebDavResource resource : homeSetAddressBooks.getMembers())
if (resource.isAddressBook()) {
Log.i(TAG, "Found address book: " + resource.getLocation().getRawPath());
ServerInfo.ResourceInfo info = new ServerInfo.ResourceInfo(
ServerInfo.ResourceInfo.Type.ADDRESS_BOOK,
resource.isReadOnly(),
resource.getLocation().toASCIIString(),
resource.getDisplayName(),
resource.getDescription(), resource.getColor()
);
addressBooks.add(info);
}
serverInfo.setAddressBooks(addressBooks);
WebDavResource homeSetAddressBooks = new WebDavResource(principal, pathAddressBooks);
if (checkCapabilities(homeSetAddressBooks, "addressbook")) {
homeSetAddressBooks.propfind(Mode.MEMBERS_COLLECTIONS);
List<ServerInfo.ResourceInfo> addressBooks = new LinkedList<ServerInfo.ResourceInfo>();
if (homeSetAddressBooks.getMembers() != null)
for (WebDavResource resource : homeSetAddressBooks.getMembers())
if (resource.isAddressBook()) {
Log.i(TAG, "Found address book: " + resource.getLocation().getRawPath());
ServerInfo.ResourceInfo info = new ServerInfo.ResourceInfo(
ServerInfo.ResourceInfo.Type.ADDRESS_BOOK,
resource.isReadOnly(),
resource.getLocation().toASCIIString(),
resource.getDisplayName(),
resource.getDescription(), resource.getColor()
);
addressBooks.add(info);
}
serverInfo.setAddressBooks(addressBooks);
} else
Log.w(TAG, "Found address-book home set, but it doesn't advertise CardDAV support");
}
}
// CalDAV
principal = getCurrentUserPrincipal(base, "caldav", "calendar-access");
principal = getCurrentUserPrincipal(base, "caldav");
if (principal != null) {
serverInfo.setCalDAV(true);
principal.propfind(Mode.HOME_SETS);
String pathCalendars = principal.getCalendarHomeSet();
if (pathCalendars != null)
if (pathCalendars != null) {
Log.i(TAG, "Found calendar home set: " + pathCalendars);
else
throw new DavIncapableException(getContext().getString(R.string.error_home_set_calendars));
WebDavResource homeSetCalendars = new WebDavResource(principal, pathCalendars);
homeSetCalendars.propfind(Mode.MEMBERS_COLLECTIONS);
List<ServerInfo.ResourceInfo> calendars = new LinkedList<ServerInfo.ResourceInfo>();
if (homeSetCalendars.getMembers() != null)
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.isReadOnly(),
resource.getLocation().toASCIIString(),
resource.getDisplayName(),
resource.getDescription(), resource.getColor()
);
info.setTimezone(resource.getTimezone());
calendars.add(info);
}
serverInfo.setCalendars(calendars);
WebDavResource homeSetCalendars = new WebDavResource(principal, pathCalendars);
if (checkCapabilities(homeSetCalendars, "calendar-access")) {
homeSetCalendars.propfind(Mode.MEMBERS_COLLECTIONS);
List<ServerInfo.ResourceInfo> calendars = new LinkedList<ServerInfo.ResourceInfo>();
if (homeSetCalendars.getMembers() != null)
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.isReadOnly(),
resource.getLocation().toASCIIString(),
resource.getDisplayName(),
resource.getDescription(), resource.getColor()
);
info.setTimezone(resource.getTimezone());
calendars.add(info);
}
serverInfo.setCalendars(calendars);
} else
Log.w(TAG, "Found calendar home set, but it doesn't advertise CalDAV support");
}
}
if (!serverInfo.isCalDAV() && !serverInfo.isCardDAV())
@ -214,24 +218,17 @@ public class QueryServerDialogFragment extends DialogFragment implements LoaderC
* Detects the current-user-principal for a given WebDavResource. At first, /.well-known/ is tried. Only
* if no current-user-principal can be detected for the .well-known location, the given location of the resource
* is tried.
* When a current-user-principal is found, it is queried for davCapability via OPTIONS.
* @param resource Location that will be queried
* @param serviceName Well-known service name ("carddav", "caldav")
* @param davCapability DAV capability to check for ("addressbook", "calendar-access")
* @return WebDavResource of current-user-principal for the given service, or null if it can't be found or it is incapable
* @return WebDavResource of current-user-principal for the given service, or null if it can't be found
*/
private WebDavResource getCurrentUserPrincipal(WebDavResource resource, String serviceName, String davCapability) throws IOException, HttpException, DavException {
private WebDavResource getCurrentUserPrincipal(WebDavResource resource, String serviceName) throws IOException, HttpException, DavException {
// look for well-known service (RFC 5785)
try {
WebDavResource wellKnown = new WebDavResource(resource, "/.well-known/" + serviceName);
wellKnown.propfind(Mode.CURRENT_USER_PRINCIPAL);
if (wellKnown.getCurrentUserPrincipal() != null) {
WebDavResource principal = new WebDavResource(wellKnown, wellKnown.getCurrentUserPrincipal());
if (checkCapabilities(principal, davCapability))
return principal;
else
Log.w(TAG, "Current-user-principal " + resource.getLocation() + " found via well-known service, but it doesn't support required DAV facilities");
}
if (wellKnown.getCurrentUserPrincipal() != null)
return new WebDavResource(wellKnown, wellKnown.getCurrentUserPrincipal());
} catch (HttpException e) {
Log.d(TAG, "Well-known service detection failed with HTTP error", e);
} catch (DavException e) {
@ -240,13 +237,8 @@ public class QueryServerDialogFragment extends DialogFragment implements LoaderC
// fall back to user-given initial context path
resource.propfind(Mode.CURRENT_USER_PRINCIPAL);
if (resource.getCurrentUserPrincipal() != null) {
WebDavResource principal = new WebDavResource(resource, resource.getCurrentUserPrincipal());
if (checkCapabilities(principal, davCapability))
return principal;
else
Log.w(TAG, "Current-user-principal " + resource.getLocation() + " found at user-given location, but it doesn't support required DAV facilities");
}
if (resource.getCurrentUserPrincipal() != null)
return new WebDavResource(resource, resource.getCurrentUserPrincipal());
return null;
}