merge bookmark @

This commit is contained in:
Goffi 2021-09-08 11:20:37 +02:00
commit 50d7cb2a51
29 changed files with 277 additions and 150 deletions

View file

@ -1,8 +1,8 @@
.. _contribuing: .. _contributing:
=========== ============
contribuing contributing
=========== ============
This part of the documentation is for people willing to contribute to the development of This part of the documentation is for people willing to contribute to the development of
Libervia and its ecosystem, it is not needed to read this if you only plan to use the Libervia and its ecosystem, it is not needed to read this if you only plan to use the

View file

@ -28,7 +28,7 @@ end-to-end tests
================ ================
End-to-end tests are located in ``tests/e2e``. They are launched in a well defined End-to-end tests are located in ``tests/e2e``. They are launched in a well defined
environment managed through Docker. The ``docker/docker-compose_e2e.yml`` is used to environment managed through Docker. The ``docker/docker-compose-e2e.yml`` is used to
create the suitable containers. create the suitable containers.
A script is available at ``tests/e2e/run_e2e.py`` to launch the tests. It will create the A script is available at ``tests/e2e/run_e2e.py`` to launch the tests. It will create the
@ -68,7 +68,7 @@ In addition to pytest option, some flags can be set with the following arguments
To log-in into the ``backend`` container, you can use the following command, from To log-in into the ``backend`` container, you can use the following command, from
``/docker`` directory:: ``/docker`` directory::
$ docker-compose -f docker-compose_e2e.yml exec backend /bin/bash $ docker-compose -f docker-compose-e2e.yml exec backend /bin/bash
Then run a python console with given instructions Then run a python console with given instructions
@ -224,7 +224,7 @@ test to be sure to have test profiles created and fake SMTP server run…::
…then to go into the ``backend`` container and work with the browser (to be run in ``docker`` …then to go into the ``backend`` container and work with the browser (to be run in ``docker``
directory)…:: directory)…::
$ docker-compose -f docker-compose_e2e.yml exec backend /bin/bash $ docker-compose -f docker-compose-e2e.yml exec backend /bin/bash
…and, inside the container, you can now run ``python3`` and enter instruction prints at …and, inside the container, you can now run ``python3`` and enter instruction prints at
the end of the test session. the end of the test session.

View file

@ -29,7 +29,7 @@ You can follow this documentation to learn more on it, or join our official XMPP
developer.rst developer.rst
/libervia-cli/index.rst /libervia-cli/index.rst
/libervia-tui/index.rst /libervia-tui/index.rst
/contribuing/index.rst /contributing/index.rst
Indices and tables Indices and tables

View file

@ -1,4 +1,5 @@
FROM libervia/backend:dev ARG REVISION=dev
FROM libervia/backend:${REVISION}
LABEL maintainer="Goffi <tmp_dockerfiles@goffi.org>" LABEL maintainer="Goffi <tmp_dockerfiles@goffi.org>"
@ -46,7 +47,7 @@ USER libervia
RUN \ RUN \
# pytest and its plugins # pytest and its plugins
pip install pytest pytest-timeout pytest-dependency \ pip install pytest pytest-timeout pytest-dependency \
# needed to test jp # needed to test libervia-cli
sh \ sh \
# needed to test libervia # needed to test libervia
helium \ helium \
@ -57,7 +58,7 @@ RUN \
RUN ./entrypoint.sh \ RUN ./entrypoint.sh \
# we create the file sharing component which will autoconnect when backend is started # we create the file sharing component which will autoconnect when backend is started
jp profile create file_sharing -j files.server1.test -p "" --xmpp-password test_e2e -C file_sharing -A && \ li profile create file_sharing -j files.server1.test -p "" --xmpp-password test_e2e -C file_sharing -A && \
libervia-backend stop libervia-backend stop
ENV LIBERVIA_TEST_REPORT_DIR=/reports ENV LIBERVIA_TEST_REPORT_DIR=/reports

View file

