Search in sources :

Example 46 with PluginInterface

use of com.biglybt.pif.PluginInterface in project BiglyBT by BiglySoftware.

the class AZPluginConnection method connect.

@Override
public void connect() throws IOException {
    String url = getURL().toString();
    int pos = url.indexOf("?");
    if (pos == -1) {
        throw (new IOException("Malformed URL - ? missing"));
    }
    url = url.substring(pos + 1);
    String[] bits = url.split("&");
    Map args = new HashMap();
    for (int i = 0; i < bits.length; i++) {
        String bit = bits[i];
        String[] x = bit.split("=");
        if (x.length == 2) {
            String lhs = x[0];
            String rhs = UrlUtils.decode(x[1]);
            args.put(lhs.toLowerCase(), rhs);
        }
    }
    String plugin_id = (String) args.get("id");
    if (plugin_id == null) {
        throw (new IOException("Plugin id missing"));
    }
    String plugin_name = (String) args.get("name");
    String arg = (String) args.get("arg");
    if (arg == null) {
        arg = "";
    }
    String plugin_str;
    if (plugin_name == null) {
        plugin_str = "with id '" + plugin_id + "'";
    } else {
        plugin_str = "'" + plugin_name + "' (id " + plugin_id + ")";
    }
    if (plugin_id.equals("subscription")) {
        SubscriptionManager manager = SubscriptionManagerFactory.getSingleton();
        if (manager == null) {
            throw (new IOException("Subscriptions are not available"));
        }
        try {
            manager.subscribeToSubscription(arg);
            input_stream = new ByteArrayInputStream(VuzeFileHandler.getSingleton().create().exportToBytes());
        } catch (Throwable e) {
            throw (new IOException("Subscription addition failed: " + Debug.getNestedExceptionMessage(e)));
        }
    } else {
        // AZPluginConnection is called via reflection
        // Let's just assume that the Core is avail..
        PluginInterface pi = CoreFactory.getSingleton().getPluginManager().getPluginInterfaceByID(plugin_id);
        if (pi == null) {
            throw (new IOException("Plugin " + plugin_str + " is required - go to 'Tools->Plugins->Installation Wizard' to install."));
        }
        IPCInterface ipc = pi.getIPC();
        try {
            if (ipc.canInvoke("handleURLProtocol", new Object[] { this, arg })) {
                input_stream = (InputStream) ipc.invoke("handleURLProtocol", new Object[] { this, arg });
            } else {
                input_stream = (InputStream) ipc.invoke("handleURLProtocol", new Object[] { arg });
            }
        } catch (IPCException ipce) {
            Throwable e = ipce;
            if (e.getCause() != null) {
                e = e.getCause();
            }
            throw (new IOException("Communication error with plugin '" + plugin_str + "': " + Debug.getNestedExceptionMessage(e)));
        }
    }
}
Also used : HashMap(java.util.HashMap) ByteArrayInputStream(java.io.ByteArrayInputStream) PluginInterface(com.biglybt.pif.PluginInterface) IPCException(com.biglybt.pif.ipc.IPCException) IOException(java.io.IOException) SubscriptionManager(com.biglybt.core.subs.SubscriptionManager) HashMap(java.util.HashMap) Map(java.util.Map) IPCInterface(com.biglybt.pif.ipc.IPCInterface)

Example 47 with PluginInterface

use of com.biglybt.pif.PluginInterface in project BiglyBT by BiglySoftware.

the class InstallablePluginImpl method isAlreadyInstalled.

/**
 * Returns the plugin's interface if already installed, null if it isn't
 * @return
 */
@Override
public boolean isAlreadyInstalled() {
    PluginInterface pi = getAlreadyInstalledPlugin();
    if (pi == null) {
        return (false);
    }
    String version = getVersion();
    if (version == null || version.length() == 0) {
        return (false);
    }
    String existing_version = pi.getPluginVersion();
    if (existing_version == null) {
        return (true);
    }
    return (Constants.compareVersions(existing_version, version) >= 0);
}
Also used : PluginInterface(com.biglybt.pif.PluginInterface)

Example 48 with PluginInterface

use of com.biglybt.pif.PluginInterface in project BiglyBT by BiglySoftware.

the class DHTTrackerPlugin method initialize.

