Author: volodya
Date: 2006-09-24 12:37:09 +0000 (Sun, 24 Sep 2006)
New Revision: 10510
Modified:
trunk/freenet/src/freenet/client/InserterException.java
trunk/freenet/src/freenet/client/async/ClientPutter.java
trunk/freenet/src/freenet/client/async/SingleFileInserter.java
trunk/freenet/src/freenet/clients/http/Toadlet.java
trunk/freenet/src/freenet/keys/FreenetURI.java
Log:
KSK does not silently remove slashes, but rather generates
InserterException.META_DATA_NOT_SUPPORTED
Modified: trunk/freenet/src/freenet/client/InserterException.java
===================================================================
--- trunk/freenet/src/freenet/client/InserterException.java 2006-09-24
12:28:58 UTC (rev 10509)
+++ trunk/freenet/src/freenet/client/InserterException.java 2006-09-24
12:37:09 UTC (rev 10510)
@@ -88,6 +88,8 @@
public static final int COLLISION = 9;
/** Cancelled by user */
public static final int CANCELLED = 10;
+ /** Meta string used in the key (most probably '/') */
+ public static final int META_STRINGS_NOT_SUPPORTED = 11;
public static String getMessage(int mode) {
switch(mode) {
@@ -109,6 +111,8 @@
return "Insert could not leave the node at all";
case COLLISION:
return "Insert collided with different, pre-existing
data at the same key";
+ case META_STRINGS_NOT_SUPPORTED:
+ return "Meta string (most likely a '/') used in the
URI";
case CANCELLED:
return "Cancelled by user";
default:
@@ -136,6 +140,8 @@
return "Request could not leave the node";
case COLLISION:
return "Collided with existing data";
+ case META_STRINGS_NOT_SUPPORTED:
+ return "Meta string used in the key";
case CANCELLED:
return "Cancelled";
default:
@@ -156,6 +162,7 @@
case FATAL_ERRORS_IN_BLOCKS:
case COLLISION:
case CANCELLED:
+ case META_STRINGS_NOT_SUPPORTED:
return true;
case BUCKET_ERROR: // maybe
case INTERNAL_ERROR: // maybe
Modified: trunk/freenet/src/freenet/client/async/ClientPutter.java
===================================================================
--- trunk/freenet/src/freenet/client/async/ClientPutter.java 2006-09-24
12:28:58 UTC (rev 10509)
+++ trunk/freenet/src/freenet/client/async/ClientPutter.java 2006-09-24
12:37:09 UTC (rev 10510)
@@ -63,6 +63,8 @@
if(Logger.shouldLog(Logger.MINOR, this))
Logger.minor(this, "Starting "+this);
try {
+ this.targetURI.checkInsertURI();
+
boolean cancel = false;
synchronized(this) {
if(startedStarting) return;
Modified: trunk/freenet/src/freenet/client/async/SingleFileInserter.java
===================================================================
--- trunk/freenet/src/freenet/client/async/SingleFileInserter.java
2006-09-24 12:28:58 UTC (rev 10509)
+++ trunk/freenet/src/freenet/client/async/SingleFileInserter.java
2006-09-24 12:37:09 UTC (rev 10510)
@@ -46,7 +46,7 @@
* update our parent to point to us as current put-stage. */
private final boolean reportMetadataOnly;
public final Object token;
- private final boolean freeData;
+ private final boolean freeData; // this is being set, but never read ???
/**
* @param parent
@@ -262,6 +262,9 @@
private ClientPutState createInserter(BaseClientPutter parent, Bucket
data, short compressionCodec, FreenetURI uri,
InserterContext ctx, PutCompletionCallback cb, boolean
isMetadata, int sourceLength, int token, boolean getCHKOnly,
boolean addToParent) throws InserterException {
+
+ uri.checkInsertURI(); // will throw an exception if needed
+
if(uri.getKeyType().equals("USK")) {
try {
return new USKInserter(parent, data,
compressionCodec, uri, ctx, cb, isMetadata, sourceLength, token,
Modified: trunk/freenet/src/freenet/clients/http/Toadlet.java
===================================================================
--- trunk/freenet/src/freenet/clients/http/Toadlet.java 2006-09-24 12:28:58 UTC
(rev 10509)
+++ trunk/freenet/src/freenet/clients/http/Toadlet.java 2006-09-24 12:37:09 UTC
(rev 10510)
@@ -100,6 +100,7 @@
FreenetURI insert(InsertBlock insert, boolean getCHKOnly) throws
InserterException {
// For now, just run it blocking.
+ insert.desiredURI.checkInsertURI();
return client.insert(insert, getCHKOnly);
}
Modified: trunk/freenet/src/freenet/keys/FreenetURI.java
===================================================================
--- trunk/freenet/src/freenet/keys/FreenetURI.java 2006-09-24 12:28:58 UTC
(rev 10509)
+++ trunk/freenet/src/freenet/keys/FreenetURI.java 2006-09-24 12:37:09 UTC
(rev 10510)
@@ -16,6 +16,7 @@
import freenet.support.HexUtil;
import freenet.support.IllegalBase64Exception;
import freenet.support.Logger;
+import freenet.client.InserterException;
/**
* Note that the metadata pairs below are not presently supported. They are
supported
@@ -173,7 +174,6 @@
routingKey,
cryptoKey,
null);
-
}
public FreenetURI(
@@ -226,6 +226,16 @@
keyType = URI.substring(colon + 1,
atchar).toUpperCase().trim();
}
URI = URI.substring(atchar + 1);
+
+ if(keyType.equalsIgnoreCase("KSK")) {
+ docName = URI;
+ metaStr = null;
+ routingKey = null;
+ cryptoKey = null;
+ extra = null;
+ suggestedEdition = -1;
+ return;
+ }
// decode metaString
Vector sv = null;
@@ -254,14 +264,6 @@
}
} else
suggestedEdition = -1;
- } else if(keyType.equalsIgnoreCase("KSK")) {
- docName = URI;
- metaStr = null;
- routingKey = null;
- cryptoKey = null;
- extra = null;
- suggestedEdition = -1;
- return;
} else {
// docName not necessary, nor is it supported, for CHKs.
docName = null;
@@ -739,5 +741,16 @@
extra,
suggestedEdition);
}
+
+ public void checkInsertURI() throws InserterException
+ {
+ if(this.keyType.equals("KSK"))
+ {
+ if((this.docName!=null &&
this.docName.indexOf('/')!=-1) ||
+ (this.cryptoKey!=null || this.extra!=null ||
this.routingKey!=null))
+ throw new
InserterException(InserterException.META_STRINGS_NOT_SUPPORTED,this);
+ }
+ }
+ public static void checkInsertURI(FreenetURI uri) throws
InserterException { uri.checkInsertURI(); }
}