Commit graph libervia-backend/sat/plugins/plugin_xep_0060.py
Author SHA1 Message Date
Goffi
6a6f15707a massive refactoring to switch from camelCase to snake_case:
historically, Libervia (SàT before) was using camelCase as allowed by PEP8 when using a
pre-PEP8 code, to use the same coding style as in Twisted.

However, snake_case is more readable and it's better to follow PEP8 best practices, so it
has been decided to move on full snake_case. Because Libervia has a huge codebase, this
ended with a ugly mix of camelCase and snake_case.

To fix that, this patch does a big refactoring by renaming every function and method
(including bridge) that are not coming from Twisted or Wokkel, to use fully snake_case.

This is a massive change, and may result in some bugs.
2023-04-08 13:54:42 +02:00
Goffi
619fcca7da plugin XEP-0060: fix namespace on node subscriptions request 2023-03-16 12:29:34 +01:00
Goffi
895ddd36be plugin XEP-0470: create a default configuration if node config can't be accessed 2022-12-05 11:54:47 +01:00
Goffi
7b9e785c13 plugin OXPS, XEP-0060: indicate which items were e2ee:
the new `encryption` key is added to `getItems` metadata if items were e2ee, it contains a
map from item ID to encryption metadata.

rel  380
2022-10-15 20:38:33 +02:00
Goffi
da9725479b plugin OXPS: OpenPGP for XMPP Pubsub implementation:
OpenPGP for XMPP Pubsub (https://xmpp.org/extensions/inbox/pubsub-encryption.html,
currently a protoXEP) is implemented and activated when `encrypted` is set to `True` in
pubsub's `extra` data.

On item retrieval, the decryption is transparent if the key is known, except if the
`decrypt` key in `extra` is set to `False` (notably useful when one wants to checks that
data is well encrypted).

Methods and corresponding bridge methods have been implemented to manage shared secrets
(to share, revoke or rotate the secrets).

plugin XEP-0060's `XEP-0060_publish` trigger point as been move before actual publish so
item can be modified (here e2ee) by the triggers. A new `XEP-0060_items` trigger point has
also been added.

`encrypted` flag can be used with plugin XEP-0277's microblog data

rel 380
2022-10-15 20:36:53 +02:00
Syndace
6d1e942f43 plugin XEP-0373 and XEP-0374: Implementation of OX and OXIM:
GPGME is used as the GPG provider.

rel 374
2022-09-20 16:22:18 +02:00
Syndace
75ae8160ae plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
- support for both (modern) OMEMO under the `urn:xmpp:omemo:2` namespace and (legacy) OMEMO under the `eu.siacs.conversations.axolotl` namespace
- maintains one identity across both versions of OMEMO
- migrates data from the old plugin
- includes more features for protocol stability
- uses SCE for modern OMEMO
- fully type-checked, linted and format-checked
- added type hints to various pieces of backend code used by the plugin
- added stubs for some Twisted APIs used by the plugin under stubs/ (use `export MYPYPATH=stubs/` before running mypy)
- core (xmpp): enabled `send` trigger and made it an asyncPoint

fix 375
2022-08-23 21:06:24 +02:00
Goffi
2502e5062a plugin XEP-0060: raise an NotFound exception instead of StanzaError in subscribe:
`exceptions.NotFound` is now raised in stead of `item-not-found` `StanzaError` for
consistency with `getItems` and because it's easier to catch (condition has to be checked
when `StanzaError` is received).

rel 372
2022-09-21 22:32:36 +02:00
Goffi
c20e09fb22 plugin XEP-0060: sender can now be specified in sendItems and publish:
if not sended is set, `client.jid` is used.
2022-07-21 18:02:33 +02:00
Goffi
6c170ef8cc plugin XEP-0060, tools (utils): doc/type hints 2022-07-20 17:18:17 +02:00
Goffi
8d64157d88 core: fix calls to domish.Element.elements:
domish.Element.elements should be called with namespace and element name as 2 arguments,
but it has been confused in several places with the call to `domish.Element.addElement`
which is often done with a `(namespace, name)` tuple. Unfortunately calling with a tuple
is accepted and doesn't raise any error in `elements`, but this result in a wrong element
returned.

