Class: EPP::Server

Inherits:
Object
  • Object
show all
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

OldServer

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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(tag, passwd, host, options = {}) ⇒ Server

Returns a new instance of Server.

Parameters:

  • tag (String)

    EPP Tag

  • passwd (String)

    EPP Tag password

  • host (String)

    EPP Server address

  • options (Hash) (defaults to: {})

    configuration options

Options Hash (options):

  • :port (Integer)

    EPP Port number, default 700

  • :compatibility (Boolean)

    Compatibility mode, default false

  • :lang (String)

    EPP Language code, default ‘en’

  • :version (String)

    EPP protocol version, default ‘1.0’

  • :extensions (Array<String>)

    EPP Extension URNs

  • :services (Array<String>)

    EPP Service URNs

  • :address_family (String)

    ‘AF_INET’ or ‘AF_INET6’ or either of the appropriate socket constants. Will cause connections to be limited to this address family. Default try all addresses.



63
64
65
66
# File 'lib/epp-client/server.rb', line 63

def initialize(tag, passwd, host, options = {})
  @tag, @passwd, @host = tag, passwd, host
  @options = DEFAULTS.merge(options)
end

Instance Attribute Details

#DEFAULT_SERVICESObject

Deprecated.

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.

Parameters:

  • const_name (Symbol)

    Name of the missing constant

See Also:

  • Module.const_missing


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

Examples:

typical usage

connection do
  # .. do stuff with logged in session ..
end

usage with with_login

connection do
   do
    # .. do stuff with logged in session ..
  end
end

Yields:

  • connected session

Raises:

  • (Errno::EHOSTUNREACH)


179
180
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
# File 'lib/epp-client/server.rb', line 179

def connection
  @connection_errors = []
  addrinfo.each do |_,port,_,addr,_,_,_|
    retried = false
    begin
      @conn = TCPSocket.new(addr, port)
    rescue Errno::EINVAL => e
      if retried
        message = e.message.split(" - ")[1]
        raise Errno::EINVAL, "#{message}: TCPSocket.new(#{addr.inspect}, #{port.inspect})"
      end

      retried = true
      retry
    end

    @sock = OpenSSL::SSL::SSLSocket.new(@conn)
    @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.message =~ /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

#greetingString

Return the greeting XML received during the last connection

Returns:

  • (String)


143
144
145
# File 'lib/epp-client/server.rb', line 143

def greeting
  @greeting
end

#helloBoolean

Sends a Hello Request to the server

Returns:

  • (Boolean)

    True if greeting was returned



70
71
72
73
74
75
76
# File 'lib/epp-client/server.rb', line 70

def hello
  hello   = EPP::Requests::Hello.new
  request = EPP::Request.new(hello)
  send_frame(request)
  return true if recv_frame =~ /<greeting>/
  false
end

#last_errorResponseError

Return the error from the last login or logout request

Returns:



131
132
133
# File 'lib/epp-client/server.rb', line 131

def last_error
  @error
end

#last_requestRequest

Return the Request object created by the last call to #request

Returns:

  • (Request)

    Last created EPP Request object



119
120
121
# File 'lib/epp-client/server.rb', line 119

def last_request
  @req
end

#last_responseResponse

Return the Response object created by the last call to #request

Returns:

  • (Response)

    Last created EPP Response object



125
126
127
# File 'lib/epp-client/server.rb', line 125

def last_response
  @resp
end

#optionsHash

Return the options the receiver was initialized with

Returns:

  • (Hash)

    configuration options



137
138
139
# File 'lib/epp-client/server.rb', line 137

def options
  @options
end

#prepare_request(command, extension = nil) ⇒ EPP::Request

Note:

Primarily an internal method, exposed to enable testing

Parameters:

  • []

    command

  • []

    extension

Returns:

See Also:



104
105
106
107
# File 'lib/epp-client/server.rb', line 104

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



109
110
111
112
113
114
# File 'lib/epp-client/server.rb', line 109

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

Examples:

typical usage

connection do
   do
    # .. do stuff with logged in session ..
  end
end

Yields:

  • logged in EPP server session



156
157
158
159
160
161
162
163
164
# File 'lib/epp-client/server.rb', line 156

def 
  login!

  begin
    yield
  ensure
    logout!
  end
end