4 * Copyright (c) 2005 VeriSign. All rights reserved.
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions are met:
9 * 1. Redistributions of source code must retain the above copyright notice,
10 * this list of conditions and the following disclaimer. 2. Redistributions in
11 * binary form must reproduce the above copyright notice, this list of
12 * conditions and the following disclaimer in the documentation and/or other
13 * materials provided with the distribution. 3. The name of the author may not
14 * be used to endorse or promote products derived from this software without
15 * specific prior written permission.
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
20 * NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
22 * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
23 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
24 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
25 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
26 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 package com.versign.tat.dnssec;
34 import org.xbill.DNS.Flags;
35 import org.xbill.DNS.Header;
36 import org.xbill.DNS.Name;
39 * Some basic utility functions.
48 * Convert a DNS name into a string suitable for use as a cache key.
50 * @param name The name to convert.
51 * @return A string representing the name. This isn't ever meant to be
52 * converted back into a DNS name.
54 public static String nameToString(Name name)
56 if (name.equals(Name.root)) return ".";
58 String n = name.toString().toLowerCase();
59 if (n.endsWith(".")) n = n.substring(0, n.length() - 1);
64 // public static SMessage errorMessage(Request request, int rcode)
66 // SMessage m = new SMessage(request.getID());
67 // Header h = m.getHeader();
69 // h.setFlag(Flags.QR);
70 // m.setQuestion(request.getQuestion());
71 // m.setOPT(request.getOPT());
76 // public static SMessage errorMessage(SMessage message, int rcode)
78 // Header h = message.getHeader();
79 // SMessage m = new SMessage(h.getID());
82 // h.setFlag(Flags.QR);
83 // m.setQuestion(message.getQuestion());
84 // m.setOPT(message.getOPT());
89 public static int parseInt(String s, int def)
91 if (s == null) return def;
94 return Integer.parseInt(s);
96 catch (NumberFormatException e)
102 public static long parseLong(String s, long def)
104 if (s == null) return def;
107 return Long.parseLong(s);
109 catch (NumberFormatException e)
115 public static class ConfigEntry
120 public ConfigEntry(String key, String value)
122 this.key = key; this.value = value;
126 public static List parseConfigPrefix(Properties config, String prefix)
128 if (! prefix.endsWith("."))
130 prefix = prefix + ".";
133 List res = new ArrayList();
135 for (Iterator i = config.entrySet().iterator(); i.hasNext(); )
137 Map.Entry entry = (Map.Entry) i.next();
138 String key = (String) entry.getKey();
139 if (key.startsWith(prefix))
141 key = key.substring(prefix.length());
143 res.add(new ConfigEntry(key, (String) entry.getValue()));