X-Git-Url: http://git.nikiroo.be/?a=blobdiff_plain;f=src%2Fbe%2Fnikiroo%2Ffanfix%2Flibrary%2FRemoteLibrary.java;h=3e0e192d1806abb2e7d4bd270f0e808821c20991;hb=34f8780d16faf3a5466c45261bd84f1b31516790;hp=bbe772a8c90168c658fa985461e92c58f13bb8d0;hpb=008b697abad5333455de13c773206495ee2b7530;p=nikiroo-utils.git
diff --git a/src/be/nikiroo/fanfix/library/RemoteLibrary.java b/src/be/nikiroo/fanfix/library/RemoteLibrary.java
index bbe772a..3e0e192 100644
--- a/src/be/nikiroo/fanfix/library/RemoteLibrary.java
+++ b/src/be/nikiroo/fanfix/library/RemoteLibrary.java
@@ -21,6 +21,8 @@ import be.nikiroo.utils.serial.server.ConnectActionClientObject;
* This {@link BasicLibrary} will access a remote server to list the available
* stories, and download the ones you try to load to the local directory
* specified in the configuration.
+ *
+ * This remote library uses a custom fanfix:// protocol.
*
* @author niki
*/
@@ -35,8 +37,8 @@ public class RemoteLibrary extends BasicLibrary {
}
@Override
- public Object send(Object data) throws IOException,
- NoSuchFieldException, NoSuchMethodException,
+ public Object send(Object data)
+ throws IOException, NoSuchFieldException, NoSuchMethodException,
ClassNotFoundException {
Object rep = super.send(data);
if (rep instanceof RemoteLibraryException) {
@@ -60,7 +62,7 @@ public class RemoteLibrary extends BasicLibrary {
* Create a {@link RemoteLibrary} linked to the given server.
*
* Note that the key is structured:
- * xxx(|yyy|wl)(|rw)
+ * xxx(|yyy(|wl)(|bl)(|rw)
*
* Note that anything before the first pipe (|) character is
* considered to be the encryption key, anything after that character is
@@ -75,16 +77,16 @@ public class RemoteLibrary extends BasicLibrary {
*
yyy: the secondary key
* rw: flag to allow read and write access if it is not the
* default on this server
- * wl: flag to allow access to all the stories (bypassing the
- * whitelist if it exists)
+ * bl: flag to bypass the blacklist (if it exists)
+ * wl: flag to bypass the whitelist if it exists
*
*
* Some examples:
*
* - my_key: normal connection, will take the default server
* options
- * - my_key|agzyzz|wl: will ask to bypass the white list (if it
- * exists)
+ * - my_key|agzyzz|wl|bl: will ask to bypass the black list and the
+ * white list (if it exists)
* - my_key|agzyzz|rw: will ask read-write access (if the default
* is read-only)
* - my_key|agzyzz|wl|rw: will ask both read-write access and white
@@ -113,28 +115,33 @@ public class RemoteLibrary extends BasicLibrary {
this.subkey = "";
}
+ if (host.startsWith("fanfix://")) {
+ host = host.substring("fanfix://".length());
+ }
+
this.host = host;
this.port = port;
}
@Override
public String getLibraryName() {
- return (rw ? "[READ-ONLY] " : "") + host + ":" + port;
+ return (rw ? "[READ-ONLY] " : "") + "fanfix://" + host + ":" + port;
}
@Override
public Status getStatus() {
- Instance.getInstance().getTraceHandler().trace("Getting remote lib status...");
+ Instance.getInstance().getTraceHandler()
+ .trace("Getting remote lib status...");
Status status = getStatusDo();
- Instance.getInstance().getTraceHandler().trace("Remote lib status: " + status);
+ Instance.getInstance().getTraceHandler()
+ .trace("Remote lib status: " + status);
return status;
}
private Status getStatusDo() {
final Status[] result = new Status[1];
- result[0] = Status.INVALID;
-
+ result[0] = null;
try {
new RemoteConnectAction() {
@Override
@@ -180,8 +187,8 @@ public class RemoteLibrary extends BasicLibrary {
@Override
public void action(ConnectActionClientObject action)
throws Exception {
- Object rep = action.send(new Object[] { subkey, "GET_COVER",
- luid });
+ Object rep = action
+ .send(new Object[] { subkey, "GET_COVER", luid });
result[0] = (Image) rep;
}
});
@@ -232,8 +239,8 @@ public class RemoteLibrary extends BasicLibrary {
pg = new Progress();
}
- Object rep = action.send(new Object[] { subkey, "GET_STORY",
- luid });
+ Object rep = action
+ .send(new Object[] { subkey, "GET_STORY", luid });
MetaData meta = null;
if (rep instanceof MetaData) {
@@ -354,7 +361,7 @@ public class RemoteLibrary extends BasicLibrary {
// Could work (more slowly) without it
public MetaData imprt(final URL url, Progress pg) throws IOException {
// Import the file locally if it is actually a file
-
+
if (url == null || url.getProtocol().equalsIgnoreCase("file")) {
return super.imprt(url, pg);
}
@@ -374,8 +381,8 @@ public class RemoteLibrary extends BasicLibrary {
throws Exception {
Progress pg = pgF;
- Object rep = action.send(new Object[] { subkey, "IMPORT",
- url.toString() });
+ Object rep = action.send(
+ new Object[] { subkey, "IMPORT", url.toString() });
while (true) {
if (!RemoteLibraryServer.updateProgress(pg, rep)) {
@@ -435,9 +442,11 @@ public class RemoteLibrary extends BasicLibrary {
* Stop the server.
*
* @throws IOException
- * in case of I/O error (including bad key)
+ * in case of I/O errors
+ * @throws SSLException
+ * when the key was not accepted
*/
- public void exit() throws IOException {
+ public void stop() throws IOException, SSLException {
connectRemoteAction(new RemoteAction() {
@Override
public void action(ConnectActionClientObject action)
@@ -476,7 +485,7 @@ public class RemoteLibrary extends BasicLibrary {
// The following methods are only used by Save and Delete in BasicLibrary:
@Override
- protected int getNextId() {
+ protected String getNextId() {
throw new java.lang.InternalError("Should not have been called");
}
@@ -522,8 +531,8 @@ public class RemoteLibrary extends BasicLibrary {
pg = new Progress();
}
- Object rep = action.send(new Object[] { subkey, "GET_METADATA",
- luid });
+ Object rep = action
+ .send(new Object[] { subkey, "GET_METADATA", luid });
while (true) {
if (!RemoteLibraryServer.updateProgress(pg, rep)) {