Author: toad
Date: 2008-01-18 14:04:15 +0000 (Fri, 18 Jan 2008)
New Revision: 17136

Modified:
   trunk/freenet/src/freenet/client/Metadata.java
   trunk/freenet/src/freenet/client/async/ClientGetter.java
   trunk/freenet/src/freenet/client/async/GetCompletionCallback.java
   trunk/freenet/src/freenet/client/async/SingleFileFetcher.java
   trunk/freenet/src/freenet/client/async/SplitFileFetcher.java
   trunk/freenet/src/freenet/client/async/USKFetcherWrapper.java
   trunk/freenet/src/freenet/client/async/USKProxyCompletionCallback.java
   trunk/freenet/src/freenet/client/async/USKRetriever.java
   trunk/freenet/src/freenet/node/fcp/ClientGet.java
Log:
Propagate size/mime type data, so we can show it on the fproxy homepage

Modified: trunk/freenet/src/freenet/client/Metadata.java
===================================================================
--- trunk/freenet/src/freenet/client/Metadata.java      2008-01-18 13:57:32 UTC 
(rev 17135)
+++ trunk/freenet/src/freenet/client/Metadata.java      2008-01-18 14:04:15 UTC 
(rev 17136)
@@ -925,4 +925,9 @@
                clientMetadata.clear();
                documentType = ZIP_MANIFEST;
        }
+
+       public String getMIMEType() {
+               if(clientMetadata == null) return null;
+               return clientMetadata.getMIMEType();
+       }
 }

Modified: trunk/freenet/src/freenet/client/async/ClientGetter.java
===================================================================
--- trunk/freenet/src/freenet/client/async/ClientGetter.java    2008-01-18 
13:57:32 UTC (rev 17135)
+++ trunk/freenet/src/freenet/client/async/ClientGetter.java    2008-01-18 
14:04:15 UTC (rev 17136)
@@ -41,6 +41,9 @@
        /** If not null, HashSet to track keys already added for a binary blob 
*/
        final HashSet binaryBlobKeysAddedAlready;
        private DataOutputStream binaryBlobStream;
