Sign Up
Log In
Log In
or
Sign Up
Places
All Projects
Status Monitor
Collapse sidebar
home:p_conrad
upm
upm-webdav.patch
Overview
Repositories
Revisions
Requests
Users
Attributes
Meta
File upm-webdav.patch of Package upm
diff -rNU3 upm-src-1.14.orig/src/com/_17od/upm/gui/DatabaseActions.java upm-src-1.14/src/com/_17od/upm/gui/DatabaseActions.java --- upm-src-1.14.orig/src/com/_17od/upm/gui/DatabaseActions.java 2013-04-12 21:34:54.000000000 +0200 +++ upm-src-1.14/src/com/_17od/upm/gui/DatabaseActions.java 2013-04-30 16:01:12.000000000 +0200 @@ -29,7 +29,7 @@ import java.awt.event.WindowFocusListener; import java.io.File; import java.io.IOException; -import java.net.URL; + import java.util.ArrayList; import java.util.Arrays; @@ -692,7 +692,7 @@ if (saveDatabaseTo != null) { // Download the database - Transport transport = Transport.getTransportForURL(new URL(remoteLocation)); + Transport transport = Transport.getTransportForURL(remoteLocation); File downloadedDatabaseFile = transport.getRemoteFile(remoteLocation, username, password); // Delete the file is it already exists @@ -824,7 +824,7 @@ } // Download the database that's already at the remote location - Transport transport = Transport.getTransportForURL(new URL(remoteLocation)); + Transport transport = Transport.getTransportForURL(remoteLocation); File remoteDatabaseFile = transport.getRemoteFile(remoteLocation, database.getDatabaseFile().getName(), httpUsername, httpPassword); // Attempt to decrypt the database using the password the user entered diff -rNU3 upm-src-1.11.orig/src/com/_17od/upm/gui/DatabasePropertiesDialog.java upm-src-1.11/src/com/_17od/upm/gui/DatabasePropertiesDialog.java --- upm-src-1.11.orig/src/com/_17od/upm/gui/DatabasePropertiesDialog.java 2013-04-12 21:34:54.000000000 +0200 +++ upm-src-1.11/src/com/_17od/upm/gui/DatabasePropertiesDialog.java 2013-04-30 16:01:12.000000000 +0200 @@ -162,15 +162,17 @@ } - private URL validateURL(String urlString) { - URL url = null; try { - url = new URL(urlString); + if (urlString.startsWith("webdav:") + || urlString.startsWith("webdavs:")) { + return new URL("http" + urlString.substring(6)); + } + return new URL(urlString); } catch (MalformedURLException e) { // If we got here the the URL is invalid + return null; } - return url; } @@ -201,7 +203,7 @@ // If the remote location has changed then upload the database if (!database.getDbOptions().getRemoteLocation().equals(remoteLocation)) { try { - Transport transport = Transport.getTransportForURL(url); + Transport transport = Transport.getTransportForURL(remoteLocation); if (!authEntry.equals("")) { String userId = database.getAccount(authEntry).getUserId(); String password = database.getAccount(authEntry).getPassword(); diff -rNU3 upm-src-1.11.orig/src/com/_17od/upm/transport/HTTPTransport.java upm-src-1.11/src/com/_17od/upm/transport/HTTPTransport.java --- upm-src-1.11.orig/src/com/_17od/upm/transport/HTTPTransport.java 2013-04-12 21:34:54.000000000 +0200 +++ upm-src-1.11/src/com/_17od/upm/transport/HTTPTransport.java 2013-04-30 16:01:12.000000000 +0200 @@ -32,6 +32,7 @@ import org.apache.commons.httpclient.HttpClient; import org.apache.commons.httpclient.HttpException; import org.apache.commons.httpclient.HttpStatus; +import org.apache.commons.httpclient.MultiThreadedHttpConnectionManager; import org.apache.commons.httpclient.UsernamePasswordCredentials; import org.apache.commons.httpclient.auth.AuthScope; import org.apache.commons.httpclient.methods.GetMethod; @@ -45,12 +46,11 @@ public class HTTPTransport extends Transport { - private HttpClient client; + protected HttpClient client; public HTTPTransport() { - - client = new HttpClient(); + client = new HttpClient(new MultiThreadedHttpConnectionManager()); Boolean acceptSelfSignedCerts = new Boolean(Preferences.get( @@ -270,7 +270,7 @@ } - private String addTrailingSlash(String url) { + protected static String addTrailingSlash(String url) { if (url.charAt(url.length() - 1) != '/') { url = url + '/'; } @@ -278,7 +278,7 @@ } - private boolean isNotEmpty(String stringToCheck) { + protected static boolean isNotEmpty(String stringToCheck) { boolean retVal = false; if (stringToCheck != null && !stringToCheck.trim().equals("")) { retVal = true; diff -rNU3 upm-src-1.11.orig/src/com/_17od/upm/transport/Transport.java upm-src-1.11/src/com/_17od/upm/transport/Transport.java --- upm-src-1.11.orig/src/com/_17od/upm/transport/Transport.java 2013-04-12 21:34:54.000000000 +0200 +++ upm-src-1.11/src/com/_17od/upm/transport/Transport.java 2013-04-30 16:01:12.000000000 +0200 @@ -22,6 +22,7 @@ import java.io.File; import java.net.URL; +import java.util.Locale; /** @@ -52,14 +53,15 @@ public abstract File getRemoteFile(String remoteLocation, String username, String password) throws TransportException; - public static Transport getTransportForURL(URL url) { - Transport retVal = null; - if (url.getProtocol().equals("http")) { - retVal = new HTTPTransport(); - } else if (url.getProtocol().equals("https")) { - retVal = new HTTPTransport(); + public static Transport getTransportForURL(String url) { + String lowerUrl = url.toLowerCase(Locale.getDefault()); + if (lowerUrl.startsWith("http:") || lowerUrl.startsWith("https:")) { + return new HTTPTransport(); } - return retVal; + if (lowerUrl.startsWith("webdav:") || lowerUrl.startsWith("webdavs:")) { + return new WebdavTransport(); + } + return null; } public static boolean isASupportedProtocol(String protocol) { @@ -70,6 +72,8 @@ supported = true; } else if (protocol.equals("file")) { supported = true; + } else if (protocol.equals("webdav") || protocol.equals("webdavs")) { + supported = true; } return supported; } diff -rNU3 upm-src-1.11.orig/src/com/_17od/upm/transport/WebdavTransport.java upm-src-1.11/src/com/_17od/upm/transport/WebdavTransport.java --- upm-src-1.11.orig/src/com/_17od/upm/transport/WebdavTransport.java 1970-01-01 01:00:00.000000000 +0100 +++ upm-src-1.11/src/com/_17od/upm/transport/WebdavTransport.java 2013-04-30 16:01:12.000000000 +0200 @@ -0,0 +1,184 @@ +/* + * (C) 2013 Peter Conrad <conrad@quisquis.de> + * + * This file is part of Universal Password Manager. + * + * Universal Password Manager 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 2 of the License, or + * (at your option) any later version. + * + * Universal Password Manager 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 Universal Password Manager; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ +package com._17od.upm.transport; + +import java.io.ByteArrayOutputStream; +import java.io.File; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.io.InputStream; + +import java.net.MalformedURLException; + +import org.apache.commons.httpclient.HostConfiguration; +import org.apache.commons.httpclient.HttpClient; +import org.apache.commons.httpclient.HttpURL; +import org.apache.commons.httpclient.HttpException; +import org.apache.commons.httpclient.HttpsURL; +import org.apache.commons.httpclient.UsernamePasswordCredentials; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +import org.apache.webdav.lib.WebdavResource; + +/** + * + * @author Peter Conrad + */ +public class WebdavTransport extends HTTPTransport { + private static class MyDavResource extends WebdavResource { + private HostConfiguration hostConfig; + + private MyDavResource(HttpClient httpClient) { + super(httpClient); + hostConfig = httpClient.getHostConfiguration(); + } + + public void setHttpURL(String url) throws HttpException, IOException { + HttpURL httpUrl; + if (url.startsWith("webdavs")) { + httpUrl = new HttpsURL("http" + url.substring(6)); + } else if (url.startsWith("webdav")) { + httpUrl = new HttpURL("http" + url.substring(6)); + } else if (url.startsWith("https")) { + httpUrl = new HttpsURL(url); + } else { + httpUrl = new HttpURL(url); + } + if (hostCredentials != null) { + UsernamePasswordCredentials cred = (UsernamePasswordCredentials) hostCredentials; + httpUrl.setUserinfo(cred.getUserName(), cred.getPassword()); + } + if (hostConfig != null) { // avoid "host parameter is null" + hostConfig.setHost(httpUrl.getHost()); + } + setHttpURL(httpUrl); + } + } + + private static Log log = LogFactory.getLog(WebdavTransport.class); + + private WebdavResource open() throws TransportException { + return new MyDavResource(client); + } + + public void put(String targetLocation, File file, + String username, String password) throws TransportException { + log.info("Webdav.put('" + targetLocation + "', '" + file.getPath() + + "', " + (username != null ? "'" + username + "'" : "null") + + ", ...)"); + WebdavResource davRes = open(); + try { + if (username != null) { + davRes.setCredentials(new UsernamePasswordCredentials(username, password)); + } + davRes.setHttpURL(addTrailingSlash(targetLocation) + file.getName()); + if (!davRes.putMethod(file)) { + throw new TransportException("There's been some kind of problem uploading a file to the WebDAV server."); + } + } catch (FileNotFoundException e) { + throw new TransportException(e); + } catch (MalformedURLException e) { + throw new TransportException(e); + } catch (HttpException e) { + throw new TransportException(e); + } catch (IOException e) { + throw new TransportException(e); + } finally { + try { + davRes.close(); + } catch (IOException ignore) {} + } + } + + public byte[] get(String url, String username, String password) + throws TransportException { + log.info("Webdav.get('" + url + "', " + + (username != null ? "'" + username + "'" : "null") + + ", ...)"); + ByteArrayOutputStream buffer = new ByteArrayOutputStream(); + WebdavResource davRes = open(); + try { + if (username != null) { + davRes.setCredentials(new UsernamePasswordCredentials(username, password)); + } + davRes.setHttpURL(url); + if (davRes.isCollection()) { + throw new TransportException("URL is a collection!"); + } + byte buf[] = new byte[1024]; + int c; + InputStream is = davRes.getMethodData(); + try { + do { + c = is.read(buf); + if (c > 0) { + buffer.write(buf, 0, c); + } + } while (c >= 0); + } finally { + is.close(); + } + } catch (FileNotFoundException e) { + throw new TransportException(e); + } catch (MalformedURLException e) { + throw new TransportException(e); + } catch (HttpException e) { + throw new TransportException(e); + } catch (IOException e) { + throw new TransportException(e); + } finally { + try { + davRes.close(); + } catch (IOException ignore) {} + } + return buffer.toByteArray(); + } + + public void delete(String targetLocation, String name, + String username, String password) throws TransportException { + /* delete is only ever called right before put, so it isn't useful. Skip it. + log.info("Webdav.delete('" + targetLocation + "', '" + name + + "', " + (username != null ? "'" + username + "'" : "null") + + ", ...)"); + WebdavResource davRes = open(); + try { + if (username != null) { + davRes.setCredentials(new UsernamePasswordCredentials(username, password)); + } + davRes.setHttpURL(addTrailingSlash(targetLocation) + name); + davRes.deleteMethod(); + } catch (FileNotFoundException e) { + throw new TransportException(e); + } catch (MalformedURLException e) { + throw new TransportException(e); + } catch (HttpException e) { + throw new TransportException(e); + } catch (IOException e) { + throw new TransportException(e); + } finally { + try { + davRes.close(); + } catch (IOException ignore) {} + } + */ + } +}
Locations
Projects
Search
Status Monitor
Help
OpenBuildService.org
Documentation
API Documentation
Code of Conduct
Contact
Support
@OBShq
Terms
openSUSE Build Service is sponsored by
The Open Build Service is an
openSUSE project
.
Sign Up
Log In
Places
Places
All Projects
Status Monitor