Commit graph libervia-backend/sat/core/xmpp.py
Author SHA1 Message Date
Goffi
da22ab2ce2 core (xmpp): client.roster now implements __contains__
Now a jid can be tested directly with "entity_jid in client.roster".
2020-11-12 14:53:15 +01:00
Goffi
459c169e63 doc, core: typos 2020-11-12 14:53:11 +01:00
Goffi
50df9e6537 plugin XEP-0329, core(xmpp): moved _compParseJids to SatXMPPComponent:
This method to retrieve owner and peer JID from an element is generally useful for
components, thus it has been moved. The part to retrieve owner JID from local JID has been
splitted in its own `getOwnerFromJid` method.
2020-09-20 14:04:11 +02:00
Goffi
edd33a126d core (xmpp): text can now be specified in sendError 2020-08-01 15:59:49 +02:00
Goffi
88072e0453 core, frontends: avatar refactoring:
/!\ huge commit

Avatar logic has been reworked around the IDENTITY plugin: plugins able to handle avatar
or other identity related metadata (like nicknames) register to IDENTITY plugin in the
same way as for other features like download/upload. Once registered, IDENTITY plugin will
call them when suitable in order of priority, and handle caching.

Methods to manage those metadata from frontend now use serialised data.

For now `avatar` and `nicknames` are handled:

- `avatar` is now a dict with `path` + metadata like `media_type`, instead of just a string
  path
- `nicknames` is now a list of nicknames in order of priority. This list is never empty,
  and `nicknames[0]` should be the preferred nickname to use by frontends in most cases.
  In addition to contact specified nicknames, user set nickname (the one set in roster) is
  used in priority when available.

Among the side changes done with this commit, there are:

- a new `contactGet` bridge method to get roster metadata for a single contact
- SatPresenceProtocol.send returns a Deferred to check when it has actually been sent
- memory's methods to handle entities data now use `client` as first argument
- metadata filter can be specified with `getIdentity`
- `getAvatar` and `setAvatar` are now part of the IDENTITY plugin instead of XEP-0054 (and
  there signature has changed)
- `isRoom` and `getBareOrFull` are now part of XEP-0045 plugin
- jp avatar/get command uses `xdg-open` first when available for `--show` flag
- `--no-cache` has been added to jp avatar/get and identity/get
- jp identity/set has been simplified, explicit options (`--nickname` only for now) are
  used instead of `--field`. `--field` may come back in the future if necessary for extra
  data.
- QuickContactList `SetContact` now handle None as a value, and doesn't use it to delete the
  metadata anymore
- improved cache handling for `metadata` and `nicknames` in quick frontend
- new `default` argument in QuickContactList `getCache`
2020-04-14 21:00:33 +02:00
Goffi
7201730938 core (xmpp): helper method to launch a plugin method:
the `p` client method can be used to launch a method for a plugin, with a default value if
the plugin is not available (or an Exception to raise).
2020-04-03 18:02:31 +02:00
Goffi
cf82140690 core (xmpp): properly clean profile data in case of startConnection failure:
- profile is now always removed from profiles_connecting
- an exception is raised if client already exists only if client is connected. Otherwise,
  it's deleted (this allow to keep session open to e.g. modify settings in case of failure
  during connection)
2020-04-01 16:17:09 +02:00
Goffi
e8269d8f6a core (xmpp): use asDeferred for profileConnecting and profileConnected 2020-03-30 19:59:12 +02:00
Goffi
8e9905363e core (memory/encryption): set encrypted flag also for outgoing messages and put it in extra:
- `encrypted` flag is now put directly in extra, so that there is nothing to change when
  sending the message to bridge for frontends to be aware of it.
- this flag is now also set when markAsEncrypted is used, so frontend can display
  appropriate indicator to show that outgoing message is encrypted or not.
2020-03-23 16:53:03 +01:00
Goffi
900daa7ad9 core (memory/encryption): encryption session are now restored on client connection 2020-03-22 18:39:12 +01:00
Goffi
f7b91d3d91 core (xmpp): use async corouting for startConnection 2020-03-22 14:31:48 +01:00
Goffi
be95a78a7c core (xmpp): fixed workflow with post_xml_treatments in sendMessage:
post_xml_treatments was incorrectly added to workflow using chainDeferred (which only
add the callback, so post_xml_treatments own callbacks were not waited). As a result,
plugins callback could not be waited as expected before a message was sent.

