add FCPPluginReply
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Sat, 12 Apr 2008 18:25:42 +0000 (18:25 +0000)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Sat, 12 Apr 2008 18:25:42 +0000 (18:25 +0000)
git-svn-id: http://trooper/svn/projects/jSite/trunk@734 c3eda9e8-030b-0410-8277-bc7414b0a119

TODO
src/net/pterodactylus/util/fcp/FCPPluginReply.java [new file with mode: 0644]
src/net/pterodactylus/util/fcp/FcpAdapter.java
src/net/pterodactylus/util/fcp/FcpConnection.java
src/net/pterodactylus/util/fcp/FcpListener.java

diff --git a/TODO b/TODO
index c630871..9d8ba1f 100644 (file)
--- a/TODO
+++ b/TODO
@@ -1,6 +1,5 @@
 ClientPutComplexDir
 ClientPutDiskDir
-FCPPluginReply (since 1075)
 GetPluginInfo (since 1075)
 GetRequestStatus
 ModifyConfig (since 1027)
diff --git a/src/net/pterodactylus/util/fcp/FCPPluginReply.java b/src/net/pterodactylus/util/fcp/FCPPluginReply.java
new file mode 100644 (file)
index 0000000..8ca7e23
--- /dev/null
@@ -0,0 +1,98 @@
+/*
+ * jSite2 - FCPPluginReply.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;
+
+import java.io.InputStream;
+
+/**
+ * The “FCPPluginReply” is sent by a plugin as a response to a
+ * {@link FCPPluginMessage} message.
+ * 
+ * @author David ‘Bombe’ Roden &lt;bombe@freenetproject.org&gt;
+ * @version $Id$
+ */
+public class FCPPluginReply extends BaseMessage {
+
+       /** The payload input stream. */
+       private final InputStream payloadInputStream;
+
+       /**
+        * Creates a new “FCPPluginReply” message that wraps the received message.
+        * 
+        * @param receivedMessage
+        *            The received message
+        * @param payloadInputStream
+        *            The optional input stream for the payload
+        */
+       FCPPluginReply(FcpMessage receivedMessage, InputStream payloadInputStream) {
+               super(receivedMessage);
+               this.payloadInputStream = payloadInputStream;
+       }
+
+       /**
+        * Returns the name of the plugin.
+        * 
+        * @return The name of the plugin
+        */
+       public String getPluginName() {
+               return getField("PluginName");
+       }
+
+       /**
+        * Returns the identifier of the request.
+        * 
+        * @return The identifier of the request
+        */
+       public String getIdentifier() {
+               return getField("Identifier");
+       }
+
+       /**
+        * Returns the length of the optional payload.
+        * 
+        * @return The length of the payload, or <code>-1</code> if there is no
+        *         payload or the length could not be parsed
+        */
+       public long getDataLength() {
+               return FcpUtils.safeParseLong(getField("DataLength"));
+       }
+
+       /**
+        * Returns a reply from the plugin.
+        * 
+        * @param key
+        *            The name of the reply
+        * @return The value of the reply
+        */
+       public String getReply(String key) {
+               return getField("Replies." + key);
+       }
+
+       /**
+        * Returns the optional payload.
+        * 
+        * @return The payload of the reply, or <code>null</code> if there is no
+        *         payload
+        */
+       public InputStream getPayloadInputStream() {
+               return payloadInputStream;
+       }
+
+}
index 491adf3..caa16ee 100644 (file)
@@ -228,6 +228,13 @@ public class FcpAdapter implements FcpListener {
        /**
         * {@inheritDoc}
         */
+       public void receivedFCPPluginReply(FcpConnection fcpConnection, FCPPluginReply fcpPluginReply) {
+               /* empty. */
+       }
+
+       /**
+        * {@inheritDoc}
+        */
        public void receivedProtocolError(FcpConnection fcpConnection, ProtocolError protocolError) {
                /* empty. */
        }
index 12d52af..9a13264 100644 (file)
@@ -537,6 +537,18 @@ public class FcpConnection {
        }
 
        /**
+        * Notifies all listeners that an “FCPPluginReply” message was received.
+        * 
+        * @param fcpPluginReply
+        *            The “FCPPluginReply” message
+        */
+       private void fireReceivedFCPPluginReply(FCPPluginReply fcpPluginReply) {
+               for (FcpListener fcpListener: fcpListeners) {
+                       fcpListener.receivedFCPPluginReply(this, fcpPluginReply);
+               }
+       }
+
+       /**
         * Notifies all listeners that a “ProtocolError” message was received.
         * 
         * @param protocolError
@@ -677,6 +689,14 @@ public class FcpConnection {
                        fireReceivedUnknownPeerNoteType(new UnknownPeerNoteType(fcpMessage));
                } else if ("UnknownNodeIdentifier".equals(messageName)) {
                        fireReceivedUnknownNodeIdentifier(new UnknownNodeIdentifier(fcpMessage));
+               } else if ("FCPPluginReply".equals(messageName)) {
+                       LimitedInputStream payloadInputStream = getInputStream(FcpUtils.safeParseLong(fcpMessage.getField("DataLength")));
+                       fireReceivedFCPPluginReply(new FCPPluginReply(fcpMessage, payloadInputStream));
+                       try {
+                               payloadInputStream.consume();
+                       } catch (IOException ioe1) {
+                               /* ignore. */
+                       }
                } else if ("PluginInfo".equals(messageName)) {
                        fireReceivedPluginInfo(new PluginInfo(fcpMessage));
                } else if ("NodeData".equals(messageName)) {
index 43967a2..a3a4381 100644 (file)
@@ -332,6 +332,16 @@ public interface FcpListener extends EventListener {
        public void receivedPluginInfo(FcpConnection fcpConnection, PluginInfo pluginInfo);
 
        /**
+        * Notifies a listener that an “FCPPluginReply“ message was received.
+        * 
+        * @param fcpConnection
+        *            The connection that received the message
+        * @param fcpPluginReply
+        *            The “FCPPluginReply” message
+        */
+       public void receivedFCPPluginReply(FcpConnection fcpConnection, FCPPluginReply fcpPluginReply);
+
+       /**
         * Notifies a listener that a “ProtocolError” was received.
         * 
         * @param fcpConnection