private Record parseRR(MyStringTokenizer st, boolean useLast, Record last, Name origin) throws IOException { Name name; int ttl; short type, dclass; if (!useLast) name = new Name(st.nextToken(), origin); else name = last.getName(); String s = st.nextToken(); try { ttl = TTL.parseTTL(s); s = st.nextToken(); } catch (NumberFormatException e) { if (!useLast || last == null) ttl = defaultTTL; else ttl = last.getTTL(); } if ((dclass = DClass.value(s)) > 0) s = st.nextToken(); else dclass = DClass.IN; if ((type = Type.value(s)) < 0) throw new IOException("Parse error"); return Record.fromString(name, type, dclass, ttl, st, origin); }
private void parseInclude(MyStringTokenizer st) throws IOException { if (!st.hasMoreTokens()) throw new IOException("Missing file to include"); File newfile; String filename = st.nextToken(); if (file.getParent() == null) newfile = new File(filename); else newfile = new File(file.getParent(), filename); if (st.hasMoreTokens()) included = new Master(newfile, new Name(st.nextToken())); else included = new Master(newfile, origin); }
KEYRecord(Name _name, short _dclass, int _ttl, MyStringTokenizer st, Name origin) throws IOException { super(_name, Type.KEY, _dclass, _ttl); flags = (short) Integer.decode(st.nextToken()).intValue(); proto = (byte) Integer.parseInt(st.nextToken()); alg = (byte) Integer.parseInt(st.nextToken()); /* If this is a null key, there's no key data */ if (!((flags & (FLAG_NOKEY)) == (FLAG_NOKEY))) key = base64.fromString(st.remainingTokens()); else key = null; }
Record rdataFromString(Name name, short dclass, int ttl, MyStringTokenizer st, Name origin) throws TextParseException { SIGRecord rec = new SIGRecord(name, dclass, ttl); rec.covered = Type.value(st.nextToken()); rec.alg = Byte.parseByte(st.nextToken()); rec.labels = Byte.parseByte(st.nextToken()); rec.origttl = TTL.parseTTL(st.nextToken()); rec.expire = parseDate(st.nextToken()); rec.timeSigned = parseDate(st.nextToken()); rec.footprint = (short) Integer.parseInt(st.nextToken()); rec.signer = Name.fromString(st.nextToken(), origin); if (st.hasMoreTokens()) rec.signature = base64.fromString(st.remainingTokens()); return rec; }
/** Returns the next record in the master file */ public Record nextRecord() throws IOException { String line; MyStringTokenizer st; if (included != null) { Record rec = included.nextRecord(); if (rec != null) return rec; included = null; } while (true) { line = readExtendedLine(br); if (line == null) return null; if (line.length() == 0 || line.startsWith(";")) continue; boolean space = line.startsWith(" ") || line.startsWith("\t"); st = new MyStringTokenizer(line); String s = st.nextToken(); if (s.equals("$ORIGIN")) { origin = parseOrigin(st); continue; } if (s.equals("$TTL")) { defaultTTL = parseTTL(st); continue; } if (s.equals("$INCLUDE")) { parseInclude(st); /* * If we continued, we wouldn't be looking in * the new file. Recursing works better. */ return nextRecord(); } else if (s.charAt(0) == '$') throw new IOException("Invalid directive: " + s); st.putBackToken(s); return (last = parseRR(st, space, last, origin)); } }
private Name parseOrigin(MyStringTokenizer st) throws IOException { if (!st.hasMoreTokens()) throw new IOException("Missing ORIGIN"); return new Name(st.nextToken()); }
private int parseTTL(MyStringTokenizer st) throws IOException { if (!st.hasMoreTokens()) throw new IOException("Missing TTL"); return Integer.parseInt(st.nextToken()); }