Updated to latest UnlegitLibrary version and implemented UDP
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
package org.openautonomousconnection.protocol.versions.v1_0_0.classic.utils;
|
||||
package org.openautonomousconnection.protocol.versions.v1_0_0.classic;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
@@ -1,51 +0,0 @@
|
||||
package org.openautonomousconnection.protocol.versions.v1_0_0.classic.events;
|
||||
|
||||
import dev.unlegitdqrk.unlegitlibrary.event.impl.Event;
|
||||
import org.openautonomousconnection.protocol.versions.v1_0_0.classic.handlers.ClassicHandlerINSServer;
|
||||
import org.openautonomousconnection.protocol.versions.v1_0_0.classic.objects.Classic_Domain;
|
||||
import org.openautonomousconnection.protocol.versions.v1_0_0.classic.objects.Classic_RequestDomain;
|
||||
import org.openautonomousconnection.protocol.versions.v1_0_0.classic.utils.Classic_ProtocolVersion;
|
||||
|
||||
/**
|
||||
* This event is fired when a classic domain packet is received.
|
||||
* This event is deprecated and will be marked for removal in future versions.
|
||||
*
|
||||
* @see ClassicHandlerINSServer
|
||||
* @see org.openautonomousconnection.protocol.versions.v1_0_0.classic.handlers.ClassicHandlerClient
|
||||
* @see org.openautonomousconnection.protocol.versions.v1_0_0.classic.handlers.ClassicHandlerWebServer
|
||||
*/
|
||||
@Deprecated(forRemoval = false, since = "1.0.0-BETA.3")
|
||||
public final class Classic_DomainPacketReceivedEvent extends Event {
|
||||
|
||||
public final Classic_ProtocolVersion protocolVersion;
|
||||
public final Classic_Domain domain;
|
||||
public final Classic_RequestDomain requestDomain;
|
||||
public final int clientID;
|
||||
|
||||
public Classic_DomainPacketReceivedEvent(Classic_ProtocolVersion protocolVersion, Classic_Domain domain, Classic_RequestDomain requestDomain, int clientID) {
|
||||
this.protocolVersion = protocolVersion;
|
||||
this.domain = domain;
|
||||
this.requestDomain = requestDomain;
|
||||
this.clientID = clientID;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Object clone() throws CloneNotSupportedException {
|
||||
return super.clone();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
return super.equals(obj);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return super.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return super.hashCode();
|
||||
}
|
||||
}
|
||||
@@ -1,52 +0,0 @@
|
||||
package org.openautonomousconnection.protocol.versions.v1_0_0.classic.events;
|
||||
|
||||
import dev.unlegitdqrk.unlegitlibrary.event.impl.Event;
|
||||
import org.openautonomousconnection.protocol.versions.v1_0_0.classic.handlers.ClassicHandlerINSServer;
|
||||
import org.openautonomousconnection.protocol.versions.v1_0_0.classic.objects.Classic_Domain;
|
||||
import org.openautonomousconnection.protocol.versions.v1_0_0.classic.objects.Classic_RequestDomain;
|
||||
import org.openautonomousconnection.protocol.versions.v1_0_0.classic.utils.Classic_ProtocolVersion;
|
||||
|
||||
/**
|
||||
* This event is fired when a classic ping packet is received.
|
||||
* This event is deprecated and will be marked for removal in future versions.
|
||||
*
|
||||
* @see ClassicHandlerINSServer
|
||||
* @see org.openautonomousconnection.protocol.versions.v1_0_0.classic.handlers.ClassicHandlerClient
|
||||
* @see org.openautonomousconnection.protocol.versions.v1_0_0.classic.handlers.ClassicHandlerWebServer
|
||||
*/
|
||||
@Deprecated(forRemoval = false, since = "1.0.0-BETA.3")
|
||||
public final class Classic_PingPacketReceivedEvent extends Event {
|
||||
public final Classic_ProtocolVersion protocolVersion;
|
||||
public final Classic_Domain domain;
|
||||
public final Classic_RequestDomain requestDomain;
|
||||
public final boolean reachable;
|
||||
public final int clientID;
|
||||
|
||||
public Classic_PingPacketReceivedEvent(Classic_ProtocolVersion protocolVersion, Classic_Domain domain, Classic_RequestDomain requestDomain, boolean reachable, int clientID) {
|
||||
this.protocolVersion = protocolVersion;
|
||||
this.domain = domain;
|
||||
this.requestDomain = requestDomain;
|
||||
this.reachable = reachable;
|
||||
this.clientID = clientID;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Object clone() throws CloneNotSupportedException {
|
||||
return super.clone();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
return super.equals(obj);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return super.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return super.hashCode();
|
||||
}
|
||||
}
|
||||
@@ -1,47 +0,0 @@
|
||||
package org.openautonomousconnection.protocol.versions.v1_0_0.classic.handlers;
|
||||
|
||||
import lombok.Getter;
|
||||
import org.openautonomousconnection.protocol.annotations.ProtocolInfo;
|
||||
import org.openautonomousconnection.protocol.packets.v1_0_0.classic.Classic_MessagePacket;
|
||||
import org.openautonomousconnection.protocol.side.client.ProtocolClient;
|
||||
import org.openautonomousconnection.protocol.versions.ProtocolVersion;
|
||||
import org.openautonomousconnection.protocol.versions.v1_0_0.beta.INSResponseStatus;
|
||||
import org.openautonomousconnection.protocol.versions.v1_0_0.classic.objects.Classic_Domain;
|
||||
import org.openautonomousconnection.protocol.versions.v1_0_0.classic.site.Classic_SiteType;
|
||||
import org.openautonomousconnection.protocol.versions.v1_0_0.classic.utils.Classic_ProtocolVersion;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* Abstract class defining the client-side handler for Classic protocol operations.
|
||||
*/
|
||||
@ProtocolInfo(protocolSide = ProtocolVersion.ProtocolSide.CLIENT)
|
||||
public abstract class ClassicHandlerClient {
|
||||
|
||||
/**
|
||||
* Reference to the ProtocolClient
|
||||
*/
|
||||
@Getter
|
||||
private final ProtocolClient client;
|
||||
|
||||
/**
|
||||
* Sets the client variable
|
||||
*
|
||||
* @param client The ProtocolClient Object
|
||||
*/
|
||||
public ClassicHandlerClient(ProtocolClient client) {
|
||||
this.client = client;
|
||||
}
|
||||
|
||||
public abstract void unsupportedClassicPacket(String classicPacketClassName, Object[] content);
|
||||
|
||||
public abstract void handleHTMLContent(Classic_SiteType siteType, Classic_Domain domain, String html);
|
||||
|
||||
public abstract void handleMessage(String message, Classic_ProtocolVersion protocolVersion);
|
||||
|
||||
public final void sendMessage(String message) throws IOException, ClassNotFoundException {
|
||||
client.getClientINSConnection().sendPacket(new Classic_MessagePacket(message, client.getClientServerConnection().getClientID(), client.getProtocolBridge()));
|
||||
}
|
||||
|
||||
public abstract void validationCompleted(Classic_Domain domain, INSResponseStatus insResponseStatus);
|
||||
}
|
||||
@@ -1,24 +0,0 @@
|
||||
package org.openautonomousconnection.protocol.versions.v1_0_0.classic.handlers;
|
||||
|
||||
import org.openautonomousconnection.protocol.annotations.ProtocolInfo;
|
||||
import org.openautonomousconnection.protocol.side.ins.ConnectedProtocolClient;
|
||||
import org.openautonomousconnection.protocol.versions.ProtocolVersion;
|
||||
import org.openautonomousconnection.protocol.versions.v1_0_0.classic.objects.Classic_Domain;
|
||||
import org.openautonomousconnection.protocol.versions.v1_0_0.classic.objects.Classic_RequestDomain;
|
||||
import org.openautonomousconnection.protocol.versions.v1_0_0.classic.utils.Classic_ProtocolVersion;
|
||||
|
||||
import java.sql.SQLException;
|
||||
|
||||
/**
|
||||
* Abstract class defining the INS server-side handler for Classic protocol operations.
|
||||
*/
|
||||
@ProtocolInfo(protocolSide = ProtocolVersion.ProtocolSide.INS)
|
||||
public abstract class ClassicHandlerINSServer {
|
||||
public abstract void handleMessage(ConnectedProtocolClient client, String message, Classic_ProtocolVersion protocolVersion);
|
||||
|
||||
public abstract Classic_Domain getDomain(Classic_RequestDomain requestDomain) throws SQLException;
|
||||
|
||||
public abstract Classic_Domain ping(Classic_RequestDomain requestDomain) throws SQLException;
|
||||
|
||||
public abstract void unsupportedClassicPacket(String className, Object[] content, ConnectedProtocolClient client);
|
||||
}
|
||||
@@ -1,16 +0,0 @@
|
||||
package org.openautonomousconnection.protocol.versions.v1_0_0.classic.handlers;
|
||||
|
||||
import org.openautonomousconnection.protocol.annotations.ProtocolInfo;
|
||||
import org.openautonomousconnection.protocol.side.ins.ConnectedProtocolClient;
|
||||
import org.openautonomousconnection.protocol.versions.ProtocolVersion;
|
||||
import org.openautonomousconnection.protocol.versions.v1_0_0.classic.utils.Classic_ProtocolVersion;
|
||||
|
||||
/**
|
||||
* Abstract class defining the web server-side handler for Classic protocol operations.
|
||||
*/
|
||||
@ProtocolInfo(protocolSide = ProtocolVersion.ProtocolSide.WEB)
|
||||
public abstract class ClassicHandlerWebServer {
|
||||
public abstract void handleMessage(ConnectedProtocolClient client, String message, Classic_ProtocolVersion protocolVersion);
|
||||
|
||||
public abstract void unsupportedClassicPacket(String className, Object[] content, ConnectedProtocolClient client);
|
||||
}
|
||||
@@ -1,74 +0,0 @@
|
||||
package org.openautonomousconnection.protocol.versions.v1_0_0.classic.handlers.builtin;
|
||||
|
||||
import lombok.Getter;
|
||||
import org.openautonomousconnection.protocol.ProtocolBridge;
|
||||
import org.openautonomousconnection.protocol.versions.v1_0_0.beta.INSRecordType;
|
||||
import org.openautonomousconnection.protocol.versions.v1_0_0.beta.INSResponseStatus;
|
||||
import org.openautonomousconnection.protocol.versions.v1_0_0.classic.handlers.ClassicHandlerClient;
|
||||
import org.openautonomousconnection.protocol.versions.v1_0_0.classic.helper.ClassicHelper;
|
||||
import org.openautonomousconnection.protocol.versions.v1_0_0.classic.objects.Classic_Domain;
|
||||
import org.openautonomousconnection.protocol.versions.v1_0_0.classic.site.Classic_SiteType;
|
||||
import org.openautonomousconnection.protocol.versions.v1_0_0.classic.site.Classic_WebsitesContent;
|
||||
import org.openautonomousconnection.protocol.versions.v1_0_0.classic.utils.Classic_ProtocolVersion;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public abstract class ClientClassic extends ClassicHandlerClient {
|
||||
@Getter
|
||||
private final ProtocolBridge bridge;
|
||||
|
||||
@Getter
|
||||
private final ClassicHelper helper;
|
||||
|
||||
public ClientClassic(ProtocolBridge bridge) {
|
||||
super(bridge.getProtocolClient());
|
||||
this.bridge = bridge;
|
||||
this.helper = new ClassicHelper(bridge);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unsupportedClassicPacket(String className, Object[] content) {
|
||||
bridge.getLogger().warn(
|
||||
"[Classic UnsupportedPacket] packet=" + className + " content=" + java.util.Arrays.toString(content)
|
||||
);
|
||||
|
||||
onUnsupportedClassicPacket(className, content);
|
||||
}
|
||||
|
||||
/**
|
||||
* Optional callback
|
||||
*
|
||||
* @param className The class name
|
||||
* @param content The content
|
||||
*/
|
||||
public void onUnsupportedClassicPacket(String className, Object[] content) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleMessage(String message, Classic_ProtocolVersion protocolVersion) {
|
||||
bridge.getLogger().info("[ClassicHandler] Message received (Classic Version " + protocolVersion.version + "): " + message);
|
||||
onMessage(message, protocolVersion);
|
||||
}
|
||||
|
||||
/**
|
||||
* Optional callback
|
||||
*
|
||||
* @param message The Message
|
||||
* @param protocolVersion the Classic version
|
||||
*/
|
||||
public void onMessage(String message, Classic_ProtocolVersion protocolVersion) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void validationCompleted(Classic_Domain domain, INSResponseStatus insResponseStatus) {
|
||||
if (insResponseStatus == INSResponseStatus.OK) {
|
||||
try {
|
||||
bridge.getProtocolClient().sendINSQuery(domain.topLevelDomain, domain.name, null, INSRecordType.A);
|
||||
} catch (IOException | ClassNotFoundException e) {
|
||||
handleHTMLContent(Classic_SiteType.CLIENT, domain, Classic_WebsitesContent.ERROR_OCCURRED(e.getMessage()));
|
||||
}
|
||||
} else {
|
||||
handleHTMLContent(Classic_SiteType.CLIENT, domain, Classic_WebsitesContent.DOMAIN_NOT_REACHABLE);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,93 +0,0 @@
|
||||
package org.openautonomousconnection.protocol.versions.v1_0_0.classic.handlers.builtin;
|
||||
|
||||
import lombok.Getter;
|
||||
import org.openautonomousconnection.protocol.ProtocolBridge;
|
||||
import org.openautonomousconnection.protocol.side.ins.ConnectedProtocolClient;
|
||||
import org.openautonomousconnection.protocol.side.ins.ProtocolINSServer;
|
||||
import org.openautonomousconnection.protocol.versions.v1_0_0.beta.INSRecord;
|
||||
import org.openautonomousconnection.protocol.versions.v1_0_0.beta.INSRecordType;
|
||||
import org.openautonomousconnection.protocol.versions.v1_0_0.classic.handlers.ClassicHandlerINSServer;
|
||||
import org.openautonomousconnection.protocol.versions.v1_0_0.classic.helper.ClassicHelper;
|
||||
import org.openautonomousconnection.protocol.versions.v1_0_0.classic.helper.ParsedDomain;
|
||||
import org.openautonomousconnection.protocol.versions.v1_0_0.classic.objects.Classic_Domain;
|
||||
import org.openautonomousconnection.protocol.versions.v1_0_0.classic.objects.Classic_RequestDomain;
|
||||
import org.openautonomousconnection.protocol.versions.v1_0_0.classic.utils.Classic_ProtocolVersion;
|
||||
|
||||
import java.sql.SQLException;
|
||||
import java.util.List;
|
||||
|
||||
public class INSClassic extends ClassicHandlerINSServer {
|
||||
|
||||
@Getter
|
||||
private final ProtocolBridge bridge;
|
||||
|
||||
@Getter
|
||||
private final ClassicHelper helper;
|
||||
|
||||
public INSClassic(ProtocolBridge bridge) {
|
||||
this.bridge = bridge;
|
||||
this.helper = new ClassicHelper(bridge);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleMessage(ConnectedProtocolClient client, String message, Classic_ProtocolVersion protocolVersion) {
|
||||
client.getServer().getProtocolBridge().getLogger().info("[ClassicHandler] Message received from ClientID " +
|
||||
client.getPipelineConnection().getClientID() +
|
||||
" (Classic Version " + protocolVersion.version + ", Client Version: " +
|
||||
client.getClientVersion().toString() + "): " + message);
|
||||
|
||||
onMessage(client, message, protocolVersion);
|
||||
}
|
||||
|
||||
/**
|
||||
* Optional callback.
|
||||
*
|
||||
* @param client The client sender.
|
||||
* @param message The message.
|
||||
* @param protocolVersion The classic version.
|
||||
*/
|
||||
public void onMessage(ConnectedProtocolClient client, String message, Classic_ProtocolVersion protocolVersion) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Classic_Domain getDomain(Classic_RequestDomain requestDomain) throws SQLException {
|
||||
if (!bridge.isRunningAsINSServer()) return null;
|
||||
|
||||
ParsedDomain pd = helper.parseDomain(requestDomain);
|
||||
ProtocolINSServer server = (ProtocolINSServer) bridge.getProtocolServer();
|
||||
|
||||
// IMPORTANT: resolve() already performs CNAME recursion + sorting.
|
||||
// Request A directly and pick the first (= best after sorting).
|
||||
List<INSRecord> aRecords = server.resolve(pd.tln(), pd.name(), pd.sub(), INSRecordType.A);
|
||||
if (aRecords.isEmpty()) return null;
|
||||
|
||||
INSRecord targetA = aRecords.get(0);
|
||||
return helper.buildClassicDomain(pd, targetA);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Classic_Domain ping(Classic_RequestDomain req) throws SQLException {
|
||||
if (!bridge.isRunningAsINSServer()) return null;
|
||||
return new Classic_Domain(req.name, req.topLevelDomain, null, req.path, bridge);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unsupportedClassicPacket(String className, Object[] content, ConnectedProtocolClient client) {
|
||||
client.getServer().getProtocolBridge().getLogger().warn(
|
||||
"[Classic UnsupportedPacket] From client " + client.getPipelineConnection().getClientID() +
|
||||
": packet=" + className + " content=" + java.util.Arrays.toString(content)
|
||||
);
|
||||
|
||||
onUnsupportedClassicPacket(className, content, client);
|
||||
}
|
||||
|
||||
/**
|
||||
* Optional callback.
|
||||
*
|
||||
* @param className The class name.
|
||||
* @param content The content.
|
||||
* @param client The client sender.
|
||||
*/
|
||||
public void onUnsupportedClassicPacket(String className, Object[] content, ConnectedProtocolClient client) {
|
||||
}
|
||||
}
|
||||
@@ -1,56 +0,0 @@
|
||||
package org.openautonomousconnection.protocol.versions.v1_0_0.classic.handlers.builtin;
|
||||
|
||||
import lombok.Getter;
|
||||
import org.openautonomousconnection.protocol.ProtocolBridge;
|
||||
import org.openautonomousconnection.protocol.side.ins.ConnectedProtocolClient;
|
||||
import org.openautonomousconnection.protocol.versions.v1_0_0.classic.handlers.ClassicHandlerWebServer;
|
||||
import org.openautonomousconnection.protocol.versions.v1_0_0.classic.utils.Classic_ProtocolVersion;
|
||||
|
||||
public class WebClassic extends ClassicHandlerWebServer {
|
||||
@Getter
|
||||
private final ProtocolBridge bridge;
|
||||
|
||||
public WebClassic(ProtocolBridge bridge) {
|
||||
this.bridge = bridge;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleMessage(ConnectedProtocolClient client, String message, Classic_ProtocolVersion protocolVersion) {
|
||||
client.getServer().getProtocolBridge().getLogger().info("[ClassicHandler] Message received from ClientID " +
|
||||
client.getPipelineConnection().getClientID() +
|
||||
" (Classic Version " + protocolVersion.version + ", Client Version: " +
|
||||
client.getClientVersion().toString() + "): " + message);
|
||||
|
||||
onMessage(client, message, protocolVersion);
|
||||
}
|
||||
|
||||
/**
|
||||
* Optional callback
|
||||
*
|
||||
* @param client The client sender
|
||||
* @param message The Message
|
||||
* @param protocolVersion the Classic version
|
||||
*/
|
||||
public void onMessage(ConnectedProtocolClient client, String message, Classic_ProtocolVersion protocolVersion) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unsupportedClassicPacket(String className, Object[] content, ConnectedProtocolClient client) {
|
||||
client.getServer().getProtocolBridge().getLogger().warn(
|
||||
"[Classic UnsupportedPacket] From client " + client.getPipelineConnection().getClientID() +
|
||||
": packet=" + className + " content=" + java.util.Arrays.toString(content)
|
||||
);
|
||||
|
||||
onUnsupportedClassicPacket(className, content, client);
|
||||
}
|
||||
|
||||
/**
|
||||
* Optional callback
|
||||
*
|
||||
* @param className The class name
|
||||
* @param content The content
|
||||
* @param client The client sender
|
||||
*/
|
||||
public void onUnsupportedClassicPacket(String className, Object[] content, ConnectedProtocolClient client) {
|
||||
}
|
||||
}
|
||||
@@ -1,41 +0,0 @@
|
||||
package org.openautonomousconnection.protocol.versions.v1_0_0.classic.helper;
|
||||
|
||||
import org.openautonomousconnection.protocol.ProtocolBridge;
|
||||
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;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
public record ClassicHelper(ProtocolBridge bridge) {
|
||||
|
||||
public Classic_Domain buildClassicDomain(ParsedDomain req, INSRecord rec) {
|
||||
Classic_Domain info = new Classic_Domain(req.name(), req.tln(), req.sub(), req.path(), bridge);
|
||||
|
||||
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(), bridge);
|
||||
}
|
||||
|
||||
public 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(".", Arrays.copyOfRange(parts, 0, parts.length - 1))
|
||||
: null;
|
||||
|
||||
return new ParsedDomain(tln, name, sub, req.path);
|
||||
}
|
||||
}
|
||||
@@ -1,4 +0,0 @@
|
||||
package org.openautonomousconnection.protocol.versions.v1_0_0.classic.helper;
|
||||
|
||||
public record ParsedDomain(String tln, String name, String sub, String path) {
|
||||
}
|
||||
@@ -1,7 +0,0 @@
|
||||
package org.openautonomousconnection.protocol.versions.v1_0_0.classic.helper;
|
||||
|
||||
/**
|
||||
* Represents a parsed CNAME target in (tln, name, sub) form.
|
||||
*/
|
||||
public record TargetName(String tln, String name, String sub) {
|
||||
}
|
||||
@@ -1,69 +0,0 @@
|
||||
package org.openautonomousconnection.protocol.versions.v1_0_0.classic.objects;
|
||||
|
||||
import org.openautonomousconnection.protocol.ProtocolBridge;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* Classic_Domain is an old representation of a InfoName, maintained for backward compatibility.
|
||||
* It encapsulates the InfoName's name, top-level name, path, and destination.
|
||||
* This class is deprecated and users are encouraged to use the InfoName class instead.
|
||||
*/
|
||||
@Deprecated(forRemoval = false, since = "1.0.0-BETA.3")
|
||||
public class Classic_Domain implements Serializable {
|
||||
|
||||
/**
|
||||
* The name of the domain.
|
||||
*/
|
||||
@Deprecated(forRemoval = false, since = "1.0.0-BETA.3")
|
||||
public final String name;
|
||||
|
||||
/**
|
||||
* The top-level domain.
|
||||
*/
|
||||
@Deprecated(forRemoval = false, since = "1.0.0-BETA.3")
|
||||
public final String topLevelDomain;
|
||||
|
||||
|
||||
/**
|
||||
* The path component of the domain.
|
||||
*/
|
||||
@Deprecated(forRemoval = false, since = "1.0.0-BETA.3")
|
||||
public final String path;
|
||||
|
||||
/**
|
||||
* The destination of the domain, typically the full URL or address.
|
||||
*/
|
||||
@Deprecated(forRemoval = false, since = "1.0.0-BETA.3")
|
||||
public final String destination;
|
||||
|
||||
/**
|
||||
* The ProtocolBridge reference.
|
||||
*/
|
||||
@Deprecated(forRemoval = false, since = "1.0.0-BETA.3")
|
||||
public final ProtocolBridge protocolBridge;
|
||||
|
||||
public Classic_Domain(String name, String topLevelDomain, String destination, String path, ProtocolBridge bridge) {
|
||||
this.protocolBridge = bridge;
|
||||
this.name = name;
|
||||
this.topLevelDomain = topLevelDomain;
|
||||
this.destination = destination;
|
||||
this.path = path;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected final Object clone() throws CloneNotSupportedException {
|
||||
return new Classic_Domain(name, topLevelDomain, destination, path, protocolBridge);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final boolean equals(Object obj) {
|
||||
if (!(obj instanceof Classic_Domain other)) return false;
|
||||
return other.name.equalsIgnoreCase(name) && other.topLevelDomain.equalsIgnoreCase(topLevelDomain);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final int hashCode() {
|
||||
return super.hashCode();
|
||||
}
|
||||
}
|
||||
@@ -1,14 +0,0 @@
|
||||
package org.openautonomousconnection.protocol.versions.v1_0_0.classic.objects;
|
||||
|
||||
import org.openautonomousconnection.protocol.ProtocolBridge;
|
||||
|
||||
/**
|
||||
* Class representing a local domain in the Classic protocol.
|
||||
* This class extends Classic_Domain and is used for local domain representation.
|
||||
*/
|
||||
@Deprecated(forRemoval = false, since = "1.0.0-BETA.3")
|
||||
public final class Classic_LocalDomain extends Classic_Domain {
|
||||
public Classic_LocalDomain(String name, String endName, String path, ProtocolBridge protocolBridge) {
|
||||
super(name, endName, null, path, protocolBridge);
|
||||
}
|
||||
}
|
||||
@@ -1,17 +0,0 @@
|
||||
package org.openautonomousconnection.protocol.versions.v1_0_0.classic.objects;
|
||||
|
||||
import org.openautonomousconnection.protocol.ProtocolBridge;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* Class representing a request for a domain in the Classic protocol.
|
||||
* This class extends Classic_Domain and is used for requesting domain information.
|
||||
*/
|
||||
@Deprecated(forRemoval = false, since = "1.0.0-BETA.3")
|
||||
public final class Classic_RequestDomain extends Classic_Domain implements Serializable {
|
||||
|
||||
public Classic_RequestDomain(String name, String topLevelDomain, String path, ProtocolBridge protocolBridge) {
|
||||
super(name, topLevelDomain, null, path, protocolBridge);
|
||||
}
|
||||
}
|
||||
@@ -1,44 +0,0 @@
|
||||
package org.openautonomousconnection.protocol.versions.v1_0_0.classic.site;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* Enum representing different types of sites in the Classic protocol.
|
||||
*/
|
||||
@Deprecated(forRemoval = false, since = "1.0.0-BETA.3")
|
||||
public enum Classic_SiteType implements Serializable {
|
||||
/**
|
||||
* Client site type.
|
||||
*/
|
||||
CLIENT("oac-client"),
|
||||
|
||||
/**
|
||||
* Web server site type.
|
||||
*/
|
||||
SERVER("oac-server"),
|
||||
|
||||
/**
|
||||
* INS server site type.
|
||||
*/
|
||||
PUBLIC("oac"),
|
||||
|
||||
/**
|
||||
* Protocol site type.
|
||||
*/
|
||||
PROTOCOL("oac-protocol"),
|
||||
|
||||
/**
|
||||
* Local site type.
|
||||
*/
|
||||
LOCAL("oac-local");
|
||||
|
||||
/**
|
||||
* The name of the site type.
|
||||
*/
|
||||
@Deprecated(forRemoval = false, since = "1.0.0-BETA.3")
|
||||
public final String name;
|
||||
|
||||
Classic_SiteType(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
}
|
||||
@@ -1,71 +0,0 @@
|
||||
package org.openautonomousconnection.protocol.versions.v1_0_0.classic.site;
|
||||
|
||||
import dev.unlegitdqrk.unlegitlibrary.utils.DefaultMethodsOverrider;
|
||||
|
||||
/**
|
||||
* This class contains predefined HTML content for various website responses in the Classic protocol.
|
||||
*/
|
||||
@Deprecated(forRemoval = false, since = "1.0.0-BETA.3")
|
||||
public final class Classic_WebsitesContent extends DefaultMethodsOverrider {
|
||||
|
||||
public static final String DOMAIN_NOT_FOUND = """
|
||||
<html>
|
||||
<head>
|
||||
<title>404 - Domain not found</title>
|
||||
<meta content="UTF-8" name="charset"/>
|
||||
<meta content="Open Autonomous Connection" name="author"/>
|
||||
<meta content="Domain not found" name="description"/>
|
||||
</head>
|
||||
<body>
|
||||
<h1>404 - This infoName was not found</h1>
|
||||
</body>
|
||||
</html>
|
||||
""";
|
||||
|
||||
public static final String FILE_NOT_FOUND = """
|
||||
<html>
|
||||
<head>
|
||||
<title>404 - File not found</title>
|
||||
<meta content="UTF-8" name="charset"/>
|
||||
<meta content="Open Autonomous Connection" name="author"/>
|
||||
<meta content="File not found" name="description"/>
|
||||
</head>
|
||||
<body>
|
||||
<h1>404 - This file was not found</h1>
|
||||
</body>
|
||||
</html>
|
||||
""";
|
||||
|
||||
public static final String DOMAIN_NOT_REACHABLE = """
|
||||
<html>
|
||||
<head>
|
||||
<title>504 - Site not reachable</title>
|
||||
<meta content="UTF-8" name="charset"/>
|
||||
<meta content="Open Autonomous Connection" name="author"/>
|
||||
<meta content="Site not reached" name="description"/>
|
||||
</head>
|
||||
<body>
|
||||
<h1>504 - This site is currently not reachable</h1>
|
||||
</body>
|
||||
</html>
|
||||
""";
|
||||
public static String ERROR_OCCURRED = ERROR_OCCURRED("No specified details!");
|
||||
|
||||
public static String ERROR_OCCURRED(String errorDetails) {
|
||||
return """
|
||||
<html>
|
||||
<head>
|
||||
<title>500 - Error occurred</title>
|
||||
<meta content="UTF-8" name="charset"/>
|
||||
<meta content="Open Autonomous Connection" name="author"/>
|
||||
<meta content="Site not reached" name="description"/>
|
||||
</head>
|
||||
<body>
|
||||
<h1>500 - Error occured while resolving infoName!</h1>
|
||||
<h4>Details:</h2>
|
||||
<h5>""" + errorDetails + "</h5>" + """
|
||||
</body>
|
||||
</html>
|
||||
""";
|
||||
}
|
||||
}
|
||||
@@ -1,131 +0,0 @@
|
||||
package org.openautonomousconnection.protocol.versions.v1_0_0.classic.utils;
|
||||
|
||||
import dev.unlegitdqrk.unlegitlibrary.event.EventListener;
|
||||
import dev.unlegitdqrk.unlegitlibrary.event.Listener;
|
||||
import lombok.Getter;
|
||||
import org.openautonomousconnection.protocol.ProtocolBridge;
|
||||
import org.openautonomousconnection.protocol.packets.v1_0_0.classic.Classic_PingPacket;
|
||||
import org.openautonomousconnection.protocol.versions.v1_0_0.classic.events.Classic_DomainPacketReceivedEvent;
|
||||
import org.openautonomousconnection.protocol.versions.v1_0_0.classic.events.Classic_PingPacketReceivedEvent;
|
||||
import org.openautonomousconnection.protocol.versions.v1_0_0.classic.objects.Classic_LocalDomain;
|
||||
import org.openautonomousconnection.protocol.versions.v1_0_0.classic.site.Classic_SiteType;
|
||||
import org.openautonomousconnection.protocol.versions.v1_0_0.classic.site.Classic_WebsitesContent;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.URL;
|
||||
|
||||
/**
|
||||
* This class listens for events related to Classic protocol operations on the client side.
|
||||
* It handles domain resolution and ping responses, facilitating communication with the INS server
|
||||
* and web content retrieval.
|
||||
*/
|
||||
@Deprecated(forRemoval = false, since = "1.0.0-BETA.3")
|
||||
public final class Classic_ClientListener extends EventListener {
|
||||
|
||||
/**
|
||||
* Reference to the ProtocolBridge
|
||||
*/
|
||||
@Getter
|
||||
private ProtocolBridge protocolBridge;
|
||||
|
||||
/**
|
||||
* Set protocol bridge
|
||||
*
|
||||
* @param protocolBridge The ProtocolBridge object
|
||||
*/
|
||||
public void setProtocolBridge(ProtocolBridge protocolBridge) {
|
||||
if (this.protocolBridge != null) return;
|
||||
this.protocolBridge = protocolBridge;
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles the event when a domain packet is received.
|
||||
* It checks if the domain exists and sends a ping request to the INS server.
|
||||
* If the domain does not exist, it handles the error accordingly.
|
||||
*
|
||||
* @param event The event containing domain information.
|
||||
*/
|
||||
@Listener
|
||||
public void onDomain(Classic_DomainPacketReceivedEvent event) {
|
||||
// Check if the domain exists
|
||||
boolean exists = event.domain != null;
|
||||
|
||||
if (exists) {
|
||||
try {
|
||||
// Send a ping request to the INS server
|
||||
if (!protocolBridge.getProtocolClient().getClientINSConnection().sendPacket(new Classic_PingPacket(event.requestDomain, event.domain, false, protocolBridge))) {
|
||||
// If sending the packet fails, handle the error
|
||||
protocolBridge.getClassicHandlerClient().handleHTMLContent(Classic_SiteType.PROTOCOL, new Classic_LocalDomain("error-occurred", "html", "", protocolBridge),
|
||||
Classic_WebsitesContent.ERROR_OCCURRED(event.domain + "/" + event.domain.path));
|
||||
}
|
||||
} catch (IOException | ClassNotFoundException e) {
|
||||
// Handle any exceptions that occur during the process
|
||||
protocolBridge.getClassicHandlerClient().handleHTMLContent(Classic_SiteType.PROTOCOL, new Classic_LocalDomain("error-occurred", "html", "", protocolBridge),
|
||||
Classic_WebsitesContent.ERROR_OCCURRED(event.domain + "/" + event.domain.path + ":\n" + e.getMessage()));
|
||||
}
|
||||
} else
|
||||
// If the domain does not exist, handle the error
|
||||
protocolBridge.getClassicHandlerClient().handleHTMLContent(Classic_SiteType.PROTOCOL, new Classic_LocalDomain("domain-not-found", "html", "", protocolBridge), Classic_WebsitesContent.DOMAIN_NOT_FOUND);
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles the event when a ping packet is received.
|
||||
* If the domain is reachable, it fetches the HTML content from the domain.
|
||||
* If not reachable, it handles the error accordingly.
|
||||
*
|
||||
* @param event The event containing ping response information.
|
||||
*/
|
||||
@Listener
|
||||
public void onPing(Classic_PingPacketReceivedEvent event) {
|
||||
// If the domain is reachable, fetch the HTML content
|
||||
if (event.reachable) {
|
||||
String destination = event.domain.destination;
|
||||
|
||||
try {
|
||||
// Create a URL object
|
||||
URL url = new URL(destination);
|
||||
HttpURLConnection connection2 = (HttpURLConnection) url.openConnection();
|
||||
connection2.setRequestMethod("GET");
|
||||
|
||||
// Read the response
|
||||
StringBuilder content = new StringBuilder();
|
||||
try (BufferedReader reader = new BufferedReader(new InputStreamReader(connection2.getInputStream()))) {
|
||||
String line;
|
||||
while ((line = reader.readLine()) != null) content.append(line);
|
||||
}
|
||||
|
||||
// Handle the HTML content
|
||||
protocolBridge.getClassicHandlerClient().handleHTMLContent(Classic_SiteType.PUBLIC, event.domain, content.toString());
|
||||
} catch (IOException exception) {
|
||||
// Handle any exceptions that occur during the process
|
||||
protocolBridge.getClassicHandlerClient().handleHTMLContent(Classic_SiteType.PROTOCOL, new Classic_LocalDomain("error-occurred", "html", "", protocolBridge),
|
||||
Classic_WebsitesContent.ERROR_OCCURRED(exception.getMessage().replace(event.domain.destination, event.domain + "/" + event.domain.path)));
|
||||
}
|
||||
} else
|
||||
// If the domain is not reachable, handle the error
|
||||
protocolBridge.getClassicHandlerClient().handleHTMLContent(Classic_SiteType.PROTOCOL, new Classic_LocalDomain("error-not-reached", "html", "", protocolBridge), Classic_WebsitesContent.DOMAIN_NOT_REACHABLE);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Object clone() throws CloneNotSupportedException {
|
||||
return super.clone();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
return super.equals(obj);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return super.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return super.hashCode();
|
||||
}
|
||||
}
|
||||
@@ -1,100 +0,0 @@
|
||||
package org.openautonomousconnection.protocol.versions.v1_0_0.classic.utils;
|
||||
|
||||
import dev.unlegitdqrk.unlegitlibrary.utils.DefaultMethodsOverrider;
|
||||
import org.openautonomousconnection.protocol.versions.v1_0_0.classic.site.Classic_SiteType;
|
||||
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
import java.net.URL;
|
||||
|
||||
/**
|
||||
* Utility class for domain-related operations in the Classic protocol.
|
||||
*/
|
||||
@Deprecated(forRemoval = false, since = "1.0.0-BETA.3")
|
||||
class Classic_DomainUtils extends DefaultMethodsOverrider {
|
||||
|
||||
/**
|
||||
* Extracts the top-level domain (TLD) from a given URL.
|
||||
*
|
||||
* @param url The URL from which to extract the TLD.
|
||||
* @return The top-level domain as a string.
|
||||
* @throws MalformedURLException If the URL is malformed.
|
||||
*/
|
||||
public static String getTopLevelDomain(String url) throws MalformedURLException {
|
||||
URL uri = null;
|
||||
String tldString = null;
|
||||
|
||||
if (url.startsWith(Classic_SiteType.PUBLIC.name + "://"))
|
||||
url = url.substring((Classic_SiteType.PUBLIC.name + "://").length());
|
||||
if (url.startsWith(Classic_SiteType.CLIENT.name + "://"))
|
||||
url = url.substring((Classic_SiteType.CLIENT.name + "://").length());
|
||||
if (url.startsWith(Classic_SiteType.SERVER.name + "://"))
|
||||
url = url.substring((Classic_SiteType.SERVER.name + "://").length());
|
||||
if (url.startsWith(Classic_SiteType.PROTOCOL.name + "://"))
|
||||
url = url.substring((Classic_SiteType.PROTOCOL.name + "://").length());
|
||||
if (url.startsWith(Classic_SiteType.LOCAL.name + "://"))
|
||||
url = url.substring((Classic_SiteType.LOCAL.name + "://").length());
|
||||
|
||||
if (!url.startsWith("https://") && !url.startsWith("http://")) url = "https://" + url;
|
||||
|
||||
uri = new URL(url);
|
||||
String[] domainNameParts = uri.getHost().split("\\.");
|
||||
tldString = domainNameParts[domainNameParts.length - 1];
|
||||
|
||||
return tldString;
|
||||
}
|
||||
|
||||
/**
|
||||
* Extracts the domain name (excluding the TLD) from a given URL.
|
||||
*
|
||||
* @param url The URL from which to extract the domain name.
|
||||
* @return The domain name as a string.
|
||||
* @throws URISyntaxException If the URL syntax is incorrect.
|
||||
* @throws MalformedURLException If the URL is malformed.
|
||||
*/
|
||||
public static String getDomainName(String url) throws URISyntaxException, MalformedURLException {
|
||||
if (url.startsWith(Classic_SiteType.PUBLIC.name + "://"))
|
||||
url = url.substring((Classic_SiteType.PUBLIC.name + "://").length());
|
||||
if (url.startsWith(Classic_SiteType.CLIENT.name + "://"))
|
||||
url = url.substring((Classic_SiteType.CLIENT.name + "://").length());
|
||||
if (url.startsWith(Classic_SiteType.SERVER.name + "://"))
|
||||
url = url.substring((Classic_SiteType.SERVER.name + "://").length());
|
||||
if (url.startsWith(Classic_SiteType.PROTOCOL.name + "://"))
|
||||
url = url.substring((Classic_SiteType.PROTOCOL.name + "://").length());
|
||||
if (url.startsWith(Classic_SiteType.LOCAL.name + "://"))
|
||||
url = url.substring((Classic_SiteType.LOCAL.name + "://").length());
|
||||
|
||||
if (!url.startsWith("https://") && !url.startsWith("http://")) url = "https://" + url;
|
||||
|
||||
URI uri = new URI(url);
|
||||
return uri.getHost().replace("." + getTopLevelDomain(url), "");
|
||||
}
|
||||
|
||||
/**
|
||||
* Extracts the path component from a given URL.
|
||||
*
|
||||
* @param url The URL from which to extract the path.
|
||||
* @return The path as a string.
|
||||
*/
|
||||
public static String getPath(String url) {
|
||||
if (!url.startsWith(Classic_SiteType.PUBLIC.name + "://") && !url.startsWith(Classic_SiteType.CLIENT.name + "://") &&
|
||||
!url.startsWith(Classic_SiteType.SERVER.name + "://") && !url.startsWith(Classic_SiteType.PROTOCOL.name + "://") &&
|
||||
!url.startsWith(Classic_SiteType.LOCAL.name + "://") && !url.startsWith("http") && !url.startsWith("https")) {
|
||||
url = Classic_SiteType.PUBLIC.name + "://" + url;
|
||||
}
|
||||
|
||||
String[] split = url.split("/");
|
||||
if (split.length <= 3) return "";
|
||||
|
||||
StringBuilder path = new StringBuilder();
|
||||
|
||||
for (int i = 3; i < split.length; i++) path.append(split[i]).append("/");
|
||||
|
||||
String pathStr = path.toString();
|
||||
if (pathStr.startsWith("/")) pathStr = pathStr.substring("/".length());
|
||||
if (pathStr.endsWith("/")) pathStr = pathStr.substring(0, pathStr.length() - "/".length());
|
||||
|
||||
return pathStr;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user