X-Git-Url: http://git.nikiroo.be/?p=nikiroo-utils.git;a=blobdiff_plain;f=Main.java;h=35365444682489d81adf7b25ed864416d6c47abe;hp=7be305a0977abc17c0fd227f10d1f18c97dca70a;hb=258e065f81071a861711ef935dca3ec5563f4360;hpb=5f3671e17febc5b7f6abbfc62c66c4045d47ec8d diff --git a/Main.java b/Main.java index 7be305a..3536544 100644 --- a/Main.java +++ b/Main.java @@ -19,6 +19,7 @@ import be.nikiroo.fanfix.library.CacheLibrary; import be.nikiroo.fanfix.library.LocalLibrary; import be.nikiroo.fanfix.library.RemoteLibrary; import be.nikiroo.fanfix.library.RemoteLibraryServer; +import be.nikiroo.fanfix.library.WebLibrary; import be.nikiroo.fanfix.library.WebLibraryServer; import be.nikiroo.fanfix.output.BasicOutput; import be.nikiroo.fanfix.output.BasicOutput.OutputType; @@ -351,7 +352,14 @@ public class Main { } else if (port == null) { port = Integer.parseInt(args[i]); - BasicLibrary lib = new RemoteLibrary(key, host, port); + BasicLibrary lib; + if (host.startsWith("http://") + || host.startsWith("https://")) { + lib = new WebLibrary(key, host, port); + } else { + lib = new RemoteLibrary(key, host, port); + } + lib = new CacheLibrary( Instance.getInstance().getRemoteDir(host), lib, Instance.getInstance().getUiConfig()); @@ -635,10 +643,36 @@ public class Main { break; case STOP_SERVER: // Can be given via "--remote XX XX XX" - if (key == null) - key = Instance.getInstance().getConfig().getString(Config.SERVER_KEY); - if (port == null) + if (key == null) { + key = Instance.getInstance().getConfig() + .getString(Config.SERVER_KEY); + + // If a subkey in RW mode exists, use it + for (String subkey : Instance.getInstance().getConfig() + .getList(Config.SERVER_ALLOWED_SUBKEYS, + new ArrayList())) { + if ((subkey + "|").contains("|rw|")) { + key = key + "|" + subkey; + break; + } + } + } + + if (port == null) { port = Instance.getInstance().getConfig().getInteger(Config.SERVER_PORT); + } + + if (host == null) { + String mode = Instance.getInstance().getConfig() + .getString(Config.SERVER_MODE, "fanfix"); + if ("http".equals(mode)) { + host = "http://localhost"; + } else if ("https".equals(mode)) { + host = "https://localhost"; + } else if ("fanfix".equals(mode)) { + host = "fanfix://localhost"; + } + } if (port == null) { System.err.println("No port given nor configured in the config file"); @@ -1061,7 +1095,7 @@ public class Main { * @param key * the key to contact the Fanfix server * @param host - * the host on which it runs (NULL means localhost) + * the host on which it runs * @param port * the port on which it runs * @@ -1070,10 +1104,13 @@ public class Main { * @throws SSLException * when the key was not accepted */ - private void stopServer( - String key, String host, Integer port) + private void stopServer(String key, String host, int port) throws IOException, SSLException { - new RemoteLibrary(key, host, port).exit(); + if (host.startsWith("http://") || host.startsWith("https://")) { + new WebLibrary(key, host, port).stop(); + } else { + new RemoteLibrary(key, host, port).stop(); + } } /**