示例#1
0
文件: iq.py 项目: vladamatena/h2x
    def onIq(self, element: Element):
        source = JID(element.getAttribute("from"))
        recipient = JID(element.getAttribute("to"))
        identification = element.getAttribute("id")
        iqType = element.getAttribute("type")

        print("IqReceived " + source.full() + " -> " + recipient.full() + ": " + iqType)

        # Process component iq
        if recipient.full() == self.h2x.config.JID:
            self.componentIq(element, source, identification, iqType)
            return

            # Process user iq
        if self.h2x.isHangUser(recipient):
            self.userIq(element, source, recipient, identification, iqType)
            return

            # TODO: Can we send something like wrong request?
        self.__sendIqError(
            recipient=source.full(),
            sender=recipient.full(),
            identification=identification,
            errorType="cancel",
            condition="service-unavailable",
        )
示例#2
0
文件: h2x.py 项目: vladamatena/h2x
	def onMessage(self, element: Element):
		msgType = element.getAttribute("type")
		recipient = JID(element.getAttribute("to"))
		sender = JID(element.getAttribute("from"))
		text = element.firstChildElement().__str__()

		if msgType == "chat":
			self.getClient(sender).sendMessage(recipient, text)
		else:
			raise NotImplementedError
示例#3
0
文件: h2x.py 项目: vladamatena/h2x
	def onPresence(self, element: Element):
		sender = JID(element.getAttribute("from"))
		recipient = JID(element.getAttribute("to"))
		presenceType = element.getAttribute("type")
		if not presenceType:
			presenceType = "available"

		print("PresenceReceived: " + sender.full() + " -> " + recipient.full() + " : " + presenceType)

		# Create client instance on available from XMPP client
		if self.getClient(sender) is None:
			if presenceType == "available":
				try:
					self.addClient(ClientWrapper(self, sender))
				except UserNotRegistered as e:
					print(e)
					self.sendPresenceError(recipient=sender, sender=recipient, errorType="auth",
										   condition="registration-required")
					return
			else:
				print("Operation on client which has not yet send available presence !!! (responding as if we are not available)")
				self.sendPresence(sender, "unavailable")
				return

		# Service component presence
		if recipient == JID(self.config.JID):
			self.getClient(sender).processComponentPresence(sender, presenceType, recipient)

		# Subscription request
		elif presenceType == "subscribe":
			self.getClient(sender).processSubscription(recipient)

		# Presence to Hangouts user
		elif self.isHangUser(recipient):
			self.getClient(sender).processPresence(recipient, presenceType)

		# Unimplemented feature
		else:
			raise NotImplemented(element)