summaryrefslogtreecommitdiff
path: root/slixmpp
diff options
context:
space:
mode:
authormathieui <mathieui@mathieui.net>2021-04-18 21:15:22 +0200
committermathieui <mathieui@mathieui.net>2021-04-18 21:15:22 +0200
commit3bb01de1201501d759c6aadb08ecd9ccf0bdc47c (patch)
tree5533bf97fa8a453562ad9977f4c89985d787340d /slixmpp
parent7057773d1878d1b7c2780425d07889d6e5be4082 (diff)
downloadslixmpp-3bb01de1201501d759c6aadb08ecd9ccf0bdc47c.tar.gz
slixmpp-3bb01de1201501d759c6aadb08ecd9ccf0bdc47c.tar.bz2
slixmpp-3bb01de1201501d759c6aadb08ecd9ccf0bdc47c.tar.xz
slixmpp-3bb01de1201501d759c6aadb08ecd9ccf0bdc47c.zip
stanza: add a Handshake class and use it in componentxmpp
Diffstat (limited to 'slixmpp')
-rw-r--r--slixmpp/componentxmpp.py8
-rw-r--r--slixmpp/stanza/__init__.py7
-rw-r--r--slixmpp/stanza/handshake.py25
3 files changed, 36 insertions, 4 deletions
diff --git a/slixmpp/componentxmpp.py b/slixmpp/componentxmpp.py
index 3a16f942..8927712e 100644
--- a/slixmpp/componentxmpp.py
+++ b/slixmpp/componentxmpp.py
@@ -10,6 +10,7 @@ import logging
import hashlib
from slixmpp.basexmpp import BaseXMPP
+from slixmpp.stanza import Handshake
from slixmpp.xmlstream import XMLStream
from slixmpp.xmlstream import ET
from slixmpp.xmlstream.matcher import MatchXPath
@@ -123,9 +124,10 @@ class ComponentXMPP(BaseXMPP):
sid = xml.get('id', '')
pre_hash = bytes('%s%s' % (sid, self.secret), 'utf-8')
- handshake = ET.Element('{jabber:component:accept}handshake')
- handshake.text = hashlib.sha1(pre_hash).hexdigest().lower()
- self.send_xml(handshake)
+ handshake = Handshake()
+ handshake['value'] = hashlib.sha1(pre_hash).hexdigest().lower()
+
+ self.send(handshake)
def _handle_handshake(self, xml):
"""The handshake has been accepted.
diff --git a/slixmpp/stanza/__init__.py b/slixmpp/stanza/__init__.py
index 6e2e9718..1371fad2 100644
--- a/slixmpp/stanza/__init__.py
+++ b/slixmpp/stanza/__init__.py
@@ -1,4 +1,3 @@
-
# Slixmpp: The Slick XMPP Library
# Copyright (C) 2010 Nathanael C. Fritz
# 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.stream_features import StreamFeatures
from slixmpp.stanza.stream_error import StreamError
+from slixmpp.stanza.handshake import Handshake
+
+__all__ = [
+ 'Error', 'Iq', 'Message', 'Presence', 'StreamFeatures', 'StreamError',
+ 'Handshake'
+]
diff --git a/slixmpp/stanza/handshake.py b/slixmpp/stanza/handshake.py
new file mode 100644
index 00000000..c58f69aa
--- /dev/null
+++ b/slixmpp/stanza/handshake.py
@@ -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 = ''