epp-client-base 0.11.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,150 @@
1
+ module EPPClient
2
+ module XML
3
+
4
+ attr_reader :sent_xml, :recv_xml, :msgQ_count, :msgQ_id, :trID
5
+
6
+ # Parses a frame and returns a Nokogiri::XML::Document.
7
+ def parse_xml(string) #:doc:
8
+ Nokogiri::XML::Document.parse(string) do |opts|
9
+ opts.options = 0
10
+ opts.noblanks
11
+ end
12
+ end
13
+ private :parse_xml
14
+
15
+ def recv_frame_to_xml #:nodoc:
16
+ @recv_xml = parse_xml(@recv_frame)
17
+ puts @recv_xml.to_s.gsub(/^/, '<< ') if debug
18
+ return @recv_xml
19
+ end
20
+
21
+ def sent_frame_to_xml #:nodoc:
22
+ @send_xml = parse_xml(@sent_frame)
23
+ puts @send_xml.to_s.gsub(/^/, '>> ') if debug
24
+ return @send_xml
25
+ end
26
+
27
+ def raw_builder(opts = {}) #:nodoc:
28
+ xml = Builder::XmlMarkup.new(opts)
29
+ yield xml
30
+ end
31
+
32
+ # creates a Builder::XmlMarkup object, mostly only used by +command+
33
+ def builder(opts = {})
34
+ raw_builder(opts) do |xml|
35
+ xml.instruct! :xml, :version =>"1.0", :encoding => "UTF-8"
36
+ xml.epp('xmlns' => EPPClient::SCHEMAS_URL['epp'], 'xmlns:epp' => EPPClient::SCHEMAS_URL['epp']) do
37
+ yield xml
38
+ end
39
+ end
40
+ end
41
+
42
+ # Takes a xml response and checks that the result is in the right range of
43
+ # results, that is, between 1000 and 1999, which are results meaning all
44
+ # went well.
45
+ #
46
+ # In case all went well, it either calls the callback if given, or returns
47
+ # true.
48
+ #
49
+ # In case there was a problem, an EPPErrorResponse exception is raised.
50
+ def get_result(args)
51
+ xml = case args
52
+ when Hash
53
+ args.delete(:xml)
54
+ else
55
+ xml = args
56
+ args = {}
57
+ xml
58
+ end
59
+
60
+ args[:range] ||= 1000..1999
61
+
62
+ if (mq = xml.xpath('epp:epp/epp:response/epp:msgQ', EPPClient::SCHEMAS_URL)).size > 0
63
+ @msgQ_count = mq.attribute('count').value.to_i
64
+ @msgQ_id = mq.attribute('id').value
65
+ puts "DEBUG: MSGQ : count=#{@msgQ_count}, id=#{@msgQ_id}\n" if debug
66
+ else
67
+ @msgQ_count = 0
68
+ @msgQ_id = nil
69
+ end
70
+
71
+ if (trID = xml.xpath('epp:epp/epp:response/epp:trID', EPPClient::SCHEMAS_URL)).size > 0
72
+ @trID = get_trid(trID)
73
+ end
74
+
75
+ res = xml.xpath('epp:epp/epp:response/epp:result', EPPClient::SCHEMAS_URL)
76
+ code = res.attribute('code').value.to_i
77
+ if args[:range].include?(code)
78
+ if args.key?(:callback)
79
+ case cb = args[:callback]
80
+ when Symbol
81
+ return send(cb, xml.xpath('epp:epp/epp:response', EPPClient::SCHEMAS_URL))
82
+ else
83
+ raise ArgumentError, "Invalid callback type"
84
+ end
85
+ else
86
+ return true
87
+ end
88
+ else
89
+ raise EPPClient::EPPErrorResponse.new(:xml => xml, :code => code, :message => res.xpath('epp:msg', EPPClient::SCHEMAS_URL).text)
90
+ end
91
+ end
92
+
93
+ def get_trid(xml)
94
+ {
95
+ :clTRID => xml.xpath('epp:clTRID', EPPClient::SCHEMAS_URL).text,
96
+ :svTRID => xml.xpath('epp:svTRID', EPPClient::SCHEMAS_URL).text,
97
+ }
98
+ end
99
+
100
+ # Creates the xml for the command.
101
+ #
102
+ # You can either pass a block to it, in that case, it's the command body,
103
+ # or a series of procs, the first one being the commands, the other ones
104
+ # being the extensions.
105
+ #
106
+ # command do |xml|
107
+ # xml.logout
108
+ # end
109
+ #
110
+ # or
111
+ #
112
+ # command(lambda do |xml|
113
+ # xml.logout
114
+ # end, lambda do |xml|
115
+ # xml.extension
116
+ # end)
117
+ def command(*args, &block)
118
+ builder do |xml|
119
+ xml.command do
120
+ if block_given?
121
+ yield xml
122
+ else
123
+ command = args.shift
124
+ command.call(xml)
125
+ args.each do |ext|
126
+ xml.extension do
127
+ ext.call(xml)
128
+ end
129
+ end
130
+ end
131
+ xml.clTRID(clTRID)
132
+ end
133
+ end
134
+ end
135
+
136
+ # Wraps the content in an epp:extension.
137
+ def extension
138
+ raw_builder do |xml|
139
+ xml.extension do
140
+ yield(xml)
141
+ end
142
+ end
143
+ end
144
+
145
+ # Insert xml2 in xml1 before pattern
146
+ def insert_extension(xml1, xml2, pattern = /<clTRID>/)
147
+ xml1.sub(pattern, "#{xml2}\\&")
148
+ end
149
+ end
150
+ end
@@ -0,0 +1,388 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+
3
+ <schema targetNamespace="urn:ietf:params:xml:ns:contact-1.0"
4
+ xmlns:contact="urn:ietf:params:xml:ns:contact-1.0"
5
+ xmlns:epp="urn:ietf:params:xml:ns:epp-1.0"
6
+ xmlns:eppcom="urn:ietf:params:xml:ns:eppcom-1.0"
7
+ xmlns="http://www.w3.org/2001/XMLSchema"
8
+ elementFormDefault="qualified">
9
+
10
+ <!--
11
+ Import common element types.
12
+ -->
13
+ <import namespace="urn:ietf:params:xml:ns:eppcom-1.0"/>
14
+ <import namespace="urn:ietf:params:xml:ns:epp-1.0"/>
15
+
16
+ <annotation>
17
+ <documentation>
18
+ Extensible Provisioning Protocol v1.0
19
+ contact provisioning schema.
20
+ </documentation>
21
+ </annotation>
22
+
23
+ <!--
24
+ Child elements found in EPP commands.
25
+ -->
26
+ <element name="check" type="contact:mIDType"/>
27
+ <element name="create" type="contact:createType"/>
28
+ <element name="delete" type="contact:sIDType"/>
29
+ <element name="info" type="contact:authIDType"/>
30
+ <element name="transfer" type="contact:authIDType"/>
31
+ <element name="update" type="contact:updateType"/>
32
+
33
+ <!--
34
+ Utility types.
35
+ -->
36
+ <simpleType name="ccType">
37
+ <restriction base="token">
38
+ <length value="2"/>
39
+ </restriction>
40
+ </simpleType>
41
+
42
+ <complexType name="e164Type">
43
+ <simpleContent>
44
+ <extension base="contact:e164StringType">
45
+ <attribute name="x" type="token"/>
46
+ </extension>
47
+ </simpleContent>
48
+ </complexType>
49
+
50
+ <simpleType name="e164StringType">
51
+ <restriction base="token">
52
+ <pattern value="(\+[0-9]{1,3}\.[0-9]{1,14})?"/>
53
+ <maxLength value="17"/>
54
+ </restriction>
55
+ </simpleType>
56
+
57
+ <simpleType name="pcType">
58
+ <restriction base="token">
59
+ <maxLength value="16"/>
60
+ </restriction>
61
+ </simpleType>
62
+
63
+ <simpleType name="postalLineType">
64
+ <restriction base="normalizedString">
65
+ <minLength value="1"/>
66
+ <maxLength value="255"/>
67
+ </restriction>
68
+ </simpleType>
69
+
70
+ <simpleType name="optPostalLineType">
71
+ <restriction base="normalizedString">
72
+ <maxLength value="255"/>
73
+ </restriction>
74
+ </simpleType>
75
+
76
+ <!--
77
+ Child elements of the <create> command.
78
+ -->
79
+ <complexType name="createType">
80
+ <sequence>
81
+ <element name="id" type="eppcom:clIDType"/>
82
+ <element name="postalInfo" type="contact:postalInfoType"
83
+ maxOccurs="2"/>
84
+ <element name="voice" type="contact:e164Type"
85
+ minOccurs="0"/>
86
+ <element name="fax" type="contact:e164Type"
87
+ minOccurs="0"/>
88
+ <element name="email" type="eppcom:minTokenType"/>
89
+ <element name="authInfo" type="contact:authInfoType"/>
90
+ <element name="disclose" type="contact:discloseType"
91
+ minOccurs="0"/>
92
+ </sequence>
93
+ </complexType>
94
+
95
+ <complexType name="postalInfoType">
96
+ <sequence>
97
+ <element name="name" type="contact:postalLineType"/>
98
+ <element name="org" type="contact:optPostalLineType"
99
+ minOccurs="0"/>
100
+ <element name="addr" type="contact:addrType"/>
101
+ </sequence>
102
+ <attribute name="type" type="contact:postalInfoEnumType"
103
+ use="required"/>
104
+ </complexType>
105
+
106
+ <simpleType name="postalInfoEnumType">
107
+ <restriction base="token">
108
+ <enumeration value="loc"/>
109
+ <enumeration value="int"/>
110
+ </restriction>
111
+ </simpleType>
112
+
113
+ <complexType name="addrType">
114
+ <sequence>
115
+ <element name="street" type="contact:optPostalLineType"
116
+ minOccurs="0" maxOccurs="3"/>
117
+ <element name="city" type="contact:postalLineType"/>
118
+ <element name="sp" type="contact:optPostalLineType"
119
+ minOccurs="0"/>
120
+ <element name="pc" type="contact:pcType"
121
+ minOccurs="0"/>
122
+ <element name="cc" type="contact:ccType"/>
123
+ </sequence>
124
+ </complexType>
125
+
126
+ <complexType name="authInfoType">
127
+ <choice>
128
+ <element name="pw" type="eppcom:pwAuthInfoType"/>
129
+ <element name="ext" type="eppcom:extAuthInfoType"/>
130
+ </choice>
131
+ </complexType>
132
+
133
+ <complexType name="discloseType">
134
+ <sequence>
135
+ <element name="name" type="contact:intLocType"
136
+ minOccurs="0" maxOccurs="2"/>
137
+ <element name="org" type="contact:intLocType"
138
+ minOccurs="0" maxOccurs="2"/>
139
+ <element name="addr" type="contact:intLocType"
140
+ minOccurs="0" maxOccurs="2"/>
141
+ <element name="voice" minOccurs="0"/>
142
+ <element name="fax" minOccurs="0"/>
143
+ <element name="email" minOccurs="0"/>
144
+ </sequence>
145
+ <attribute name="flag" type="boolean" use="required"/>
146
+ </complexType>
147
+
148
+ <complexType name="intLocType">
149
+ <attribute name="type" type="contact:postalInfoEnumType"
150
+ use="required"/>
151
+ </complexType>
152
+
153
+ <!--
154
+ Child element of commands that require only an identifier.
155
+ -->
156
+ <complexType name="sIDType">
157
+ <sequence>
158
+ <element name="id" type="eppcom:clIDType"/>
159
+ </sequence>
160
+ </complexType>
161
+
162
+ <!--
163
+ Child element of commands that accept multiple identifiers.
164
+ -->
165
+ <complexType name="mIDType">
166
+ <sequence>
167
+ <element name="id" type="eppcom:clIDType"
168
+ maxOccurs="unbounded"/>
169
+ </sequence>
170
+ </complexType>
171
+
172
+ <!--
173
+ Child elements of the <info> and <transfer> commands.
174
+ -->
175
+ <complexType name="authIDType">
176
+ <sequence>
177
+ <element name="id" type="eppcom:clIDType"/>
178
+ <element name="authInfo" type="contact:authInfoType"
179
+ minOccurs="0"/>
180
+ </sequence>
181
+ </complexType>
182
+
183
+ <!--
184
+ Child elements of the <update> command.
185
+ -->
186
+ <complexType name="updateType">
187
+ <sequence>
188
+ <element name="id" type="eppcom:clIDType"/>
189
+ <element name="add" type="contact:addRemType"
190
+ minOccurs="0"/>
191
+ <element name="rem" type="contact:addRemType"
192
+ minOccurs="0"/>
193
+ <element name="chg" type="contact:chgType"
194
+ minOccurs="0"/>
195
+ </sequence>
196
+ </complexType>
197
+
198
+ <!--
199
+ Data elements that can be added or removed.
200
+ -->
201
+ <complexType name="addRemType">
202
+ <sequence>
203
+ <element name="status" type="contact:statusType"
204
+ maxOccurs="7"/>
205
+ </sequence>
206
+ </complexType>
207
+
208
+ <!--
209
+ Data elements that can be changed.
210
+ -->
211
+ <complexType name="chgType">
212
+ <sequence>
213
+ <element name="postalInfo" type="contact:chgPostalInfoType"
214
+ minOccurs="0" maxOccurs="2"/>
215
+ <element name="voice" type="contact:e164Type"
216
+ minOccurs="0"/>
217
+ <element name="fax" type="contact:e164Type"
218
+ minOccurs="0"/>
219
+ <element name="email" type="eppcom:minTokenType"
220
+ minOccurs="0"/>
221
+ <element name="authInfo" type="contact:authInfoType"
222
+ minOccurs="0"/>
223
+ <element name="disclose" type="contact:discloseType"
224
+ minOccurs="0"/>
225
+ </sequence>
226
+ </complexType>
227
+
228
+ <complexType name="chgPostalInfoType">
229
+ <sequence>
230
+ <element name="name" type="contact:postalLineType"
231
+ minOccurs="0"/>
232
+ <element name="org" type="contact:optPostalLineType"
233
+ minOccurs="0"/>
234
+ <element name="addr" type="contact:addrType"
235
+ minOccurs="0"/>
236
+ </sequence>
237
+ <attribute name="type" type="contact:postalInfoEnumType"
238
+ use="required"/>
239
+ </complexType>
240
+
241
+ <!--
242
+ Child response elements.
243
+ -->
244
+ <element name="chkData" type="contact:chkDataType"/>
245
+ <element name="creData" type="contact:creDataType"/>
246
+ <element name="infData" type="contact:infDataType"/>
247
+ <element name="panData" type="contact:panDataType"/>
248
+ <element name="trnData" type="contact:trnDataType"/>
249
+
250
+ <!--
251
+ <check> response elements.
252
+ -->
253
+ <complexType name="chkDataType">
254
+ <sequence>
255
+ <element name="cd" type="contact:checkType"
256
+ maxOccurs="unbounded"/>
257
+ </sequence>
258
+ </complexType>
259
+
260
+ <complexType name="checkType">
261
+ <sequence>
262
+ <element name="id" type="contact:checkIDType"/>
263
+ <element name="reason" type="eppcom:reasonType"
264
+ minOccurs="0"/>
265
+ </sequence>
266
+ </complexType>
267
+
268
+ <complexType name="checkIDType">
269
+ <simpleContent>
270
+ <extension base="eppcom:clIDType">
271
+ <attribute name="avail" type="boolean"
272
+ use="required"/>
273
+ </extension>
274
+ </simpleContent>
275
+ </complexType>
276
+
277
+ <!--
278
+ <create> response elements.
279
+ -->
280
+ <complexType name="creDataType">
281
+ <sequence>
282
+ <element name="id" type="eppcom:clIDType"/>
283
+ <element name="crDate" type="dateTime"/>
284
+ </sequence>
285
+ </complexType>
286
+
287
+ <!--
288
+ <info> response elements.
289
+ -->
290
+ <complexType name="infDataType">
291
+ <sequence>
292
+ <element name="id" type="eppcom:clIDType"/>
293
+ <element name="roid" type="eppcom:roidType"/>
294
+ <element name="status" type="contact:statusType"
295
+ maxOccurs="7"/>
296
+ <element name="postalInfo" type="contact:postalInfoType"
297
+ maxOccurs="2"/>
298
+ <element name="voice" type="contact:e164Type"
299
+ minOccurs="0"/>
300
+ <element name="fax" type="contact:e164Type"
301
+ minOccurs="0"/>
302
+ <element name="email" type="eppcom:minTokenType"/>
303
+ <element name="clID" type="eppcom:clIDType"/>
304
+ <element name="crID" type="eppcom:clIDType"/>
305
+ <element name="crDate" type="dateTime"/>
306
+ <element name="upID" type="eppcom:clIDType"
307
+ minOccurs="0"/>
308
+ <element name="upDate" type="dateTime"
309
+ minOccurs="0"/>
310
+ <element name="trDate" type="dateTime"
311
+ minOccurs="0"/>
312
+ <element name="authInfo" type="contact:authInfoType"
313
+ minOccurs="0"/>
314
+ <element name="disclose" type="contact:discloseType"
315
+ minOccurs="0"/>
316
+ </sequence>
317
+ </complexType>
318
+
319
+ <!--
320
+ Status is a combination of attributes and an optional human-readable
321
+ message that may be expressed in languages other than English.
322
+ -->
323
+ <complexType name="statusType">
324
+ <simpleContent>
325
+ <extension base="normalizedString">
326
+ <attribute name="s" type="contact:statusValueType"
327
+ use="required"/>
328
+ <attribute name="lang" type="language"
329
+ default="en"/>
330
+ </extension>
331
+ </simpleContent>
332
+ </complexType>
333
+
334
+ <simpleType name="statusValueType">
335
+ <restriction base="token">
336
+ <enumeration value="clientDeleteProhibited"/>
337
+ <enumeration value="clientTransferProhibited"/>
338
+ <enumeration value="clientUpdateProhibited"/>
339
+ <enumeration value="linked"/>
340
+ <enumeration value="ok"/>
341
+ <enumeration value="pendingCreate"/>
342
+ <enumeration value="pendingDelete"/>
343
+ <enumeration value="pendingTransfer"/>
344
+ <enumeration value="pendingUpdate"/>
345
+ <enumeration value="serverDeleteProhibited"/>
346
+ <enumeration value="serverTransferProhibited"/>
347
+ <enumeration value="serverUpdateProhibited"/>
348
+ </restriction>
349
+ </simpleType>
350
+
351
+ <!--
352
+ Pending action notification response elements.
353
+ -->
354
+ <complexType name="panDataType">
355
+ <sequence>
356
+ <element name="id" type="contact:paCLIDType"/>
357
+ <element name="paTRID" type="epp:trIDType"/>
358
+ <element name="paDate" type="dateTime"/>
359
+ </sequence>
360
+ </complexType>
361
+
362
+ <complexType name="paCLIDType">
363
+ <simpleContent>
364
+ <extension base="eppcom:clIDType">
365
+ <attribute name="paResult" type="boolean"
366
+ use="required"/>
367
+ </extension>
368
+ </simpleContent>
369
+ </complexType>
370
+
371
+ <!--
372
+ <transfer> response elements.
373
+ -->
374
+ <complexType name="trnDataType">
375
+ <sequence>
376
+ <element name="id" type="eppcom:clIDType"/>
377
+ <element name="trStatus" type="eppcom:trStatusType"/>
378
+ <element name="reID" type="eppcom:clIDType"/>
379
+ <element name="reDate" type="dateTime"/>
380
+ <element name="acID" type="eppcom:clIDType"/>
381
+ <element name="acDate" type="dateTime"/>
382
+ </sequence>
383
+ </complexType>
384
+
385
+ <!--
386
+ End of schema.
387
+ -->
388
+ </schema>