From 60ba7c6bfca09b5bb4d7abf8c94a1caa752c5ddb Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Sat, 12 Apr 2008 10:06:54 +0000 Subject: [PATCH] add GetConfig and ConfigData git-svn-id: http://trooper/svn/projects/jSite/trunk@717 c3eda9e8-030b-0410-8277-bc7414b0a119 --- TODO | 2 - src/net/pterodactylus/util/fcp/ConfigData.java | 130 +++++++++++++++++++++ src/net/pterodactylus/util/fcp/FcpAdapter.java | 7 ++ src/net/pterodactylus/util/fcp/FcpConnection.java | 14 +++ src/net/pterodactylus/util/fcp/FcpListener.java | 10 ++ src/net/pterodactylus/util/fcp/GetConfig.java | 134 ++++++++++++++++++++++ 6 files changed, 295 insertions(+), 2 deletions(-) create mode 100644 src/net/pterodactylus/util/fcp/ConfigData.java create mode 100644 src/net/pterodactylus/util/fcp/GetConfig.java diff --git a/TODO b/TODO index 8863f31..db7dee8 100644 --- a/TODO +++ b/TODO @@ -1,9 +1,7 @@ ClientPutComplexDir ClientPutDiskDir -ConfigData (since 1027) FCPPluginMessage (since 1075) FCPPluginReply (since 1075) -GetConfig (since 1027) GetFailed GetPluginInfo (since 1075) GetRequestStatus diff --git a/src/net/pterodactylus/util/fcp/ConfigData.java b/src/net/pterodactylus/util/fcp/ConfigData.java new file mode 100644 index 0000000..aa8ea6f --- /dev/null +++ b/src/net/pterodactylus/util/fcp/ConfigData.java @@ -0,0 +1,130 @@ +/* + * jSite2 - ConfigData.java - + * Copyright © 2008 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 + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +package net.pterodactylus.util.fcp; + +/** + * A “ConfigData” message contains various aspects of the node’s configuration. + * + * @see GetConfig + * @author David ‘Bombe’ Roden <bombe@freenetproject.org> + * @version $Id$ + */ +public class ConfigData extends BaseMessage { + + /** + * Creates a new “ConfigData” message that wraps the received message. + * + * @param receivedMessage + * The received message + */ + ConfigData(FcpMessage receivedMessage) { + super(receivedMessage); + } + + /** + * Returns the current value of the given option. + * + * @param option + * The name of the option + * @return The current value of the option + */ + public String getCurrent(String option) { + return getField("current." + option); + } + + /** + * Returns the short description of the given option. + * + * @param option + * The name of the option + * @return The short description of the option + */ + public String getShortDescription(String option) { + return getField("shortDescription." + option); + } + + /** + * Returns the long description of the given option. + * + * @param option + * The name of the option + * @return The long description of the option + */ + public String getLongDescription(String option) { + return getField("longDescription." + option); + } + + /** + * Returns the data type of the given option. + * + * @param option + * The name of the option + * @return The data type of the option + */ + public String getDataType(String option) { + return getField("dataType." + option); + } + + /** + * Returns the default value of the given option. + * + * @param option + * The name of the option + * @return The default value of the option + */ + public String getDefault(String option) { + return getField("default." + option); + } + + /** + * Returns the sort order of the given option. + * + * @param option + * The name of the option + * @return The sort order of the option, or -1 if the sort + * order could not be parsed + */ + public int getSortOrder(String option) { + return FcpUtils.safeParseInt(getField("sortOrder." + option)); + } + + /** + * Returns the expert flag of the given option. + * + * @param option + * The name of the option + * @return The expert flag of the option + */ + public boolean getExpertFlag(String option) { + return Boolean.valueOf(getField("expertFlag." + option)); + } + + /** + * Returns the force-write flag of the given option + * + * @param option + * The name of the option + * @return The force-write flag of the given option + */ + public boolean getForceWriteFlag(String option) { + return Boolean.valueOf(getField("forceWriteFlag." + option)); + } + +} diff --git a/src/net/pterodactylus/util/fcp/FcpAdapter.java b/src/net/pterodactylus/util/fcp/FcpAdapter.java index 37fd77f..0402045 100644 --- a/src/net/pterodactylus/util/fcp/FcpAdapter.java +++ b/src/net/pterodactylus/util/fcp/FcpAdapter.java @@ -177,6 +177,13 @@ public class FcpAdapter implements FcpListener { } /** + * @see FcpListener#receivedConfigData(FcpConnection, ConfigData) + */ + public void receivedConfigData(FcpConnection fcpConnection, ConfigData configData) { + /* empty. */ + } + + /** * @see FcpListener#receivedProtocolError(FcpConnection, ProtocolError) */ public void receivedProtocolError(FcpConnection fcpConnection, ProtocolError protocolError) { diff --git a/src/net/pterodactylus/util/fcp/FcpConnection.java b/src/net/pterodactylus/util/fcp/FcpConnection.java index cc48dfb..a57a823 100644 --- a/src/net/pterodactylus/util/fcp/FcpConnection.java +++ b/src/net/pterodactylus/util/fcp/FcpConnection.java @@ -439,6 +439,18 @@ public class FcpConnection { } /** + * Notifies all listeners that a “ConfigData” message was received. + * + * @param configData + * The “ConfigData” message + */ + private void fireReceivedConfigData(ConfigData configData) { + for (FcpListener fcpListener: fcpListeners) { + fcpListener.receivedConfigData(this, configData); + } + } + + /** * Notifies all listeners that a “ProtocolError” message was received. * * @param protocolError @@ -580,6 +592,8 @@ public class FcpConnection { fireReceivedTestDDAReply(new TestDDAReply(fcpMessage)); } else if ("TestDDAComplete".equals(messageName)) { fireReceivedTestDDAComplete(new TestDDAComplete(fcpMessage)); + } else if ("ConfigData".equals(messageName)) { + fireReceivedConfigData(new ConfigData(fcpMessage)); } else if ("NodeHello".equals(messageName)) { fireReceivedNodeHello(new NodeHello(fcpMessage)); } else if ("CloseConnectionDuplicateClientName".equals(messageName)) { diff --git a/src/net/pterodactylus/util/fcp/FcpListener.java b/src/net/pterodactylus/util/fcp/FcpListener.java index 9b75bdb..ad1205d 100644 --- a/src/net/pterodactylus/util/fcp/FcpListener.java +++ b/src/net/pterodactylus/util/fcp/FcpListener.java @@ -251,6 +251,16 @@ public interface FcpListener extends EventListener { public void receivedUnknownNodeIdentifier(FcpConnection fcpConnection, UnknownNodeIdentifier unknownNodeIdentifier); /** + * Notifies a listener that a “ConfigData” message was received. + * + * @param fcpConnection + * The connection that received the message + * @param configData + * The “ConfigData” message + */ + public void receivedConfigData(FcpConnection fcpConnection, ConfigData configData); + + /** * Notifies a listener that a “ProtocolError” was received. * * @param fcpConnection diff --git a/src/net/pterodactylus/util/fcp/GetConfig.java b/src/net/pterodactylus/util/fcp/GetConfig.java new file mode 100644 index 0000000..53c8555 --- /dev/null +++ b/src/net/pterodactylus/util/fcp/GetConfig.java @@ -0,0 +1,134 @@ +/* + * jSite2 - GetConfig.java - + * Copyright © 2008 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 + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +package net.pterodactylus.util.fcp; + +/** + * The “GetConfig” command tells the node to send its configuration to the + * client. + * + * @author David ‘Bombe’ Roden <bombe@freenetproject.org> + * @version $Id$ + */ +public class GetConfig extends FcpMessage { + + /** + * Creates a new “GetConfig” command. + */ + public GetConfig() { + super("GetConfig"); + } + + /** + * Sets whether the {@link ConfigData} result message shall include the + * current values. + * + * @param withCurrent + * true to include current values in the result, + * false otherwise + */ + public void setWithCurrent(boolean withCurrent) { + setField("WithCurrent", String.valueOf(withCurrent)); + } + + /** + * Sets whether the {@link ConfigData} result message shall include the + * short descriptions. + * + * @param withShortDescription + * true to include the short descriptions in the + * result, false otherwise + */ + public void setWithShortDescription(boolean withShortDescription) { + setField("WithShortDescription", String.valueOf(withShortDescription)); + } + + /** + * Sets whether the {@link ConfigData} result message shall include the long + * descriptions. + * + * @param withLongDescription + * true to include the long descriptions in the + * result, false otherwise + */ + public void setWithLongDescription(boolean withLongDescription) { + setField("WithLongDescription", String.valueOf(withLongDescription)); + } + + /** + * Sets whether the {@link ConfigData} result message shall include the data + * types. + * + * @param withDataTypes + * true to include the data types in the result, + * false otherwise + */ + public void setWithDataTypes(boolean withDataTypes) { + setField("WithDataTypes", String.valueOf(withDataTypes)); + } + + /** + * Sets whether the {@link ConfigData} result message shall include the + * defaults. + * + * @param setWithDefaults + * true to include the defaults in the result, + * false otherwise + */ + public void setWithDefaults(boolean setWithDefaults) { + setField("WithDefaults", String.valueOf(setWithDefaults)); + } + + /** + * Sets whether the {@ConfigData} result message shall include the sort + * order. + * + * @param withSortOrder + * true to include the sort order in the result, + * false otherwise + */ + public void setWithSortOrder(boolean withSortOrder) { + setField("WithSortOrder", String.valueOf(withSortOrder)); + } + + /** + * Sets whether the {@link ConfigData} result message shall include the + * expert flag. + * + * @param withExpertFlag + * true to include the expert flag in the result, + * false otherwise + */ + public void setWithExpertFlag(boolean withExpertFlag) { + setField("WithExpertFlag", String.valueOf(withExpertFlag)); + } + + /** + * Sets whether the {@link ConfigData} result message shall include the + * force-write flag. + * + * @param withForceWriteFlag + * true to include the force-write flag in the + * result, false otherwise + */ + public void setWithForceWriteFlag(boolean withForceWriteFlag) { + setField("WithForceWriteFlag", String.valueOf(withForceWriteFlag)); + } + +} -- 2.7.4