This patch fixes the erroneous calls.
2022-07-20 17:12:29 +02:00
Goffi
5ceb75a137 plugin XEP-0060: fix bad naming of return variable 2022-07-14 12:55:30 +02:00
Goffi
c2ee7cbbbc plugin XEP-0060: handle priority in addManagedNode:
Priority lets order the callback list when an event is received. This is important in some
use case, notably when a plugin needs to check the former item before it is deleted from
cache or updated.

rel 370
2022-07-14 12:55:30 +02:00
Goffi
11d003b8c1 plugin XEP-0060: type hints 2022-06-29 11:36:31 +02:00
Goffi
83a6d475a9 plugin XEP-0060: do not raise an error when not subscribed on unsubscribe:
when an error is received on unsubscribe because user was not subscribed, a warning is
logged, but no exception is raised anymore, as the expected result is reached.
2022-06-17 14:15:23 +02:00
Goffi
d20e609a5c plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
- update psSubscriptionsGet to use serialised return value
- implement XEP-0376 Pubsub Account Management
- implement XEP-0465 Public Pubsub Subscriptions
- CLI `pubsub` commands updated accordingly, and added `--public` flags to `subscribe`,
  `Subscriptions` and `node Subscriptions get`

⚠ `XEP-0465` is speculative, the XEP has been accepted by council but not published yet.
As is should be the next one, and current latest one is `XEP-0464`, `XEP-0465` has been
anticipated.

rel 365
2022-05-13 18:38:05 +02:00
Goffi
feee36791b plugin XEP-0060: use serialised options in psSubscribe + triggers update 2022-05-13 18:29:42 +02:00
Goffi
24a1355686 plugin XEP-0060: better filtering when looking for default pubsub service 2022-05-13 18:22:06 +02:00
Goffi
81513eb7d8 plugin XEP-0060: specify sender using client.jid in subscribe:
this is necessary to do a subscription with a component managing a virtual JID (i.e. not
the JID of the component itself, but the one linked to a account, see
`SatXMPPComponent.getVirtualClient`).

rel 364
2022-03-22 17:00:42 +01:00
Goffi
01a1bf8691 plugin XEP-0060, XEP-0163, XEP-0277, text syntaxes: make those plugins usable with components 2022-01-25 17:26:05 +01:00
Goffi
738ef6ccf4 plugin XEP-0060: None must not be used for getItems's node 2022-01-25 17:16:37 +01:00
Goffi
92c0c09eb2 plugin pubsub cache: Pubsub Caching implementation 2021-07-29 22:51:01 +02:00
Goffi
a7bae11831 plugin XEP-0277: ignore max_items if rsm_request is set 2021-07-29 21:28:48 +02:00
Goffi
91faf66b36 plugin XEP-0060: fix notification handling in retractItems 2021-07-29 17:28:02 +02:00
Goffi
5dcbd8eeef plugin XEP-0060: add trigger points 2021-07-29 17:26:59 +02:00
Goffi
9ef1f7a1f8 plugin XEP-0060: events callbacks can now be sync or async 2021-07-29 17:10:36 +02:00
Goffi
42979a7140 plugin XEP-0060: handle purge notifications 2021-07-29 15:54:54 +02:00
Goffi
f2a06bbcbf plugin XEP-0060: getItems extra is now serialised dict 2021-07-28 23:01:15 +02:00
Goffi
bab851006f plugin XEP-0060: getItem(s), publish and (un)subscribe are now coroutines 2021-06-30 16:19:14 +02:00
Goffi
435027c1c9 plugin XEP-0060, XEP-0277: new rename methods (psItemRename, mbRename):
Those methods recreate an item to given new ID, and if successful, delete the former one.
2021-05-01 18:37:57 +02:00
Goffi
69112bcd79 plugin XEP-0277: better resilience to broken items:
- if `author` element can't be found, `publisher` attribute, then `IQ`'s `from` attributes
  are used as fallback to find author jid
