X-Git-Url: http://git.nikiroo.be/?a=blobdiff_plain;f=src%2Fbe%2Fnikiroo%2Ffanfix%2Flibrary%2FRemoteLibraryServer.java;h=f4075dd7bf5df4e9fb1d734bc8d47fdb95852b5e;hb=fb25273cf02653ac343d5437083b1bc41af5ce23;hp=d73943831144add2b16bd4edfeaf35cd9c43d94d;hpb=3989dfc5ced262e3c8d07fc796ec06ce5513c6b8;p=nikiroo-utils.git diff --git a/src/be/nikiroo/fanfix/library/RemoteLibraryServer.java b/src/be/nikiroo/fanfix/library/RemoteLibraryServer.java index d739438..f4075dd 100644 --- a/src/be/nikiroo/fanfix/library/RemoteLibraryServer.java +++ b/src/be/nikiroo/fanfix/library/RemoteLibraryServer.java @@ -4,9 +4,14 @@ import java.io.IOException; import java.net.URL; import java.util.ArrayList; import java.util.Date; +import java.util.HashMap; import java.util.List; +import java.util.Map; + +import javax.net.ssl.SSLException; import be.nikiroo.fanfix.Instance; +import be.nikiroo.fanfix.bundles.Config; import be.nikiroo.fanfix.data.Chapter; import be.nikiroo.fanfix.data.MetaData; import be.nikiroo.fanfix.data.Paragraph; @@ -19,45 +24,51 @@ import be.nikiroo.utils.serial.server.ConnectActionServerObject; import be.nikiroo.utils.serial.server.ServerObject; /** - * Create a new remote server that will listen for order on the given port. + * Create a new remote server that will listen for orders on the given port. + *
+ * The available commands are given as arrays of objects (first item is the + * command, the rest are the arguments). *
- * The available commands are given as arrays of objects (first item is the key, - * second is the command, the rest are the arguments). + * All the commands are always prefixed by the subkey (which can be EMPTY if + * none). *
- * The md5 is always a String (the MD5 hash of the access key), the commands are - * also Strings; the parameters vary depending upon the command. *
+ * Note: the key we use here is the encryption key (it must not contain a
+ * subkey).
*
* @param key
* the key that will restrict access to this server
@@ -68,22 +79,28 @@ public class RemoteLibraryServer extends ServerObject {
* in case of I/O error
*/
public RemoteLibraryServer(String key, int port) throws IOException {
- super("Fanfix remote library", port, true);
- this.md5 = StringUtils.getMd5Hash(key);
-
+ super("Fanfix remote library", port, key);
setTraceHandler(Instance.getTraceHandler());
}
@Override
protected Object onRequest(ConnectActionServerObject action,
- Version clientVersion, Object data) throws Exception {
- String md5 = "";
+ Version clientVersion, Object data, long id) throws Exception {
+ long start = new Date().getTime();
+
+ // defaults are positive (as previous versions without the feature)
+ boolean rw = true;
+ boolean wl = true;
+
+ String subkey = "";
String command = "";
Object[] args = new Object[0];
if (data instanceof Object[]) {
Object[] dataArray = (Object[]) data;
- if (dataArray.length >= 2) {
- md5 = "" + dataArray[0];
+ if (dataArray.length > 0) {
+ subkey = "" + dataArray[0];
+ }
+ if (dataArray.length > 1) {
command = "" + dataArray[1];
args = new Object[dataArray.length - 2];
@@ -93,32 +110,83 @@ public class RemoteLibraryServer extends ServerObject {
}
}
- String trace = "[ " + command + "] ";
- for (Object arg : args) {
- trace += arg + " ";
+ List