This patch fixes it by not using chainDeferred anymore.
2020-03-22 13:59:19 +01:00
Goffi
f7360d31e2 core (xmpp): isConnected now returns True when full connection is done:
isConnected was returning True as soon as transport was connected. It is now returning
True only if full connection is done (i.e. transport is connected + all plugins have been
initialised).
2020-03-06 18:19:03 +01:00
Goffi
e2a5f7394e core (xmpp): check that entity_jid is actually a jid in SatRosterProtocol.isJidInRoster 2020-03-01 18:29:46 +01:00
Goffi
7924b601ab core (constants): renamed MESS_KEY_MEDIA_TYPE to MESS_KEY_ATTACHMENTS_MEDIA_TYPE 2020-02-29 16:55:22 +01:00
Goffi
b0c3d4d8ac core (xmpp): use pathlib.Path to complete attachments names, and use name to guess type 2020-02-26 15:54:34 +01:00
Goffi
1ba18cc1fa core (xmpp): complete attachments for sent attachments:
sent attachments are stored and sent back to frontends, so it is necessary to complete
them in the same way as incoming attachments.
2020-02-23 17:49:21 +01:00
Goffi
a194874638 bridge: messageSend's extra is now serialised 2020-02-21 12:17:38 +01:00
Goffi
576c319d6e core (xmpp): add name and media_type in attachements if they are missing. 2020-02-18 18:17:18 +01:00
Goffi
5b0e084a5d core (xmpp): new message key to handle attachments 2020-02-18 18:17:14 +01:00
Goffi
3b64263f3b core: renamed "MessageReceived" trigger to "messageReceived" for consistency. 2020-02-18 18:13:19 +01:00
Goffi
6a7d247754 core: use serialised dict for extra in messageNew and historyGet 2020-02-18 18:13:17 +01:00
Goffi
104902f076 core (xmpp), plugin android: fixed DNS, SRV handling on Android:
Android doesn't have a "/etc/resolv.conf" that Twisted expect. As a result, SRV records
can't be checked correctly on connection.

To work around that, DNS servers used on Android are checked when necessary (on Android
plugin startup and on connectivity change), using some hacks, and Twisted is patched to
use them.
2020-02-09 23:56:42 +01:00
Goffi
1a2078739e core (xmpp): avoid starting several clients at the same time:
a check is done to avoid running startConnection several times at once, which would lead
to the creation of several SatXMPPEntity instances at the same time, resulting in many
issues.

If startConnection is called while a previous one is not finished yet, a CancelError is
now raised.
2020-02-03 13:46:24 +01:00
Goffi
8d1305764a core (xmpp): use a stable resource (sat.[shortuuid]) instead of server one if nothing is specified 2020-01-29 20:21:21 +01:00
Goffi
aadf9ed7e4 core (xmpp): raise InternalError when a new profile Client is created while there is already one in host 2020-01-29 11:00:14 +01:00
Goffi
e1a44cf4e4 fixed shebangs 2020-01-29 10:07:00 +01:00
Goffi
a39349fe64 dates update 2020-01-29 09:50:54 +01:00
Goffi
b0dd28a346 core (xmpp): don't purge entity on disconnect if continueTrying is set 2020-01-28 22:42:10 +01:00
Goffi
c951c67698 plugin android: reconnect profiles with autoconnect if network is activated:
if network is activated, we check that all profiles with autoconnect are indeed connected,
and reconnect them if necesssary.
2020-01-26 18:08:09 +01:00
Goffi
34ca8a6cb3 core: history is skipped as requested log message is now at debug level 2019-10-18 14:36:46 +02:00
Goffi
310ce2eb13 core (patches): updated TLS patches:
- updated patches to handle TLS after implementation in Twisted 19.7.0. A patch is still
  needed for Wokkel.
- minimum required version of Twisted is now 19.7.0
2019-10-01 22:49:10 +02:00
Goffi
76aadbb3fb jp: jp asyncio port:
/!\ this commit is huge. Jp is temporarily not working with `dbus` bridge /!\

This patch implements the port of jp to asyncio, so it is now correctly using the bridge
asynchronously, and it can be used with bridges like `pb`. This also simplify the code,
notably for things which were previously implemented with many callbacks (like pagination
with RSM).

During the process, some behaviours have been modified/fixed, in jp and backends, check
diff for details.
2019-09-25 08:56:41 +02:00
Goffi
fbfe96c505 Python 3 port:
/!\ this is a huge commit
/!\ starting from this commit, SàT is needs Python 3.6+
/!\ SàT maybe be instable or some feature may not work anymore, this will improve with time

This patch port backend, bridge and frontends to Python 3.

Roughly this has been done this way:

