Author: saces
Date: 2007-11-17 12:27:57 +0000 (Sat, 17 Nov 2007)
New Revision: 15798

Modified:
   trunk/freenet/src/freenet/node/fcp/FCPConnectionHandler.java
   trunk/freenet/src/freenet/node/fcp/FCPConnectionInputHandler.java
   trunk/freenet/src/freenet/node/fcp/FCPMessage.java
   trunk/freenet/src/freenet/node/fcp/ProtocolErrorMessage.java
   trunk/freenet/src/freenet/pluginmanager/PluginInfoWrapper.java
   trunk/freenet/src/freenet/pluginmanager/PluginManager.java
Log:
initial plugin-fcp implementation

Modified: trunk/freenet/src/freenet/node/fcp/FCPConnectionHandler.java
===================================================================
--- trunk/freenet/src/freenet/node/fcp/FCPConnectionHandler.java        
2007-11-17 12:27:06 UTC (rev 15797)
+++ trunk/freenet/src/freenet/node/fcp/FCPConnectionHandler.java        
2007-11-17 12:27:57 UTC (rev 15798)
@@ -54,7 +54,7 @@
        final FCPServer server;
        final Socket sock;
        final FCPConnectionInputHandler inputHandler;
-       final FCPConnectionOutputHandler outputHandler;
+       public final FCPConnectionOutputHandler outputHandler;
        private boolean isClosed;
        private boolean inputClosed;
        private boolean outputClosed;

