def recv_component(self,m): global s t = xml.etree.ElementTree.fromstring(m) mid = t.attrib['id'] mfrom = t.attrib['from'] qtag = t.find('*') if qtag == None: return if qtag.tag == xmpp.utils.nt(ns.HTTP_DINFO,ns.TAG_QUERY): if t.tag != xmpp.utils.nt(ns.JABBER_CLIENT,ns.TAG_IQ): return icateg = "conference" itype = "text" iname = "Chatrooms" featlist = ["http://jabber.org/protocol/muc"] self.s.send(msgout.dinfo(mid, self.name, mfrom, icateg, itype, iname, featlist)) return if qtag.tag == xmpp.utils.nt(ns.HTTP_DITEMS,ns.TAG_QUERY): if t.tag != xmpp.utils.nt(ns.JABBER_CLIENT,ns.TAG_IQ): return itemslist = [] for k,v in self.rooms.items(): itemslist.append(k+"@"+self.name) pass self.s.send(msgout.ditems(mid, self.name, mfrom, itemslist)) return if t.attrib['type'] == 'get' and \ qtag.tag == xmpp.utils.nt("urn:xmpp:ping","ping"): self.s.send(msgout.pong(self.name, mfrom, t.attrib['id'])) return pass
def cbrecv(self, stream,m): try: t = xml.etree.ElementTree.fromstring(m) except: m += "</stream:stream>" try: t = xml.etree.ElementTree.fromstring(m) except: return pass # stream header if t.tag == xmpp.utils.nt("http://etherx.jabber.org/streams", "stream"): self.s.send(msgout.hshake(t.attrib['id'], self.ckey)) return # to component-self if ('to' in t.attrib) == False: self.recv_component(m) return if t.attrib['to'] == self.name: self.recv_component(m) return (roomname, servname, nickname) = xmpp.msgin.splitjid(t.attrib['to']) # to room if roomname != '' and servname != '' and nickname == '': t = xml.etree.ElementTree.fromstring(m) if t.tag == xmpp.utils.nt(ns.JABBER_CLIENT,ns.TAG_MSG) or t.tag==ns.TAG_MSG: fromnick = '' for (fjid,nick) in self.rooms[roomname]: if t.attrib['from']==fjid: fromnick = nick pass for (fjid,nick) in self.rooms[roomname]: newto = fjid newfm = roomname+"@"+servname+"/"+fromnick t.attrib["from"] = newfm t.attrib["to"] = newto self.s.send(tostring(t).decode("utf-8")) pass pass intag = t.find('*') if t.tag == xmpp.utils.nt(ns.JABBER_CLIENT,ns.TAG_IQ) and \ intag != None and \ intag.tag == xmpp.utils.nt(ns.HTTP_DINFO,ns.TAG_QUERY): icateg = "conference" itype = "text" iname = "The Room" featlist = ["http://jabber.org/protocol/muc", "muc_public", "muc_persistent", "muc_open", "muc_semianonymous", "muc_unmoderated", "muc_unsecured"] mfrom = t.attrib['from'] mid = t.attrib['id'] self.s.send(msgout.dinfo(mid, self.name, mfrom, icateg, itype, iname, featlist)) return if t.tag == xmpp.utils.nt(ns.JABBER_CLIENT,ns.TAG_IQ) and \ intag != None and \ intag.tag == xmpp.utils.nt(ns.HTTP_DITEMS,ns.TAG_QUERY): itemslist = [] if roomname in self.rooms: for (f,n) in self.rooms[roomname]: itemslist.append(n) pass pass mfrom = t.attrib['from'] mid = t.attrib['id'] self.s.send(msgout.ditems(mid, self.name, mfrom, itemslist)) return pass # to user in a room if roomname != '' and servname != '' and nickname != '': t = xml.etree.ElementTree.fromstring(m) if t.tag == xmpp.utils.nt(ns.JABBER_CLIENT,ns.TAG_PRES) or \ t.tag == ns.TAG_PRES: if ('type' in t.attrib) == False: t.attrib['type'] = 'available' pass mfrom = t.attrib['from'] mto = t.attrib['to'] if t.attrib['type'] == 'available': if roomname in self.rooms: found = False for (f,n) in self.rooms[roomname]: if f == mfrom: found = True if n == nickname: found = True pass if found == False: self.rooms[roomname].append((mfrom,nickname)) pass else: self.rooms[roomname] = [(mfrom,nickname)] if roomname in self.rooms: for (f,n) in self.rooms[roomname]: t = roomname+"@"+servname+"/"+nickname self.s.send(msgout.presence_ret(t, f, '', '', '')) pass for (f,n) in self.rooms[roomname]: t = roomname+"@"+servname+"/"+n self.s.send(msgout.presence_ret(t, mfrom, '', '', '')) pass pass pass elif t.attrib['type'] == 'unavailable': if roomname in self.rooms == False: return # send unavailable presence to other group members for (f,n) in self.rooms[roomname]: if f == mfrom: self.rooms[roomname].remove((f,n)) pass for (f,n) in self.rooms[roomname]: t = roomname+"@"+servname+"/"+nickname self.s.send(msgout.presence_ret(t,f, 'unavailable', '', '')) pass if len(self.rooms[roomname]) == 0: self.rooms.pop(roomname) pass else: pass pass pass pass