X-Git-Url: https://git.pterodactylus.net/?p=Sone.git;a=blobdiff_plain;f=src%2Fmain%2Fjava%2Fnet%2Fpterodactylus%2Fsone%2Ffcp%2FFcpInterface.java;h=3bb8777f6767812f9e485db88dcc732746ba96c0;hp=9448210f9be2270a3c8d577f425777d41f24301c;hb=HEAD;hpb=b32c81368c80e92de1d9bc2e8fdb635d251ecfa2 diff --git a/src/main/java/net/pterodactylus/sone/fcp/FcpInterface.java b/src/main/java/net/pterodactylus/sone/fcp/FcpInterface.java index 9448210..3bb8777 100644 --- a/src/main/java/net/pterodactylus/sone/fcp/FcpInterface.java +++ b/src/main/java/net/pterodactylus/sone/fcp/FcpInterface.java @@ -1,5 +1,5 @@ /* - * Sone - FcpInterface.java - Copyright © 2011–2016 David Roden + * Sone - FcpInterface.java - Copyright © 2011–2020 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 @@ -54,16 +54,12 @@ import com.google.inject.Inject; /** * Implementation of an FCP interface for other clients or plugins to * communicate with Sone. - * - * @author David ‘Bombe’ Roden */ @Singleton public class FcpInterface { /** * The action level that full access for the FCP connection is required. - * - * @author David ‘Bombe’ Roden */ public enum FullAccessRequired { @@ -85,7 +81,7 @@ public class FcpInterface { private final AtomicBoolean active = new AtomicBoolean(); /** What function full access is required for. */ - private final AtomicReference fullAccessRequired = new AtomicReference(FullAccessRequired.ALWAYS); + private final AtomicReference fullAccessRequired = new AtomicReference<>(FullAccessRequired.ALWAYS); /** All available FCP commands. */ private final Map commands; @@ -144,26 +140,26 @@ public class FcpInterface { * {@link FredPluginFCP#ACCESS_FCP_RESTRICTED} */ public void handle(PluginReplySender pluginReplySender, SimpleFieldSet parameters, Bucket data, int accessType) { + String identifier = parameters.get("Identifier"); + if ((identifier == null) || (identifier.length() == 0)) { + sendErrorReply(pluginReplySender, null, 400, "Missing Identifier."); + return; + } if (!active.get()) { - sendErrorReply(pluginReplySender, null, 503, "FCP Interface deactivated"); + sendErrorReply(pluginReplySender, identifier, 503, "FCP Interface deactivated"); return; } AbstractSoneCommand command = commands.get(parameters.get("Message")); if (command == null) { - sendErrorReply(pluginReplySender, null, 404, "Unrecognized Message: " + parameters.get("Message")); + sendErrorReply(pluginReplySender, identifier, 404, "Unrecognized Message: " + parameters.get("Message")); return; } if (!accessAuthorizer.authorized(AccessType.values()[accessType], fullAccessRequired.get(), command.requiresWriteAccess())) { - sendErrorReply(pluginReplySender, null, 401, "Not authorized"); - return; - } - String identifier = parameters.get("Identifier"); - if ((identifier == null) || (identifier.length() == 0)) { - sendErrorReply(pluginReplySender, null, 400, "Missing Identifier."); + sendErrorReply(pluginReplySender, identifier, 401, "Not authorized"); return; } try { - Response response = command.execute(parameters, data, AccessType.values()[accessType]); + Response response = command.execute(parameters); sendReply(pluginReplySender, identifier, response); } catch (Exception e1) { logger.log(Level.WARNING, "Could not process FCP command “%s”.", command);