Add method to return an int from the parameters.
[Sone.git] / src / main / java / net / pterodactylus / sone / freenet / fcp / FcpInterface.java
index 6fc4866..8da41ed 100644 (file)
@@ -24,6 +24,7 @@ import java.util.Map;
 import net.pterodactylus.sone.core.Core;
 import net.pterodactylus.sone.freenet.fcp.Command.AccessType;
 import net.pterodactylus.sone.freenet.fcp.Command.Reply;
+import freenet.pluginmanager.FredPluginFCP;
 import freenet.pluginmanager.PluginNotFoundException;
 import freenet.pluginmanager.PluginReplySender;
 import freenet.support.SimpleFieldSet;
@@ -37,15 +38,34 @@ import freenet.support.api.Bucket;
  */
 public class FcpInterface {
 
-       private final Core core;
+       /** All available FCP commands. */
        private final Map<String, Command> commands = Collections.synchronizedMap(new HashMap<String, Command>());
 
+       /**
+        * Creates a new FCP interface.
+        *
+        * @param core
+        *            The core
+        */
        public FcpInterface(Core core) {
-               this.core = core;
                commands.put("Version", new VersionCommand());
                commands.put("GetPostFeed", new GetPostFeedCommand(core));
        }
 
+       /**
+        * Handles a plugin FCP request.
+        *
+        * @param pluginReplySender
+        *            The reply sender
+        * @param parameters
+        *            The message parameters
+        * @param data
+        *            The message data (may be {@code null})
+        * @param accessType
+        *            One of {@link FredPluginFCP#ACCESS_DIRECT},
+        *            {@link FredPluginFCP#ACCESS_FCP_FULL},
+        *            {@link FredPluginFCP#ACCESS_FCP_RESTRICTED}
+        */
        public void handle(PluginReplySender pluginReplySender, SimpleFieldSet parameters, Bucket data, int accessType) {
                Command command = commands.get(parameters.get("Message"));
                if (command == null) {
@@ -57,8 +77,8 @@ public class FcpInterface {
                        /* TODO - return error? */
                        return;
                }
-               Reply reply = command.execute(parameters, data, AccessType.values()[accessType]);
                try {
+                       Reply reply = command.execute(parameters, data, AccessType.values()[accessType]);
                        SimpleFieldSet replyParameters = reply.getReplyParameters();
                        replyParameters.putOverwrite("Identifier", identifier);
                        if (reply.hasData()) {
@@ -68,6 +88,8 @@ public class FcpInterface {
                        } else {
                                pluginReplySender.send(replyParameters);
                        }
+               } catch (FcpException fe1) {
+                       /* TODO - log, report */
                } catch (PluginNotFoundException pnfe1) {
                        /* TODO - log */
                }