On Thu, Jun 26, 2003 at 07:10:16PM +0100, Toad wrote:
> On Fri, Jun 27, 2003 at 02:06:24AM +1000, fish wrote:
> Just do it with the metadata. The zip manifest file will have metadata,
> the metadata will have a new kind of redirect inside it. And where is
> the metadata spec again? :)

Hrm, so I read that completly incorrectly originally, implented it 
differently, but in some respects I prefer this method - ezach file
has an associated file.metadata with the metadata for that file. 
The nice thing about this, as opposed to the sttoring the data in the 
zip manifst, is that it doens't require modification of client tools
in order to take advantage of it.  But I'll change it if people really
care, heh

> > Attempting to actualyl use this will result in bad things, most likely.  Like
> > the old release notes said, this isn't supposed to work, and if it does, then
> > ergo it isn't doing what it's supposed to, and hence isn't working :)
> 
> Oh, and don't implement it at the fproxy level! Implement it at the
> freenet.client level.

So I implented it at freenet.client level, hopefully in the correct place.
(GetRequestProcess).  I fully expect that it's still bob the angry flower, but
it seems sensible in my world ;)

        --fish

Index: GetRequestProcess.java
===================================================================
RCS file: /cvsroot/freenet/freenet/src/freenet/client/GetRequestProcess.java,v
retrieving revision 1.24
diff -u -3 -p -u -r1.24 GetRequestProcess.java
--- GetRequestProcess.java      16 May 2003 18:52:37 -0000      1.24
+++ GetRequestProcess.java      27 Jun 2003 08:06:42 -0000
@@ -6,8 +6,10 @@ import freenet.client.metadata.MetadataS
 import freenet.client.metadata.DocumentCommand;
 import freenet.client.metadata.InvalidPartException;
 import freenet.support.Bucket;
+import freenet.support.BucketTools;
 import freenet.support.BucketFactory;
 import freenet.support.ArrayBucket;
+import freenet.support.FileBucket;
 import freenet.support.io.DataNotValidIOException;
 import freenet.client.events.GeneratedURIEvent;
 import freenet.client.events.RedirectFollowedEvent;
@@ -20,6 +22,9 @@ import java.io.IOException;
 import java.util.Vector;
 import freenet.Core; // for logging
 import freenet.support.Logger;
+import java.io.*;
+import java.util.jar.*;
+import java.util.zip.*;
 /**
  * Handeles a series of requests to fill a bucket by traversing down
  * metadata redirections.
@@ -48,6 +53,11 @@ public class GetRequestProcess extends C
     }
 
     public synchronized Request getNextRequest() {
+           return this.getNextRequest(true);
+    }
+    
+           
+    public synchronized Request getNextRequest(boolean followContainer) {
        boolean logDEBUG = Core.logger.shouldLog(Logger.DEBUG);
        if(logDEBUG) 
            Core.logger.log(this, "In getNextRequest() for "+this, Logger.DEBUG);
@@ -93,6 +103,103 @@ public class GetRequestProcess extends C
                        if(logDEBUG)
                            Core.logger.log(this, "Processed Metadata for "+this+":\n"+
                                            metadata.writeString(), Logger.DEBUG);
+
+                       // Check for a JAR archive - do this by mime type
+                       String mimeType=metadata.getMimeType(null);
+                       if(mimeType != null && followContainer)
+                       {
+                               
if(mimeType.equalsIgnoreCase("application/x-java-archive"))
+                               {
+                                       String containerFile=uri.getMetaString();
+                                       // follow the jar
+                                       // Check if we need to de-container this file
+                                       // FIXME: cache jar's
+                                       if(containerFile != null)
+                                       {
+                                               Bucket newData = new FileBucket();
+                                               metadataBucket = new ArrayBucket();
+                                               InputStream myIs=data.getInputStream();
+                                               JarInputStream myJis=new 
JarInputStream(myIs);
+                                               String 
containerMeta=containerFile+".metadata";
+                                               // because we don't have access to a 
File object,
+                                               // we have to skip through until we 
hit our filename...
+                                               JarEntry ent=null;
+                                               boolean done=false;
+                                               boolean metadone=false;
+                                               do
+                                               {
+                                                               try {
+                                                                       
ent=myJis.getNextJarEntry();
+                                                                       if(ent==null)
+                                                                       {
+                                                                               
if(!done)
+                                                                               {
+                                                                                      
 // No file of this name
+                                                                                      
 origThrowable = new 
+                                                                                      
 KeyNotInManifestException();
+                                                           failed = true;
+                                                           return null;
+                                                                               }
+                                                                               else
+                                                                               {
+                                                                                      
         // no metadata
+                                                                                      
         metadone=true;
+                                                                               }
+                                                                       }
+                                                                       else 
if(ent.getName().equalsIgnoreCase(containerFile))
+                                                                       {
+                                                                               
BufferedOutputStream myOs=new BufferedOutputStream(newData.getOutputStream());
+                                                                               
BufferedInputStream mybj=new BufferedInputStream(myJis);
+                                                                               int tt;
+                                                                               do
+                                                                               {
+                                                                                      
 tt=mybj.read();
+                                                                                      
 if(tt== -1)
+                                                                                      
 {
+                                                                                      
                 done=true;
+                                                                                      
 }
+                                                                                      
 else
+                                                                                      
 {
+                                                                                      
                 myOs.write(tt);
+                                                                                      
 }
+                                                                               } 
while(!done);
+                                                                       }
+                                                                       else 
if(ent.getName().equalsIgnoreCase(containerMeta))
+                                                                       {
+                                                                               
BufferedOutputStream myOs=new BufferedOutputStream(metadataBucket.getOutputStream());
+                                                                               
BufferedInputStream mybj=new BufferedInputStream(myJis);
+                                                                               int tt;
+                                                                               do
+                                                                               {
+                                                                                      
 tt=mybj.read();
+                                                                                      
 if(tt== -1)
+                                                                                      
 {
+                                                                                      
                 metadone=true;
+                                                                                      
 }
+                                                                                      
 else
+                                                                                      
 {
+                                                                                      
                 myOs.write(tt);
+                                                                                      
 }
+                                                                               } 
while(!metadone);
+                                                                       }
+                                                       } catch (ZipException e) {
+                                                               error = "Key not found 
in JAR Container";
+                                                               origThrowable = new 
+                                                           
KeyNotInManifestException();
+                                   failed = true;
+                                   return null;
+                                                       }
+                                               } while(!done || !metadone);
+                        metadata = 
+                            new Metadata(metadataBucket.getInputStream(),
+                                         msettings);
+                                               data.resetWrite();
+                                               BucketTools.copy(newData, data);
+                                               uri=uri.popMetaString();
+                                       }
+                               }
+                       }
+       
                         // Extract the checksum CHK from the info part.
                         // If more than one value is specified, we
                         // favor the one that is closest to the end

Attachment: pgp00000.pgp
Description: PGP signature

Reply via email to