From af360130ec8655f9c947fc97bee2c033d62d2798 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philipp=20H=C3=B6rist?= Date: Sun, 13 Oct 2019 11:57:29 +0200 Subject: Add OOB (XEP-0066) support --- nbxmpp/modules/oob.py | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 nbxmpp/modules/oob.py (limited to 'nbxmpp/modules') diff --git a/nbxmpp/modules/oob.py b/nbxmpp/modules/oob.py new file mode 100644 index 0000000..c0de07f --- /dev/null +++ b/nbxmpp/modules/oob.py @@ -0,0 +1,49 @@ +# Copyright (C) 2018 Philipp Hörist +# +# This file is part of nbxmpp. +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License +# as published by the Free Software Foundation; either version 3 +# of the License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; If not, see . + +import logging + +from nbxmpp.protocol import NS_X_OOB +from nbxmpp.structs import StanzaHandler +from nbxmpp.structs import OOBData + +log = logging.getLogger('nbxmpp.m.oob') + + +class OOB: + def __init__(self, client): + self._client = client + self.handlers = [ + StanzaHandler(name='message', + callback=self._process_message_oob, + ns=NS_X_OOB, + priority=15), + ] + + def _process_message_oob(self, _con, stanza, properties): + oob = stanza.getTag('x', namespace=NS_X_OOB) + if oob is None: + return + + url = oob.getTagData('url') + if url is None: + log.warning('OOB data without url') + log.warning(stanza) + return + + desc = oob.getTagData('desc') + properties.oob = OOBData(url, desc) -- cgit v1.2.3