@ -1,13 +1,15 @@
FROM debian:buster-slim FROM debian:bullseye-slim
LABEL maintainer="Goffi <tmp_dockerfiles@goffi.org>" LABEL maintainer="Goffi <tmp_dockerfiles@goffi.org>"
ARG REVISION
ARG DEBIAN_FRONTEND=noninteractive ARG DEBIAN_FRONTEND=noninteractive
RUN apt-get update && apt-get upgrade -y && \ RUN echo "Building image for Libervia ${REVISION:-dev}" && \
apt-get update && apt-get upgrade -y && \
apt-get install -y --no-install-recommends locales python3-dev python3-venv python3-wheel mercurial libxml2-dev libxslt-dev libcairo2-dev libjpeg-dev libgirepository1.0-dev libdbus-1-dev libdbus-glib-1-dev dbus-x11 cmake && \ apt-get install -y --no-install-recommends locales python3-dev python3-venv python3-wheel mercurial libxml2-dev libxslt-dev libcairo2-dev libjpeg-dev libgirepository1.0-dev libdbus-1-dev libdbus-glib-1-dev dbus-x11 cmake && \
\ \
# will be used to put many SàT specific data # will be used to put many Libervia specific data
mkdir -p /usr/share/libervia/certificates && \ mkdir -p /usr/share/libervia/certificates && \
addgroup tls-cert --gid 9999 && \ addgroup tls-cert --gid 9999 && \
chown :tls-cert /usr/share/libervia/certificates && \ chown :tls-cert /usr/share/libervia/certificates && \
@ -18,12 +20,12 @@ RUN apt-get update && apt-get upgrade -y && \
mkdir /src && chown libervia:libervia /src && \ mkdir /src && chown libervia:libervia /src && \
\ \
# we need UTF-8 locale # we need UTF-8 locale
sed -i "s/# en_US.UTF-8/en_US.UTF-8/" /etc/locale.gen && locale-gen && \ sed -i "s/# en_US.UTF-8/en_US.UTF-8/" /etc/locale.gen && locale-gen
\
# we need a TCP socket for D-Bus
sed -i "s&<listen>unix:tmpdir=/tmp</listen>&\0\n <listen>tcp:host=localhost,bind=*,port=55555,family=ipv4</listen>\n <auth>ANONYMOUS</auth>\n <allow_anonymous/>&" /usr/share/dbus-1/session.conf
ENV LC_ALL en_US.UTF-8 ENV LC_ALL en_US.UTF-8
ENV DOCKER_LIBERVIA_REV=${REVISION:-dev}
COPY --chown=root:root session.conf /usr/share/dbus-1/session.conf
WORKDIR /home/libervia WORKDIR /home/libervia
USER libervia USER libervia
@ -34,15 +36,16 @@ RUN python3 -m venv libervia_env && libervia_env/bin/pip install -U pip wheel &&
# local repos without it them cause troubles # local repos without it them cause troubles
hg clone https://repos.goffi.org/urwid-satext && ~/libervia_env/bin/pip install -e urwid-satext && \ hg clone https://repos.goffi.org/urwid-satext && ~/libervia_env/bin/pip install -e urwid-satext && \
mv urwid-satext/urwid_satext.egg-info ~/libervia_env/lib/python3.*/site-packages && \ mv urwid-satext/urwid_satext.egg-info ~/libervia_env/lib/python3.*/site-packages && \
hg clone https://repos.goffi.org/sat_tmp && ~/libervia_env/bin/pip install -e sat_tmp && \ hg clone https://repos.goffi.org/sat_tmp -u "${REVISION:-tip}" && ~/libervia_env/bin/pip install -e sat_tmp && \
mv sat_tmp/sat_tmp.egg-info ~/libervia_env/lib/python3.*/site-packages && \ mv sat_tmp/sat_tmp.egg-info ~/libervia_env/lib/python3.*/site-packages && \
hg clone https://repos.goffi.org/sat_templates && ~/libervia_env/bin/pip install -e sat_templates && \ hg clone https://repos.goffi.org/libervia-templates && ~/libervia_env/bin/pip install -e libervia-templates && \
mv sat_templates/libervia_templates.egg-info ~/libervia_env/lib/python3.*/site-packages && \ mv libervia-templates/libervia_templates.egg-info ~/libervia_env/lib/python3.*/site-packages && \
hg clone https://repos.goffi.org/sat_media && \ hg clone https://repos.goffi.org/libervia-media && \
hg clone https://repos.goffi.org/sat && ~/libervia_env/bin/pip install -e 'sat[SVG]' && \ hg clone https://repos.goffi.org/libervia-backend -u "${REVISION:-tip}" && ~/libervia_env/bin/pip install -e 'libervia-backend[SVG]' && \
mv sat/libervia_backend.egg-info ~/libervia_env/lib/python3.*/site-packages mv libervia-backend/libervia_backend.egg-info ~/libervia_env/lib/python3.*/site-packages && \
mkdir -p /home/libervia/.local/share/libervia
ENV DBUS_SESSION_BUS_ADDRESS=tcp:host=backend,port=55555,family=ipv4 ENV DBUS_SESSION_BUS_ADDRESS="tcp:host=backend,port=55555,family=ipv4;unix:path=/home/libervia/.local/share/libervia/dbus_socket"
ENV PATH=/home/libervia/libervia_env/bin:$PATH ENV PATH=/home/libervia/libervia_env/bin:$PATH
COPY --chown=root:root libervia.conf /etc/_libervia.conf COPY --chown=root:root libervia.conf /etc/_libervia.conf

