def query_handler(self, success, element): if not success: return for message in element.named("message").with_attrs("from"): sender = JID(message.get_attr("from")) room_jid = sender.bare() chat_type = message.get_attr("type") if chat_type == "groupchat": attrs = dict(type=chat_type) to = room_jid else: attrs = dict() to = sender if room_jid not in self.xmpp.muc.rooms: return if room_jid == self.service_room: room_jid = None else: room_jid = unicode(room_jid) for jid in self.xmpp.muc.rooms: for room in self.xmpp.muc.rooms[jid]: if room.nick_jid == sender: return if message.children("event"): self.event_parser(element, to, room_jid, **attrs) elif message.children("body"): self.command_parser(element, to, room_jid, **attrs)
def xmpp_to_log(inner, self, own_jid, participants): in_room = set() for participant in participants: in_room.add(participant.name.resource) event = self.joined(participant.name) inner.send(event) while True: elements = yield inner for message in elements: sender = JID(elements.get_attr("from")) if sender == own_jid: continue if sender.resource is None: continue resource = sender.resource.encode("unicode-escape") bare = unicode(sender.bare()).encode("unicode-escape") type = message.get_attr("type", None) if type == "unavailable": if sender.resource in in_room: in_room.discard(sender.resource) self.log.info("* %s left the room %s.", resource, bare) #clear event event = events.Event() event.add('id', sender.resource) inner.send(event) else: if sender.resource not in in_room: in_room.add(sender.resource) self.log.info("* %s entered the room %s.", sender.resource, bare) event = self.joined(sender) inner.send(event)
def xmpp_to_log(inner, self, own_jid, room): while True: elements = yield inner for message in elements.with_attrs("from"): print message.serialize() sender = JID(elements.get_attr("from")) if sender == own_jid: continue if sender.resource is None: continue resource = sender.resource.encode("unicode-escape") bare = unicode(sender.bare()).encode("unicode-escape") for event in message.children("event"): event = events.Event.from_element(event) self.log.info("<%s> %s", unicode(sender).encode("unicode-escape"), event)
def handle_iq(self, iq, payload): if not iq.with_attrs("from", type="set"): return False jid = JID(iq.get_attr("from")) if jid.bare() != self.room.room_jid: return False if not payload.named("start").with_attrs("id"): return False service_id = payload.get_attr("id") try: try: result = self._start(jid, service_id, payload) except SessionError: raise except: _, exc, tb = sys.exc_info() raise SessionError("Session handling failed: " + repr(exc)) except SessionError, se: msg = se.args[0] error = self.xmpp.core.build_error("cancel", "session-failure", msg) self.xmpp.core.iq_error(iq, error)