2 * Sone - Command.java - Copyright © 2011 David Roden
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 package net.pterodactylus.sone.freenet.fcp;
20 import freenet.support.SimpleFieldSet;
21 import freenet.support.api.Bucket;
24 * Implementation of an FCP interface for other clients or plugins to
25 * communicate with Sone.
27 * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
29 public interface Command {
32 * Executes the command, returning a reply that will be sent back to the
36 * The parameters of the comand
38 * The data of the command (may be {@code null})
41 * @return A reply to send back to the plugin
43 public Reply execute(SimpleFieldSet parameters, Bucket data, AccessType accessType);
46 * The access type of the request.
48 * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
50 public static enum AccessType {
52 /** Access from another plugin. */
55 /** Access via restricted FCP. */
58 /** Access via FCP with full access. */
64 * Interface for command replies.
66 * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
68 public static class Reply {
70 /** The reply parameters. */
71 private final SimpleFieldSet replyParameters;
73 /** The reply data, may be {@code null}. */
74 private final byte[] data;
76 /** The data bucket, may be {@code null}. */
77 private final Bucket bucket;
80 * Creates a new reply with the given parameters.
82 * @param replyParameters
83 * The reply parameters
85 public Reply(SimpleFieldSet replyParameters) {
86 this(replyParameters, null, null);
90 * Creates a new reply with the given parameters.
92 * @param replyParameters
93 * The reply parameters
95 * The data of the reply (may be {@code null})
97 public Reply(SimpleFieldSet replyParameters, byte[] data) {
98 this(replyParameters, data, null);
102 * Creates a new reply with the given parameters.
104 * @param replyParameters
105 * The reply parameters
107 * The bucket of the reply (may be {@code null})
109 public Reply(SimpleFieldSet replyParameters, Bucket bucket) {
110 this(replyParameters, null, bucket);
114 * Creates a new reply with the given parameters.
116 * @param replyParameters
117 * The reply parameters
119 * The data of the reply (may be {@code null})
121 * The bucket of the reply (may be {@code null})
123 private Reply(SimpleFieldSet replyParameters, byte[] data, Bucket bucket) {
124 this.replyParameters = replyParameters;
126 this.bucket = bucket;
130 * Returns the reply parameters.
132 * @return The reply parameters
134 public SimpleFieldSet getReplyParameters() {
135 return replyParameters;
139 * Returns whether the reply has reply data.
142 * @return {@code true} if this reply has data, {@code false} otherwise
144 public boolean hasData() {
149 * Returns the data of the reply.
151 * @return The data of the reply
153 public byte[] getData() {
158 * Returns whether the reply has a data bucket.
161 * @return {@code true} if the reply has a data bucket, {@code false}
164 public boolean hasBucket() {
165 return bucket != null;
169 * Returns the data bucket of the reply.
171 * @return The data bucket of the reply
173 public Bucket getBucket() {