View file

@ -1,5 +1,5 @@
[DEFAULT] [DEFAULT]
media_dir = /src/sat_media media_dir = /src/libervia-media
[cli] [cli]
# FIXME: default "auto" value cause trouble # FIXME: default "auto" value cause trouble

View file

@ -0,0 +1,32 @@
<!DOCTYPE busconfig PUBLIC "-//freedesktop//DTD D-Bus Bus Configuration 1.0//EN"
"http://www.freedesktop.org/standards/dbus/1.0/busconfig.dtd">
<busconfig>
<type>session</type>
<keep_umask/>
<listen>unix:path=/home/libervia/.local/share/libervia/dbus_socket</listen>
<listen>tcp:host=localhost,bind=*,port=55555,family=ipv4</listen>
<auth>ANONYMOUS</auth>
<allow_anonymous/>
<standard_session_servicedirs />
<policy context="default">
<allow send_destination="*" eavesdrop="true"/>
<allow eavesdrop="true"/>
<allow own="*"/>
</policy>
<include if_selinux_enabled="yes" selinux_root_relative="yes">contexts/dbus_contexts</include>
<limit name="max_incoming_bytes">1000000000</limit>
<limit name="max_incoming_unix_fds">250000000</limit>
<limit name="max_outgoing_bytes">1000000000</limit>
<limit name="max_outgoing_unix_fds">250000000</limit>
<limit name="max_message_size">1000000000</limit>
<limit name="service_start_timeout">120000</limit>
<limit name="auth_timeout">240000</limit>
<limit name="pending_fd_timeout">150000</limit>
<limit name="max_completed_connections">100000</limit>
<limit name="max_incomplete_connections">10000</limit>
<limit name="max_connections_per_user">100000</limit>
<limit name="max_pending_service_starts">10000</limit>
<limit name="max_names_per_connection">50000</limit>
<limit name="max_match_rules_per_connection">50000</limit>
<limit name="max_replies_per_connection">50000</limit>
</busconfig>

View file

@ -38,8 +38,11 @@ services:
LIBERVIA_PUBSUB_XMPP_PWD: test_e2e LIBERVIA_PUBSUB_XMPP_PWD: test_e2e
backend: backend:
image: libervia/backend:dev-e2e image: libervia/backend:${DOCKER_LIBERVIA_REV:-dev}-e2e
build: backend-dev-e2e build:
context: backend-dev-e2e
args:
REVISION: ${DOCKER_LIBERVIA_REV:-}
environment: environment:
LIBERVIA_TEST_ENV_E2E: "1" LIBERVIA_TEST_ENV_E2E: "1"
LIBERVIA_TEST_ENV_E2E_WEB: "1" LIBERVIA_TEST_ENV_E2E_WEB: "1"
@ -54,8 +57,11 @@ services:
- libervia-backend.test - libervia-backend.test
web: web:
image: libervia/web:dev-e2e image: libervia/web:${DOCKER_LIBERVIA_REV:-dev}-e2e
build: libervia-web-dev-e2e build:
context: libervia-web-dev-e2e
args:
REVISION: ${DOCKER_LIBERVIA_REV:-}
depends_on: depends_on:
- backend - backend
environment: environment:

