Initial support for XEP-0258
This commit is contained in:
parent
0b7f134021
commit
5c4f7bfe8b
5 changed files with 202 additions and 0 deletions
1
setup.py
1
setup.py
|
@ -91,6 +91,7 @@ packages = [ 'sleekxmpp',
|
||||||
'sleekxmpp/plugins/xep_0224',
|
'sleekxmpp/plugins/xep_0224',
|
||||||
'sleekxmpp/plugins/xep_0231',
|
'sleekxmpp/plugins/xep_0231',
|
||||||
'sleekxmpp/plugins/xep_0249',
|
'sleekxmpp/plugins/xep_0249',
|
||||||
|
'sleekxmpp/plugins/xep_0258',
|
||||||
'sleekxmpp/features',
|
'sleekxmpp/features',
|
||||||
'sleekxmpp/features/feature_mechanisms',
|
'sleekxmpp/features/feature_mechanisms',
|
||||||
'sleekxmpp/features/feature_mechanisms/stanza',
|
'sleekxmpp/features/feature_mechanisms/stanza',
|
||||||
|
|
|
@ -52,4 +52,5 @@ __all__ = [
|
||||||
'xep_0224', # Attention
|
'xep_0224', # Attention
|
||||||
'xep_0231', # Bits of Binary
|
'xep_0231', # Bits of Binary
|
||||||
'xep_0249', # Direct MUC Invitations
|
'xep_0249', # Direct MUC Invitations
|
||||||
|
'xep_0258', # Security Labels in XMPP
|
||||||
]
|
]
|
||||||
|
|
18
sleekxmpp/plugins/xep_0258/__init__.py
Normal file
18
sleekxmpp/plugins/xep_0258/__init__.py
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
"""
|
||||||
|
SleekXMPP: The Sleek XMPP Library
|
||||||
|
Copyright (C) 2010 Nathanael C. Fritz, Lance J.T. Stout
|
||||||
|
This file is part of SleekXMPP.
|
||||||
|
|
||||||
|
See the file LICENSE for copying permission.
|
||||||
|
"""
|
||||||
|
|
||||||
|
from sleekxmpp.plugins.base import register_plugin
|
||||||
|
|
||||||
|
from sleekxmpp.plugins.xep_0258 import stanza
|
||||||
|
from sleekxmpp.plugins.xep_0258.stanza import SecurityLabel, Label
|
||||||
|
from sleekxmpp.plugins.xep_0258.stanza import DisplayMarking, EquivalentLabel
|
||||||
|
from sleekxmpp.plugins.xep_0258.stanza import ESSLabel, Catalog, CatalogItem
|
||||||
|
from sleekxmpp.plugins.xep_0258.security_labels import XEP_0258
|
||||||
|
|
||||||
|
|
||||||
|
register_plugin(XEP_0258)
|
40
sleekxmpp/plugins/xep_0258/security_labels.py
Normal file
40
sleekxmpp/plugins/xep_0258/security_labels.py
Normal file
|
@ -0,0 +1,40 @@
|
||||||
|
"""
|
||||||
|
SleekXMPP: The Sleek XMPP Library
|
||||||
|
Copyright (C) 2012 Nathanael C. Fritz, Lance J.T. Stout
|
||||||
|
This file is part of SleekXMPP.
|
||||||
|
|
||||||
|
See the file LICENSE for copying permission.
|
||||||
|
"""
|
||||||
|
|
||||||
|
import logging
|
||||||
|
|
||||||
|
from sleekxmpp import Iq, Message
|
||||||
|
from sleekxmpp.plugins import BasePlugin
|
||||||
|
from sleekxmpp.xmlstream import register_stanza_plugin
|
||||||
|
from sleekxmpp.plugins.xep_0258 import stanza, SecurityLabel, Catalog
|
||||||
|
|
||||||
|
|
||||||
|
log = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
|
class XEP_0258(BasePlugin):
|
||||||
|
|
||||||
|
name = 'xep_0258'
|
||||||
|
description = 'XEP-0258: Security Labels in XMPP'
|
||||||
|
dependencies = set(['xep_0030'])
|
||||||
|
stanza = stanza
|
||||||
|
|
||||||
|
def plugin_init(self):
|
||||||
|
self.xmpp['xep_0030'].add_feature(SecurityLabel.namespace)
|
||||||
|
|
||||||
|
register_stanza_plugin(Message, SecurityLabel)
|
||||||
|
register_stanza_plugin(Iq, Catalog)
|
||||||
|
|
||||||
|
def get_catalog(self, jid, ifrom=None, block=True,
|
||||||
|
callback=None, timeout=None):
|
||||||
|
iq = self.xmpp.Iq()
|
||||||
|
iq['to'] = jid
|
||||||
|
iq['from'] = ifrom
|
||||||
|
iq['type'] = 'get'
|
||||||
|
iq.enable('security_label_catalog')
|
||||||
|
return iq.send(block=block, callback=callback, timeout=timeout)
|
142
sleekxmpp/plugins/xep_0258/stanza.py
Normal file
142
sleekxmpp/plugins/xep_0258/stanza.py
Normal file
|
@ -0,0 +1,142 @@
|
||||||
|
"""
|
||||||
|
SleekXMPP: The Sleek XMPP Library
|
||||||
|
Copyright (C) 2012 Nathanael C. Fritz, Lance J.T. Stout
|
||||||
|
This file is part of SleekXMPP.
|
||||||
|
|
||||||
|
See the file LICENSE for copying permission.
|
||||||
|
"""
|
||||||
|
|
||||||
|
from base64 import b64encode, b64decode
|
||||||
|
|
||||||
|
from sleekxmpp.thirdparty.suelta.util import bytes
|
||||||
|
|
||||||
|
from sleekxmpp.xmlstream import ElementBase, ET, register_stanza_plugin
|
||||||
|
|
||||||
|
|
||||||
|
class SecurityLabel(ElementBase):
|
||||||
|
name = 'securitylabel'
|
||||||
|
namespace = 'urn:xmpp:sec-label:0'
|
||||||
|
plugin_attrib = 'security_label'
|
||||||
|
|
||||||
|
def add_equivalent(self, label):
|
||||||
|
equiv = EquivalentLabel(parent=self)
|
||||||
|
equiv.append(label)
|
||||||
|
return equiv
|
||||||
|
|
||||||
|
|
||||||
|
class Label(ElementBase):
|
||||||
|
name = 'label'
|
||||||
|
namespace = 'urn:xmpp:sec-label:0'
|
||||||
|
plugin_attrib = 'label'
|
||||||
|
|
||||||
|
|
||||||
|
class DisplayMarking(ElementBase):
|
||||||
|
name = 'displaymarking'
|
||||||
|
namespace = 'urn:xmpp:sec-label:0'
|
||||||
|
plugin_attrib = 'display_marking'
|
||||||
|
interfaces = set(['fgcolor', 'bgcolor', 'value'])
|
||||||
|
|
||||||
|
def get_fgcolor(self):
|
||||||
|
return self._get_attr('fgcolor', 'black')
|
||||||
|
|
||||||
|
def get_bgcolor(self):
|
||||||
|
return self._get_attr('fgcolor', 'white')
|
||||||
|
|
||||||
|
def get_value(self):
|
||||||
|
return self.xml.text
|
||||||
|
|
||||||
|
def set_value(self, value):
|
||||||
|
self.xml.text = value
|
||||||
|
|
||||||
|
def del_value(self):
|
||||||
|
self.xml.text = ''
|
||||||
|
|
||||||
|
|
||||||
|
class EquivalentLabel(ElementBase):
|
||||||
|
name = 'equivalentlabel'
|
||||||
|
namespace = 'urn:xmpp:sec-label:0'
|
||||||
|
plugin_attrib = 'equivalent_label'
|
||||||
|
plugin_multi_attrib = 'equivalent_labels'
|
||||||
|
|
||||||
|
|
||||||
|
class Catalog(ElementBase):
|
||||||
|
name = 'catalog'
|
||||||
|
namespace = 'urn:xmpp:sec-label:catalog:2'
|
||||||
|
plugin_attrib = 'security_label_catalog'
|
||||||
|
interfaces = set(['to', 'from', 'name', 'desc', 'id', 'size', 'restrict'])
|
||||||
|
|
||||||
|
def get_to(self):
|
||||||
|
return JID(self._get_attr('to'))
|
||||||
|
pass
|
||||||
|
|
||||||
|
def set_to(self, value):
|
||||||
|
return self._set_attr('to', str(value))
|
||||||
|
|
||||||
|
def get_from(self):
|
||||||
|
return JID(self._get_attr('from'))
|
||||||
|
|
||||||
|
def set_from(self, value):
|
||||||
|
return self._set_attr('from', str(value))
|
||||||
|
|
||||||
|
def get_restrict(self):
|
||||||
|
value = self._get_attr('restrict', '')
|
||||||
|
if value and value.lower() in ('true', '1'):
|
||||||
|
return True
|
||||||
|
return False
|
||||||
|
|
||||||
|
def set_restrict(self, value):
|
||||||
|
self._del_attr('restrict')
|
||||||
|
if value:
|
||||||
|
self._set_attr('restrict', 'true')
|
||||||
|
elif value == False:
|
||||||
|
self._set_attr('restrict', 'false')
|
||||||
|
|
||||||
|
|
||||||
|
class CatalogItem(ElementBase):
|
||||||
|
name = 'catalog'
|
||||||
|
namespace = 'urn:xmpp:sec-label:catalog:2'
|
||||||
|
plugin_attrib = 'item'
|
||||||
|
plugin_multi_attrib = 'items'
|
||||||
|
interfaces = set(['selector', 'default'])
|
||||||
|
|
||||||
|
def get_default(self):
|
||||||
|
value = self._get_attr('default', '')
|
||||||
|
if value.lower() in ('true', '1'):
|
||||||
|
return True
|
||||||
|
return False
|
||||||
|
|
||||||
|
def set_default(self, value):
|
||||||
|
self._del_attr('default')
|
||||||
|
if value:
|
||||||
|
self._set_attr('default', 'true')
|
||||||
|
elif value == False:
|
||||||
|
self._set_attr('default', 'false')
|
||||||
|
|
||||||
|
|
||||||
|
class ESSLabel(ElementBase):
|
||||||
|
name = 'esssecuritylabel'
|
||||||
|
namespace = 'urn:xmpp:sec-label:ess:0'
|
||||||
|
plugin_attrib = 'ess'
|
||||||
|
interfaces = set(['value'])
|
||||||
|
|
||||||
|
def get_value(self):
|
||||||
|
if self.xml.text:
|
||||||
|
return b64decode(bytes(self.xml.text))
|
||||||
|
return ''
|
||||||
|
|
||||||
|
def set_value(self, value):
|
||||||
|
self.xml.text = ''
|
||||||
|
if value:
|
||||||
|
self.xml.text = b64encode(bytes(value))
|
||||||
|
|
||||||
|
def del_value(self):
|
||||||
|
self.xml.text = ''
|
||||||
|
|
||||||
|
|
||||||
|
register_stanza_plugin(Catalog, CatalogItem, iterable=True)
|
||||||
|
register_stanza_plugin(CatalogItem, SecurityLabel)
|
||||||
|
register_stanza_plugin(EquivalentLabel, ESSLabel)
|
||||||
|
register_stanza_plugin(Label, ESSLabel)
|
||||||
|
register_stanza_plugin(SecurityLabel, DisplayMarking)
|
||||||
|
register_stanza_plugin(SecurityLabel, EquivalentLabel, iterable=True)
|
||||||
|
register_stanza_plugin(SecurityLabel, Label)
|
Loading…
Reference in a new issue