On Wed, Jul 16, 2003 at 02:58:56AM +0100, Toad wrote: > Fish produced a patch for this, which had some minor issues IIRC, but > could probably be integrated reasonably easily.
it didn't support metadata properly. this one does, although
it's in a file called 'metadata' rather than the java manifest, to
allow people to use (win)zip to create the files rather than having
to deal with the horrors of jar cvf sdjl.har foo.
it detects based on mime type, btw, which is i guess important for
one reason or another, but does allow one ot still have path names
that don't look like ass.
right now, if there is no filename, it will donwload the jar, so as
to not intefere with people distributing them already ;)
it worked for me when i tested it, but that's really all i have to
say about that
- jj
Index: GetRequestProcess.java
===================================================================
RCS file: /cvsroot/freenet/freenet/src/freenet/client/GetRequestProcess.java,v
retrieving revision 1.24
diff -u -3 -p -r1.24 GetRequestProcess.java
--- GetRequestProcess.java 16 May 2003 18:52:37 -0000 1.24
+++ GetRequestProcess.java 20 Jul 2003 19:37:31 -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,114 @@ 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="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;
+ boolean metafound=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=metafound=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);
+ if(metafound)
+ {
+ // check that this document
exists in the metadata
+ // and ignore the metadata if
it doens't, to prevent
+ // big scary monsters eating
you and, more importantly,
+ // throwing a key not in
metadata exception
+
if(metadata.getDocument(containerFile)==null)
+
uri=uri.popMetaString();
+ }
+ else
+ 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
pgp00000.pgp
Description: PGP signature
