Browse Source

Protect setLabel in case plugin isn't installed.

pull/407/head
Alon Albert 7 years ago
parent
commit
c7a6946e0a
  1. 8
      app/src/main/java/org/transdroid/daemon/Deluge/DelugeAdapter.java
  2. 5
      app/src/main/java/org/transdroid/daemon/Deluge/DelugeCommon.java
  3. 23
      app/src/main/java/org/transdroid/daemon/Deluge/DelugeRpcAdapter.java

8
app/src/main/java/org/transdroid/daemon/Deluge/DelugeAdapter.java

@ -69,8 +69,8 @@ import static org.transdroid.daemon.Deluge.DelugeCommon.RPC_TOTALSEEDS; @@ -69,8 +69,8 @@ import static org.transdroid.daemon.Deluge.DelugeCommon.RPC_TOTALSEEDS;
import static org.transdroid.daemon.Deluge.DelugeCommon.RPC_TOTALSIZE;
import static org.transdroid.daemon.Deluge.DelugeCommon.RPC_TRACKERS;
import static org.transdroid.daemon.Deluge.DelugeCommon.RPC_TRACKER_STATUS;
import static org.transdroid.daemon.Deluge.DelugeCommon.RPC_TRACKER_TIER;
import static org.transdroid.daemon.Deluge.DelugeCommon.RPC_TRACKER_URL;
import static org.transdroid.daemon.Deluge.DelugeCommon.RPC_TIER;
import static org.transdroid.daemon.Deluge.DelugeCommon.RPC_URL;
import static org.transdroid.daemon.Deluge.DelugeCommon.RPC_UPLOADEDEVER;
import com.android.internalcopy.http.multipart.FilePart;
@ -388,8 +388,8 @@ public class DelugeAdapter implements IDaemonAdapter { @@ -388,8 +388,8 @@ public class DelugeAdapter implements IDaemonAdapter {
// Build an JSON arrays of objcts that each have a tier (order) number and an url
for (int i = 0; i < trackersTask.getNewTrackers().size(); i++) {
JSONObject trackerObj = new JSONObject();
trackerObj.put(RPC_TRACKER_TIER, i);
trackerObj.put(RPC_TRACKER_URL, trackersTask.getNewTrackers().get(i));
trackerObj.put(RPC_TIER, i);
trackerObj.put(RPC_URL, trackersTask.getNewTrackers().get(i));
trackers.put(trackerObj);
}
params.put(new JSONArray().put(task.getTargetTorrent().getUniqueID()));

5
app/src/main/java/org/transdroid/daemon/Deluge/DelugeCommon.java

@ -28,6 +28,7 @@ import org.transdroid.daemon.TorrentStatus; @@ -28,6 +28,7 @@ import org.transdroid.daemon.TorrentStatus;
* @author alon.albert
*/
class DelugeCommon {
static final String RPC_DETAILS = "files";
static final String RPC_DOWNLOADEDEVER = "total_done";
static final String RPC_ETA = "eta";
@ -81,11 +82,11 @@ class DelugeCommon { @@ -81,11 +82,11 @@ class DelugeCommon {
static final String RPC_TORRENTS = "torrents";
static final String RPC_TOTALPEERS = "total_peers";
static final String RPC_TOTALSEEDS = "total_seeds";
static final String RPC_TIER = "tier";
static final String RPC_TOTALSIZE = "total_size";
static final String RPC_TRACKERS = "trackers";
static final String RPC_TRACKER_STATUS = "tracker_status";
static final String RPC_TRACKER_TIER = "tier";
static final String RPC_TRACKER_URL = "url";
static final String RPC_URL = "url";
static final String RPC_UPLOADEDEVER = "total_uploaded";
static final String[] RPC_DETAILS_FIELDS_ARRAY = {

23
app/src/main/java/org/transdroid/daemon/Deluge/DelugeRpcAdapter.java

@ -66,8 +66,8 @@ import static org.transdroid.daemon.Deluge.DelugeCommon.RPC_TOTALSEEDS; @@ -66,8 +66,8 @@ import static org.transdroid.daemon.Deluge.DelugeCommon.RPC_TOTALSEEDS;
import static org.transdroid.daemon.Deluge.DelugeCommon.RPC_TOTALSIZE;
import static org.transdroid.daemon.Deluge.DelugeCommon.RPC_TRACKERS;
import static org.transdroid.daemon.Deluge.DelugeCommon.RPC_TRACKER_STATUS;
import static org.transdroid.daemon.Deluge.DelugeCommon.RPC_TRACKER_TIER;
import static org.transdroid.daemon.Deluge.DelugeCommon.RPC_TRACKER_URL;
import static org.transdroid.daemon.Deluge.DelugeCommon.RPC_TIER;
import static org.transdroid.daemon.Deluge.DelugeCommon.RPC_URL;
import static org.transdroid.daemon.Deluge.DelugeCommon.RPC_UPLOADEDEVER;
import android.support.annotation.NonNull;
@ -209,9 +209,7 @@ public class DelugeRpcAdapter implements IDaemonAdapter { @@ -209,9 +209,7 @@ public class DelugeRpcAdapter implements IDaemonAdapter {
final List<Torrent> torrents = getTorrents(torrentsStatus.values());
// Check if Label plugin is enabled
//noinspection unchecked
final List<String> methods = (List<String>) client.sendRequest(RPC_METHOD_GET_METHOD_LIST);
final boolean hasLabelPlugin = methods.contains(RPC_METHOD_GET_LABELS);
final boolean hasLabelPlugin = hasMethod(client, RPC_METHOD_GET_LABELS);
// Get label list from server
//noinspection unchecked
@ -239,7 +237,7 @@ public class DelugeRpcAdapter implements IDaemonAdapter { @@ -239,7 +237,7 @@ public class DelugeRpcAdapter implements IDaemonAdapter {
.get(RPC_TRACKERS);
final List<String> trackers = new ArrayList<>();
for (Map<String, Object> trackerResponse : trackerResponses) {
trackers.add((String) trackerResponse.get(RPC_TRACKER_URL));
trackers.add((String) trackerResponse.get(RPC_URL));
}
return new GetTorrentDetailsTaskSuccessResult(task, new TorrentDetails(
@ -295,6 +293,9 @@ public class DelugeRpcAdapter implements IDaemonAdapter { @@ -295,6 +293,9 @@ public class DelugeRpcAdapter implements IDaemonAdapter {
@NonNull
private DaemonTaskResult doSetLabel(DelugeRpcClient client, SetLabelTask task) throws DaemonException {
if (!hasMethod(client, RPC_METHOD_SETLABEL)) {
throw new DaemonException(ExceptionType.MethodUnsupported, "Label plugin not installed");
}
final String torrentId = task.getTargetTorrent().getUniqueID();
final String label = task.getNewLabel() == null ? "" : task.getNewLabel();
client.sendRequest(RPC_METHOD_SETLABEL, torrentId, label);
@ -345,8 +346,8 @@ public class DelugeRpcAdapter implements IDaemonAdapter { @@ -345,8 +346,8 @@ public class DelugeRpcAdapter implements IDaemonAdapter {
final ArrayList<String> newTrackers = task.getNewTrackers();
for (int i = 0, n = newTrackers.size(); i < n; i++) {
final Map<String, Object> tracker = new HashMap<>();
tracker.put(RPC_TRACKER_TIER, i);
tracker.put(RPC_TRACKER_URL, newTrackers.get(i));
tracker.put(RPC_TIER, i);
tracker.put(RPC_URL, newTrackers.get(i));
trackers.add(tracker);
}
client.sendRequest(RPC_METHOD_SETTRACKERS, task.getTargetTorrent().getUniqueID(), trackers);
@ -539,6 +540,12 @@ public class DelugeRpcAdapter implements IDaemonAdapter { @@ -539,6 +540,12 @@ public class DelugeRpcAdapter implements IDaemonAdapter {
return new String[]{task.getTargetTorrent().getUniqueID()};
}
private boolean hasMethod(DelugeRpcClient client, String method) throws DaemonException {
//noinspection unchecked
final List<String> methods = (List<String>) client.sendRequest(RPC_METHOD_GET_METHOD_LIST);
return methods.contains(method);
}
/**
* Used to count torrents in labels.
*/

Loading…
Cancel
Save