def _call_remote(self, pto, pmethod, callback, *arguments): iq = self._client.plugin['xep_0009'].make_iq_method_call(pto, pmethod, py2xml(*arguments)) pid = iq['id'] if callback is None: future = Future() self._register_callback(pid, future) iq.send() return future.get_value(30) else: log.debug("[RemoteSession] _call_remote %s" % callback) self._register_callback(pid, callback) iq.send()
def _on_jabber_rpc_method_call(self, iq): iq.enable('rpc_query') params = iq['rpc_query']['method_call']['params'] args = xml2py(params) pmethod = iq['rpc_query']['method_call']['method_name'] try: with self._lock: entry = self._entries[pmethod] rules = self._acls[entry.get_endpoint_FQN()] if ACL.check(rules, iq['from'], pmethod): return_value = entry.call_method(args) else: raise AuthorizationException( "Unauthorized access to %s from %s!" % (pmethod, iq['from'])) if return_value is None: return_value = () response = self._client.plugin['xep_0009'].make_iq_method_response( iq['id'], iq['from'], py2xml(*return_value)) response.send() except InvocationException as ie: fault = dict() fault['code'] = 500 fault['string'] = ie.get_message() self._client.plugin['xep_0009']._send_fault(iq, fault2xml(fault)) except AuthorizationException as ae: log.error(ae.get_message()) error = self._client.plugin['xep_0009']._forbidden(iq) error.send() except Exception as e: if isinstance(e, KeyError): log.error("No handler available for %s!" % pmethod) error = self._client.plugin['xep_0009']._item_not_found(iq) else: traceback.print_exc(file=sys.stderr) log.error( "An unexpected problem occurred invoking method %s!" % pmethod) error = self._client.plugin['xep_0009']._undefined_condition( iq) #! print "[REMOTE.PY] _handle_remote_procedure_call AN ERROR SHOULD BE SENT NOW %s " % e error.send()
def _on_jabber_rpc_method_call(self, iq): iq.enable("rpc_query") params = iq["rpc_query"]["method_call"]["params"] args = xml2py(params) pmethod = iq["rpc_query"]["method_call"]["method_name"] try: with self._lock: entry = self._entries[pmethod] rules = self._acls[entry.get_endpoint_FQN()] if ACL.check(rules, iq["from"], pmethod): return_value = entry.call_method(args) else: raise AuthorizationException("Unauthorized access to %s from %s!" % (pmethod, iq["from"])) if return_value is None: return_value = () response = self._client.plugin["xep_0009"].make_iq_method_response( iq["id"], iq["from"], py2xml(*return_value) ) response.send() except InvocationException as ie: fault = dict() fault["code"] = 500 fault["string"] = ie.get_message() self._client.plugin["xep_0009"]._send_fault(iq, fault2xml(fault)) except AuthorizationException as ae: log.error(ae.get_message()) error = self._client.plugin["xep_0009"]._forbidden(iq) error.send() except Exception as e: if isinstance(e, KeyError): log.error("No handler available for %s!", pmethod) error = self._client.plugin["xep_0009"]._item_not_found(iq) else: traceback.print_exc(file=sys.stderr) log.error("An unexpected problem occurred invoking method %s!", pmethod) error = self._client.plugin["xep_0009"]._undefined_condition(iq) #! print "[REMOTE.PY] _handle_remote_procedure_call AN ERROR SHOULD BE SENT NOW %s " % e error.send()