|
|
@ -51,13 +51,10 @@ import com.android.internalcopy.http.multipart.FilePart; |
|
|
|
import com.android.internalcopy.http.multipart.MultipartEntity; |
|
|
|
import com.android.internalcopy.http.multipart.MultipartEntity; |
|
|
|
import com.android.internalcopy.http.multipart.Part; |
|
|
|
import com.android.internalcopy.http.multipart.Part; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* An adapter that allows for easy access to Torrentflux-b4rt installs. Communication |
|
|
|
* An adapter that allows for easy access to Torrentflux-b4rt installs. Communication is handled via HTTP GET requests |
|
|
|
* is handled via HTTP GET requests and XML responses. |
|
|
|
* and XML responses. |
|
|
|
* |
|
|
|
|
|
|
|
* @author erickok |
|
|
|
* @author erickok |
|
|
|
* |
|
|
|
|
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public class Tfb4rtAdapter implements IDaemonAdapter { |
|
|
|
public class Tfb4rtAdapter implements IDaemonAdapter { |
|
|
|
|
|
|
|
|
|
|
@ -110,7 +107,8 @@ public class Tfb4rtAdapter implements IDaemonAdapter { |
|
|
|
|
|
|
|
|
|
|
|
// Remove a torrent
|
|
|
|
// Remove a torrent
|
|
|
|
RemoveTask removeTask = (RemoveTask) task; |
|
|
|
RemoveTask removeTask = (RemoveTask) task; |
|
|
|
makeActionRequest((removeTask.includingData()? "deleteWithData": "delete"), task.getTargetTorrent().getUniqueID()); |
|
|
|
makeActionRequest((removeTask.includingData() ? "deleteWithData" : "delete"), task.getTargetTorrent() |
|
|
|
|
|
|
|
.getUniqueID()); |
|
|
|
return new DaemonTaskSuccessResult(task); |
|
|
|
return new DaemonTaskSuccessResult(task); |
|
|
|
|
|
|
|
|
|
|
|
case Pause: |
|
|
|
case Pause: |
|
|
@ -144,7 +142,8 @@ public class Tfb4rtAdapter implements IDaemonAdapter { |
|
|
|
return null; |
|
|
|
return null; |
|
|
|
|
|
|
|
|
|
|
|
default: |
|
|
|
default: |
|
|
|
return new DaemonTaskFailureResult(task, new DaemonException(ExceptionType.MethodUnsupported, task.getMethod() + " is not supported by " + getType())); |
|
|
|
return new DaemonTaskFailureResult(task, new DaemonException(ExceptionType.MethodUnsupported, |
|
|
|
|
|
|
|
task.getMethod() + " is not supported by " + getType())); |
|
|
|
} |
|
|
|
} |
|
|
|
} catch (DaemonException e) { |
|
|
|
} catch (DaemonException e) { |
|
|
|
return new DaemonTaskFailureResult(task, e); |
|
|
|
return new DaemonTaskFailureResult(task, e); |
|
|
@ -190,7 +189,8 @@ public class Tfb4rtAdapter implements IDaemonAdapter { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Make request
|
|
|
|
// Make request
|
|
|
|
HttpGet httpget = new HttpGet(buildWebUIUrl(RPC_URL_DISPATCH + action + RPC_URL_DISPATCH2 + RPC_URL_AID + (action.equals("urlUpload")? RPC_URL_URL: RPC_URL_TRANSFER) + target)); |
|
|
|
HttpGet httpget = new HttpGet(buildWebUIUrl(RPC_URL_DISPATCH + action + RPC_URL_DISPATCH2 + RPC_URL_AID |
|
|
|
|
|
|
|
+ (action.equals("urlUpload") ? RPC_URL_URL : RPC_URL_TRANSFER) + target)); |
|
|
|
HttpResponse response = httpclient.execute(httpget); |
|
|
|
HttpResponse response = httpclient.execute(httpget); |
|
|
|
|
|
|
|
|
|
|
|
// Read response (a successful action always returned '1')
|
|
|
|
// Read response (a successful action always returned '1')
|
|
|
@ -261,15 +261,22 @@ public class Tfb4rtAdapter implements IDaemonAdapter { |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Build the URL of specific Torrentflux site request from the user settings and some requested action. |
|
|
|
* Build the URL of specific Torrentflux site request from the user settings and some requested action. |
|
|
|
* @param act The action to perform, which is an already build query string without usernmae/password, i.e. dispatcher.php?action=stop&transfer=ubuntu.torrent |
|
|
|
* @param act The action to perform, which is an already build query string without usernmae/password, i.e. |
|
|
|
* @return The URL of a specific request, i.e. http://localhost:80/turrentflux/dispatcher.php?action=stop&transfer=ubuntu.torrent&username=admin&md5pass=asd98as7d
|
|
|
|
* dispatcher.php?action=stop&transfer=ubuntu.torrent |
|
|
|
|
|
|
|
* @return The URL of a specific request, i.e. |
|
|
|
|
|
|
|
* http://localhost:80/turrentflux/dispatcher.php?action=stop&transfer=ubuntu
|
|
|
|
|
|
|
|
* .torrent&username=admin&md5pass=asd98as7d |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
private String buildWebUIUrl(String act) { |
|
|
|
private String buildWebUIUrl(String act) { |
|
|
|
String folder = settings.getFolder().endsWith("/")? |
|
|
|
String folder = ""; |
|
|
|
settings.getFolder().substring(0, settings.getFolder().length() - 1): |
|
|
|
if (settings.getFolder() != null) { |
|
|
|
settings.getFolder(); |
|
|
|
folder = settings.getFolder(); |
|
|
|
return (settings.getSsl() ? "https://" : "http://") + settings.getAddress() + ":" + settings.getPort() + |
|
|
|
if (folder.endsWith("/")) |
|
|
|
folder + act + RPC_URL_USER + settings.getUsername() + RPC_URL_PASS + md5Pass((settings.getPassword() == null? "": settings.getPassword())); |
|
|
|
folder = folder.substring(0, folder.length() - 1); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return (settings.getSsl() ? "https://" : "http://") + settings.getAddress() + ":" + settings.getPort() + folder |
|
|
|
|
|
|
|
+ act + RPC_URL_USER + settings.getUsername() + RPC_URL_PASS |
|
|
|
|
|
|
|
+ md5Pass((settings.getPassword() == null ? "" : settings.getPassword())); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|