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. 313
      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. 36
      lib/src/org/transdroid/daemon/util/HttpHelper.java

2
android/AndroidManifest.xml

@ -22,7 +22,7 @@
android:versionCode="145" android:versionCode="145"
android:installLocation="auto"> 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" /> <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.INTERNET" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" /> <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />

2
android/project.properties

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

4
android/res/values/arrays.xml

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

3
android/res/values/strings.xml

@ -363,7 +363,10 @@
<string name="xirvik_pref_type_info">Shared, semi- or dedicated</string> <string name="xirvik_pref_type_info">Shared, semi- or dedicated</string>
<string name="xirvik_pref_server">Server name</string> <string name="xirvik_pref_server">Server name</string>
<string name="xirvik_pref_server_info">Like dedi000.xirvik.com</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_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_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> <string name="seedm8_add_new_xserver">Add SeedM8 server</string>

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

@ -15,15 +15,26 @@
* along with Transdroid. If not, see <http://www.gnu.org/licenses/>. * 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.R;
import org.transdroid.daemon.DaemonException;
import org.transdroid.daemon.util.HttpHelper;
import org.transdroid.preferences.Preferences; import org.transdroid.preferences.Preferences;
import org.transdroid.preferences.TransdroidCheckBoxPreference; import org.transdroid.preferences.TransdroidCheckBoxPreference;
import org.transdroid.preferences.TransdroidEditTextPreference; import org.transdroid.preferences.TransdroidEditTextPreference;
import org.transdroid.preferences.TransdroidListPreference; import org.transdroid.preferences.TransdroidListPreference;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.os.AsyncTask;
import android.os.Bundle; import android.os.Bundle;
import android.preference.Preference; import android.preference.Preference;
import android.preference.PreferenceActivity; import android.preference.PreferenceActivity;
@ -39,7 +50,7 @@ import android.widget.Toast;
public class PreferencesXirvikServer extends PreferenceActivity { public class PreferencesXirvikServer extends PreferenceActivity {
public static final String PREFERENCES_XSERVER_KEY = "PREFERENCES_XSERVER_POSTFIX"; 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" }; public static final String[] validAddressEnding = { ".xirvik.com", ".xirvik.net" };
private String serverPostfix; private String serverPostfix;
@ -47,6 +58,7 @@ public class PreferencesXirvikServer extends PreferenceActivity {
private TransdroidEditTextPreference name; private TransdroidEditTextPreference name;
private TransdroidListPreference type; private TransdroidListPreference type;
private TransdroidEditTextPreference server; private TransdroidEditTextPreference server;
private TransdroidEditTextPreference folder;
private TransdroidEditTextPreference user; private TransdroidEditTextPreference user;
private TransdroidEditTextPreference pass; private TransdroidEditTextPreference pass;
private TransdroidCheckBoxPreference alarmFinished; private TransdroidCheckBoxPreference alarmFinished;
@ -55,94 +67,104 @@ public class PreferencesXirvikServer extends PreferenceActivity {
private String nameValue = null; private String nameValue = null;
private String typeValue = null; private String typeValue = null;
private String serverValue = null; private String serverValue = null;
private String folderValue = null;
private String userValue = null; private String userValue = null;
//private String passValue = null; private String passValue = null;
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
// For which server? // For which server?
serverPostfix = getIntent().getStringExtra(PREFERENCES_XSERVER_KEY); serverPostfix = getIntent().getStringExtra(PREFERENCES_XSERVER_KEY);
// Create the preferences screen here: this takes care of saving/loading, but also contains the ListView adapter, etc. // Create the preferences screen here: this takes care of saving/loading, but also contains the
setPreferenceScreen(getPreferenceManager().createPreferenceScreen(this)); // ListView adapter, etc.
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); 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); nameValue = prefs.getString(Preferences.KEY_PREF_XNAME + serverPostfix, null);
serverValue = prefs.getString(Preferences.KEY_PREF_XSERVER + serverPostfix, null); typeValue = prefs.getString(Preferences.KEY_PREF_XTYPE + serverPostfix, null);
userValue = prefs.getString(Preferences.KEY_PREF_XUSER + serverPostfix, null); serverValue = prefs.getString(Preferences.KEY_PREF_XSERVER + serverPostfix, null);
//passValue = prefs.getString(Preferences.KEY_PREF_XPASS + serverPostfix, null); folderValue = prefs.getString(Preferences.KEY_PREF_XFOLDER + serverPostfix, null);
userValue = prefs.getString(Preferences.KEY_PREF_XUSER + serverPostfix, null);
// Create preference objects passValue = prefs.getString(Preferences.KEY_PREF_XPASS + serverPostfix, null);
getPreferenceScreen().setTitle(R.string.xirvik_pref_title);
// Name // Create preference objects
name = new TransdroidEditTextPreference(this); getPreferenceScreen().setTitle(R.string.xirvik_pref_title);
name.setTitle(R.string.pref_name); // Name
name.setKey(Preferences.KEY_PREF_XNAME + serverPostfix); name = new TransdroidEditTextPreference(this);
name.getEditText().setSingleLine(); name.setTitle(R.string.pref_name);
name.setDialogTitle(R.string.pref_name); name.setKey(Preferences.KEY_PREF_XNAME + serverPostfix);
name.setOnPreferenceChangeListener(updateHandler); name.getEditText().setSingleLine();
getPreferenceScreen().addItemFromInflater(name); name.setDialogTitle(R.string.pref_name);
// Type name.setOnPreferenceChangeListener(updateHandler);
type = new TransdroidListPreference(this); getPreferenceScreen().addItemFromInflater(name);
type.setTitle(R.string.xirvik_pref_type); // Type
type.setKey(Preferences.KEY_PREF_XTYPE + serverPostfix); type = new TransdroidListPreference(this);
type.setEntries(R.array.pref_xirvik_types); type.setTitle(R.string.xirvik_pref_type);
type.setEntryValues(R.array.pref_xirvik_values); type.setKey(Preferences.KEY_PREF_XTYPE + serverPostfix);
type.setDialogTitle(R.string.xirvik_pref_type); type.setEntries(R.array.pref_xirvik_types);
type.setOnPreferenceChangeListener(updateHandler); type.setEntryValues(R.array.pref_xirvik_values);
getPreferenceScreen().addItemFromInflater(type); type.setDialogTitle(R.string.xirvik_pref_type);
// Server type.setOnPreferenceChangeListener(updateHandler);
server = new TransdroidEditTextPreference(this); getPreferenceScreen().addItemFromInflater(type);
server.setTitle(R.string.xirvik_pref_server); // Server
server.setKey(Preferences.KEY_PREF_XSERVER + serverPostfix); server = new TransdroidEditTextPreference(this);
server.getEditText().setSingleLine(); server.setTitle(R.string.xirvik_pref_server);
server.getEditText().setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_URI); server.setKey(Preferences.KEY_PREF_XSERVER + serverPostfix);
server.setDialogTitle(R.string.xirvik_pref_server); server.getEditText().setSingleLine();
server.setOnPreferenceChangeListener(updateHandler); server.getEditText().setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_URI);
getPreferenceScreen().addItemFromInflater(server); server.setDialogTitle(R.string.xirvik_pref_server);
// User server.setOnPreferenceChangeListener(updateHandler);
user = new TransdroidEditTextPreference(this); getPreferenceScreen().addItemFromInflater(server);
user.setTitle(R.string.pref_user); // Folder
user.setKey(Preferences.KEY_PREF_XUSER + serverPostfix); folder = new TransdroidEditTextPreference(this);
user.getEditText().setSingleLine(); folder.setTitle(R.string.xirvik_pref_folder);
user.getEditText().setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_FILTER); folder.setKey(Preferences.KEY_PREF_XFOLDER + serverPostfix);
user.setDialogTitle(R.string.pref_user); folder.setEnabled(false);
user.setOnPreferenceChangeListener(updateHandler); folder.setSummary(R.string.xirvik_pref_setautomatically);
getPreferenceScreen().addItemFromInflater(user); getPreferenceScreen().addItemFromInflater(folder);
// Pass // User
pass = new TransdroidEditTextPreference(this); user = new TransdroidEditTextPreference(this);
pass.setTitle(R.string.pref_pass); user.setTitle(R.string.pref_user);
pass.setKey(Preferences.KEY_PREF_XPASS + serverPostfix); user.setKey(Preferences.KEY_PREF_XUSER + serverPostfix);
pass.getEditText().setSingleLine(); user.getEditText().setSingleLine();
pass.getEditText().setInputType(EditorInfo.TYPE_TEXT_VARIATION_PASSWORD); user.getEditText().setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_FILTER);
pass.getEditText().setTransformationMethod(new PasswordTransformationMethod()); user.setDialogTitle(R.string.pref_user);
pass.setDialogTitle(R.string.pref_pass); user.setOnPreferenceChangeListener(updateHandler);
pass.setOnPreferenceChangeListener(updateHandler); getPreferenceScreen().addItemFromInflater(user);
getPreferenceScreen().addItemFromInflater(pass); // Pass
pass = new TransdroidEditTextPreference(this);
// AlertFinished pass.setTitle(R.string.pref_pass);
alarmFinished = new TransdroidCheckBoxPreference(this); pass.setKey(Preferences.KEY_PREF_XPASS + serverPostfix);
alarmFinished.setDefaultValue(true); pass.getEditText().setSingleLine();
alarmFinished.setTitle(R.string.pref_alarmfinished); pass.getEditText().setInputType(EditorInfo.TYPE_TEXT_VARIATION_PASSWORD);
alarmFinished.setSummary(R.string.pref_alarmfinished_info); pass.getEditText().setTransformationMethod(new PasswordTransformationMethod());
alarmFinished.setKey(Preferences.KEY_PREF_XALARMFINISHED + serverPostfix); pass.setDialogTitle(R.string.pref_pass);
alarmFinished.setOnPreferenceChangeListener(updateHandler); pass.setOnPreferenceChangeListener(updateHandler);
getPreferenceScreen().addItemFromInflater(alarmFinished); getPreferenceScreen().addItemFromInflater(pass);
// AlertNew
alarmNew = new TransdroidCheckBoxPreference(this); // AlertFinished
alarmNew.setTitle(R.string.pref_alarmnew); alarmFinished = new TransdroidCheckBoxPreference(this);
alarmNew.setSummary(R.string.pref_alarmnew_info); alarmFinished.setDefaultValue(true);
alarmNew.setKey(Preferences.KEY_PREF_XALARMNEW + serverPostfix); alarmFinished.setTitle(R.string.pref_alarmfinished);
alarmNew.setOnPreferenceChangeListener(updateHandler); alarmFinished.setSummary(R.string.pref_alarmfinished_info);
getPreferenceScreen().addItemFromInflater(alarmNew); alarmFinished.setKey(Preferences.KEY_PREF_XALARMFINISHED + serverPostfix);
alarmFinished.setOnPreferenceChangeListener(updateHandler);
updateDescriptionTexts(); getPreferenceScreen().addItemFromInflater(alarmFinished);
// AlertNew
} alarmNew = new TransdroidCheckBoxPreference(this);
alarmNew.setTitle(R.string.pref_alarmnew);
private OnPreferenceChangeListener updateHandler = new OnPreferenceChangeListener() { 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 @Override
public boolean onPreferenceChange(Preference preference, Object newValue) { public boolean onPreferenceChange(Preference preference, Object newValue) {
if (preference == name) { if (preference == name) {
@ -158,48 +180,107 @@ public class PreferencesXirvikServer extends PreferenceActivity {
validEnd |= newServer.endsWith(validAddressEnding[i]); validEnd |= newServer.endsWith(validAddressEnding[i]);
} }
if (!valid || !validEnd) { 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; return false;
} }
serverValue = newServer; serverValue = newServer;
} else if (preference == user) { } else if (preference == user) {
userValue = (String) newValue; userValue = (String) newValue;
} else if (preference == pass) { } else if (preference == pass) {
//passValue = (String) newValue; passValue = (String) newValue;
} }
updateDescriptionTexts(); updateDescriptionTexts();
updateScgiMountFolder();
// Set the value as usual // Set the value as usual
return true; return true;
} }
}; };
@Override @Override
protected void onListItemClick(ListView l, View v, int position, long id) { protected void onListItemClick(ListView l, View v, int position, long id) {
// Perform click action, which always is a Preference // Perform click action, which always is a Preference
Preference item = (Preference) getListAdapter().getItem(position); Preference item = (Preference) getListAdapter().getItem(position);
// Let the Preference open the right dialog // Let the Preference open the right dialog
if (item instanceof TransdroidListPreference) { if (item instanceof TransdroidListPreference) {
((TransdroidListPreference)item).click(); ((TransdroidListPreference) item).click();
} else if (item instanceof TransdroidCheckBoxPreference) { } else if (item instanceof TransdroidCheckBoxPreference) {
((TransdroidCheckBoxPreference)item).click(); ((TransdroidCheckBoxPreference) item).click();
} else if (item instanceof TransdroidEditTextPreference) { } 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());
private void updateDescriptionTexts() { Editor edit = prefs.edit();
edit.putString(Preferences.KEY_PREF_XFOLDER + serverPostfix, result);
// Update the 'summary' labels of all preferences to show their current value edit.commit();
XirvikServerType typeType = XirvikServerType.fromCode(typeValue); folderValue = result;
updateDescriptionTexts();
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); private void updateDescriptionTexts() {
user.setSummary(userValue == null? "": userValue);
// 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);
folder.setSummary(folderValue == null ? "" : folderValue);
}
} }

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

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

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

