-
Notifications
You must be signed in to change notification settings - Fork 17
/
greeting.go
141 lines (130 loc) · 4.21 KB
/
greeting.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
package epp
import (
"encoding/xml"
"github.com/nbio/xx"
)
// Hello sends a <hello> command to request a <greeting> from the EPP server.
func (c *Conn) Hello() error {
err := c.writeRequest(xmlHello)
if err != nil {
return err
}
_, err = c.readGreeting()
return err
}
var xmlHello = []byte(xml.Header + startEPP + `<hello/>` + endEPP)
// Greeting is an EPP response that represents server status and capabilities.
// https://tools.ietf.org/html/rfc5730#section-2.4
type Greeting struct {
ServerName string `xml:"svID"`
Versions []string `xml:"svcMenu>version"`
Languages []string `xml:"svcMenu>lang"`
Objects []string `xml:"svcMenu>objURI"`
Extensions []string `xml:"svcMenu>svcExtension>extURI,omitempty"`
}
// SupportsObject returns true if the EPP server supports
// the object specified by uri.
func (g *Greeting) SupportsObject(uri string) bool {
if g == nil {
return false
}
for _, v := range g.Objects {
if v == uri {
return true
}
}
return false
}
// SupportsExtension returns true if the EPP server supports
// the extension specified by uri.
func (g *Greeting) SupportsExtension(uri string) bool {
if g == nil {
return false
}
for _, v := range g.Extensions {
if v == uri {
return true
}
}
return false
}
// EPP extension URNs
const (
ObjDomain = "urn:ietf:params:xml:ns:domain-1.0"
ObjHost = "urn:ietf:params:xml:ns:host-1.0"
ObjContact = "urn:ietf:params:xml:ns:contact-1.0"
ObjFinance = "http://www.unitedtld.com/epp/finance-1.0"
ExtSecDNS = "urn:ietf:params:xml:ns:secDNS-1.1"
ExtRGP = "urn:ietf:params:xml:ns:rgp-1.0"
ExtLaunch = "urn:ietf:params:xml:ns:launch-1.0"
ExtIDN = "urn:ietf:params:xml:ns:idn-1.0"
ExtCharge = "http://www.unitedtld.com/epp/charge-1.0"
ExtFee05 = "urn:ietf:params:xml:ns:fee-0.5"
ExtFee06 = "urn:ietf:params:xml:ns:fee-0.6"
ExtFee07 = "urn:ietf:params:xml:ns:fee-0.7"
ExtFee08 = "urn:ietf:params:xml:ns:fee-0.8"
ExtFee09 = "urn:ietf:params:xml:ns:fee-0.9"
ExtFee11 = "urn:ietf:params:xml:ns:fee-0.11"
ExtFee21 = "urn:ietf:params:xml:ns:fee-0.21"
ExtFee10 = "urn:ietf:params:xml:ns:epp:fee-1.0"
ExtPrice = "urn:ar:params:xml:ns:price-1.1"
ExtNamestore = "http://www.verisign-grs.com/epp/namestoreExt-1.1"
ExtNeulevel = "urn:ietf:params:xml:ns:neulevel"
ExtNeulevel10 = "urn:ietf:params:xml:ns:neulevel-1.0"
)
// ExtURNNames maps short extension names to their full URN.
var ExtURNNames = map[string]string{
"secDNS-1.1": ExtSecDNS,
"rgp-1.0": ExtRGP,
"launch-1.0": ExtLaunch,
"idn-1.0": ExtIDN,
"charge-1.0": ExtCharge,
"fee-0.5": ExtFee05,
"fee-0.6": ExtFee06,
"fee-0.7": ExtFee07,
"fee-0.8": ExtFee08,
"fee-0.9": ExtFee09,
"fee-0.11": ExtFee11,
"fee-0.21": ExtFee21,
"fee-1.0": ExtFee10,
"price-1.1": ExtPrice,
"namestoreExt-1.1": ExtNamestore,
"neulevel": ExtNeulevel,
"neulevel-1.0": ExtNeulevel10,
}
// TODO: check if res.Greeting is not empty.
func (c *Conn) readGreeting() (Greeting, error) {
res, err := c.readResponse()
if err != nil {
return Greeting{}, err
}
return res.Greeting, nil
}
func init() {
path := "epp>greeting"
scanResponse.MustHandleCharData(path+">svID", func(c *xx.Context) error {
res := c.Value.(*Response)
res.Greeting.ServerName = string(c.CharData)
return nil
})
scanResponse.MustHandleCharData(path+">svcMenu>version", func(c *xx.Context) error {
res := c.Value.(*Response)
res.Greeting.Versions = append(res.Greeting.Versions, string(c.CharData))
return nil
})
scanResponse.MustHandleCharData(path+">svcMenu>lang", func(c *xx.Context) error {
res := c.Value.(*Response)
res.Greeting.Languages = append(res.Greeting.Languages, string(c.CharData))
return nil
})
scanResponse.MustHandleCharData(path+">svcMenu>objURI", func(c *xx.Context) error {
res := c.Value.(*Response)
res.Greeting.Objects = append(res.Greeting.Objects, string(c.CharData))
return nil
})
scanResponse.MustHandleCharData(path+">svcMenu>svcExtension>extURI", func(c *xx.Context) error {
res := c.Value.(*Response)
res.Greeting.Extensions = append(res.Greeting.Extensions, string(c.CharData))
return nil
})
}