- fix categories (tags) parsing if `author` element is not found
- remove items which have failed parsing from `mbGet` results (instead of using `None`).
2021-03-27 14:38:27 +01:00
Goffi
dc86957043 date update 2021-03-19 15:45:14 +01:00
Goffi
b1d0905974 plugin XEP-0060: added constants for overwrite policy configuration option 2021-02-27 18:25:20 +01:00
Goffi
96d229abdb plugin XEP-0060: renamed psRetractItem(s) to psItem(s)Retract for consistency. 2021-02-19 15:53:27 +01:00
Goffi
df6f87d69a plugin XEP-0060: add constants for common values of publish model 2020-12-11 17:50:53 +01:00
Goffi
4e803712f7 plugin XEP-0060: use xml_tools.parse instead of wokkel.generic.parseXml:
`xml_tools.parse` does a better parsing, as wokkel's `parseXml` may be missing text
nodes.
2020-11-12 14:53:15 +01:00
Goffi
f8b346e115 plugin XEP-0060: serialise psItemsGet result with data_format 2020-07-17 12:57:23 +02:00
Goffi
e03eb5bfcc plugins XEP-0059, XEP-0060, XEP-0277, XEP-0313: better serialisation:
`data_format.serialise` is now used for `mbGet`, and RSM/MAM values are not transtyped to
strings anymore. A serialised dict is now used, items are put in the `items` key.

Comments handling has been refactored to use a list for the potentially multiple comments
nodes.

`rsm` data are now in a `rsm` key of the dict, and `mam` data are merged with other
metadata.
2020-07-16 09:07:20 +02:00
Goffi
abbd14484b plugin XEP-0060: fixed payload parsing in sendItem 2020-05-18 23:38:21 +02:00
Goffi
d1abda6ddb plugin XEP-0060: async sendItems + precondition-not-met policy:
- sendItems is now an "async" coroutine, and sendItem use it instead of duplicating
  publication logic
- policy to use when a precondition is not met (with publish-options) can now be
  specified, for now it's either raise the exception (default policy), or try to publish
  without the options
- constants have been added to handle "extra" keys
2020-03-11 19:15:48 +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
b7a74d5034 plugin XEP-0060, jp (pubsub/set): publish-options implementation:
- publishing options (XEP-0060 §7.1.5) implementation.
- jp pubsub/set can specify publish-options using `-f` and `-F`
- doc has been updated to explain that
- psItemSend and psItemsSend now use serialisation for "extra"
- publish-options can be specified in extra['publish-options'] with those methods
2019-12-28 20:02:18 +01:00
Goffi
9c84e5dcab plugin XEP-0277: fixed comments URLs parsing 2019-11-08 11:55:21 +01:00
Goffi
7e92cb1b1c plugin XEP-0060: fixed bad MAM unwrapping after Python 3 port 2019-10-20 19:34:26 +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
1ccb54e571 tools (sat_defer), plugin XEP-0060: added a function "stanza2NotFound" to convert item-not-found StanzaError to exceptions.NotFound in an errback 2019-04-14 08:21:51 +02:00
Goffi
6b83ef5c51 plugins: removed useless execute permission 2019-04-14 08:21:51 +02:00
Goffi
512ae0b91e plugin XEP-0277: blog items data are now entirely serialised before going to bridge:
So far, and for historical reasons, blog items data where serialised using a unicode: unicode dict, which was causing trouble for many types of values (timestamps, booleans, lists).
This patch changes it by serialising the whole items before going to bridge, and deserialising it when going back. This way, complex data can be used easily in items.
This impact psEvent and serItemsData* methods which are renamed transItemsData* because there are not always serialising anymore (a new argument "serialise" allows to specify it).
When editing a blog post in jp, metadata are now more easy to manipulate, specially lists like tags.
2019-02-23 18:59:00 +01:00
Goffi
fc3598e660 plugin XEP-0060: added purgeNode/psNodePurge method to remove all items from a node 2019-02-15 22:13:43 +01:00