@Override
public void initialize(PluginInterface _plugin_interface) {
    plugin_interface = _plugin_interface;
    log = plugin_interface.getLogger().getTimeStampedChannel(PLUGIN_NAME);
    ta_networks = plugin_interface.getTorrentManager().getAttribute(TorrentAttribute.TA_NETWORKS);
    ta_peer_sources = plugin_interface.getTorrentManager().getAttribute(TorrentAttribute.TA_PEER_SOURCES);
    UIManager ui_manager = plugin_interface.getUIManager();
    model = ui_manager.createBasicPluginViewModel(PLUGIN_RESOURCE_ID);
    model.setConfigSectionID(PLUGIN_CONFIGSECTION_ID);
    BasicPluginConfigModel config = ui_manager.createBasicPluginConfigModel(ConfigSection.SECTION_PLUGINS, PLUGIN_CONFIGSECTION_ID);
    track_normal_when_offline = config.addBooleanParameter2("dhttracker.tracknormalwhenoffline", "dhttracker.tracknormalwhenoffline", TRACK_NORMAL_DEFAULT);
    track_limited_when_online = config.addBooleanParameter2("dhttracker.tracklimitedwhenonline", "dhttracker.tracklimitedwhenonline", TRACK_LIMITED_DEFAULT);
    track_limited_when_online.addListener(new ParameterListener() {

        @Override
        public void parameterChanged(Parameter param) {
            configChanged();
        }
    });
    track_normal_when_offline.addListener(new ParameterListener() {

        @Override
        public void parameterChanged(Parameter param) {
            track_limited_when_online.setEnabled(track_normal_when_offline.getValue());
            configChanged();
        }
    });
    if (!track_normal_when_offline.getValue()) {
        track_limited_when_online.setEnabled(false);
    }
    interesting_pub_max = plugin_interface.getPluginconfig().getPluginIntParameter("dhttracker.presencepubmax", INTERESTING_PUB_MAX_DEFAULT);
    if (!TRACK_NORMAL_DEFAULT) {
        // should be TRUE by default
        System.out.println("**** DHT Tracker default set for testing purposes ****");
    }
    BooleanParameter enable_alt = config.addBooleanParameter2("dhttracker.enable_alt", "dhttracker.enable_alt", true);
    IntParameter alt_port = config.addIntParameter2("dhttracker.alt_port", "dhttracker.alt_port", 0, 0, 65535);
    enable_alt.addEnabledOnSelection(alt_port);
    config.createGroup("dhttracker.alt_group", new Parameter[] { enable_alt, alt_port });
    if (enable_alt.getValue()) {
        alt_lookup_handler = new DHTTrackerPluginAlt(alt_port.getValue());
    }
    model.getActivity().setVisible(false);
    model.getProgress().setVisible(false);
    model.getLogArea().setMaximumSize(80000);
    log.addListener(new LoggerChannelListener() {

        @Override
        public void messageLogged(int type, String message) {
            model.getLogArea().appendText(message + "\n");
        }

        @Override
        public void messageLogged(String str, Throwable error) {
            model.getLogArea().appendText(error.toString() + "\n");
        }
    });
    model.getStatus().setText(MessageText.getString("ManagerItem.initializing"));
    log.log("Waiting for Distributed Database initialisation");
    plugin_interface.addListener(new PluginListener() {

        @Override
        public void initializationComplete() {
            boolean release_now = true;
            try {
                final PluginInterface dht_pi = plugin_interface.getPluginManager().getPluginInterfaceByClass(DHTPlugin.class);
                if (dht_pi != null) {
                    dht = (DHTPlugin) dht_pi.getPlugin();
                    final DelayedTask dt = plugin_interface.getUtilities().createDelayedTask(new Runnable() {

                        @Override
                        public void run() {
                            AEThread2 t = new AEThread2("DHTTrackerPlugin:init", true) {

                                @Override
                                public void run() {
                                    try {
                                        if (dht.isEnabled()) {
                                            log.log("DDB Available");
                                            model.getStatus().setText(MessageText.getString("DHTView.activity.status.false"));
                                            initialise();
                                        } else {
                                            log.log("DDB Disabled");
                                            model.getStatus().setText(MessageText.getString("dht.status.disabled"));
                                            notRunning();
                                        }
                                    } catch (Throwable e) {
                                        log.log("DDB Failed", e);
                                        model.getStatus().setText(MessageText.getString("DHTView.operations.failed"));
                                        notRunning();
                                    } finally {
                                        initialised_sem.releaseForever();
                                    }
                                }
                            };
                            t.start();
                        }
                    });
                    dt.queue();
                    release_now = false;
                } else {
                    log.log("DDB Plugin missing");
                    model.getStatus().setText(MessageText.getString("DHTView.operations.failed"));
                    notRunning();
                }
            } finally {
                if (release_now) {
                    initialised_sem.releaseForever();
                }
            }
        }

        @Override
        public void closedownInitiated() {
        }

        @Override
        public void closedownComplete() {
        }
    });
}
Also used : LoggerChannelListener(com.biglybt.pif.logging.LoggerChannelListener) PluginInterface(com.biglybt.pif.PluginInterface) UIManager(com.biglybt.pif.ui.UIManager) PluginListener(com.biglybt.pif.PluginListener) DelayedTask(com.biglybt.pif.utils.DelayedTask) DHTPlugin(com.biglybt.plugin.dht.DHTPlugin) BasicPluginConfigModel(com.biglybt.pif.ui.model.BasicPluginConfigModel)

