Class: XMLRPC::BasicServer

Class | XMLRPC::BasicServer
In: | xmlrpc/server.rb
Parent: | Object

### Methods

add_handler add_introspection add_multicall get_default_handler get_service_hook new process set_default_handler set_service_hook

### Included Modules

ParserWriterChooseMixin ParseContentType

### Constants

ERR_METHOD_MISSING | = | 1
ERR_UNCAUGHT_EXCEPTION | = | 2
ERR_MC_WRONG_PARAM | = | 3
ERR_MC_MISSING_PARAMS | = | 4
ERR_MC_MISSING_METHNAME | = | 5
ERR_MC_RECURSIVE_CALL | = | 6
ERR_MC_WRONG_PARAM_PARAMS | = | 7
ERR_MC_EXPECTED_STRUCT | = | 8

### Public Class methods

new(class_delim=".")

[Source]

    # File xmlrpc/server.rb, line 170
      def initialize(class_delim=".")
        @handler = []
        @default_handler = nil
        @service_hook = nil

        @class_delim = class_delim
        @create = nil
        @parser = nil

        add_multicall     if Config::ENABLE_MULTICALL
        add_introspection if Config::ENABLE_INTROSPECTION
      end

### Public Instance methods

add_handler(prefix, obj_or_signature=nil, help=nil, &block)

[Source]

    # File xmlrpc/server.rb, line 183
      def add_handler(prefix, obj_or_signature=nil, help=nil, &block)
        if block_given?
          # proc-handler
          @handler << [prefix, block, obj_or_signature, help]
        else
          if prefix.kind_of? String
            # class-handler
            raise ArgumentError, "Expected non-nil value" if obj_or_signature.nil?
            @handler << [prefix + @class_delim, obj_or_signature]
          elsif prefix.kind_of? XMLRPC::Service::BasicInterface
            # class-handler with interface
            # add all methods
            @handler += prefix.get_methods(obj_or_signature, @class_delim)
          else
            raise ArgumentError, "Wrong type for parameter 'prefix'"
          end
        end
        self
      end

add_introspection()

[Source]

    # File xmlrpc/server.rb, line 263
      def add_introspection
        add_handler("system.listMethods",%w(array), "List methods available on this XML-RPC server") do
          methods = []
          @handler.each do |name, obj|
            if obj.kind_of? Proc
              methods << name
            else
              obj.methods.each {|meth| methods << name + meth}
            end
          end
          methods
        end

        add_handler("system.methodSignature", %w(array string), "Returns method signature") do |meth|
          sigs = []
          @handler.each do |name, obj, sig|
            if obj.kind_of? Proc and sig != nil and name == meth
              if sig[0].kind_of? Array
                # sig contains multiple signatures, e.g. [["array"], ["array", "string"]]
                sig.each {|s| sigs << s}
              else
                # sig is a single signature, e.g. ["array"]
                sigs << sig
              end
            end
          end
          sigs.uniq! || sigs  # remove eventually duplicated signatures
        end

        add_handler("system.methodHelp", %w(string string), "Returns help on using this method") do |meth|
          help = nil
          @handler.each do |name, obj, sig, hlp|
            if obj.kind_of? Proc and name == meth
              help = hlp
              break
            end
          end
          help || ""
        end

        self
      end

add_multicall()

[Source]

    # File xmlrpc/server.rb, line 221
      def add_multicall
        add_handler("system.multicall", %w(array array), "Multicall Extension") do |arrStructs|
          unless arrStructs.is_a? Array
            raise XMLRPC::FaultException.new(ERR_MC_WRONG_PARAM, "system.multicall expects an array")
          end

          arrStructs.collect {|call|
            if call.is_a? Hash
              methodName = call["methodName"]
              params     = call["params"]

              if params.nil?
                multicall_fault(ERR_MC_MISSING_PARAMS, "Missing params")
              elsif methodName.nil?
                multicall_fault(ERR_MC_MISSING_METHNAME, "Missing methodName")
              else
                if methodName == "system.multicall"
                  multicall_fault(ERR_MC_RECURSIVE_CALL, "Recursive system.multicall forbidden")
                else
                  unless params.is_a? Array
                    multicall_fault(ERR_MC_WRONG_PARAM_PARAMS, "Parameter params have to be an Array")
                  else
                    ok, val = call_method(methodName, *params)
                    if ok
                      # correct return value
                      [val]
                    else
                      # exception
                      multicall_fault(val.faultCode, val.faultString)
                    end
                  end
                end
              end

            else
              multicall_fault(ERR_MC_EXPECTED_STRUCT, "system.multicall expected struct")
            end
          }
        end # end add_handler
        self
      end

get_default_handler()

[Source]

    # File xmlrpc/server.rb, line 212
      def get_default_handler
        @default_handler
      end

get_service_hook()

[Source]

    # File xmlrpc/server.rb, line 203
      def get_service_hook
        @service_hook
      end

process(data)

[Source]

    # File xmlrpc/server.rb, line 308
      def process(data)
        method, params = parser().parseMethodCall(data)
        handle(method, *params)
      end

set_default_handler(&handler)

[Source]

    # File xmlrpc/server.rb, line 216
      def set_default_handler (&handler)
        @default_handler = handler
        self
      end

set_service_hook(&handler)

[Source]

    # File xmlrpc/server.rb, line 207
      def set_service_hook(&handler)
        @service_hook = handler
        self
      end

[Validate]