def get_stats(self): """ Get statistics of the current transport. Note that this method requires the xmpp library to be installed. @return: The IQ packet send back by the client @rtype: U{xmpp.protocol.Iq<http://xmpppy.sourceforge.net/apidocs/xmpp.protocol.Iq-class.html>} """ import xmpp interface = config_interface.config_interface(self) ns = "http://jabber.org/protocol/stats" nodes = [] for name in [ "uptime", "users/registered", "users/online", "contacts/online", "contacts/total", "messages/in", "messages/out", "memory-usage", ]: nodes.append(xmpp.simplexml.Node("stat", attrs={"name": name})) try: return interface.query(nodes, ns) except RuntimeError, e: raise RuntimeError("%s" % (e.message))
def register(self, jid, username, passwd, lang, enc, status): """ Register a user to the transport. @param jid: The JID of the user to be registered. @type jid: str @param username: The username of the user in the legacy network. @type username: str @param passwd: The password for the legacy network. @type passwd: str @param lang: The language code used by the user (e.g. 'en'). @type lang: str @param enc: The default character encoding (e.g. 'utf8'). @type enc: str @param status: The VIP status of the user: 1 if true, 0 if not @type status: str @raise RuntimeError: In case the command fails. """ interface = config_interface.config_interface(self) state = 'ADHOC_ADMIN_REGISTER_USER' fields = [('user_jid', 'text-single', jid), ('user_username', 'text-single', username), ('user_password', 'text-single', passwd), ('user_language', 'text-single', lang), ('user_encoding', 'text-single', enc), ('user_vip', 'text-single', status)] interface.command(state, fields) return 0
def register(self, jid, username, passwd, lang, enc, status): """ Register a user to the transport. @param jid: The JID of the user to be registered. @type jid: str @param username: The username of the user in the legacy network. @type username: str @param passwd: The password for the legacy network. @type passwd: str @param lang: The language code used by the user (e.g. 'en'). @type lang: str @param enc: The default character encoding (e.g. 'utf8'). @type enc: str @param status: The VIP status of the user: 1 if true, 0 if not @type status: str @raise RuntimeError: In case the command fails. """ interface = config_interface.config_interface(self) state = "ADHOC_ADMIN_REGISTER_USER" fields = [ ("user_jid", "text-single", jid), ("user_username", "text-single", username), ("user_password", "text-single", passwd), ("user_language", "text-single", lang), ("user_encoding", "text-single", enc), ("user_vip", "text-single", status), ] interface.command(state, fields) return 0
def unregister(self, jid): """ Unregister a user from the transport. @param jid: The JID to unregister @type jid: string @raise RuntimeError: In case the command fails. """ interface = config_interface.config_interface(self) state = 'ADHOC_ADMIN_UNREGISTER_USER' fields = [('user_jid', 'text-single', jid)] interface.command(state, fields) return 0
def unregister(self, jid): """ Unregister a user from the transport. @param jid: The JID to unregister @type jid: string @raise RuntimeError: In case the command fails. """ interface = config_interface.config_interface(self) state = "ADHOC_ADMIN_UNREGISTER_USER" fields = [("user_jid", "text-single", jid)] interface.command(state, fields) return 0
def message_all(self, message): """ Send a message to all users currently online. @param message: The message to send @type message: str @raise RuntimeError: In case the command fails. """ interface = config_interface.config_interface(self) state = 'ADHOC_ADMIN_SEND_MESSAGE' fields = [('message', 'text-multi', message)] interface.command(state, fields) return 0
def message_all(self, message): """ Send a message to all users currently online. @param message: The message to send @type message: str @raise RuntimeError: In case the command fails. """ interface = config_interface.config_interface(self) state = "ADHOC_ADMIN_SEND_MESSAGE" fields = [("message", "text-multi", message)] interface.command(state, fields) return 0
def set_vip_status(self, jid, state): """ Set the VIP status of a user. @param jid: The JID that should have its status set @type jid: str @param state: The state you want to set. This should be "0" for disabling VIP status and "1" for enabling it. Note that this argument really I{is} a string. @type state: str @raise RuntimeError: In case the command fails. """ interface = config_interface.config_interface(self) state = 'ADHOC_ADMIN_USER2' fields = [('user_jid', 'hidden', jid), ('user_vip', 'boolean', state)] interface.command(state, fields) return 0
def set_vip_status(self, jid, state): """ Set the VIP status of a user. @param jid: The JID that should have its status set @type jid: str @param state: The state you want to set. This should be "0" for disabling VIP status and "1" for enabling it. Note that this argument really I{is} a string. @type state: str @raise RuntimeError: In case the command fails. """ interface = config_interface.config_interface(self) state = "ADHOC_ADMIN_USER2" fields = [("user_jid", "hidden", jid), ("user_vip", "boolean", state)] interface.command(state, fields) return 0
def get_stats(self): """ Get statistics of the current transport. Note that this method requires the xmpp library to be installed. @return: The IQ packet send back by the client @rtype: U{xmpp.protocol.Iq<http://xmpppy.sourceforge.net/apidocs/xmpp.protocol.Iq-class.html>} """ import xmpp interface = config_interface.config_interface(self) ns = 'http://jabber.org/protocol/stats' nodes = [] for name in [ 'uptime', 'users/registered', 'users/online', 'contacts/online', 'contacts/total', 'messages/in', 'messages/out', 'memory-usage' ]: nodes.append(xmpp.simplexml.Node('stat', attrs={'name': name})) try: return interface.query(nodes, ns) except RuntimeError, e: raise RuntimeError("%s" % (e.message))