Updated everything to new INS
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
package org.openautonomousconnection.ins.utils;
|
||||
|
||||
import org.openautonomousconnection.ins.Main;
|
||||
import org.openautonomousconnection.protocol.versions.v1_0_0.beta.INSRecord;
|
||||
import org.openautonomousconnection.protocol.versions.v1_0_0.classic.objects.Classic_Domain;
|
||||
import org.openautonomousconnection.protocol.versions.v1_0_0.classic.objects.Classic_RequestDomain;
|
||||
|
||||
public class ClassicHelper {
|
||||
public static Classic_Domain buildClassicDomain(ParsedDomain req, INSRecord rec) {
|
||||
Classic_Domain info = new Classic_Domain(req.name, req.tln, req.sub, req.path, Main.getProtocolBridge());
|
||||
|
||||
String host = rec.value;
|
||||
int port = rec.port > 0 ? rec.port : 80;
|
||||
|
||||
return new Classic_Domain(
|
||||
req.name, req.tln,
|
||||
host.contains(":") ? host : host + ":" + port,
|
||||
req.path, Main.getProtocolBridge());
|
||||
}
|
||||
|
||||
public static ParsedDomain parseDomain(Classic_RequestDomain req) {
|
||||
String tln = req.topLevelDomain; // example: "net"
|
||||
String full = req.name; // example: "api.v1.example"
|
||||
|
||||
String[] parts = full.split("\\.");
|
||||
|
||||
if (parts.length == 1) {
|
||||
return new ParsedDomain(tln, full, null, req.path);
|
||||
}
|
||||
|
||||
String name = parts[parts.length - 1];
|
||||
String sub = parts.length > 1
|
||||
? String.join(".", java.util.Arrays.copyOfRange(parts, 0, parts.length - 1))
|
||||
: null;
|
||||
|
||||
return new ParsedDomain(tln, name, sub, req.path);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package org.openautonomousconnection.ins.utils;
|
||||
|
||||
public final class ParsedDomain {
|
||||
public final String tln;
|
||||
public final String name;
|
||||
public final String sub;
|
||||
public final String path;
|
||||
|
||||
public ParsedDomain(String tln, String name, String sub, String path) {
|
||||
this.tln = tln;
|
||||
this.name = name;
|
||||
this.sub = sub;
|
||||
this.path = path;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user