Search in sources :

Example 1 with IPCInterface

use of com.biglybt.pif.ipc.IPCInterface in project BiglyBT by BiglySoftware.

the class DeviceManagerImpl method getStreamURL.

protected URL getStreamURL(TranscodeFileImpl file, String host) {
    IPCInterface ipc = upnp_manager.getUPnPAVIPC();
    if (ipc != null) {
        try {
            DiskManagerFileInfo f = file.getTargetFile();
            String str = (String) ipc.invoke("getContentURL", new Object[] { f });
            if (str != null && str.length() > 0) {
                if (host != null) {
                    str = str.replace("127.0.0.1", host);
                }
                return (new URL(str));
            }
        } catch (Throwable e) {
        }
    }
    return (null);
}
Also used : DiskManagerFileInfo(com.biglybt.pif.disk.DiskManagerFileInfo) IPCInterface(com.biglybt.pif.ipc.IPCInterface) URL(java.net.URL)

Example 2 with IPCInterface

use of com.biglybt.pif.ipc.IPCInterface in project BiglyBT by BiglySoftware.

the class DeviceManagerImpl method getMimeType.

protected String getMimeType(TranscodeFileImpl file) {
    if (getMimeType_fails > 5) {
        return (null);
    }
    IPCInterface ipc = upnp_manager.getUPnPAVIPC();
    if (ipc != null) {
        try {
            DiskManagerFileInfo f = file.getTargetFile();
            String[] strs = (String[]) ipc.invoke("getMimeTypes", new Object[] { f });
            if (strs != null && strs.length > 0) {
                return (strs[0]);
            }
        } catch (Throwable e) {
            getMimeType_fails++;
            e.printStackTrace();
        }
    }
    return (null);
}
Also used : DiskManagerFileInfo(com.biglybt.pif.disk.DiskManagerFileInfo) IPCInterface(com.biglybt.pif.ipc.IPCInterface)

Example 3 with IPCInterface

use of com.biglybt.pif.ipc.IPCInterface in project BiglyBT by BiglySoftware.

the class DeviceManagerUPnPImpl method addListener.

