From 48bc1d9d5ceaba2754c8601acb579917c2b33bd9 Mon Sep 17 00:00:00 2001 From: David Blacka Date: Tue, 8 Jun 2010 23:18:45 -0400 Subject: [PATCH] add initial query string parsing code --- src/com/verisign/cl/DNSSECReconciler.java | 71 ++++++++++++++++++++--- 1 file changed, 62 insertions(+), 9 deletions(-) diff --git a/src/com/verisign/cl/DNSSECReconciler.java b/src/com/verisign/cl/DNSSECReconciler.java index 2b35d69..49c0777 100644 --- a/src/com/verisign/cl/DNSSECReconciler.java +++ b/src/com/verisign/cl/DNSSECReconciler.java @@ -3,6 +3,7 @@ package com.verisign.cl; import java.util.*; import org.xbill.DNS.*; + import com.verisign.tat.dnssec.CaptiveValidator; public class DNSSECReconciler { @@ -14,18 +15,71 @@ public class DNSSECReconciler { private CaptiveValidator validator; // Options - public String server; - public String query; - public String queryFile; - public String dnskeyFile; - public List dnskeyNames; + public String server; + public String query; + public String queryFile; + public String dnskeyFile; + public List dnskeyNames; DNSSECReconciler() { validator = new CaptiveValidator(); } - public void execute() { + /** + * Convert a query line of the form: to a request + * message. + * + * @param query_line + * @return A query message + * @throws TextParseException + * @throws NameTooLongException + */ + private Message queryFromString(String query_line) + throws TextParseException, NameTooLongException { + String[] tokens = query_line.split("[ \t]+"); + + Name qname = null; + int qtype = -1; + int qclass = -1; + + if (tokens.length < 1) + return null; + qname = Name.fromString(tokens[0]); + if (!qname.isAbsolute()) { + qname = Name.concatenate(qname, Name.root); + } + + for (int i = 1; i < tokens.length; i++) { + if (tokens[i].startsWith("+")) { + // For now, we ignore flags as uninteresting + continue; + } + + int type = Type.value(tokens[i]); + if (type > 0) { + qtype = type; + continue; + } + int cls = DClass.value(tokens[i]); + if (cls > 0) { + qclass = cls; + continue; + } + } + if (qtype < 0) { + qtype = Type.A; + } + if (qclass < 0) { + qclass = DClass.IN; + } + + Message query = Message.newQuery(Record.newRecord(qname, qtype, qclass)); + + return query; + } + + public void execute() { } private static void usage() { @@ -50,7 +104,7 @@ public class DNSSECReconciler { usage(); return 1; } - + String[] split_arg = arg.split("[ \t]*=[ \t]*", 2); String opt = split_arg[0]; String optarg = split_arg[1]; @@ -89,8 +143,7 @@ public class DNSSECReconciler { usage(); return 1; } - - + // Execute the job dr.execute();