X-Git-Url: http://git.linex4red.de/pub/Android/ownCloud.git/blobdiff_plain/b2dc291653d589178aa230ce6226106e442a8c11..6deca0f9b1f3d3caa8497a89f55e5d3934545fe6:/src/eu/alefzero/owncloud/syncadapter/AbstractOwnCloudSyncAdapter.java?ds=inline diff --git a/src/eu/alefzero/owncloud/syncadapter/AbstractOwnCloudSyncAdapter.java b/src/eu/alefzero/owncloud/syncadapter/AbstractOwnCloudSyncAdapter.java index 524904f3..e4bacf29 100644 --- a/src/eu/alefzero/owncloud/syncadapter/AbstractOwnCloudSyncAdapter.java +++ b/src/eu/alefzero/owncloud/syncadapter/AbstractOwnCloudSyncAdapter.java @@ -1,36 +1,53 @@ -package eu.alefzero.owncloud.syncadapter; - -import java.io.IOException; -import java.net.UnknownHostException; -import java.util.Date; -import java.util.LinkedList; +/* ownCloud Android client application + * Copyright (C) 2011 Bartek Przybylski + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ -import org.apache.http.HttpHost; -import org.apache.http.HttpRequest; -import org.apache.http.HttpResponse; -import org.apache.http.auth.AuthScope; -import org.apache.http.auth.UsernamePasswordCredentials; -import org.apache.http.client.ClientProtocolException; -import org.apache.http.conn.ConnectionKeepAliveStrategy; -import org.apache.http.impl.auth.BasicScheme; -import org.apache.http.impl.client.DefaultHttpClient; -import org.apache.http.protocol.BasicHttpContext; -import org.apache.http.protocol.HttpContext; +package eu.alefzero.owncloud.syncadapter; -import android.accounts.Account; -import android.accounts.AccountManager; -import android.accounts.AuthenticatorException; -import android.accounts.OperationCanceledException; -import android.content.AbstractThreadedSyncAdapter; -import android.content.ContentProviderClient; -import android.content.Context; -import android.net.Uri; -import android.text.TextUtils; -import eu.alefzero.owncloud.authenticator.AccountAuthenticator; -import eu.alefzero.webdav.HttpPropFind; -import eu.alefzero.webdav.TreeNode; -import eu.alefzero.webdav.TreeNode.NodeProperty; -import eu.alefzero.webdav.WebdavUtils; +import java.io.IOException; +import java.net.UnknownHostException; +import java.util.Date; +import java.util.LinkedList; + +import org.apache.http.HttpHost; +import org.apache.http.HttpRequest; +import org.apache.http.HttpResponse; +import org.apache.http.client.ClientProtocolException; +import org.apache.http.conn.ConnectionKeepAliveStrategy; +import org.apache.http.impl.auth.BasicScheme; +import org.apache.http.impl.client.DefaultHttpClient; +import org.apache.http.protocol.BasicHttpContext; +import org.apache.http.protocol.HttpContext; + +import android.accounts.Account; +import android.accounts.AccountManager; +import android.accounts.AuthenticatorException; +import android.accounts.OperationCanceledException; +import android.content.AbstractThreadedSyncAdapter; +import android.content.ContentProviderClient; +import android.content.Context; +import android.net.Uri; +import android.text.TextUtils; +import eu.alefzero.owncloud.authenticator.AccountAuthenticator; +import eu.alefzero.webdav.HttpPropFind; +import eu.alefzero.webdav.TreeNode; +import eu.alefzero.webdav.WebdavClient; +import eu.alefzero.webdav.WebdavUtils; +import eu.alefzero.webdav.TreeNode.NodeProperty; /** * Base SyncAdapter for OwnCloud @@ -46,8 +63,8 @@ public abstract class AbstractOwnCloudSyncAdapter extends AbstractThreadedSyncAd private ContentProviderClient contentProvider; private Date lastUpdated; - private DefaultHttpClient client = null; - private HttpHost host; + private HttpHost mHost; + private WebdavClient mClient = null; public AbstractOwnCloudSyncAdapter(Context context, boolean autoInitialize) { super(context, autoInitialize); @@ -109,7 +126,7 @@ public abstract class AbstractOwnCloudSyncAdapter extends AbstractThreadedSyncAd BasicScheme basicAuth = new BasicScheme(); httpContext.setAttribute("preemptive-auth", basicAuth); - HttpResponse response = getClient().execute(this.host, query, httpContext); + HttpResponse response = getClient().execute(mHost, query, httpContext); return response; } @@ -118,7 +135,7 @@ public abstract class AbstractOwnCloudSyncAdapter extends AbstractThreadedSyncAd TreeNode root = new TreeNode(); root.setProperty(TreeNode.NodeProperty.NAME, "/"); - this.parseResponse(response, getUri(), getClient(), this.host, root.getChildList()); + this.parseResponse(response, getUri(), getClient(), mHost, root.getChildList()); return root; } @@ -127,7 +144,7 @@ public abstract class AbstractOwnCloudSyncAdapter extends AbstractThreadedSyncAd } private DefaultHttpClient getClient() throws OperationCanceledException, AuthenticatorException, IOException { - if(this.client == null) { + if(mClient == null) { String username = getAccount().name.split("@")[0]; String password = this.getAccountManager().blockingGetAuthToken(getAccount(), AccountAuthenticator.AUTH_TOKEN_TYPE, true); if (this.getAccountManager().getUserData(getAccount(), AccountAuthenticator.KEY_OC_URL) == null) { @@ -135,17 +152,13 @@ public abstract class AbstractOwnCloudSyncAdapter extends AbstractThreadedSyncAd } Uri uri = getUri(); - int port = (uri.getPort() == -1) ? 80 : uri.getPort(); - this.client = new DefaultHttpClient(); - this.client.getCredentialsProvider().setCredentials( - new AuthScope(uri.getHost(), port), - new UsernamePasswordCredentials(username, password) - ); - this.client.setKeepAliveStrategy(this.getKeepAliveStrategy()); - this.host = new HttpHost(uri.getHost(), port, (uri.getScheme() == "https") ? "https" : "http"); + mClient = new WebdavClient(uri); + mClient.setCredentials(username, password); + mClient.allowUnsignedCertificates(); + mHost = mClient.getTargetHost(); } - return this.client; + return mClient.getHttpClient(); } private void parseResponse(HttpResponse resp, Uri uri, DefaultHttpClient client, HttpHost targetHost, LinkedList insertList) throws IOException, OperationCanceledException, AuthenticatorException { @@ -167,5 +180,4 @@ public abstract class AbstractOwnCloudSyncAdapter extends AbstractThreadedSyncAd } } } - } \ No newline at end of file