Commit 007cb6a2 authored by Mikio Hara's avatar Mikio Hara

go.net/ipv6: make IANA registry parser robust

- specify complete resource path to avoid receiving xhtml
- make use of keyword instead of table index

R=golang-dev, dave
CC=golang-dev
https://golang.org/cl/10738043
parent ecb7ecda
...@@ -28,7 +28,7 @@ var registries = []struct { ...@@ -28,7 +28,7 @@ var registries = []struct {
parse func(io.Writer, io.Reader) error parse func(io.Writer, io.Reader) error
}{ }{
{ {
"http://www.iana.org/assignments/icmpv6-parameters", "http://www.iana.org/assignments/icmpv6-parameters/icmpv6-parameters.xml",
parseICMPv6Parameters, parseICMPv6Parameters,
}, },
{ {
...@@ -73,7 +73,7 @@ func parseICMPv6Parameters(w io.Writer, r io.Reader) error { ...@@ -73,7 +73,7 @@ func parseICMPv6Parameters(w io.Writer, r io.Reader) error {
if err := dec.Decode(&icp); err != nil { if err := dec.Decode(&icp); err != nil {
return err return err
} }
prs := icp.escape(1) prs := icp.escape()
fmt.Fprintf(w, "// %s, Updated: %s\n", icp.Title, icp.Updated) fmt.Fprintf(w, "// %s, Updated: %s\n", icp.Title, icp.Updated)
fmt.Fprintf(w, "const (\n") fmt.Fprintf(w, "const (\n")
for _, pr := range prs { for _, pr := range prs {
...@@ -119,7 +119,17 @@ type canonICMPv6ParamRecord struct { ...@@ -119,7 +119,17 @@ type canonICMPv6ParamRecord struct {
Value int Value int
} }
func (icp *icmpv6Parameters) escape(id int) []canonICMPv6ParamRecord { func (icp *icmpv6Parameters) escape() []canonICMPv6ParamRecord {
id := -1
for i, r := range icp.Registries {
if strings.Contains(r.Title, "Type") || strings.Contains(r.Title, "type") {
id = i
break
}
}
if id < 0 {
return nil
}
prs := make([]canonICMPv6ParamRecord, len(icp.Registries[id].Records)) prs := make([]canonICMPv6ParamRecord, len(icp.Registries[id].Records))
sr := strings.NewReplacer( sr := strings.NewReplacer(
"Messages", "", "Messages", "",
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment