From 82f80fed1c2167056ab9637baf67698a5db39b87 Mon Sep 17 00:00:00 2001 From: Ricki Hirner Date: Mon, 19 Oct 2015 01:04:59 +0200 Subject: [PATCH] Resource detection fixes * check TXT records for ._tcp.domain.tld instead of domain.tld * duplicate log to ADB for successful resource detection --- .../davdroid/resource/DavResourceFinder.java | 23 ++++++++++--------- .../ui/setup/QueryServerDialogFragment.java | 20 ++++++++++++++++ app/src/main/res/values-de/strings.xml | 2 +- app/src/main/res/values/strings.xml | 2 +- 4 files changed, 34 insertions(+), 13 deletions(-) diff --git a/app/src/main/java/at/bitfire/davdroid/resource/DavResourceFinder.java b/app/src/main/java/at/bitfire/davdroid/resource/DavResourceFinder.java index 048efec2..ba3772fa 100644 --- a/app/src/main/java/at/bitfire/davdroid/resource/DavResourceFinder.java +++ b/app/src/main/java/at/bitfire/davdroid/resource/DavResourceFinder.java @@ -45,6 +45,7 @@ import at.bitfire.dav4android.property.CurrentUserPrivilegeSet; import at.bitfire.dav4android.property.DisplayName; import at.bitfire.dav4android.property.ResourceType; import at.bitfire.dav4android.property.SupportedCalendarComponentSet; +import at.bitfire.davdroid.Constants; import at.bitfire.davdroid.HttpClient; import lombok.NonNull; @@ -396,18 +397,18 @@ public class DavResourceFinder { log.info("Found " + service + " service: fqdn=" + fqdn + ", port=" + port); // look for TXT record too (for initial context path) - records = new Lookup(domain, Type.TXT).run(); - if (records != null && records.length >= 1) { - TXTRecord txt = (TXTRecord)records[0]; - for (String segment : (String[])txt.getStrings().toArray(new String[0])) - if (segment.startsWith("path=")) { - paths.add(segment.substring(5)); - log.info("Found TXT record; initial context path=" + paths); - break; - } - } + records = new Lookup(query, Type.TXT).run(); + if (records != null) + for (Record record : records) + if (record instanceof TXTRecord) + for (String segment : (List) ((TXTRecord) record).getStrings()) + if (segment.startsWith("path=")) { + paths.add(segment.substring(5)); + log.info("Found TXT record; initial context path=" + paths); + break; + } - // if there's TXT record if it it's wrong, try well-known + // if there's TXT record and if it it's wrong, try well-known paths.add("/.well-known/" + service.name); // if this fails, too, try "/" paths.add("/"); diff --git a/app/src/main/java/at/bitfire/davdroid/ui/setup/QueryServerDialogFragment.java b/app/src/main/java/at/bitfire/davdroid/ui/setup/QueryServerDialogFragment.java index 16523d8d..c5770963 100644 --- a/app/src/main/java/at/bitfire/davdroid/ui/setup/QueryServerDialogFragment.java +++ b/app/src/main/java/at/bitfire/davdroid/ui/setup/QueryServerDialogFragment.java @@ -21,12 +21,19 @@ import android.content.Intent; import android.content.Loader; import android.os.Bundle; +import java.io.BufferedInputStream; +import java.io.BufferedReader; +import java.io.IOException; +import java.io.StringReader; + +import at.bitfire.davdroid.Constants; import at.bitfire.davdroid.R; import at.bitfire.davdroid.log.StringLogger; import at.bitfire.davdroid.resource.DavResourceFinder; import at.bitfire.davdroid.resource.LocalTaskList; import at.bitfire.davdroid.resource.ServerInfo; import at.bitfire.davdroid.ui.DebugInfoActivity; +import lombok.Cleanup; public class QueryServerDialogFragment extends DialogFragment implements LoaderCallbacks { public static final String KEY_SERVER_INFO = "server_info"; @@ -154,7 +161,20 @@ public class QueryServerDialogFragment extends DialogFragment implements LoaderC DavResourceFinder finder = new DavResourceFinder(logger, context, serverInfo); finder.findResources(); + // duplicate logs to ADB + String logs = logger.toString(); + try { + @Cleanup BufferedReader logStream = new BufferedReader(new StringReader(logs)); + Constants.log.info("Successful resource detection:"); + String line; + while ((line = logStream.readLine()) != null) + Constants.log.debug(line); + } catch (IOException e) { + Constants.log.error("Couldn't read resource detection logs", e); + } + serverInfo.setLogs(logger.toString()); + return serverInfo; } } diff --git a/app/src/main/res/values-de/strings.xml b/app/src/main/res/values-de/strings.xml index 39d0cc89..6d06ddda 100644 --- a/app/src/main/res/values-de/strings.xml +++ b/app/src/main/res/values-de/strings.xml @@ -145,7 +145,7 @@ Dieses Programm ist freie Software. Sie können es unter den Bedingungen der GNU Konto-Details Kontoname: Mein CalDAV/CardDAV-Konto - \"Verwenden Sie Ihre Email-Adresse als Kontoname, da Android den Kontonamen als ORGANIZER-Feld in Terminen benutzt. Sie können keine zwei Konten mit dem gleichen Namen anlegen. + Verwenden Sie Ihre Email-Adresse als Kontoname, da Android den Kontonamen als ORGANIZER-Feld in Terminen benutzt. Sie können keine zwei Konten mit dem gleichen Namen anlegen. schreibgeschützt Debug-Info diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index c4203ef2..b25e8e3b 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -178,7 +178,7 @@ Account details Account name: My CalDAV/CardDAV Account - "Use your email address as account name because Android will use the account name as ORGANIZER field for events you create. You can't have two accounts with the same name. + Use your email address as account name because Android will use the account name as ORGANIZER field for events you create. You can\'t have two accounts with the same name. read-only