forked from I2P_Developers/i2p.i2p
* i2psnark: Escape fixes
- fix ':' in name (again) - Change priority key from file name to file number so we don't hav to escape
This commit is contained in:
@ -316,15 +316,34 @@ public class Storage
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Get index to pass to remaining(), getPriority(), setPriority()
|
||||||
|
*
|
||||||
* @param file non-canonical path (non-directory)
|
* @param file non-canonical path (non-directory)
|
||||||
|
* @return internal index of file; -1 if unknown file
|
||||||
|
* @since 0.9.15
|
||||||
|
*/
|
||||||
|
public int indexOf(File file) {
|
||||||
|
for (int i = 0; i < _torrentFiles.size(); i++) {
|
||||||
|
File f = _torrentFiles.get(i).RAFfile;
|
||||||
|
if (f.equals(file))
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param fileIndex as obtained from indexOf
|
||||||
* @return number of bytes remaining; -1 if unknown file
|
* @return number of bytes remaining; -1 if unknown file
|
||||||
* @since 0.7.14
|
* @since 0.7.14
|
||||||
*/
|
*/
|
||||||
public long remaining(File file) {
|
public long remaining(int fileIndex) {
|
||||||
|
if (fileIndex < 0 || fileIndex >= _torrentFiles.size())
|
||||||
|
return -1;
|
||||||
long bytes = 0;
|
long bytes = 0;
|
||||||
for (TorrentFile tf : _torrentFiles) {
|
for (int i = 0; i < _torrentFiles.size(); i++) {
|
||||||
File f = tf.RAFfile;
|
TorrentFile tf = _torrentFiles.get(i);
|
||||||
if (f.equals(file)) {
|
if (i == fileIndex) {
|
||||||
|
File f = tf.RAFfile;
|
||||||
if (complete())
|
if (complete())
|
||||||
return 0;
|
return 0;
|
||||||
int psz = piece_size;
|
int psz = piece_size;
|
||||||
@ -350,37 +369,30 @@ public class Storage
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param file non-canonical path (non-directory)
|
* @param fileIndex as obtained from indexOf
|
||||||
* @since 0.8.1
|
* @since 0.8.1
|
||||||
*/
|
*/
|
||||||
public int getPriority(File file) {
|
public int getPriority(int fileIndex) {
|
||||||
if (complete() || metainfo.getFiles() == null)
|
if (complete() || metainfo.getFiles() == null)
|
||||||
return 0;
|
return 0;
|
||||||
for (TorrentFile tf : _torrentFiles) {
|
if (fileIndex < 0 || fileIndex >= _torrentFiles.size())
|
||||||
File f = tf.RAFfile;
|
return 0;
|
||||||
if (f.equals(file))
|
return _torrentFiles.get(fileIndex).priority;
|
||||||
return tf.priority;
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Must call Snark.updatePiecePriorities()
|
* Must call Snark.updatePiecePriorities()
|
||||||
* (which calls getPiecePriorities()) after calling this.
|
* (which calls getPiecePriorities()) after calling this.
|
||||||
* @param file non-canonical path (non-directory)
|
* @param fileIndex as obtained from indexOf
|
||||||
* @param pri default 0; <0 to disable
|
* @param pri default 0; <0 to disable
|
||||||
* @since 0.8.1
|
* @since 0.8.1
|
||||||
*/
|
*/
|
||||||
public void setPriority(File file, int pri) {
|
public void setPriority(int fileIndex, int pri) {
|
||||||
if (complete() || metainfo.getFiles() == null)
|
if (complete() || metainfo.getFiles() == null)
|
||||||
return;
|
return;
|
||||||
for (TorrentFile tf : _torrentFiles) {
|
if (fileIndex < 0 || fileIndex >= _torrentFiles.size())
|
||||||
File f = tf.RAFfile;
|
return;
|
||||||
if (f.equals(file)) {
|
_torrentFiles.get(fileIndex).priority = pri;
|
||||||
tf.priority = pri;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1432,8 +1432,7 @@ public class I2PSnarkServlet extends BasicServlet {
|
|||||||
out.write("</td><td class=\"snarkTorrentName\"");
|
out.write("</td><td class=\"snarkTorrentName\"");
|
||||||
if (isMultiFile) {
|
if (isMultiFile) {
|
||||||
// link on the whole td
|
// link on the whole td
|
||||||
String jsec = encodedBaseName.replace("'", "\\'");
|
out.write(" onclick=\"document.location='" + encodedBaseName + "/';\">");
|
||||||
out.write(" onclick=\"document.location='" + jsec + "/';\">");
|
|
||||||
} else {
|
} else {
|
||||||
out.write('>');
|
out.write('>');
|
||||||
}
|
}
|
||||||
@ -2692,6 +2691,7 @@ public class I2PSnarkServlet extends BasicServlet {
|
|||||||
boolean complete = false;
|
boolean complete = false;
|
||||||
String status = "";
|
String status = "";
|
||||||
long length = item.length();
|
long length = item.length();
|
||||||
|
int fileIndex = -1;
|
||||||
int priority = 0;
|
int priority = 0;
|
||||||
if (item.isDirectory()) {
|
if (item.isDirectory()) {
|
||||||
complete = true;
|
complete = true;
|
||||||
@ -2703,8 +2703,9 @@ public class I2PSnarkServlet extends BasicServlet {
|
|||||||
status = toImg("cancel") + ' ' + _("Torrent not found?");
|
status = toImg("cancel") + ' ' + _("Torrent not found?");
|
||||||
} else {
|
} else {
|
||||||
Storage storage = snark.getStorage();
|
Storage storage = snark.getStorage();
|
||||||
|
fileIndex = storage.indexOf(item);
|
||||||
|
|
||||||
long remaining = storage.remaining(item);
|
long remaining = storage.remaining(fileIndex);
|
||||||
if (remaining < 0) {
|
if (remaining < 0) {
|
||||||
complete = true;
|
complete = true;
|
||||||
status = toImg("cancel") + ' ' + _("File not found in torrent?");
|
status = toImg("cancel") + ' ' + _("File not found in torrent?");
|
||||||
@ -2712,7 +2713,7 @@ public class I2PSnarkServlet extends BasicServlet {
|
|||||||
complete = true;
|
complete = true;
|
||||||
status = toImg("tick") + ' ' + _("Complete");
|
status = toImg("tick") + ' ' + _("Complete");
|
||||||
} else {
|
} else {
|
||||||
priority = storage.getPriority(item);
|
priority = storage.getPriority(fileIndex);
|
||||||
if (priority < 0)
|
if (priority < 0)
|
||||||
status = toImg("cancel");
|
status = toImg("cancel");
|
||||||
else if (priority == 0)
|
else if (priority == 0)
|
||||||
@ -2764,17 +2765,17 @@ public class I2PSnarkServlet extends BasicServlet {
|
|||||||
if (showPriority) {
|
if (showPriority) {
|
||||||
buf.append("<td class=\"priority\">");
|
buf.append("<td class=\"priority\">");
|
||||||
if ((!complete) && (!item.isDirectory())) {
|
if ((!complete) && (!item.isDirectory())) {
|
||||||
buf.append("<input type=\"radio\" value=\"5\" name=\"pri.").append(item).append("\" ");
|
buf.append("<input type=\"radio\" value=\"5\" name=\"pri.").append(fileIndex).append("\" ");
|
||||||
if (priority > 0)
|
if (priority > 0)
|
||||||
buf.append("checked=\"true\"");
|
buf.append("checked=\"true\"");
|
||||||
buf.append('>').append(_("High"));
|
buf.append('>').append(_("High"));
|
||||||
|
|
||||||
buf.append("<input type=\"radio\" value=\"0\" name=\"pri.").append(item).append("\" ");
|
buf.append("<input type=\"radio\" value=\"0\" name=\"pri.").append(fileIndex).append("\" ");
|
||||||
if (priority == 0)
|
if (priority == 0)
|
||||||
buf.append("checked=\"true\"");
|
buf.append("checked=\"true\"");
|
||||||
buf.append('>').append(_("Normal"));
|
buf.append('>').append(_("Normal"));
|
||||||
|
|
||||||
buf.append("<input type=\"radio\" value=\"-9\" name=\"pri.").append(item).append("\" ");
|
buf.append("<input type=\"radio\" value=\"-9\" name=\"pri.").append(fileIndex).append("\" ");
|
||||||
if (priority < 0)
|
if (priority < 0)
|
||||||
buf.append("checked=\"true\"");
|
buf.append("checked=\"true\"");
|
||||||
buf.append('>').append(_("Skip"));
|
buf.append('>').append(_("Skip"));
|
||||||
@ -2873,10 +2874,10 @@ public class I2PSnarkServlet extends BasicServlet {
|
|||||||
String key = entry.getKey();
|
String key = entry.getKey();
|
||||||
if (key.startsWith("pri.")) {
|
if (key.startsWith("pri.")) {
|
||||||
try {
|
try {
|
||||||
File file = new File(key.substring(4));
|
int fileIndex = Integer.parseInt(key.substring(4));
|
||||||
String val = entry.getValue()[0]; // jetty arrays
|
String val = entry.getValue()[0]; // jetty arrays
|
||||||
int pri = Integer.parseInt(val);
|
int pri = Integer.parseInt(val);
|
||||||
storage.setPriority(file, pri);
|
storage.setPriority(fileIndex, pri);
|
||||||
//System.err.println("Priority now " + pri + " for " + file);
|
//System.err.println("Priority now " + pri + " for " + file);
|
||||||
} catch (Throwable t) { t.printStackTrace(); }
|
} catch (Throwable t) { t.printStackTrace(); }
|
||||||
}
|
}
|
||||||
|
@ -84,6 +84,7 @@ class URIUtil
|
|||||||
case '<':
|
case '<':
|
||||||
case '>':
|
case '>':
|
||||||
case ' ':
|
case ' ':
|
||||||
|
case ':':
|
||||||
buf=new StringBuilder(path.length()*2);
|
buf=new StringBuilder(path.length()*2);
|
||||||
break loop;
|
break loop;
|
||||||
default:
|
default:
|
||||||
@ -139,6 +140,9 @@ class URIUtil
|
|||||||
case 0x7f:
|
case 0x7f:
|
||||||
buf.append("%7F");
|
buf.append("%7F");
|
||||||
continue;
|
continue;
|
||||||
|
case ':':
|
||||||
|
buf.append("%3A");
|
||||||
|
continue;
|
||||||
default:
|
default:
|
||||||
if (c <= 0x1f) // includes negative
|
if (c <= 0x1f) // includes negative
|
||||||
toHex(c,buf);
|
toHex(c,buf);
|
||||||
@ -183,6 +187,9 @@ class URIUtil
|
|||||||
case ' ':
|
case ' ':
|
||||||
buf.append("%20");
|
buf.append("%20");
|
||||||
continue;
|
continue;
|
||||||
|
case ':':
|
||||||
|
buf.append("%3A");
|
||||||
|
continue;
|
||||||
default:
|
default:
|
||||||
if (c <= 0x1f || (c >= 0x7f && c <= 0x9f) || Character.isSpaceChar(c))
|
if (c <= 0x1f || (c >= 0x7f && c <= 0x9f) || Character.isSpaceChar(c))
|
||||||
toHex(c,buf);
|
toHex(c,buf);
|
||||||
|
@ -1,3 +1,6 @@
|
|||||||
|
2014-09-09 zzz
|
||||||
|
* i2psnark: Escape fixes
|
||||||
|
|
||||||
2014-08-31 zzz
|
2014-08-31 zzz
|
||||||
* Build: Add support for bundling router infos in the package
|
* Build: Add support for bundling router infos in the package
|
||||||
* I2PTunnel: Allow changing of spoof host and target host/port without
|
* I2PTunnel: Allow changing of spoof host and target host/port without
|
||||||
|
@ -18,7 +18,7 @@ public class RouterVersion {
|
|||||||
/** deprecated */
|
/** deprecated */
|
||||||
public final static String ID = "Monotone";
|
public final static String ID = "Monotone";
|
||||||
public final static String VERSION = CoreVersion.VERSION;
|
public final static String VERSION = CoreVersion.VERSION;
|
||||||
public final static long BUILD = 15;
|
public final static long BUILD = 16;
|
||||||
|
|
||||||
/** for example "-test" */
|
/** for example "-test" */
|
||||||
public final static String EXTRA = "-rc";
|
public final static String EXTRA = "-rc";
|
||||||
|
Reference in New Issue
Block a user