Browse Source

Support for new style Xirvik shared servers.

pull/11/head
Eric Kok 13 years ago
parent
commit
23c7adb9f1
  1. 2
      android/AndroidManifest.xml
  2. 2
      android/project.properties
  3. 4
      android/res/values/arrays.xml
  4. 3
      android/res/values/strings.xml
  5. 297
      android/src/com/xirvik/transdroid/preferences/PreferencesXirvikServer.java
  6. 6
      android/src/com/xirvik/transdroid/preferences/XirvikServerType.java
  7. 39
      android/src/com/xirvik/transdroid/preferences/XirvikSettings.java
  8. 5
      android/src/org/transdroid/preferences/Preferences.java
  9. 2
      lib/src/org/transdroid/daemon/Rtorrent/RtorrentAdapter.java
  10. 34
      lib/src/org/transdroid/daemon/util/HttpHelper.java

2
android/AndroidManifest.xml

@ -22,7 +22,7 @@ @@ -22,7 +22,7 @@
android:versionCode="145"
android:installLocation="auto">
<uses-sdk android:minSdkVersion="4" android:targetSdkVersion="13" />
<uses-sdk android:minSdkVersion="4" android:targetSdkVersion="14" />
<supports-screens smallScreens="true" normalScreens="true" largeScreens="true" xlargeScreens="true" android:anyDensity="true" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />

2
android/project.properties

@ -10,6 +10,6 @@ @@ -10,6 +10,6 @@
# Indicates whether an apk should be generated for each density.
split.density=false
# Project target.
target=android-13
target=android-14
apk-configurations=
android.library.reference.1=../external/JakeWharton-ActionBarSherlock/library

4
android/res/values/arrays.xml

@ -43,12 +43,14 @@ @@ -43,12 +43,14 @@
</string-array>
<string-array name="pref_xirvik_types">
<item>Shared</item>
<item>Shared (Torrentflux)</item>
<item>Shared (rTorrent)</item>
<item>Semi-dedicated</item>
<item>Dedicated</item>
</string-array>
<string-array name="pref_xirvik_values">
<item>type_shared</item>
<item>type_sharedrt</item>
<item>type_semi</item>
<item>type_dedicated</item>
</string-array>

3
android/res/values/strings.xml

@ -363,7 +363,10 @@ @@ -363,7 +363,10 @@
<string name="xirvik_pref_type_info">Shared, semi- or dedicated</string>
<string name="xirvik_pref_server">Server name</string>
<string name="xirvik_pref_server_info">Like dedi000.xirvik.com</string>
<string name="xirvik_pref_folder">SCGI mount</string>
<string name="xirvik_pref_setautomatically">Set automatically</string>
<string name="xirvik_error_invalid_servername">Invalid server (use the full host name, like dedi000.xirvik.com)</string>
<string name="xirvik_error_nofolder">Cannot retrieve the Xirvik SCGI folder setting; please try again later ro correct your server name setting</string>
<string name="seedm8_info">SeedM8 offers unmetered GBit seedbox hosting. Transdroid provides easy setup for SeedM8 servers.\n\nRead more at www.seedm8.com</string>
<string name="seedm8_add_new_xserver">Add SeedM8 server</string>

297
android/src/com/xirvik/transdroid/preferences/PreferencesXirvikServer.java

