Skip to content
Snippets Groups Projects
Commit 5c995389 authored by Philipp Hörist's avatar Philipp Hörist
Browse files

SecurityLabels: Adapt to nbxmpp changes

parent 5e3e0ad3
No related branches found
No related tags found
No related merge requests found
......@@ -483,7 +483,8 @@ def _sec_labels_received(self, event):
model.clear()
sel = 0
_label, labellist, default = event.catalog
labellist = event.catalog.get_label_names()
default = event.catalog.default
for index, label in enumerate(labellist):
model.append([label])
if label == default:
......@@ -973,7 +974,7 @@ def get_seclabel(self):
if self._type.is_privatechat:
jid = self.gc_contact.room_jid
catalog = con.get_module('SecLabels').get_catalog(jid)
labels, label_list, _ = catalog
labels, label_list = catalog.labels, catalog.get_label_names()
lname = label_list[idx]
label = labels[lname]
return label
......
......@@ -28,7 +28,6 @@
from gajim.common.const import KindConstant
from gajim.common.modules.base import BaseModule
from gajim.common.modules.util import get_eme_message
from gajim.common.modules.security_labels import parse_securitylabel
from gajim.common.modules.misc import parse_correction
from gajim.common.modules.misc import parse_oob
from gajim.common.modules.misc import parse_xhtml
......@@ -178,6 +177,10 @@ def _message_received(self, _con, stanza, properties):
if properties.eme is not None:
msgtxt = get_eme_message(properties.eme)
displaymarking = None
if properties.has_security_label:
displaymarking = properties.security_label.displaymarking
event_attr = {
'conn': self._con,
'stanza': stanza,
......@@ -195,7 +198,7 @@ def _message_received(self, _con, stanza, properties):
'gc_control': gc_control,
'popup': False,
'msg_log_id': None,
'displaymarking': parse_securitylabel(stanza),
'displaymarking': displaymarking,
'properties': properties,
}
......@@ -306,7 +309,7 @@ def build_message_stanza(self, message):
stanza.setOriginID(message.message_id)
if message.label:
stanza.addChild(node=message.label)
stanza.addChild(node=message.label.to_node())
# XEP-0172: user_nickname
if message.user_nick:
......
......@@ -14,15 +14,22 @@
# XEP-0258: Security Labels in XMPP
import nbxmpp
from nbxmpp.namespaces import Namespace
from nbxmpp.errors import is_error
from gajim.common import app
from gajim.common.nec import NetworkIncomingEvent
from gajim.common.nec import NetworkEvent
from gajim.common.modules.base import BaseModule
from gajim.common.modules.util import as_task
class SecLabels(BaseModule):
_nbxmpp_extends = 'SecurityLabels'
_nbxmpp_methods = [
'request_catalog',
]
def __init__(self, con):
BaseModule.__init__(self, con)
......@@ -36,58 +43,28 @@ def pass_disco(self, info):
self.supported = True
self._log.info('Discovered security labels: %s', info.jid)
@as_task
def request_catalog(self, jid):
server = app.get_jid_from_account(self._account).split("@")[1]
iq = nbxmpp.Iq(typ='get', to=server)
iq.addChild(name='catalog',
namespace=Namespace.SECLABEL_CATALOG,
attrs={'to': jid})
self._log.info('Request catalog: server: %s, to: %s', server, jid)
self._con.connection.SendAndCallForResponse(
iq, self._catalog_received)
def _catalog_received(self, _nbxmpp_client, stanza):
if not nbxmpp.isResultNode(stanza):
self._log.info('Error: %s', stanza.getError())
return
_task = yield
query = stanza.getTag('catalog', namespace=Namespace.SECLABEL_CATALOG)
to = query.getAttr('to')
items = query.getTags('item')
catalog = yield self._nbxmpp('SecurityLabels').request_catalog(jid)
labels = {}
label_list = []
default = None
for item in items:
label = item.getAttr('selector')
labels[label] = item.getTag('securitylabel')
label_list.append(label)
if item.getAttr('default') == 'true':
default = label
if is_error(catalog):
self._log.info(catalog)
return
catalog = (labels, label_list, default)
self._catalogs[to] = catalog
self._catalogs[jid] = catalog
self._log.info('Received catalog: %s', to)
self._log.debug(catalog)
self._log.info('Received catalog: %s', jid)
app.nec.push_incoming_event(SecLabelCatalog(
None, account=self._account, jid=to, catalog=catalog))
app.nec.push_incoming_event(NetworkEvent('sec-catalog-received',
account=self._account,
jid=jid,
catalog=catalog))
def get_catalog(self, jid):
return self._catalogs.get(jid)
def parse_securitylabel(stanza):
seclabel = stanza.getTag('securitylabel', namespace=Namespace.SECLABEL)
if seclabel is None:
return None
return seclabel.getTag('displaymarking')
class SecLabelCatalog(NetworkIncomingEvent):
name = 'sec-catalog-received'
def get_instance(*args, **kwargs):
return SecLabels(*args, **kwargs), 'SecLabels'
......@@ -1084,9 +1084,9 @@ def print_time(self, text, kind, tim, direction_mark, other_tags_for_time, iter_
'time_sometimes')
def print_displaymarking(self, displaymarking, iter_):
bgcolor = displaymarking.getAttr('bgcolor') or '#FFF'
fgcolor = displaymarking.getAttr('fgcolor') or '#000'
text = displaymarking.getData()
bgcolor = displaymarking.bgcolor
fgcolor = displaymarking.fgcolor
text = displaymarking.name
if text:
buffer_ = self.tv.get_buffer()
tag = self.displaymarking_tags.setdefault(bgcolor + '/' + fgcolor,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment