コード例 #1
0
ファイル: server.py プロジェクト: chromebookbob/python2012
 def report_presence_unavailable(self):
     for user in self.factory.get_clients().items():
         stanza = Stanza("presence", {
             'from': self.login,
             'to': user[1].login_res,
             'type': 'unavailable'
         })
         user[1].__send_(stanza.to_xml())
コード例 #2
0
ファイル: server.py プロジェクト: chromebookbob/python2012
 def __handle_message_(self, stanza):
     attrs = stanza.get_attrs()
     to = attrs['to'].split("@")[0]
     user = self.factory.get_client(to)
     if user:
         attrs['to'] = user.login
         attrs['from'] = self.username + '@' + self.realm
         attrs['xml:lang'] = 'en'
         stanza.add_child(
             Stanza('active',
                    {'xmlns': 'http://jabber.org/protocol/chatstates'}))
         user.__send_(stanza.to_xml())
コード例 #3
0
ファイル: server.py プロジェクト: VOVAN1993/python2012
 def report_presence(self, other_user):
     stanza = Stanza("presence", {'from': other_user.login, 'to': self.login})
     self.transport.write(stanza.to_xml())
コード例 #4
0
ファイル: server.py プロジェクト: VOVAN1993/python2012
    def handle_query(self, stanza):
        attrs = stanza.get_attrs()
        id = attrs["id"]
        type = attrs["type"]
        if type == "set":
            child1 = stanza.get_children()[0]
            if child1.get_name() == "bind":
                resource = child1.get_children()[0]
                del child1.get_children()[0]
                self.resource = resource.get_text()
                response = Stanza("iq", {'id': id, 'type': 'result'})
                self.login = self.username + "@" + self.realm + "/" + self.resource

                self.add_user()
                jid = Stanza("jid", text=self.login)
                child1.add_child(jid)
                response.add_child(child1)
                self.transport.write(response.to_xml())
            elif child1.get_name() == "session":
                response = Stanza("iq", {'from': self.realm, 'type': 'result', "id": id})
                self.transport.write(response.to_xml())
            else:
                stanza = Stanza("iq", {'type': 'error', 'from': self.factory.get_host(), 'id': id, 'to': self.login})
        elif type == "get":
            for child in stanza.get_children():
                if child.get_name() == "query":
                    query = child
                    if query.get_attr("xmlns") == "jabber:iq:roster":
                        response = Stanza("iq", {"to": self.login, type: "result", "id": id})
                        response.add_child(query)
                        for user in self.factory.get_clients().items():
                            if user[0] != self.username:
                                item = Stanza("item",
                                    {'jid': user[1].login, 'name': user[1].username, 'subscription': 'both'})
                                query.add_child(item)
                        self.transport.write(response.to_xml())
                        for user in self.factory.get_clients().items():
                            if user[0] != self.username:
                                presence = Stanza("presence", {'from': user[1].login, 'to': self.login})
                                self.transport.write(presence.to_xml())
                    else:
                        stanza = Stanza("iq",
                            {'type': 'error', 'from': self.factory.get_host(), 'id': id, 'to': self.login})
                        stanza.add_child(query)
                        self.transport.write(stanza.to_xml())
コード例 #5
0
ファイル: server.py プロジェクト: chromebookbob/python2012
 def report_presence_unavailable(self):
     for user in self.factory.get_clients().items():
         stanza = Stanza("presence", {'from': self.login, 'to': user[1].login_res, 'type': 'unavailable'})
         user[1].__send_(stanza.to_xml())
コード例 #6
0
ファイル: server.py プロジェクト: chromebookbob/python2012
 def report_presence(self, other_user):
     stanza = Stanza("presence", {'from': other_user.login, 'to': self.login_res})
     self.__send_(stanza.to_xml())
コード例 #7
0
ファイル: server.py プロジェクト: chromebookbob/python2012
 def gotTagStart(self, name, attributes):
     stanza = Stanza(name, attributes)
     self.stack_stanzas.append(stanza)
     self.__handle_()
コード例 #8
0
ファイル: server.py プロジェクト: chromebookbob/python2012
 def report_presence(self, other_user):
     stanza = Stanza("presence", {
         'from': other_user.login,
         'to': self.login_res
     })
     self.__send_(stanza.to_xml())
コード例 #9
0
ファイル: server.py プロジェクト: chromebookbob/python2012
    def handle_query(self, stanza):
        attrs = stanza.get_attrs()
        id = attrs["id"]
        type = attrs["type"]
        if type == "set":
            child1 = stanza.get_children()[0]
            if child1.get_name() == "bind":
                resource = child1.get_children()[0]
                del child1.get_children()[0]
                self.resource = resource.get_text()
                response = Stanza("iq", {'id': id, 'type': 'result'})
                self.login_res = self.username + "@" + self.realm + "/" + self.resource
                self.login = self.username + "@" + self.realm
                self.add_user()
                jid = Stanza("jid", text=self.login_res)
                child1.add_child(jid)
                response.add_child(child1)
                self.__send_(response.to_xml())
            elif child1.get_name() == "session":
                response = Stanza("iq", {
                    'from': self.realm,
                    'type': 'result',
                    "id": id
                })
                self.__send_(response.to_xml())
            else:
                stanza = Stanza(
                    "iq", {
                        'type': 'error',
                        'from': self.factory.get_host(),
                        'id': id,
                        'to': self.login_res
                    })
        elif type == "get":
            for child in stanza.get_children():
                if child.get_name() == "query":
                    query = child
                    if query.get_attr("xmlns") == "jabber:iq:roster":
                        response = Stanza("iq", {
                            "to": self.login_res,
                            type: "result",
                            "id": id
                        })
                        response.add_child(query)
                        for user in self.factory.get_clients().items():
                            if user[0] != self.username:
                                item = Stanza(
                                    "item", {
                                        'jid': user[1].login,
                                        'name': user[1].username,
                                        'subscription': 'both'
                                    })
                                query.add_child(item)

                        self.__send_(response.to_xml())
                        for user in self.factory.get_clients().items():
                            if user[0] != self.username:
                                presence = Stanza("presence", {
                                    'from': user[1].login,
                                    'to': self.login_res
                                })
                                self.__send_(presence.to_xml())
                    else:
                        stanza = Stanza(
                            "iq", {
                                'type': 'error',
                                'from': self.factory.get_host(),
                                'id': id,
                                'to': self.login_res
                            })
                        stanza.add_child(query)
                        self.__send_(stanza.to_xml())