Modified: trunk/freenet/src/freenet/node/fcp/FCPConnectionInputHandler.java
===================================================================
--- trunk/freenet/src/freenet/node/fcp/FCPConnectionInputHandler.java   
2007-11-17 12:27:06 UTC (rev 15797)
+++ trunk/freenet/src/freenet/node/fcp/FCPConnectionInputHandler.java   
2007-11-17 12:27:57 UTC (rev 15798)
@@ -82,7 +82,7 @@
                        try {
                                if(Logger.shouldLog(Logger.DEBUG, this))
                                        Logger.debug(this, "Incoming FCP 
message:\n"+messageType+'\n'+fs.toString());
-                               msg = FCPMessage.create(messageType, fs, 
handler.bf, handler.server.core.persistentTempBucketFactory);
+                               msg = FCPMessage.create(messageType, fs, 
handler.bf, handler.server.core.persistentTempBucketFactory, 
handler.server.node.pluginManager);
                                if(msg == null) continue;
                        } catch (MessageInvalidException e) {
                                if(firstMessage) {

Modified: trunk/freenet/src/freenet/node/fcp/FCPMessage.java
===================================================================
--- trunk/freenet/src/freenet/node/fcp/FCPMessage.java  2007-11-17 12:27:06 UTC 
(rev 15797)
+++ trunk/freenet/src/freenet/node/fcp/FCPMessage.java  2007-11-17 12:27:57 UTC 
(rev 15798)
@@ -4,6 +4,8 @@
 import java.io.OutputStream;

 import freenet.node.Node;
+import freenet.pluginmanager.FredPluginFCP;
+import freenet.pluginmanager.PluginManager;
 import freenet.support.Logger;
 import freenet.support.SimpleFieldSet;
 import freenet.support.api.BucketFactory;
@@ -34,7 +36,7 @@
        /**
         * Create a message from a SimpleFieldSet, and the message's name, if 
possible. 
         */
-       public static FCPMessage create(String name, SimpleFieldSet fs, 
BucketFactory bfTemp, PersistentTempBucketFactory bfPersistent) throws 
MessageInvalidException {
+       public static FCPMessage create(String name, SimpleFieldSet fs, 
BucketFactory bfTemp, PersistentTempBucketFactory bfPersistent, PluginManager 
pluginmanager) throws MessageInvalidException {
                if(name.equals(AddPeer.NAME))
                        return new AddPeer(fs);
                if(name.equals(ClientGetMessage.NAME))
@@ -87,6 +89,28 @@
                        return new WatchGlobal(fs);
                if(name.equals("Void"))
                        return null;
+               // We reached here? Must be a plugin. find it
+               
+               // plugins.HelloFCP.HelloFCP.Ping
+               // split at last point
+               int lp = name.lastIndexOf('.'); 
+               if (lp > 2) {
+                       String plugname = name.substring(0, lp);
+                       String plugcmd = name.substring(lp+1);
+                       
+                       System.err.println("plugname: " + plugname);
+                       System.err.println("plugcmd: " + plugcmd);
+               
+                       FredPluginFCP plug = 
pluginmanager.getFCPPlugin(plugname);
+                       if (plug != null) {
+                               System.err.println("plug found: " + plugname);
+                               FCPMessage msg = plug.create(plugcmd, fs);
+                               if (msg != null) {
+                                       System.err.println("plug cmd seems 
valid: " + plugcmd);
+                                       return msg;
+                               }
+                       }
+               }
                throw new 
MessageInvalidException(ProtocolErrorMessage.INVALID_MESSAGE, "Unknown message 
name "+name, null, false);
        }

@@ -95,7 +119,7 @@
         * Usefull for FCPClients
         */
        public static FCPMessage create(String name, SimpleFieldSet fs) throws 
MessageInvalidException {
-               return FCPMessage.create(name, fs, null, null);
+               return FCPMessage.create(name, fs, null, null, null);
        }

        /** Do whatever it is that we do with this type of message. 

Modified: trunk/freenet/src/freenet/node/fcp/ProtocolErrorMessage.java
===================================================================
--- trunk/freenet/src/freenet/node/fcp/ProtocolErrorMessage.java        
2007-11-17 12:27:06 UTC (rev 15797)
+++ trunk/freenet/src/freenet/node/fcp/ProtocolErrorMessage.java        
2007-11-17 12:27:57 UTC (rev 15798)
@@ -28,7 +28,7 @@
        static final int FREENET_URI_PARSE_ERROR = 4;
        static final int MISSING_FIELD = 5;
        static final int ERROR_PARSING_NUMBER = 6;
-       static final int INVALID_MESSAGE = 7;
+       public static final int INVALID_MESSAGE = 7;
        static final int INVALID_FIELD = 8;
        static final int FILE_NOT_FOUND = 9;
        static final int DISK_TARGET_EXISTS = 10;

Modified: trunk/freenet/src/freenet/pluginmanager/PluginInfoWrapper.java
===================================================================
--- trunk/freenet/src/freenet/pluginmanager/PluginInfoWrapper.java      
2007-11-17 12:27:06 UTC (rev 15797)
+++ trunk/freenet/src/freenet/pluginmanager/PluginInfoWrapper.java      
2007-11-17 12:27:57 UTC (rev 15798)
@@ -20,6 +20,7 @@
        private boolean isIPDetectorPlugin;
        private boolean isPortForwardPlugin;
        private boolean isMultiplePlugin;
+       private boolean isFCPPlugin;
        private String filename;
        private HashSet toadletLinks=new HashSet();
        private boolean stopping = false;
@@ -39,6 +40,7 @@
                isIPDetectorPlugin = (plug instanceof FredPluginIPDetector);
                isPortForwardPlugin = (plug instanceof FredPluginPortForward);
                isMultiplePlugin = (plug instanceof FredPluginMultiple);
+               isFCPPlugin = (plug instanceof FredPluginFCP);
        }

        void setThread(Thread ps) {
@@ -156,6 +158,10 @@
        public boolean isMultiplePlugin() {
                return isMultiplePlugin;
        }
+       
+       public boolean isFCPPlugin() {
+               return isFCPPlugin;
+       }

        public synchronized boolean isStopping() {
                return stopping;

Modified: trunk/freenet/src/freenet/pluginmanager/PluginManager.java
===================================================================
--- trunk/freenet/src/freenet/pluginmanager/PluginManager.java  2007-11-17 
12:27:06 UTC (rev 15797)
+++ trunk/freenet/src/freenet/pluginmanager/PluginManager.java  2007-11-17 
12:27:57 UTC (rev 15798)
@@ -344,6 +344,22 @@
                }
                return out;
        }
+       
+       /**
+        * look for a FCPPlugin with given classname
+        * @param plugname
+        * @return the plugin or null if not found
+        */
+       public FredPluginFCP getFCPPlugin(String plugname) {
+               synchronized (pluginWrappers) {
+                       for(int i=0;i<pluginWrappers.size();i++) {
+                               PluginInfoWrapper pi = (PluginInfoWrapper) 
pluginWrappers.get(i);
+                               if (pi.isFCPPlugin() && 
pi.getPluginClassName().equals(plugname))
+                                       return (FredPluginFCP) pi.plug;
+                       }
+               }
+               return null;
+       }

        public String handleHTTPGet(String plugin, HTTPRequest request) throws 
PluginHTTPException {
                FredPlugin handler = null;


Reply via email to