Class: EPP::Server
- Inherits:
-
Object
- Object
- EPP::Server
- Defined in:
- lib/epp-client/server.rb
Overview
Handles sending and receiving data to EPP servers. Supports new style EPP servers which include length of payloads in transmission.
Direct Known Subclasses
Constant Summary collapse
- DEFAULTS =
Default connection options
{ :port => 700, :compatibility => false, :lang => 'en', :version => '1.0', :extensions => [], :services => EPP::Client::DEFAULT_SERVICES, :address_family => nil }
- HEADER_LEN =
Receive frame header length
4
Instance Attribute Summary collapse
-
#DEFAULT_SERVICES ⇒ Object
deprecated
Deprecated.
please use EPP::Client::DEFAULT_SERVICES
Class Method Summary collapse
-
.const_missing(const_name) ⇒ Object
Handles emitting warnings for deprecated constants.
Instance Method Summary collapse
-
#connection { ... } ⇒ Object
EPP Server Connection.
-
#greeting ⇒ String
Return the greeting XML received during the last connection.
-
#hello ⇒ Boolean
Sends a Hello Request to the server.
-
#initialize(tag, passwd, host, options = {}) ⇒ Server
constructor
A new instance of Server.
-
#last_error ⇒ ResponseError
Return the error from the last login or logout request.
-
#last_request ⇒ Request
Return the Request object created by the last call to #request.
-
#last_response ⇒ Response
Return the Response object created by the last call to #request.
-
#options ⇒ Hash
Return the options the receiver was initialized with.
- #prepare_request(command, extension = nil) ⇒ EPP::Request
- #request(command, extension = nil) ⇒ Object
-
#with_login { ... } ⇒ Object
Runs a block while logged into the receiver.
Constructor Details
Instance Attribute Details
#DEFAULT_SERVICES ⇒ Object
please use EPP::Client::DEFAULT_SERVICES
Provided for legacy clients who might be using it. The constant has been moved into the EPP::Client class which is the primary client facing API.
|
# File 'lib/epp-client/server.rb', line 19
|
Class Method Details
.const_missing(const_name) ⇒ Object
Handles emitting warnings for deprecated constants.
32 33 34 35 36 37 38 39 40 |
# File 'lib/epp-client/server.rb', line 32 def self.const_missing(const_name) case const_name when :DEFAULT_SERVICES warn "EPP::Server::DEFAULT_SERVICES has been deprecated, please use EPP::Client::DEFAULT_SERVICES" EPP::Client::DEFAULT_SERVICES else super end end |
Instance Method Details
#connection { ... } ⇒ Object
EPP Server Connection
181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 |
# File 'lib/epp-client/server.rb', line 181 def connection @connection_errors = [] addrinfo.each do |_,port,_,addr,_,_,_| retried = false begin @conn = TCPSocket.new(addr, port) rescue Errno::EINVAL => e if retried = e..split(" - ")[1] raise Errno::EINVAL, "#{}: TCPSocket.new(#{addr.inspect}, #{port.inspect})" end retried = true retry end args = [@conn] args << [:ssl_context] if [:ssl_context] @sock = OpenSSL::SSL::SSLSocket.new(*args) @sock.sync_close = true begin @sock.connect @greeting = recv_frame # Perform initial recv return yield rescue Errno::ECONNREFUSED, Errno::ECONNRESET, Errno::EHOSTUNREACH => e @connection_errors << e next # try the next address in the list rescue OpenSSL::SSL::SSLError => e # Connection error, most likely the IP isn't in the allow list if e. =~ /returned=5 errno=0/ @connection_errors << ConnectionError.new("SSL Connection error, IP may not be permitted to connect to #{@host}", @conn.addr, @conn.peeraddr, e) next else raise e end ensure @sock.close # closes @conn @conn = @sock = nil end end # Should only get here if we didn't return from the block above addrinfo(true) # Update our addrinfo in case the DNS has changed raise @connection_errors.last unless @connection_errors.empty? raise Errno::EHOSTUNREACH, "Failed to connect to host #{@host}" end |
#greeting ⇒ String
Return the greeting XML received during the last connection
145 146 147 |
# File 'lib/epp-client/server.rb', line 145 def greeting @greeting end |
#hello ⇒ Boolean
Sends a Hello Request to the server
72 73 74 75 76 77 78 |
# File 'lib/epp-client/server.rb', line 72 def hello hello = EPP::Requests::Hello.new request = EPP::Request.new(hello) send_frame(request) return true if recv_frame =~ /<greeting>/ false end |
#last_error ⇒ ResponseError
Return the error from the last login or logout request
133 134 135 |
# File 'lib/epp-client/server.rb', line 133 def last_error @error end |
#last_request ⇒ Request
Return the Request object created by the last call to #request
121 122 123 |
# File 'lib/epp-client/server.rb', line 121 def last_request @req end |
#last_response ⇒ Response
Return the Response object created by the last call to #request
127 128 129 |
# File 'lib/epp-client/server.rb', line 127 def last_response @resp end |
#options ⇒ Hash
Return the options the receiver was initialized with
139 140 141 |
# File 'lib/epp-client/server.rb', line 139 def @options end |
#prepare_request(command, extension = nil) ⇒ EPP::Request
Primarily an internal method, exposed to enable testing
106 107 108 109 |
# File 'lib/epp-client/server.rb', line 106 def prepare_request(command, extension = nil) cmd = EPP::Requests::Command.new(req_tid, command, extension) EPP::Request.new(cmd) end |
#request(command, extension = nil) ⇒ Object
111 112 113 114 115 116 |
# File 'lib/epp-client/server.rb', line 111 def request(command, extension = nil) @req = command.is_a?(EPP::Request) ? command : prepare_request(command, extension) @resp = send_recv_frame(@req) end |
#with_login { ... } ⇒ Object
Runs a block while logged into the receiver
158 159 160 161 162 163 164 165 166 |
# File 'lib/epp-client/server.rb', line 158 def with_login login! begin yield ensure logout! end end |