+       private String expectedMIME;
+       private long expectedSize;
+       private boolean finalizedMetadata;

        /**
         * Fetch a key.
@@ -315,4 +318,30 @@
        boolean collectingBinaryBlob() {
                return binaryBlobBucket != null;
        }
+
+       public void onExpectedMIME(String mime) {
+               if(finalizedMetadata) return;
+               expectedMIME = mime;
+       }
+
+       public void onExpectedSize(long size) {
+               if(finalizedMetadata) return;
+               expectedSize = size;
+       }
+
+       public void onFinalizedMetadata() {
+               finalizedMetadata = true;
+       }
+       
+       public boolean finalizedMetadata() {
+               return finalizedMetadata;
+       }
+       
+       public String expectedMIME() {
+               return expectedMIME;
+       }
+       
+       public long expectedSize() {
+               return expectedSize;
+       }
 }
\ No newline at end of file

Modified: trunk/freenet/src/freenet/client/async/GetCompletionCallback.java
===================================================================
--- trunk/freenet/src/freenet/client/async/GetCompletionCallback.java   
2008-01-18 13:57:32 UTC (rev 17135)
+++ trunk/freenet/src/freenet/client/async/GetCompletionCallback.java   
2008-01-18 14:04:15 UTC (rev 17136)
@@ -23,4 +23,10 @@

        public void onTransition(ClientGetState oldState, ClientGetState 
newState);

+       public void onExpectedSize(long size);
+       
+       public void onExpectedMIME(String mime);
+       
+       public void onFinalizedMetadata();
+       
 }

Modified: trunk/freenet/src/freenet/client/async/SingleFileFetcher.java
===================================================================
--- trunk/freenet/src/freenet/client/async/SingleFileFetcher.java       
2008-01-18 13:57:32 UTC (rev 17135)
+++ trunk/freenet/src/freenet/client/async/SingleFileFetcher.java       
2008-01-18 14:04:15 UTC (rev 17136)
@@ -303,6 +303,8 @@
                        } else if(metadata.isArchiveInternalRedirect()) {
                                if(logMINOR) Logger.minor(this, "Is 
archive-internal redirect");
                                
clientMetadata.mergeNoOverwrite(metadata.getClientMetadata());
+                               String mime = clientMetadata.getMIMEType();
+                               if(mime != null) rcb.onExpectedMIME(mime);
                                if(metaStrings.isEmpty() && isFinal && 
clientMetadata.getMIMETypeNoParams() != null && ctx.allowedMIMETypes != null &&
                                                
!ctx.allowedMIMETypes.contains(clientMetadata.getMIMETypeNoParams())) {
                                        throw new 
FetchException(FetchException.WRONG_MIME_TYPE, -1, false, 
clientMetadata.getMIMEType());
@@ -382,6 +384,8 @@
                        } else if(metadata.isSingleFileRedirect()) {
                                if(logMINOR) Logger.minor(this, "Is single-file 
redirect");
                                
clientMetadata.mergeNoOverwrite(metadata.getClientMetadata()); // even 
splitfiles can have mime types!
+                               String mime = clientMetadata.getMIMEType();
+                               if(mime != null) rcb.onExpectedMIME(mime);

                                String mimeType = 
clientMetadata.getMIMETypeNoParams();
                                if(mimeType != null && 
ArchiveManager.isUsableArchiveType(mimeType) && metaStrings.size() > 0) {
@@ -444,6 +448,8 @@
                                if(logMINOR) Logger.minor(this, "Fetching 
splitfile");

                                
clientMetadata.mergeNoOverwrite(metadata.getClientMetadata()); // even 
splitfiles can have mime types!
+                               String mime = clientMetadata.getMIMEType();
+                               if(mime != null) rcb.onExpectedMIME(mime);

                                String mimeType = 
clientMetadata.getMIMETypeNoParams();
                                if(mimeType != null && 
ArchiveManager.isUsableArchiveType(mimeType) && metaStrings.size() > 0) {
@@ -605,6 +611,18 @@
                public void onTransition(ClientGetState oldState, 
ClientGetState newState) {
                        // Ignore
                }
+
+               public void onExpectedMIME(String mime) {
+                       // Ignore
+               }
+
+               public void onExpectedSize(long size) {
+                       rcb.onExpectedSize(size);
+               }
+
+               public void onFinalizedMetadata() {
+                       // Ignore
+               }

        }

@@ -636,6 +654,18 @@
                public void onTransition(ClientGetState oldState, 
ClientGetState newState) {
                        // Ignore
                }
+
+               public void onExpectedMIME(String mime) {
+                       // Ignore
+               }
+
+               public void onExpectedSize(long size) {
+                       rcb.onExpectedSize(size);
+               }
+
+               public void onFinalizedMetadata() {
+                       // Ignore
+               }

        }


Modified: trunk/freenet/src/freenet/client/async/SplitFileFetcher.java
===================================================================
--- trunk/freenet/src/freenet/client/async/SplitFileFetcher.java        
2008-01-18 13:57:32 UTC (rev 17135)
+++ trunk/freenet/src/freenet/client/async/SplitFileFetcher.java        
2008-01-18 14:04:15 UTC (rev 17136)
@@ -85,8 +85,13 @@
                                throw new 
FetchException(FetchException.INVALID_METADATA, "Splitfile is "+finalLength+" 
but length is "+finalLength);
                        finalLength = overrideLength;
                }
-               
                long eventualLength = Math.max(overrideLength, 
metadata.uncompressedDataLength());
+               cb.onExpectedSize(eventualLength);
+               String mimeType = metadata.getMIMEType();
+               if(mimeType != null)
+                       cb.onExpectedMIME(mimeType);
+               if(metadata.uncompressedDataLength() > 0)
+                       cb.onFinalizedMetadata();
                if(eventualLength > 0 && newCtx.maxOutputLength > 0 && 
eventualLength > newCtx.maxOutputLength)
                        throw new FetchException(FetchException.TOO_BIG, 
eventualLength, true, clientMetadata.getMIMEType());


Modified: trunk/freenet/src/freenet/client/async/USKFetcherWrapper.java
===================================================================
--- trunk/freenet/src/freenet/client/async/USKFetcherWrapper.java       
2008-01-18 13:57:32 UTC (rev 17135)
+++ trunk/freenet/src/freenet/client/async/USKFetcherWrapper.java       
2008-01-18 14:04:15 UTC (rev 17136)
@@ -51,4 +51,16 @@
        public String toString() {
                return super.toString()+ ':' +usk;
        }
+
+       public void onExpectedMIME(String mime) {
+               // Ignore
+       }
+
+       public void onExpectedSize(long size) {
+               // Ignore
+       }
+
+       public void onFinalizedMetadata() {
+               // Ignore
+       }
 }

Modified: trunk/freenet/src/freenet/client/async/USKProxyCompletionCallback.java
===================================================================
--- trunk/freenet/src/freenet/client/async/USKProxyCompletionCallback.java      
2008-01-18 13:57:32 UTC (rev 17135)
+++ trunk/freenet/src/freenet/client/async/USKProxyCompletionCallback.java      
2008-01-18 14:04:15 UTC (rev 17136)
@@ -42,4 +42,16 @@
                // Ignore
        }

+       public void onExpectedMIME(String mime) {
+               cb.onExpectedMIME(mime);
+       }
+
+       public void onExpectedSize(long size) {
+               cb.onExpectedSize(size);
+       }
+
+       public void onFinalizedMetadata() {
+               cb.onFinalizedMetadata();
+       }
+
 }

Modified: trunk/freenet/src/freenet/client/async/USKRetriever.java
===================================================================
--- trunk/freenet/src/freenet/client/async/USKRetriever.java    2008-01-18 
13:57:32 UTC (rev 17135)
+++ trunk/freenet/src/freenet/client/async/USKRetriever.java    2008-01-18 
14:04:15 UTC (rev 17136)
@@ -76,4 +76,16 @@
                // Ignore
        }

+       public void onExpectedMIME(String mime) {
+               // Ignore
+       }
+
+       public void onExpectedSize(long size) {
+               // Ignore
+       }
+
+       public void onFinalizedMetadata() {
+               // Ignore
+       }
+
 }

Modified: trunk/freenet/src/freenet/node/fcp/ClientGet.java
===================================================================
--- trunk/freenet/src/freenet/node/fcp/ClientGet.java   2008-01-18 13:57:32 UTC 
(rev 17135)
+++ trunk/freenet/src/freenet/node/fcp/ClientGet.java   2008-01-18 14:04:15 UTC 
(rev 17136)
@@ -619,11 +619,19 @@
        }

        public long getDataSize() {
-               return foundDataLength;
+               if(foundDataLength > 0)
+                       return foundDataLength;
+               if(getter != null)
+                       return getter.expectedSize();
+               return -1;
        }

        public String getMIMEType() {
-               return foundDataMimeType;
+               if(foundDataMimeType != null)
+                       return foundDataMimeType;
+               if(getter != null)
+                       return getter.expectedMIME();
+               return null;
        }

        public File getDestFilename() {


Reply via email to