xep_0384: Promote to multiple files
This commit is contained in:
commit
9100f9899b
3 changed files with 113 additions and 0 deletions
15
__init__.py
Normal file
15
__init__.py
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
"""
|
||||||
|
Slixmpp: The Slick XMPP Library
|
||||||
|
Copyright (C) 2018 Maxime “pep” Buquet <pep@bouah.net>
|
||||||
|
This file is part of Slixmpp.
|
||||||
|
|
||||||
|
See the file LICENSE for copying permission.
|
||||||
|
"""
|
||||||
|
|
||||||
|
from slixmpp.plugins.base import register_plugin
|
||||||
|
|
||||||
|
from slixmpp.plugins.xep_0384.omemo import XEP_0384
|
||||||
|
from slixmpp.plugins.xep_0384 import stanza
|
||||||
|
|
||||||
|
|
||||||
|
register_plugin(XEP_0384)
|
60
omemo.py
Normal file
60
omemo.py
Normal file
|
@ -0,0 +1,60 @@
|
||||||
|
"""
|
||||||
|
Slixmpp: The Slick XMPP Library
|
||||||
|
Copyright (C) 2018 Maxime “pep” Buquet <pep@bouah.net>
|
||||||
|
This file is part of Slixmpp.
|
||||||
|
|
||||||
|
See the file LICENSE for copying permission.
|
||||||
|
"""
|
||||||
|
|
||||||
|
import logging
|
||||||
|
|
||||||
|
from slixmpp.jid import JID
|
||||||
|
from slixmpp.plugins.xep_0384.stanza import OMEMO_BASE_NS
|
||||||
|
from slixmpp.plugins.xep_0384.stanza import OMEMO_DEVICES_NS, OMEMO_BUNDLE_NS
|
||||||
|
from slixmpp.plugins.base import BasePlugin, register_plugin
|
||||||
|
|
||||||
|
log = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
class XEP_0384(BasePlugin):
|
||||||
|
|
||||||
|
"""
|
||||||
|
XEP-0384: OMEMO
|
||||||
|
"""
|
||||||
|
|
||||||
|
name = 'xep_0384'
|
||||||
|
description = 'XEP-0384 OMEMO'
|
||||||
|
dependencies = {'xep_0163'}
|
||||||
|
|
||||||
|
device_ids = {}
|
||||||
|
|
||||||
|
def plugin_init(self):
|
||||||
|
self.xmpp.add_event_handler('pubsub_publish', self.device_list)
|
||||||
|
|
||||||
|
def plugin_end(self):
|
||||||
|
self.xmpp.del_event_handler('pubsub_publish', self.device_list)
|
||||||
|
self.xmpp['xep_0163'].remove_interest(OMEMO_DEVICES_NS)
|
||||||
|
|
||||||
|
def session_bind(self, _jid):
|
||||||
|
self.xmpp['xep_0163'].add_interest(OMEMO_DEVICES_NS)
|
||||||
|
|
||||||
|
def device_list(self, msg):
|
||||||
|
if msg['pubsub_event']['items']['node'] != OMEMO_DEVICES_NS:
|
||||||
|
return
|
||||||
|
|
||||||
|
jid = JID(msg['from']).bare
|
||||||
|
items = msg['pubsub_event']['items']
|
||||||
|
for item in items:
|
||||||
|
device_ids = [d['id'] for d in item['list']]
|
||||||
|
if jid not in self.device_ids:
|
||||||
|
self.device_ids[jid] = device_ids
|
||||||
|
self.xmpp.event('omemo_device_ids', (jid, device_ids))
|
||||||
|
|
||||||
|
# XXX: There should only be one item so this is fine, but slixmpp
|
||||||
|
# loops forever otherwise. ???
|
||||||
|
return
|
||||||
|
|
||||||
|
|
||||||
|
register_plugin(XEP_0384)
|
38
stanza.py
Normal file
38
stanza.py
Normal file
|
@ -0,0 +1,38 @@
|
||||||
|
"""
|
||||||
|
Slixmpp: The Slick XMPP Library
|
||||||
|
Copyright (C) 2018 Maxime “pep” Buquet <pep@bouah.net>
|
||||||
|
This file is part of Slixmpp.
|
||||||
|
|
||||||
|
See the file LICENSE for copying permission.
|
||||||
|
"""
|
||||||
|
|
||||||
|
from slixmpp import Message
|
||||||
|
from slixmpp.plugins.xep_0060.stanza.pubsub_event import EventItem
|
||||||
|
from slixmpp.xmlstream import register_stanza_plugin, ElementBase
|
||||||
|
|
||||||
|
OMEMO_BASE_NS = 'eu.siacs.conversations.axolotl'
|
||||||
|
OMEMO_DEVICES_NS = OMEMO_BASE_NS + '.devicelist'
|
||||||
|
OMEMO_BUNDLE_NS = OMEMO_BASE_NS + '.bundle'
|
||||||
|
|
||||||
|
|
||||||
|
class ItemList(ElementBase):
|
||||||
|
namespace = OMEMO_BASE_NS
|
||||||
|
name = 'list'
|
||||||
|
plugin_attrib = 'list'
|
||||||
|
interfaces = set()
|
||||||
|
|
||||||
|
|
||||||
|
class Device(ElementBase):
|
||||||
|
namespace = OMEMO_BASE_NS
|
||||||
|
name = 'device'
|
||||||
|
plugin_attrib = name
|
||||||
|
interfaces = {'id'}
|
||||||
|
|
||||||
|
def get_payload(self):
|
||||||
|
children = list(self.xml)
|
||||||
|
if len(children) > 0:
|
||||||
|
return children[0]
|
||||||
|
|
||||||
|
|
||||||
|
register_stanza_plugin(EventItem, ItemList)
|
||||||
|
register_stanza_plugin(ItemList, Device, iterable=True)
|
Loading…
Reference in a new issue