private static void ParseResourceRecord(DnsZoneParseContext context) { string @class; TimeSpan?ttl; var nameToken = context.Tokens.Dequeue(); var name = nameToken.Type != TokenType.Whitespace ? nameToken.StringValue : ""; if (context.TryParseClass(out @class)) { context.TryParseTtl(out ttl); } else if (context.TryParseTtl(out ttl)) { context.TryParseClass(out @class); } var type = context.ReadResourceRecordType(); //An RRT.NULL return indicates we encountered some kind of //whitespace instead of the ReadResourceRecordType. if (type == ResourceRecordType.NULL) { return; } string domainName; try { domainName = context.ResolveDomainName(!string.IsNullOrWhiteSpace(name) ? name : context.PrevName); } catch (ArgumentException exc) { throw new TokenException(exc.Message, nameToken); } var record = DnsZoneUtils.CreateRecord(type); record.Name = domainName; record.Class = !string.IsNullOrWhiteSpace(@class) ? @class : context.PrevClass; record.Ttl = context.GetTimeSpan(ttl); record.AcceptVistor(_reader, context); context.Zone.Records.Add(record); context.PrevName = name; if (!string.IsNullOrWhiteSpace(@class)) { context.PrevClass = @class; } }
private static void ParseResourceRecord(DnsZoneParseContext context) { string @class; TimeSpan?ttl; var nameToken = context.Tokens.Dequeue(); var name = nameToken.Type != TokenType.Whitespace ? nameToken.StringValue : ""; if (context.TryParseClass(out @class)) { context.TryParseTtl(out ttl); } else if (context.TryParseTtl(out ttl)) { context.TryParseClass(out @class); } var type = context.ReadResourceRecordType(); var record = DnsZoneUtils.CreateRecord(type); record.Name = context.ResolveDomainName(!string.IsNullOrWhiteSpace(name) ? name : context.PrevName); record.Class = !string.IsNullOrWhiteSpace(@class) ? @class : context.PrevClass; record.Ttl = context.GetTimeSpan(ttl); record.AcceptVistor(_reader, context); context.Zone.Records.Add(record); context.PrevName = name; if (!string.IsNullOrWhiteSpace(@class)) { context.PrevClass = @class; } }
private static void ParseResourceRecord(DnsZoneParseContext context) { string @class = null; TimeSpan?ttl = null; if (context.Tokens.Count == 0) { return; } string name = null; var nameToken = context.Tokens.Dequeue(); if (nameToken.Type == TokenType.Literal) { name = nameToken.StringValue; } else if (nameToken.Type == TokenType.Whitespace) { var preview = context.Tokens.Peek(); if (preview.Type == TokenType.NewLine || preview.Type == TokenType.NewLine) { context.Tokens.Dequeue(); return; } name = ""; } else if (nameToken.Type == TokenType.Comments) { return; } else if (nameToken.Type == TokenType.NewLine) { return; } while (@class == null || ttl == null) { if (context.Tokens.Count == 0) { if (string.IsNullOrWhiteSpace(name)) { return; } else { throw new TokenException("missing record type", nameToken); } } var token = context.Tokens.Peek(); if (token.Type == TokenType.Literal) { if (@class == null) { if (context.TryParseClass(out @class)) { continue; } } if (@ttl == null) { if (context.TryParseTtl(out ttl)) { continue; } } break; } else if (token.Type == TokenType.Comments || token.Type == TokenType.NewLine) { throw new TokenException("missing record type", token); } else { throw new TokenException("unexpected token", token); } } var type = context.ReadResourceRecordType(); string domainName; try { domainName = context.ResolveDomainName(!string.IsNullOrWhiteSpace(name) ? name : context.PrevName); } catch (ArgumentException exc) { throw new TokenException(exc.Message, nameToken); } var record = DnsZoneUtils.CreateRecord(type); record.Name = domainName; record.Class = !string.IsNullOrWhiteSpace(@class) ? @class : context.PrevClass; record.Ttl = context.GetTimeSpan(ttl); record.AcceptVistor(_reader, context); context.Zone.Records.Add(record); if (!string.IsNullOrWhiteSpace(name)) { context.PrevName = name; } if (!string.IsNullOrWhiteSpace(@class)) { context.PrevClass = @class; } }