@ -15,15 +15,26 @@ @@ -15,15 +15,26 @@
* along with Transdroid. If not, see <http://www.gnu.org/licenses/>.
*
*/
package com.xirvik.transdroid.preferences;
package com.xirvik.transdroid.preferences;
import java.io.IOException;
import java.io.InputStream;
import org.apache.http.HttpResponse;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;
import org.transdroid.R;
import org.transdroid.daemon.DaemonException;
import org.transdroid.daemon.util.HttpHelper;
import org.transdroid.preferences.Preferences;
import org.transdroid.preferences.TransdroidCheckBoxPreference;
import org.transdroid.preferences.TransdroidEditTextPreference;
import org.transdroid.preferences.TransdroidListPreference;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.os.AsyncTask;
import android.os.Bundle;
import android.preference.Preference;
import android.preference.PreferenceActivity;
@ -39,7 +50,7 @@ import android.widget.Toast; @@ -39,7 +50,7 @@ import android.widget.Toast;
public class PreferencesXirvikServer extends PreferenceActivity {
public static final String PREFERENCES_XSERVER_KEY = "PREFERENCES_XSERVER_POSTFIX";
/*public static final String[] validAddressStart = { "dedi", "semi" };*/
/* public static final String[] validAddressStart = { "dedi", "semi" }; */
public static final String[] validAddressEnding = { ".xirvik.com", ".xirvik.net" };
private String serverPostfix;
@ -47,6 +58,7 @@ public class PreferencesXirvikServer extends PreferenceActivity { @@ -47,6 +58,7 @@ public class PreferencesXirvikServer extends PreferenceActivity {
private TransdroidEditTextPreference name;
private TransdroidListPreference type;
private TransdroidEditTextPreference server;
private TransdroidEditTextPreference folder;
private TransdroidEditTextPreference user;
private TransdroidEditTextPreference pass;
private TransdroidCheckBoxPreference alarmFinished;
@ -55,94 +67,104 @@ public class PreferencesXirvikServer extends PreferenceActivity { @@ -55,94 +67,104 @@ public class PreferencesXirvikServer extends PreferenceActivity {
private String nameValue = null;
private String typeValue = null;
private String serverValue = null;
private String folderValue = null;
private String userValue = null;
//private String passValue = null;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// For which server?
serverPostfix = getIntent().getStringExtra(PREFERENCES_XSERVER_KEY);
// Create the preferences screen here: this takes care of saving/loading, but also contains the ListView adapter, etc.
setPreferenceScreen(getPreferenceManager().createPreferenceScreen(this));
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
nameValue = prefs.getString(Preferences.KEY_PREF_XNAME + serverPostfix, null);
typeValue = prefs.getString(Preferences.KEY_PREF_XTYPE + serverPostfix, null);
serverValue = prefs.getString(Preferences.KEY_PREF_XSERVER + serverPostfix, null);
userValue = prefs.getString(Preferences.KEY_PREF_XUSER + serverPostfix, null);
//passValue = prefs.getString(Preferences.KEY_PREF_XPASS + serverPostfix, null);
// Create preference objects
getPreferenceScreen().setTitle(R.string.xirvik_pref_title);
// Name
name = new TransdroidEditTextPreference(this);
name.setTitle(R.string.pref_name);
name.setKey(Preferences.KEY_PREF_XNAME + serverPostfix);
name.getEditText().setSingleLine();
name.setDialogTitle(R.string.pref_name);
name.setOnPreferenceChangeListener(updateHandler);
getPreferenceScreen().addItemFromInflater(name);
// Type
type = new TransdroidListPreference(this);
type.setTitle(R.string.xirvik_pref_type);
type.setKey(Preferences.KEY_PREF_XTYPE + serverPostfix);
type.setEntries(R.array.pref_xirvik_types);
type.setEntryValues(R.array.pref_xirvik_values);
type.setDialogTitle(R.string.xirvik_pref_type);
type.setOnPreferenceChangeListener(updateHandler);
getPreferenceScreen().addItemFromInflater(type);
// Server
server = new TransdroidEditTextPreference(this);
server.setTitle(R.string.xirvik_pref_server);
server.setKey(Preferences.KEY_PREF_XSERVER + serverPostfix);
server.getEditText().setSingleLine();
server.getEditText().setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_URI);
server.setDialogTitle(R.string.xirvik_pref_server);
server.setOnPreferenceChangeListener(updateHandler);
getPreferenceScreen().addItemFromInflater(server);
// User
user = new TransdroidEditTextPreference(this);
user.setTitle(R.string.pref_user);
user.setKey(Preferences.KEY_PREF_XUSER + serverPostfix);
user.getEditText().setSingleLine();
user.getEditText().setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_FILTER);
user.setDialogTitle(R.string.pref_user);
user.setOnPreferenceChangeListener(updateHandler);
getPreferenceScreen().addItemFromInflater(user);
// Pass
pass = new TransdroidEditTextPreference(this);
pass.setTitle(R.string.pref_pass);
pass.setKey(Preferences.KEY_PREF_XPASS + serverPostfix);
pass.getEditText().setSingleLine();
pass.getEditText().setInputType(EditorInfo.TYPE_TEXT_VARIATION_PASSWORD);
pass.getEditText().setTransformationMethod(new PasswordTransformationMethod());
pass.setDialogTitle(R.string.pref_pass);
pass.setOnPreferenceChangeListener(updateHandler);
getPreferenceScreen().addItemFromInflater(pass);
// AlertFinished
alarmFinished = new TransdroidCheckBoxPreference(this);
alarmFinished.setDefaultValue(true);
alarmFinished.setTitle(R.string.pref_alarmfinished);
alarmFinished.setSummary(R.string.pref_alarmfinished_info);
alarmFinished.setKey(Preferences.KEY_PREF_XALARMFINISHED + serverPostfix);
alarmFinished.setOnPreferenceChangeListener(updateHandler);
getPreferenceScreen().addItemFromInflater(alarmFinished);
// AlertNew
alarmNew = new TransdroidCheckBoxPreference(this);
alarmNew.setTitle(R.string.pref_alarmnew);
alarmNew.setSummary(R.string.pref_alarmnew_info);
alarmNew.setKey(Preferences.KEY_PREF_XALARMNEW + serverPostfix);
alarmNew.setOnPreferenceChangeListener(updateHandler);
getPreferenceScreen().addItemFromInflater(alarmNew);
updateDescriptionTexts();
}
private OnPreferenceChangeListener updateHandler = new OnPreferenceChangeListener() {
private String passValue = null;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// For which server?
serverPostfix = getIntent().getStringExtra(PREFERENCES_XSERVER_KEY);
// Create the preferences screen here: this takes care of saving/loading, but also contains the
// ListView adapter, etc.
setPreferenceScreen(getPreferenceManager().createPreferenceScreen(this));
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
nameValue = prefs.getString(Preferences.KEY_PREF_XNAME + serverPostfix, null);
typeValue = prefs.getString(Preferences.KEY_PREF_XTYPE + serverPostfix, null);
serverValue = prefs.getString(Preferences.KEY_PREF_XSERVER + serverPostfix, null);
folderValue = prefs.getString(Preferences.KEY_PREF_XFOLDER + serverPostfix, null);
userValue = prefs.getString(Preferences.KEY_PREF_XUSER + serverPostfix, null);
passValue = prefs.getString(Preferences.KEY_PREF_XPASS + serverPostfix, null);
// Create preference objects
getPreferenceScreen().setTitle(R.string.xirvik_pref_title);
// Name
name = new TransdroidEditTextPreference(this);
name.setTitle(R.string.pref_name);
name.setKey(Preferences.KEY_PREF_XNAME + serverPostfix);
name.getEditText().setSingleLine();
name.setDialogTitle(R.string.pref_name);
name.setOnPreferenceChangeListener(updateHandler);
getPreferenceScreen().addItemFromInflater(name);
// Type
type = new TransdroidListPreference(this);
type.setTitle(R.string.xirvik_pref_type);
type.setKey(Preferences.KEY_PREF_XTYPE + serverPostfix);
type.setEntries(R.array.pref_xirvik_types);
type.setEntryValues(R.array.pref_xirvik_values);
type.setDialogTitle(R.string.xirvik_pref_type);
type.setOnPreferenceChangeListener(updateHandler);
getPreferenceScreen().addItemFromInflater(type);
// Server
server = new TransdroidEditTextPreference(this);
server.setTitle(R.string.xirvik_pref_server);
server.setKey(Preferences.KEY_PREF_XSERVER + serverPostfix);
server.getEditText().setSingleLine();
server.getEditText().setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_URI);
server.setDialogTitle(R.string.xirvik_pref_server);
server.setOnPreferenceChangeListener(updateHandler);
getPreferenceScreen().addItemFromInflater(server);
// Folder
folder = new TransdroidEditTextPreference(this);
folder.setTitle(R.string.xirvik_pref_folder);
folder.setKey(Preferences.KEY_PREF_XFOLDER + serverPostfix);
folder.setEnabled(false);
folder.setSummary(R.string.xirvik_pref_setautomatically);
getPreferenceScreen().addItemFromInflater(folder);
// User
user = new TransdroidEditTextPreference(this);
user.setTitle(R.string.pref_user);
user.setKey(Preferences.KEY_PREF_XUSER + serverPostfix);
user.getEditText().setSingleLine();
user.getEditText().setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_FILTER);
user.setDialogTitle(R.string.pref_user);
user.setOnPreferenceChangeListener(updateHandler);
getPreferenceScreen().addItemFromInflater(user);
// Pass
pass = new TransdroidEditTextPreference(this);
pass.setTitle(R.string.pref_pass);
pass.setKey(Preferences.KEY_PREF_XPASS + serverPostfix);
pass.getEditText().setSingleLine();
pass.getEditText().setInputType(EditorInfo.TYPE_TEXT_VARIATION_PASSWORD);
pass.getEditText().setTransformationMethod(new PasswordTransformationMethod());
pass.setDialogTitle(R.string.pref_pass);
pass.setOnPreferenceChangeListener(updateHandler);
getPreferenceScreen().addItemFromInflater(pass);
// AlertFinished
alarmFinished = new TransdroidCheckBoxPreference(this);
alarmFinished.setDefaultValue(true);
alarmFinished.setTitle(R.string.pref_alarmfinished);
alarmFinished.setSummary(R.string.pref_alarmfinished_info);
alarmFinished.setKey(Preferences.KEY_PREF_XALARMFINISHED + serverPostfix);
alarmFinished.setOnPreferenceChangeListener(updateHandler);
getPreferenceScreen().addItemFromInflater(alarmFinished);
// AlertNew
alarmNew = new TransdroidCheckBoxPreference(this);
alarmNew.setTitle(R.string.pref_alarmnew);
alarmNew.setSummary(R.string.pref_alarmnew_info);
alarmNew.setKey(Preferences.KEY_PREF_XALARMNEW + serverPostfix);
alarmNew.setOnPreferenceChangeListener(updateHandler);
getPreferenceScreen().addItemFromInflater(alarmNew);
updateDescriptionTexts();
}
private OnPreferenceChangeListener updateHandler = new OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
if (preference == name) {
@ -158,48 +180,107 @@ public class PreferencesXirvikServer extends PreferenceActivity { @@ -158,48 +180,107 @@ public class PreferencesXirvikServer extends PreferenceActivity {
validEnd |= newServer.endsWith(validAddressEnding[i]);
}
if (!valid || !validEnd) {
Toast.makeText(getApplicationContext(), R.string.xirvik_error_invalid_servername, Toast.LENGTH_LONG).show();
Toast
.makeText(getApplicationContext(), R.string.xirvik_error_invalid_servername, Toast.LENGTH_LONG)
.show();
return false;
}
serverValue = newServer;
} else if (preference == user) {
userValue = (String) newValue;
} else if (preference == pass) {
//passValue = (String) newValue;
passValue = (String) newValue;
}
updateDescriptionTexts();
updateScgiMountFolder();
// Set the value as usual
return true;
}
};
};
@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
// Perform click action, which always is a Preference
Preference item = (Preference) getListAdapter().getItem(position);
// Perform click action, which always is a Preference
Preference item = (Preference) getListAdapter().getItem(position);
// Let the Preference open the right dialog
if (item instanceof TransdroidListPreference) {
((TransdroidListPreference)item).click();
((TransdroidListPreference) item).click();
} else if (item instanceof TransdroidCheckBoxPreference) {
((TransdroidCheckBoxPreference)item).click();
((TransdroidCheckBoxPreference) item).click();
} else if (item instanceof TransdroidEditTextPreference) {
((TransdroidEditTextPreference)item).click();
if (((TransdroidEditTextPreference) item).isEnabled()) {
((TransdroidEditTextPreference) item).click();
}
}
}
private void updateScgiMountFolder() {
if (typeValue != null && XirvikServerType.fromCode(typeValue) == XirvikServerType.SharedRtorrent) {
new AsyncTask<Void, Void, String>() {
@Override
protected String doInBackground(Void... params) {
try {
// Get, from the server, the RPC SCGI mount address
DefaultHttpClient httpclient = HttpHelper.createStandardHttpClient(true, userValue, passValue,
true, null, HttpHelper.DEFAULT_CONNECTION_TIMEOUT, serverValue, 443);
String url = "https://" + serverValue + ":443/browsers_addons/transdroid_autoconf.txt";
HttpResponse request = httpclient.execute(new HttpGet(url));
InputStream stream = request.getEntity().getContent();
String folderVal = HttpHelper.ConvertStreamToString(stream).trim();
if (folderVal.startsWith("<?xml")) {
folderVal = null;
}
stream.close();
return folderVal;
} catch (DaemonException e) {
} catch (ClientProtocolException e) {
} catch (IOException e) {
}
return null;
}
@Override
protected void onPostExecute(String result) {
storeScgiMountFolder(result);
}
}.execute();
} else {
// No need to retrieve this value
storeScgiMountFolder(XirvikSettings.RTORRENT_FOLDER);
}
}
protected void storeScgiMountFolder(String result) {
if (result == null) {
// The RPC SCGI mount folder address couldn't be retrieved, so we cannot continue: show an error
Toast.makeText(getApplicationContext(), R.string.xirvik_error_nofolder, Toast.LENGTH_LONG).show();
folder.setSummary(R.string.xirvik_error_nofolder);
result = "";
}
}
// Store the new folder setting
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
Editor edit = prefs.edit();
edit.putString(Preferences.KEY_PREF_XFOLDER + serverPostfix, result);
edit.commit();
folderValue = result;
updateDescriptionTexts();
}
private void updateDescriptionTexts() {
private void updateDescriptionTexts() {
// Update the 'summary' labels of all preferences to show their current value
XirvikServerType typeType = XirvikServerType.fromCode(typeValue);
// Update the 'summary' labels of all preferences to show their current value
XirvikServerType typeType = XirvikServerType.fromCode(typeValue);
name.setSummary(nameValue == null? getText(R.string.pref_name_info): nameValue);
type.setSummary(typeType == null? getText(R.string.xirvik_pref_type_info): typeType.toString());
server.setSummary(serverValue == null? getText(R.string.xirvik_pref_server_info): serverValue);
user.setSummary(userValue == null? "": userValue);
name.setSummary(nameValue == null ? getText(R.string.pref_name_info) : nameValue);
type.setSummary(typeType == null ? getText(R.string.xirvik_pref_type_info) : typeType.toString());
server.setSummary(serverValue == null ? getText(R.string.xirvik_pref_server_info) : serverValue);
user.setSummary(userValue == null ? "" : userValue);
folder.setSummary(folderValue == null ? "" : folderValue);
}
}
}