Example 49 with PluginInterface

use of com.biglybt.pif.PluginInterface in project BiglyBT by BiglySoftware.

the class BuddyPluginBeta method startup.

protected void startup() {
    plugin_interface.addEventListener(new PluginEventListener() {

        @Override
        public void handleEvent(PluginEvent ev) {
            int type = ev.getType();
            if (type == PluginEvent.PEV_INITIAL_SHARING_COMPLETE) {
                try {
                    ShareManager share_manager = plugin_interface.getShareManager();
                    share_manager.addListener(new ShareManagerListener() {

                        @Override
                        public void resourceModified(ShareResource old_resource, ShareResource new_resource) {
                            checkTag(new_resource);
                        }

                        @Override
                        public void resourceDeleted(ShareResource resource) {
                        }

                        @Override
                        public void resourceAdded(ShareResource resource) {
                            checkTag(resource);
                        }

                        @Override
                        public void reportProgress(int percent_complete) {
                        }

                        @Override
                        public void reportCurrentTask(String task_description) {
                        }
                    });
                    ShareResource[] existing = share_manager.getShares();
                    for (ShareResource sr : existing) {
                        checkTag(sr);
                    }
                } catch (Throwable e) {
                    Debug.out(e);
                }
            } else if (type == PluginEvent.PEV_PLUGIN_OPERATIONAL) {
                pluginAdded((PluginInterface) ev.getValue());
            } else if (type == PluginEvent.PEV_PLUGIN_NOT_OPERATIONAL) {
                pluginRemoved((PluginInterface) ev.getValue());
            }
        }
    });
    PluginInterface[] plugins = plugin_interface.getPluginManager().getPlugins(true);
    for (PluginInterface pi : plugins) {
        if (pi.getPluginState().isOperational()) {
            pluginAdded(pi);
        }
    }
}
Also used : PluginEventListener(com.biglybt.pif.PluginEventListener) PluginInterface(com.biglybt.pif.PluginInterface) PluginEvent(com.biglybt.pif.PluginEvent)

Example 50 with PluginInterface

use of com.biglybt.pif.PluginInterface in project BiglyBT by BiglySoftware.

the class BuddyPluginAZ2 method processAZ2Request.