protected void addListener(PluginInterface pi) {
    try {
        IPCInterface my_ipc = new IPCInterfaceImpl(new Object() {

            public Map<String, Object> browseReceived(TrackerWebPageRequest request, Map<String, Object> browser_args) {
                Map headers = request.getHeaders();
                String user_agent = (String) headers.get("user-agent");
                String client_info = (String) headers.get("x-av-client-info");
                InetSocketAddress client_address = request.getClientAddress2();
                DeviceMediaRenderer explicit_renderer = null;
                boolean handled = false;
                if (user_agent != null) {
                    String lc_agent = user_agent.toLowerCase();
                    if (lc_agent.contains("playstation 3")) {
                        handlePS3(client_address);
                        handled = true;
                    } else if (lc_agent.contains("xbox")) {
                        handleXBox(client_address);
                        handled = true;
                    } else if (lc_agent.contains("nintendo wii")) {
                        handleWii(client_address);
                        handled = true;
                    }
                }
                if (client_info != null) {
                    String lc_info = client_info.toLowerCase();
                    if (lc_info.contains("playstation 3")) {
                        handlePS3(client_address);
                        handled = true;
                    } else if (lc_info.contains("azureus") || lc_info.contains("vuze") || lc_info.contains("biglybt")) {
                        explicit_renderer = handleVuzeMSBrowser(client_address, client_info);
                        handled = true;
                    }
                }
                if (!handled) {
                    handled = manager.browseReceived(request, browser_args);
                }
                if (!handled) {
                    String source = (String) browser_args.get("source");
                    if (source != null && source.equalsIgnoreCase("http")) {
                        handleBrowser(client_address);
                        handled = true;
                    }
                }
                /**
                 *							System.out.println(
                 *									"Received browse: " + request.getClientAddress() +
                 *									", agent=" + user_agent +
                 *									", info=" + client_info +
                 *									", handled=" + handled + ", " + request.getURL());
                 *									System.out.println("\n\n");
                 *								/*
                 */
                DeviceImpl[] devices = manager.getDevices();
                final List<DeviceMediaRendererImpl> browse_devices = new ArrayList<>();
                boolean restrict_access = false;
                for (DeviceImpl device : devices) {
                    if (device instanceof DeviceMediaRendererImpl) {
                        DeviceMediaRendererImpl renderer = (DeviceMediaRendererImpl) device;
                        if (explicit_renderer != null) {
                            if (renderer != explicit_renderer) {
                                continue;
                            }
                        }
                        InetAddress device_address = renderer.getAddress();
                        try {
                            if (device_address != null) {
                                if (device_address.equals(client_address.getAddress())) {
                                    if (renderer.canFilterFilesView()) {
                                        boolean skip = false;
                                        if (renderer.canRestrictAccess()) {
                                            String restriction = renderer.getAccessRestriction().trim();
                                            if (restriction.length() > 0) {
                                                String x = client_address.getAddress().getHostAddress();
                                                skip = true;
                                                String[] ips = restriction.split(",");
                                                for (String ip : ips) {
                                                    if (ip.startsWith("-")) {
                                                        ip = ip.substring(1);
                                                        if (ip.equals(x)) {
                                                            break;
                                                        }
                                                    } else {
                                                        if (ip.startsWith("+")) {
                                                            ip = ip.substring(1);
                                                        }
                                                        if (ip.equals(x)) {
                                                            skip = false;
                                                            break;
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                        if (skip) {
                                            restrict_access = true;
                                            String host = client_address.getAddress().getHostAddress();
                                            synchronized (access_logs) {
                                                if (!access_logs.contains(host)) {
                                                    access_logs.add(host);
                                                    manager.log("Ignoring browse from " + host + " due to access restriction for '" + renderer.getName() + "'");
                                                }
                                            }
                                        }
                                        browse_devices.add(renderer);
                                        renderer.browseReceived();
                                    }
                                }
                            }
                        } catch (Throwable e) {
                            Debug.out(e);
                        }
                    }
                }
                Map<String, Object> result = new HashMap<>();
                if (browse_devices.size() > 0) {
                    synchronized (unassociated_devices) {
                        unassociated_devices.remove(client_address.getAddress());
                    }
                    final boolean f_restrict_access = restrict_access;
                    result.put("filter", new ContentFilter() {

                        @Override
                        public boolean isVisible(ContentDownload download, Map<String, Object> browse_args) {
                            if (f_restrict_access) {
                                return (false);
                            }
                            boolean visible = false;
                            for (DeviceUPnPImpl device : browse_devices) {
                                if (device.isVisible(download)) {
                                    visible = true;
                                }
                            }
                            return (visible);
                        }

                        @Override
                        public boolean isVisible(ContentFile file, Map<String, Object> browse_args) {
                            if (f_restrict_access) {
                                return (false);
                            }
                            boolean visible = false;
                            for (DeviceUPnPImpl device : browse_devices) {
                                if (device.isVisible(file)) {
                                    visible = true;
                                }
                            }
                            return (visible);
                        }
                    });
                } else {
                    if (request.getHeader().substring(0, 4).equalsIgnoreCase("POST")) {
                        synchronized (unassociated_devices) {
                            unassociated_devices.put(client_address.getAddress(), user_agent);
                        }
                    }
                }
                return (result);
            }
        });
        if (upnpav_ipc.canInvoke("addBrowseListener", new Object[] { my_ipc })) {
            DeviceImpl[] devices = manager.getDevices();
            for (DeviceImpl device : devices) {
                if (device instanceof DeviceUPnPImpl) {
                    DeviceUPnPImpl u_d = (DeviceUPnPImpl) device;
                    u_d.resetUPNPAV();
                }
            }
            upnpav_ipc.invoke("addBrowseListener", new Object[] { my_ipc });
        } else {
            manager.log("UPnPAV plugin needs upgrading");
        }
    } catch (Throwable e) {
        manager.log("Failed to hook into UPnPAV", e);
    }
}
Also used : ContentDownload(com.biglybt.core.content.ContentDownload) ContentFile(com.biglybt.core.content.ContentFile) TrackerWebPageRequest(com.biglybt.pif.tracker.web.TrackerWebPageRequest) InetSocketAddress(java.net.InetSocketAddress) IPCInterfaceImpl(com.biglybt.pifimpl.local.ipc.IPCInterfaceImpl) ContentFilter(com.biglybt.core.content.ContentFilter) DeviceMediaRenderer(com.biglybt.core.devices.DeviceMediaRenderer) IPCInterface(com.biglybt.pif.ipc.IPCInterface) InetAddress(java.net.InetAddress)

Example 4 with IPCInterface

use of com.biglybt.pif.ipc.IPCInterface in project BiglyBT by BiglySoftware.

the class Handler method getProxy.

private URL getProxy(URL u) throws IOException {
    PluginInterface pi = CoreFactory.getSingleton().getPluginManager().getPluginInterfaceByID("azwebtorrent");
    if (pi == null) {
        installPlugin();
        throw (new IOException("'WebTorrent Support Plugin' is required - go to 'Tools->Plugins->Installation Wizard' to install."));
    }
    IPCInterface ipc = pi.getIPC();
    try {
        URL url = (URL) ipc.invoke("getProxyURL", new Object[] { u });
        return (url);
    } catch (IPCException ipce) {
        Throwable e = ipce;
        if (e.getCause() != null) {
            e = e.getCause();
        }
        throw (new IOException("Communication error with WebTorrent Support Plugin: " + Debug.getNestedExceptionMessage(e)));
    }
}
Also used : PluginInterface(com.biglybt.pif.PluginInterface) IPCException(com.biglybt.pif.ipc.IPCException) IOException(java.io.IOException) IPCInterface(com.biglybt.pif.ipc.IPCInterface) URL(java.net.URL)

Example 5 with IPCInterface

use of com.biglybt.pif.ipc.IPCInterface in project BiglyBT by BiglySoftware.

the class TransferPanel2 method show.

/* (non-Javadoc)
   * @see com.biglybt.ui.swt.wizard.IWizardPanel#show()
   */
@Override
public void show() {
    wizard.setTitle(MessageText.getString("configureWizard.transfer.title"));
    wizard.setCurrentInfo(MessageText.getString("configureWizard.transfer2.hint"));
    final Composite rootPanel = wizard.getPanel();
    GridLayout layout = new GridLayout();
    layout.numColumns = 1;
    rootPanel.setLayout(layout);
    Composite panel = new Composite(rootPanel, SWT.NULL);
    GridData gridData = new GridData(GridData.FILL_BOTH);
    Utils.setLayoutData(panel, gridData);
    layout = new GridLayout();
    layout.numColumns = 2;
    panel.setLayout(layout);
    Label label = new Label(panel, SWT.WRAP);
    gridData = new GridData(GridData.FILL_HORIZONTAL);
    gridData.horizontalSpan = 2;
    Utils.setLayoutData(label, gridData);
    Messages.setLanguageText(label, "configureWizard.transfer2.message");
    final Group gRadio = new Group(panel, SWT.NULL);
    Messages.setLanguageText(gRadio, "configureWizard.transfer2.group");
    Utils.setLayoutData(gRadio, gridData);
    layout = new GridLayout();
    layout.numColumns = 2;
    gRadio.setLayout(layout);
    gridData = new GridData(GridData.FILL_HORIZONTAL);
    gridData.horizontalSpan = 2;
    Utils.setLayoutData(gRadio, gridData);
    // auto button
    Button auto_button = new Button(gRadio, SWT.RADIO);
    Messages.setLanguageText(auto_button, "auto.mode");
    auto_button.setSelection(true);
    new Label(gRadio, SWT.NULL);
    // speed test button
    label = new Label(gRadio, SWT.NULL);
    Messages.setLanguageText(label, "configureWizard.transfer2.test.info");
    final Button speed_test = new Button(gRadio, SWT.NULL);
    Messages.setLanguageText(speed_test, "configureWizard.transfer2.test");
    final SelectionAdapter speed_test_listener = new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent arg0) {
            speed_test.setEnabled(false);
            test_in_progress = true;
            updateNextEnabled();
            rootPanel.getShell().setEnabled(false);
            UIFunctionsManager.getUIFunctions().installPlugin("mlab", "dlg.install.mlab", new UIFunctions.actionListener() {

                @Override
                public void actionComplete(Object result) {
                    if (result instanceof Boolean) {
                        PluginInterface pi = CoreFactory.getSingleton().getPluginManager().getPluginInterfaceByID("mlab");
                        if (pi == null) {
                            Debug.out("mlab plugin not found");
                            enableTest();
                        } else {
                            IPCInterface callback = new IPCInterface() {

                                @Override
                                public Object invoke(String methodName, Object[] params) {
                                    try {
                                        if (methodName.equals("results")) {
                                            Map<String, Object> results = (Map<String, Object>) params[0];
                                            Long up_rate = (Long) results.get("up");
                                            if (up_rate != null) {
                                                final int u = up_rate.intValue();
                                                if (u > 0) {
                                                    Utils.execSWTThread(new Runnable() {

                                                        @Override
                                                        public void run() {
                                                            updateUp(u, false);
                                                        }
                                                    });
                                                }
                                            }
                                        }
                                        return (null);
                                    } finally {
                                        enableTest();
                                    }
                                }

                                @Override
                                public boolean canInvoke(String methodName, Object[] params) {
                                    return (true);
                                }
                            };
                            try {
                                pi.getIPC().invoke("runTest", new Object[] { new HashMap<String, Object>(), callback, false });
                            } catch (Throwable e) {
                                Debug.out(e);
                                enableTest();
                            }
                        }
                    } else {
                        try {
                            Throwable error = (Throwable) result;
                            Debug.out(error);
                        } finally {
                            enableTest();
                        }
                    }
                }

                protected void enableTest() {
                    Utils.execSWTThread(new Runnable() {

                        @Override
                        public void run() {
                            speed_test.setEnabled(true);
                            test_in_progress = false;
                            updateNextEnabled();
                            rootPanel.getShell().setEnabled(true);
                        }
                    });
                }
            });
        }
    };
    speed_test.addSelectionListener(speed_test_listener);
    // manual
    final Button manual_button = new Button(gRadio, SWT.RADIO);
    Messages.setLanguageText(manual_button, "manual.mode");
    new Label(gRadio, SWT.NULL);
    // drop down speed selector
    final Label manual_label = new Label(gRadio, SWT.NULL);
    Messages.setLanguageText(manual_label, "configureWizard.transfer2.mselect");
    String[] connection_labels = new String[connection_rates.length];
    connection_labels[0] = MessageText.getString("configureWizard.transfer2.current");
    String dial_up = MessageText.getString("dial.up");
    for (int i = 1; i < connection_rates.length; i++) {
        connection_labels[i] = (i < 3 ? (dial_up + " ") : "xxx/") + DisplayFormatters.formatByteCountToBitsPerSec(connection_rates[i] / 8);
    }
    final Combo connection_speed = new Combo(gRadio, SWT.SINGLE | SWT.READ_ONLY);
    for (int i = 0; i < connection_rates.length; i++) {
        connection_speed.add(connection_labels[i]);
    }
    connection_speed.select(0);
    connection_speed.addListener(SWT.Selection, new Listener() {

        @Override
        public void handleEvent(Event arg0) {
            int index = connection_speed.getSelectionIndex();
            updateUp(connection_rates[index] / 8, true);
        }
    });
    final Label manual2_label = new Label(gRadio, SWT.WRAP);
    Messages.setLanguageText(manual2_label, "configureWizard.transfer2.mselect.info");
    gridData = new GridData(GridData.FILL_HORIZONTAL);
    gridData.horizontalSpan = 2;
    Utils.setLayoutData(manual2_label, gridData);
    Listener listener = new Listener() {

        @Override
        public void handleEvent(Event arg0) {
            boolean is_manual = manual_button.getSelection();
            speed_test.setEnabled(!is_manual);
            connection_speed.setEnabled(is_manual);
            manual_label.setEnabled(is_manual);
            manual2_label.setEnabled(is_manual);
            manual_mode = is_manual;
            updateNextEnabled();
        }
    };
    manual_button.addListener(SWT.Selection, listener);
    listener.handleEvent(null);
    uprate_label = new Label(panel, SWT.WRAP);
    gridData = new GridData(GridData.FILL_BOTH);
    gridData.verticalIndent = 10;
    Utils.setLayoutData(uprate_label, gridData);
    updateUp(0, true);
    manual_mode = false;
    updateNextEnabled();
    if (wizard.getWizardMode() == ConfigureWizard.WIZARD_MODE_SPEED_TEST_AUTO) {
        Utils.execSWTThreadLater(0, new Runnable() {

            @Override
            public void run() {
                speed_test_listener.widgetSelected(null);
            }
        });
    }
}
Also used : HashMap(java.util.HashMap) GridLayout(org.eclipse.swt.layout.GridLayout) UIFunctions(com.biglybt.ui.UIFunctions) SelectionEvent(org.eclipse.swt.events.SelectionEvent) IPCInterface(com.biglybt.pif.ipc.IPCInterface) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) PluginInterface(com.biglybt.pif.PluginInterface) GridData(org.eclipse.swt.layout.GridData) SelectionEvent(org.eclipse.swt.events.SelectionEvent) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

IPCInterface (com.biglybt.pif.ipc.IPCInterface)24 PluginInterface (com.biglybt.pif.PluginInterface)14 DHTPluginInterface (com.biglybt.plugin.dht.DHTPluginInterface)6 Map (java.util.Map)6 DiskManagerFileInfo (com.biglybt.pif.disk.DiskManagerFileInfo)5 URL (java.net.URL)5 HashMap (java.util.HashMap)5 ContentFile (com.biglybt.core.content.ContentFile)4 IPCException (com.biglybt.pif.ipc.IPCException)4 DiskManagerFileInfoURL (com.biglybt.core.download.DiskManagerFileInfoURL)3 File (java.io.File)3 AEThread2 (com.biglybt.core.util.AEThread2)2 UIFunctions (com.biglybt.ui.UIFunctions)2 IOException (java.io.IOException)2 ContentDownload (com.biglybt.core.content.ContentDownload)1 ContentFilter (com.biglybt.core.content.ContentFilter)1 DeviceMediaRenderer (com.biglybt.core.devices.DeviceMediaRenderer)1 DiskManagerPiece (com.biglybt.core.disk.DiskManagerPiece)1 DownloadManagerStateAttributeListener (com.biglybt.core.download.DownloadManagerStateAttributeListener)1 MessageText (com.biglybt.core.internat.MessageText)1