39 lines
1.5 KiB
Java
39 lines
1.5 KiB
Java
|
|
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);
|
||
|
|
}
|
||
|
|
}
|