From 09dc47bc79814f9c6ff59513ab9ee6074b0f829a Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Thu, 10 Apr 2008 00:09:57 +0000 Subject: [PATCH] add TestDDARequest and TestDDAReply git-svn-id: http://trooper/svn/projects/jSite/trunk@682 c3eda9e8-030b-0410-8277-bc7414b0a119 --- src/net/pterodactylus/util/fcp/FcpAdapter.java | 10 +++ src/net/pterodactylus/util/fcp/FcpConnection.java | 14 ++++ src/net/pterodactylus/util/fcp/FcpListener.java | 10 +++ src/net/pterodactylus/util/fcp/TestDDAReply.java | 84 ++++++++++++++++++++++ src/net/pterodactylus/util/fcp/TestDDARequest.java | 49 +++++++++++++ 5 files changed, 167 insertions(+) create mode 100644 src/net/pterodactylus/util/fcp/TestDDAReply.java create mode 100644 src/net/pterodactylus/util/fcp/TestDDARequest.java diff --git a/src/net/pterodactylus/util/fcp/FcpAdapter.java b/src/net/pterodactylus/util/fcp/FcpAdapter.java index 098b335..62adc9e 100644 --- a/src/net/pterodactylus/util/fcp/FcpAdapter.java +++ b/src/net/pterodactylus/util/fcp/FcpAdapter.java @@ -86,6 +86,16 @@ public class FcpAdapter implements FcpListener { } /** + * {@inheritDoc} + * + * @see net.pterodactylus.util.fcp.FcpListener#receivedTestDDAReply(net.pterodactylus.util.fcp.FcpConnection, + * net.pterodactylus.util.fcp.TestDDAReply) + */ + public void receivedTestDDAReply(FcpConnection fcpConnection, TestDDAReply testDDAReply) { + /* empty. */ + } + + /** * @see net.pterodactylus.util.fcp.FcpListener#receivedMessage(net.pterodactylus.util.fcp.FcpConnection, * net.pterodactylus.util.fcp.FcpMessage) */ diff --git a/src/net/pterodactylus/util/fcp/FcpConnection.java b/src/net/pterodactylus/util/fcp/FcpConnection.java index 2181f23..6cd71b4 100644 --- a/src/net/pterodactylus/util/fcp/FcpConnection.java +++ b/src/net/pterodactylus/util/fcp/FcpConnection.java @@ -259,6 +259,18 @@ public class FcpConnection { } /** + * Notifies all listeners that a “TestDDAReply” message was received. + * + * @param testDDAReply + * The “TestDDAReply” message + */ + private void fireReceivedTestDDAReply(TestDDAReply testDDAReply) { + for (FcpListener fcpListener: fcpListeners) { + fcpListener.receivedTestDDAReply(this, testDDAReply); + } + } + + /** * Notifies all registered listeners that a message has been received. * * @see FcpListener#receivedMessage(FcpConnection, FcpMessage) @@ -346,6 +358,8 @@ public class FcpConnection { fireReceivedPeerRemoved(new PeerRemoved(fcpMessage)); } else if ("NodeData".equals(messageName)) { fireReceivedNodeData(new NodeData(fcpMessage)); + } else if ("TestDDAReply".equals(messageName)) { + fireReceivedTestDDAReply(new TestDDAReply(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 63043fc..f34cd0d 100644 --- a/src/net/pterodactylus/util/fcp/FcpListener.java +++ b/src/net/pterodactylus/util/fcp/FcpListener.java @@ -121,6 +121,16 @@ public interface FcpListener extends EventListener { public void receivedNodeData(FcpConnection fcpConnection, NodeData nodeData); /** + * Notifies a listener that a “TestDDAReply” message was received. + * + * @param fcpConnection + * The connection that received the message + * @param testDDAReply + * The “TestDDAReply” message + */ + public void receivedTestDDAReply(FcpConnection fcpConnection, TestDDAReply testDDAReply); + + /** * Notifies a listener that a message has been received. This method is only * called if {@link FcpConnection#handleMessage(FcpMessage)} does not * recognize the message. Should that ever happen, please file a bug report! diff --git a/src/net/pterodactylus/util/fcp/TestDDAReply.java b/src/net/pterodactylus/util/fcp/TestDDAReply.java new file mode 100644 index 0000000..05034be --- /dev/null +++ b/src/net/pterodactylus/util/fcp/TestDDAReply.java @@ -0,0 +1,84 @@ +/* + * jSite2 - TestDDAReply.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 “TestDDAReply” is sent as a response to {@link TestDDARequest}. If you + * specified that you wanted to read files from that directory + * {@link #getReadFilename()} will give you a filename. Similarly, if you + * specified that you want to write in the directory {@link #getWriteFilename()} + * will give you a filename to write {@link #getContentToWrite()} to. + * + * @author David Roden <droden@gmail.com> + * @version $Id$ + */ +public class TestDDAReply extends BaseMessage { + + /** + * Creates a “TestDDAReply” message that wraps the received message. + * + * @param receivedMessage + * The received message + */ + public TestDDAReply(FcpMessage receivedMessage) { + super(receivedMessage); + } + + /** + * Returns the directory the TestDDRequest was made for. + * + * @return The directory to test + */ + public String getDirectory() { + return getField("Directory"); + } + + /** + * Returns the filename you have to read to proof your ability to read that + * specific directory. + * + * @return The name of the file to read + */ + public String getReadFilename() { + return getField("ReadFilename"); + } + + /** + * Returns the filename you have to write to to proof your ability to write + * to that specific directory. + * + * @return The name of the file write to + */ + public String getWriteFilename() { + return getField("WriteFilename"); + } + + /** + * If you requested a test for writing permissions you have to write the + * return value of this method to the file given by + * {@link #getWriteFilename()}. + * + * @return The content to write to the file + */ + public String getContentToWrite() { + return getField("ContentToWrite"); + } + +} diff --git a/src/net/pterodactylus/util/fcp/TestDDARequest.java b/src/net/pterodactylus/util/fcp/TestDDARequest.java new file mode 100644 index 0000000..0e41b69 --- /dev/null +++ b/src/net/pterodactylus/util/fcp/TestDDARequest.java @@ -0,0 +1,49 @@ +/* + * jSite2 - TestDDARequest.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 “TestDDARequest” initiates a DDA test sequence. + * + * @author David Roden <droden@gmail.com> + * @version $Id$ + */ +public class TestDDARequest extends FcpMessage { + + /** + * Creates a new “TestDDARequest” command that initiates a DDA test. + * + * @param directory + * The directory you want to access files in + * @param wantReadDirectory + * true if you want to read files from the + * directory + * @param wantWriteDirectory + * true if you want to write files to the + * directory + */ + public TestDDARequest(String directory, boolean wantReadDirectory, boolean wantWriteDirectory) { + super("TestDDARequest"); + setField("Directory", directory); + setField("WantReadDirectory", String.valueOf(wantReadDirectory)); + setField("WantWriteDirectory", String.valueOf(wantWriteDirectory)); + } + +} -- 2.7.4