summaryrefslogtreecommitdiff
path: root/src/org/noreply/fancydress/directory/OutgoingMMTPSection.java
blob: 8b9ca9b4ad5207d1899c111213d6a8714684ff57 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
/* $Id$ */
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 Outgoing/MMTP section of a server descriptor.
 *
 * @see ServerDescriptor
 */
public class OutgoingMMTPSection {
	/*
	 * version we understand.
	 */
	private static final String VERSION = "0.1";

	private String name;

	/* Required */
	private String version;
	private String[] protocols;

	/**
	 * Construct an Outgoing/MMTP section.
	 *
	 * @param section the section to parse.
	 * @throws Mix3BadServerFormatException if the Section is syntactially invalid.
	 */
	public OutgoingMMTPSection(DirectorySection section)
		throws Mix3BadServerFormatException
	{
		name = section.getName();
		parseOutgoingMMTPSection(section);
	}

	/**
	 * Parse an Outgoing/MMTP section.
	 *
	 * @param section the section to parse.
	 * @throws Mix3BadServerFormatException if the Section is syntactially invalid.
	 */
	private void parseOutgoingMMTPSection(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(VERSION))
			/* We have to ignore unknown Versions */
			throw new Mix3BadServerUnrecognizedVersionException("Unrecognized " + name + " Version "+version);

		/* mandatory entries */
		DirectoryEntry entryProtocols = section.getEntry("Protocols");

		/* check if mandatory entries are available */
		if (entryProtocols == null)
			throw new Mix3BadServerFormatException("Protocols not in " + name + " section");
		protocols = Util.tokenize(entryProtocols.getValue(), ',');
	}

	public String[] getProtocols() {
		return protocols;
	}
}