# XMLRPC::Server (Class)

In: | xmlrpc/server.rb
Parent: | BasicServer

## Methods

get_valid_ip ip_auth_handler new request_handler serve set_valid_ip shutdown

## Public Class methods

new(port=8080, host="127.0.0.1", maxConnections=4, stdlog=$stdout, audit=true, debug=true, *a)

[Source]

    # File xmlrpc/server.rb, line 646
      def initialize(port=8080, host="127.0.0.1", maxConnections=4, stdlog=$stdout, audit=true, debug=true, *a)
        super(*a)
        @server = ::HttpServer.new(self, port, host, maxConnections, stdlog, audit, debug)
        @valid_ip = nil
      end

## Public Instance methods

serve()

[Source]

    # File xmlrpc/server.rb, line 652
      def serve
        if RUBY_PLATFORM =~ /mingw|mswin32/
          signal = 1
        else
          signal = "HUP"
        end
        trap(signal) { @server.shutdown }

        @server.start.join
      end

shutdown()

[Source]

    # File xmlrpc/server.rb, line 663
      def shutdown
        @server.shutdown
      end

set_valid_ip(*ip_addr)

[Source]

    # File xmlrpc/server.rb, line 667
      def set_valid_ip(*ip_addr)
        if ip_addr.size == 1 and ip_addr[0].nil?
          @valid_ip = nil
        else
          @valid_ip = ip_addr
        end
      end

get_valid_ip()

[Source]

    # File xmlrpc/server.rb, line 675
      def get_valid_ip
        @valid_ip
      end

request_handler(request, response)

methods that get called by HttpServer ——————————————

[Source]

    # File xmlrpc/server.rb, line 681
      def request_handler(request, response)
        $stderr.puts "in request_handler" if $DEBUG

        if request.method != "POST"
          # Method not allowed

          response.status = 405
          return
        end

        if parse_content_type(request.header['Content-type']).first != "text/xml"
          # Bad request

          response.status = 400
          return
        end

        length = request.content_length || 0

        unless length > 0
          # Length required

          response.status = 411
          return
        end

        data = request.data.read(length)

        if data.nil? or data.size != length
          # Bad request

          response.status = 400
          return
        end

        resp = process(data)
        raise if resp.nil? or resp.size <= 0  # => Internal Server Error

        response.status = 200
        response.header['Content-Length'] = resp.size
        response.header['Content-Type']   = "text/xml"
        response.body = resp

       end

ip_auth_handler(io)

Is called before request_handler and should return true if the client is allowed to connect to the server. `io’ is a Socket object.

[Source]

    # File xmlrpc/server.rb, line 726
       def ip_auth_handler(io)
         if @valid_ip
           client_ip = io.peeraddr[3]
           @valid_ip.each { |ip|
             return true if client_ip =~ ip
           }
           false
         else
           true
         end
       end

[Validate]