Author: toad
Date: 2007-06-16 20:30:15 +0000 (Sat, 16 Jun 2007)
New Revision: 13627

Modified:
   trunk/freenet/src/freenet/node/fcp/ClientGet.java
   trunk/freenet/src/freenet/node/fcp/ClientGetMessage.java
   trunk/freenet/src/freenet/support/SimpleFieldSet.java
Log:
FCP support for AllowedMIMETypes

Modified: trunk/freenet/src/freenet/node/fcp/ClientGet.java
===================================================================
--- trunk/freenet/src/freenet/node/fcp/ClientGet.java   2007-06-16 20:20:17 UTC 
(rev 13626)
+++ trunk/freenet/src/freenet/node/fcp/ClientGet.java   2007-06-16 20:30:15 UTC 
(rev 13627)
@@ -6,6 +6,7 @@
 import java.io.File;
 import java.io.FileOutputStream;
 import java.io.IOException;
+import java.util.HashSet;

 import freenet.client.FetchContext;
 import freenet.client.FetchException;
@@ -267,6 +268,12 @@
                }
                returnBucket = ret;

+               String[] allowed = fs.getAll("AllowedMIMETypes");
+               if(allowed != null) {
+                       fctx.allowedMIMETypes = new HashSet();
+                       for(int i=0;i<allowed.length;i++) 
fctx.allowedMIMETypes.add(allowed[i]);
+               }
+               
                getter = new ClientGetter(this, 
client.core.requestStarters.chkFetchScheduler, 
                                client.core.requestStarters.sskFetchScheduler, 
uri, 
                                fctx, priorityClass, client.lowLevelClient, 
@@ -527,6 +534,8 @@
                fs.putSingle("MaxRetries", 
Integer.toString(fctx.maxNonSplitfileRetries));
                fs.putSingle("Finished", Boolean.toString(finished));
                fs.putSingle("Succeeded", Boolean.toString(succeeded));
+               if(fctx.allowedMIMETypes != null)
+                       fs.putOverwrite("AllowedMIMETypes", (String[]) 
fctx.allowedMIMETypes.toArray(new String[fctx.allowedMIMETypes.size()]));
                if(finished) {
                        if(succeeded) {
                                fs.putSingle("FoundDataLength", 
Long.toString(foundDataLength));

Modified: trunk/freenet/src/freenet/node/fcp/ClientGetMessage.java
===================================================================
--- trunk/freenet/src/freenet/node/fcp/ClientGetMessage.java    2007-06-16 
20:20:17 UTC (rev 13626)
+++ trunk/freenet/src/freenet/node/fcp/ClientGetMessage.java    2007-06-16 
20:30:15 UTC (rev 13627)
@@ -55,6 +55,7 @@
        final String clientToken;
        final boolean global;
        final boolean binaryBlob;
+       final String[] allowedMIMETypes;

        // FIXME move these to the actual getter process
        static final short RETURN_TYPE_DIRECT = 0; // over FCP
@@ -69,6 +70,7 @@
                ignoreDS = Fields.stringToBool(fs.get("IgnoreDS"), false);
                dsOnly = Fields.stringToBool(fs.get("DSOnly"), false);
                identifier = fs.get("Identifier");
+               allowedMIMETypes = fs.getAll("AllowedMIMETypes");
                if(identifier == null)
                        throw new 
MessageInvalidException(ProtocolErrorMessage.MISSING_FIELD, "No Identifier", 
null, global);
                try {

Modified: trunk/freenet/src/freenet/support/SimpleFieldSet.java
===================================================================
--- trunk/freenet/src/freenet/support/SimpleFieldSet.java       2007-06-16 
20:20:17 UTC (rev 13626)
+++ trunk/freenet/src/freenet/support/SimpleFieldSet.java       2007-06-16 
20:30:15 UTC (rev 13627)
@@ -181,7 +181,9 @@
     }

     public String[] getAll(String key) {
-       return split(get(key));
+       String k = get(key);
+       if(k == null) return null;
+       return split(k);
     }

     private static final String[] split(String string) {
@@ -203,6 +205,15 @@
 //     return (String[]) v.toArray();
        }

+    private static final String unsplit(String[] strings) {
+       StringBuffer sb = new StringBuffer();
+       for(int i=0;i<strings.length;i++) {
+               if(i != 0) sb.append(';');
+               sb.append(strings[i]);
+       }
+       return sb.toString();
+    }
+    
     /**
      * Put contents of a fieldset, overwrite old values.
      */
@@ -714,4 +725,8 @@
                return ret;
        }

+       public void putOverwrite(String key, String[] strings) {
+               putOverwrite(key, unsplit(strings));
+       }
+
 }


Reply via email to