If you're going to include filename you should include the URI it was fetched 
from and whether it will be auto-refreshed. Are there corresponding commands 
to list plugins? Also eventually we may have multiple plugins of the same 
class - is there anything we can do to prepare for this?

On Saturday 17 November 2007 21:06, saces at freenetproject.org wrote:
> Author: saces
> Date: 2007-11-17 21:06:14 +0000 (Sat, 17 Nov 2007)
> New Revision: 15800
> 
> Added:
>    trunk/freenet/src/freenet/node/fcp/GetPluginInfo.java
>    trunk/freenet/src/freenet/node/fcp/PluginInfoMessage.java
> Modified:
>    trunk/freenet/src/freenet/node/fcp/FCPMessage.java
>    trunk/freenet/src/freenet/node/fcp/ProtocolErrorMessage.java
>    trunk/freenet/src/freenet/pluginmanager/PluginManager.java
> Log:
> new fcp command to ask for the presence of a plugin (GetPluginInfo)
> 
> Modified: trunk/freenet/src/freenet/node/fcp/FCPMessage.java
> ===================================================================
> --- trunk/freenet/src/freenet/node/fcp/FCPMessage.java        2007-11-17 
> 12:29:18 
UTC (rev 15799)
> +++ trunk/freenet/src/freenet/node/fcp/FCPMessage.java        2007-11-17 
> 21:06:14 
UTC (rev 15800)
> @@ -55,6 +55,8 @@
>                       return new GetConfig(fs);
>               if(name.equals(GetNode.NAME))
>                       return new GetNode(fs);
> +             if(name.equals(GetPluginInfo.NAME))
> +                     return new GetPluginInfo(fs);
>               if(name.equals(GetRequestStatusMessage.NAME))
>                       return new GetRequestStatusMessage(fs);
>               if(name.equals(ListPeerMessage.NAME))
> 
> Added: trunk/freenet/src/freenet/node/fcp/GetPluginInfo.java
> ===================================================================
> --- trunk/freenet/src/freenet/node/fcp/GetPluginInfo.java                     
>         
(rev 0)
> +++ trunk/freenet/src/freenet/node/fcp/GetPluginInfo.java     2007-11-17 
21:06:14 UTC (rev 15800)
> @@ -0,0 +1,50 @@
> +/* This code is part of Freenet. It is distributed under the GNU General
> + * Public License, version 2 (or at your option any later version). See
> + * http://www.gnu.org/ for further details of the GPL. */
> +package freenet.node.fcp;
> +
> +import freenet.node.Node;
> +import freenet.pluginmanager.PluginInfoWrapper;
> +import freenet.pluginmanager.PluginManager;
> +import freenet.support.Fields;
> +import freenet.support.SimpleFieldSet;
> +
> +public class GetPluginInfo extends FCPMessage {
> +
> +     static final String NAME = "GetPluginInfo";
> +     
> +     private final String identifier;
> +     private final boolean detailed;
> +     private final String plugname;
> +     
> +     public GetPluginInfo(SimpleFieldSet fs) throws MessageInvalidException {
> +             identifier = fs.get("Identifier");  // optional
> +             detailed = Fields.stringToBool(fs.get("Detailed"), false);
> +             plugname = fs.get("PluginName");
> +             if(plugname == null)
> +                     throw new 
MessageInvalidException(ProtocolErrorMessage.MISSING_FIELD, "GetPluginInfo 
must contain a PluginName field", null, false);
> +     }
> +     
> +     public SimpleFieldSet getFieldSet() {
> +             return new SimpleFieldSet(true);
> +     }
> +     
> +     public String getName() {
> +             return NAME;
> +     }
> +     
> +     public void run(FCPConnectionHandler handler, Node node)
> +                     throws MessageInvalidException {
> +             if(!handler.hasFullAccess()) {
> +                     throw new 
MessageInvalidException(ProtocolErrorMessage.ACCESS_DENIED, "GetPluginInfo 
requires full access", identifier, false);
> +             }
> +
> +             PluginInfoWrapper pi = 
> node.pluginManager.getPluginInfo(plugname);
> +             if (pi == null) {
> +                     handler.outputHandler.queue(new 
ProtocolErrorMessage(ProtocolErrorMessage.NO_SUCH_PLUGIN, false, "Plugin '"+ 
plugname + "' does not exist", identifier, false));
> +             } else {
> +                     handler.outputHandler.queue(new PluginInfoMessage(pi, 
> identifier, 
detailed));
> +             }
> +     }
> +     
> +}
> 
> Added: trunk/freenet/src/freenet/node/fcp/PluginInfoMessage.java
> ===================================================================
> --- trunk/freenet/src/freenet/node/fcp/PluginInfoMessage.java                 
>         
(rev 0)
> +++ trunk/freenet/src/freenet/node/fcp/PluginInfoMessage.java 2007-11-17 
21:06:14 UTC (rev 15800)
> @@ -0,0 +1,62 @@
> +/* This code is part of Freenet. It is distributed under the GNU General
> + * Public License, version 2 (or at your option any later version). See
> + * http://www.gnu.org/ for further details of the GPL. */
> +package freenet.node.fcp;
> +
> +import freenet.node.Node;
> +import freenet.pluginmanager.PluginInfoWrapper;
> +import freenet.support.SimpleFieldSet;
> +
> +/**
> + * @author saces
> + *
> + */
> +public class PluginInfoMessage extends FCPMessage {
> +     
> +     static final String NAME = "PluginInfo";
> +     
> +     private final String identifier;
> +     
> +     private final boolean detailed;
> +
> +     private final String classname;
> +     private final String filename;
> +
> +     private final boolean isHTTP;
> +     private final boolean isFCP;
> +     
> +     PluginInfoMessage(PluginInfoWrapper pi, String identifier, boolean 
> detail) 
{
> +             this.identifier = identifier;
> +             this.detailed = detail;
> +             
> +             classname = pi.getPluginClassName();
> +             filename = pi.getFilename();
> +             
> +             isHTTP = pi.isPproxyPlugin();
> +             isFCP = pi.isFCPPlugin();
> +     }
> +
> +     public SimpleFieldSet getFieldSet() {
> +             SimpleFieldSet sfs = new SimpleFieldSet(true);
> +             if(identifier != null) // is optional on these two only
> +                     sfs.putSingle("Identifier", identifier);
> +             sfs.putSingle("PluginName", classname);
> +             
> +             if (detailed) {
> +                     sfs.putSingle("FileName", filename);
> +                     
> +                     sfs.put("IsHTTPPlugin", isHTTP);
> +                     sfs.put("IsFCPPlugin", isFCP);
> +             }
> +             return sfs;
> +     }
> +
> +     public String getName() {
> +             return NAME;
> +     }
> +
> +     public void run(FCPConnectionHandler handler, Node node) throws 
MessageInvalidException {
> +             throw new 
> MessageInvalidException(ProtocolErrorMessage.INVALID_MESSAGE, 
NAME + " goes from server to client not the other way around", null, false);
> +     }
> +
> +}
> 
> Modified: trunk/freenet/src/freenet/node/fcp/ProtocolErrorMessage.java
> ===================================================================
> --- trunk/freenet/src/freenet/node/fcp/ProtocolErrorMessage.java      
> 2007-11-17 
12:29:18 UTC (rev 15799)
> +++ trunk/freenet/src/freenet/node/fcp/ProtocolErrorMessage.java      
> 2007-11-17 
21:06:14 UTC (rev 15800)
> @@ -53,6 +53,7 @@
>       static final int DUPLICATE_PEER_REF = 29;
>       static final int OPENNET_DISABLED = 30;
>       static final int DARKNET_ONLY = 31;
> +     static final int NO_SUCH_PLUGIN = 32;  
>       
>       final int code;
>       final String extra;
> @@ -124,6 +125,8 @@
>                       return "Opennet is currently disabled in the node's 
> configuration";
>               case DARKNET_ONLY:
>                       return "Operation only available on a darknet peer";
> +             case NO_SUCH_PLUGIN:
> +                     return "No such plugin";
>               default:
>                       Logger.error(this, "Unknown error code: "+code, new 
> Exception("debug"));
>               return "(Unknown)";
> 
> Modified: trunk/freenet/src/freenet/pluginmanager/PluginManager.java
> ===================================================================
> --- trunk/freenet/src/freenet/pluginmanager/PluginManager.java        
> 2007-11-17 
12:29:18 UTC (rev 15799)
> +++ trunk/freenet/src/freenet/pluginmanager/PluginManager.java        
> 2007-11-17 
21:06:14 UTC (rev 15800)
> @@ -346,6 +346,22 @@
>       }
>       
>       /**
> +      * look for PluginInfo for a Plugin with given classname
> +      * @param plugname
> +      * @return the PluginInfo or null if not found
> +      */
> +     public PluginInfoWrapper getPluginInfo(String plugname) {
> +             synchronized (pluginWrappers) {
> +                     for(int i=0;i<pluginWrappers.size();i++) {
> +                             PluginInfoWrapper pi = (PluginInfoWrapper) 
> pluginWrappers.get(i);
> +                             if (pi.getPluginClassName().equals(plugname))
> +                                     return pi;
> +                     }
> +             }
> +             return null;
> +     }
> +     
> +     /**
>        * look for a FCPPlugin with given classname
>        * @param plugname
>        * @return the plugin or null if not found
> 
> _______________________________________________
> cvs mailing list
> cvs at freenetproject.org
> http://emu.freenetproject.org/cgi-bin/mailman/listinfo/cvs
> 
> 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
URL: 
<https://emu.freenetproject.org/pipermail/devl/attachments/20071117/f88c00a6/attachment.pgp>

Reply via email to