1# Copyright (C) 2018 Philipp Hörist <philipp AT hoerist.com> 2# 3# This file is part of nbxmpp. 4# 5# This program is free software; you can redistribute it and/or 6# modify it under the terms of the GNU General Public License 7# as published by the Free Software Foundation; either version 3 8# of the License, or (at your option) any later version. 9# 10# This program is distributed in the hope that it will be useful, 11# but WITHOUT ANY WARRANTY; without even the implied warranty of 12# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13# GNU General Public License for more details. 14# 15# You should have received a copy of the GNU General Public License 16# along with this program; If not, see <http://www.gnu.org/licenses/>. 17 18from nbxmpp.namespaces import Namespace 19from nbxmpp.structs import StanzaHandler 20from nbxmpp.structs import EMEData 21from nbxmpp.modules.base import BaseModule 22 23 24class EME(BaseModule): 25 def __init__(self, client): 26 BaseModule.__init__(self, client) 27 28 self._client = client 29 self.handlers = [ 30 StanzaHandler(name='message', 31 callback=self._process_eme, 32 ns=Namespace.EME, 33 priority=40) 34 ] 35 36 def _process_eme(self, _client, stanza, properties): 37 encryption = stanza.getTag('encryption', namespace=Namespace.EME) 38 if encryption is None: 39 return 40 41 name = encryption.getAttr('name') 42 namespace = encryption.getAttr('namespace') 43 if namespace is None: 44 self._log.warning('No namespace on message') 45 return 46 47 properties.eme = EMEData(name=name, namespace=namespace) 48 self._log.info('Found data: %s', properties.eme) 49