View file

@ -2,11 +2,17 @@ version: "3.6"
services: services:
backend: backend:
image: libervia/backend:dev image: "libervia/backend:${DOCKER_LIBERVIA_REV:-dev}"
build: backend-dev build:
context: backend-dev
args:
REVISION: "${DOCKER_LIBERVIA_REV:-}"
web: web:
image: libervia/web:dev image: "libervia/web:${DOCKER_LIBERVIA_REV:-dev}"
build: libervia-web-dev build:
context: libervia-web-dev
args:
REVISION: "${DOCKER_LIBERVIA_REV:-}"
depends_on: depends_on:
- backend - backend

View file

@ -1,4 +1,5 @@
FROM libervia/web:dev ARG REVISION=dev
FROM libervia/web:${REVISION}
LABEL maintainer="Goffi <tmp_dockerfiles@goffi.org>" LABEL maintainer="Goffi <tmp_dockerfiles@goffi.org>"

View file

@ -1,4 +1,5 @@
FROM libervia/web:dev ARG REVISION=dev
FROM libervia/web:${REVISION}
LABEL maintainer="Goffi <tmp_dockerfiles@goffi.org>" LABEL maintainer="Goffi <tmp_dockerfiles@goffi.org>"

View file

@ -1,7 +1,9 @@
FROM libervia/backend:dev ARG REVISION
FROM libervia/backend:${REVISION:-dev}
LABEL maintainer="Goffi <tmp_dockerfiles@goffi.org>" LABEL maintainer="Goffi <tmp_dockerfiles@goffi.org>"
ARG REVISION
ARG DEBIAN_FRONTEND=noninteractive ARG DEBIAN_FRONTEND=noninteractive
USER root USER root
@ -9,9 +11,9 @@ USER root
RUN apt-get install -y --no-install-recommends yarnpkg RUN apt-get install -y --no-install-recommends yarnpkg
WORKDIR /home/libervia WORKDIR /home/libervia
USER libervia USER libervia
RUN cd /src && hg clone https://repos.goffi.org/libervia && \ RUN cd /src && hg clone https://repos.goffi.org/libervia-web -u "${REVISION:-tip}" && \
~/libervia_env/bin/pip install -e libervia && \ ~/libervia_env/bin/pip install -e libervia-web && \
mv libervia/libervia_web.egg-info ~/libervia_env/lib/python3.*/site-packages mv libervia-web/libervia_web.egg-info ~/libervia_env/lib/python3.*/site-packages
RUN ./entrypoint.sh \ RUN ./entrypoint.sh \
# we build here to avoid re-downloading node modules or other browser # we build here to avoid re-downloading node modules or other browser

View file

@ -1,4 +1,4 @@
FROM debian:buster-slim FROM debian:bullseye-slim
LABEL maintainer="Goffi <tmp_dockerfiles@goffi.org>" LABEL maintainer="Goffi <tmp_dockerfiles@goffi.org>"
@ -29,6 +29,6 @@ RUN python3 -m venv libervia_env && libervia_env/bin/pip install -U pip wheel &&
hg clone https://repos.goffi.org/sat_tmp && ~/libervia_env/bin/pip install -e sat_tmp && \ hg clone https://repos.goffi.org/sat_tmp && ~/libervia_env/bin/pip install -e sat_tmp && \
mv sat_tmp/sat_tmp.egg-info ~/libervia_env/lib/python3.*/site-packages && \ mv sat_tmp/sat_tmp.egg-info ~/libervia_env/lib/python3.*/site-packages && \
hg clone https://repos.goffi.org/sat_pubsub && ~/libervia_env/bin/pip install -e sat_pubsub && \ hg clone https://repos.goffi.org/sat_pubsub && ~/libervia_env/bin/pip install -e sat_pubsub && \
mv sat_pubsub/libervia_pubsub.egg-info ~/libervia_env/lib/python3.*/site-packages mv sat_pubsub/sat_pubsub.egg-info ~/libervia_env/lib/python3.*/site-packages
ENTRYPOINT ["/home/libervia/entrypoint.sh"] ENTRYPOINT ["/home/libervia/entrypoint.sh"]

