コード例 #1
0
ファイル: RosterRetrieval.py プロジェクト: Ashaman-/pyaimt
	def incomingIq(self, el):
		to = el.getAttribute("from")
		fro = el.getAttribute("from")
		froj = internJID(fro)
		ID = el.getAttribute("id")
		if not hasattr(self.pytrans, "legacycon"):
			self.pytrans.iq.sendIqError(to=to, fro=config.jid, ID=ID, xmlns=globals.COMMANDS, etype="cancel", condition="service-unavailable")
		ulang = utils.getLang(el)

		if not self.pytrans.sessions.has_key(froj.userhost()):
			self.pytrans.iq.sendIqError(to=fro, fro=config.jid, ID=ID, xmlns=globals.COMMANDS, etype="cancel", condition="service-unavailable")
			return
		s = self.pytrans.sessions[froj.userhost()]
		if not s.ready:
			self.pytrans.iq.sendIqError(to=fro, fro=config.jid, ID=ID, xmlns=globals.COMMANDS, etype="cancel", condition="service-unavailable")
			return

		iq = Element((None, "iq"))
		iq.attributes["to"] = to
		iq.attributes["from"] = config.jid
		if ID:
			iq.attributes["id"] = ID
		iq.attributes["type"] = "result"

		command = iq.addElement("command")
		command.attributes["sessionid"] = self.pytrans.makeMessageID()
		command.attributes["node"] = "retrieveroster"
		command.attributes["xmlns"] = globals.COMMANDS
		command.attributes["status"] = "completed"

		x = command.addElement("x")
		x.attributes["xmlns"] = globals.XDATA
		x.attributes["type"] = "result"

		title = x.addElement("title")
		title.addContent(lang.get("command_RosterRetrieval", ulang))

		reported = x.addElement("reported")
		reported.addChild(utils.makeDataFormElement(None, "legacyid", "Legacy ID"))
		reported.addChild(utils.makeDataFormElement(None, "nick", "Nickname"))

		entities = s.pytrans.xdb.getList("roster", s.jabberID)
		if entities != None:
			for e in entities:
				name = e[0]
				attrs = e[1]

				item = x.addElement("item")

				field = item.addElement("field")
				field.attributes["var"] = "legacyid"
				field.addElement("value").addContent(name)

				field = item.addElement("field")
				field.attributes["var"] = "nick"
				field.addElement("value").addContent(attrs.get('nickname',''))

		self.pytrans.send(iq)
コード例 #2
0
    def gotSearchResults(self, results, iq, d):
        LogEvent(INFO, self.session.jabberID)
        from glue import aim2jid

        x = None
        for query in iq.elements():
            if query.name == "query":
                for child in query.elements():
                    if child.name == "x":
                        x = child
                        break
                break

        if x:
            for r in results:
                if r.has_key("screenname"):
                    r["jid"] = aim2jid(r["screenname"])
                else:
                    r["jid"] = "Unknown"
                item = x.addElement("item")
                for k in [
                        "jid", "first", "middle", "last", "maiden", "nick",
                        "email", "address", "city", "state", "country", "zip",
                        "region"
                ]:
                    item.addChild(
                        utils.makeDataFormElement(None,
                                                  k,
                                                  value=r.get(k, None)))
        d.callback(iq)
コード例 #3
0
ファイル: glue.py プロジェクト: fritteli/pyicqt
	def gotSearchResults(self, results, iq, d):
		LogEvent(INFO, self.session.jabberID)
		from glue import icq2jid

		x = None
		for query in iq.elements():
			if query.name == "query":
				for child in query.elements():
					if child.name == "x":
						x = child
						break
				break

		if x:
			for r in results:
				if r.has_key("screenname"):
					r["jid"] = icq2jid(r["screenname"])
				else:
					r["jid"] = "Unknown"
				item = x.addElement("item")
				for k in ["jid","first","middle","last","maiden","nick","email","address","city","state","country","zip","region"]:
					item.addChild(utils.makeDataFormElement(None, k, value=r.get(k,None)))
		d.callback(iq)
コード例 #4
0
	def processSearch(self, el):
		LogEvent(INFO)
		ulang = utils.getLang(el)
		iq = Element((None, "iq"))
		iq.attributes["type"] = "result"
		to = el.getAttribute("to")
		iq.attributes["from"] = to
		fro = el.getAttribute("from")
		iq.attributes["to"] = fro
		ID = el.getAttribute("id")
		if ID:
			iq.attributes["id"] = ID
		query = iq.addElement("query")
		query.attributes["xmlns"] = globals.IQSEARCH
		x = query.addElement("x")
		x.attributes["xmlns"] = globals.XDATA
		x.attributes["type"] = "result"
		x.addChild(utils.makeDataFormElement("hidden", "FORM_TYPE", value="jabber:iq:search"))
		reported = x.addElement("reported")
		reported.addChild(utils.makeDataFormElement(None, "jid", "Jabber ID"))
		reported.addChild(utils.makeDataFormElement(None, "first", "First Name"))
		reported.addChild(utils.makeDataFormElement(None, "middle", "Middle Name"))
		reported.addChild(utils.makeDataFormElement(None, "last", "Last Name"))
		reported.addChild(utils.makeDataFormElement(None, "maiden", "Maiden Name"))
		reported.addChild(utils.makeDataFormElement(None, "nick", "Nickname"))
		reported.addChild(utils.makeDataFormElement(None, "email", "E-Mail Address"))
		reported.addChild(utils.makeDataFormElement(None, "address", "Street Address"))
		reported.addChild(utils.makeDataFormElement(None, "city", "City"))
		reported.addChild(utils.makeDataFormElement(None, "state", "State"))
		reported.addChild(utils.makeDataFormElement(None, "country", "Country"))
		reported.addChild(utils.makeDataFormElement(None, "zip", "Zip Code"))
		reported.addChild(utils.makeDataFormElement(None, "region", "Region"))

		dataform = None
		for query in el.elements():
			if query.name == "query":
				for child in query.elements():
					if child.name == "x":
						dataform = child
						break
				break

		if not hasattr(self.pytrans, "legacycon"):
			self.pytrans.iq.sendIqError(to=to, fro=config.jid, ID=ID, xmlns=globals.IQSEARCH, etype="cancel", condition="bad-request")

		if dataform:
			self.pytrans.legacycon.doSearch(dataform, iq).addCallback(self.gotSearchResponse)
		else:
			self.pytrans.iq.sendIqError(to=to, fro=config.jid, ID=ID, xmlns=globals.IQSEARCH, etype="retry", condition="bad-request")
