コード例 #1
0
ファイル: __init__.py プロジェクト: wvhn/plugins
    def __init__(self, smarthome, jid, password, logic='XMPP'):
        self.logger = logging.getLogger(__name__)
        server = self.get_parameter_value('server')
        plugins = self.get_parameter_value('plugins')
        joins = self.get_parameter_value('join')

        # Check server parameter and default to port 5222
        if server is None:
            self._server = None
        elif ':' in server:
            parts = server.split(':')
            self._server = (parts[0].strip(), parts[1].strip())
        else:
            self._server = (server, 5222)

        # Enable MUC in case account should join channels
        if len(joins) and 'xep_0045' not in plugins:
            plugins.append('xep_0045')

        self.xmpp = slixmpp.ClientXMPP(jid, password)
        for plugin in plugins:
            self.xmpp.register_plugin(plugin)
        self.xmpp.use_ipv6 = self.get_parameter_value('use_ipv6')
        self.xmpp.add_event_handler("session_start", self.handleXMPPConnected)
        self.xmpp.add_event_handler("session_end", self.handleXMPPDisconnected)
        self.xmpp.add_event_handler("message", self.handleIncomingMessage)
        self._logic = logic
        self._sh = smarthome
        self._join = joins
        self._connected = False
        self.xmpp.loop = asyncio.get_event_loop()
コード例 #2
0
    def load(self):

        try:
            asyncio.get_event_loop()

        except RuntimeError:
            # slixmpp can not handle not having an event_loop
            # see: https://lab.louiz.org/poezio/slixmpp/-/issues/3456
            # This is a work-around to this problem
            asyncio.set_event_loop(asyncio.new_event_loop())

        # Prepare our object
        self.xmpp = slixmpp.ClientXMPP(self.jid, self.password)

        # Register our session
        self.xmpp.add_event_handler("session_start", self.session_start)

        for xep in self.xep:
            # Load xep entries
            try:
                self.xmpp.register_plugin('xep_{0:04d}'.format(xep))

            except slixmpp.plugins.base.PluginNotFound:
                self.logger.warning(
                    'Could not register plugin {}'.format(
                        'xep_{0:04d}'.format(xep)))
                return False

        if self.secure:
            # Don't even try to use the outdated ssl.PROTOCOL_SSLx
            self.xmpp.ssl_version = ssl.PROTOCOL_TLSv1

            # If the python version supports it, use highest TLS version
            # automatically
            if hasattr(ssl, "PROTOCOL_TLS"):
                # Use the best version of TLS available to us
                self.xmpp.ssl_version = ssl.PROTOCOL_TLS

            self.xmpp.ca_certs = None
            if self.verify_certificate:
                # Set the ca_certs variable for certificate verification
                self.xmpp.ca_certs = next(
                    (cert for cert in self.CA_CERTIFICATE_FILE_LOCATIONS
                     if isfile(cert)), None)

                if self.xmpp.ca_certs is None:
                    self.logger.warning(
                        'XMPP Secure comunication can not be verified; '
                        'no local CA certificate file')
                    return False

        # If the user specified a port, skip SRV resolving, otherwise it is a
        # lot easier to let slixmpp handle DNS instead of the user.
        self.override_connection = \
            None if not self.port else (self.host, self.port)

        # We're good
        return True
コード例 #3
0
    def new_session(cls, jid, password, callback=None):
        '''
        Opens a new session and instantiates a new XMPP client.

        Arguments:
            jid -- The XMPP JID for logging in.
            password -- The password for logging in.
            callback -- An optional callback which can be used to track
                the starting state of the session.
        '''
        client = slixmpp.ClientXMPP(jid, password)
        #? Register plug-ins.
        client.register_plugin('xep_0004')  # Data Forms
        client.register_plugin('xep_0009')  # Jabber-RPC
        client.register_plugin('xep_0030')  # Service Discovery
        client.register_plugin('xep_0060')  # PubSub
        client.register_plugin('xep_0199')  # XMPP Ping
        return cls.new_session_with_client(client, callback)
コード例 #4
0
    def testPresenceUnsolicitedOffline(self):
        """
        Unsolicted offline presence does not spawn changed_status
        or update the roster.
        """
        p = self.Presence()
        p['type'] = 'unavailable'
        p['from'] = '[email protected]/gmail15af'

        c = slixmpp.ClientXMPP('crap@wherever', 'password')
        happened = []

        def handlechangedpresence(event):
            happened.append(True)

        c.add_event_handler("changed_status", handlechangedpresence)
        c._handle_presence(p)

        self.failUnless(happened == [],
            "changed_status event triggered for extra unavailable presence")
        roster = c.roster['crap@wherever']
        self.failUnless(roster['*****@*****.**'].resources == {},
            "Roster updated for superfulous unavailable presence")
コード例 #5
0
ファイル: migrate_roster.py プロジェクト: yikuide/slixmpp
args = parser.parse_args()

# Setup logging.
logging.basicConfig(level=args.loglevel, format='%(levelname)-8s %(message)s')

if args.old_jid is None:
    args.old_jid = input("Old JID: ")
if args.old_password is None:
    args.old_password = getpass("Old Password: "******"New JID: ")
if args.new_password is None:
    args.new_password = getpass("New Password: ")

old_xmpp = slixmpp.ClientXMPP(args.old_jid, args.old_password)

# If you are connecting to Facebook and wish to use the
# X-FACEBOOK-PLATFORM authentication mechanism, you will need
# your API key and an access token. Then you'll set:
# xmpp.credentials['api_key'] = 'THE_API_KEY'
# xmpp.credentials['access_token'] = 'THE_ACCESS_TOKEN'

# If you are connecting to MSN, then you will need an
# access token, and it does not matter what JID you
# specify other than that the domain is 'messenger.live.com',
# so '*****@*****.**' will work. You can specify
# the access token as so:
# xmpp.credentials['access_token'] = 'THE_ACCESS_TOKEN'

# If you are working with an OpenFire server, you may need