def __init__(self, jid, secret, host=None, port=None, plugin_config={}, plugin_whitelist=[], use_jc_ns=False): if use_jc_ns: default_ns = 'jabber:client' else: default_ns = 'jabber:component:accept' BaseXMPP.__init__(self, jid, default_ns) self.auto_authorize = None self.stream_header = "<stream:stream %s %s to='%s'>" % ( 'xmlns="jabber:component:accept"', 'xmlns:stream="%s"' % self.stream_ns, jid) self.stream_footer = "</stream:stream>" self.server_host = host self.server_port = port self.secret = secret self.plugin_config = plugin_config self.plugin_whitelist = plugin_whitelist self.is_component = True self.register_handler( Callback('Handshake', MatchXPath('{jabber:component:accept}handshake'), self._handle_handshake)) self.add_event_handler('presence_probe', self._handle_probe)
def __init__(self, jid, secret, host=None, port=None, plugin_config={}, plugin_whitelist=[], use_jc_ns=False): if use_jc_ns: default_ns = "jabber:client" else: default_ns = "jabber:component:accept" BaseXMPP.__init__(self, jid, default_ns) self.auto_authorize = None self.stream_header = "<stream:stream %s %s to='%s'>" % ( 'xmlns="jabber:component:accept"', 'xmlns:stream="%s"' % self.stream_ns, jid, ) self.stream_footer = "</stream:stream>" self.server_host = host self.server_port = port self.secret = secret self.plugin_config = plugin_config self.plugin_whitelist = plugin_whitelist self.is_component = True self.register_handler( Callback("Handshake", MatchXPath("{jabber:component:accept}handshake"), self._handle_handshake) ) self.add_event_handler("presence_probe", self._handle_probe)
def __init__(self, jid, password, ssl=False, plugin_config={}, plugin_whitelist=[], escape_quotes=True, sasl_mech=None): """ Create a new SleekXMPP client. Arguments: jid -- The JID of the XMPP user account. password -- The password for the XMPP user account. ssl -- Deprecated. plugin_config -- A dictionary of plugin configurations. plugin_whitelist -- A list of approved plugins that will be loaded when calling register_plugins. escape_quotes -- Deprecated. """ BaseXMPP.__init__(self, jid, 'jabber:client') self.set_jid(jid) self.password = password self.escape_quotes = escape_quotes self.plugin_config = plugin_config self.plugin_whitelist = plugin_whitelist self.default_port = 5222 self.stream_header = "<stream:stream to='%s' %s %s version='1.0'>" % ( self.boundjid.host, "xmlns:stream='%s'" % self.stream_ns, "xmlns='%s'" % self.default_ns) self.stream_footer = "</stream:stream>" self.features = set() self._stream_feature_handlers = {} self._stream_feature_order = [] #TODO: Use stream state here self.authenticated = False self.sessionstarted = False self.bound = False self.bindfail = False self.add_event_handler('connected', self._handle_connected) self.register_stanza(StreamFeatures) self.register_handler( Callback('Stream Features', MatchXPath('{%s}features' % self.stream_ns), self._handle_stream_features)) self.register_handler( Callback('Roster Update', MatchXPath('{%s}iq/{%s}query' % ( self.default_ns, 'jabber:iq:roster')), self._handle_roster)) # Setup default stream features self.register_plugin('feature_starttls') self.register_plugin('feature_bind') self.register_plugin('feature_session') self.register_plugin('feature_mechanisms', pconfig={'use_mech': sasl_mech} if sasl_mech else None)
def __init__(self, jid, password, plugin_config={}, plugin_whitelist=[], escape_quotes=True, sasl_mech=None, lang='en'): BaseXMPP.__init__(self, jid, 'jabber:client') self.escape_quotes = escape_quotes self.plugin_config = plugin_config self.plugin_whitelist = plugin_whitelist self.default_port = 5222 self.default_lang = lang self.credentials = {} self.password = password self.stream_header = "<stream:stream to='%s' %s %s %s %s>" % ( self.boundjid.host, "xmlns:stream='%s'" % self.stream_ns, "xmlns='%s'" % self.default_ns, "xml:lang='%s'" % self.default_lang, "version='1.0'") self.stream_footer = "</stream:stream>" self.features = set() self._stream_feature_handlers = {} self._stream_feature_order = [] self.dns_service = 'xmpp-client' #TODO: Use stream state here self.authenticated = False self.sessionstarted = False self.bound = False self.bindfail = False self.add_event_handler('connected', self._reset_connection_state) self.add_event_handler('session_bind', self._handle_session_bind) self.add_event_handler('roster_update', self._handle_roster) self.register_stanza(StreamFeatures) self.register_handler( Callback('Stream Features', MatchXPath('{%s}features' % self.stream_ns), self._handle_stream_features)) self.register_handler( Callback('Roster Update', StanzaPath('iq@type=set/roster'), lambda iq: self.event('roster_update', iq))) # Setup default stream features self.register_plugin('feature_starttls') self.register_plugin('feature_bind') self.register_plugin('feature_session') self.register_plugin('feature_rosterver') self.register_plugin('feature_preapproval') self.register_plugin('feature_mechanisms') if sasl_mech: self['feature_mechanisms'].use_mech = sasl_mech
def __init__( self, jid, password, plugin_config={}, plugin_whitelist=[], escape_quotes=True, sasl_mech=None, lang="en" ): BaseXMPP.__init__(self, jid, "jabber:client") self.escape_quotes = escape_quotes self.plugin_config = plugin_config self.plugin_whitelist = plugin_whitelist self.default_port = 5222 self.default_lang = lang self.credentials = {} self.password = password self.stream_header = "<stream:stream to='%s' %s %s %s %s>" % ( self.boundjid.host, "xmlns:stream='%s'" % self.stream_ns, "xmlns='%s'" % self.default_ns, "xml:lang='%s'" % self.default_lang, "version='1.0'", ) self.stream_footer = "</stream:stream>" self.features = set() self._stream_feature_handlers = {} self._stream_feature_order = [] self.dns_service = "xmpp-client" # TODO: Use stream state here self.authenticated = False self.sessionstarted = False self.bound = False self.bindfail = False self.add_event_handler("connected", self._reset_connection_state) self.add_event_handler("session_bind", self._handle_session_bind) self.register_stanza(StreamFeatures) self.register_handler( Callback("Stream Features", MatchXPath("{%s}features" % self.stream_ns), self._handle_stream_features) ) self.register_handler(Callback("Roster Update", StanzaPath("iq@type=set/roster"), self._handle_roster)) # Setup default stream features self.register_plugin("feature_starttls") self.register_plugin("feature_bind") self.register_plugin("feature_session") self.register_plugin("feature_rosterver") self.register_plugin("feature_preapproval") self.register_plugin("feature_mechanisms") if sasl_mech: self["feature_mechanisms"].use_mech = sasl_mech
def __init__(self, jid, password, ssl=False, plugin_config={}, plugin_whitelist=[], escape_quotes=True, sasl_mech=None): BaseXMPP.__init__(self, jid, 'jabber:client') self.set_jid(jid) self.escape_quotes = escape_quotes self.plugin_config = plugin_config self.plugin_whitelist = plugin_whitelist self.default_port = 5222 self.credentials = {} self.password = password self.stream_header = "<stream:stream to='%s' %s %s version='1.0'>" % ( self.boundjid.host, "xmlns:stream='%s'" % self.stream_ns, "xmlns='%s'" % self.default_ns) self.stream_footer = "</stream:stream>" self.features = set() self._stream_feature_handlers = {} self._stream_feature_order = [] #TODO: Use stream state here self.authenticated = False self.sessionstarted = False self.bound = False self.bindfail = False self.add_event_handler('connected', self._handle_connected) self.add_event_handler('session_bind', self._handle_session_bind) self.register_stanza(StreamFeatures) self.register_handler( Callback('Stream Features', MatchXPath('{%s}features' % self.stream_ns), self._handle_stream_features)) self.register_handler( Callback('Roster Update', MatchXPath('{%s}iq/{%s}query' % ( self.default_ns, 'jabber:iq:roster')), self._handle_roster)) # Setup default stream features self.register_plugin('feature_starttls') self.register_plugin('feature_bind') self.register_plugin('feature_session') self.register_plugin('feature_mechanisms', pconfig={'use_mech': sasl_mech} if sasl_mech else None) self.register_plugin('feature_rosterver')
def __init__(self, jid, secret, host, port, plugin_config={}, plugin_whitelist=[], use_jc_ns=False): """ Arguments: jid -- The JID of the component. secret -- The secret or password for the component. host -- The server accepting the component. port -- The port used to connect to the server. plugin_config -- A dictionary of plugin configurations. plugin_whitelist -- A list of desired plugins to load when using register_plugins. use_js_ns -- Indicates if the 'jabber:client' namespace should be used instead of the standard 'jabber:component:accept' namespace. Defaults to False. """ if use_jc_ns: default_ns = 'jabber:client' else: default_ns = 'jabber:component:accept' BaseXMPP.__init__(self, jid, default_ns) self.auto_authorize = None self.stream_header = "<stream:stream %s %s to='%s'>" % ( 'xmlns="jabber:component:accept"', 'xmlns:stream="%s"' % self.stream_ns, jid) self.stream_footer = "</stream:stream>" self.server_host = host self.server_port = port self.secret = secret self.plugin_config = plugin_config self.plugin_whitelist = plugin_whitelist self.is_component = True self.register_handler( Callback('Handshake', MatchXPath('{jabber:component:accept}handshake'), self._handle_handshake)) self.add_event_handler('presence_probe', self._handle_probe)
def start_stream_handler(self, xml): """ Once the streams are established, attempt to handshake with the server to be accepted as a component. :param xml: The incoming stream's root element. """ BaseXMPP.start_stream_handler(self, xml) # Construct a hash of the stream ID and the component secret. sid = xml.get("id", "") pre_hash = "%s%s" % (sid, self.secret) if sys.version_info >= (3, 0): # Handle Unicode byte encoding in Python 3. pre_hash = bytes(pre_hash, "utf-8") handshake = ET.Element("{jabber:component:accept}handshake") handshake.text = hashlib.sha1(pre_hash).hexdigest().lower() self.send_xml(handshake, now=True)
def start_stream_handler(self, xml): """ Once the streams are established, attempt to handshake with the server to be accepted as a component. :param xml: The incoming stream's root element. """ BaseXMPP.start_stream_handler(self, xml) # Construct a hash of the stream ID and the component secret. sid = xml.get('id', '') pre_hash = '%s%s' % (sid, self.secret) if sys.version_info >= (3, 0): # Handle Unicode byte encoding in Python 3. pre_hash = bytes(pre_hash, 'utf-8') handshake = ET.Element('{jabber:component:accept}handshake') handshake.text = hashlib.sha1(pre_hash).hexdigest().lower() self.send_xml(handshake, now=True)
def __init__(self, jid, password, ssl=False, plugin_config={}, plugin_whitelist=[], escape_quotes=True): """ Create a new SleekXMPP client. Arguments: jid -- The JID of the XMPP user account. password -- The password for the XMPP user account. ssl -- Deprecated. plugin_config -- A dictionary of plugin configurations. plugin_whitelist -- A list of approved plugins that will be loaded when calling register_plugins. escape_quotes -- Deprecated. """ BaseXMPP.__init__(self, 'jabber:client') # To comply with PEP8, method names now use underscores. # Deprecated method names are re-mapped for backwards compatibility. self.updateRoster = self.update_roster self.delRosterItem = self.del_roster_item self.getRoster = self.get_roster self.registerFeature = self.register_feature self.set_jid(jid) self.password = password self.escape_quotes = escape_quotes self.plugin_config = plugin_config self.plugin_whitelist = plugin_whitelist self.srv_support = SRV_SUPPORT self.session_started_event = threading.Event() self.session_started_event.clear() self.stream_header = "<stream:stream to='%s' %s %s version='1.0'>" % ( self.boundjid.host, "xmlns:stream='%s'" % self.stream_ns, "xmlns='%s'" % self.default_ns) self.stream_footer = "</stream:stream>" self.features = [] self.registered_features = [] #TODO: Use stream state here self.authenticated = False self.sessionstarted = False self.bound = False self.bindfail = False self.add_event_handler('connected', self.handle_connected) self.register_handler( Callback('Stream Features', MatchXPath('{%s}features' % self.stream_ns), self._handle_stream_features)) self.register_handler( Callback('Roster Update', MatchXPath('{%s}iq/{%s}query' % ( self.default_ns, 'jabber:iq:roster')), self._handle_roster)) self.register_feature( "<starttls xmlns='urn:ietf:params:xml:ns:xmpp-tls' />", self._handle_starttls, True) self.register_feature( "<mechanisms xmlns='urn:ietf:params:xml:ns:xmpp-sasl' />", self._handle_sasl_auth, True) self.register_feature( "<bind xmlns='urn:ietf:params:xml:ns:xmpp-bind' />", self._handle_bind_resource) self.register_feature( "<session xmlns='urn:ietf:params:xml:ns:xmpp-session' />", self._handle_start_session)
def __init__(self, jid, password, ssl=False, plugin_config={}, plugin_whitelist=[], escape_quotes=True): """ Create a new SleekXMPP client. Arguments: jid -- The JID of the XMPP user account. password -- The password for the XMPP user account. ssl -- Deprecated. plugin_config -- A dictionary of plugin configurations. plugin_whitelist -- A list of approved plugins that will be loaded when calling register_plugins. escape_quotes -- Deprecated. """ BaseXMPP.__init__(self, 'jabber:client') # To comply with PEP8, method names now use underscores. # Deprecated method names are re-mapped for backwards compatibility. self.updateRoster = self.update_roster self.delRosterItem = self.del_roster_item self.getRoster = self.get_roster self.registerFeature = self.register_feature self.set_jid(jid) self.password = password self.escape_quotes = escape_quotes self.plugin_config = plugin_config self.plugin_whitelist = plugin_whitelist self.srv_support = SRV_SUPPORT self.session_started_event = threading.Event() self.session_started_event.clear() self.stream_header = "<stream:stream to='%s' %s %s version='1.0'>" % ( self.boundjid.host, "xmlns:stream='%s'" % self.stream_ns, "xmlns='%s'" % self.default_ns) self.stream_footer = "</stream:stream>" self.features = [] self.registered_features = [] #TODO: Use stream state here self.authenticated = False self.sessionstarted = False self.bound = False self.bindfail = False self.add_event_handler('connected', self.handle_connected) self.register_handler( Callback('Stream Features', MatchXPath('{%s}features' % self.stream_ns), self._handle_stream_features)) self.register_handler( Callback( 'Roster Update', MatchXPath('{%s}iq/{%s}query' % (self.default_ns, 'jabber:iq:roster')), self._handle_roster)) self.register_feature( "<starttls xmlns='urn:ietf:params:xml:ns:xmpp-tls' />", self._handle_starttls, True) self.register_feature( "<mechanisms xmlns='urn:ietf:params:xml:ns:xmpp-sasl' />", self._handle_sasl_auth, True) self.register_feature( "<bind xmlns='urn:ietf:params:xml:ns:xmpp-bind' />", self._handle_bind_resource) self.register_feature( "<session xmlns='urn:ietf:params:xml:ns:xmpp-session' />", self._handle_start_session)
def __init__(self, jid, password, ssl=False, plugin_config={}, plugin_whitelist=[], escape_quotes=True, sasl_mech=None): """ Create a new SleekXMPP client. Arguments: jid -- The JID of the XMPP user account. password -- The password for the XMPP user account. ssl -- Deprecated. plugin_config -- A dictionary of plugin configurations. plugin_whitelist -- A list of approved plugins that will be loaded when calling register_plugins. escape_quotes -- Deprecated. """ BaseXMPP.__init__(self, jid, 'jabber:client') self.set_jid(jid) self.password = password self.escape_quotes = escape_quotes self.plugin_config = plugin_config self.plugin_whitelist = plugin_whitelist self.default_port = 5222 self.stream_header = "<stream:stream to='%s' %s %s version='1.0'>" % ( self.boundjid.host, "xmlns:stream='%s'" % self.stream_ns, "xmlns='%s'" % self.default_ns) self.stream_footer = "</stream:stream>" self.features = set() self._stream_feature_handlers = {} self._stream_feature_order = [] #TODO: Use stream state here self.authenticated = False self.sessionstarted = False self.bound = False self.bindfail = False self.add_event_handler('connected', self._handle_connected) self.register_stanza(StreamFeatures) self.register_handler( Callback('Stream Features', MatchXPath('{%s}features' % self.stream_ns), self._handle_stream_features)) self.register_handler( Callback( 'Roster Update', MatchXPath('{%s}iq/{%s}query' % (self.default_ns, 'jabber:iq:roster')), self._handle_roster)) # Setup default stream features self.register_plugin('feature_starttls') self.register_plugin('feature_bind') self.register_plugin('feature_session') self.register_plugin( 'feature_mechanisms', pconfig={'use_mech': sasl_mech} if sasl_mech else None)