X-Git-Url: http://git.nikiroo.be/?a=blobdiff_plain;f=src%2Fbe%2Fnikiroo%2Ffanfix%2Flibrary%2FRemoteLibrary.java;h=63e45efc63b2977571eaacc18a133bc9cee3597d;hb=3358927d64264e9b8dafa794450057b0ea61365f;hp=884eee9a114d2c40853fb6659044bf4b0b3122e9;hpb=ea734ab478afa830550dd63800e855618a4cab4d;p=fanfix.git diff --git a/src/be/nikiroo/fanfix/library/RemoteLibrary.java b/src/be/nikiroo/fanfix/library/RemoteLibrary.java index 884eee9..63e45ef 100644 --- a/src/be/nikiroo/fanfix/library/RemoteLibrary.java +++ b/src/be/nikiroo/fanfix/library/RemoteLibrary.java @@ -12,7 +12,6 @@ import be.nikiroo.fanfix.data.MetaData; import be.nikiroo.fanfix.data.Story; import be.nikiroo.utils.Image; import be.nikiroo.utils.Progress; -import be.nikiroo.utils.StringUtils; import be.nikiroo.utils.Version; import be.nikiroo.utils.serial.server.ConnectActionClientObject; @@ -58,11 +57,11 @@ public class RemoteLibrary extends BasicLibrary { try { Instance.getTraceHandler().trace("Getting remote lib status..."); - new ConnectActionClientObject(host, port, false) { + new ConnectActionClientObject(host, port, key) { @Override public void action(Version serverVersion) throws Exception { try { - Object rep = sendCmd(this, new Object[] { "PING" }); + Object rep = send(new Object[] { "PING" }); if ("PONG".equals(rep)) { result[0] = Status.READY; @@ -96,11 +95,10 @@ public class RemoteLibrary extends BasicLibrary { final Image[] result = new Image[1]; try { - new ConnectActionClientObject(host, port, false) { + new ConnectActionClientObject(host, port, key) { @Override public void action(Version serverVersion) throws Exception { - Object rep = sendCmd(this, - new Object[] { "GET_COVER", luid }); + Object rep = send(new Object[] { "GET_COVER", luid }); result[0] = (Image) rep; } @@ -131,11 +129,11 @@ public class RemoteLibrary extends BasicLibrary { final Image[] result = new Image[1]; try { - new ConnectActionClientObject(host, port, false) { + new ConnectActionClientObject(host, port, key) { @Override public void action(Version serverVersion) throws Exception { - Object rep = sendCmd(this, - new Object[] { "GET_CUSTOM_COVER", type, source }); + Object rep = send(new Object[] { "GET_CUSTOM_COVER", type, + source }); result[0] = (Image) rep; } @@ -157,7 +155,7 @@ public class RemoteLibrary extends BasicLibrary { final Story[] result = new Story[1]; try { - new ConnectActionClientObject(host, port, false) { + new ConnectActionClientObject(host, port, key) { @Override public void action(Version serverVersion) throws Exception { Progress pg = pgF; @@ -165,8 +163,7 @@ public class RemoteLibrary extends BasicLibrary { pg = new Progress(); } - Object rep = sendCmd(this, - new Object[] { "GET_STORY", luid }); + Object rep = send(new Object[] { "GET_STORY", luid }); MetaData meta = null; if (rep instanceof MetaData) { @@ -177,8 +174,7 @@ public class RemoteLibrary extends BasicLibrary { } List list = new ArrayList(); - for (Object obj = send(null); obj != null; obj = send( - null)) { + for (Object obj = send(null); obj != null; obj = send(null)) { list.add(obj); pg.add(1); } @@ -215,7 +211,7 @@ public class RemoteLibrary extends BasicLibrary { final Progress pgF = pgSave; - new ConnectActionClientObject(host, port, false) { + new ConnectActionClientObject(host, port, key) { @Override public void action(Version serverVersion) throws Exception { Progress pg = pgF; @@ -223,7 +219,7 @@ public class RemoteLibrary extends BasicLibrary { pg.setMinMax(0, (int) story.getMeta().getWords()); } - sendCmd(this, new Object[] { "SAVE_STORY", luid }); + send(new Object[] { "SAVE_STORY", luid }); List list = RemoteLibraryServer.breakStory(story); for (Object obj : list) { @@ -260,10 +256,10 @@ public class RemoteLibrary extends BasicLibrary { @Override public synchronized void delete(final String luid) throws IOException { - new ConnectActionClientObject(host, port, false) { + new ConnectActionClientObject(host, port, key) { @Override public void action(Version serverVersion) throws Exception { - sendCmd(this, new Object[] { "DELETE_STORY", luid }); + send(new Object[] { "DELETE_STORY", luid }); } @Override @@ -287,11 +283,10 @@ public class RemoteLibrary extends BasicLibrary { private void setCover(final String value, final String luid, final String type) { try { - new ConnectActionClientObject(host, port, false) { + new ConnectActionClientObject(host, port, key) { @Override public void action(Version serverVersion) throws Exception { - sendCmd(this, - new Object[] { "SET_COVER", type, value, luid }); + send(new Object[] { "SET_COVER", type, value, luid }); } @Override @@ -328,13 +323,12 @@ public class RemoteLibrary extends BasicLibrary { final String[] luid = new String[1]; try { - new ConnectActionClientObject(host, port, false) { + new ConnectActionClientObject(host, port, key) { @Override public void action(Version serverVersion) throws Exception { Progress pg = pgF; - Object rep = sendCmd(this, - new Object[] { "IMPORT", url.toString() }); + Object rep = send(new Object[] { "IMPORT", url.toString() }); while (true) { if (!RemoteLibraryServer.updateProgress(pg, rep)) { @@ -376,13 +370,13 @@ public class RemoteLibrary extends BasicLibrary { final Progress pgF = pg == null ? new Progress() : pg; try { - new ConnectActionClientObject(host, port, false) { + new ConnectActionClientObject(host, port, key) { @Override public void action(Version serverVersion) throws Exception { Progress pg = pgF; - Object rep = sendCmd(this, new Object[] { "CHANGE_STA", - luid, newSource, newTitle, newAuthor }); + Object rep = send(new Object[] { "CHANGE_STA", luid, + newSource, newTitle, newAuthor }); while (true) { if (!RemoteLibraryServer.updateProgress(pg, rep)) { break; @@ -413,10 +407,10 @@ public class RemoteLibrary extends BasicLibrary { */ public void exit() { try { - new ConnectActionClientObject(host, port, false) { + new ConnectActionClientObject(host, port, key) { @Override public void action(Version serverVersion) throws Exception { - sendCmd(this, new Object[] { "EXIT" }); + send(new Object[] { "EXIT" }); } @Override @@ -492,7 +486,7 @@ public class RemoteLibrary extends BasicLibrary { final List metas = new ArrayList(); try { - new ConnectActionClientObject(host, port, false) { + new ConnectActionClientObject(host, port, key) { @Override public void action(Version serverVersion) throws Exception { Progress pg = pgF; @@ -500,9 +494,7 @@ public class RemoteLibrary extends BasicLibrary { pg = new Progress(); } - - Object rep = sendCmd(this, - new Object[] { "GET_METADATA", luid }); + Object rep = send(new Object[] { "GET_METADATA", luid }); while (true) { if (!RemoteLibraryServer.updateProgress(pg, rep)) { @@ -532,35 +524,4 @@ public class RemoteLibrary extends BasicLibrary { return metas; } - - // IllegalArgumentException if key is bad - private Object sendCmd(ConnectActionClientObject action, Object[] params) - throws IOException, NoSuchFieldException, NoSuchMethodException, - ClassNotFoundException { - Object rep = action.send(params); - - String hash = hashKey(key, "" + rep); - rep = action.send(hash); - if (rep == null) { - throw new java.lang.IllegalArgumentException(); - } - - return action.send(hash); - } - - /** - * Return a hash that corresponds to the given key and the given random - * value. - * - * @param key - * the key (the secret) - * - * @param random - * the random value - * - * @return a hash that was computed using both - */ - static String hashKey(String key, String random) { - return StringUtils.getMd5Hash(key + " <==> " + random); - } }