protected Map processAZ2Request(final BuddyPluginBuddy from_buddy, Map request) throws BuddyPluginException {
    logMessage("AZ2 request received: " + from_buddy.getString() + " -> " + request);
    int type = ((Long) request.get("type")).intValue();
    Map reply = new HashMap();
    if (type == RT_AZ2_REQUEST_MESSAGE) {
        try {
            String msg = new String((byte[]) request.get("msg"), "UTF8");
            from_buddy.setLastMessageReceived(msg);
        } catch (Throwable e) {
        }
        reply.put("type", new Long(RT_AZ2_REPLY_MESSAGE));
    } else if (type == RT_AZ2_REQUEST_SEND_TORRENT) {
        try {
            final Torrent torrent = plugin.getPluginInterface().getTorrentManager().createFromBEncodedData((byte[]) request.get("torrent"));
            new AEThread2("torrentAdder", true) {

                @Override
                public void run() {
                    PluginInterface pi = plugin.getPluginInterface();
                    String msg = pi.getUtilities().getLocaleUtilities().getLocalisedMessageText("azbuddy.addtorrent.msg", new String[] { from_buddy.getName(), torrent.getName() });
                    long res = pi.getUIManager().showMessageBox("azbuddy.addtorrent.title", "!" + msg + "!", UIManagerEvent.MT_YES | UIManagerEvent.MT_NO);
                    if (res == UIManagerEvent.MT_YES) {
                        pi.getUIManager().openTorrent(torrent);
                    }
                }
            }.start();
            reply.put("type", new Long(RT_AZ2_REPLY_SEND_TORRENT));
        } catch (Throwable e) {
            throw (new BuddyPluginException("Torrent receive failed " + type));
        }
    } else if (type == RT_AZ2_REQUEST_CHAT) {
        Map msg = (Map) request.get("msg");
        String id = new String((byte[]) msg.get("id"));
        chatInstance chat;
        boolean new_chat = false;
        synchronized (chats) {
            chat = (chatInstance) chats.get(id);
            if (chat == null) {
                if (chats.size() > 32) {
                    throw (new BuddyPluginException("Too many chats"));
                }
                chat = new chatInstance(id);
                chats.put(id, chat);
                new_chat = true;
            }
        }
        if (new_chat) {
            informCreated(chat);
        }
        chat.addParticipant(from_buddy);
        chat.process(from_buddy, msg);
        reply.put("type", new Long(RT_AZ2_REPLY_CHAT));
    } else if (type == RT_AZ2_REQUEST_TRACK) {
        Map msg = (Map) request.get("msg");
        Iterator it = track_listeners.iterator();
        boolean ok = false;
        while (it.hasNext()) {
            try {
                Map res = ((BuddyPluginAZ2TrackerListener) it.next()).messageReceived(from_buddy, msg);
                if (res != null) {
                    reply.put("msg", res);
                    reply.put("type", new Long(RT_AZ2_REPLY_TRACK));
                    ok = true;
                    break;
                }
            } catch (Throwable e) {
                Debug.printStackTrace(e);
            }
        }
        if (!ok) {
            throw (new BuddyPluginException("Unhandled request type " + type));
        }
    } else if (type == RT_AZ2_REQUEST_RSS) {
        try {
            Map<String, Object> res = new HashMap<>();
            reply.put("msg", res);
            reply.put("type", new Long(RT_AZ2_REPLY_RSS));
            Map msg = (Map) request.get("msg");
            String category = new String((byte[]) msg.get("cat"), "UTF-8");
            byte[] hash = (byte[]) msg.get("hash");
            if (hash == null) {
                byte[] if_mod = (byte[]) msg.get("if_mod");
                BuddyPlugin.feedDetails feed = plugin.getRSS(from_buddy, category, if_mod == null ? null : new String(if_mod, "UTF-8"));
                res.put("rss", feed.getContent());
                res.put("last_mod", feed.getLastModified());
            } else {
                res.put("torrent", plugin.getRSSTorrent(from_buddy, category, hash));
            }
        } catch (BuddyPluginException e) {
            throw (e);
        } catch (Throwable e) {
            throw (new BuddyPluginException("Failed to handle rss", e));
        }
    } else {
        throw (new BuddyPluginException("Unrecognised request type " + type));
    }
    logMessage("AZ2 reply sent: " + from_buddy.getString() + " <- " + reply);
    return (reply);
}
Also used : Torrent(com.biglybt.pif.torrent.Torrent) PluginInterface(com.biglybt.pif.PluginInterface)

Aggregations

PluginInterface (com.biglybt.pif.PluginInterface)120 URL (java.net.URL)15 IPCInterface (com.biglybt.pif.ipc.IPCInterface)14 UIManager (com.biglybt.pif.ui.UIManager)13 PluginManager (com.biglybt.pif.PluginManager)12 HashMap (java.util.HashMap)12 List (java.util.List)12 Download (com.biglybt.pif.download.Download)10 MenuItemListener (com.biglybt.pif.ui.menus.MenuItemListener)10 File (java.io.File)10 Map (java.util.Map)10 DownloadManager (com.biglybt.core.download.DownloadManager)9 UIFunctions (com.biglybt.ui.UIFunctions)9 ArrayList (java.util.ArrayList)9 PluginException (com.biglybt.pif.PluginException)8 MenuItem (com.biglybt.pif.ui.menus.MenuItem)8 MenuManager (com.biglybt.pif.ui.menus.MenuManager)8 DHTPlugin (com.biglybt.plugin.dht.DHTPlugin)8 DHT (com.biglybt.core.dht.DHT)7 SelectionEvent (org.eclipse.swt.events.SelectionEvent)7