Mercurial > libervia-backend
comparison sat/plugins/plugin_comp_ap_gateway/regex.py @ 3833:381340b9a9ee
component AP gateway: convert XMPP mentions to AP:
When a XEP-0372 mention is received, the linked pubsub item is looked after in cache, and
if found, it is send to mentioned entity with `mention` tag added.
However, this doesn't work in some cases (see incoming doc for details). To work around
that, `@user@server.tld` type mention are also scanned in body, and mentions are added
when found (this can be disabled with `auto_mentions` setting).
Mention are only scanned in "public" messages, i.e. for pubsub items, and not direct
messages.
rel 369
author | Goffi <goffi@goffi.org> |
---|---|
date | Sun, 10 Jul 2022 16:15:06 +0200 |
parents | eddab3798aca |
children |
comparison
equal
deleted
inserted
replaced
3832:201a22bfbb74 | 3833:381340b9a9ee |
---|---|
14 # GNU Affero General Public License for more details. | 14 # GNU Affero General Public License for more details. |
15 | 15 |
16 # You should have received a copy of the GNU Affero General Public License | 16 # You should have received a copy of the GNU Affero General Public License |
17 # along with this program. If not, see <http://www.gnu.org/licenses/>. | 17 # along with this program. If not, see <http://www.gnu.org/licenses/>. |
18 | 18 |
19 """Regular Expression to parse "Signature" header""" | 19 """Various Regular Expression for AP gateway""" |
20 | |
21 import re | |
22 | |
23 ## "Signature" header parsing | |
20 | 24 |
21 # those expression have been generated with abnf-to-regex | 25 # those expression have been generated with abnf-to-regex |
22 # (https://github.com/aas-core-works/abnf-to-regexp) | 26 # (https://github.com/aas-core-works/abnf-to-regexp) |
23 | 27 |
24 # the base RFC 7320 ABNF rules come from https://github.com/EricGT/ABNF | 28 # the base RFC 7320 ABNF rules come from https://github.com/EricGT/ABNF |
36 # / obs-text | 40 # / obs-text |
37 # quoted-pair = "\" ( HTAB / SP / VCHAR / obs-text ) | 41 # quoted-pair = "\" ( HTAB / SP / VCHAR / obs-text ) |
38 # obs-text = %x80-FF | 42 # obs-text = %x80-FF |
39 # --- | 43 # --- |
40 | 44 |
41 import re | |
42 | |
43 ows = '[ \t]*' | 45 ows = '[ \t]*' |
44 bws = f'{ows}' | 46 bws = f'{ows}' |
45 obs_text = '[\\x80-\\xff]' | 47 obs_text = '[\\x80-\\xff]' |
46 qdtext = f'([\t !#-\\[\\]-~]|{obs_text})' | 48 qdtext = f'([\t !#-\\[\\]-~]|{obs_text})' |
47 quoted_pair = f'\\\\([\t !-~]|{obs_text})' | 49 quoted_pair = f'\\\\([\t !-~]|{obs_text})' |
50 token = f'({tchar})+' | 52 token = f'({tchar})+' |
51 RE_SIG_PARAM = re.compile( | 53 RE_SIG_PARAM = re.compile( |
52 f'(?P<key>{token}{bws})={bws}' | 54 f'(?P<key>{token}{bws})={bws}' |
53 f'((?P<uq_value>{token})|(?P<quoted_value>{quoted_string}))' | 55 f'((?P<uq_value>{token})|(?P<quoted_value>{quoted_string}))' |
54 ) | 56 ) |
57 | |
58 | |
59 ## Account/Mention | |
60 | |
61 # FIXME: naive regex, should be approved following webfinger, but popular implementations | |
62 # such as Mastodon use a very restricted subset | |
63 RE_ACCOUNT = re.compile(r"[a-zA-Z0-9._-]+@[a-zA-Z0-9-]+.[a-zA-Z0-9-]+") | |
64 RE_MENTION = re.compile(rf"(?<!\w)@{RE_ACCOUNT.pattern}\b") |