stanza: add a Handshake class and use it in componentxmpp
This commit is contained in:
parent
7057773d18
commit
3bb01de120
@ -10,6 +10,7 @@ import logging
|
|||||||
import hashlib
|
import hashlib
|
||||||
|
|
||||||
from slixmpp.basexmpp import BaseXMPP
|
from slixmpp.basexmpp import BaseXMPP
|
||||||
|
from slixmpp.stanza import Handshake
|
||||||
from slixmpp.xmlstream import XMLStream
|
from slixmpp.xmlstream import XMLStream
|
||||||
from slixmpp.xmlstream import ET
|
from slixmpp.xmlstream import ET
|
||||||
from slixmpp.xmlstream.matcher import MatchXPath
|
from slixmpp.xmlstream.matcher import MatchXPath
|
||||||
@ -123,9 +124,10 @@ class ComponentXMPP(BaseXMPP):
|
|||||||
sid = xml.get('id', '')
|
sid = xml.get('id', '')
|
||||||
pre_hash = bytes('%s%s' % (sid, self.secret), 'utf-8')
|
pre_hash = bytes('%s%s' % (sid, self.secret), 'utf-8')
|
||||||
|
|
||||||
handshake = ET.Element('{jabber:component:accept}handshake')
|
handshake = Handshake()
|
||||||
handshake.text = hashlib.sha1(pre_hash).hexdigest().lower()
|
handshake['value'] = hashlib.sha1(pre_hash).hexdigest().lower()
|
||||||
self.send_xml(handshake)
|
|
||||||
|
self.send(handshake)
|
||||||
|
|
||||||
def _handle_handshake(self, xml):
|
def _handle_handshake(self, xml):
|
||||||
"""The handshake has been accepted.
|
"""The handshake has been accepted.
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
|
|
||||||
# Slixmpp: The Slick XMPP Library
|
# Slixmpp: The Slick XMPP Library
|
||||||
# Copyright (C) 2010 Nathanael C. Fritz
|
# Copyright (C) 2010 Nathanael C. Fritz
|
||||||
# This file is part of Slixmpp.
|
# This file is part of Slixmpp.
|
||||||
@ -10,3 +9,9 @@ from slixmpp.stanza.message import Message
|
|||||||
from slixmpp.stanza.presence import Presence
|
from slixmpp.stanza.presence import Presence
|
||||||
from slixmpp.stanza.stream_features import StreamFeatures
|
from slixmpp.stanza.stream_features import StreamFeatures
|
||||||
from slixmpp.stanza.stream_error import StreamError
|
from slixmpp.stanza.stream_error import StreamError
|
||||||
|
from slixmpp.stanza.handshake import Handshake
|
||||||
|
|
||||||
|
__all__ = [
|
||||||
|
'Error', 'Iq', 'Message', 'Presence', 'StreamFeatures', 'StreamError',
|
||||||
|
'Handshake'
|
||||||
|
]
|
||||||
|
25
slixmpp/stanza/handshake.py
Normal file
25
slixmpp/stanza/handshake.py
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
# Slixmpp: The Slick XMPP Library
|
||||||
|
# Copyright (C) 2021 Mathieu Pasquet
|
||||||
|
# This file is part of Slixmpp.
|
||||||
|
# See the file LICENSE for copying permission.
|
||||||
|
|
||||||
|
from slixmpp.xmlstream import StanzaBase
|
||||||
|
|
||||||
|
|
||||||
|
class Handshake(StanzaBase):
|
||||||
|
|
||||||
|
"""
|
||||||
|
Jabber Component protocol handshake
|
||||||
|
"""
|
||||||
|
namespace = 'jabber:component:accept'
|
||||||
|
name = 'handshake'
|
||||||
|
interfaces = {'value'}
|
||||||
|
|
||||||
|
def set_value(self, value: str):
|
||||||
|
self.xml.text = value
|
||||||
|
|
||||||
|
def get_value(self) -> str:
|
||||||
|
return self.xml.text
|
||||||
|
|
||||||
|
def del_value(self):
|
||||||
|
self.xml.text = ''
|
Loading…
Reference in New Issue
Block a user