X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Fnet%2Fpterodactylus%2Fsone%2Ffreenet%2Ffcp%2FCommand.java;h=32df6d86143a2d5f1ab085ce6b9905f461d7ae61;hb=d29c22bb5e41a90554a6b5aa29f86f64ceeb7361;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..32df6d8 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â2013 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,6 +17,7 @@
package net.pterodactylus.sone.freenet.fcp;
+import net.pterodactylus.sone.freenet.SimpleFieldSetBuilder;
import freenet.support.SimpleFieldSet;
import freenet.support.api.Bucket;
@@ -42,7 +43,7 @@ public interface Command {
* @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, Bucket data, AccessType accessType) throws FcpException;
/**
* The access type of the request.
@@ -67,7 +68,10 @@ public interface Command {
*
* @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;
@@ -81,40 +85,48 @@ public interface Command {
/**
* 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);
+ public Response(String messageName, SimpleFieldSet replyParameters) {
+ this(messageName, replyParameters, null, null);
}
/**
* Creates a new reply with the given parameters.
*
+ * @param messageName
+ * The message name
* @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);
+ public Response(String messageName, SimpleFieldSet replyParameters, byte[] data) {
+ this(messageName, replyParameters, data, null);
}
/**
* Creates a new reply with the given parameters.
*
+ * @param messageName
+ * The message name
* @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);
+ public Response(String messageName, SimpleFieldSet replyParameters, Bucket bucket) {
+ this(messageName, replyParameters, null, bucket);
}
/**
* Creates a new reply with the given parameters.
*
+ * @param messageName
+ * The message name
* @param replyParameters
* The reply parameters
* @param data
@@ -122,7 +134,8 @@ public interface Command {
* @param bucket
* The bucket of the reply (may be {@code null})
*/
- private Reply(SimpleFieldSet replyParameters, byte[] data, Bucket bucket) {
+ private Response(String messageName, SimpleFieldSet replyParameters, byte[] data, Bucket bucket) {
+ this.messageName = messageName;
this.replyParameters = replyParameters;
this.data = data;
this.bucket = bucket;
@@ -134,7 +147,7 @@ public interface Command {
* @return The reply parameters
*/
public SimpleFieldSet getReplyParameters() {
- return replyParameters;
+ return new SimpleFieldSetBuilder(replyParameters).put("Message", messageName).get();
}
/**
@@ -178,4 +191,36 @@ public interface Command {
}
+ /**
+ * Response implementation that can return an error message and an optional
+ * error code.
+ *
+ * @author David âBombeâ Roden
+ */
+ public class ErrorResponse extends Response {
+
+ /**
+ * Creates a new error response with the given message.
+ *
+ * @param message
+ * The error message
+ */
+ public ErrorResponse(String message) {
+ super("Error", new SimpleFieldSetBuilder().put("ErrorMessage", message).get());
+ }
+
+ /**
+ * Creates a new error response with the given code and message.
+ *
+ * @param code
+ * The error code
+ * @param message
+ * The error message
+ */
+ public ErrorResponse(int code, String message) {
+ super("Error", new SimpleFieldSetBuilder().put("ErrorMessage", message).put("ErrorCode", code).get());
+ }
+
+ }
+
}