Author: toad
Date: 2007-06-16 20:20:17 +0000 (Sat, 16 Jun 2007)
New Revision: 13626
Modified:
trunk/freenet/src/freenet/client/ClientMetadata.java
trunk/freenet/src/freenet/client/FetchContext.java
trunk/freenet/src/freenet/client/FetchException.java
trunk/freenet/src/freenet/client/async/SingleFileFetcher.java
trunk/freenet/src/freenet/l10n/freenet.l10n.en.properties
Log:
Fix another NPE, and add support in the client layer for a list of allowed MIME
types.
Modified: trunk/freenet/src/freenet/client/ClientMetadata.java
===================================================================
--- trunk/freenet/src/freenet/client/ClientMetadata.java 2007-06-16
19:32:35 UTC (rev 13625)
+++ trunk/freenet/src/freenet/client/ClientMetadata.java 2007-06-16
20:20:17 UTC (rev 13626)
@@ -56,4 +56,14 @@
public void clear() {
mimeType = null;
}
+
+ public String getMIMETypeNoParams() {
+ if(mimeType == null) return null;
+ String s = mimeType;
+ int i = s.indexOf(';');
+ if(i > -1) {
+ s = s.substring(i);
+ }
+ return s;
+ }
}
Modified: trunk/freenet/src/freenet/client/FetchContext.java
===================================================================
--- trunk/freenet/src/freenet/client/FetchContext.java 2007-06-16 19:32:35 UTC
(rev 13625)
+++ trunk/freenet/src/freenet/client/FetchContext.java 2007-06-16 20:20:17 UTC
(rev 13626)
@@ -3,6 +3,8 @@
* http://www.gnu.org/ for further details of the GPL. */
package freenet.client;
+import java.util.Set;
+
import freenet.client.async.BlockSet;
import freenet.client.async.HealingQueue;
import freenet.client.async.USKManager;
@@ -48,6 +50,7 @@
public final boolean ignoreTooManyPathComponents;
/** If set, contains a set of blocks to be consulted before checking
the datastore. */
public BlockSet blocks;
+ public Set allowedMIMETypes;
public FetchContext(long curMaxLength,
long curMaxTempLength, int maxMetadataSize, int
maxRecursionLevel, int maxArchiveRestarts, int maxArchiveLevels,
@@ -91,6 +94,7 @@
this.uskManager = ctx.uskManager;
this.ignoreTooManyPathComponents =
ctx.ignoreTooManyPathComponents;
this.blocks = ctx.blocks;
+ this.allowedMIMETypes = ctx.allowedMIMETypes;
if(maskID == IDENTICAL_MASK) {
this.maxOutputLength = ctx.maxOutputLength;
this.maxMetadataSize = ctx.maxMetadataSize;
Modified: trunk/freenet/src/freenet/client/FetchException.java
===================================================================
--- trunk/freenet/src/freenet/client/FetchException.java 2007-06-16
19:32:35 UTC (rev 13625)
+++ trunk/freenet/src/freenet/client/FetchException.java 2007-06-16
20:20:17 UTC (rev 13626)
@@ -285,6 +285,8 @@
public static final int ARCHIVE_RESTART = 26;
/** There is a more recent version of the USK, ~= HTTP 301; FProxy will
turn this into a 301 */
public static final int PERMANENT_REDIRECT = 27;
+ /** Requestor specified a list of allowed MIME types, and the key's
type wasn't in the list */
+ public static final int WRONG_MIME_TYPE = 29;
/** Is an error fatal i.e. is there no point retrying? */
public boolean isFatal() {
@@ -332,6 +334,7 @@
case CANCELLED:
case ARCHIVE_RESTART:
case PERMANENT_REDIRECT:
+ case WRONG_MIME_TYPE:
// Fatal
return true;
Modified: trunk/freenet/src/freenet/client/async/SingleFileFetcher.java
===================================================================
--- trunk/freenet/src/freenet/client/async/SingleFileFetcher.java
2007-06-16 19:32:35 UTC (rev 13625)
+++ trunk/freenet/src/freenet/client/async/SingleFileFetcher.java
2007-06-16 20:20:17 UTC (rev 13626)
@@ -307,6 +307,10 @@
} else if(metadata.isArchiveInternalRedirect()) {
if(logMINOR) Logger.minor(this, "Is
archive-internal redirect");
clientMetadata.mergeNoOverwrite(metadata.getClientMetadata());
+ if(clientMetadata.getMIMETypeNoParams() != null
&& ctx.allowedMIMETypes != null &&
+
!ctx.allowedMIMETypes.contains(clientMetadata.getMIMETypeNoParams())) {
+ onFailure(new
FetchException(FetchException.WRONG_MIME_TYPE));
+ }
// Fetch it from the archive
if(ah == null)
throw new
FetchException(FetchException.UNKNOWN_METADATA, "Archive redirect not in an
archive manifest");
@@ -375,12 +379,17 @@
clientMetadata.mergeNoOverwrite(metadata.getClientMetadata()); // even
splitfiles can have mime types!
String mimeType = clientMetadata.getMIMEType();
- if(ArchiveManager.isUsableArchiveType(mimeType)
&& metaStrings.size() > 0) {
+ if(mimeType != null &&
ArchiveManager.isUsableArchiveType(mimeType) && metaStrings.size() > 0) {
// Looks like an implicit archive,
handle as such
metadata.setArchiveManifest();
continue;
}
+ if(mimeType != null && ctx.allowedMIMETypes !=
null &&
+
!ctx.allowedMIMETypes.contains(clientMetadata.getMIMETypeNoParams())) {
+ onFailure(new
FetchException(FetchException.WRONG_MIME_TYPE));
+ }
+
// Simple redirect
// Just create a new SingleFileFetcher
// Which will then fetch the target URI, and
call the rcd.success
@@ -427,12 +436,17 @@
clientMetadata.mergeNoOverwrite(metadata.getClientMetadata()); // even
splitfiles can have mime types!
String mimeType = clientMetadata.getMIMEType();
- if(ArchiveManager.isUsableArchiveType(mimeType)
&& metaStrings.size() > 0) {
+ if(mimeType != null &&
ArchiveManager.isUsableArchiveType(mimeType) && metaStrings.size() > 0) {
// Looks like an implicit archive,
handle as such
metadata.setArchiveManifest();
continue;
}
+ if(mimeType != null && ctx.allowedMIMETypes !=
null &&
+
!ctx.allowedMIMETypes.contains(clientMetadata.getMIMETypeNoParams())) {
+ onFailure(new
FetchException(FetchException.WRONG_MIME_TYPE));
+ }
+
// Splitfile (possibly compressed)
if(metadata.isCompressed()) {
Modified: trunk/freenet/src/freenet/l10n/freenet.l10n.en.properties
===================================================================
--- trunk/freenet/src/freenet/l10n/freenet.l10n.en.properties 2007-06-16
19:32:35 UTC (rev 13625)
+++ trunk/freenet/src/freenet/l10n/freenet.l10n.en.properties 2007-06-16
20:20:17 UTC (rev 13626)
@@ -291,6 +291,7 @@
FetchException.longError.26=Archive restarted
FetchException.longError.27=Permanent redirect: use the new URI
FetchException.longError.28=Not enough data found; some data was fetched but
redirect may point to nowhere
+FetchException.longError.29=Wrong MIME Type: The key was not in the list of
allowed MIME types provided by the client
FetchException.longError.2=Don't know what to do with splitfile
FetchException.longError.3=Don't know what to do with metadata
FetchException.longError.4=Failed to parse metadata
@@ -319,6 +320,7 @@
FetchException.shortError.26=Archive restarted
FetchException.shortError.27=New URI
FetchException.shortError.28=All data not found
+FetchException.shortError.29=Wrong MIME type
FetchException.shortError.2=Unknown splitfile metadata
FetchException.shortError.3=Unknown metadata
FetchException.shortError.4=Invalid metadata