Skip to content

Commit 440e020

Browse files
committed
Added SimpleAPI plugin method to set download plugin options
1 parent 277173d commit 440e020

File tree

3 files changed

+114
-0
lines changed

3 files changed

+114
-0
lines changed

core/src/com/biglybt/core/download/DownloadManagerState.java

+1
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@
9494
public static final String AT_SWARM_TAGS = "stag"; // list
9595
public static final String AT_MASK_DL_COMP_OPTIONAL = "mdlc"; // Boolean (optional)
9696
public static final String AT_REAL_DM_MAGNET_TIME = "rdmmt"; // long
97+
public static final String AT_PLUGIN_OPTIONS = "pluginoptions"; // Map; enabled=boolean
9798

9899
public static final String AT_TRANSIENT_FLAGS = "t_flags";
99100
public static final String AT_TRANSIENT_TAG_SORT = "t_tagsort";

core/src/com/biglybt/pifimpl/local/download/DownloadImpl.java

+37
Original file line numberDiff line numberDiff line change
@@ -1675,6 +1675,43 @@ void announceTrackerResultsToListener(DownloadTrackerListener l) {
16751675
{
16761676
String class_name = getTrackingName( result );
16771677

1678+
if ( class_name != null ){
1679+
1680+
Map all_opts = download_manager.getDownloadState().getMapAttribute( DownloadManagerState.AT_PLUGIN_OPTIONS );
1681+
1682+
if ( all_opts != null ){
1683+
1684+
Map opts = (Map)all_opts.get( class_name.toLowerCase( Locale.US ));
1685+
1686+
if ( opts != null ){
1687+
1688+
Number e = (Number)opts.get( "enableannounce" );
1689+
1690+
if ( e != null && e.intValue() == 0 ){
1691+
1692+
boolean inform = false;
1693+
1694+
try{
1695+
peer_listeners_mon.enter();
1696+
1697+
inform = announce_response_map.remove( class_name ) != null;
1698+
1699+
}finally{
1700+
1701+
peer_listeners_mon.exit();
1702+
}
1703+
1704+
if ( inform ){
1705+
1706+
download_manager.informTPSChanged();
1707+
}
1708+
1709+
return;
1710+
}
1711+
}
1712+
}
1713+
}
1714+
16781715
boolean new_entry = false;
16791716

16801717
if ( class_name != null ){

core/src/com/biglybt/plugin/simpleapi/SimpleAPIPlugin.java

+76
Original file line numberDiff line numberDiff line change
@@ -805,6 +805,82 @@
805805

806806
dm.getDownloadState().setFlag( DownloadManagerState.FLAG_DISABLE_IP_FILTER, !enable );
807807

808+
}else if ( name.equals( "pluginoption" )){
809+
810+
String[] opt_strs = value.split( "&" );
811+
812+
String plugin_id = null;
813+
Boolean enable_announce = null;
814+
815+
for ( String opt_str: opt_strs ){
816+
817+
String[] bits = opt_str.split( "=" );
818+
819+
String opt_name = bits[0].toLowerCase( Locale.US );
820+
String opt_value;
821+
822+
if ( bits.length == 2 ){
823+
824+
opt_value = UrlUtils.decode( bits[1] );
825+
826+
}else{
827+
828+
opt_value = "";
829+
}
830+
831+
if ( opt_name.equals( "id" )){
832+
833+
plugin_id = opt_value;
834+
835+
}else if ( opt_name.equals( "enableannounce" )){
836+
837+
enable_announce = getBoolean( opt_value );
838+
}
839+
}
840+
841+
if ( plugin_id == null ){
842+
843+
throw( new Exception( "Plugin id parameter missing" ));
844+
}
845+
846+
PluginInterface pi = plugin_interface.getPluginManager().getPluginInterfaceByID( plugin_id );
847+
848+
if ( pi == null ){
849+
850+
throw( new Exception( "Plugin id '" + plugin_id + "' not found" ));
851+
}
852+
853+
if ( enable_announce == null ){
854+
855+
throw( new Exception( "No plugin options supplied" ));
856+
}
857+
858+
plugin_id = plugin_id.toLowerCase( Locale.US );
859+
860+
Map opts_map = dm.getDownloadState().getMapAttribute( DownloadManagerState.AT_PLUGIN_OPTIONS );
861+
862+
if ( opts_map == null ){
863+
864+
opts_map = new HashMap<>();
865+
866+
}else{
867+
868+
opts_map = BEncoder.cloneMap(opts_map);
869+
}
870+
871+
Map opt_map = (Map)opts_map.get( plugin_id );
872+
873+
if ( opt_map == null ){
874+
875+
opt_map = new HashMap<>();
876+
877+
opts_map.put( plugin_id, opt_map );
878+
}
879+
880+
opt_map.put( "enableannounce", enable_announce?1:0 );
881+
882+
dm.getDownloadState().setMapAttribute( DownloadManagerState.AT_PLUGIN_OPTIONS, opts_map );
883+
808884
}else{
809885

810886
throw( new Exception( "invalid 'name' parameter (" + name + ")" ));

0 commit comments

Comments
 (0)