コード例 #5
0
	def sendSearchForm(self, el):
		LogEvent(INFO)
		ulang = utils.getLang(el)
		iq = Element((None, "iq"))
		iq.attributes["type"] = "result"
		iq.attributes["from"] = el.getAttribute("to")
		iq.attributes["to"] = el.getAttribute("from")
		if el.getAttribute("id"):
			iq.attributes["id"] = el.getAttribute("id")
		query = iq.addElement("query")
		query.attributes["xmlns"] = globals.IQSEARCH
		forminstr = query.addElement("instructions")
		forminstr.addContent(lang.get("searchnodataform", ulang))
		x = query.addElement("x")
		x.attributes["xmlns"] = globals.XDATA
		x.attributes["type"] = "form"
		title = x.addElement("title")
		title.addContent(lang.get("searchtitle", ulang))
		instructions = x.addElement("instructions")
		instructions.addContent(lang.get("searchinstructions", ulang))
		x.addChild(utils.makeDataFormElement("hidden", "FORM_TYPE", value="jabber:iq:search"))
		x.addChild(utils.makeDataFormElement("text-single", "email", "E-Mail Address"))
		x.addChild(utils.makeDataFormElement("text-single", "first", "First Name"))
		x.addChild(utils.makeDataFormElement("text-single", "middle", "Middle Name"))
		x.addChild(utils.makeDataFormElement("text-single", "last", "Last Name"))
		x.addChild(utils.makeDataFormElement("text-single", "maiden", "Maiden Name"))
		x.addChild(utils.makeDataFormElement("text-single", "nick", "Nickname"))
		x.addChild(utils.makeDataFormElement("text-single", "address", "Street Address"))
		x.addChild(utils.makeDataFormElement("text-single", "city", "City"))
		x.addChild(utils.makeDataFormElement("text-single", "state", "State"))
		x.addChild(utils.makeDataFormElement("text-single", "zip", "Zip Code"))
		x.addChild(utils.makeDataFormElement("text-single", "country", "Country"))
		x.addChild(utils.makeDataFormElement("text-single", "interest", "Interest"))

		self.pytrans.send(iq)
コード例 #6
0
    def incomingIq(self, el):
        to = el.getAttribute("from")
        fro = el.getAttribute("from")
        froj = internJID(fro)
        ID = el.getAttribute("id")
        if not hasattr(self.pytrans, "legacycon"):
            self.pytrans.iq.sendIqError(to=to,
                                        fro=config.jid,
                                        ID=ID,
                                        xmlns=globals.COMMANDS,
                                        etype="cancel",
                                        condition="service-unavailable")
        ulang = utils.getLang(el)

        if not self.pytrans.sessions.has_key(froj.userhost()):
            self.pytrans.iq.sendIqError(to=fro,
                                        fro=config.jid,
                                        ID=ID,
                                        xmlns=globals.COMMANDS,
                                        etype="cancel",
                                        condition="service-unavailable")
            return
        s = self.pytrans.sessions[froj.userhost()]
        if not s.ready:
            self.pytrans.iq.sendIqError(to=fro,
                                        fro=config.jid,
                                        ID=ID,
                                        xmlns=globals.COMMANDS,
                                        etype="cancel",
                                        condition="service-unavailable")
            return

        iq = Element((None, "iq"))
        iq.attributes["to"] = to
        iq.attributes["from"] = config.jid
        if ID:
            iq.attributes["id"] = ID
        iq.attributes["type"] = "result"

        command = iq.addElement("command")
        command.attributes["sessionid"] = self.pytrans.makeMessageID()
        command.attributes["node"] = "retrieveroster"
        command.attributes["xmlns"] = globals.COMMANDS
        command.attributes["status"] = "completed"

        x = command.addElement("x")
        x.attributes["xmlns"] = globals.XDATA
        x.attributes["type"] = "result"

        title = x.addElement("title")
        title.addContent(lang.get("command_RosterRetrieval", ulang))

        reported = x.addElement("reported")
        reported.addChild(
            utils.makeDataFormElement(None, "legacyid", "Legacy ID"))
        reported.addChild(utils.makeDataFormElement(None, "nick", "Nickname"))

        entities = s.pytrans.xdb.getList("roster", s.jabberID)
        if entities != None:
            for e in entities:
                name = e[0]
                attrs = e[1]

                item = x.addElement("item")

                field = item.addElement("field")
                field.attributes["var"] = "legacyid"
                field.addElement("value").addContent(name)

                field = item.addElement("field")
                field.attributes["var"] = "nick"
                field.addElement("value").addContent(attrs.get('nickname', ''))

        self.pytrans.send(iq)