Skip to content

Instantly share code, notes, and snippets.

@primalmotion
Created July 24, 2011 16:53
Show Gist options
  • Select an option

  • Save primalmotion/1102814 to your computer and use it in GitHub Desktop.

Select an option

Save primalmotion/1102814 to your computer and use it in GitHub Desktop.
def iq_users_list(self, iq):
"""
List all registered users.
@type iq: xmpp.Protocol.Iq
@param iq: the received IQ
@rtype: xmpp.Protocol.Iq
@return: a ready to send IQ containing the result of the action
"""
try:
reply = iq.buildReply("result")
server = self.entity.jid.getDomain()
answer = self.xmlrpc_server.registered_users({"host": server})
nodes = []
users = answer["users"]
for user in users:
entity_type = "human"
try:
answer = self.xmlrpc_server.get_vcard({"host": server, "user": user["username"], "name" : "ROLE"})
if answer["content"] in ("hypervisor", "virtualmachine"):
entity_type = answer["content"]
except:
pass
nodes.append(xmpp.Node("user", attrs={"jid": "%s@%s" % (user["username"], server), "type": entity_type}))
self.entity.push_change("xmppserver:users", "listfetched", content_node=xmpp.Node("users", payload=nodes))
reply.setQueryPayload(nodes)
except Exception as ex:
reply = build_error_iq(self, ex, iq, ARCHIPEL_ERROR_CODE_XMPPSERVER_USERS_LIST)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment