class Jabber::RPC::Server

XMLRPC Server

Public Class Methods

new(stream,class_delim=".") click to toggle source

new - creates a new server

Calls superclass method
# File lib/xmpp4r/rpc/helper/server.rb, line 24
def initialize(stream,class_delim=".")
  super(class_delim)
  @stream = stream
  @stream.add_iq_callback(120,"Helpers::RPCServer") { |iq|
    if iq.type == :set and iq.type != :result
      handle_iq(iq)
      true
    else
      false
    end
  }
end

Public Instance Methods

handle_iq(iq) click to toggle source

handles incoming iqs

iq
Jabber::IQ
  • the jabber iq

# File lib/xmpp4r/rpc/helper/server.rb, line 40
def handle_iq(iq)
  if iq.type == :set
    if iq.query.kind_of?(IqQueryRPC)
      data = iq.query
      response = IqQueryRPC.new
      data.elements.each { |rpc|
        if rpc
          response.typed_add(handle_rpc_requests(rpc))
        end
      }

      respiq = iq.answer(false)
      respiq.type = :result
      respiq.add(response)
      @stream.send(respiq)
    end
  end
end

Private Instance Methods

handle_rpc_requests(rpcdata) click to toggle source

handles the rpc requests

takes rpcdata
String
# File lib/xmpp4r/rpc/helper/server.rb, line 64
def handle_rpc_requests(rpcdata)
  resp = process(rpcdata.to_s)
  if resp == nil or resp.size <= 0
    raise Jabber::ErrorResponse.new(:forbidden)
  else
    return resp
  end
end