|
|
@ -17,6 +17,8 @@ |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
package org.transdroid.daemon.Transmission; |
|
|
|
package org.transdroid.daemon.Transmission; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import android.text.TextUtils; |
|
|
|
|
|
|
|
|
|
|
|
import org.apache.http.HttpEntity; |
|
|
|
import org.apache.http.HttpEntity; |
|
|
|
import org.apache.http.HttpResponse; |
|
|
|
import org.apache.http.HttpResponse; |
|
|
|
import org.apache.http.client.methods.HttpPost; |
|
|
|
import org.apache.http.client.methods.HttpPost; |
|
|
@ -416,6 +418,13 @@ public class TransmissionAdapter implements IDaemonAdapter { |
|
|
|
httppost.addHeader(sessionHeader, sessionToken); |
|
|
|
httppost.addHeader(sessionHeader, sessionToken); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Force preemptive authentication. This makes sure there is an 'Authentication: ' header being send before trying and failing and
|
|
|
|
|
|
|
|
// retrying by the basic authentication mechanism of DefaultHttpClient
|
|
|
|
|
|
|
|
if (settings.shouldUseAuthentication() && !TextUtils.isEmpty(settings.getUsername())) { |
|
|
|
|
|
|
|
httppost.addHeader("Authorization", "Basic " + |
|
|
|
|
|
|
|
Base64.encodeBytes((settings.getUsername() + ":" + settings.getPassword()).getBytes())); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Execute
|
|
|
|
// Execute
|
|
|
|
log.d(LOG_NAME, "Execute " + data.getString("method") + " request to " + httppost.getURI().toString()); |
|
|
|
log.d(LOG_NAME, "Execute " + data.getString("method") + " request to " + httppost.getURI().toString()); |
|
|
|
HttpResponse response = httpclient.execute(httppost); |
|
|
|
HttpResponse response = httpclient.execute(httppost); |
|
|
@ -499,7 +508,7 @@ public class TransmissionAdapter implements IDaemonAdapter { |
|
|
|
private ArrayList<Torrent> parseJsonRetrieveTorrents(JSONObject response) throws JSONException { |
|
|
|
private ArrayList<Torrent> parseJsonRetrieveTorrents(JSONObject response) throws JSONException { |
|
|
|
|
|
|
|
|
|
|
|
// Parse response
|
|
|
|
// Parse response
|
|
|
|
ArrayList<Torrent> torrents = new ArrayList<Torrent>(); |
|
|
|
ArrayList<Torrent> torrents = new ArrayList<>(); |
|
|
|
JSONArray rarray = response.getJSONArray("torrents"); |
|
|
|
JSONArray rarray = response.getJSONArray("torrents"); |
|
|
|
for (int i = 0; i < rarray.length(); i++) { |
|
|
|
for (int i = 0; i < rarray.length(); i++) { |
|
|
|
JSONObject tor = rarray.getJSONObject(i); |
|
|
|
JSONObject tor = rarray.getJSONObject(i); |
|
|
@ -580,7 +589,7 @@ public class TransmissionAdapter implements IDaemonAdapter { |
|
|
|
private ArrayList<TorrentFile> parseJsonFileList(JSONObject response, Torrent torrent) throws JSONException { |
|
|
|
private ArrayList<TorrentFile> parseJsonFileList(JSONObject response, Torrent torrent) throws JSONException { |
|
|
|
|
|
|
|
|
|
|
|
// Parse response
|
|
|
|
// Parse response
|
|
|
|
ArrayList<TorrentFile> torrentfiles = new ArrayList<TorrentFile>(); |
|
|
|
ArrayList<TorrentFile> torrentfiles = new ArrayList<>(); |
|
|
|
JSONArray rarray = response.getJSONArray("torrents"); |
|
|
|
JSONArray rarray = response.getJSONArray("torrents"); |
|
|
|
if (rarray.length() > 0) { |
|
|
|
if (rarray.length() > 0) { |
|
|
|
JSONArray files = rarray.getJSONObject(0).getJSONArray("files"); |
|
|
|
JSONArray files = rarray.getJSONObject(0).getJSONArray("files"); |
|
|
@ -628,12 +637,12 @@ public class TransmissionAdapter implements IDaemonAdapter { |
|
|
|
JSONArray rarray = response.getJSONArray("torrents"); |
|
|
|
JSONArray rarray = response.getJSONArray("torrents"); |
|
|
|
if (rarray.length() > 0) { |
|
|
|
if (rarray.length() > 0) { |
|
|
|
JSONArray trackersList = rarray.getJSONObject(0).getJSONArray("trackers"); |
|
|
|
JSONArray trackersList = rarray.getJSONObject(0).getJSONArray("trackers"); |
|
|
|
List<String> trackers = new ArrayList<String>(); |
|
|
|
List<String> trackers = new ArrayList<>(); |
|
|
|
for (int i = 0; i < trackersList.length(); i++) { |
|
|
|
for (int i = 0; i < trackersList.length(); i++) { |
|
|
|
trackers.add(trackersList.getJSONObject(i).getString("announce")); |
|
|
|
trackers.add(trackersList.getJSONObject(i).getString("announce")); |
|
|
|
} |
|
|
|
} |
|
|
|
JSONArray trackerStatsList = rarray.getJSONObject(0).getJSONArray("trackerStats"); |
|
|
|
JSONArray trackerStatsList = rarray.getJSONObject(0).getJSONArray("trackerStats"); |
|
|
|
List<String> errors = new ArrayList<String>(); |
|
|
|
List<String> errors = new ArrayList<>(); |
|
|
|
for (int i = 0; i < trackerStatsList.length(); i++) { |
|
|
|
for (int i = 0; i < trackerStatsList.length(); i++) { |
|
|
|
// Get the tracker response and if it was an error then add it
|
|
|
|
// Get the tracker response and if it was an error then add it
|
|
|
|
String lar = trackerStatsList.getJSONObject(i).getString("lastAnnounceResult"); |
|
|
|
String lar = trackerStatsList.getJSONObject(i).getString("lastAnnounceResult"); |
|
|
|