Пример #1
0
func ParseNS(name string, ttl int32, rdclass string, zstate *ZoneState, s *scanner.Scanner) (rdtype.Rdtyper, error) {
	cur := <-s.Next()
	if err := goodToken(&cur); err != nil {
		return nil, err
	}
	targetName := trueName(zstate, cur.Value)
	if err := requireDNSName(&cur.Value); err != nil {
		return nil, err
	}
	ns := rdtype.NS{name, ttl, targetName}
	return rdtype.Rdtyper(ns), nil
}
Пример #2
0
func ParseSOA(name string, ttl int32, rdclass string, zstate *ZoneState, s *scanner.Scanner) (rdtype.Rdtyper, error) {
	// Assume scanner is currently on rdtype
	// We expect to see:
	// primary contact (serial, refresh, retry, exprire, minimum)
	// Parse out comments and ignore them
	//fmt.Printf("ParseSOA rdclass='%s' rdtype='%s'\n", rdclass, "SOA")
	cur := <-s.Next()
	if err := goodToken(&cur); err != nil {
		return nil, err
	}
	primary := trueName(zstate, cur.Value)
	//fmt.Printf("primary=%s\n", primary)

	cur = <-s.NextUntil(`[\n\(]`)
	if err := goodToken(&cur); err != nil {
		return nil, err
	}
	contact := trueName(zstate, cur.Value)
	//fmt.Printf("contact=%s\n", contact)

	if err := ClearCommentNewLine(s); err != nil {
		return nil, err
	}

	//fmt.Printf("peek='%s'\n", (<-s.Peek()).Value)
	cur = <-s.NextUntil(`[\(\n]`)
	//fmt.Printf("lparen='%s'\n", cur.Value)
	//fmt.Printf("peek='%s'\n", (<-s.Peek()).Value)
	if err := goodToken(&cur); err != nil {
		return nil, err
	}
	if cur.Value != "(" {
		return nil, fmt.Errorf(
			"Expected '(' in SOA definition but instead found '%s'\n", cur.Value)
	}

	if err := ClearCommentNewLine(s); err != nil {
		return nil, err
	}

	serial, err := parseSOAInt32(s, cur)
	if err != nil {
		return nil, err
	}
	//fmt.Printf("serial=%d\n", serial)

	refresh, err := parseSOAInt32(s, cur)
	if err != nil {
		return nil, err
	}
	//fmt.Printf("refresh=%d\n", refresh)

	retry, err := parseSOAInt32(s, cur)
	if err != nil {
		return nil, err
	}
	//fmt.Printf("retry=%d\n", retry)

	expire, err := parseSOAInt32(s, cur)
	if err != nil {
		return nil, err
	}
	//fmt.Printf("expire=%d\n", expire)

	cur = <-s.NextUntil(`[\)\n]`)
	if err := goodToken(&cur); err != nil {
		return nil, err
	}
	minimum, err := requireInt32(cur.Value)
	if err != nil {
		return nil, err
	}
	//fmt.Printf("minimum=%d\n", minimum)

	//fmt.Printf("-------------\n")
	if err := ClearCommentNewLine(s); err != nil {
		return nil, err
	}

	cur = <-s.Next()
	if cur.Value != ")" {
		return nil, fmt.Errorf(
			"Expected ')' in SOA definition but instead found '%s'\n", cur.Value)
	}
	soa := rdtype.SOA{name, ttl, primary, contact, serial, retry, refresh, expire, minimum}
	return rdtype.Rdtyper(soa), nil
}