- 2to3 tools has been applied (with python 3.7)
- all references to python2 have been replaced with python3 (notably shebangs)
- fixed files not handled by 2to3 (notably the shell script)
- several manual fixes
- fixed issues reported by Python 3 that where not handled in Python 2
- replaced "async" with "async_" when needed (it's a reserved word from Python 3.7)
- replaced zope's "implements" with @implementer decorator
- temporary hack to handle data pickled in database, as str or bytes may be returned,
  to be checked later
- fixed hash comparison for password
- removed some code which is not needed anymore with Python 3
- deactivated some code which needs to be checked (notably certificate validation)
- tested with jp, fixed reported issues until some basic commands worked
- ported Primitivus (after porting dependencies like urwid satext)
- more manual fixes
2019-08-13 19:08:41 +02:00
Goffi
5e43c6c98c core, plugin XEP-0045: fixed message type autodetection + ENTITY_TYPE_MUC constant:
an old hardcoded value was used in several places to detect if an entity is a MUC, but this
value was not valid anymore. This has been fixed, and ENTITY_TYPE_MUC constant is now used
instead. This fixes message type autodetection for "groupchat" messages.

fixes 300
2019-07-09 09:06:45 +02:00
Goffi
57c621e534 core (xmpp): removed log for presence, as it is barely useful and too verbose even for debug logs. 2019-07-02 19:36:26 +02:00
Goffi
c18b828940 core (xmpp): set message timestamp on message reception:
message timestamp was set during the parsing, but this could lead to misordering as async
calls are done before message is parsed (so a variable delay could happen before the
timestamp was set). This patch workaround this by setting timestamp as soon as message is
received (in onMessage).
2019-07-02 19:36:15 +02:00
Goffi
e5aab2f453 core (xmpp): fixed URI correction while parsing messages:
A double "==" was used instead of a single one. As a result URI was never fixed and some
elements could be missed (like body), and then the message discarded.
Should fix 294 (to be confirmed).

fix 294
2019-07-02 09:09:04 +02:00
Goffi
c226b72b20 core, plugin XEP-0045: fix crashes when changing URIs:
When adding missing URIs in message, the "children" property was used instead of elements(). "children" not only return elements, and this was causing crashes.
This may fix bug 294

rel 294
2019-06-30 15:52:30 +02:00
Goffi
c3fcfb3d64 core: fixed component connexion:
presence announcement has been moved to startConnection, but component don't have presence. This patch fixes it by moving presence announcement to clients only.
2019-04-14 08:21:51 +02:00
Goffi
4d64efcda9 code (xmpp): store version after roster item update + fix item removal:
roster version is now stored after roster item has been added or removed. This way if something interrupting the process happens, former item update will be received and roster should be updated correctly.

Roster item removal was crashing because `load()` is not used (local PersistentDict cache is then not updated, and the key to remove is missing there). The exception is now catched and ignored to avoid loading the data only to remove an item.
2019-04-10 21:04:41 +02:00
Goffi
5a90f9d407 core, quick_frontend(app): fixed connected signal handling 2019-04-07 20:55:27 +02:00
Goffi
f51e924eb6 core: added a rosterResync method to bridge:
rosterResync do a full resynchronisation of roster with server. This should not be needed, but may be useful if user suspect a sync issue for whatever reason.
2019-04-07 18:49:41 +02:00
Goffi
5ceffc1491 core (xmpp): implemented roster versioning 2019-04-07 18:47:17 +02:00
Goffi
c2c7dbddfe core (xmpp): new networkEnabled() and networkDisabled() methods:
those methods can be called by platform specific plugins when network is known to be (un)available. This way, connection attempts can be cancelled when no network is available, saving resources (notably battery on mobile devices), or attempts can be restarted immediately when network is known to be available again.
2019-04-06 19:05:57 +02:00
Goffi
5b3aa5c60f core (xmpp): advanced handling of connection termination
factory's clientConnectionFailed and clientConnectionLost methods are monkey patched to allow client to tune termination:
    - a warning when connection is lost in an unclean way
    - connector is saved to allow to disable automatic reconnection and retry manually later
    - new triggers connection_failed and connection_lost allow plugins to tune connection termination workflow
2019-04-06 18:51:20 +02:00
Goffi
9186fd1a3c core (xmpp): use the cleaner stopTrying() instead of setting continueTrying = 0 when connection is not possible due to invalid certificate. 2019-04-05 21:22:05 +02:00
Goffi
6033a0a0cb core: renamed presenceReceived to presence_reveiced + use "client" as first arguments instead of "profile" 2019-03-01 12:12:50 +01:00
Goffi
198db6c2ca plugin XEP-0045: fixed crash when <delay> is used at an unexpected time. 2019-01-26 20:07:45 +01:00
Goffi
e2ab5e33c8 core, XEP-0315: move XML element handling to sat_tmp:
XML Element is now implemented in sat_tmp, so it can be available also for SàT Pubsub.
The XEP-0315 is thus not needed anymore and have been removed, XEP-0315 namespace has been added to base disco features.
Use the new install() function of sat_tmp to do the patching.
2019-01-16 09:18:16 +01:00