Ejemplo n.º 1
0
    def init_client(self):
        """
        Initializes the XMPP client instance.
        """
        from headstock.client import AsyncClient

        jid = JID(self.settings.username, self.settings.domain,
                  self.settings.resource)
        self.client = AsyncClient(unicode(jid),
                                  self.settings.password,
                                  hostname=self.settings.hostname,
                                  port=self.settings.port,
                                  tls=self.settings.tls,
                                  registercls=None)
        log_path = None
        if self.settings.log_dir:
            log_path = "%s.log" % os.path.join(self.settings.log_dir,
                                               self.settings.username)
        self.client.set_log(path=log_path, stdout=self.settings.log_stdout)

        if self.settings.register:
            self.client.stream.register = True
            self.client.swap_handler(self.register,
                                     "register",
                                     "http://jabber.org/features/iq-register",
                                     once=True,
                                     forget=False)
            self.client.swap_handler(self.handle_registration,
                                     "query",
                                     XMPP_IBR_NS,
                                     once=True)
            self.client.swap_handler(self.handle_conflict,
                                     "conflict",
                                     XMPP_STANZA_ERROR_NS,
                                     once=True)
            self.client.swap_handler(self.handle_not_authorized,
                                     "not-authorized",
                                     XMPP_SASL_NS,
                                     once=True)
Ejemplo n.º 2
0
    @headstock.xmpphandler('entry', ATOM10_NS)
    def entry(self, e):
        print e.get_child('title', ns=ATOM10_NS).xml_text

    @headstock.xmpphandler('message', XMPP_CLIENT_NS)
    def message(self, e):
        pass


if __name__ == '__main__':
    from headstock.lib.utils import parse_commandline

    options = parse_commandline()
    if not options.password:
        from getpass import getpass
        options.password = getpass()
    host, port = options.address.split(':')

    c = AsyncClient(unicode(options.jid),
                    unicode(options.password),
                    hostname=host,
                    port=int(port),
                    tls=options.usetls)
    c.set_log(stdout=True)

    c.register(Basic())
    c.register(PubSub())

    c.run()