Methods
A
C
D
G
H
M
N
P
S
Included Modules
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
 
Class Public methods
new(class_delim=".")
# File ../ruby/lib/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
Instance Public methods
add_handler(prefix, obj_or_signature=nil, help=nil, &block)
# File ../ruby/lib/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()
# File ../ruby/lib/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.class.public_instance_methods(false).each do |meth|
          methods << "#{name}#{meth}"
        end
      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()
# File ../ruby/lib/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()
# File ../ruby/lib/xmlrpc/server.rb, line 212
def get_default_handler
  @default_handler
end
get_service_hook()
# File ../ruby/lib/xmlrpc/server.rb, line 203
def get_service_hook
  @service_hook
end
process(data)
# File ../ruby/lib/xmlrpc/server.rb, line 310
def process(data)
  method, params = parser().parseMethodCall(data)
  handle(method, *params)
end
set_default_handler(&handler)
# File ../ruby/lib/xmlrpc/server.rb, line 216
def set_default_handler (&handler)
  @default_handler = handler
  self
end
set_service_hook(&handler)
# File ../ruby/lib/xmlrpc/server.rb, line 207
def set_service_hook(&handler)
  @service_hook = handler
  self
end
Instance Private methods
call_method(methodname, *args)
# File ../ruby/lib/xmlrpc/server.rb, line 366
def call_method(methodname, *args)
  begin
    [true, dispatch(methodname, *args)]
  rescue XMLRPC::FaultException => e
    [false, e]
  rescue Exception => e
    [false, XMLRPC::FaultException.new(ERR_UNCAUGHT_EXCEPTION, "Uncaught exception #{e.message} in method #{methodname}")]
  end
end
check_arity(obj, n_args)

returns true, if the arity of “obj” matches

# File ../ruby/lib/xmlrpc/server.rb, line 354
def check_arity(obj, n_args)
  ary = obj.arity

  if ary >= 0
    n_args == ary
  else
    n_args >= (ary+1).abs
  end
end
dispatch(methodname, *args)

method dispatch

# File ../ruby/lib/xmlrpc/server.rb, line 324
def dispatch(methodname, *args)
  for name, obj in @handler
    if obj.kind_of? Proc
      next unless methodname == name
    else
      next unless methodname =~ /^#{name}(.+)$/
      next unless obj.respond_to? $1
      obj = obj.method($1)
    end

    if check_arity(obj, args.size)
      if @service_hook.nil?
        return obj.call(*args)
      else
        return @service_hook.call(obj, *args)
      end
    end
  end

  if @default_handler.nil?
    raise XMLRPC::FaultException.new(ERR_METHOD_MISSING, "Method #{methodname} missing or wrong number of parameters!")
  else
    @default_handler.call(methodname, *args)
  end
end
handle(methodname, *args)
# File ../ruby/lib/xmlrpc/server.rb, line 379
def handle(methodname, *args)
  create().methodResponse(*call_method(methodname, *args))
end
multicall_fault(nr, str)
# File ../ruby/lib/xmlrpc/server.rb, line 317
def multicall_fault(nr, str)
  {"faultCode" => nr, "faultString" => str}
end