I2P Address: [http://git.idk.i2p]

Skip to content
Snippets Groups Projects
Commit 3eb57329 authored by zzz's avatar zzz
Browse files

SusiDNS: Support adding b32's (ticket #2101)

parent 0b9babab
No related branches found
No related tags found
No related merge requests found
......@@ -28,6 +28,8 @@ import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.Arrays;
import java.util.Comparator;
import java.util.LinkedList;
......@@ -259,11 +261,44 @@ public class AddressbookBean extends BaseBean
message = _t("Host name {0} is already in address book with a different destination. Click \"Replace\" to overwrite.", displayHost);
} else {
boolean valid = true;
boolean wasB32 = false;
try {
// just to check validity
new Destination(destination);
if (destination.length() >= 516) {
// just to check validity
new Destination(destination);
} else if (destination.contains(".b32.i2p")) {
wasB32 = true;
Destination dest;
if (destination.startsWith("http://") ||
destination.startsWith("https://")) {
// do them a favor, pull b32 out of pasted URL
try {
URI uri = new URI(destination);
String b32 = uri.getHost();
if (b32 == null || !b32.endsWith(".b32.i2p") || b32.length() < 60)
throw new DataFormatException("");
dest = _context.namingService().lookup(b32);
if (dest == null)
throw new DataFormatException(_t("Unable to resolve Base 32 address"));
} catch(URISyntaxException use) {
throw new DataFormatException("");
}
} else if (destination.endsWith(".b32.i2p") && destination.length() >= 60) {
dest = _context.namingService().lookup(destination);
if (dest == null)
throw new DataFormatException(_t("Unable to resolve Base 32 address"));
} else {
throw new DataFormatException("");
}
destination = dest.toBase64();
} else {
throw new DataFormatException("");
}
} catch (DataFormatException dfe) {
valid = false;
String msg = dfe.getMessage();
if (msg != null)
message = msg;
}
if (valid) {
addressbook.put( host, destination );
......@@ -278,7 +313,12 @@ public class AddressbookBean extends BaseBean
hostname = null;
destination = null;
} else {
message = _t("Invalid Base 64 destination.");
if (message.length() <= 0) {
if (wasB32)
message = _t("Invalid Base 32 host name.");
else
message = _t("Invalid Base 64 destination.");
}
}
}
} catch (IllegalArgumentException iae) {
......
......@@ -27,6 +27,8 @@ import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.Writer;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.Arrays;
import java.util.ArrayList;
import java.util.Collections;
......@@ -255,8 +257,37 @@ public class NamingServiceBean extends AddressbookBean
} else if (oldDest != null && action.equals(_t("Add"))) {
message = _t("Host name {0} is already in address book with a different destination. Click \"Replace\" to overwrite.", displayHost);
} else {
boolean wasB32 = false;
try {
Destination dest = new Destination(destination);
Destination dest;
if (destination.length() >= 516) {
dest = new Destination(destination);
} else if (destination.contains(".b32.i2p")) {
wasB32 = true;
if (destination.startsWith("http://") ||
destination.startsWith("https://")) {
// do them a favor, pull b32 out of pasted URL
try {
URI uri = new URI(destination);
String b32 = uri.getHost();
if (b32 == null || !b32.endsWith(".b32.i2p") || b32.length() < 60)
throw new DataFormatException("");
dest = _context.namingService().lookup(b32);
if (dest == null)
throw new DataFormatException(_t("Unable to resolve Base 32 address"));
} catch(URISyntaxException use) {
throw new DataFormatException("");
}
} else if (destination.endsWith(".b32.i2p") && destination.length() >= 60) {
dest = _context.namingService().lookup(destination);
if (dest == null)
throw new DataFormatException(_t("Unable to resolve Base 32 address"));
} else {
throw new DataFormatException("");
}
} else {
throw new DataFormatException("");
}
if (oldDest != null) {
nsOptions.putAll(outProperties);
String now = Long.toString(_context.clock().now());
......@@ -294,7 +325,13 @@ public class NamingServiceBean extends AddressbookBean
message = _t("Failed to add Destination for {0} to naming service {1}", displayHost, getNamingService().getName()) + "<br>";
}
} catch (DataFormatException dfe) {
message = _t("Invalid Base 64 destination.");
String msg = dfe.getMessage();
if (msg != null && msg.length() > 0)
message = msg;
else if (wasB32)
message = _t("Invalid Base 32 host name.");
else
message = _t("Invalid Base 64 destination.");
}
}
} catch (IllegalArgumentException iae) {
......
......@@ -245,7 +245,7 @@ ${book.loadBookMessages}
<td><input type="text" name="hostname" value="${book.hostname}" size="54"></td>
</tr>
<tr>
<td><b><%=intl._t("Destination")%></b></td>
<td><b><%=intl._t("Destination or Base 32 Address")%></b></td>
<td><textarea name="destination" rows="1" style="height:3em" wrap="off" cols="70" spellcheck="false">${book.destination}</textarea></td>
</tr>
</table>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment