// Copyright (c) 1999 Brian Wellington (bwelling@xbill.org)
// Portions Copyright (c) 1999 Network Associates, Inc.

package org.xbill.DNS;

import java.util.*;

/**
 * Boolean options:<BR>
 * bindttl - Print TTLs in BIND format<BR>
 * noprintin - Don't print the class of a record if it's IN<BR>
 * nohex - Don't print anything in hex (KEY flags, for example)<BR>
 * pqdn - Allow partially qualified domain names<BR>
 * verbose - Turn on general debugging statements<BR>
 * verbosehmac - Print all data digested by the HMAC routines<BR>
 * verbosemsg - Print all messages sent or received by SimpleResolver<BR>
 * verbosecompression - Print messages related to name compression<BR>
 * verbosebitstring - Print messages related to bitstring labels<BR>
 * verbosesec - Print messages related to signature verification<BR>
 * verbosecache - Print messages related to cache lookups<BR>
 * <BR>
 * Valued options:<BR>
 * tsigfudge=n - Sets the default TSIG fudge value (in seconds)<BR>
 * sig0validity=n - Sets the default SIG(0) validity period (in seconds)<BR>
 *
 * @author Brian Wellington
 */

public final class Options {

private static Map table;

static {
	String s = System.getProperty("dnsjava.options");
	if (s != null) {
		StringTokenizer st = new StringTokenizer(s, ",");
		while (st.hasMoreTokens()) {
			String token = st.nextToken();
			int index = token.indexOf('=');
			if (index == -1)
				set(token);
			else {
				String option = token.substring(0, index);
				String value = token.substring(index + 1);
				set(option, value);
			}
		}
	}
}

private
Options() {}

/** Sets an option to "true" */
public static void
set(String option) {
	if (table == null)
		table = new HashMap();
	table.put(option.toLowerCase(), "true");
}

/** Sets an option to the the supplied value */
public static void
set(String option, String value) {
	if (table == null)
		table = new HashMap();
	table.put(option.toLowerCase(), value.toLowerCase());
}

/** Removes an option */
public static void
unset(String option) {
	if (table == null)
		return;
	table.remove(option.toLowerCase());
}

/** Checks if an option is defined */
public static boolean
check(String option) {
	if (table == null)
		return false;
	return (table.get(option.toLowerCase()) != null);
}

/** Returns the value of an option */
public static String
value(String option) {
	if (table == null)
		return null;
	return ((String)table.get(option.toLowerCase()));
}

}

@@ -2424,10 +2424,318 @@
 )));%0A%7D%0A%0A
+/**%0A * Returns the value of an option as an integer, or -1 if not defined.%0A */%0Apublic static int%0AintValue(String option) %7B%0A%09String s = value(option);%0A%09if (s != null) %7B%0A%09%09try %7B%0A%09%09%09int val = Integer.parseInt(s);%0A%09%09%09if (val %3E 0)%0A%09%09%09%09return (val);%0A%09%09%7D%0A%09%09catch (NumberFormatException e) %7B%0A%09%09%7D%0A%09%7D%0A%09return (-1);%0A%7D%0A%0A
 %7D%0A

add Options.intValue()