View file

@ -140,7 +140,21 @@ class Bridge:
kwargs['reply_handler'] = _callback kwargs['reply_handler'] = _callback
kwargs['error_handler'] = lambda err: _errback(dbus_to_bridge_exception(err)) kwargs['error_handler'] = lambda err: _errback(dbus_to_bridge_exception(err))
return method(*args, **kwargs) try:
return method(*args, **kwargs)
except ValueError as e:
if e.args[0].startswith("Unable to guess signature"):
# XXX: if frontend is started too soon after backend, the
# inspection misses methods (notably plugin dynamically added
# methods). The following hack works around that by redoing the
# cache of introspected methods signatures.
log.debug("using hack to work around inspection issue")
proxy = self.db_plugin_iface.proxy_object
IN_PROGRESS = proxy.INTROSPECT_STATE_INTROSPECT_IN_PROGRESS
proxy._introspect_state = IN_PROGRESS
proxy._Introspect()
return self.db_plugin_iface.get_dbus_method(name)(*args, **kwargs)
raise e
return getPluginMethod return getPluginMethod
@ -167,13 +181,32 @@ class AIOBridge(Bridge):
fut.set_result, ret) fut.set_result, ret)
error_handler = lambda err: loop.call_soon_threadsafe( error_handler = lambda err: loop.call_soon_threadsafe(
fut.set_exception, dbus_to_bridge_exception(err)) fut.set_exception, dbus_to_bridge_exception(err))
method( try:
*args, method(
**kwargs, *args,
timeout=const_TIMEOUT, **kwargs,
reply_handler=reply_handler, timeout=const_TIMEOUT,
error_handler=error_handler reply_handler=reply_handler,
) error_handler=error_handler
)
except ValueError as e:
if e.args[0].startswith("Unable to guess signature"):
# same hack as for Bridge.__getattribute__
log.warning("using hack to work around inspection issue")
proxy = self.db_plugin_iface.proxy_object
IN_PROGRESS = proxy.INTROSPECT_STATE_INTROSPECT_IN_PROGRESS
proxy._introspect_state = IN_PROGRESS
proxy._Introspect()
self.db_plugin_iface.get_dbus_method(name)(
*args,
**kwargs,
timeout=const_TIMEOUT,
reply_handler=reply_handler,
error_handler=error_handler
)
else:
raise e
return fut return fut
return getPluginMethod return getPluginMethod

View file

@ -228,11 +228,7 @@ class SAT(service.Service):
ui_contact_list.ContactList(self) ui_contact_list.ContactList(self)
ui_profile_manager.ProfileManager(self) ui_profile_manager.ProfileManager(self)
except Exception as e: except Exception as e:
log.error( log.error(f"Could not initialize backend: {e}")
_("Could not initialize backend: {reason}").format(
reason=str(e).decode("utf-8", "ignore")
)
)
sys.exit(1) sys.exit(1)
self._addBaseMenus() self._addBaseMenus()
@ -344,6 +340,12 @@ class SAT(service.Service):
plugin_modes = plugin_info["modes"] = set( plugin_modes = plugin_info["modes"] = set(
plugin_info.setdefault("modes", C.PLUG_MODE_DEFAULT) plugin_info.setdefault("modes", C.PLUG_MODE_DEFAULT)
) )
if not plugin_modes.intersection(C.PLUG_MODE_BOTH):
log.error(
f"Can't import plugin at {plugin_path}, invalid {C.PI_MODES!r} "
f"value: {plugin_modes!r}"
)
continue
# if the plugin is an entry point, it must work in component mode # if the plugin is an entry point, it must work in component mode
if plugin_info["type"] == C.PLUG_TYPE_ENTRY_POINT: if plugin_info["type"] == C.PLUG_TYPE_ENTRY_POINT:

View file

