}
if(identifier == null)
throw new MessageInvalidException(ProtocolErrorMessage.MISSING_FIELD, "No Identifier", null, global);
try {
if(binaryBlob)
uri = new FreenetURI("CHK@");
else {
String u = fs.get("URI");
if(u == null)
throw new MessageInvalidException(ProtocolErrorMessage.MISSING_FIELD, "No URI", identifier, global);
FreenetURI uu = new FreenetURI(u);
String[] metas = uu.getAllMetaStrings();
if(metas != null && metas.length == 1) {
fnam = metas[0];
uu = uu.setMetaString(null);
} // if >1, will fail later
uri = uu;
}
} catch (MalformedURLException e) {
throw new MessageInvalidException(ProtocolErrorMessage.FREENET_URI_PARSE_ERROR, e.getMessage(), identifier, global);
}
String verbosityString = fs.get("Verbosity");
if(verbosityString == null)
verbosity = 0;
else {
try {
verbosity = Integer.parseInt(verbosityString, 10);
} catch (NumberFormatException e) {
throw new MessageInvalidException(ProtocolErrorMessage.ERROR_PARSING_NUMBER, "Error parsing Verbosity field: "+e.getMessage(), identifier, global);
}
}
contentType = fs.get("Metadata.ContentType");
String maxRetriesString = fs.get("MaxRetries");
if(maxRetriesString == null)
// default to 0
maxRetries = 0;
else {
try {
maxRetries = Integer.parseInt(maxRetriesString, 10);
} catch (NumberFormatException e) {
throw new MessageInvalidException(ProtocolErrorMessage.ERROR_PARSING_NUMBER, "Error parsing MaxSize field: "+e.getMessage(), identifier, global);
}
}
getCHKOnly = fs.getBoolean("GetCHKOnly", false);
String priorityString = fs.get("PriorityClass");
if(priorityString == null) {
// defaults to the one just below FProxy
priorityClass = RequestStarter.IMMEDIATE_SPLITFILE_PRIORITY_CLASS;
} else {
try {
priorityClass = Short.parseShort(priorityString);
if(!RequestStarter.isValidPriorityClass(priorityClass))
throw new MessageInvalidException(ProtocolErrorMessage.INVALID_FIELD, "Invalid priority class "+priorityClass+" - range is "+RequestStarter.PAUSED_PRIORITY_CLASS+" to "+RequestStarter.MAXIMUM_PRIORITY_CLASS, identifier, global);
} catch (NumberFormatException e) {
throw new MessageInvalidException(ProtocolErrorMessage.ERROR_PARSING_NUMBER, "Error parsing PriorityClass field: "+e.getMessage(), identifier, global);
}
}
// We do *NOT* check that FileHash is valid here for backward compatibility... and to make the override work
this.fileHash = fs.get(ClientPutBase.FILE_HASH);
String uploadFrom = fs.get("UploadFrom");
if((uploadFrom == null) || uploadFrom.equalsIgnoreCase("direct")) {
uploadFromType = UploadFrom.DIRECT;
String dataLengthString = fs.get("DataLength");
if(dataLengthString == null)
throw new MessageInvalidException(ProtocolErrorMessage.MISSING_FIELD, "Need DataLength on a ClientPut", identifier, global);
try {
dataLength = Long.parseLong(dataLengthString, 10);
} catch (NumberFormatException e) {
throw new MessageInvalidException(ProtocolErrorMessage.ERROR_PARSING_NUMBER, "Error parsing DataLength field: "+e.getMessage(), identifier, global);
}
this.origFilename = null;
redirectTarget = null;
} else if(uploadFrom.equalsIgnoreCase("disk")) {
uploadFromType = UploadFrom.DISK;
String filename = fs.get("Filename");
if(filename == null)
throw new MessageInvalidException(ProtocolErrorMessage.MISSING_FIELD, "Missing field Filename", identifier, global);
File f = new File(filename);
if(!(f.exists() && f.isFile() && f.canRead()))
throw new MessageInvalidException(ProtocolErrorMessage.FILE_NOT_FOUND, null, identifier, global);
dataLength = f.length();
FileBucket fileBucket = new FileBucket(f, true, false, false, false);
this.bucket = fileBucket;
this.origFilename = f;
redirectTarget = null;
if(fnam == null)
fnam = origFilename.getName();
} else if(uploadFrom.equalsIgnoreCase("redirect")) {
uploadFromType = UploadFrom.REDIRECT;
String target = fs.get("TargetURI");
if(target == null)
throw new MessageInvalidException(ProtocolErrorMessage.MISSING_FIELD, "TargetURI missing but UploadFrom=redirect", identifier, global);
try {
redirectTarget = new FreenetURI(target);
} catch (MalformedURLException e) {
throw new MessageInvalidException(ProtocolErrorMessage.INVALID_FIELD, "Invalid TargetURI: "+e, identifier, global);
}
dataLength = 0;
origFilename = null;