mirror of
https://github.com/etesync/android
synced 2025-01-22 21:51:04 +00:00
Bug fixes
* optimise URL repairs: don't replace "[", "]", ":" in host names, allowing IP address literals (closes #98) * SyncManager: minor refactoring
This commit is contained in:
parent
520ec21d9e
commit
983214d23b
@ -1,3 +1,13 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2014 Richard Hirner (bitfire web engineering).
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the GNU Public License v3.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.gnu.org/licenses/gpl.html
|
||||
*
|
||||
* Contributors:
|
||||
* Richard Hirner (bitfire web engineering) - initial API and implementation
|
||||
******************************************************************************/
|
||||
package at.bitfire.davdroid;
|
||||
|
||||
import java.lang.reflect.Array;
|
||||
|
@ -1,9 +1,12 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2013 Richard Hirner (bitfire web engineering).
|
||||
* Copyright (c) 2014 Richard Hirner (bitfire web engineering).
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the GNU Public License v3.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.gnu.org/licenses/gpl.html
|
||||
*
|
||||
* Contributors:
|
||||
* Richard Hirner (bitfire web engineering) - initial API and implementation
|
||||
******************************************************************************/
|
||||
package at.bitfire.davdroid;
|
||||
|
||||
|
@ -1,3 +1,13 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2014 Richard Hirner (bitfire web engineering).
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the GNU Public License v3.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.gnu.org/licenses/gpl.html
|
||||
*
|
||||
* Contributors:
|
||||
* Richard Hirner (bitfire web engineering) - initial API and implementation
|
||||
******************************************************************************/
|
||||
package at.bitfire.davdroid;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
|
@ -1,3 +1,13 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2014 Richard Hirner (bitfire web engineering).
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the GNU Public License v3.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.gnu.org/licenses/gpl.html
|
||||
*
|
||||
* Contributors:
|
||||
* Richard Hirner (bitfire web engineering) - initial API and implementation
|
||||
******************************************************************************/
|
||||
package at.bitfire.davdroid;
|
||||
|
||||
import android.app.Activity;
|
||||
|
@ -1,5 +1,18 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2014 Richard Hirner (bitfire web engineering).
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the GNU Public License v3.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.gnu.org/licenses/gpl.html
|
||||
*
|
||||
* Contributors:
|
||||
* Richard Hirner (bitfire web engineering) - initial API and implementation
|
||||
******************************************************************************/
|
||||
package at.bitfire.davdroid;
|
||||
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.util.Log;
|
||||
|
||||
@ -10,25 +23,48 @@ public class URIUtils {
|
||||
|
||||
// handles invalid URLs/paths as good as possible
|
||||
public static String sanitize(String original) {
|
||||
String url = original;
|
||||
Pattern p = Pattern.compile("^((https?:)?//([^/]+))?(.*)", Pattern.CASE_INSENSITIVE);
|
||||
// $1: "http://hostname" or "https://hostname" or "//hostname" or empty (hostname may end with":port")
|
||||
// $2: "http:" or "https:" or empty
|
||||
// $3: hostname (may end with ":port") or empty
|
||||
// $4: path or empty
|
||||
|
||||
// ":" is reserved as scheme/port separator, but we assume http:// and https:// URLs only
|
||||
// and will encode ":" in URLs without one of these schemata
|
||||
if (!url.toLowerCase().startsWith("http://") && // ":" is valid scheme separator
|
||||
!url.toLowerCase().startsWith("https://") && // ":" is valid scheme separator
|
||||
!url.startsWith("//")) // ":" may be valid port separator
|
||||
url = url.replace(":", "%3A"); // none of these -> ":" is not used for reserved purpose -> must be encoded
|
||||
|
||||
// rewrite reserved characters:
|
||||
// "@" should be used for user name/password, but this case shouldn't appear in our URLs
|
||||
// rewrite unsafe characters, too:
|
||||
// " ", "<", ">", """, "#", "{", "}", "|", "\", "^", "~", "["], "]", "`"
|
||||
// do not rewrite "%" because we assume that URLs should be already encoded correctly
|
||||
for (char c : new char[] { '@', ' ', '<', '>', '"', '#', '{', '}', '|', '\\', '^', '~', '[', ']', '`' })
|
||||
url = url.replace(String.valueOf(c), "%" + Integer.toHexString(c));
|
||||
|
||||
if (!url.equals(original))
|
||||
Log.w(TAG, "Trying to repair invalid URL: " + original + " -> " + url);
|
||||
return url;
|
||||
Matcher m = p.matcher(original);
|
||||
if (m.find()) {
|
||||
String schema = m.group(2),
|
||||
host = m.group(3),
|
||||
path = m.group(4);
|
||||
|
||||
if (host != null)
|
||||
// sanitize host name (don't replace "[", "]", ":" for IP address literals and port numbers)
|
||||
// "@" should be used for user name/password, but this case shouldn't appear in our URLs
|
||||
for (char c : new char[] { '@', ' ', '<', '>', '"', '#', '{', '}', '|', '\\', '^', '~', '`' })
|
||||
host = host.replace(String.valueOf(c), "%" + Integer.toHexString(c));
|
||||
|
||||
if (path != null)
|
||||
// rewrite reserved characters:
|
||||
// ":" and "@" may be used in the host part but not in the path
|
||||
// rewrite unsafe characters:
|
||||
// " ", "<", ">", """, "#", "{", "}", "|", "\", "^", "~", "["], "]", "`"
|
||||
// do not rewrite "%" because we assume that URLs should be already encoded correctly
|
||||
for (char c : new char[] { ':', '@', ' ', '<', '>', '"', '#', '{', '}', '|', '\\', '^', '~', '[', ']', '`' })
|
||||
path = path.replace(String.valueOf(c), "%" + Integer.toHexString(c));
|
||||
|
||||
String url = (schema != null) ? schema : "";
|
||||
if (host != null)
|
||||
url = url + "//" + host;
|
||||
if (path != null)
|
||||
url = url + path;
|
||||
|
||||
if (!url.equals(original))
|
||||
Log.w(TAG, "Trying to repair invalid URL: " + original + " -> " + url);
|
||||
return url;
|
||||
|
||||
} else {
|
||||
|
||||
Log.w(TAG, "Couldn't sanitize URL: " + original);
|
||||
return original;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,9 +1,12 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2013 Richard Hirner (bitfire web engineering).
|
||||
* Copyright (c) 2014 Richard Hirner (bitfire web engineering).
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the GNU Public License v3.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.gnu.org/licenses/gpl.html
|
||||
*
|
||||
* Contributors:
|
||||
* Richard Hirner (bitfire web engineering) - initial API and implementation
|
||||
******************************************************************************/
|
||||
package at.bitfire.davdroid.resource;
|
||||
|
||||
|
@ -1,9 +1,12 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2013 Richard Hirner (bitfire web engineering).
|
||||
* Copyright (c) 2014 Richard Hirner (bitfire web engineering).
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the GNU Public License v3.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.gnu.org/licenses/gpl.html
|
||||
*
|
||||
* Contributors:
|
||||
* Richard Hirner (bitfire web engineering) - initial API and implementation
|
||||
******************************************************************************/
|
||||
package at.bitfire.davdroid.resource;
|
||||
|
||||
|
@ -1,9 +1,12 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2013 Richard Hirner (bitfire web engineering).
|
||||
* Copyright (c) 2014 Richard Hirner (bitfire web engineering).
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the GNU Public License v3.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.gnu.org/licenses/gpl.html
|
||||
*
|
||||
* Contributors:
|
||||
* Richard Hirner (bitfire web engineering) - initial API and implementation
|
||||
******************************************************************************/
|
||||
package at.bitfire.davdroid.resource;
|
||||
|
||||
|
@ -1,9 +1,12 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2013 Richard Hirner (bitfire web engineering).
|
||||
* Copyright (c) 2014 Richard Hirner (bitfire web engineering).
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the GNU Public License v3.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.gnu.org/licenses/gpl.html
|
||||
*
|
||||
* Contributors:
|
||||
* Richard Hirner (bitfire web engineering) - initial API and implementation
|
||||
******************************************************************************/
|
||||
package at.bitfire.davdroid.resource;
|
||||
|
||||
|
@ -1,9 +1,12 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2013 Richard Hirner (bitfire web engineering).
|
||||
* Copyright (c) 2014 Richard Hirner (bitfire web engineering).
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the GNU Public License v3.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.gnu.org/licenses/gpl.html
|
||||
*
|
||||
* Contributors:
|
||||
* Richard Hirner (bitfire web engineering) - initial API and implementation
|
||||
******************************************************************************/
|
||||
package at.bitfire.davdroid.resource;
|
||||
|
||||
|
@ -1,3 +1,13 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2014 Richard Hirner (bitfire web engineering).
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the GNU Public License v3.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.gnu.org/licenses/gpl.html
|
||||
*
|
||||
* Contributors:
|
||||
* Richard Hirner (bitfire web engineering) - initial API and implementation
|
||||
******************************************************************************/
|
||||
package at.bitfire.davdroid.resource;
|
||||
|
||||
public class LocalStorageException extends Exception {
|
||||
|
@ -1,3 +1,13 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2014 Richard Hirner (bitfire web engineering).
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the GNU Public License v3.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.gnu.org/licenses/gpl.html
|
||||
*
|
||||
* Contributors:
|
||||
* Richard Hirner (bitfire web engineering) - initial API and implementation
|
||||
******************************************************************************/
|
||||
package at.bitfire.davdroid.resource;
|
||||
|
||||
public class RecordNotFoundException extends LocalStorageException {
|
||||
|
@ -1,9 +1,12 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2013 Richard Hirner (bitfire web engineering).
|
||||
* Copyright (c) 2014 Richard Hirner (bitfire web engineering).
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the GNU Public License v3.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.gnu.org/licenses/gpl.html
|
||||
*
|
||||
* Contributors:
|
||||
* Richard Hirner (bitfire web engineering) - initial API and implementation
|
||||
******************************************************************************/
|
||||
package at.bitfire.davdroid.resource;
|
||||
|
||||
|
@ -1,9 +1,12 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2013 Richard Hirner (bitfire web engineering).
|
||||
* Copyright (c) 2014 Richard Hirner (bitfire web engineering).
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the GNU Public License v3.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.gnu.org/licenses/gpl.html
|
||||
*
|
||||
* Contributors:
|
||||
* Richard Hirner (bitfire web engineering) - initial API and implementation
|
||||
******************************************************************************/
|
||||
package at.bitfire.davdroid.resource;
|
||||
|
||||
|
@ -1,9 +1,12 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2013 Richard Hirner (bitfire web engineering).
|
||||
* Copyright (c) 2014 Richard Hirner (bitfire web engineering).
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the GNU Public License v3.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.gnu.org/licenses/gpl.html
|
||||
*
|
||||
* Contributors:
|
||||
* Richard Hirner (bitfire web engineering) - initial API and implementation
|
||||
******************************************************************************/
|
||||
package at.bitfire.davdroid.syncadapter;
|
||||
|
||||
|
@ -1,3 +1,13 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2014 Richard Hirner (bitfire web engineering).
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the GNU Public License v3.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.gnu.org/licenses/gpl.html
|
||||
*
|
||||
* Contributors:
|
||||
* Richard Hirner (bitfire web engineering) - initial API and implementation
|
||||
******************************************************************************/
|
||||
package at.bitfire.davdroid.syncadapter;
|
||||
|
||||
import android.accounts.Account;
|
||||
|
@ -1,9 +1,12 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2013 Richard Hirner (bitfire web engineering).
|
||||
* Copyright (c) 2014 Richard Hirner (bitfire web engineering).
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the GNU Public License v3.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.gnu.org/licenses/gpl.html
|
||||
*
|
||||
* Contributors:
|
||||
* Richard Hirner (bitfire web engineering) - initial API and implementation
|
||||
******************************************************************************/
|
||||
package at.bitfire.davdroid.syncadapter;
|
||||
|
||||
|
@ -1,9 +1,12 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2013 Richard Hirner (bitfire web engineering).
|
||||
* Copyright (c) 2014 Richard Hirner (bitfire web engineering).
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the GNU Public License v3.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.gnu.org/licenses/gpl.html
|
||||
*
|
||||
* Contributors:
|
||||
* Richard Hirner (bitfire web engineering) - initial API and implementation
|
||||
******************************************************************************/
|
||||
package at.bitfire.davdroid.syncadapter;
|
||||
|
||||
|
@ -1,9 +1,12 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2013 Richard Hirner (bitfire web engineering).
|
||||
* Copyright (c) 2014 Richard Hirner (bitfire web engineering).
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the GNU Public License v3.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.gnu.org/licenses/gpl.html
|
||||
*
|
||||
* Contributors:
|
||||
* Richard Hirner (bitfire web engineering) - initial API and implementation
|
||||
******************************************************************************/
|
||||
package at.bitfire.davdroid.syncadapter;
|
||||
|
||||
|
@ -1,3 +1,13 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2014 Richard Hirner (bitfire web engineering).
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the GNU Public License v3.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.gnu.org/licenses/gpl.html
|
||||
*
|
||||
* Contributors:
|
||||
* Richard Hirner (bitfire web engineering) - initial API and implementation
|
||||
******************************************************************************/
|
||||
package at.bitfire.davdroid.syncadapter;
|
||||
|
||||
import java.io.IOException;
|
||||
@ -52,15 +62,13 @@ public abstract class DavSyncAdapter extends AbstractThreadedSyncAdapter {
|
||||
// set class loader for iCal4j ResourceLoader
|
||||
Thread.currentThread().setContextClassLoader(getContext().getClassLoader());
|
||||
|
||||
SyncManager syncManager = new SyncManager();
|
||||
|
||||
Map<LocalCollection<?>, RemoteCollection<?>> syncCollections = getSyncPairs(account, provider);
|
||||
if (syncCollections == null)
|
||||
Log.i(TAG, "Nothing to synchronize");
|
||||
else
|
||||
try {
|
||||
for (Map.Entry<LocalCollection<?>, RemoteCollection<?>> entry : syncCollections.entrySet())
|
||||
syncManager.synchronize(entry.getKey(), entry.getValue(), extras.containsKey(ContentResolver.SYNC_EXTRAS_MANUAL), syncResult);
|
||||
new SyncManager(entry.getKey(), entry.getValue()).synchronize(extras.containsKey(ContentResolver.SYNC_EXTRAS_MANUAL), syncResult);
|
||||
|
||||
} catch (AuthenticationException ex) {
|
||||
syncResult.stats.numAuthExceptions++;
|
||||
|
@ -1,9 +1,12 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2013 Richard Hirner (bitfire web engineering).
|
||||
* Copyright (c) 2014 Richard Hirner (bitfire web engineering).
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the GNU Public License v3.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.gnu.org/licenses/gpl.html
|
||||
*
|
||||
* Contributors:
|
||||
* Richard Hirner (bitfire web engineering) - initial API and implementation
|
||||
******************************************************************************/
|
||||
package at.bitfire.davdroid.syncadapter;
|
||||
|
||||
@ -125,7 +128,7 @@ public class EnterCredentialsFragment extends Fragment implements TextWatcher {
|
||||
|
||||
// check host name
|
||||
try {
|
||||
URL url = new URL(protocol + editBaseURL.getText().toString());
|
||||
URL url = new URL(URIUtils.sanitize(protocol + editBaseURL.getText().toString()));
|
||||
if (url.getHost() == null || url.getHost().isEmpty())
|
||||
ok = false;
|
||||
} catch (MalformedURLException e) {
|
||||
|
@ -1,9 +1,12 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2013 Richard Hirner (bitfire web engineering).
|
||||
* Copyright (c) 2014 Richard Hirner (bitfire web engineering).
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the GNU Public License v3.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.gnu.org/licenses/gpl.html
|
||||
*
|
||||
* Contributors:
|
||||
* Richard Hirner (bitfire web engineering) - initial API and implementation
|
||||
******************************************************************************/
|
||||
package at.bitfire.davdroid.syncadapter;
|
||||
|
||||
|
@ -1,9 +1,12 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2013 Richard Hirner (bitfire web engineering).
|
||||
* Copyright (c) 2014 Richard Hirner (bitfire web engineering).
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the GNU Public License v3.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.gnu.org/licenses/gpl.html
|
||||
*
|
||||
* Contributors:
|
||||
* Richard Hirner (bitfire web engineering) - initial API and implementation
|
||||
******************************************************************************/
|
||||
package at.bitfire.davdroid.syncadapter;
|
||||
|
||||
|
@ -1,9 +1,12 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2013 Richard Hirner (bitfire web engineering).
|
||||
* Copyright (c) 2014 Richard Hirner (bitfire web engineering).
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the GNU Public License v3.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.gnu.org/licenses/gpl.html
|
||||
*
|
||||
* Contributors:
|
||||
* Richard Hirner (bitfire web engineering) - initial API and implementation
|
||||
******************************************************************************/
|
||||
package at.bitfire.davdroid.syncadapter;
|
||||
|
||||
|
@ -1,9 +1,12 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2013 Richard Hirner (bitfire web engineering).
|
||||
* Copyright (c) 2014 Richard Hirner (bitfire web engineering).
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the GNU Public License v3.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.gnu.org/licenses/gpl.html
|
||||
*
|
||||
* Contributors:
|
||||
* Richard Hirner (bitfire web engineering) - initial API and implementation
|
||||
******************************************************************************/
|
||||
package at.bitfire.davdroid.syncadapter;
|
||||
|
||||
|
@ -31,12 +31,21 @@ public class SyncManager {
|
||||
|
||||
private static final int MAX_MULTIGET_RESOURCES = 35;
|
||||
|
||||
protected LocalCollection<? extends Resource> local;
|
||||
protected RemoteCollection<? extends Resource> remote;
|
||||
|
||||
|
||||
public SyncManager(LocalCollection<? extends Resource> local, RemoteCollection<? extends Resource> remote) {
|
||||
this.local = local;
|
||||
this.remote = remote;
|
||||
}
|
||||
|
||||
public static void synchronize(LocalCollection<? extends Resource> local, RemoteCollection<? extends Resource> remote, boolean manualSync, SyncResult syncResult) throws LocalStorageException, IOException, HttpException {
|
||||
|
||||
public void synchronize(boolean manualSync, SyncResult syncResult) throws LocalStorageException, IOException, HttpException {
|
||||
// PHASE 1: push local changes to server
|
||||
int deletedRemotely = pushDeleted(local, remote),
|
||||
addedRemotely = pushNew(local, remote),
|
||||
updatedRemotely = pushDirty(local, remote);
|
||||
int deletedRemotely = pushDeleted(),
|
||||
addedRemotely = pushNew(),
|
||||
updatedRemotely = pushDirty();
|
||||
|
||||
syncResult.stats.numEntries = deletedRemotely + addedRemotely + updatedRemotely;
|
||||
|
||||
@ -70,8 +79,8 @@ public class SyncManager {
|
||||
}
|
||||
|
||||
// PHASE 3: pull remote changes from server
|
||||
syncResult.stats.numInserts = pullNew(local, remote, remotelyAdded.toArray(new Resource[0]));
|
||||
syncResult.stats.numUpdates = pullChanged(local, remote, remotelyUpdated.toArray(new Resource[0]));
|
||||
syncResult.stats.numInserts = pullNew(remotelyAdded.toArray(new Resource[0]));
|
||||
syncResult.stats.numUpdates = pullChanged(remotelyUpdated.toArray(new Resource[0]));
|
||||
syncResult.stats.numEntries += syncResult.stats.numInserts + syncResult.stats.numUpdates;
|
||||
|
||||
Log.i(TAG, "Removing non-dirty resources that are not present remotely anymore");
|
||||
@ -85,7 +94,7 @@ public class SyncManager {
|
||||
}
|
||||
|
||||
|
||||
private static int pushDeleted(LocalCollection<? extends Resource> local, RemoteCollection<? extends Resource> remote) throws LocalStorageException, IOException, HttpException {
|
||||
private int pushDeleted() throws LocalStorageException, IOException, HttpException {
|
||||
int count = 0;
|
||||
long[] deletedIDs = local.findDeleted();
|
||||
|
||||
@ -111,7 +120,7 @@ public class SyncManager {
|
||||
return count;
|
||||
}
|
||||
|
||||
private static int pushNew(LocalCollection<? extends Resource> local, RemoteCollection<? extends Resource> remote) throws LocalStorageException, IOException, HttpException {
|
||||
private int pushNew() throws LocalStorageException, IOException, HttpException {
|
||||
int count = 0;
|
||||
long[] newIDs = local.findNew();
|
||||
Log.i(TAG, "Uploading " + newIDs.length + " new resource(s) (if not existing)");
|
||||
@ -135,7 +144,7 @@ public class SyncManager {
|
||||
return count;
|
||||
}
|
||||
|
||||
private static int pushDirty(LocalCollection<? extends Resource> local, RemoteCollection<? extends Resource> remote) throws LocalStorageException, IOException, HttpException {
|
||||
private int pushDirty() throws LocalStorageException, IOException, HttpException {
|
||||
int count = 0;
|
||||
long[] dirtyIDs = local.findDirty();
|
||||
Log.i(TAG, "Uploading " + dirtyIDs.length + " modified resource(s) (if not changed)");
|
||||
@ -160,7 +169,7 @@ public class SyncManager {
|
||||
return count;
|
||||
}
|
||||
|
||||
private static int pullNew(LocalCollection<? extends Resource> local, RemoteCollection<? extends Resource> remote, Resource[] resourcesToAdd) throws LocalStorageException, IOException, HttpException {
|
||||
private int pullNew(Resource[] resourcesToAdd) throws LocalStorageException, IOException, HttpException {
|
||||
int count = 0;
|
||||
Log.i(TAG, "Fetching " + resourcesToAdd.length + " new remote resource(s)");
|
||||
|
||||
@ -177,7 +186,7 @@ public class SyncManager {
|
||||
return count;
|
||||
}
|
||||
|
||||
private static int pullChanged(LocalCollection<? extends Resource> local, RemoteCollection<? extends Resource> remote, Resource[] resourcesToUpdate) throws LocalStorageException, IOException, HttpException {
|
||||
private int pullChanged(Resource[] resourcesToUpdate) throws LocalStorageException, IOException, HttpException {
|
||||
int count = 0;
|
||||
Log.i(TAG, "Fetching " + resourcesToUpdate.length + " updated remote resource(s)");
|
||||
|
||||
|
@ -1,9 +1,12 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2013 Richard Hirner (bitfire web engineering).
|
||||
* Copyright (c) 2014 Richard Hirner (bitfire web engineering).
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the GNU Public License v3.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.gnu.org/licenses/gpl.html
|
||||
*
|
||||
* Contributors:
|
||||
* Richard Hirner (bitfire web engineering) - initial API and implementation
|
||||
******************************************************************************/
|
||||
package at.bitfire.davdroid.syncadapter;
|
||||
|
||||
|
@ -1,9 +1,12 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2013 Richard Hirner (bitfire web engineering).
|
||||
* Copyright (c) 2014 Richard Hirner (bitfire web engineering).
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the GNU Public License v3.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.gnu.org/licenses/gpl.html
|
||||
*
|
||||
* Contributors:
|
||||
* Richard Hirner (bitfire web engineering) - initial API and implementation
|
||||
******************************************************************************/
|
||||
package at.bitfire.davdroid.webdav;
|
||||
|
||||
|
@ -1,9 +1,12 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2013 Richard Hirner (bitfire web engineering).
|
||||
* Copyright (c) 2014 Richard Hirner (bitfire web engineering).
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the GNU Public License v3.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.gnu.org/licenses/gpl.html
|
||||
*
|
||||
* Contributors:
|
||||
* Richard Hirner (bitfire web engineering) - initial API and implementation
|
||||
******************************************************************************/
|
||||
package at.bitfire.davdroid.webdav;
|
||||
|
||||
|
@ -1,3 +1,13 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2014 Richard Hirner (bitfire web engineering).
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the GNU Public License v3.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.gnu.org/licenses/gpl.html
|
||||
*
|
||||
* Contributors:
|
||||
* Richard Hirner (bitfire web engineering) - initial API and implementation
|
||||
******************************************************************************/
|
||||
package at.bitfire.davdroid.webdav;
|
||||
|
||||
import org.apache.http.HttpException;
|
||||
|
@ -1,9 +1,12 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2013 Richard Hirner (bitfire web engineering).
|
||||
* Copyright (c) 2014 Richard Hirner (bitfire web engineering).
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the GNU Public License v3.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.gnu.org/licenses/gpl.html
|
||||
*
|
||||
* Contributors:
|
||||
* Richard Hirner (bitfire web engineering) - initial API and implementation
|
||||
******************************************************************************/
|
||||
package at.bitfire.davdroid.webdav;
|
||||
|
||||
|
@ -1,3 +1,13 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2014 Richard Hirner (bitfire web engineering).
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the GNU Public License v3.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.gnu.org/licenses/gpl.html
|
||||
*
|
||||
* Contributors:
|
||||
* Richard Hirner (bitfire web engineering) - initial API and implementation
|
||||
******************************************************************************/
|
||||
package at.bitfire.davdroid.webdav;
|
||||
|
||||
import org.apache.http.client.params.HttpClientParams;
|
||||
|
@ -1,9 +1,12 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2013 Richard Hirner (bitfire web engineering).
|
||||
* Copyright (c) 2014 Richard Hirner (bitfire web engineering).
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the GNU Public License v3.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.gnu.org/licenses/gpl.html
|
||||
*
|
||||
* Contributors:
|
||||
* Richard Hirner (bitfire web engineering) - initial API and implementation
|
||||
******************************************************************************/
|
||||
package at.bitfire.davdroid.webdav;
|
||||
|
||||
|
@ -1,9 +1,12 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2013 Richard Hirner (bitfire web engineering).
|
||||
* Copyright (c) 2014 Richard Hirner (bitfire web engineering).
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the GNU Public License v3.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.gnu.org/licenses/gpl.html
|
||||
*
|
||||
* Contributors:
|
||||
* Richard Hirner (bitfire web engineering) - initial API and implementation
|
||||
******************************************************************************/
|
||||
package at.bitfire.davdroid.webdav;
|
||||
|
||||
|
@ -1,9 +1,12 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2013 Richard Hirner (bitfire web engineering).
|
||||
* Copyright (c) 2014 Richard Hirner (bitfire web engineering).
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the GNU Public License v3.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.gnu.org/licenses/gpl.html
|
||||
*
|
||||
* Contributors:
|
||||
* Richard Hirner (bitfire web engineering) - initial API and implementation
|
||||
******************************************************************************/
|
||||
package at.bitfire.davdroid.webdav;
|
||||
|
||||
|
@ -1,3 +1,13 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2014 Richard Hirner (bitfire web engineering).
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the GNU Public License v3.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.gnu.org/licenses/gpl.html
|
||||
*
|
||||
* Contributors:
|
||||
* Richard Hirner (bitfire web engineering) - initial API and implementation
|
||||
******************************************************************************/
|
||||
package at.bitfire.davdroid.webdav;
|
||||
|
||||
public class DavNoContentException extends DavException {
|
||||
|
@ -1,3 +1,13 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2014 Richard Hirner (bitfire web engineering).
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the GNU Public License v3.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.gnu.org/licenses/gpl.html
|
||||
*
|
||||
* Contributors:
|
||||
* Richard Hirner (bitfire web engineering) - initial API and implementation
|
||||
******************************************************************************/
|
||||
package at.bitfire.davdroid.webdav;
|
||||
|
||||
public class DavNoMultiStatusException extends DavException {
|
||||
|
@ -1,9 +1,12 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2013 Richard Hirner (bitfire web engineering).
|
||||
* Copyright (c) 2014 Richard Hirner (bitfire web engineering).
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the GNU Public License v3.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.gnu.org/licenses/gpl.html
|
||||
*
|
||||
* Contributors:
|
||||
* Richard Hirner (bitfire web engineering) - initial API and implementation
|
||||
******************************************************************************/
|
||||
package at.bitfire.davdroid.webdav;
|
||||
|
||||
|
@ -1,9 +1,12 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2013 Richard Hirner (bitfire web engineering).
|
||||
* Copyright (c) 2014 Richard Hirner (bitfire web engineering).
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the GNU Public License v3.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.gnu.org/licenses/gpl.html
|
||||
*
|
||||
* Contributors:
|
||||
* Richard Hirner (bitfire web engineering) - initial API and implementation
|
||||
******************************************************************************/
|
||||
package at.bitfire.davdroid.webdav;
|
||||
|
||||
|
@ -1,9 +1,12 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2013 Richard Hirner (bitfire web engineering).
|
||||
* Copyright (c) 2014 Richard Hirner (bitfire web engineering).
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the GNU Public License v3.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.gnu.org/licenses/gpl.html
|
||||
*
|
||||
* Contributors:
|
||||
* Richard Hirner (bitfire web engineering) - initial API and implementation
|
||||
******************************************************************************/
|
||||
package at.bitfire.davdroid.webdav;
|
||||
|
||||
|
@ -1,9 +1,12 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2013 Richard Hirner (bitfire web engineering).
|
||||
* Copyright (c) 2014 Richard Hirner (bitfire web engineering).
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the GNU Public License v3.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.gnu.org/licenses/gpl.html
|
||||
*
|
||||
* Contributors:
|
||||
* Richard Hirner (bitfire web engineering) - initial API and implementation
|
||||
******************************************************************************/
|
||||
package at.bitfire.davdroid.webdav;
|
||||
|
||||
|
@ -1,9 +1,12 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2013 Richard Hirner (bitfire web engineering).
|
||||
* Copyright (c) 2014 Richard Hirner (bitfire web engineering).
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the GNU Public License v3.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.gnu.org/licenses/gpl.html
|
||||
*
|
||||
* Contributors:
|
||||
* Richard Hirner (bitfire web engineering) - initial API and implementation
|
||||
******************************************************************************/
|
||||
package at.bitfire.davdroid.webdav;
|
||||
|
||||
|
@ -1,9 +1,12 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2013 Richard Hirner (bitfire web engineering).
|
||||
* Copyright (c) 2014 Richard Hirner (bitfire web engineering).
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the GNU Public License v3.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.gnu.org/licenses/gpl.html
|
||||
*
|
||||
* Contributors:
|
||||
* Richard Hirner (bitfire web engineering) - initial API and implementation
|
||||
******************************************************************************/
|
||||
package at.bitfire.davdroid.webdav;
|
||||
|
||||
|
@ -1,9 +1,12 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2013 Richard Hirner (bitfire web engineering).
|
||||
* Copyright (c) 2014 Richard Hirner (bitfire web engineering).
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the GNU Public License v3.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.gnu.org/licenses/gpl.html
|
||||
*
|
||||
* Contributors:
|
||||
* Richard Hirner (bitfire web engineering) - initial API and implementation
|
||||
******************************************************************************/
|
||||
package at.bitfire.davdroid.webdav;
|
||||
|
||||
|
@ -1,9 +1,12 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2013 Richard Hirner (bitfire web engineering).
|
||||
* Copyright (c) 2014 Richard Hirner (bitfire web engineering).
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the GNU Public License v3.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.gnu.org/licenses/gpl.html
|
||||
*
|
||||
* Contributors:
|
||||
* Richard Hirner (bitfire web engineering) - initial API and implementation
|
||||
******************************************************************************/
|
||||
package at.bitfire.davdroid.webdav;
|
||||
|
||||
|
@ -1,9 +1,12 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2013 Richard Hirner (bitfire web engineering).
|
||||
* Copyright (c) 2014 Richard Hirner (bitfire web engineering).
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the GNU Public License v3.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.gnu.org/licenses/gpl.html
|
||||
*
|
||||
* Contributors:
|
||||
* Richard Hirner (bitfire web engineering) - initial API and implementation
|
||||
******************************************************************************/
|
||||
package at.bitfire.davdroid.webdav;
|
||||
|
||||
|
@ -1,9 +1,12 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2013 Richard Hirner (bitfire web engineering).
|
||||
* Copyright (c) 2014 Richard Hirner (bitfire web engineering).
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the GNU Public License v3.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.gnu.org/licenses/gpl.html
|
||||
*
|
||||
* Contributors:
|
||||
* Richard Hirner (bitfire web engineering) - initial API and implementation
|
||||
******************************************************************************/
|
||||
package at.bitfire.davdroid.webdav;
|
||||
|
||||
|
@ -1,3 +1,13 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2014 Richard Hirner (bitfire web engineering).
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the GNU Public License v3.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.gnu.org/licenses/gpl.html
|
||||
*
|
||||
* Contributors:
|
||||
* Richard Hirner (bitfire web engineering) - initial API and implementation
|
||||
******************************************************************************/
|
||||
package at.bitfire.davdroid.webdav;
|
||||
|
||||
import java.io.IOException;
|
||||
|
@ -1,9 +1,12 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2013 Richard Hirner (bitfire web engineering).
|
||||
* Copyright (c) 2014 Richard Hirner (bitfire web engineering).
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the GNU Public License v3.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.gnu.org/licenses/gpl.html
|
||||
*
|
||||
* Contributors:
|
||||
* Richard Hirner (bitfire web engineering) - initial API and implementation
|
||||
******************************************************************************/
|
||||
package at.bitfire.davdroid.webdav;
|
||||
|
||||
|
@ -1,23 +1,27 @@
|
||||
package at.bitfire.davdroid.test;
|
||||
|
||||
import java.net.URI;
|
||||
|
||||
import android.test.InstrumentationTestCase;
|
||||
import junit.framework.TestCase;
|
||||
import at.bitfire.davdroid.URIUtils;
|
||||
|
||||
public class URIUtilsTest extends InstrumentationTestCase {
|
||||
final static String
|
||||
ROOT_URI = "http://server/",
|
||||
BASE_URI = ROOT_URI + "dir/";
|
||||
URI baseURI;
|
||||
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
baseURI = new URI(BASE_URI);
|
||||
}
|
||||
public class URIUtilsTest extends TestCase {
|
||||
|
||||
public void testSanitize() {
|
||||
// escape "@"
|
||||
assertEquals("https://my%40server/my%40email.com/dir", URIUtils.sanitize("https://my@server/my@email.com/dir"));
|
||||
assertEquals("http://my%40server/my%40email.com/dir", URIUtils.sanitize("http://my@server/my@email.com/dir"));
|
||||
assertEquals("//my%40server/my%40email.com/dir", URIUtils.sanitize("//my@server/my@email.com/dir"));
|
||||
assertEquals("/my%40email.com/dir", URIUtils.sanitize("/my@email.com/dir"));
|
||||
assertEquals("my%3Afile.vcf", URIUtils.sanitize("my:file.vcf"));
|
||||
assertEquals("my%40email.com/dir", URIUtils.sanitize("my@email.com/dir"));
|
||||
|
||||
// escape ":" in path but not as port separator
|
||||
assertEquals("https://www.test.at:80/my%3afile.vcf", URIUtils.sanitize("https://www.test.at:80/my:file.vcf"));
|
||||
assertEquals("http://www.test.at:80/my%3afile.vcf", URIUtils.sanitize("http://www.test.at:80/my:file.vcf"));
|
||||
assertEquals("//www.test.at:80/my%3afile.vcf", URIUtils.sanitize("//www.test.at:80/my:file.vcf"));
|
||||
assertEquals("/my%3afile.vcf", URIUtils.sanitize("/my:file.vcf"));
|
||||
assertEquals("my%3afile.vcf", URIUtils.sanitize("my:file.vcf"));
|
||||
|
||||
// keep literal IPv6 addresses (only in host name)
|
||||
assertEquals("https://[1:2::1]/", URIUtils.sanitize("https://[1:2::1]/"));
|
||||
assertEquals("/%5b1%3a2%3a%3a1%5d/", URIUtils.sanitize("/[1:2::1]/"));
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user