ultraspeed-epp 1.0.6 → 1.0.7
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/epp/server.rb +48 -28
- metadata +1 -1
data/lib/epp/server.rb
CHANGED
@@ -2,7 +2,7 @@ module Epp #:nodoc:
|
|
2
2
|
class Server
|
3
3
|
include RequiresParameters
|
4
4
|
|
5
|
-
attr_accessor :tag, :password, :server, :port, :clTRID
|
5
|
+
attr_accessor :tag, :password, :server, :port, :clTRID, :old_server
|
6
6
|
|
7
7
|
# ==== Required Attrbiutes
|
8
8
|
#
|
@@ -14,14 +14,18 @@ module Epp #:nodoc:
|
|
14
14
|
#
|
15
15
|
# * <tt>:port</tt> - The EPP standard port is 700. However, you can choose a different port to use.
|
16
16
|
# * <tt>:clTRID</tt> - The client transaction identifier is an element that EPP specifies MAY be used to uniquely identify the command to the server. You are responsible for maintaining your own transaction identifier space to ensure uniqueness. Defaults to "ABC-12345"
|
17
|
+
# * <tt>:old_server</tt> - Set to true to read and write frames in a way that is compatible with old EPP servers. Default is false.
|
18
|
+
# * <tt>:lang</tt> - Set custom language attribute. Default is 'en'.
|
17
19
|
def initialize(attributes = {})
|
18
20
|
requires!(attributes, :tag, :password, :server)
|
19
21
|
|
20
|
-
@tag
|
21
|
-
@password
|
22
|
-
@server
|
23
|
-
@port
|
24
|
-
@clTRID
|
22
|
+
@tag = attributes[:tag]
|
23
|
+
@password = attributes[:password]
|
24
|
+
@server = attributes[:server]
|
25
|
+
@port = attributes[:port] || 700
|
26
|
+
@clTRID = attributes[:clTRID] || "ABC-12345"
|
27
|
+
@old_server = attributes[:old_server] || false
|
28
|
+
@lang = attributes[:lang] || 'en'
|
25
29
|
end
|
26
30
|
|
27
31
|
# Sends an XML request to the EPP server, and receives an XML response.
|
@@ -35,10 +39,10 @@ module Epp #:nodoc:
|
|
35
39
|
login
|
36
40
|
@response = send_request(xml)
|
37
41
|
ensure
|
38
|
-
logout
|
42
|
+
logout unless @old_server
|
39
43
|
close_connection
|
40
44
|
end
|
41
|
-
|
45
|
+
|
42
46
|
return @response
|
43
47
|
end
|
44
48
|
|
@@ -69,7 +73,7 @@ module Epp #:nodoc:
|
|
69
73
|
|
70
74
|
options = login.add_element("options")
|
71
75
|
options.add_element("version").text = "1.0"
|
72
|
-
options.add_element("lang").text =
|
76
|
+
options.add_element("lang").text = @lang
|
73
77
|
|
74
78
|
services = login.add_element("svcs")
|
75
79
|
services.add_element("objURI").text = "urn:ietf:params:xml:ns:domain-1.0"
|
@@ -80,10 +84,10 @@ module Epp #:nodoc:
|
|
80
84
|
|
81
85
|
# Receive the login response
|
82
86
|
response = Hpricot.XML(send_request(xml.to_s))
|
83
|
-
|
87
|
+
|
84
88
|
result_message = (response/"epp"/"response"/"result"/"msg").text.strip
|
85
89
|
result_code = (response/"epp"/"response"/"result").attr("code").to_i
|
86
|
-
|
90
|
+
|
87
91
|
if result_code == 1000
|
88
92
|
return true
|
89
93
|
else
|
@@ -154,30 +158,46 @@ module Epp #:nodoc:
|
|
154
158
|
# this method will wait until the connection becomes available for use. If
|
155
159
|
# the connection is broken, a SocketError will be raised. Otherwise,
|
156
160
|
# it will return a string containing the XML from the server.
|
157
|
-
def get_frame
|
158
|
-
|
161
|
+
def get_frame
|
162
|
+
if @old_server
|
163
|
+
data = ''
|
164
|
+
first_char = @socket.read(1)
|
165
|
+
if first_char.nil? and @socket.eof?
|
166
|
+
raise SocketError.new("Connection closed by remote server")
|
167
|
+
elsif first_char.nil?
|
168
|
+
raise SocketError.new("Error reading frame from remote server")
|
169
|
+
else
|
170
|
+
data << first_char
|
171
|
+
while char = @socket.read(1)
|
172
|
+
data << char
|
173
|
+
return data if data =~ %r|<\/epp>\n$|mi # at end
|
174
|
+
end
|
175
|
+
end
|
176
|
+
else
|
177
|
+
header = @socket.read(4)
|
159
178
|
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
179
|
+
if header.nil? and @socket.eof?
|
180
|
+
raise SocketError.new("Connection closed by remote server")
|
181
|
+
elsif header.nil?
|
182
|
+
raise SocketError.new("Error reading frame from remote server")
|
183
|
+
else
|
184
|
+
unpacked_header = header.unpack("N")
|
185
|
+
length = unpacked_header[0]
|
167
186
|
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
187
|
+
if length < 5
|
188
|
+
raise SocketError.new("Got bad frame header length of #{length} bytes from the server")
|
189
|
+
else
|
190
|
+
response = @socket.read(length - 4)
|
191
|
+
end
|
192
|
+
end
|
193
|
+
end
|
174
194
|
end
|
175
|
-
|
195
|
+
|
176
196
|
# Send an XML frame to the server. Should return the total byte
|
177
197
|
# size of the frame sent to the server. If the socket returns EOF,
|
178
198
|
# the connection has closed and a SocketError is raised.
|
179
199
|
def send_frame(xml)
|
180
|
-
|
200
|
+
@socket.write( @old_server ? (xml + "\r\n") : ([xml.size + 4].pack("N") + xml) )
|
181
201
|
end
|
182
202
|
end
|
183
203
|
end
|