@ -16,25 +16,26 @@ public class XirvikSettings {
private static final int TFB4RT_PORT = 443; private static final int TFB4RT_PORT = 443;
private static final String TFB4RT_FOLDER = "/tfx"; private static final String TFB4RT_FOLDER = "/tfx";
private static final int RTORRENT_PORT = 443; private static final int RTORRENT_PORT = 443;
private static final String RTORRENT_FOLDER_DEDI = "/RPC2"; public static final String RTORRENT_FOLDER = "/RPC2";
private static final String RTORRENT_FOLDER_SEMI = "/RPC2";
private static final int UTORRENT_PORT = 5010; private static final int UTORRENT_PORT = 5010;
final private String name; final private String name;
final private XirvikServerType type; final private XirvikServerType type;
final private String server; final private String server;
final private String folder;
final private String username; final private String username;
final private String password; final private String password;
final private boolean alarmOnFinishedDownload; final private boolean alarmOnFinishedDownload;
final private boolean alarmOnNewTorrent; final private boolean alarmOnNewTorrent;
final private String idString; 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 password, boolean alarmOnFinishedDownload, boolean alarmOnNewTorrent,
String idString) { String idString) {
this.name = name; this.name = name;
this.type = type; this.type = type;
this.server = server; this.server = server;
this.folder = folder;
this.username = username; this.username = username;
this.password = password; this.password = password;
this.alarmOnFinishedDownload = alarmOnFinishedDownload; this.alarmOnFinishedDownload = alarmOnFinishedDownload;
@ -51,6 +52,9 @@ public class XirvikSettings {
public String getServer() { public String getServer() {
return server; return server;
} }
public String getFolder() {
return folder;
}
public String getUsername() { public String getUsername() {
return username; return username;
} }
@ -94,13 +98,13 @@ public class XirvikSettings {
getPassword(), HttpHelper.DEFAULT_CONNECTION_TIMEOUT, shouldAlarmOnFinishedDownload(), getPassword(), HttpHelper.DEFAULT_CONNECTION_TIMEOUT, shouldAlarmOnFinishedDownload(),
shouldAlarmOnNewTorrent(), "" + startID++, true)); shouldAlarmOnNewTorrent(), "" + startID++, true));
} }
if (getType() == XirvikServerType.SemiDedicated || isDedi) { if (getType() == XirvikServerType.SharedRtorrent || getType() == XirvikServerType.SemiDedicated || isDedi) {
daemons.add( daemons.add(
new DaemonSettings( new DaemonSettings(
getName() + (isDedi? " rTorrent": ""), getName() + (isDedi? " rTorrent": ""),
Daemon.rTorrent, getServer(), RTORRENT_PORT, Daemon.rTorrent, getServer(), RTORRENT_PORT,
true, true, null, true, true, null,
(isDedi? RTORRENT_FOLDER_DEDI: getSemiFoldername()), true, getUsername(), getPassword(), getFolder(), true, getUsername(), getPassword(),
OS.Linux, "/", "ftp://" + getName() + ":" + getServer() + "/", OS.Linux, "/", "ftp://" + getName() + ":" + getServer() + "/",
getPassword(), HttpHelper.DEFAULT_CONNECTION_TIMEOUT, shouldAlarmOnFinishedDownload(), getPassword(), HttpHelper.DEFAULT_CONNECTION_TIMEOUT, shouldAlarmOnFinishedDownload(),
shouldAlarmOnNewTorrent(), "" + startID++, true)); shouldAlarmOnNewTorrent(), "" + startID++, true));
@ -119,29 +123,4 @@ public class XirvikSettings {
return daemons; 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 {
public static final String KEY_PREF_XNAME = "transdroid_xserver_name"; 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_XTYPE = "transdroid_xserver_type";
public static final String KEY_PREF_XSERVER = "transdroid_xserver_server"; 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_XUSER = "transdroid_xserver_user";
public static final String KEY_PREF_XPASS = "transdroid_xserver_pass"; public static final String KEY_PREF_XPASS = "transdroid_xserver_pass";
public static final String KEY_PREF_XALARMFINISHED = "transdroid_xserver_alarmfinished"; public static final String KEY_PREF_XALARMFINISHED = "transdroid_xserver_alarmfinished";
@ -240,7 +241,8 @@ public class Preferences {
String toId = (id == 0? "": Integer.toString(id)); String toId = (id == 0? "": Integer.toString(id));
editor.putString(KEY_PREF_XNAME + toId, prefs.getString(KEY_PREF_XNAME + fromId, null)); 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_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_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_XPASS + toId, prefs.getString(KEY_PREF_XPASS + fromId, null));
editor.putString(KEY_PREF_XALARMFINISHED + toId, prefs.getString(KEY_PREF_XALARMFINISHED + fromId, null)); editor.putString(KEY_PREF_XALARMFINISHED + toId, prefs.getString(KEY_PREF_XALARMFINISHED + fromId, null));
@ -817,6 +819,7 @@ public class Preferences {
prefs.getString(KEY_PREF_XNAME + postfix, null), prefs.getString(KEY_PREF_XNAME + postfix, null),
XirvikServerType.fromCode(prefType), XirvikServerType.fromCode(prefType),
prefs.getString(KEY_PREF_XSERVER + postfix, null), 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_XUSER + postfix, null),
prefs.getString(KEY_PREF_XPASS + postfix, null), prefs.getString(KEY_PREF_XPASS + postfix, null),
prefs.getBoolean(KEY_PREF_XALARMFINISHED + postfix, true), 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 {
*/ */
private void initialise() throws DaemonException { private void initialise() throws DaemonException {
this.rpcclient = new XMLRPCClient(HttpHelper.createStandardHttpClient(settings, true), buildWebUIUrl()); this.rpcclient = new XMLRPCClient(HttpHelper.createStandardHttpClient(settings, true), buildWebUIUrl().trim());
} }

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

@ -68,30 +68,42 @@ public class HttpHelper {
* The 'User-Agent' name to send to the server * The 'User-Agent' name to send to the server
*/ */
public static String userAgent = null; public static String userAgent = null;
/** /**
* Creates a standard Apache HttpClient that is thread safe, supports different * Creates a standard Apache HttpClient that is thread safe, supports different
* SSL auth methods and basic authentication * SSL auth methods and basic authentication
* @param settings The server settings to adhere * @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 * @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 * @throws DaemonException Thrown when information (such as username/password) is missing
*/ */
public static DefaultHttpClient createStandardHttpClient(DaemonSettings settings, boolean userBasicAuth) throws DaemonException { 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 // Register http and https sockets
SchemeRegistry registry = new SchemeRegistry(); SchemeRegistry registry = new SchemeRegistry();
registry.register(new Scheme("http", new PlainSocketFactory(), 80)); registry.register(new Scheme("http", new PlainSocketFactory(), 80));
SocketFactory https_socket = SocketFactory https_socket = sslTrustAll ? new FakeSocketFactory()
settings.getSslTrustAll() ? new FakeSocketFactory() : sslTrustkey != null ? new FakeSocketFactory(sslTrustkey) : SSLSocketFactory.getSocketFactory();
: settings.getSslTrustKey() != null ? new FakeSocketFactory(settings.getSslTrustKey())
: SSLSocketFactory.getSocketFactory();
registry.register(new Scheme("https", https_socket, 443)); registry.register(new Scheme("https", https_socket, 443));
// Standard parameters // Standard parameters
HttpParams httpparams = new BasicHttpParams(); HttpParams httpparams = new BasicHttpParams();
HttpConnectionParams.setConnectionTimeout(httpparams, settings.getTimeoutInMilliseconds()); HttpConnectionParams.setConnectionTimeout(httpparams, timeout);
HttpConnectionParams.setSoTimeout(httpparams, settings.getTimeoutInMilliseconds()); HttpConnectionParams.setSoTimeout(httpparams, timeout);
if (userAgent != null) { if (userAgent != null) {
HttpProtocolParams.setUserAgent(httpparams, userAgent); HttpProtocolParams.setUserAgent(httpparams, userAgent);
} }
@ -99,13 +111,13 @@ public class HttpHelper {
DefaultHttpClient httpclient = new DefaultHttpClient(new ThreadSafeClientConnManager(httpparams, registry), httpparams); DefaultHttpClient httpclient = new DefaultHttpClient(new ThreadSafeClientConnManager(httpparams, registry), httpparams);
// Authentication credentials // Authentication credentials
if (userBasicAuth && settings.shouldUseAuthentication()) { if (userBasicAuth) {
if (settings.getUsername() == null || settings.getPassword() == null) { if (username == null || password == null) {
throw new InvalidParameterException("No username or password was provided while we hadauthentication enabled"); throw new InvalidParameterException("No username or password was provided while we hadauthentication enabled");
} }
httpclient.getCredentialsProvider().setCredentials( httpclient.getCredentialsProvider().setCredentials(
new AuthScope(settings.getAddress(), settings.getPort(), AuthScope.ANY_REALM), new AuthScope(authAddress, authPort, AuthScope.ANY_REALM),
new UsernamePasswordCredentials(settings.getUsername(), settings.getPassword())); new UsernamePasswordCredentials(username, password));
} }
return httpclient; return httpclient;

Loading…
Cancel
Save