Browse Source

Improved backwards compatible rTorrent adapter, which can switch to the right methods (currently for adding torrents) based on the version.

pull/222/merge
Eric Kok 10 years ago
parent
commit
1fb1ef7b41
  1. 24
      app/src/main/java/org/transdroid/daemon/Rtorrent/RtorrentAdapter.java

24
app/src/main/java/org/transdroid/daemon/Rtorrent/RtorrentAdapter.java

@ -82,6 +82,7 @@ public class RtorrentAdapter implements IDaemonAdapter {
private DaemonSettings settings; private DaemonSettings settings;
private XMLRPCClient rpcclient; private XMLRPCClient rpcclient;
private List<Label> lastKnownLabels = null; private List<Label> lastKnownLabels = null;
private Integer version = null;
public RtorrentAdapter(DaemonSettings settings) { public RtorrentAdapter(DaemonSettings settings) {
this.settings = settings; this.settings = settings;
@ -91,6 +92,16 @@ public class RtorrentAdapter implements IDaemonAdapter {
public DaemonTaskResult executeTask(Log log, DaemonTask task) { public DaemonTaskResult executeTask(Log log, DaemonTask task) {
try { try {
// Ensure a version number is know to switch to the right methods
if (version == null) {
try {
Object versionObject = makeRtorrentCall(log, "system.client_version", new String[0]);
String[] versionRaw = versionObject.toString().split("\\.");
version = (Integer.parseInt(versionRaw[0]) * 10000) + (Integer.parseInt(versionRaw[1]) * 100) + Integer.parseInt(versionRaw[2]);
} catch (Exception e) {
version = 10000;
}
}
switch (task.getMethod()) { switch (task.getMethod()) {
case Retrieve: case Retrieve:
@ -167,22 +178,35 @@ public class RtorrentAdapter implements IDaemonAdapter {
byte[] bytes = baos.toByteArray(); byte[] bytes = baos.toByteArray();
int size = (int) file.length() * 2; int size = (int) file.length() * 2;
final int XMLRPC_EXTRA_PADDING = 1280; final int XMLRPC_EXTRA_PADDING = 1280;
if (version >= 904) {
makeRtorrentCall(log, "network.xmlrpc.size_limit.set", new Object[]{size + XMLRPC_EXTRA_PADDING}); makeRtorrentCall(log, "network.xmlrpc.size_limit.set", new Object[]{size + XMLRPC_EXTRA_PADDING});
makeRtorrentCall(log, "load.raw_start", new Object[]{bytes}); makeRtorrentCall(log, "load.raw_start", new Object[]{bytes});
} else {
makeRtorrentCall(log, "set_xmlrpc_size_limit", new Object[]{size + XMLRPC_EXTRA_PADDING});
makeRtorrentCall(log, "load_raw_start", new Object[]{bytes});
}
return new DaemonTaskSuccessResult(task); return new DaemonTaskSuccessResult(task);
case AddByUrl: case AddByUrl:
// Request to add a torrent by URL // Request to add a torrent by URL
String url = ((AddByUrlTask) task).getUrl(); String url = ((AddByUrlTask) task).getUrl();
if (version >= 904) {
makeRtorrentCall(log, "load.start", new String[]{"", url}); makeRtorrentCall(log, "load.start", new String[]{"", url});
} else {
makeRtorrentCall(log, "load_start", new String[]{url});
}
return new DaemonTaskSuccessResult(task); return new DaemonTaskSuccessResult(task);
case AddByMagnetUrl: case AddByMagnetUrl:
// Request to add a magnet link by URL // Request to add a magnet link by URL
String magnet = ((AddByMagnetUrlTask) task).getUrl(); String magnet = ((AddByMagnetUrlTask) task).getUrl();
if (version >= 904) {
makeRtorrentCall(log, "load.start", new String[]{"", magnet}); makeRtorrentCall(log, "load.start", new String[]{"", magnet});
} else {
makeRtorrentCall(log, "load_start", new String[]{magnet});
}
return new DaemonTaskSuccessResult(task); return new DaemonTaskSuccessResult(task);
case Remove: case Remove:

Loading…
Cancel
Save