summaryrefslogtreecommitdiff
path: root/src/org/noreply/fancydress/directory
diff options
context:
space:
mode:
Diffstat (limited to 'src/org/noreply/fancydress/directory')
-rw-r--r--src/org/noreply/fancydress/directory/IncomingMMTPSection.java10
-rw-r--r--src/org/noreply/fancydress/directory/Server.java20
-rw-r--r--src/org/noreply/fancydress/directory/ServerDescriptor.java59
3 files changed, 74 insertions, 15 deletions
diff --git a/src/org/noreply/fancydress/directory/IncomingMMTPSection.java b/src/org/noreply/fancydress/directory/IncomingMMTPSection.java
index bd1ec67..92e17d7 100644
--- a/src/org/noreply/fancydress/directory/IncomingMMTPSection.java
+++ b/src/org/noreply/fancydress/directory/IncomingMMTPSection.java
@@ -100,4 +100,14 @@ public class IncomingMMTPSection {
protocols = entryProtocols.getValue();
}
+
+ public InetAddress getIP() {
+ return ip;
+ }
+ public String getHostname() {
+ return hostname;
+ }
+ public int getPort() {
+ return port;
+ }
}
diff --git a/src/org/noreply/fancydress/directory/Server.java b/src/org/noreply/fancydress/directory/Server.java
index 53455f4..c4052d9 100644
--- a/src/org/noreply/fancydress/directory/Server.java
+++ b/src/org/noreply/fancydress/directory/Server.java
@@ -77,11 +77,23 @@ public class Server {
}
/**
- * get the first server descriptor (needs fixing).
+ * get the the currently valid server descriptor.
*
- * @return first server descriptor
+ * @return current server descriptor
*/
- public ServerDescriptor getDescriptor() { /* FIXME */
- return (ServerDescriptor) descriptors.get(0);
+ public ServerDescriptor getDescriptor() throws Mix3Exception {
+ ServerDescriptor result = null;
+ Date now = new Date();
+
+ for (int i=0; i<descriptors.size(); i++) {
+ ServerDescriptor desc = (ServerDescriptor) descriptors.get(i);
+ if (now.after( desc.getValidAfter() ) &&
+ now.before( desc.getValidUntil() ) &&
+ ((result == null) || desc.getPublished().after( result.getPublished())))
+ result = desc;
+ }
+ if (result == null)
+ throw new Mix3Exception("No valid server descriptor found.");
+ return result;
}
}
diff --git a/src/org/noreply/fancydress/directory/ServerDescriptor.java b/src/org/noreply/fancydress/directory/ServerDescriptor.java
index 2f076f6..020d31b 100644
--- a/src/org/noreply/fancydress/directory/ServerDescriptor.java
+++ b/src/org/noreply/fancydress/directory/ServerDescriptor.java
@@ -45,11 +45,11 @@ public class ServerDescriptor {
private Boolean secureConfiguration;
private String whyInsecure;
- private IncomingMMTPSection IncomingMMTPSection;
- private Object OutgoingMMTPSection;
- private DeliveryMBOXSection DeliveryMBOXSection;
- private DeliverySMTPSection DeliverySMTPSection;
- private Object DeliveryFragmentedSection;
+ private IncomingMMTPSection incomingMMTPSection;
+ private Object outgoingMMTPSection;
+ private DeliveryMBOXSection deliveryMBOXSection;
+ private DeliverySMTPSection deliverySMTPSection;
+ private Object deliveryFragmentedSection;
/**
@@ -79,17 +79,17 @@ public class ServerDescriptor {
DirectorySection section;
section = m.getSection("Incoming/MMTP");
try {
- IncomingMMTPSection = section == null ? null : new IncomingMMTPSection(section);
+ incomingMMTPSection = section == null ? null : new IncomingMMTPSection(section);
} catch (Mix3BadServerFormatException e) { System.err.println(e); };
section = m.getSection("Delivery/MBOX");
try {
- DeliveryMBOXSection = section == null ? null : new DeliveryMBOXSection(section);
+ deliveryMBOXSection = section == null ? null : new DeliveryMBOXSection(section);
} catch (Mix3BadServerFormatException e) { System.err.println(e); };
section = m.getSection("Delivery/SMTP");
try {
- DeliverySMTPSection = section == null ? null : new DeliverySMTPSection(section);
+ deliverySMTPSection = section == null ? null : new DeliverySMTPSection(section);
} catch (Mix3BadServerFormatException e) { System.err.println(e); };
}
@@ -130,12 +130,12 @@ public class ServerDescriptor {
while ((indexOf = s.indexOf(',', indexFrom)) != -1) {
String v = s.substring(indexFrom, indexOf).trim();
- if (Packet.isPacketVersionSupported(v) || !onlySupported )
+ if (!v.equals("") && (Packet.isPacketVersionSupported(v) || !onlySupported ))
versions.add( v );
indexFrom = indexOf + 1;
}
String v = s.substring(indexFrom).trim();
- if (Packet.isPacketVersionSupported(v) || !onlySupported )
+ if (!v.equals("") && (Packet.isPacketVersionSupported(v) || !onlySupported ))
versions.add( v );
String[] result = new String[versions.size()];
@@ -223,7 +223,7 @@ public class ServerDescriptor {
identity = Base64.decode(entryIdentity.getValue());
digest = Base64.decode(entryDigest.getValue());
signature = Base64.decode(entrySignature.getValue());
- published = Util.parseDate(entryPublished.getValue());
+ published = Util.parseDateTime(entryPublished.getValue());
validAfter = Util.parseDate(entryValidAfter.getValue());
validUntil = Util.parseDate(entryValidUntil.getValue());
packetKey = new RSAPublicKey(Base64.decode(entryPacketKey.getValue()));
@@ -317,4 +317,41 @@ public class ServerDescriptor {
public RSAPublicKey getPacketKey() {
return packetKey;
}
+
+ /**
+ * Get the date after which this server descriptor is valid.
+ *
+ * @return date after which this server descriptor is valid
+ */
+ public Date getValidAfter() {
+ return validAfter;
+ }
+
+ /**
+ * Get the date until which this server descriptor is valid.
+ *
+ * @return date until which this server descriptor is valid
+ */
+ public Date getValidUntil() {
+ return validUntil;
+ }
+
+ /**
+ * Get the date when this server descriptor was published.
+ *
+ * @return date when this server descriptor was published
+ */
+ public Date getPublished() {
+ return published;
+ }
+
+ /**
+ * Get the Incoming/MMTP section.
+ *
+ * @return this server descriptor's Incoming/MMTP section
+ */
+ public IncomingMMTPSection getIncomingMMTPSection() {
+ return incomingMMTPSection;
+ }
+
}