X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;ds=sidebyside;f=src%2Fmain%2Fjava%2Fnet%2Fpterodactylus%2Fsone%2Ffreenet%2Ffcp%2FCommand.java;h=63fc8ebd669f68270ee1c73f63d4648575bbc51f;hb=a73c33904ed963cf8ecb0d4507c90e45ef83e407;hp=07fb7a4f7b01a0c99c0aed6c1eedbdc8bbf20728;hpb=35aeb7dde28426cb1b22c91d90444d95c22d4edc;p=Sone.git
diff --git a/src/main/java/net/pterodactylus/sone/freenet/fcp/Command.java b/src/main/java/net/pterodactylus/sone/freenet/fcp/Command.java
index 07fb7a4..63fc8eb 100644
--- a/src/main/java/net/pterodactylus/sone/freenet/fcp/Command.java
+++ b/src/main/java/net/pterodactylus/sone/freenet/fcp/Command.java
@@ -1,5 +1,5 @@
/*
- * Sone - Command.java - Copyright © 2011 David Roden
+ * Sone - Command.java - Copyright © 2011â2019 David Roden
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -17,14 +17,12 @@
package net.pterodactylus.sone.freenet.fcp;
+import net.pterodactylus.sone.freenet.SimpleFieldSetBuilder;
import freenet.support.SimpleFieldSet;
-import freenet.support.api.Bucket;
/**
* Implementation of an FCP interface for other clients or plugins to
* communicate with Sone.
- *
- * @author David âBombeâ Roden
*/
public interface Command {
@@ -34,20 +32,14 @@ public interface Command {
*
* @param parameters
* The parameters of the comand
- * @param data
- * The data of the command (may be {@code null})
- * @param accessType
- * The access type
* @return A reply to send back to the plugin
* @throws FcpException
* if an error processing the parameters occurs
*/
- public Reply execute(SimpleFieldSet parameters, Bucket data, AccessType accessType) throws FcpException;
+ public Response execute(SimpleFieldSet parameters) throws FcpException;
/**
* The access type of the request.
- *
- * @author David âBombeâ Roden
*/
public static enum AccessType {
@@ -64,68 +56,26 @@ public interface Command {
/**
* Interface for command replies.
- *
- * @author David âBombeâ Roden
*/
- public static class Reply {
+ public static class Response {
+
+ /** The message name of the reponse. */
+ private final String messageName;
/** The reply parameters. */
private final SimpleFieldSet replyParameters;
- /** The reply data, may be {@code null}. */
- private final byte[] data;
-
- /** The data bucket, may be {@code null}. */
- private final Bucket bucket;
-
/**
* Creates a new reply with the given parameters.
*
+ * @param messageName
+ * The message name
* @param replyParameters
* The reply parameters
*/
- public Reply(SimpleFieldSet replyParameters) {
- this(replyParameters, null, null);
- }
-
- /**
- * Creates a new reply with the given parameters.
- *
- * @param replyParameters
- * The reply parameters
- * @param data
- * The data of the reply (may be {@code null})
- */
- public Reply(SimpleFieldSet replyParameters, byte[] data) {
- this(replyParameters, data, null);
- }
-
- /**
- * Creates a new reply with the given parameters.
- *
- * @param replyParameters
- * The reply parameters
- * @param bucket
- * The bucket of the reply (may be {@code null})
- */
- public Reply(SimpleFieldSet replyParameters, Bucket bucket) {
- this(replyParameters, null, bucket);
- }
-
- /**
- * Creates a new reply with the given parameters.
- *
- * @param replyParameters
- * The reply parameters
- * @param data
- * The data of the reply (may be {@code null})
- * @param bucket
- * The bucket of the reply (may be {@code null})
- */
- private Reply(SimpleFieldSet replyParameters, byte[] data, Bucket bucket) {
+ public Response(String messageName, SimpleFieldSet replyParameters) {
+ this.messageName = messageName;
this.replyParameters = replyParameters;
- this.data = data;
- this.bucket = bucket;
}
/**
@@ -134,46 +84,37 @@ public interface Command {
* @return The reply parameters
*/
public SimpleFieldSet getReplyParameters() {
- return replyParameters;
+ return new SimpleFieldSetBuilder(replyParameters).put("Message", messageName).get();
}
- /**
- * Returns whether the reply has reply data.
- *
- * @see #getData()
- * @return {@code true} if this reply has data, {@code false} otherwise
- */
- public boolean hasData() {
- return data != null;
- }
+ }
- /**
- * Returns the data of the reply.
- *
- * @return The data of the reply
- */
- public byte[] getData() {
- return data;
- }
+ /**
+ * Response implementation that can return an error message and an optional
+ * error code.
+ */
+ public class ErrorResponse extends Response {
/**
- * Returns whether the reply has a data bucket.
+ * Creates a new error response with the given message.
*
- * @see #getBucket()
- * @return {@code true} if the reply has a data bucket, {@code false}
- * otherwise
+ * @param message
+ * The error message
*/
- public boolean hasBucket() {
- return bucket != null;
+ public ErrorResponse(String message) {
+ super("Error", new SimpleFieldSetBuilder().put("ErrorMessage", message).get());
}
/**
- * Returns the data bucket of the reply.
+ * Creates a new error response with the given code and message.
*
- * @return The data bucket of the reply
+ * @param code
+ * The error code
+ * @param message
+ * The error message
*/
- public Bucket getBucket() {
- return bucket;
+ public ErrorResponse(int code, String message) {
+ super("Error", new SimpleFieldSetBuilder().put("ErrorMessage", message).put("ErrorCode", code).get());
}
}