From d0c0e1b356a9979067f751b4131840d08bf507f5 Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Mon, 11 Apr 2011 09:15:26 +0200 Subject: [PATCH] Add possibility to activate and deactivate the FCP interface. --- .../net/pterodactylus/sone/fcp/FcpInterface.java | 31 ++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/src/main/java/net/pterodactylus/sone/fcp/FcpInterface.java b/src/main/java/net/pterodactylus/sone/fcp/FcpInterface.java index 8854347..1c97f3a 100644 --- a/src/main/java/net/pterodactylus/sone/fcp/FcpInterface.java +++ b/src/main/java/net/pterodactylus/sone/fcp/FcpInterface.java @@ -47,6 +47,9 @@ public class FcpInterface { /** The logger. */ private static final Logger logger = Logging.getLogger(FcpInterface.class); + /** Whether the FCP interface is currently active. */ + private volatile boolean active; + /** All available FCP commands. */ private final Map commands = Collections.synchronizedMap(new HashMap()); @@ -63,6 +66,26 @@ public class FcpInterface { commands.put("GetPostFeed", new GetPostFeedCommand(core)); } + // + // ACCESSORS + // + + /** + * Sets whether the FCP interface should handle requests. If {@code active} + * is {@code false}, all requests are answered with an error. + * + * @param active + * {@code true} to activate the FCP interface, {@code false} to + * deactivate the FCP interface + */ + public void setActive(boolean active) { + this.active = active; + } + + // + // ACTIONS + // + /** * Handles a plugin FCP request. * @@ -78,6 +101,14 @@ public class FcpInterface { * {@link FredPluginFCP#ACCESS_FCP_RESTRICTED} */ public void handle(PluginReplySender pluginReplySender, SimpleFieldSet parameters, Bucket data, int accessType) { + if (!active) { + try { + sendReply(pluginReplySender, null, new ErrorResponse(400, "FCP Interface deactivated")); + } catch (PluginNotFoundException pnfe1) { + logger.log(Level.FINE, "Could not set error to plugin.", pnfe1); + } + return; + } Command command = commands.get(parameters.get("Message")); try { if (command == null) { -- 2.7.4