6
android/src/com/xirvik/transdroid/preferences/XirvikServerType.java

@ -8,7 +8,8 @@ public enum XirvikServerType { @@ -8,7 +8,8 @@ public enum XirvikServerType {
Dedicated (1),
SemiDedicated (2),
Shared (3);
Shared (3),
SharedRtorrent (4);
private int code;
private static final Map<Integer,XirvikServerType> lookup = new HashMap<Integer,XirvikServerType>();
@ -48,6 +49,9 @@ public enum XirvikServerType { @@ -48,6 +49,9 @@ public enum XirvikServerType {
if (code.equals("type_shared")) {
return Shared;
}
if (code.equals("type_sharedrt")) {
return SharedRtorrent;
}
return null;
}
}

39
android/src/com/xirvik/transdroid/preferences/XirvikSettings.java

@ -16,25 +16,26 @@ public class XirvikSettings { @@ -16,25 +16,26 @@ public class XirvikSettings {
private static final int TFB4RT_PORT = 443;
private static final String TFB4RT_FOLDER = "/tfx";
private static final int RTORRENT_PORT = 443;
private static final String RTORRENT_FOLDER_DEDI = "/RPC2";
private static final String RTORRENT_FOLDER_SEMI = "/RPC2";
public static final String RTORRENT_FOLDER = "/RPC2";
private static final int UTORRENT_PORT = 5010;
final private String name;
final private XirvikServerType type;
final private String server;
final private String folder;
final private String username;
final private String password;
final private boolean alarmOnFinishedDownload;
final private boolean alarmOnNewTorrent;
final private String idString;
public XirvikSettings(String name, XirvikServerType type, String server, String username,
public XirvikSettings(String name, XirvikServerType type, String server, String folder, String username,
String password, boolean alarmOnFinishedDownload, boolean alarmOnNewTorrent,
String idString) {
this.name = name;
this.type = type;
this.server = server;
this.folder = folder;
this.username = username;
this.password = password;
this.alarmOnFinishedDownload = alarmOnFinishedDownload;
@ -51,6 +52,9 @@ public class XirvikSettings { @@ -51,6 +52,9 @@ public class XirvikSettings {
public String getServer() {
return server;
}
public String getFolder() {
return folder;
}
public String getUsername() {
return username;
}
@ -94,13 +98,13 @@ public class XirvikSettings { @@ -94,13 +98,13 @@ public class XirvikSettings {
getPassword(), HttpHelper.DEFAULT_CONNECTION_TIMEOUT, shouldAlarmOnFinishedDownload(),
shouldAlarmOnNewTorrent(), "" + startID++, true));
}
if (getType() == XirvikServerType.SemiDedicated || isDedi) {
if (getType() == XirvikServerType.SharedRtorrent || getType() == XirvikServerType.SemiDedicated || isDedi) {
daemons.add(
new DaemonSettings(
getName() + (isDedi? " rTorrent": ""),
Daemon.rTorrent, getServer(), RTORRENT_PORT,
true, true, null,
(isDedi? RTORRENT_FOLDER_DEDI: getSemiFoldername()), true, getUsername(), getPassword(),
getFolder(), true, getUsername(), getPassword(),
OS.Linux, "/", "ftp://" + getName() + ":" + getServer() + "/",
getPassword(), HttpHelper.DEFAULT_CONNECTION_TIMEOUT, shouldAlarmOnFinishedDownload(),
shouldAlarmOnNewTorrent(), "" + startID++, true));
@ -119,29 +123,4 @@ public class XirvikSettings { @@ -119,29 +123,4 @@ public class XirvikSettings {
return daemons;
}
/**
* Returns the rTorrent folder name for a semi-dedicated server, based on the server, i.e. 'store001a.xirvik.com'
* @return The full folder name, i.e. '/RPC2'
*/
private String getSemiFoldername() {
/*int nr = 0;
if (getServer().length() > 1) {
switch (getServer().charAt(getServer().indexOf(".") - 1)) {
case 'a':
nr = 1;
break;
case 'b':
nr = 2;
break;
case 'c':
nr = 3;
break;
case 'd':
nr = 4;
break;
}
}*/
return RTORRENT_FOLDER_SEMI;
}
}

5
android/src/org/transdroid/preferences/Preferences.java

@ -64,6 +64,7 @@ public class Preferences { @@ -64,6 +64,7 @@ public class Preferences {
public static final String KEY_PREF_XNAME = "transdroid_xserver_name";
public static final String KEY_PREF_XTYPE = "transdroid_xserver_type";
public static final String KEY_PREF_XSERVER = "transdroid_xserver_server";
public static final String KEY_PREF_XFOLDER = "transdroid_xserver_folder";
public static final String KEY_PREF_XUSER = "transdroid_xserver_user";
public static final String KEY_PREF_XPASS = "transdroid_xserver_pass";
public static final String KEY_PREF_XALARMFINISHED = "transdroid_xserver_alarmfinished";
@ -240,7 +241,8 @@ public class Preferences { @@ -240,7 +241,8 @@ public class Preferences {
String toId = (id == 0? "": Integer.toString(id));
editor.putString(KEY_PREF_XNAME + toId, prefs.getString(KEY_PREF_XNAME + fromId, null));
editor.putString(KEY_PREF_XTYPE + toId, prefs.getString(KEY_PREF_XTYPE + fromId, null));
editor.putString(KEY_PREF_XSERVER+ toId, prefs.getString(KEY_PREF_XSERVER + fromId, null));
editor.putString(KEY_PREF_XSERVER + toId, prefs.getString(KEY_PREF_XSERVER + fromId, null));
editor.putString(KEY_PREF_XFOLDER + toId, prefs.getString(KEY_PREF_XFOLDER + fromId, null));
editor.putString(KEY_PREF_XUSER + toId, prefs.getString(KEY_PREF_XUSER + fromId, null));
editor.putString(KEY_PREF_XPASS + toId, prefs.getString(KEY_PREF_XPASS + fromId, null));
editor.putString(KEY_PREF_XALARMFINISHED + toId, prefs.getString(KEY_PREF_XALARMFINISHED + fromId, null));
@ -817,6 +819,7 @@ public class Preferences { @@ -817,6 +819,7 @@ public class Preferences {
prefs.getString(KEY_PREF_XNAME + postfix, null),
XirvikServerType.fromCode(prefType),
prefs.getString(KEY_PREF_XSERVER + postfix, null),
prefs.getString(KEY_PREF_XFOLDER + postfix, XirvikSettings.RTORRENT_FOLDER),
prefs.getString(KEY_PREF_XUSER + postfix, null),
prefs.getString(KEY_PREF_XPASS + postfix, null),
prefs.getBoolean(KEY_PREF_XALARMFINISHED + postfix, true),

2
lib/src/org/transdroid/daemon/Rtorrent/RtorrentAdapter.java

@ -240,7 +240,7 @@ public class RtorrentAdapter implements IDaemonAdapter { @@ -240,7 +240,7 @@ public class RtorrentAdapter implements IDaemonAdapter {
*/
private void initialise() throws DaemonException {
this.rpcclient = new XMLRPCClient(HttpHelper.createStandardHttpClient(settings, true), buildWebUIUrl());
this.rpcclient = new XMLRPCClient(HttpHelper.createStandardHttpClient(settings, true), buildWebUIUrl().trim());
}

34
lib/src/org/transdroid/daemon/util/HttpHelper.java

@ -73,25 +73,37 @@ public class HttpHelper { @@ -73,25 +73,37 @@ public class HttpHelper {
* Creates a standard Apache HttpClient that is thread safe, supports different
* SSL auth methods and basic authentication
* @param settings The server settings to adhere
* @param connectionTimeout The connection timeout for all requests
* @return An HttpClient that should be stored locally and reused for every new request
* @throws DaemonException Thrown when information (such as username/password) is missing
*/
public static DefaultHttpClient createStandardHttpClient(DaemonSettings settings, boolean userBasicAuth) throws DaemonException {
return createStandardHttpClient(userBasicAuth && settings.shouldUseAuthentication(), settings.getUsername(), settings.getPassword(), settings.getSslTrustAll(), settings.getSslTrustKey(), settings.getTimeoutInMilliseconds(), settings.getAddress(), settings.getPort());
}
/**
* Creates a standard Apache HttpClient that is thread safe, supports different
* SSL auth methods and basic authentication
* @param sslTrustAll Whether to trust all SSL certificates
* @param sslTrustkey A specific SSL key to accept exclusively
* @param timeout The connection timeout for all requests
* @param authAddress The authentication domain address
* @param authPort The authentication domain port number
* @return An HttpClient that should be stored locally and reused for every new request
* @throws DaemonException Thrown when information (such as username/password) is missing
*/
public static DefaultHttpClient createStandardHttpClient(boolean userBasicAuth, String username, String password, boolean sslTrustAll, String sslTrustkey, int timeout, String authAddress, int authPort) throws DaemonException {
// Register http and https sockets
SchemeRegistry registry = new SchemeRegistry();
registry.register(new Scheme("http", new PlainSocketFactory(), 80));
SocketFactory https_socket =
settings.getSslTrustAll() ? new FakeSocketFactory()
: settings.getSslTrustKey() != null ? new FakeSocketFactory(settings.getSslTrustKey())
: SSLSocketFactory.getSocketFactory();
SocketFactory https_socket = sslTrustAll ? new FakeSocketFactory()
: sslTrustkey != null ? new FakeSocketFactory(sslTrustkey) : SSLSocketFactory.getSocketFactory();
registry.register(new Scheme("https", https_socket, 443));
// Standard parameters
HttpParams httpparams = new BasicHttpParams();
HttpConnectionParams.setConnectionTimeout(httpparams, settings.getTimeoutInMilliseconds());
HttpConnectionParams.setSoTimeout(httpparams, settings.getTimeoutInMilliseconds());
HttpConnectionParams.setConnectionTimeout(httpparams, timeout);
HttpConnectionParams.setSoTimeout(httpparams, timeout);
if (userAgent != null) {
HttpProtocolParams.setUserAgent(httpparams, userAgent);
}
@ -99,13 +111,13 @@ public class HttpHelper { @@ -99,13 +111,13 @@ public class HttpHelper {
DefaultHttpClient httpclient = new DefaultHttpClient(new ThreadSafeClientConnManager(httpparams, registry), httpparams);
// Authentication credentials
if (userBasicAuth && settings.shouldUseAuthentication()) {
if (settings.getUsername() == null || settings.getPassword() == null) {
if (userBasicAuth) {
if (username == null || password == null) {
throw new InvalidParameterException("No username or password was provided while we hadauthentication enabled");
}
httpclient.getCredentialsProvider().setCredentials(
new AuthScope(settings.getAddress(), settings.getPort(), AuthScope.ANY_REALM),
new UsernamePasswordCredentials(settings.getUsername(), settings.getPassword()));
new AuthScope(authAddress, authPort, AuthScope.ANY_REALM),
new UsernamePasswordCredentials(username, password));
}
return httpclient;

Loading…
Cancel
Save