@ -204,7 +204,7 @@ class LazyPersistentBinaryDict(PersistentBinaryDict):
)) ))
def __repr__(self): def __repr__(self):
raise NotImplementedError return self.__str__()
def __str__(self): def __str__(self):
return "LazyPersistentBinaryDict (namespace: {})".format(self.namespace) return "LazyPersistentBinaryDict (namespace: {})".format(self.namespace)

View file

@ -309,9 +309,11 @@ class AndroidPlugin(object):
# "XXX has no attribute 'invoke'" error (looks like the same issue as # "XXX has no attribute 'invoke'" error (looks like the same issue as
# https://github.com/kivy/pyjnius/issues/59) # https://github.com/kivy/pyjnius/issues/59)
self.br = BroadcastReceiver( self.br = BroadcastReceiver(
callback=lambda *args, **kwargs: reactor.callLater(0, callback=lambda *args, **kwargs: reactor.callFromThread(
self.onConnectivityChange), self.onConnectivityChange
actions=["android.net.conn.CONNECTIVITY_CHANGE"]) ),
actions=["android.net.conn.CONNECTIVITY_CHANGE"]
)
self.br.start() self.br.start()
@property @property

View file

@ -237,8 +237,8 @@ class FilePlugin:
data_cb=file_data.get("data_cb"), data_cb=file_data.get("data_cb"),
) )
def _gotConfirmation( async def _gotConfirmation(
self, data, client, peer_jid, transfer_data, file_data, stream_object self, client, data, peer_jid, transfer_data, file_data, stream_object
): ):
"""Called when the permission and dest path have been received """Called when the permission and dest path have been received
@ -258,19 +258,7 @@ class FilePlugin:
# we manage case where file already exists # we manage case where file already exists
if os.path.exists(file_path): if os.path.exists(file_path):
overwrite = await xml_tools.deferConfirm(
def check_overwrite(overwrite):
if overwrite:
self.openFileWrite(
client, file_path, transfer_data, file_data, stream_object
)
return True
else:
return defer.ensureDeferred(
self.getDestDir(client, peer_jid, transfer_data, file_data)
)
exists_d = xml_tools.deferConfirm(
self.host, self.host,
_(CONFIRM_OVERWRITE).format(file_path), _(CONFIRM_OVERWRITE).format(file_path),
_(CONFIRM_OVERWRITE_TITLE), _(CONFIRM_OVERWRITE_TITLE),
@ -282,8 +270,9 @@ class FilePlugin:
security_limit=SECURITY_LIMIT, security_limit=SECURITY_LIMIT,
profile=client.profile, profile=client.profile,
) )
exists_d.addCallback(check_overwrite)
return exists_d if not overwrite:
return await self.getDestDir(client, peer_jid, transfer_data, file_data)
self.openFileWrite(client, file_path, transfer_data, file_data, stream_object) self.openFileWrite(client, file_path, transfer_data, file_data, stream_object)
return True return True
@ -315,7 +304,7 @@ class FilePlugin:
"size_human" will also be added with human readable file size "size_human" will also be added with human readable file size
@param stream_object(bool): if True, a stream_object will be used instead of file_obj @param stream_object(bool): if True, a stream_object will be used instead of file_obj
a stream.FileStreamObject will be used a stream.FileStreamObject will be used
return (defer.Deferred): True if transfer is accepted return: True if transfer is accepted
""" """
cont, ret_value = await self.host.trigger.asyncReturnPoint( cont, ret_value = await self.host.trigger.asyncReturnPoint(
"FILE_getDestDir", client, peer_jid, transfer_data, file_data, stream_object "FILE_getDestDir", client, peer_jid, transfer_data, file_data, stream_object
@ -327,7 +316,7 @@ class FilePlugin:
assert PROGRESS_ID_KEY in file_data assert PROGRESS_ID_KEY in file_data
# human readable size # human readable size
file_data["size_human"] = common_utils.getHumanSize(file_data["size"]) file_data["size_human"] = common_utils.getHumanSize(file_data["size"])
d = xml_tools.deferDialog( resp_data = await xml_tools.deferDialog(
self.host, self.host,
_(CONFIRM).format(peer=peer_jid.full(), **file_data), _(CONFIRM).format(peer=peer_jid.full(), **file_data),
_(CONFIRM_TITLE), _(CONFIRM_TITLE),
@ -341,12 +330,13 @@ class FilePlugin:
security_limit=SECURITY_LIMIT, security_limit=SECURITY_LIMIT,
profile=client.profile, profile=client.profile,
) )
d.addCallback(
self._gotConfirmation, accepted = await self._gotConfirmation(
client, client,
resp_data,
peer_jid, peer_jid,
transfer_data, transfer_data,
file_data, file_data,
stream_object, stream_object,
) )
return d return accepted

View file

@ -19,7 +19,6 @@
import time import time
import dateutil import dateutil
import calendar import calendar
import urllib.parse
from secrets import token_urlsafe from secrets import token_urlsafe
from typing import Optional from typing import Optional
from functools import partial from functools import partial
@ -1032,13 +1031,12 @@ class XEP_0277(object):
will return(JID(u'sat-pubsub.example.net'), 'urn:xmpp:comments:_af43b363-3259-4b2a-ba4c-1bc33aa87634__urn:xmpp:groupblog:somebody@example.net') will return(JID(u'sat-pubsub.example.net'), 'urn:xmpp:comments:_af43b363-3259-4b2a-ba4c-1bc33aa87634__urn:xmpp:groupblog:somebody@example.net')
@return (tuple[jid.JID, unicode]): service and node @return (tuple[jid.JID, unicode]): service and node
""" """
parsed_url = urllib.parse.urlparse(node_url, "xmpp") try:
service = jid.JID(parsed_url.path) parsed_url = xmpp_uri.parseXMPPUri(node_url)
parsed_queries = urllib.parse.parse_qs(parsed_url.query) service = jid.JID(parsed_url["path"])
node = parsed_queries.get("node", [""])[0] node = parsed_url["node"]
except Exception as e:
if not node: raise exceptions.DataError(f"Invalid comments link: {e}")
raise exceptions.DataError("Invalid comments link")
return (service, node) return (service, node)

View file

@ -19,7 +19,7 @@
from zope.interface import implementer from zope.interface import implementer
from twisted.internet import defer from twisted.internet import defer
from twisted.internet import reactor from twisted.internet import reactor
from twisted.words.protocols.jabber import xmlstream, jid from twisted.words.protocols.jabber import xmlstream, jid, error
from twisted.words.xish import domish from twisted.words.xish import domish
from wokkel import disco, iwokkel from wokkel import disco, iwokkel
from sat.core.i18n import _, D_ from sat.core.i18n import _, D_
@ -38,7 +38,7 @@ PLUGIN_INFO = {
C.PI_NAME: "Jingle Message Initiation", C.PI_NAME: "Jingle Message Initiation",
C.PI_IMPORT_NAME: "XEP-0353", C.PI_IMPORT_NAME: "XEP-0353",
C.PI_TYPE: "XEP", C.PI_TYPE: "XEP",
C.PI_MODES: C.PLUG_MODE_CLIENT, C.PI_MODES: [C.PLUG_MODE_CLIENT],
C.PI_PROTOCOLS: ["XEP-0353"], C.PI_PROTOCOLS: ["XEP-0353"],
C.PI_DEPENDENCIES: ["XEP-0166"], C.PI_DEPENDENCIES: ["XEP-0166"],
C.PI_MAIN: "XEP_0353", C.PI_MAIN: "XEP_0353",
@ -85,8 +85,15 @@ class XEP_0353:
if peer_jid.resource: if peer_jid.resource:
return True return True
infos = await self.host.memory.disco.getInfos(client, peer_jid) try:
categories = {c for c, __ in infos.identities} infos = await self.host.memory.disco.getInfos(client, peer_jid)
except error.StanzaError as e:
if e.condition == "service-unavailable":
categories = {}
else:
raise e
else:
categories = {c for c, __ in infos.identities}
if "component" in categories: if "component" in categories:
# we don't use message initiation with components # we don't use message initiation with components
return True return True

Some files were not shown because too many files have changed in this diff Show more