summaryrefslogtreecommitdiff
path: root/src/org/noreply/fancydress/directory/IncomingMMTPSection.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/org/noreply/fancydress/directory/IncomingMMTPSection.java')
-rw-r--r--src/org/noreply/fancydress/directory/IncomingMMTPSection.java102
1 files changed, 102 insertions, 0 deletions
diff --git a/src/org/noreply/fancydress/directory/IncomingMMTPSection.java b/src/org/noreply/fancydress/directory/IncomingMMTPSection.java
new file mode 100644
index 0000000..28511b2
--- /dev/null
+++ b/src/org/noreply/fancydress/directory/IncomingMMTPSection.java
@@ -0,0 +1,102 @@
+package org.noreply.fancydress.directory;
+
+import org.bouncycastle.util.encoders.Base64;
+import org.noreply.fancydress.directory.parser.*;
+import org.noreply.fancydress.misc.Util;
+import org.noreply.fancydress.crypto.*;
+import org.noreply.fancydress.status.*;
+import java.util.*;
+import java.text.ParseException;
+import java.net.InetAddress;
+import java.net.UnknownHostException;
+
+/* FIXME: parse allow/deny ACLs */
+
+/**
+ * Represent an Incoming/MMTP section of a server descriptor.
+ *
+ * @see ServerDescriptor
+ */
+public class IncomingMMTPSection {
+ private String name;
+
+ /* Required */
+ private String version;
+ private InetAddress ip;
+ private String hostname;
+ private int port;
+ private String protocols;
+
+ /**
+ * Construct an Incoming/MMTP section.
+ *
+ * @param section the section to parse.
+ * @throws Mix3BadServerFormatException if the Section is syntactially invalid.
+ */
+ public IncomingMMTPSection(DirectorySection section)
+ throws Mix3BadServerFormatException
+ {
+ name = section.getName();
+ parseIncomingMMTPSection(section);
+ }
+
+ /**
+ * Parse an Incoming/MMTP section.
+ *
+ * @param section the section to parse.
+ * @throws Mix3BadServerFormatException if the Section is syntactially invalid.
+ */
+ private void parseIncomingMMTPSection(DirectorySection section) throws Mix3BadServerFormatException {
+ /* Check Version */
+ DirectoryEntry entryVersion = section.getEntry("Version");
+ if (entryVersion == null)
+ throw new Mix3BadServerFormatException("Version not in " + name + " section");
+ version = entryVersion.getValue();
+ if (! version.equals("0.1"))
+ /* We have to ignore unknown Versions */
+ throw new Mix3BadServerUnrecognizedVersionException("Unrecognized " + name + " Version "+version);
+
+ /* mandatory entries */
+ DirectoryEntry entryIP = section.getEntry("IP");
+ DirectoryEntry entryHostname = section.getEntry("Hostname");
+ DirectoryEntry entryPort = section.getEntry("Port");
+ DirectoryEntry entryProtocols = section.getEntry("Protocols");
+
+ /* check if mandatory entries are available */
+ if (entryIP == null)
+ throw new Mix3BadServerFormatException("IP not in " + name + " section");
+ /* FIXME: spec is changing from IP to hostname, for now, hostname is not used */
+ /*
+ if (entryHostname == null)
+ throw new Mix3BadServerFormatException("Hostname not in " + name + " section");
+ */
+ if (entryPort == null)
+ throw new Mix3BadServerFormatException("Port not in " + name + " section");
+ if (entryProtocols == null)
+ throw new Mix3BadServerFormatException("Protocols not in " + name + " section");
+
+
+ try {
+ ip = InetAddress.getByName(entryIP.getValue());
+ } catch (UnknownHostException e) {
+ throw new Mix3BadServerFormatException("IP is not a valid IP adress in " + name + " section", e);
+ }
+ if (!ip.getHostAddress().equals(entryIP.getValue()))
+ throw new Mix3BadServerFormatException(
+ "parsed IP to string does not match its directory representation in " + name + " section: "+
+ ip.getHostAddress() + " vs. " + entryIP.getValue());
+
+ hostname = entryHostname == null ? null : entryHostname.getValue(); /* FIXME */
+
+ try {
+ Integer p = new Integer(entryPort.getValue());
+ port = p.intValue();
+ } catch (NumberFormatException e) {
+ throw new Mix3BadServerFormatException("Port is not a valid integer in " + name + " section", e);
+ };
+ if (port < 0 || port > 65535)
+ throw new Mix3BadServerFormatException("Port is not in TCP/IP port range in " + name + " section");
+
+ protocols = entryProtocols.getValue();
+ }
+}