summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--slixmpp/basexmpp.py2
-rw-r--r--slixmpp/plugins/xep_0356/stanza.py11
-rw-r--r--slixmpp/stanza/message.py8
-rw-r--r--slixmpp/xmlstream/xmlstream.py25
-rw-r--r--tests/test_stanza_xep_0356.py2
-rw-r--r--tests/test_stream_xep_0356.py4
6 files changed, 33 insertions, 19 deletions
diff --git a/slixmpp/basexmpp.py b/slixmpp/basexmpp.py
index cd228312..c54ec63a 100644
--- a/slixmpp/basexmpp.py
+++ b/slixmpp/basexmpp.py
@@ -140,7 +140,7 @@ class BaseXMPP(XMLStream):
self.use_presence_ids = True
#: XEP-0359 <origin-id/> tag that gets added to <message/> stanzas.
- self.use_origin_id = True
+ self.use_origin_id = False
#: The API registry is a way to process callbacks based on
#: JID+node combinations. Each callback in the registry is
diff --git a/slixmpp/plugins/xep_0356/stanza.py b/slixmpp/plugins/xep_0356/stanza.py
index ef01ee3e..46f1523a 100644
--- a/slixmpp/plugins/xep_0356/stanza.py
+++ b/slixmpp/plugins/xep_0356/stanza.py
@@ -7,7 +7,7 @@ from slixmpp.plugins.xep_0297 import Forwarded
class Privilege(ElementBase):
- namespace = "urn:xmpp:privilege:1"
+ namespace = "urn:xmpp:privilege:2"
name = "privilege"
plugin_attrib = "privilege"
@@ -24,7 +24,10 @@ class Privilege(ElementBase):
def presence(self):
return self.permission("presence")
-
+
+ def iq(self):
+ return self.permission("iq")
+
def add_perm(self, access, type):
# This should only be needed for servers, so maybe out of scope for slixmpp
perm = Perm()
@@ -34,7 +37,7 @@ class Privilege(ElementBase):
class Perm(ElementBase):
- namespace = "urn:xmpp:privilege:1"
+ namespace = "urn:xmpp:privilege:2"
name = "perm"
plugin_attrib = "perm"
plugin_multi_attrib = "perms"
@@ -44,4 +47,4 @@ class Perm(ElementBase):
def register():
register_stanza_plugin(Message, Privilege)
register_stanza_plugin(Privilege, Forwarded)
- register_stanza_plugin(Privilege, Perm, iterable=True) \ No newline at end of file
+ register_stanza_plugin(Privilege, Perm, iterable=True)
diff --git a/slixmpp/stanza/message.py b/slixmpp/stanza/message.py
index 50d32ff0..eda11df6 100644
--- a/slixmpp/stanza/message.py
+++ b/slixmpp/stanza/message.py
@@ -64,9 +64,9 @@ class Message(RootStanza):
if self.stream:
use_ids = getattr(self.stream, 'use_message_ids', None)
if use_ids:
- self['id'] = self.stream.new_id()
+ self.set_id(self.stream.new_id())
else:
- del self['origin_id']
+ self.del_origin_id()
def get_type(self):
"""
@@ -96,8 +96,8 @@ class Message(RootStanza):
self.xml.attrib['id'] = value
if self.stream:
- use_orig_ids = getattr(self.stream, 'use_origin_id', None)
- if not use_orig_ids:
+ if not getattr(self.stream, 'use_origin_id', False):
+ self.del_origin_id()
return None
sub = self.xml.find(ORIGIN_NAME)
diff --git a/slixmpp/xmlstream/xmlstream.py b/slixmpp/xmlstream/xmlstream.py
index 18143f87..18464ccd 100644
--- a/slixmpp/xmlstream/xmlstream.py
+++ b/slixmpp/xmlstream/xmlstream.py
@@ -493,16 +493,11 @@ class XMLStream(asyncio.BaseProtocol):
except Socket.gaierror as e:
self.event('connection_failed',
'No DNS record available for %s' % self.default_domain)
+ self.reschedule_connection_attempt()
except OSError as e:
log.debug('Connection failed: %s', e)
self.event("connection_failed", e)
- if self._current_connection_attempt is None:
- return
- self._connect_loop_wait = self._connect_loop_wait * 2 + 1
- self._current_connection_attempt = asyncio.ensure_future(
- self._connect_routine(),
- loop=self.loop,
- )
+ self.reschedule_connection_attempt()
def process(self, *, forever: bool = True, timeout: Optional[int] = None) -> None:
"""Process all the available XMPP events (receiving or sending data on the
@@ -638,6 +633,20 @@ class XMLStream(asyncio.BaseProtocol):
self._set_disconnected_future()
self.event("disconnected", self.disconnect_reason or exception)
+ def reschedule_connection_attempt(self) -> None:
+ """
+ Increase the exponential back-off and initate another background
+ _connect_routine call to connect to the server.
+ """
+ # abort if there is no ongoing connection attempt
+ if self._current_connection_attempt is None:
+ return
+ self._connect_loop_wait = min(300, self._connect_loop_wait * 2 + 1)
+ self._current_connection_attempt = asyncio.ensure_future(
+ self._connect_routine(),
+ loop=self.loop,
+ )
+
def cancel_connection_attempt(self) -> None:
"""
Immediately cancel the current create_connection() Future.
@@ -800,6 +809,8 @@ class XMLStream(asyncio.BaseProtocol):
self.ssl_context.verify_mode = ssl.CERT_REQUIRED
self.ssl_context.load_verify_locations(cafile=ca_cert)
+ else:
+ self.ssl_context.set_default_verify_paths()
return self.ssl_context
diff --git a/tests/test_stanza_xep_0356.py b/tests/test_stanza_xep_0356.py
index ef116db2..cf14ccba 100644
--- a/tests/test_stanza_xep_0356.py
+++ b/tests/test_stanza_xep_0356.py
@@ -13,7 +13,7 @@ class TestPermissions(SlixTest):
def testAdvertisePermission(self):
xmlstring = """
<message from='capulet.net' to='pubub.capulet.lit'>
- <privilege xmlns='urn:xmpp:privilege:1'>
+ <privilege xmlns='urn:xmpp:privilege:2'>
<perm access='roster' type='both'/>
<perm access='message' type='outgoing'/>
<perm access='presence' type='managed_entity'/>
diff --git a/tests/test_stream_xep_0356.py b/tests/test_stream_xep_0356.py
index 2949daad..e2ce9569 100644
--- a/tests/test_stream_xep_0356.py
+++ b/tests/test_stream_xep_0356.py
@@ -31,7 +31,7 @@ class TestPermissions(SlixTest):
self.recv(
"""
<message from='capulet.net' to='pubub.capulet.lit' id='54321'>
- <privilege xmlns='urn:xmpp:privilege:1'>
+ <privilege xmlns='urn:xmpp:privilege:2'>
<perm access='roster' type='both'/>
<perm access='message' type='outgoing'/>
</privilege>
@@ -95,7 +95,7 @@ class TestPermissions(SlixTest):
def testMakeOutgoingMessage(self):
xmlstring = """
<message xmlns="jabber:component:accept" from='pubsub.capulet.lit' to='capulet.net'>
- <privilege xmlns='urn:xmpp:privilege:1'>
+ <privilege xmlns='urn:xmpp:privilege:2'>
<forwarded xmlns='urn:xmpp:forward:0'>
<message from="juliet@capulet.lit" to="romeo@montague.lit" xmlns="jabber:client">
<body>I do not hate you</body>