X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Fnet%2Fpterodactylus%2Fsone%2Ffcp%2FFcpInterface.java;h=0b321f4866a86da6172d965a8dd5acd40e6a5e85;hb=90cd4ab2d7c55e2a8acc9e0fd3d8bad5f9d24efa;hp=9448210f9be2270a3c8d577f425777d41f24301c;hpb=b32c81368c80e92de1d9bc2e8fdb635d251ecfa2;p=Sone.git
diff --git a/src/main/java/net/pterodactylus/sone/fcp/FcpInterface.java b/src/main/java/net/pterodactylus/sone/fcp/FcpInterface.java
index 9448210..0b321f4 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â2019 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);