212 Commits

Author SHA1 Message Date
c61ddeb338 chore(xep): Move FAST from staging into xep_0484.dart 2024-11-17 20:24:03 +01:00
e2515e25e4 fix(tests): Fix component integration test 2024-11-16 17:59:11 +01:00
09a849c6eb fix(xep): Fix failure with multiple SCRAM negotiators and SASL2 2024-11-16 17:57:29 +01:00
9eb94e5f48 fix(xep): Fix crash when the device list node is empty 2024-10-19 21:45:18 +02:00
db77790bf4 fix(meta): Fix version conflicts with moxxy 2024-09-29 18:46:04 +02:00
7ceee48d31 fix(core): Bump omemo_dart (and everything else) 2024-09-29 18:39:49 +02:00
941c3e4fd8 test(xep): Test SCRAM-SHA-1 with SASL2 2024-08-12 23:05:38 +02:00
365ff2f238 fix(xep): Fix replies in the context of Gajim 2024-06-16 14:56:07 +02:00
b3c8a6cd2f fix(docs): Update link to moxxmpp documentation 2024-04-27 00:22:45 +02:00
d4166d087e fix(core): An empty iq is okay with roster versioning
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
2023-10-25 21:03:04 +02:00
ddf781daff fix(core): Remove erroneous override
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
2023-10-05 20:55:41 +02:00
5973076b89 fix(core): Remove overrides file 2023-10-05 20:54:47 +02:00
72cb76d1f6 Merge pull request 'Various improvements and fixes' (#49) from fix/stanza-ordering into master
Reviewed-on: https://codeberg.org/moxxy/moxxmpp/pulls/49
2023-10-05 18:50:32 +00:00
be7581e841 fix(core): Remove empty file 2023-10-04 22:42:36 +02:00
8a2435e4ad fix(example): Bump moxxmpp* versions to 0.4.0 2023-10-04 22:35:00 +02:00
97f082b6f5 feat(example): Add a very simple client example 2023-10-04 22:15:59 +02:00
f287d501ab fix(example): Comform examples to the new TCPSocketWrapper constructor 2023-10-04 22:15:24 +02:00
93e9d6ca22 feat(xep): Handle a user changing their nickname 2023-10-01 20:44:47 +02:00
007cdce53d fix(xep): Fix wrong event being triggered on join 2023-10-01 13:34:13 +02:00
6d3a5e98de fix(xep): Export XEP-0045 events 2023-10-01 13:33:58 +02:00
e97d6e6517 feat(xep): Track our own affiliation and role 2023-09-29 22:45:56 +02:00
882d20dc7a feat(core): Bump moxxmpp_socket_tcp's version 2023-09-29 21:19:28 +02:00
1f712151e4 feat(xep): Ignore the ack timer if we are receiving data 2023-09-29 21:18:43 +02:00
e7922668b1 feat(core): Add a callback for raw data events 2023-09-29 21:13:57 +02:00
87866bf3f5 fix(core): Allow disabling logging of all incoming and outgoing data 2023-09-29 20:53:29 +02:00
41b789fa28 feat(core): Stop an exception in a handler to deadlock the connection 2023-09-29 20:50:03 +02:00
0a68f09fb4 fix(style): Fix style issues 2023-09-29 20:46:14 +02:00
edf1d0b257 feat(core): Replace custom class with a record type 2023-09-29 20:33:56 +02:00
59b90307c2 fix(core): Remove the negotiation lock 2023-09-29 20:29:25 +02:00
49d3c6411b fix(tests): Fix tests 2023-09-29 20:24:58 +02:00
3a94dd9634 feat(core): Log handler executions 2023-09-29 20:01:09 +02:00
fb4b4c71e2 fix(core): Remove async_queue 2023-09-29 19:59:38 +02:00
d9fbb9e102 fix(xep,core): Ensure in-order processing of incoming stanzas 2023-09-29 19:58:43 +02:00
aba90f2e90 feat(example): Print the number of users in the MUC 2023-09-27 18:58:17 +02:00
9211963390 fix(xep): Fix ending presence processing too early if containing a photo 2023-09-27 18:57:42 +02:00
c7d58c3d3f feat(core): Add logging for when a manager ends processing early 2023-09-27 18:57:13 +02:00
6dbbf08be4 feat(xep): Add an event for when someone leaves the MUC
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
2023-09-26 23:42:49 +02:00
7ca648c478 feat(xep): Add MUC events
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
2023-09-26 23:34:53 +02:00
814f99436b fix(xep): Do not automatically request vCards
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
2023-09-26 14:16:41 +02:00
5bd2466c54 feat(xep): Parse the room info from the extended disco info
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
2023-09-26 14:00:27 +02:00
14b62cef96 fix(xep): Fix crash for messages with no id 2023-09-26 13:59:51 +02:00
c3088f9046 fix(xep): Make leaving the room non-awaitable
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
2023-09-25 21:08:24 +02:00
64b93b536e fix(xep): Add missing metadata
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
2023-09-24 18:44:23 +02:00
c1c48d0a83 feat(xep): Provide an implementation of XEP-0392 2023-09-24 18:43:06 +02:00
4a681b9483 fix(xep): Somehow fix reconnection issues
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
2023-09-23 22:19:06 +02:00
c504afc944 fix(xep): Fix joining a MUC making it stuck
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
2023-09-23 14:14:23 +02:00
76a9f7be7a feat(xep): Allow adding MUCs to join later
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
2023-09-22 21:43:56 +02:00
afa3927720 feat(xep): Rejoin groupchats on a new stream 2023-09-22 21:22:18 +02:00
5f36289f50 fix(all): Fix linter warnings 2023-09-22 20:57:05 +02:00
fbe3b90200 feat(xep): Implement ignoring the message reflection 2023-09-22 20:42:45 +02:00
d7c13abde6 feat(xep): Allow ignoring the discussion history
Also allow specifying the amount of stanzas of discussion history we
want.
2023-09-22 19:23:35 +02:00
d4416c8a47 fix(xep): Fix null-deference
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
2023-09-17 20:19:50 +02:00
9666557655 feat(xep): Make avatar queries more explicit
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
2023-09-17 20:10:53 +02:00
1625f912b0 chore(docs): Fix moxxmpp docs
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
2023-09-04 21:11:00 +02:00
864cc0e747 feat(meta): Remove omemo_dart override
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
2023-08-22 20:21:16 +02:00
c9e817054d fix(ci): Fix moxxmpp test pipeline
Some checks failed
ci/woodpecker/push/woodpecker Pipeline failed
2023-08-22 20:07:50 +02:00
d57bf2ef80 fix(ci): Use the pubcached pub.dev cache
Some checks failed
ci/woodpecker/push/woodpecker Pipeline failed
2023-08-22 20:02:43 +02:00
8bfdd5e54a fix(ci): Remove event restriction
Some checks failed
ci/woodpecker/manual/woodpecker Pipeline failed
ci/woodpecker/push/woodpecker Pipeline failed
2023-08-19 22:49:16 +02:00
e58082bf38 feat(ci): Notify on build failure
Some checks failed
ci/woodpecker/manual/woodpecker Pipeline failed
2023-08-19 22:47:29 +02:00
dbb945b424 fix(docs): Remove duplicate <programming-language /> 2023-08-10 15:00:11 +02:00
2431eafa6c fix(docs): Fix broken DOAP 2023-08-10 14:58:16 +02:00
264ab130ee chore(docs): Update DOAP 2023-08-10 14:44:57 +02:00
38dba0e6b7 fix(xep): Export JingleContentThumbnail 2023-08-06 13:14:57 +02:00
94d6fe4925 Merge branch 'feat/remove-eft' 2023-08-06 13:05:55 +02:00
c8b903e5df chore(all): Fix linter issues 2023-08-06 13:04:12 +02:00
b14363319a feat(xep): Remove Extensible File Thumbnails 2023-08-06 13:01:28 +02:00
a18507cc3a chore(flake): Update flake 2023-08-06 12:23:46 +02:00
93418f0127 fix(xep): Fix missing handling of StanzaError
Fixes #48.
2023-07-29 19:27:40 +02:00
1e7279e23b Merge pull request 'Implement XEP-0045 support in moxxmpp' (#46) from ikjot-2605/moxxmpp:xep_0045 into master
Reviewed-on: https://codeberg.org/moxxy/moxxmpp/pulls/46
2023-07-01 19:42:12 +00:00
ikjot-2605
b2724aba0c Merge branch 'master' into xep_0045 2023-07-01 12:01:33 +00:00
Ikjot Singh Dhody
d3742ea156 feat(xep): Small fixes - MUC Example.
Signed-off-by: Ikjot Singh Dhody <ikjotsd@gmail.com>
2023-07-01 17:29:51 +05:30
b92e825bc1 fix(xep): Fix handling StanzaErrors from the DiscoManager 2023-07-01 13:19:26 +02:00
Ikjot Singh Dhody
8b00e85167 feat(xep): Add example for XEP 0045 Moxxmpp.
Signed-off-by: Ikjot Singh Dhody <ikjotsd@gmail.com>
2023-07-01 09:16:51 +05:30
Ikjot Singh Dhody
04dfc6d2ac feat(xep): Replace DiscoError with StanzaError.
Signed-off-by: Ikjot Singh Dhody <ikjotsd@gmail.com>
2023-06-30 18:33:00 +05:30
ikjot-2605
9e70e802ef Merge branch 'master' into xep_0045 2023-06-30 04:56:15 +00:00
Ikjot Singh Dhody
3ebd9b86ec feat(xep): Fix lint issues and use moxlib for result.
Signed-off-by: Ikjot Singh Dhody <ikjotsd@gmail.com>
2023-06-30 10:25:17 +05:30
a928c5c877 feat(xep): Also potentially return "generic" stanza errors 2023-06-29 21:12:30 +02:00
77a1acb0e7 fix(moxxmpp): Somewhat fix (and break) moxxmpp_socket_tcp integration tests 2023-06-25 12:47:47 +02:00
Ikjot Singh Dhody
a873edb9ec feat(xep): Check for null nick before leaveRoom.
Signed-off-by: Ikjot Singh Dhody <ikjotsd@gmail.com>
2023-06-21 12:20:14 +05:30
Ikjot Singh Dhody
e6bd6d05cd feat(xep): Remove NOOP cache access.
Signed-off-by: Ikjot Singh Dhody <ikjotsd@gmail.com>
2023-06-21 00:41:51 +05:30
05e3d804a4 feat(example): Fix omemo_dart dependency 2023-06-20 16:36:49 +02:00
b5efc2dfae feat(xep): Expose new/replaced ratchets in the MessageEvent 2023-06-20 16:35:51 +02:00
Ikjot Singh Dhody
b7d53b8f47 feat(xep): Add docstings for the XEP-0045 routines
Signed-off-by: Ikjot Singh Dhody <ikjotsd@gmail.com>
2023-06-20 17:44:24 +05:30
Ikjot Singh Dhody
217c3ac236 feat(xep): Fix cache issue with join/leaveRoom.
Signed-off-by: Ikjot Singh Dhody <ikjotsd@gmail.com>
2023-06-20 17:38:30 +05:30
d35b955259 fix(xep): Accidentally left getUnackedStanzas exposed 2023-06-19 23:15:29 +02:00
30dca67fb6 feat(all): Remove freezed
Fixes #43.
2023-06-19 23:11:58 +02:00
2db44e2f51 fix(xep): Fix resend behaviour leading to period disconnects
It seems that we were expecting acks "in the future" for old stanzas.
Also, this commit should prevent E2EE implementations from re-encrypting
resent stanzas.

Fixes #38.
2023-06-19 22:55:50 +02:00
Ikjot Singh Dhody
51bca6c25d feat(xep): XEP-0045 cache fixes.
Signed-off-by: Ikjot Singh Dhody <ikjotsd@gmail.com>
2023-06-19 18:40:39 +05:30
4f9a0605c7 Merge pull request 'OMEMO Improvements' (#47) from omemo-changes into master
Reviewed-on: https://codeberg.org/moxxy/moxxmpp/pulls/47
2023-06-18 19:58:05 +00:00
3621f2709a chore(docs): Update changelog 2023-06-18 21:57:53 +02:00
9da6d319a3 feat(all): Use 0.5.0 of omemo_dart 2023-06-18 21:30:35 +02:00
e3ca83670a feat(example): Implement common argument parsing 2023-06-18 21:16:47 +02:00
fbbe413148 feat(example): Improve the example code 2023-06-18 20:59:54 +02:00
Ikjot Singh Dhody
8728166a4d feat(xep): Add cache and roomstate to MUC implementation.
Signed-off-by: Ikjot Singh Dhody <ikjotsd@gmail.com>
2023-06-18 20:49:13 +05:30
Ikjot Singh Dhody
1f1321b269 feat(xep): Small fixes - review cycle 1.
Signed-off-by: Ikjot Singh Dhody <ikjotsd@gmail.com>
2023-06-18 20:09:06 +05:30
9fd2daabb2 feat(xep): Adjust to more omemo_dart changes 2023-06-17 23:51:52 +02:00
8252472fae feat(xep): Adjust to omemo_dart changes 2023-06-17 23:37:08 +02:00
3cb5a568ce feat(xep,core): Migrate to moxlib's Result type 2023-06-17 21:45:00 +02:00
c2f62e2967 feat(xep): Implement an OMEMO example client 2023-06-17 21:28:54 +02:00
Ikjot Singh Dhody
66195f66fa Merge branch 'master' into xep_0045
Signed-off-by: Ikjot Singh Dhody <ikjotsd@gmail.com>
2023-06-14 10:48:28 +05:30
Ikjot Singh Dhody
70fdfaf16d feat(xep): Fix imports for xep_0045 files.
Signed-off-by: Ikjot Singh Dhody <ikjotsd@gmail.com>
2023-06-14 10:47:51 +05:30
Ikjot Singh Dhody
cd73f89e63 feat(xep): Remove duplicate manager string
Signed-off-by: Ikjot Singh Dhody <ikjotsd@gmail.com>
2023-06-14 10:47:51 +05:30
Ikjot Singh Dhody
05c41d3185 feat(xep): Refactor sendMessage to allow groupchat
Signed-off-by: Ikjot Singh Dhody <ikjotsd@gmail.com>
2023-06-14 10:47:50 +05:30
Ikjot Singh Dhody
64a8de6caa feat(xep): Set base for XEP 0045 implementation
Signed-off-by: Ikjot Singh Dhody <ikjotsd@gmail.com>
2023-06-14 10:47:07 +05:30
Ikjot Singh Dhody
68809469f6 feat(xep): Add joinRoom, leaveRoom routines.
Signed-off-by: Ikjot Singh Dhody <ikjotsd@gmail.com>
2023-06-14 10:46:48 +05:30
Ikjot Singh Dhody
762cf1c77a feat(xep): Set base for XEP 0045 implementation
Signed-off-by: Ikjot Singh Dhody <ikjotsd@gmail.com>
2023-06-14 10:46:48 +05:30
29a5417b31 Merge pull request 'Add support for XEP-0421.' (#45) from ikjot-2605/moxxmpp:feat_xep_0421 into master
Reviewed-on: https://codeberg.org/moxxy/moxxmpp/pulls/45
2023-06-12 10:58:32 +00:00
Ikjot Singh Dhody
255d0f88e0 feat(xep): Use cascading operation to return state
Signed-off-by: Ikjot Singh Dhody <ikjotsd@gmail.com>
2023-06-12 15:00:37 +05:30
fa2ce7c2d1 feat(xep): FASTSaslNegotiator now only takes a string as its token 2023-06-11 22:22:45 +02:00
Ikjot Singh Dhody
fa11a3a384 feat(xep): Checked for the occupant-id directly.
Signed-off-by: Ikjot Singh Dhody <ikjotsd@gmail.com>
2023-06-11 23:29:17 +05:30
Ikjot Singh Dhody
ac5bb9e461 feat(xep): Implement XEP 0421 in Moxxmpp.
Signed-off-by: Ikjot Singh Dhody <ikjotsd@gmail.com>
2023-06-11 22:09:29 +05:30
aa71d3ed5d feat(xep): Allow changing the SASL2 user agent 2023-06-11 16:30:49 +02:00
f2d8c6a009 fix(xep): Fix parsing user avatar data with newlines 2023-06-10 21:06:30 +02:00
88545e3308 fix(xep): Fix the OOB fallback for SFS 2023-06-09 00:07:18 +02:00
925a46c0da feat(xep): Move to JID 2023-06-09 00:07:05 +02:00
327f695a40 Merge pull request 'Replace StanzaHandlerData with something more extensible' (#42) from feat/type-map-rework into master
Reviewed-on: https://codeberg.org/moxxy/moxxmpp/pulls/42
2023-06-07 21:44:28 +00:00
8266765ff8 feat(core): Add encryption info to MessageEvent 2023-06-07 23:42:05 +02:00
e234c812ff feat(core): Add a shorthand for MessageEvent.extensions.get 2023-06-07 21:11:11 +02:00
4ff2992a03 fix(all): Last minute fixes 2023-06-07 21:04:05 +02:00
09fd5845aa feat(core): Re-fix the subscription functions 2023-06-07 18:54:05 +02:00
963f3f2cd9 feat(core): Check if we can do subscription pre-approval 2023-06-07 18:41:08 +02:00
da1d28a6d6 feat(core): Remove the PresenceReceivedEvent 2023-06-07 15:12:34 +02:00
cbd90b1163 feat(core): Add a list constructor to TypedMap 2023-06-07 14:13:46 +02:00
f0538b0447 feat(xep): Write a test for XEP-0334 2023-06-06 21:46:33 +02:00
968604b0ba fix(tests): Fix SFS parsing test 2023-06-06 21:31:14 +02:00
60279a84e0 feat(all): Restrict extensions to StanzaHandlerExtension 2023-06-06 21:19:42 +02:00
cf3287ccf4 feat(core): Remove freezed artifact 2023-06-06 20:26:35 +02:00
1ab0ed856f feat(all): Bump version to 0.4.0 2023-06-06 20:22:13 +02:00
10a5046431 feat(core): Rework [MessageEvent] 2023-06-06 16:19:16 +02:00
4d76b9f57a feat(core): Remove [MessageDetails] 2023-06-06 15:57:55 +02:00
0ec3777f44 feat(xep): Managers register the sending callback 2023-06-06 15:14:19 +02:00
6f5de9c4dc feat(xep): Implement the message sending callbacks 2023-06-06 14:12:49 +02:00
79d7e3ba64 feat(all): Move all managers to the new data system 2023-06-04 21:53:47 +02:00
8270185027 feat(core): Implement a typed map 2023-06-03 00:41:23 +02:00
9e0f38154e feat(all): Various changes
- Fix unavailable presence being sent *after* connecting
- Migrate more APIs to the JID class
- Advertise +notify for user avatar metadata
2023-06-02 22:00:44 +02:00
1475cb542f fix(xep): Just receiving <stanza-id/>s does not require disco
It is only required when we try to use them.
2023-05-25 12:42:42 +02:00
b949ec6ff5 fix(docs): Fix typo 2023-05-24 23:44:48 +02:00
c3be199cca Merge pull request 'Stanza send queue' (#40) from feat/send-queue into master
Reviewed-on: https://codeberg.org/moxxy/moxxmpp/pulls/40
2023-05-24 20:50:03 +00:00
83ebe58c47 feat(tests): Test emptying stanza queue on connect 2023-05-24 22:03:17 +02:00
4db0ef6b34 feat(core): Expose StanzaDetails 2023-05-24 20:41:02 +02:00
b95e75329d feat(all): Remove StanzaAddFrom 2023-05-24 20:27:01 +02:00
3163101f82 feat(all): Migrate to the new StanzaDetails API 2023-05-24 14:28:42 +02:00
bd4e1d28ea feat(core): Implement the send queue 2023-05-24 13:34:36 +02:00
b1da6e5a53 chore(xep): Move DiscoManager from String to JID 2023-05-23 17:28:20 +02:00
c6552968d5 feat(core): Remove resumed from connection state change events 2023-05-23 15:56:38 +02:00
1d87c0ce95 feat(xep): Separate XEP-0030 and XEP-0115 support
Also, we now validate whatever we get in terms of disco#info
and capability hashes before caching.
2023-05-23 15:52:48 +02:00
da591a552d fix(xep): Fix discovery of XEP-0191 and XEP-0280 2023-05-16 19:06:50 +02:00
47b679d168 fix(xep): Do not set C2S counter to 0 after connecting 2023-05-16 13:45:52 +02:00
320f4a8d4c fix(xep): Fix issues with enhanced enums 2023-05-16 00:59:50 +02:00
1fdefacd52 feat(xep): Improve API using enhanced enums 2023-05-15 20:40:39 +02:00
09b8613c80 fix(style): Style fixes 2023-05-07 00:15:37 +02:00
f3d906e69b feat(core): Re-add xmlns for StanzaHandler 2023-05-07 00:13:25 +02:00
483cb0d7f1 fix(core): Fix stream parsing breaking after some time 2023-05-07 00:09:35 +02:00
f73daf4d1c fix(core): Fix getting stuck on invalid stream ends
Whenever the stream ends in a weird state, for example with
`<some-tag`, initiating a new stream will confuse the XML parser
and lead errors causing the connection to get stuck.

To fix this, we had to work around xml's extension methods and implement
the extensions in the new "stream parser" where we can reset the parser
(and by reset I mean replace) and thus continue with a fresh parsing state
whenever we reconnect (or connect).
2023-05-06 20:58:34 +02:00
a8693da262 chore(xep): Formatting 2023-04-09 13:17:21 +02:00
0fb66f6aca fix(xep,core): Fix some reconnection issues
- Use handleError instead of directly invoking onFailure
- Stop the ack timer only when we receive ack responses
- NoConnectionPossibleErrors are not irrecoverable
2023-04-09 13:14:53 +02:00
c9173c49bd feat(tests): Add a MUC component for testing 2023-04-09 13:14:30 +02:00
2de1126fa9 fix(example): Remove useDirectTLS 2023-04-09 13:14:06 +02:00
4d312b2100 chore(docs): Update changelog 2023-04-07 15:28:43 +02:00
c1ad646905 fix(core,xep): Fix multiple issues
- Fix a deadlock in the RandomBackoffReconnectionPolicy on failure
- Fix enablement of stream management happening too early
2023-04-07 15:26:49 +02:00
c88ab940c4 release: Version 0.3.1 2023-04-05 13:20:16 +02:00
916be1c927 fix(core): Fix components' stanza matching 2023-04-05 13:17:18 +02:00
5c47c35a46 chore(docs): Bump version of derivation 2023-04-04 16:03:42 +02:00
7f3538875b feat(core): Make all managers optional 2023-04-04 15:59:07 +02:00
f6efa20ff4 chore(meta): Bump versions 2023-04-04 15:55:52 +02:00
8443411f07 fix(docs): XEP-0144 -> XEP-0114 2023-04-04 15:53:57 +02:00
dc24b3c48a chore(core): Remove useDirectTLS 2023-04-04 15:52:56 +02:00
f6abf3d5b5 feat(xep): Implement XEP-0114 2023-04-04 15:48:26 +02:00
63c84d9479 feat(core): Allow tracking the stream id 2023-04-03 23:18:10 +02:00
3e43ac22d7 feat(core): Remove getter and setter for connectionSettings 2023-04-03 17:56:31 +02:00
47d821c02e docs(core): Add comments to NegotiationsHandler 2023-04-03 16:17:09 +02:00
355d580a9a fix(tests): Fix negotiator tests 2023-04-03 16:15:46 +02:00
03328bdf7a feat(core): Allow implementing different negotiation strategies
Fixes #27.
2023-04-03 16:05:20 +02:00
275d6e0346 feat(core): Attempt to improve the ReconnectionPolicy 2023-04-03 13:40:13 +02:00
0d9afd546c feat(core): Remove ignoreLock 2023-04-03 12:47:38 +02:00
3da334b5cf feat(core): Remove the connection lock 2023-04-03 12:46:15 +02:00
2947e2c539 Merge pull request 'SASL2 and friends' (#34) from feat/sasl2 into master
Reviewed-on: https://codeberg.org/moxxy/moxxmpp/pulls/34
2023-04-02 21:36:02 +00:00
ac8433f51f chore(core): Refactor RFC6120 implementations 2023-04-02 23:33:53 +02:00
808371b271 chore(tests): Fix tests 2023-04-02 23:23:50 +02:00
7fdd83ea69 chore(xep): Clean the SASL2 implementation 2023-04-02 23:06:02 +02:00
68e2a65dcf docs(tests): Mention that we need prosody-trunk 2023-04-02 19:49:00 +02:00
d977a74446 feat(tests): Add an integration test for SASL2 2023-04-02 17:20:14 +02:00
29f0419154 feat(meta): Remove log redaction 2023-04-02 14:38:32 +02:00
b354ca8d0a feat(xep): Improve the ergonomics of Bind2 negotiators 2023-04-02 13:39:43 +02:00
ec6b5ab753 feat(xep): Allow inline enablement of carbons 2023-04-02 12:44:09 +02:00
ce1815d1f3 fix(tests): Fix namespace of <bound /> 2023-04-02 12:43:28 +02:00
fbb495dc2f feat(xep): Allow inlining CSI 2023-04-01 23:16:37 +02:00
4a6aa79e56 fix(xep): When using FAST, fallback to other SASL mechanisms on failure 2023-04-01 21:42:52 +02:00
0033d0eb6e feat(xep): Implement FAST 2023-04-01 21:10:46 +02:00
24cb05f91b feat(xep): Handle inline stream enablement with Bind2 2023-04-01 17:38:40 +02:00
91f763ac26 feat(xep): Allow negotiating SM enabling inline with Bind2 2023-04-01 17:16:29 +02:00
51edb61443 feat(xep): Implement SASL2 inline stream resumption 2023-04-01 15:50:13 +02:00
4e01d32e90 feat(xep): Allow setting a tag when using Bind2 2023-04-01 13:15:46 +02:00
f2fe06104c fix(core): Fix formatting 2023-04-01 13:13:19 +02:00
89fe8f0a9c feat(core): Make the PresenceManager optional 2023-04-01 13:09:43 +02:00
9358175925 feat(xep): Inline resource binding with Bind2 2023-04-01 13:00:35 +02:00
564a237986 feat(xep): Set the resource if SASL2 resulted in a resource 2023-04-01 12:51:26 +02:00
cf425917cf feat(core): Reset the resource if lastResource is null 2023-04-01 12:39:15 +02:00
63b7abd6f9 fix(core): Prevent resource binding if we already have a resource 2023-04-01 12:38:18 +02:00
f460e5ebe9 feat(core): Handle less resource binding in the core connection class 2023-04-01 12:28:11 +02:00
af8bc606d6 feat(xep): Guard against random data in the SASL2 result 2023-04-01 00:51:51 +02:00
30482c86f0 feat(xep): Implement inline negotiation 2023-04-01 00:47:45 +02:00
f86dbe6af8 feat(core): Verify the server signature with SASL2 2023-03-31 23:52:48 +02:00
478b5b8770 feat(core): Make SCRAM SASL2 aware 2023-03-31 21:09:16 +02:00
7ab3f4f0d9 feat(xep): Implement negotiating PLAIN via SASL2 2023-03-31 20:53:06 +02:00
2e60e9841e feat(xep): Begin work on SASL2 2023-03-31 19:02:57 +02:00
52ad9a7ddb fix(core): Reset the connection tracker when timing out 2023-03-31 15:53:11 +02:00
ac5e0c13b7 fix(xep): Do not subscribe to the data node 2023-03-31 15:52:50 +02:00
b49658784b fix(example): Adjust example to changes 2023-03-30 16:18:28 +02:00
d4a972e073 feat(core): Close the socket on an error 2023-03-30 16:17:42 +02:00
1009a2f967 feat(core): Fix typing and remove logging parameter 2023-03-30 16:17:12 +02:00
f355f01fc8 fix(tests): Fix integration tests 2023-03-30 16:15:44 +02:00
216 changed files with 13712 additions and 5393 deletions

View File

@@ -7,7 +7,7 @@ line-length=72
[title-trailing-punctuation] [title-trailing-punctuation]
[title-hard-tab] [title-hard-tab]
[title-match-regex] [title-match-regex]
regex=^((feat|fix|chore|refactor|docs|release|test)\((meta|tests|style|docs|xep|core|example)+(,(meta|tests|style|docs|xep|core|example))*\)|release): [A-Z0-9].*$ regex=^((feat|fix|chore|refactor|docs|release|test)\((meta|tests|style|docs|xep|core|example|all|flake|ci)+(,(meta|tests|style|docs|xep|core|example|all|flake|ci))*\)|release): [A-Z0-9].*$
[body-trailing-whitespace] [body-trailing-whitespace]

View File

@@ -1,28 +1,49 @@
when:
branch: master
pipeline: pipeline:
# Check moxxmpp # Check moxxmpp
moxxmpp-lint: moxxmpp-lint:
image: dart:2.18.1 image: dart:3.0.7
commands: commands:
- cd packages/moxxmpp - cd packages/moxxmpp
- dart pub get # Proxy requests to pub.dev using pubcached
- PUB_HOSTED_URL=http://172.17.0.1:8000 dart pub get
- dart analyze --fatal-infos --fatal-warnings - dart analyze --fatal-infos --fatal-warnings
moxxmpp-test: moxxmpp-test:
image: dart:2.18.1 image: dart:3.0.7
commands: commands:
- cd packages/moxxmpp - cd packages/moxxmpp
- dart pub get # Proxy requests to pub.dev using pubcached
- PUB_HOSTED_URL=http://172.17.0.1:8000 dart pub get
- dart test - dart test
# Check moxxmpp_socket_tcp # Check moxxmpp_socket_tcp
moxxmpp_socket_tcp-lint: moxxmpp_socket_tcp-lint:
image: dart:2.18.1 image: dart:3.0.7
commands: commands:
- cd packages/moxxmpp_socket_tcp - cd packages/moxxmpp_socket_tcp
- dart pub get # Proxy requests to pub.dev using pubcached
- PUB_HOSTED_URL=http://172.17.0.1:8000 dart pub get
- dart analyze --fatal-infos --fatal-warnings - dart analyze --fatal-infos --fatal-warnings
# moxxmpp-test: # moxxmpp-test:
# image: dart:2.18.1 # image: dart:3.0.7
# commands: # commands:
# - cd packages/moxxmpp # - cd packages/moxxmpp
# - dart pub get # # Proxy requests to pub.dev using pubcached
# - PUB_HOSTED_URL=http://172.17.0.1:8000 dart pub get
# - dart test # - dart test
notify:
image: git.polynom.me/papatutuwawa/woodpecker-xmpp
settings:
xmpp_tls: 1
xmpp_is_muc: 1
xmpp_recipient: moxxy-build@muc.moxxy.org
xmpp_alias: 2Bot
secrets: [ xmpp_jid, xmpp_password, xmpp_server ]
when:
status:
- failure

View File

@@ -7,7 +7,7 @@ moxxmpp is a XMPP library written purely in Dart for usage in Moxxy.
This package contains the actual XMPP code that is platform-independent. This package contains the actual XMPP code that is platform-independent.
Documentation is available [here](https://moxxy.org/developers/docs/moxxmpp/). Documentation is available [here](https://docs.moxxy.org/moxxmpp/index.html).
### [moxxmpp_socket_tcp](./packages/moxxmpp_socket_tcp) ### [moxxmpp_socket_tcp](./packages/moxxmpp_socket_tcp)
@@ -15,6 +15,10 @@ Documentation is available [here](https://moxxy.org/developers/docs/moxxmpp/).
implements the RFC6120 connection algorithm and XEP-0368 direct TLS connections, implements the RFC6120 connection algorithm and XEP-0368 direct TLS connections,
if a DNS implementation is given, and supports StartTLS. if a DNS implementation is given, and supports StartTLS.
### moxxmpp_color
Implementation of [XEP-0392](https://xmpp.org/extensions/xep-0392.html).
## Development ## Development
To begin, use [melos](https://github.com/invertase/melos) to bootstrap the project: `melos bootstrap`. Then, the example To begin, use [melos](https://github.com/invertase/melos) to bootstrap the project: `melos bootstrap`. Then, the example
@@ -24,6 +28,15 @@ To run the example, make sure that Flutter is correctly set up and working. If y
the development shell provided by the NixOS Flake, ensure that `ANDROID_HOME` and the development shell provided by the NixOS Flake, ensure that `ANDROID_HOME` and
`ANDROID_AVD_HOME` are pointing to the correct directories. `ANDROID_AVD_HOME` are pointing to the correct directories.
## Examples
This repository contains 2 types of examples:
- `example_flutter`: An example of using moxxmpp using Flutter
- `examples_dart`: A collection of pure Dart examples for showing different aspects of moxxmpp
For more information, see the respective README files.
## License ## License
See `./LICENSE`. See `./LICENSE`.

View File

@@ -1,6 +0,0 @@
# melos_managed_dependency_overrides: moxxmpp,moxxmpp_socket_tcp
dependency_overrides:
moxxmpp:
path: ../packages/moxxmpp
moxxmpp_socket_tcp:
path: ../packages/moxxmpp_socket_tcp

View File

Before

Width:  |  Height:  |  Size: 544 B

After

Width:  |  Height:  |  Size: 544 B

View File

Before

Width:  |  Height:  |  Size: 442 B

After

Width:  |  Height:  |  Size: 442 B

View File

Before

Width:  |  Height:  |  Size: 721 B

After

Width:  |  Height:  |  Size: 721 B

View File

Before

Width:  |  Height:  |  Size: 1.0 KiB

After

Width:  |  Height:  |  Size: 1.0 KiB

View File

Before

Width:  |  Height:  |  Size: 1.4 KiB

After

Width:  |  Height:  |  Size: 1.4 KiB

View File

@@ -5,7 +5,7 @@ import 'package:moxxmpp/moxxmpp.dart';
import 'package:moxxmpp_socket_tcp/moxxmpp_socket_tcp.dart'; import 'package:moxxmpp_socket_tcp/moxxmpp_socket_tcp.dart';
class ExampleTcpSocketWrapper extends TCPSocketWrapper { class ExampleTcpSocketWrapper extends TCPSocketWrapper {
ExampleTcpSocketWrapper() : super(false); ExampleTcpSocketWrapper() : super();
@override @override
Future<List<MoxSrvRecord>> srvQuery(String domain, bool dnssec) async { Future<List<MoxSrvRecord>> srvQuery(String domain, bool dnssec) async {
@@ -61,10 +61,11 @@ class _MyHomePageState extends State<MyHomePage> {
final XmppConnection connection = XmppConnection( final XmppConnection connection = XmppConnection(
RandomBackoffReconnectionPolicy(1, 60), RandomBackoffReconnectionPolicy(1, 60),
AlwaysConnectedConnectivityManager(), AlwaysConnectedConnectivityManager(),
ClientToServerNegotiator(),
// The below causes the app to crash. // The below causes the app to crash.
//ExampleTcpSocketWrapper(), //ExampleTcpSocketWrapper(),
// In a production app, the below should be false. // In a production app, the below should be false.
TCPSocketWrapper(true), TCPSocketWrapper(),
); );
TextEditingController jidController = TextEditingController(); TextEditingController jidController = TextEditingController();
TextEditingController passwordController = TextEditingController(); TextEditingController passwordController = TextEditingController();
@@ -107,12 +108,9 @@ class _MyHomePageState extends State<MyHomePage> {
setState(() { setState(() {
loading = true; loading = true;
}); });
connection.setConnectionSettings( connection.connectionSettings = ConnectionSettings(
ConnectionSettings( jid: JID.fromString(jidController.text),
jid: JID.fromString(jidController.text), password: passwordController.text,
password: passwordController.text,
useDirectTLS: true,
),
); );
final result = await connection.connect(waitUntilLogin: true); final result = await connection.connect(waitUntilLogin: true);
setState(() { setState(() {

View File

@@ -16,10 +16,10 @@ dependencies:
version: 0.1.4+1 version: 0.1.4+1
moxxmpp: moxxmpp:
hosted: https://git.polynom.me/api/packages/Moxxy/pub hosted: https://git.polynom.me/api/packages/Moxxy/pub
version: 0.1.6+1 version: 0.3.1
moxxmpp_socket_tcp: moxxmpp_socket_tcp:
hosted: https://git.polynom.me/api/packages/Moxxy/pub hosted: https://git.polynom.me/api/packages/Moxxy/pub
version: 0.1.2+9 version: 0.3.1
dev_dependencies: dev_dependencies:
flutter_test: flutter_test:

6
examples_dart/.gitignore vendored Normal file
View File

@@ -0,0 +1,6 @@
# Files and directories created by pub.
.dart_tool/
.packages
# Conventional directory for build output.
build/

7
examples_dart/README.md Normal file
View File

@@ -0,0 +1,7 @@
# Dart Examples
Run using `dart run bin/<example>.dart`.
## Examples
- `component.dart`: Use moxxmpp to implement a component using XEP-0114.

View File

@@ -0,0 +1,30 @@
# This file configures the static analysis results for your project (errors,
# warnings, and lints).
#
# This enables the 'recommended' set of lints from `package:lints`.
# This set helps identify many issues that may lead to problems when running
# or consuming Dart code, and enforces writing Dart using a single, idiomatic
# style and format.
#
# If you want a smaller set of lints you can change this to specify
# 'package:lints/core.yaml'. These are just the most critical lints
# (the recommended set includes the core lints).
# The core lints are also what is used by pub.dev for scoring packages.
include: package:lints/recommended.yaml
# Uncomment the following section to specify additional rules.
# linter:
# rules:
# - camel_case_types
# analyzer:
# exclude:
# - path/to/excluded/files/**
# For more information about the core and recommended set of lints, see
# https://dart.dev/go/core-lints
# For additional information about configuring this file, see
# https://dart.dev/guides/language/analysis-options

View File

@@ -0,0 +1,94 @@
import 'package:logging/logging.dart';
import 'package:moxxmpp/moxxmpp.dart';
import 'package:moxxmpp_socket_tcp/moxxmpp_socket_tcp.dart';
class TestingTCPSocketWrapper extends TCPSocketWrapper {
TestingTCPSocketWrapper() : super(true);
@override
bool onBadCertificate(dynamic certificate, String domain) {
return true;
}
}
class EchoMessageManager extends XmppManagerBase {
EchoMessageManager() : super('org.moxxy.example.message');
@override
Future<bool> isSupported() async => true;
@override
List<StanzaHandler> getIncomingStanzaHandlers() => [
StanzaHandler(
stanzaTag: 'message',
callback: _onMessage,
priority: -100,
xmlns: null,
)
];
Future<StanzaHandlerData> _onMessage(
Stanza stanza,
StanzaHandlerData state,
) async {
final body = stanza.firstTag('body');
if (body == null) return state..done = true;
final bodyText = body.innerText();
await getAttributes().sendStanza(
StanzaDetails(
Stanza.message(
to: stanza.from,
children: [
XMLNode(
tag: 'body',
text: 'Hello, ${stanza.from}! You said "$bodyText"',
),
],
),
awaitable: false,
),
);
return state..done = true;
}
}
void main(List<String> arguments) async {
Logger.root.level = Level.ALL;
Logger.root.onRecord.listen((record) {
// ignore: avoid_print
print(
'[${record.level.name}] (${record.loggerName}) ${record.time}: ${record.message}',
);
});
final conn = XmppConnection(
TestingReconnectionPolicy(),
AlwaysConnectedConnectivityManager(),
ComponentToServerNegotiator(),
TestingTCPSocketWrapper(),
)..connectionSettings = ConnectionSettings(
jid: JID.fromString('component.localhost'),
password: 'abc123',
host: '127.0.0.1',
port: 8888,
);
await conn.registerManagers([
EchoMessageManager(),
]);
final result = await conn.connect(
waitUntilLogin: true,
shouldReconnect: false,
enableReconnectOnSuccess: false,
);
if (result.isType<XmppError>()) {
print('Failed to connect as component');
return;
}
// Just block for some time to test the connection
await Future<void>.delayed(const Duration(seconds: 9999));
}

View File

@@ -0,0 +1,111 @@
import 'package:cli_repl/cli_repl.dart';
import 'package:example_dart/arguments.dart';
import 'package:example_dart/socket.dart';
import 'package:logging/logging.dart';
import 'package:moxxmpp/moxxmpp.dart';
void main(List<String> args) async {
// Set up logging
Logger.root.level = Level.ALL;
Logger.root.onRecord.listen((record) {
// ignore: avoid_print
print(
'[${record.level.name}] (${record.loggerName}) ${record.time}: ${record.message}',
);
});
final parser = ArgumentParser()
..parser.addOption('muc', help: 'The MUC to send messages to')
..parser.addOption('nick', help: 'The nickname with which to join the MUC');
final options = parser.handleArguments(args);
if (options == null) {
return;
}
// Connect
final muc = JID.fromString(options['muc']! as String).toBare();
final nick = options['nick']! as String;
final connection = XmppConnection(
TestingReconnectionPolicy(),
AlwaysConnectedConnectivityManager(),
ClientToServerNegotiator(),
ExampleTCPSocketWrapper(parser.srvRecord),
)..connectionSettings = parser.connectionSettings;
// Register the managers and negotiators
await connection.registerManagers([
PresenceManager(),
DiscoManager([]),
PubSubManager(),
MessageManager(),
StableIdManager(),
MUCManager(),
]);
await connection.registerFeatureNegotiators([
SaslPlainNegotiator(),
ResourceBindingNegotiator(),
StartTlsNegotiator(),
SaslScramNegotiator(10, '', '', ScramHashType.sha1),
]);
// Connect
Logger.root.info('Connecting...');
final result =
await connection.connect(shouldReconnect: false, waitUntilLogin: true);
if (!result.isType<bool>()) {
Logger.root.severe('Authentication failed!');
return;
}
Logger.root.info('Connected.');
// Print received messages.
connection
.asBroadcastStream()
.where((event) => event is MessageEvent)
.listen((event) {
event as MessageEvent;
// Ignore messages with no <body />
final body = event.get<MessageBodyData>()?.body;
if (body == null) {
return;
}
print('=====> [${event.from}] $body');
});
// Join room
final mm = connection.getManagerById<MUCManager>(mucManager)!;
await mm.joinRoom(
muc,
nick,
maxHistoryStanzas: 0,
);
final state = (await mm.getRoomState(muc))!;
print('=====> ${state.members.length} users in room');
print('=====> ${state.members.values.map((m) => m.nick).join(", ")}');
final repl = Repl(prompt: '> ');
await for (final line in repl.runAsync()) {
await connection
.getManagerById<MessageManager>(messageManager)!
.sendMessage(
muc,
TypedMap<StanzaHandlerExtension>.fromList([
MessageBodyData(line),
StableIdData(
// NOTE: Don't do this. Use a UUID.
DateTime.now().millisecondsSinceEpoch.toString(),
null,
),
]),
type: 'groupchat');
}
// Leave room
await connection.getManagerById<MUCManager>(mucManager)!.leaveRoom(muc);
// Disconnect
await connection.disconnect();
}

View File

@@ -0,0 +1,116 @@
import 'package:chalkdart/chalk.dart';
import 'package:cli_repl/cli_repl.dart';
import 'package:example_dart/arguments.dart';
import 'package:example_dart/socket.dart';
import 'package:logging/logging.dart';
import 'package:moxxmpp/moxxmpp.dart';
import 'package:omemo_dart/omemo_dart.dart' as omemo;
void main(List<String> args) async {
// Set up logging
Logger.root.level = Level.ALL;
Logger.root.onRecord.listen((record) {
// ignore: avoid_print
print(
'[${record.level.name}] (${record.loggerName}) ${record.time}: ${record.message}',
);
});
final parser = ArgumentParser()
..parser.addOption('to', help: 'The JID to send messages to');
final options = parser.handleArguments(args);
if (options == null) {
return;
}
// Connect
final jid = parser.jid;
final to = JID.fromString(options['to']! as String).toBare();
final connection = XmppConnection(
TestingReconnectionPolicy(),
AlwaysConnectedConnectivityManager(),
ClientToServerNegotiator(),
ExampleTCPSocketWrapper(parser.srvRecord, true),
)..connectionSettings = parser.connectionSettings;
// Generate OMEMO data
omemo.OmemoManager? oom;
final moxxmppOmemo = OmemoManager(
() async => oom!,
(toJid, _) async => toJid == to,
);
oom = omemo.OmemoManager(
await omemo.OmemoDevice.generateNewDevice(jid.toString(), opkAmount: 5),
omemo.BlindTrustBeforeVerificationTrustManager(),
moxxmppOmemo.sendEmptyMessageImpl,
moxxmppOmemo.fetchDeviceList,
moxxmppOmemo.fetchDeviceBundle,
moxxmppOmemo.subscribeToDeviceListImpl,
moxxmppOmemo.publishDeviceImpl,
);
final deviceId = await oom.getDeviceId();
Logger.root.info('Our device id: $deviceId');
// Register the managers and negotiators
await connection.registerManagers([
PresenceManager(),
DiscoManager([]),
PubSubManager(),
MessageManager(),
moxxmppOmemo,
]);
await connection.registerFeatureNegotiators([
SaslPlainNegotiator(),
ResourceBindingNegotiator(),
StartTlsNegotiator(),
SaslScramNegotiator(10, '', '', ScramHashType.sha1),
]);
// Set up event handlers
connection.asBroadcastStream().listen((event) {
if (event is MessageEvent) {
Logger.root.info(event.id);
Logger.root.info(event.extensions.keys.toList());
final body = event.encryptionError != null
? chalk.red('Failed to decrypt message: ${event.encryptionError}')
: chalk.green(event.get<MessageBodyData>()?.body ?? '');
print('[${event.from.toString()}] $body');
}
});
// Connect
Logger.root.info('Connecting...');
final result =
await connection.connect(shouldReconnect: false, waitUntilLogin: true);
if (!result.isType<bool>()) {
Logger.root.severe('Authentication failed!');
return;
}
Logger.root.info('Connected.');
// Publish our bundle
Logger.root.info('Publishing bundle');
final device = await oom.getDevice();
final omemoResult = await moxxmppOmemo.publishBundle(await device.toBundle());
if (!omemoResult.isType<bool>()) {
Logger.root.severe(
'Failed to publish OMEMO bundle: ${omemoResult.get<OmemoError>()}');
return;
}
final repl = Repl(prompt: '> ');
await for (final line in repl.runAsync()) {
await connection
.getManagerById<MessageManager>(messageManager)!
.sendMessage(
to,
TypedMap<StanzaHandlerExtension>.fromList([
MessageBodyData(line),
]),
);
}
// Disconnect
await connection.disconnect();
}

View File

@@ -0,0 +1,112 @@
import 'package:logging/logging.dart';
import 'package:moxxmpp/moxxmpp.dart';
import 'package:moxxmpp_socket_tcp/moxxmpp_socket_tcp.dart';
/// The JID we want to authenticate as.
final xmppUser = JID.fromString('jane@example.com');
/// The password to authenticate with.
const xmppPass = 'secret';
/// The [xmppHost]:[xmppPort] server address to connect to.
/// In a real application, one might prefer to use [TCPSocketWrapper]
/// with a custom DNS implementation to let moxxmpp resolve the XMPP
/// server's address automatically. However, if we just provide a host
/// and a port, then [TCPSocketWrapper] will just skip the resolution and
/// immediately use the provided connection details.
const xmppHost = 'localhost';
const xmppPort = 5222;
void main(List<String> args) async {
Logger.root.level = Level.ALL;
Logger.root.onRecord.listen((record) {
print('${record.level.name}|${record.time}: ${record.message}');
});
// This class manages every aspect of handling the XMPP stream.
final connection = XmppConnection(
// A reconnection policy tells the connection how to handle an error
// while or after connecting to the server. The [TestingReconnectionPolicy]
// immediately triggers a reconnection. In a real implementation, one might
// prefer to use a smarter strategy, like using an exponential backoff.
TestingReconnectionPolicy(),
// A connectivity manager tells the connection when it can connect. This is to
// ensure that we're not constantly trying to reconnect because we have no
// Internet connection. [AlwaysConnectedConnectivityManager] always says that
// we're connected. In a real application, one might prefer to use a smarter
// strategy, like using connectivity_plus to query the system's network connectivity
// state.
AlwaysConnectedConnectivityManager(),
// This kind of negotiator tells the connection how to handle the stream
// negotiations. The [ClientToServerNegotiator] allows to connect to the server
// as a regular client. Another negotiator would be the [ComponentToServerNegotiator] that
// allows for connections to the server where we're acting as a component.
ClientToServerNegotiator(),
// A wrapper around any kind of connection. In this case, we use the [TCPSocketWrapper], which
// uses a dart:io Socket/SecureSocket to connect to the server. If you want, you can also
// provide your own socket to use, for example, WebSockets or any other connection
// mechanism.
TCPSocketWrapper(false),
)..connectionSettings = ConnectionSettings(
jid: xmppUser,
password: xmppPass,
host: xmppHost,
port: xmppPort,
);
// Register a set of "managers" that provide you with implementations of various
// XEPs. Some have interdependencies, which need to be met. However, this example keeps
// it simple and just registers a [MessageManager], which has no required dependencies.
await connection.registerManagers([
// The [MessageManager] handles receiving and sending <message /> stanzas.
MessageManager(),
]);
// Feature negotiators are objects that tell the connection negotiator what stream features
// we can negotiate and enable. moxxmpp negotiators always try to enable their features.
await connection.registerFeatureNegotiators([
// This negotiator authenticates to the server using SASL PLAIN with the provided
// credentials.
SaslPlainNegotiator(),
// This negotiator attempts to bind a resource. By default, it's always a random one.
ResourceBindingNegotiator(),
// This negotiator attempts to do StartTLS before authenticating.
StartTlsNegotiator(),
]);
// Set up a stream handler for the connection's event stream. Managers and negotiators
// may trigger certain events. The [MessageManager], for example, triggers a [MessageEvent]
// whenever a message is received. If other managers are registered that parse a message's
// contents, then they can add their data to the event.
connection.asBroadcastStream().listen((event) {
if (event is! MessageEvent) {
return;
}
// The text body (contents of the <body /> element) are returned as a
// [MessageBodyData] object. However, a message does not have to contain a
// body, so it is nullable.
final body = event.extensions.get<MessageBodyData>()?.body;
print('[<-- ${event.from}] $body');
});
// Connect to the server.
final result = await connection.connect(
// This flag indicates that we want to reconnect in case something happens.
shouldReconnect: true,
// This flag indicates that we want the returned Future to only resolve
// once the stream negotiations are done and no negotiator has any feature left
// to negotiate.
waitUntilLogin: true,
);
// Check if the connection was successful. [connection.connect] can return a boolean
// to indicate success or a [XmppError] in case the connection attempt failed.
if (!result.isType<bool>()) {
print('Failed to connect to server');
return;
}
}

View File

@@ -0,0 +1,84 @@
import 'package:args/args.dart';
import 'package:chalkdart/chalk.dart';
import 'package:moxxmpp/moxxmpp.dart';
import 'package:moxxmpp_socket_tcp/moxxmpp_socket_tcp.dart';
extension StringToInt on String {
int toInt() => int.parse(this);
}
/// A wrapper around [ArgParser] for providing convenience functions and standard parameters
/// to the examples.
class ArgumentParser {
ArgumentParser() {
parser
..addOption('jid', help: 'The JID to connect as')
..addOption('password', help: 'The password to use for authenticating')
..addOption('host',
help:
'The host address to connect to (By default uses the domain part of the JID)')
..addOption('port', help: 'The port to connect to')
..addOption('xmpps-srv',
help:
'Inject a SRV record for _xmpps-client._tcp. Format: <priority>,<weight>,<target>,<port>')
..addFlag('help',
abbr: 'h',
negatable: false,
defaultsTo: false,
help: 'Show this help text');
}
/// The [ArgParser] that handles parsing the arguments.
final ArgParser parser = ArgParser();
/// The parsed options. Only valid after calling [handleArguments].
late ArgResults options;
ArgResults? handleArguments(List<String> args) {
options = parser.parse(args);
if (options['help']!) {
print(parser.usage);
return null;
}
if (options['jid'] == null) {
print(chalk.red('No JID specified'));
print(parser.usage);
return null;
}
if (options['password'] == null) {
print(chalk.red('No password specified'));
print(parser.usage);
return null;
}
return options;
}
/// The JID to connect as.
JID get jid => JID.fromString(options['jid']!).toBare();
/// Construct connection settings from the parsed options.
ConnectionSettings get connectionSettings => ConnectionSettings(
jid: jid,
password: options['password']!,
host: options['host'],
port: (options['port'] as String?)?.toInt(),
);
/// Construct an xmpps-client SRV record for injection, if specified.
MoxSrvRecord? get srvRecord {
if (options['xmpps-srv'] == null) {
return null;
}
final parts = options['xmpps-srv']!.split(',');
return MoxSrvRecord(
int.parse(parts[0]),
int.parse(parts[1]),
parts[2],
int.parse(parts[3]),
);
}
}

View File

@@ -0,0 +1,22 @@
import 'package:moxxmpp_socket_tcp/moxxmpp_socket_tcp.dart';
/// A simple socket for examples that allows injection of SRV records (since
/// we cannot use moxdns here).
class ExampleTCPSocketWrapper extends TCPSocketWrapper {
ExampleTCPSocketWrapper(this.srvRecord, bool logData) : super(logData);
/// A potential SRV record to inject for testing.
final MoxSrvRecord? srvRecord;
@override
bool onBadCertificate(dynamic certificate, String domain) {
return true;
}
@override
Future<List<MoxSrvRecord>> srvQuery(String domain, bool dnssec) async {
return [
if (srvRecord != null) srvRecord!,
];
}
}

View File

@@ -0,0 +1,35 @@
name: example_dart
description: A collection of samples for moxxmpp.
version: 1.0.0
environment:
sdk: '>=3.0.0 <4.0.0'
dependencies:
args: 2.4.1
chalkdart: 2.0.9
cli_repl: 0.2.3
logging: ^1.0.2
moxxmpp:
hosted: https://git.polynom.me/api/packages/Moxxy/pub
version: 0.4.0
moxxmpp_socket_tcp:
hosted: https://git.polynom.me/api/packages/Moxxy/pub
version: 0.4.0
omemo_dart:
hosted: https://git.polynom.me/api/packages/PapaTutuWawa/pub
version: ^0.5.1
dependency_overrides:
moxxmpp:
path: ../packages/moxxmpp
moxxmpp_socket_tcp:
path: ../packages/moxxmpp_socket_tcp
omemo_dart:
git:
url: https://github.com/PapaTutuWawa/omemo_dart.git
rev: 49c7e114e6cf80dcde55fbbd218bba3182045862
dev_dependencies:
lints: ^2.0.0
test: ^1.16.0

133
flake.lock generated
View File

@@ -1,12 +1,74 @@
{ {
"nodes": { "nodes": {
"flake-utils": { "android-nixpkgs": {
"inputs": {
"devshell": "devshell",
"flake-utils": "flake-utils",
"nixpkgs": "nixpkgs"
},
"locked": { "locked": {
"lastModified": 1667395993, "lastModified": 1727554699,
"narHash": "sha256-nuEHfE/LcWyuSWnS8t12N1wc105Qtau+/OdUAjtQ0rA=", "narHash": "sha256-puBCNL5PW7Pej+6Srmi2YjEgNeE015NFe33hbkkLqeQ=",
"owner": "tadfisher",
"repo": "android-nixpkgs",
"rev": "bc34ef1c71fe9eafcfb1d637b431fca83d746625",
"type": "github"
},
"original": {
"owner": "tadfisher",
"repo": "android-nixpkgs",
"type": "github"
}
},
"devshell": {
"inputs": {
"nixpkgs": [
"android-nixpkgs",
"nixpkgs"
]
},
"locked": {
"lastModified": 1722113426,
"narHash": "sha256-Yo/3loq572A8Su6aY5GP56knpuKYRvM2a1meP9oJZCw=",
"owner": "numtide",
"repo": "devshell",
"rev": "67cce7359e4cd3c45296fb4aaf6a19e2a9c757ae",
"type": "github"
},
"original": {
"owner": "numtide",
"repo": "devshell",
"type": "github"
}
},
"flake-utils": {
"inputs": {
"systems": "systems"
},
"locked": {
"lastModified": 1726560853,
"narHash": "sha256-X6rJYSESBVr3hBoH0WbKE5KvhPU5bloyZ2L4K60/fPQ=",
"owner": "numtide", "owner": "numtide",
"repo": "flake-utils", "repo": "flake-utils",
"rev": "5aed5285a952e0b949eb3ba02c12fa4fcfef535f", "rev": "c1dfcf08411b08f6b8615f7d8971a2bfa81d5e8a",
"type": "github"
},
"original": {
"owner": "numtide",
"repo": "flake-utils",
"type": "github"
}
},
"flake-utils_2": {
"inputs": {
"systems": "systems_2"
},
"locked": {
"lastModified": 1692799911,
"narHash": "sha256-3eihraek4qL744EvQXsK1Ha6C3CR7nnT8X2qWap4RNk=",
"owner": "numtide",
"repo": "flake-utils",
"rev": "f9e7cf818399d17d347f847525c5a5a8032e4e44",
"type": "github" "type": "github"
}, },
"original": { "original": {
@@ -17,24 +79,71 @@
}, },
"nixpkgs": { "nixpkgs": {
"locked": { "locked": {
"lastModified": 1676076353, "lastModified": 1727348695,
"narHash": "sha256-mdUtE8Tp40cZETwcq5tCwwLqkJVV1ULJQ5GKRtbshag=", "narHash": "sha256-J+PeFKSDV+pHL7ukkfpVzCOO7mBSrrpJ3svwBFABbhI=",
"owner": "AtaraxiaSjel", "owner": "NixOS",
"repo": "nixpkgs", "repo": "nixpkgs",
"rev": "5deb99bdccbbb97e7562dee4ba8a3ee3021688e6", "rev": "1925c603f17fc89f4c8f6bf6f631a802ad85d784",
"type": "github" "type": "github"
}, },
"original": { "original": {
"owner": "AtaraxiaSjel", "owner": "NixOS",
"ref": "update/flutter", "ref": "nixos-unstable",
"repo": "nixpkgs",
"type": "github"
}
},
"nixpkgs_2": {
"locked": {
"lastModified": 1727586919,
"narHash": "sha256-e/YXG0tO5GWHDS8QQauj8aj4HhXEm602q9swrrlTlKQ=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "2dcd9c55e8914017226f5948ac22c53872a13ee2",
"type": "github"
},
"original": {
"owner": "NixOS",
"ref": "nixpkgs-unstable",
"repo": "nixpkgs", "repo": "nixpkgs",
"type": "github" "type": "github"
} }
}, },
"root": { "root": {
"inputs": { "inputs": {
"flake-utils": "flake-utils", "android-nixpkgs": "android-nixpkgs",
"nixpkgs": "nixpkgs" "flake-utils": "flake-utils_2",
"nixpkgs": "nixpkgs_2"
}
},
"systems": {
"locked": {
"lastModified": 1681028828,
"narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=",
"owner": "nix-systems",
"repo": "default",
"rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e",
"type": "github"
},
"original": {
"owner": "nix-systems",
"repo": "default",
"type": "github"
}
},
"systems_2": {
"locked": {
"lastModified": 1681028828,
"narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=",
"owner": "nix-systems",
"repo": "default",
"rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e",
"type": "github"
},
"original": {
"owner": "nix-systems",
"repo": "default",
"type": "github"
} }
} }
}, },

View File

@@ -1,18 +1,20 @@
{ {
description = "moxxmpp"; description = "moxxmpp";
inputs = { inputs = {
nixpkgs.url = "github:AtaraxiaSjel/nixpkgs/update/flutter"; nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
android-nixpkgs.url = "github:tadfisher/android-nixpkgs";
flake-utils.url = "github:numtide/flake-utils"; flake-utils.url = "github:numtide/flake-utils";
}; };
outputs = { self, nixpkgs, flake-utils }: flake-utils.lib.eachDefaultSystem (system: let outputs = { self, nixpkgs, android-nixpkgs, flake-utils }: flake-utils.lib.eachDefaultSystem (system: let
pkgs = import nixpkgs { pkgs = import nixpkgs {
inherit system; inherit system;
config = { config = {
android_sdk.accept_license = true; android_sdk.accept_license = true;
allowUnfree = true; allowUnfree = true;
}; };
}; };
# Everything to make Flutter happy
android = pkgs.androidenv.composeAndroidPackages { android = pkgs.androidenv.composeAndroidPackages {
# TODO: Find a way to pin these # TODO: Find a way to pin these
#toolsVersion = "26.1.1"; #toolsVersion = "26.1.1";
@@ -29,6 +31,7 @@
useGoogleAPIs = false; useGoogleAPIs = false;
useGoogleTVAddOns = false; useGoogleTVAddOns = false;
}; };
lib = pkgs.lib;
pinnedJDK = pkgs.jdk17; pinnedJDK = pkgs.jdk17;
pythonEnv = pkgs.python3.withPackages (ps: with ps; [ pythonEnv = pkgs.python3.withPackages (ps: with ps; [
@@ -46,11 +49,30 @@
}; };
}; };
devShell = pkgs.mkShell { devShell = let
prosody-newer-community-modules = pkgs.prosody.overrideAttrs (old: {
communityModules = pkgs.fetchhg {
url = "https://hg.prosody.im/prosody-modules";
rev = "e3a3a6c86a9f";
sha256 = "sha256-C2x6PCv0sYuj4/SroDOJLsNPzfeNCodYKbMqmNodFrk=";
};
src = pkgs.fetchhg {
url = "https://hg.prosody.im/trunk";
rev = "8a2f75e38eb2";
sha256 = "sha256-zMNp9+wQ/hvUVyxFl76DqCVzQUPP8GkNdstiTDkG8Hw=";
};
});
prosody-sasl2 = prosody-newer-community-modules.override {
withCommunityModules = [
"sasl2" "sasl2_fast" "sasl2_sm" "sasl2_bind2"
];
};
in pkgs.mkShell {
buildInputs = with pkgs; [ buildInputs = with pkgs; [
flutter pinnedJDK android.platform-tools dart # Dart flutter pinnedJDK android.platform-tools dart # Dart
gitlint # Code hygiene gitlint # Code hygiene
ripgrep # General utilities ripgrep # General utilities
# Flutter dependencies for Linux desktop # Flutter dependencies for Linux desktop
atk atk
@@ -71,12 +93,35 @@
# For the scripts in ./scripts/ # For the scripts in ./scripts/
pythonEnv pythonEnv
# For integration testing against a local prosody server
prosody-sasl2
mkcert
]; ];
CPATH = "${pkgs.xorg.libX11.dev}/include:${pkgs.xorg.xorgproto}/include"; CPATH = "${pkgs.xorg.libX11.dev}/include:${pkgs.xorg.xorgproto}/include";
LD_LIBRARY_PATH = with pkgs; lib.makeLibraryPath [ atk cairo epoxy gdk-pixbuf glib gtk3 harfbuzz pango ]; LD_LIBRARY_PATH = with pkgs; lib.makeLibraryPath [ atk cairo epoxy gdk-pixbuf glib gtk3 harfbuzz pango ];
ANDROID_SDK_ROOT = "${android.androidsdk}/share/android-sdk";
ANDROID_HOME = "${android.androidsdk}/share/android-sdk";
JAVA_HOME = pinnedJDK; JAVA_HOME = pinnedJDK;
# Fix an issue with Flutter using an older version of aapt2, which does not know
# an used parameter.
GRADLE_OPTS = "-Dorg.gradle.project.android.aapt2FromMavenOverride=${android.androidsdk}/share/android-sdk/build-tools/34.0.0/aapt2";
};
apps = {
regenerateNixPackage = let
script = pkgs.writeShellScript "regenerate-nix-package.sh" ''
set -e
${pythonEnv}/bin/python ./scripts/pubspec2lock.py ./packages/moxxmpp/pubspec.lock ./nix/moxxmpp.lock
${pythonEnv}/bin/python ./scripts/lock2nix.py ./nix/moxxmpp.lock ./nix/pubcache.moxxmpp.nix moxxmpp
'';
in {
type = "app";
program = "${script}";
};
}; };
}); });
} }

6
integration_tests/.gitignore vendored Normal file
View File

@@ -0,0 +1,6 @@
# Files and directories created by pub.
.dart_tool/
.packages
# Conventional directory for build output.
build/

View File

@@ -0,0 +1,5 @@
# Integration Tests
The included `./prosody.cfg.lua` config file must be used for integration testing.
Additionally, ensure that a user `testuser@localhost` with the password `abc123`
exists. Note that this currently requires prosody-trunk.

View File

@@ -0,0 +1 @@
include: ../analysis_options.yaml

View File

@@ -0,0 +1,24 @@
-----BEGIN CERTIFICATE-----
MIIEAzCCAmugAwIBAgIQd61NPnP8++X7h8a+85C6DjANBgkqhkiG9w0BAQsFADBZ
MR4wHAYDVQQKExVta2NlcnQgZGV2ZWxvcG1lbnQgQ0ExFzAVBgNVBAsMDmFsZXhh
bmRlckBtaWt1MR4wHAYDVQQDDBVta2NlcnQgYWxleGFuZGVyQG1pa3UwHhcNMjMw
NDAyMTM1ODIxWhcNMjUwNzAyMTM1ODIxWjBCMScwJQYDVQQKEx5ta2NlcnQgZGV2
ZWxvcG1lbnQgY2VydGlmaWNhdGUxFzAVBgNVBAsMDmFsZXhhbmRlckBtaWt1MIIB
IjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA1DElEXPY+VDQP7cSikK0ne0K
gDgorGYPG9R7lOeuPLHyFYYry78+hB037OT0BOyA2uTu1yrog0dI/4YGicPDIqXh
IgHfjV+4kMi5SgO7ECWOBmZFqTC3bBwvbNtoW40aFjYSFaOkm/nnfp+nalEJJZ/N
kSkD4gdT3pH1ClsovlI4BlsxeIoJtyGzxMidJVXDAqMNraLatzJBwnT3OEs93xTf
7Kd1KUpQp9OZFrGi15zv/n6tCmrcC3xMOVHuYkhW0UCTFmev7ZqbghQsQ9N9s0E6
kk9rUf9xtMNH4Af6+2YRkT1DAGQ6FkXl1nQdB5H5XRgOBl+3k9s8wUrxQvQddQID
AQABo14wXDAOBgNVHQ8BAf8EBAMCBaAwEwYDVR0lBAwwCgYIKwYBBQUHAwEwHwYD
VR0jBBgwFoAU54aUZ+dytAOBTsYIdGtSnjiig/gwFAYDVR0RBA0wC4IJbG9jYWxo
b3N0MA0GCSqGSIb3DQEBCwUAA4IBgQBU8p7Ua0Cs+lXlWmtCh2j+YF9R+dvc+3Iw
dYEzCmYd375uxPctyHXW0yYjyuH9WuYn0F7OicEFEeC2+exHND+/z0J2Zv5yu34r
SfgHVfvE/Vxisn9InYrUCVtfRwLDF3HgLyIlm8FVzIyiIANhpe6vJdqjEWTsiL2X
I6hoDf1xlRgEqUx+Wxl2IFWrg+1SPPGTQzDPImiRlz8d+9ZJ9v48vaV5+aITMvDP
Gfm/bnNXXd5Gf7nGwL8zFHiwLoYQ5AUYl0IfXYwFAXJ72+LjiRT33IOidVJF0gsQ
6k9cTsc4lIrt4FOzdchalbF1Eu2prieWoZxz0apG8OuUeAhaB+t8kT6swAkwvkLW
OnlSATm9Cls9Pc4XDHTbZlbMmwF2Jmukgz/l1vlTutt4ZgZwQkSEa9Qfoi9Zym0R
iKls1CgD49zguR/cFDKK3agvfv6Afw6HdgaS/WqcI/Ros7b+RCkbAlAG5gqr6BLQ
8RGyVjZSC4Mz/ddcnMEpRAnjuFJjhGA=
-----END CERTIFICATE-----

View File

@@ -0,0 +1,28 @@
-----BEGIN PRIVATE KEY-----
MIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQDUMSURc9j5UNA/
txKKQrSd7QqAOCisZg8b1HuU5648sfIVhivLvz6EHTfs5PQE7IDa5O7XKuiDR0j/
hgaJw8MipeEiAd+NX7iQyLlKA7sQJY4GZkWpMLdsHC9s22hbjRoWNhIVo6Sb+ed+
n6dqUQkln82RKQPiB1PekfUKWyi+UjgGWzF4igm3IbPEyJ0lVcMCow2totq3MkHC
dPc4Sz3fFN/sp3UpSlCn05kWsaLXnO/+fq0KatwLfEw5Ue5iSFbRQJMWZ6/tmpuC
FCxD032zQTqST2tR/3G0w0fgB/r7ZhGRPUMAZDoWReXWdB0HkfldGA4GX7eT2zzB
SvFC9B11AgMBAAECggEAYaj4yY6LFzxVjG2i79WBsYnOonK2bZpPa9ygwEjdTXwM
0lE9SPoNONsFyVca5EVBjP1+27MY7orZkxlJWxCpeAHmmzNHg5bBqIlpliIfb3AJ
bPKXLyaH1Q8n2K8m2bQYhI6ARktZ0Jv1KrcqY2lGj3V8NEovSlFbDX4ZzJlmKCly
d4Ia6eQ7f9AjgsOwpQGeCTF7WLaVDnch6D4JfCGrW08lFeaqogiBQczsOE3hcNSd
tEul21Z0CkC7Iiw28KdkApPINquo1VYdAcOvUCOXkwJfPC1gsJwK4O2jxfi9v5NF
uU1niK0/00b396pQKvXpkfViynexwzK0MZCoo3zuQQKBgQDzaZexcniQNDyWqN3C
oMe4V3rnxs+aO/lu8Ed3mng+Jf4vuarZlxNot7WRBMGT/T+b7/UIrqRJy50CYAPY
3RRR84tLg3UMwUWhDYsPucNc2icODBG4c+QWJ300W19r+J+iT8PwS9AbH2n094Rn
LCRYFrX5aMsgIH5uwuncKzweMQKBgQDfKj2i1ptC53aOcr1tMCFYcnMGtaAZ8u6+
cKSgnzKlTw/g0EYlGcETUnCyZe0oVYWp3y859FBXU0JMDmxu84aYEZNF6BwRVlpF
feQgtUFZHyf9MepQGhjIJ5El8n7jhh1bsBY18QbDFe6/GtqPx/mQEF7vE+wPFl9h
putwdv3OhQKBgGKPyi2/BVSW4kW7IPiTM+vP+GNrnFp+mHS0dKvYb4HyzmcyzhyH
UQOhB7Mt8thivmP9GQIn/TwoZ24zxLsGYhkA/dFY7Id6pyAcpMd8V7/8Ub4dYvuG
acASw1709MF6jeEiXVuqxxyEbtoTc5h3Rkwo/gx8w2tB3RAqepl9JD2xAoGAfVL3
ci8a2iOqTKza/Cp/T3BWcHonAuuOb5xKl3lPs84GmLXd7o/cAcHWUBk1aeU9Pvx7
RQyS4bd8D8I52sUf3N5h2mxS9tmLsGLWbhfcLvR0PJh/gaRmLmEp/imEYLm8WvU0
Q+6rYXs7rE6kVwJygBjxd0m003Q49FoM9gec2RECgYEA5SLAe2UmJSLIb0DKk27o
nSfARDSdi9N40vIjDFHmDRdKTOYicED/f7KqXnxVpvFxDdCvJ7xeC4V7vkaqiiwd
/oMLQq0GjmBxG/PNd1AFIWDydyH+JcY6U4XWIzIw92OKVYC/KMvd2f9orTfmDyAU
RsGMfgV90kCzouAZKy3yPmo=
-----END PRIVATE KEY-----

View File

@@ -0,0 +1,4 @@
set -ex
prosodyctl --config ./prosody.cfg.lua register testuser1 localhost abc123
prosodyctl --config ./prosody.cfg.lua register testuser2 localhost abc123

View File

@@ -0,0 +1,62 @@
admins = { }
plugin_paths = {}
modules_enabled = {
-- Generally required
"disco"; -- Service discovery
"roster"; -- Allow users to have a roster. Recommended ;)
"saslauth"; -- Authentication for clients and servers. Recommended if you want to log in.
"tls"; -- Add support for secure TLS on c2s/s2s connections
-- Not essential, but recommended
"blocklist"; -- Allow users to block communications with other users
"bookmarks"; -- Synchronise the list of open rooms between clients
"carbons"; -- Keep multiple online clients in sync
"dialback"; -- Support for verifying remote servers using DNS
"limits"; -- Enable bandwidth limiting for XMPP connections
"pep"; -- Allow users to store public and private data in their account
"private"; -- Legacy account storage mechanism (XEP-0049)
"smacks"; -- Stream management and resumption (XEP-0198)
"vcard4"; -- User profiles (stored in PEP)
"vcard_legacy"; -- Conversion between legacy vCard and PEP Avatar, vcard
-- Nice to have
"csi_simple"; -- Simple but effective traffic optimizations for mobile devices
"invites"; -- Create and manage invites
"invites_adhoc"; -- Allow admins/users to create invitations via their client
"invites_register"; -- Allows invited users to create accounts
"ping"; -- Replies to XMPP pings with pongs
"register"; -- Allow users to register on this server using a client and change passwords
"time"; -- Let others know the time here on this server
"uptime"; -- Report how long server has been running
"version"; -- Replies to server version requests
-- SASL2
"sasl2";
"sasl2_sm";
"sasl2_fast";
"sasl2_bind2";
}
s2s_secure_auth = false
-- Authentication
authentication = "internal_plain"
-- Storage
storage = "internal"
data_path = "/tmp/prosody-data/"
log = {
debug = "*console";
}
pidfile = "/tmp/prosody.pid"
component_ports = { 8888 }
component_interfaces = { '127.0.0.1' }
VirtualHost "localhost"
Component "component.localhost"
component_secret = "abc123"
Component "muc.localhost" "muc"

View File

@@ -0,0 +1,18 @@
name: integration_tests
description: A sample command-line application.
version: 1.0.0
environment:
sdk: ">=3.0.0 <4.0.0"
dependencies:
logging: ^1.3.0
moxxmpp:
path: ../packages/moxxmpp
moxxmpp_socket_tcp:
path: ../packages/moxxmpp_socket_tcp
dev_dependencies:
build_runner: ^2.4.13
test: ^1.25.8
very_good_analysis: ^6.0.0

View File

@@ -0,0 +1,44 @@
import 'package:logging/logging.dart';
import 'package:moxxmpp/moxxmpp.dart';
import 'package:moxxmpp_socket_tcp/moxxmpp_socket_tcp.dart';
import 'package:test/test.dart';
class TestingTCPSocketWrapper extends TCPSocketWrapper {
TestingTCPSocketWrapper() : super(true);
@override
bool onBadCertificate(dynamic certificate, String domain) {
return true;
}
}
void main() {
Logger.root.level = Level.ALL;
Logger.root.onRecord.listen((record) {
// ignore: avoid_print
print(
'[${record.level.name}] (${record.loggerName}) ${record.time}: ${record.message}',
);
});
test('Test connecting to prosody as a component', () async {
final conn = XmppConnection(
TestingReconnectionPolicy(),
AlwaysConnectedConnectivityManager(),
ComponentToServerNegotiator(),
TestingTCPSocketWrapper(),
)..connectionSettings = ConnectionSettings(
jid: JID.fromString('component.localhost'),
password: 'abc123',
host: '127.0.0.1',
port: 8888,
);
final result = await conn.connect(
waitUntilLogin: true,
shouldReconnect: false,
enableReconnectOnSuccess: false,
);
expect(result.isType<bool>(), true);
});
}

View File

@@ -0,0 +1,77 @@
import 'package:logging/logging.dart';
import 'package:moxxmpp/moxxmpp.dart';
import 'package:moxxmpp_socket_tcp/moxxmpp_socket_tcp.dart';
import 'package:test/test.dart';
class TestingTCPSocketWrapper extends TCPSocketWrapper {
TestingTCPSocketWrapper() : super(true);
@override
bool onBadCertificate(dynamic certificate, String domain) {
return true;
}
}
void main() {
Logger.root.level = Level.ALL;
Logger.root.onRecord.listen((record) {
// ignore: avoid_print
print(
'[${record.level.name}] (${record.loggerName}) ${record.time}: ${record.message}',
);
});
test('Test authenticating against Prosody with SASL2, Bind2, and FAST',
() async {
final conn = XmppConnection(
TestingReconnectionPolicy(),
AlwaysConnectedConnectivityManager(),
ClientToServerNegotiator(),
TestingTCPSocketWrapper(),
)..connectionSettings = ConnectionSettings(
jid: JID.fromString('testuser1@localhost'),
password: 'abc123',
host: '127.0.0.1',
port: 5222,
);
final csi = CSIManager();
await csi.setInactive(sendNonza: false);
await conn.registerManagers([
RosterManager(TestingRosterStateManager('', [])),
DiscoManager([]),
]);
await conn.registerFeatureNegotiators([
SaslPlainNegotiator(),
SaslScramNegotiator(9, '', '', ScramHashType.sha1),
SaslScramNegotiator(10, '', '', ScramHashType.sha256),
ResourceBindingNegotiator(),
FASTSaslNegotiator(),
Bind2Negotiator(),
StartTlsNegotiator(),
Sasl2Negotiator()
..userAgent = const UserAgent(
id: 'd4565fa7-4d72-4749-b3d3-740edbf87770',
software: 'moxxmpp',
device: "PapaTutuWawa's awesome device",
),
]);
final result = await conn.connect(
waitUntilLogin: true,
shouldReconnect: false,
enableReconnectOnSuccess: false,
);
expect(result.isType<bool>(), true);
expect(
conn.getNegotiatorById<Sasl2Negotiator>(sasl2Negotiator)!.state,
NegotiatorState.done,
);
expect(
conn
.getNegotiatorById<FASTSaslNegotiator>(saslFASTNegotiator)!
.fastToken !=
null,
true,
);
});
}

View File

@@ -7,7 +7,7 @@
stdenv.mkDerivation { stdenv.mkDerivation {
pname = "moxxmpp-docs"; pname = "moxxmpp-docs";
version = "0.2.0"; version = "0.3.1";
PUB_CACHE = "${pubCache}"; PUB_CACHE = "${pubCache}";

File diff suppressed because it is too large Load Diff

View File

@@ -1,28 +1,30 @@
# GENERATED BY LOCK2NIX.py
# DO NOT EDIT BY HAND
{fetchzip, runCommand} : rec { {fetchzip, runCommand} : rec {
_fe_analyzer_shared = fetchzip { _fe_analyzer_shared = fetchzip {
sha256 = "1hyd5pmjcfyvfwhsc0wq6k0229abmqq5zn95g31hh42bklb2gci5"; sha256 = "15fh9ka41dw4qsynv07msq4i243fibprcmafdygw5x88f7m55fq3";
url = "https://pub.dartlang.org/packages/_fe_analyzer_shared/versions/50.0.0.tar.gz"; url = "https://pub.dartlang.org/packages/_fe_analyzer_shared/versions/61.0.0.tar.gz";
stripRoot = false; stripRoot = false;
extension = "tar.gz"; extension = "tar.gz";
}; };
analyzer = fetchzip { analyzer = fetchzip {
sha256 = "0niy5b3w39aywpjpw5a84pxdilhh3zzv1c22x8ywml756pybmj4r"; sha256 = "0w604zngxwfx0xqxvhbxrhdh04wgm6ad6a1lbwnyvmk57amv44np";
url = "https://pub.dartlang.org/packages/analyzer/versions/5.2.0.tar.gz"; url = "https://pub.dartlang.org/packages/analyzer/versions/5.13.0.tar.gz";
stripRoot = false; stripRoot = false;
extension = "tar.gz"; extension = "tar.gz";
}; };
args = fetchzip { args = fetchzip {
sha256 = "0c78zkzg2d2kzw1qrpiyrj1qvm4pr0yhnzapbqk347m780ha408g"; sha256 = "01ps253280c6dbx0vncw4wga4l2qp1zx779qjj2x06xzb3744zbz";
url = "https://pub.dartlang.org/packages/args/versions/2.3.1.tar.gz"; url = "https://pub.dartlang.org/packages/args/versions/2.4.2.tar.gz";
stripRoot = false; stripRoot = false;
extension = "tar.gz"; extension = "tar.gz";
}; };
async = fetchzip { async = fetchzip {
sha256 = "00hhylamsjcqmcbxlsrfimri63gb384l31r9mqvacn6c6bvk4yfx"; sha256 = "0hfgvjajp5c2mw68186hgrk9v5zjhhi149hlhl0fap274p2v1g3q";
url = "https://pub.dartlang.org/packages/async/versions/2.10.0.tar.gz"; url = "https://pub.dartlang.org/packages/async/versions/2.11.0.tar.gz";
stripRoot = false; stripRoot = false;
extension = "tar.gz"; extension = "tar.gz";
}; };
@@ -49,29 +51,29 @@
}; };
build_daemon = fetchzip { build_daemon = fetchzip {
sha256 = "0b6hnwjc3gi5g7cnpy8xyiqigcrs0xp51c7y7v1pqn9v75g25w6j"; sha256 = "1wn7bq846vgdj62bkh9h25l95xdsndv0jdyw52nyr0591l3bpg3h";
url = "https://pub.dartlang.org/packages/build_daemon/versions/3.1.0.tar.gz"; url = "https://pub.dartlang.org/packages/build_daemon/versions/3.1.1.tar.gz";
stripRoot = false; stripRoot = false;
extension = "tar.gz"; extension = "tar.gz";
}; };
build_resolvers = fetchzip { build_resolvers = fetchzip {
sha256 = "0fnrisgq6rnvbqsf8v43hb11kr1qq6azrxbsvx3wwimd37nxx8m5"; sha256 = "00h9abhrfmnl0xxziyf6p68sxnbv2ww1c4dhgpnz00mzbmamnq5c";
url = "https://pub.dartlang.org/packages/build_resolvers/versions/2.1.0.tar.gz"; url = "https://pub.dartlang.org/packages/build_resolvers/versions/2.3.1.tar.gz";
stripRoot = false; stripRoot = false;
extension = "tar.gz"; extension = "tar.gz";
}; };
build_runner = fetchzip { build_runner = fetchzip {
sha256 = "0246bxl9rxgil55fhfzi7csd9a56blj9s1j1z79717hiyzsr60x6"; sha256 = "0b5ha1l6k0gn2swqgqvfy2vl58klf81sxrjnmk0p7rj1wzbqjm7l";
url = "https://pub.dartlang.org/packages/build_runner/versions/2.3.2.tar.gz"; url = "https://pub.dartlang.org/packages/build_runner/versions/2.3.3.tar.gz";
stripRoot = false; stripRoot = false;
extension = "tar.gz"; extension = "tar.gz";
}; };
build_runner_core = fetchzip { build_runner_core = fetchzip {
sha256 = "0bpil0fw0dag3vbnin9p945ymi7xjgkiy7jrq9j52plljf7cnf5z"; sha256 = "07r1kfy6ylm4i4xrb24ns8l26h4h1lgcskmnf8wvq2rd5d5hq790";
url = "https://pub.dartlang.org/packages/build_runner_core/versions/7.2.7.tar.gz"; url = "https://pub.dartlang.org/packages/build_runner_core/versions/7.2.7%2B1.tar.gz";
stripRoot = false; stripRoot = false;
extension = "tar.gz"; extension = "tar.gz";
}; };
@@ -84,29 +86,29 @@
}; };
built_value = fetchzip { built_value = fetchzip {
sha256 = "0sslr4258snvcj8qhbdk6wapka174als0viyxddwqlnhs7dlci8i"; sha256 = "1y84imf9xqqy3gnd5zz9bcln6mycy7qx35r70b0izm31ismlbzkv";
url = "https://pub.dartlang.org/packages/built_value/versions/8.4.2.tar.gz"; url = "https://pub.dartlang.org/packages/built_value/versions/8.6.2.tar.gz";
stripRoot = false; stripRoot = false;
extension = "tar.gz"; extension = "tar.gz";
}; };
checked_yaml = fetchzip { checked_yaml = fetchzip {
sha256 = "1gf7ankc5jb7mk17br87ajv05pfg6vb8nf35ay6c35w8jp70ra7k"; sha256 = "1sn01yrmj0pkijn08g3v45c3zmyvdygk9svigkkzybgicdwlkpqs";
url = "https://pub.dartlang.org/packages/checked_yaml/versions/2.0.1.tar.gz"; url = "https://pub.dartlang.org/packages/checked_yaml/versions/2.0.3.tar.gz";
stripRoot = false; stripRoot = false;
extension = "tar.gz"; extension = "tar.gz";
}; };
code_builder = fetchzip { code_builder = fetchzip {
sha256 = "1vl9dl23yd0zjw52ndrazijs6dw83fg1rvyb2gfdpd6n1lj9nbhg"; sha256 = "1shgl7mxiyv0hhw326yqj2b9jxi1h74qxmsnxf1d1xc6yz766p9a";
url = "https://pub.dartlang.org/packages/code_builder/versions/4.3.0.tar.gz"; url = "https://pub.dartlang.org/packages/code_builder/versions/4.6.0.tar.gz";
stripRoot = false; stripRoot = false;
extension = "tar.gz"; extension = "tar.gz";
}; };
collection = fetchzip { collection = fetchzip {
sha256 = "1iyl3v3j7mj3sxjf63b1kc182fwrwd04mjp5x2i61hic8ihfw545"; sha256 = "1mr8j0078c4z9hhckiq8m735rggsazwfprm0w9gisil51vh7j2mk";
url = "https://pub.dartlang.org/packages/collection/versions/1.17.0.tar.gz"; url = "https://pub.dartlang.org/packages/collection/versions/1.18.0.tar.gz";
stripRoot = false; stripRoot = false;
extension = "tar.gz"; extension = "tar.gz";
}; };
@@ -119,29 +121,29 @@
}; };
coverage = fetchzip { coverage = fetchzip {
sha256 = "0akbg1yp2h4vprc8r9xvrpgvp5d26h7m80h5sbzgr5dlis1bcw0d"; sha256 = "1yy9bgkax5b6kk7qa07p452v82fyj4rl1j03fn366ywyvhfrh6lp";
url = "https://pub.dartlang.org/packages/coverage/versions/1.6.1.tar.gz"; url = "https://pub.dartlang.org/packages/coverage/versions/1.6.3.tar.gz";
stripRoot = false; stripRoot = false;
extension = "tar.gz"; extension = "tar.gz";
}; };
crypto = fetchzip { crypto = fetchzip {
sha256 = "1kjfb8fvdxazmv9ps2iqdhb8kcr31115h0nwn6v4xmr71k8jb8ds"; sha256 = "100ai8qa4p3dyvvd60c4xa9p0gm06yh0d68xgcfm3giraad8xmqj";
url = "https://pub.dartlang.org/packages/crypto/versions/3.0.2.tar.gz"; url = "https://pub.dartlang.org/packages/crypto/versions/3.0.3.tar.gz";
stripRoot = false; stripRoot = false;
extension = "tar.gz"; extension = "tar.gz";
}; };
cryptography = fetchzip { cryptography = fetchzip {
sha256 = "0jqph45d9lbhdakprnb84c3qhk4aq05hhb1pmn8w23yhl41ypijs"; sha256 = "1yxn9slqq93ri81fbr2nbsinz0mpk9wk39ny076ja8q31d4i8v3f";
url = "https://pub.dartlang.org/packages/cryptography/versions/2.0.5.tar.gz"; url = "https://pub.dartlang.org/packages/cryptography/versions/2.5.0.tar.gz";
stripRoot = false; stripRoot = false;
extension = "tar.gz"; extension = "tar.gz";
}; };
dart_style = fetchzip { dart_style = fetchzip {
sha256 = "01wg15kalbjlh4i3xbawc9zk8yrk28qhak7xp7mlwn2syhdckn7v"; sha256 = "0cjhrb1hs8iw9smmfd0fgnxq3nm0w8sz17l6q6svyz6kif19wk9k";
url = "https://pub.dartlang.org/packages/dart_style/versions/2.2.4.tar.gz"; url = "https://pub.dartlang.org/packages/dart_style/versions/2.3.2.tar.gz";
stripRoot = false; stripRoot = false;
extension = "tar.gz"; extension = "tar.gz";
}; };
@@ -154,43 +156,29 @@
}; };
fixnum = fetchzip { fixnum = fetchzip {
sha256 = "1m8cdfqp9d6w1cik3fwz9bai1wf9j11rjv2z0zlv7ich87q9kkjk"; sha256 = "0nqrzj41ys8dpxf1x70r0kfj1avj0f2j2b7498k8kvc0i9c5asz7";
url = "https://pub.dartlang.org/packages/fixnum/versions/1.0.1.tar.gz"; url = "https://pub.dartlang.org/packages/fixnum/versions/1.1.0.tar.gz";
stripRoot = false;
extension = "tar.gz";
};
freezed = fetchzip {
sha256 = "1i9s4djf4vlz56zqn8brcck3n7sk07qay23wmaan991cqydd10iq";
url = "https://pub.dartlang.org/packages/freezed/versions/2.1.1.tar.gz";
stripRoot = false;
extension = "tar.gz";
};
freezed_annotation = fetchzip {
sha256 = "0ym120dh1lpfnb68gxh1finm8p9l445q5x10aw8269y469b9k9z3";
url = "https://pub.dartlang.org/packages/freezed_annotation/versions/2.1.0.tar.gz";
stripRoot = false; stripRoot = false;
extension = "tar.gz"; extension = "tar.gz";
}; };
frontend_server_client = fetchzip { frontend_server_client = fetchzip {
sha256 = "0nv4avkv2if9hdcfzckz36f3mclv7vxchivrg8j3miaqhnjvv4bj"; sha256 = "096v7ycix5hgnk750s1qgykyghl2mymhdkg39jrlk3kbj6xygq5b";
url = "https://pub.dartlang.org/packages/frontend_server_client/versions/3.1.0.tar.gz"; url = "https://pub.dartlang.org/packages/frontend_server_client/versions/3.2.0.tar.gz";
stripRoot = false; stripRoot = false;
extension = "tar.gz"; extension = "tar.gz";
}; };
glob = fetchzip { glob = fetchzip {
sha256 = "0a6gbwsbz6rkg35dkff0zv88rvcflqdmda90hdfpn7jp1z1w9rhs"; sha256 = "0ffab3azx8zkma36mk6wnig8bn8g5g0vjrq2gl21y77rxgw9iqxj";
url = "https://pub.dartlang.org/packages/glob/versions/2.1.0.tar.gz"; url = "https://pub.dartlang.org/packages/glob/versions/2.1.2.tar.gz";
stripRoot = false; stripRoot = false;
extension = "tar.gz"; extension = "tar.gz";
}; };
graphs = fetchzip { graphs = fetchzip {
sha256 = "0cr6dgs1a7ln2ir5gd0kiwpn787lk4dwhqfjv8876hkkr1rv80m9"; sha256 = "0fda0j8y6sq1rc9zpzglrzysl5h49y2ji1wq2lq0wx2c609dxm7f";
url = "https://pub.dartlang.org/packages/graphs/versions/2.2.0.tar.gz"; url = "https://pub.dartlang.org/packages/graphs/versions/2.3.1.tar.gz";
stripRoot = false; stripRoot = false;
extension = "tar.gz"; extension = "tar.gz";
}; };
@@ -217,78 +205,78 @@
}; };
io = fetchzip { io = fetchzip {
sha256 = "1bp5l8hkrp6fjj7zw9af51hxyp52sjspc5558lq0lmi453l0czni"; sha256 = "101kd0rw26vglmr1m5p130kbrp3k7dk4p5nr77wsbwgg53w8c0d4";
url = "https://pub.dartlang.org/packages/io/versions/1.0.3.tar.gz"; url = "https://pub.dartlang.org/packages/io/versions/1.0.4.tar.gz";
stripRoot = false; stripRoot = false;
extension = "tar.gz"; extension = "tar.gz";
}; };
js = fetchzip { js = fetchzip {
sha256 = "13fbxgyg1v6bmzvxamg6494vk3923fn3mgxj6f4y476aqwk99n50"; sha256 = "124a9yqrjdw3p4nnirab9hm9ziwraldlw4q5cb3sr0dcrli74qpw";
url = "https://pub.dartlang.org/packages/js/versions/0.6.5.tar.gz"; url = "https://pub.dartlang.org/packages/js/versions/0.6.7.tar.gz";
stripRoot = false; stripRoot = false;
extension = "tar.gz"; extension = "tar.gz";
}; };
json_annotation = fetchzip { json_annotation = fetchzip {
sha256 = "1p9nvn33psx2zbalhyqjw8gr4agd76jj5jq0fdz0i584c7l77bby"; sha256 = "1jjw7p8qyqajgdq4jqvxipq5w0qrq9dpi1qmia70pk995akryh6m";
url = "https://pub.dartlang.org/packages/json_annotation/versions/4.7.0.tar.gz"; url = "https://pub.dartlang.org/packages/json_annotation/versions/4.8.1.tar.gz";
stripRoot = false; stripRoot = false;
extension = "tar.gz"; extension = "tar.gz";
}; };
json_serializable = fetchzip { json_serializable = fetchzip {
sha256 = "04d7laaxrbiybcgbv3y223hy8d6n9f84h5lv9sv79zd9ffzkb2hg"; sha256 = "1pmidql9x6s2pbhdx9x20pwqwvwpfkvrz0h0cm1f8pqis76c90hb";
url = "https://pub.dartlang.org/packages/json_serializable/versions/6.5.4.tar.gz"; url = "https://pub.dartlang.org/packages/json_serializable/versions/6.6.2.tar.gz";
stripRoot = false; stripRoot = false;
extension = "tar.gz"; extension = "tar.gz";
}; };
logging = fetchzip { logging = fetchzip {
sha256 = "0hl1mjh662c44ci7z60x92i0jsyqg1zm6k6fc89n9pdcxsqdpwfs"; sha256 = "124hfjs66r30p92ndfmy5fymgy66yk9in97h8sq6fi7r78pqyc7g";
url = "https://pub.dartlang.org/packages/logging/versions/1.0.2.tar.gz"; url = "https://pub.dartlang.org/packages/logging/versions/1.2.0.tar.gz";
stripRoot = false; stripRoot = false;
extension = "tar.gz"; extension = "tar.gz";
}; };
matcher = fetchzip { matcher = fetchzip {
sha256 = "0pjgc38clnjbv124n8bh724db1wcc4kk125j7dxl0icz7clvm0p0"; sha256 = "0inznqkrxqnq09lcbwvda3xd07qfm1k3aa6dv1wy39gvci8hybss";
url = "https://pub.dartlang.org/packages/matcher/versions/0.12.13.tar.gz"; url = "https://pub.dartlang.org/packages/matcher/versions/0.12.16.tar.gz";
stripRoot = false; stripRoot = false;
extension = "tar.gz"; extension = "tar.gz";
}; };
meta = fetchzip { meta = fetchzip {
sha256 = "01kqdd25nln5a219pr94s66p27m0kpqz0wpmwnm24kdy3ngif1v5"; sha256 = "1l3zaz6q2s9mnm7s674xshsfqspy79p5kdbbnc99rf2l76avv4h3";
url = "https://pub.dartlang.org/packages/meta/versions/1.8.0.tar.gz"; url = "https://pub.dartlang.org/packages/meta/versions/1.9.1.tar.gz";
stripRoot = false; stripRoot = false;
extension = "tar.gz"; extension = "tar.gz";
}; };
mime = fetchzip { mime = fetchzip {
sha256 = "1dr3qikzvp10q1saka7azki5gk2kkf2v7k9wfqjsyxmza2zlv896"; sha256 = "1dha9z64bsz8xhi0p62vmlyikr8xwbdlrw90hxghmm3rdgd9h25w";
url = "https://pub.dartlang.org/packages/mime/versions/1.0.2.tar.gz"; url = "https://pub.dartlang.org/packages/mime/versions/1.0.4.tar.gz";
stripRoot = false; stripRoot = false;
extension = "tar.gz"; extension = "tar.gz";
}; };
moxlib = fetchzip { moxlib = fetchzip {
sha256 = "1j52xglpwy8c7dbylc3f6vrh0p52xhhwqs4h0qcqk8c1rvjn5czq"; sha256 = "1qaacmcqhq33grn2nq8sn23ki62dcmw0fqy589xm1zv6w0pzfmsk";
url = "https://git.polynom.me/api/packages/moxxy/pub/api/packages/moxlib/files/0.1.5.tar.gz"; url = "https://git.polynom.me/api/packages/moxxy/pub/api/packages/moxlib/files/0.2.0.tar.gz";
stripRoot = false; stripRoot = false;
extension = "tar.gz"; extension = "tar.gz";
}; };
node_preamble = fetchzip { node_preamble = fetchzip {
sha256 = "0i0gfc2yqa09182vc01lj47qpq98kfm9m8h4n8c5fby0mjd0lvyx"; sha256 = "12ajg76r9aqmqkavvlxbnb3sszg1szcq3f30badkd0xc25mnhyh8";
url = "https://pub.dartlang.org/packages/node_preamble/versions/2.0.1.tar.gz"; url = "https://pub.dartlang.org/packages/node_preamble/versions/2.0.2.tar.gz";
stripRoot = false; stripRoot = false;
extension = "tar.gz"; extension = "tar.gz";
}; };
omemo_dart = fetchzip { omemo_dart = fetchzip {
sha256 = "09x3jqa11hjdjp31nxnz91j6jssbc2f8a1lh44fmkc0d79hs8bbi"; sha256 = "0fhf89ic5mdyld25l6rfb37a1fk1f0f2b4d72xi4r7pvr0ddjhz8";
url = "https://git.polynom.me/api/packages/PapaTutuWawa/pub/api/packages/omemo_dart/files/0.4.3.tar.gz"; url = "https://git.polynom.me/api/packages/PapaTutuWawa/pub/api/packages/omemo_dart/files/0.5.1.tar.gz";
stripRoot = false; stripRoot = false;
extension = "tar.gz"; extension = "tar.gz";
}; };
@@ -301,8 +289,8 @@
}; };
path = fetchzip { path = fetchzip {
sha256 = "16ggdh29ciy7h8sdshhwmxn6dd12sfbykf2j82c56iwhhlljq181"; sha256 = "1mjdhq2fsz6i9krhp2mnaks2bcw34sa4p7mg0v6njk8dgx2754iv";
url = "https://pub.dartlang.org/packages/path/versions/1.8.2.tar.gz"; url = "https://pub.dartlang.org/packages/path/versions/1.8.3.tar.gz";
stripRoot = false; stripRoot = false;
extension = "tar.gz"; extension = "tar.gz";
}; };
@@ -315,8 +303,8 @@
}; };
petitparser = fetchzip { petitparser = fetchzip {
sha256 = "1pqqqqiy9ald24qsi24q9qrr0zphgpsrnrv9rlx4vwr6xak7d8c0"; sha256 = "19zqrpb1z77aw1k2s8rsxdfxczzv9934g2rdfj2jyiv3pqgdq8gh";
url = "https://pub.dartlang.org/packages/petitparser/versions/5.1.0.tar.gz"; url = "https://pub.dartlang.org/packages/petitparser/versions/5.4.0.tar.gz";
stripRoot = false; stripRoot = false;
extension = "tar.gz"; extension = "tar.gz";
}; };
@@ -335,16 +323,30 @@
extension = "tar.gz"; extension = "tar.gz";
}; };
protobuf = fetchzip {
sha256 = "1jriyisf8bnvq5ygjk93mn2yzdlnii7xrhy6aabz54xr3y4dcy9x";
url = "https://pub.dartlang.org/packages/protobuf/versions/2.1.0.tar.gz";
stripRoot = false;
extension = "tar.gz";
};
protoc_plugin = fetchzip {
sha256 = "0hjjd1xkv4s4g1d5n2aza0kdwlbfl2aivq99230m3yml7irn00jk";
url = "https://pub.dartlang.org/packages/protoc_plugin/versions/20.0.1.tar.gz";
stripRoot = false;
extension = "tar.gz";
};
pub_semver = fetchzip { pub_semver = fetchzip {
sha256 = "1vsj5c1f2dza4l5zmjix4zh65lp8gsg6pw01h57pijx2id0g4bwi"; sha256 = "0wpcfz1crxipbjm18m71pl4vl2ra8vw1n93ff8snr54mmlyfb9z1";
url = "https://pub.dartlang.org/packages/pub_semver/versions/2.1.2.tar.gz"; url = "https://pub.dartlang.org/packages/pub_semver/versions/2.1.4.tar.gz";
stripRoot = false; stripRoot = false;
extension = "tar.gz"; extension = "tar.gz";
}; };
pubspec_parse = fetchzip { pubspec_parse = fetchzip {
sha256 = "19dmr9k4wsqjnhlzp1lbrw8dv7a1gnwmr8l5j9zlw407rmfg20d1"; sha256 = "0dj8sf1w61g7vh1ly3sl690z0nwllzjzbapxswmgsglr0ndcyrs1";
url = "https://pub.dartlang.org/packages/pubspec_parse/versions/1.2.1.tar.gz"; url = "https://pub.dartlang.org/packages/pubspec_parse/versions/1.2.3.tar.gz";
stripRoot = false; stripRoot = false;
extension = "tar.gz"; extension = "tar.gz";
}; };
@@ -364,43 +366,43 @@
}; };
shelf = fetchzip { shelf = fetchzip {
sha256 = "0x2xl7glrnq0hdxpy2i94a4wxbdrd6dm46hvhzgjn8alsm8z0wz1"; sha256 = "10yk98nadrgj5d3r3241kdaywjjs1j10mg8gacv80kg1mhcfdrxp";
url = "https://pub.dartlang.org/packages/shelf/versions/1.4.0.tar.gz"; url = "https://pub.dartlang.org/packages/shelf/versions/1.4.1.tar.gz";
stripRoot = false; stripRoot = false;
extension = "tar.gz"; extension = "tar.gz";
}; };
shelf_packages_handler = fetchzip { shelf_packages_handler = fetchzip {
sha256 = "199rbdbifj46lg3iynznnsbs8zr4dfcw0s7wan8v73nvpqvli82q"; sha256 = "1h8s42nff9ar0xn7yb42m64lpvmqzq8wranqrkkixdnp7w3pmv1x";
url = "https://pub.dartlang.org/packages/shelf_packages_handler/versions/3.0.1.tar.gz"; url = "https://pub.dartlang.org/packages/shelf_packages_handler/versions/3.0.2.tar.gz";
stripRoot = false; stripRoot = false;
extension = "tar.gz"; extension = "tar.gz";
}; };
shelf_static = fetchzip { shelf_static = fetchzip {
sha256 = "1kqbaslz7bna9lldda3ibrjg0gczbzlwgm9cic8shg0bnl0v3s34"; sha256 = "1bcqynn2z2syrigmrclxgg8hjhd1x9742938i62cicbaga6vclaz";
url = "https://pub.dartlang.org/packages/shelf_static/versions/1.1.1.tar.gz"; url = "https://pub.dartlang.org/packages/shelf_static/versions/1.1.2.tar.gz";
stripRoot = false; stripRoot = false;
extension = "tar.gz"; extension = "tar.gz";
}; };
shelf_web_socket = fetchzip { shelf_web_socket = fetchzip {
sha256 = "0rr87nx2wdf9alippxiidqlgi82fbprnsarr1jswg9qin0yy4jpn"; sha256 = "110b5hrqwpnmq16shxxzjmcih5yfs5kh80dn8avfv0xj5iv7n94c";
url = "https://pub.dartlang.org/packages/shelf_web_socket/versions/1.0.3.tar.gz"; url = "https://pub.dartlang.org/packages/shelf_web_socket/versions/1.0.4.tar.gz";
stripRoot = false; stripRoot = false;
extension = "tar.gz"; extension = "tar.gz";
}; };
source_gen = fetchzip { source_gen = fetchzip {
sha256 = "1kxgx782lzpjhv736h0pz3lnxpcgiy05h0ysy0q77gix8q09i1hz"; sha256 = "1jql5zccv4vnbbvwcpyyvz8l27pg1rviqbp4vrks5313nf4b0kjg";
url = "https://pub.dartlang.org/packages/source_gen/versions/1.2.6.tar.gz"; url = "https://pub.dartlang.org/packages/source_gen/versions/1.3.2.tar.gz";
stripRoot = false; stripRoot = false;
extension = "tar.gz"; extension = "tar.gz";
}; };
source_helper = fetchzip { source_helper = fetchzip {
sha256 = "044kzmzlfpx93s4raz5avijahizmvai0zvl0lbm4wi93ynhdp1pd"; sha256 = "0mdd02vhcdcv9n58gzbx2q0bphwj0alz312ca1a8xpkf8jx3y8v4";
url = "https://pub.dartlang.org/packages/source_helper/versions/1.3.3.tar.gz"; url = "https://pub.dartlang.org/packages/source_helper/versions/1.3.4.tar.gz";
stripRoot = false; stripRoot = false;
extension = "tar.gz"; extension = "tar.gz";
}; };
@@ -413,29 +415,29 @@
}; };
source_maps = fetchzip { source_maps = fetchzip {
sha256 = "18ixrlz3l2alk3hp0884qj0mcgzhxmjpg6nq0n1200pfy62pc4z6"; sha256 = "004lcfka01agxjdw7zjhrffdkisvgx5s61b5gsl8qqk2jd1rswa7";
url = "https://pub.dartlang.org/packages/source_maps/versions/0.10.11.tar.gz"; url = "https://pub.dartlang.org/packages/source_maps/versions/0.10.12.tar.gz";
stripRoot = false; stripRoot = false;
extension = "tar.gz"; extension = "tar.gz";
}; };
source_span = fetchzip { source_span = fetchzip {
sha256 = "1lq4sy7lw15qsv9cijf6l48p16qr19r7njzwr4pxn8vv1kh6rb86"; sha256 = "1nybnf7l5chslp4fczhqnrgrhymy844lw7qrj6y08i626dshrd46";
url = "https://pub.dartlang.org/packages/source_span/versions/1.9.1.tar.gz"; url = "https://pub.dartlang.org/packages/source_span/versions/1.10.0.tar.gz";
stripRoot = false; stripRoot = false;
extension = "tar.gz"; extension = "tar.gz";
}; };
stack_trace = fetchzip { stack_trace = fetchzip {
sha256 = "0bggqvvpkrfvqz24bnir4959k0c45azc3zivk4lyv3mvba6092na"; sha256 = "0xpk2cvmgdh46iwip9jsb54fqx13jnina8pk03akxkmsxvag5izb";
url = "https://pub.dartlang.org/packages/stack_trace/versions/1.11.0.tar.gz"; url = "https://pub.dartlang.org/packages/stack_trace/versions/1.11.1.tar.gz";
stripRoot = false; stripRoot = false;
extension = "tar.gz"; extension = "tar.gz";
}; };
stream_channel = fetchzip { stream_channel = fetchzip {
sha256 = "054by84c60yxphr3qgg6f82gg6d22a54aqjp265anlm8dwz1ji32"; sha256 = "0nrlw6zcscgnn6818krkbgs9qiv3f7q8pa7ljw1bqkrsb7xabm8s";
url = "https://pub.dartlang.org/packages/stream_channel/versions/2.1.1.tar.gz"; url = "https://pub.dartlang.org/packages/stream_channel/versions/2.1.2.tar.gz";
stripRoot = false; stripRoot = false;
extension = "tar.gz"; extension = "tar.gz";
}; };
@@ -455,8 +457,8 @@
}; };
synchronized = fetchzip { synchronized = fetchzip {
sha256 = "1j6108cq1hbcqpwhk9sah8q3gcidd7222bzhha2nk9syxhzqy82i"; sha256 = "1fx1z1p5qkn4qnq24riw5s86vmq645ppg8f74iyv2fc9rvr301ar";
url = "https://pub.dartlang.org/packages/synchronized/versions/3.0.0%2B2.tar.gz"; url = "https://pub.dartlang.org/packages/synchronized/versions/3.1.0.tar.gz";
stripRoot = false; stripRoot = false;
extension = "tar.gz"; extension = "tar.gz";
}; };
@@ -469,36 +471,36 @@
}; };
test = fetchzip { test = fetchzip {
sha256 = "08kimbjvkdw3bkj7za36p3yqdr8dnlb5v30c250kvdncb7k09h4x"; sha256 = "002phlj2pg6nll5hv449izxbqk29zwmwc77d0jx2iimz18dgy2r5";
url = "https://pub.dartlang.org/packages/test/versions/1.22.0.tar.gz"; url = "https://pub.dartlang.org/packages/test/versions/1.24.3.tar.gz";
stripRoot = false; stripRoot = false;
extension = "tar.gz"; extension = "tar.gz";
}; };
test_api = fetchzip { test_api = fetchzip {
sha256 = "0mfyjpqkkmaqdh7xygrydx12591wq9ll816f61n80dc6rmkdx7px"; sha256 = "0as1xcywjrd2zax3cm56qmnac12shf8c1ynnzzjwnggm23f61dxb";
url = "https://pub.dartlang.org/packages/test_api/versions/0.4.16.tar.gz"; url = "https://pub.dartlang.org/packages/test_api/versions/0.6.0.tar.gz";
stripRoot = false; stripRoot = false;
extension = "tar.gz"; extension = "tar.gz";
}; };
test_core = fetchzip { test_core = fetchzip {
sha256 = "1r8dnvkxxvh55z1c8lrsja1m0dkf5i4lgwwqixcx0mqvxx5w3005"; sha256 = "1cx2rmz1xzk5z5yh8fpbsrsz4mgjanrw4xvnp0qzdnm2d7vhaq0y";
url = "https://pub.dartlang.org/packages/test_core/versions/0.4.20.tar.gz"; url = "https://pub.dartlang.org/packages/test_core/versions/0.5.3.tar.gz";
stripRoot = false; stripRoot = false;
extension = "tar.gz"; extension = "tar.gz";
}; };
timing = fetchzip { timing = fetchzip {
sha256 = "0a02znvy0fbzr0n4ai67pp8in7w6m768aynkk1kp5lnmgy17ppsg"; sha256 = "15jvxsw7v0gwbdlykma60l1qlhlzb3brh6m0sg2bgbfir4l5s9gw";
url = "https://pub.dartlang.org/packages/timing/versions/1.0.0.tar.gz"; url = "https://pub.dartlang.org/packages/timing/versions/1.0.1.tar.gz";
stripRoot = false; stripRoot = false;
extension = "tar.gz"; extension = "tar.gz";
}; };
typed_data = fetchzip { typed_data = fetchzip {
sha256 = "1x402bvyzdmdvmyqhyfamjxf54p9j8sa8ns2n5dwsdhnfqbw859g"; sha256 = "0q6ggc52vfpr8kqaq69h757wy942hvgshhnsr2pjdinb4zk2sxl1";
url = "https://pub.dartlang.org/packages/typed_data/versions/1.3.1.tar.gz"; url = "https://pub.dartlang.org/packages/typed_data/versions/1.3.2.tar.gz";
stripRoot = false; stripRoot = false;
extension = "tar.gz"; extension = "tar.gz";
}; };
@@ -511,8 +513,8 @@
}; };
uuid = fetchzip { uuid = fetchzip {
sha256 = "12lsynr07lw9848jknmzxvzn3ia12xdj07iiva0vg0qjvpq7ladg"; sha256 = "1nh1hxfr6bhyadqqcxrpwrphmm75f1iq4rzfjdwa2486xwlh7vx3";
url = "https://pub.dartlang.org/packages/uuid/versions/3.0.5.tar.gz"; url = "https://pub.dartlang.org/packages/uuid/versions/3.0.7.tar.gz";
stripRoot = false; stripRoot = false;
extension = "tar.gz"; extension = "tar.gz";
}; };
@@ -525,8 +527,8 @@
}; };
vm_service = fetchzip { vm_service = fetchzip {
sha256 = "05xaxaxzyfls6jklw1hzws2jmina1cjk10gbl7a63djh1ghnzjb5"; sha256 = "15ail7rbaq9ksg73cc0mw2k5imbiidl95yfd4v49k81gp5xmj92w";
url = "https://pub.dartlang.org/packages/vm_service/versions/9.4.0.tar.gz"; url = "https://pub.dartlang.org/packages/vm_service/versions/11.10.0.tar.gz";
stripRoot = false; stripRoot = false;
extension = "tar.gz"; extension = "tar.gz";
}; };
@@ -539,8 +541,8 @@
}; };
web_socket_channel = fetchzip { web_socket_channel = fetchzip {
sha256 = "147amn05v1f1a1grxjr7yzgshrczjwijwiywggsv6dgic8kxyj5a"; sha256 = "0f9441c4zifb5qadpjg319dcilimpkdhfacnkl543802bf8qjn4w";
url = "https://pub.dartlang.org/packages/web_socket_channel/versions/2.2.0.tar.gz"; url = "https://pub.dartlang.org/packages/web_socket_channel/versions/2.4.0.tar.gz";
stripRoot = false; stripRoot = false;
extension = "tar.gz"; extension = "tar.gz";
}; };
@@ -553,262 +555,262 @@
}; };
xml = fetchzip { xml = fetchzip {
sha256 = "0jwknkfcnb5svg6r01xjsj0aiw06mlx54pgay1ymaaqm2mjhyz01"; sha256 = "120azx71gazvrrn07vd83vrffzrhsqnmf9rdjxl73rra9py8ixiy";
url = "https://pub.dartlang.org/packages/xml/versions/6.2.0.tar.gz"; url = "https://pub.dartlang.org/packages/xml/versions/6.3.0.tar.gz";
stripRoot = false; stripRoot = false;
extension = "tar.gz"; extension = "tar.gz";
}; };
yaml = fetchzip { yaml = fetchzip {
sha256 = "0mqqmzn3c9rr38b5xm312fz1vyp6vb36lm477r9hak77bxzpp0iw"; sha256 = "0awh9dynbhrlq8zgszaiyxbyyn9b6wyps1zww4z2lx62nbma0pda";
url = "https://pub.dartlang.org/packages/yaml/versions/3.1.1.tar.gz"; url = "https://pub.dartlang.org/packages/yaml/versions/3.1.2.tar.gz";
stripRoot = false; stripRoot = false;
extension = "tar.gz"; extension = "tar.gz";
}; };
pubCache = runCommand "moxxmpp-pub-cache" {} '' pubCache = runCommand "moxxmpp-pub-cache" {} ''
mkdir -p $out/hosted/pub.dartlang.org mkdir -p $out/hosted/pub.dev
ln -s ${_fe_analyzer_shared} $out/hosted/pub.dartlang.org/_fe_analyzer_shared-50.0.0 ln -s ${_fe_analyzer_shared} $out/hosted/pub.dev/_fe_analyzer_shared-61.0.0
mkdir -p $out/hosted/pub.dartlang.org mkdir -p $out/hosted/pub.dev
ln -s ${analyzer} $out/hosted/pub.dartlang.org/analyzer-5.2.0 ln -s ${analyzer} $out/hosted/pub.dev/analyzer-5.13.0
mkdir -p $out/hosted/pub.dartlang.org mkdir -p $out/hosted/pub.dev
ln -s ${args} $out/hosted/pub.dartlang.org/args-2.3.1 ln -s ${args} $out/hosted/pub.dev/args-2.4.2
mkdir -p $out/hosted/pub.dartlang.org mkdir -p $out/hosted/pub.dev
ln -s ${async} $out/hosted/pub.dartlang.org/async-2.10.0 ln -s ${async} $out/hosted/pub.dev/async-2.11.0
mkdir -p $out/hosted/pub.dartlang.org mkdir -p $out/hosted/pub.dev
ln -s ${boolean_selector} $out/hosted/pub.dartlang.org/boolean_selector-2.1.1 ln -s ${boolean_selector} $out/hosted/pub.dev/boolean_selector-2.1.1
mkdir -p $out/hosted/pub.dartlang.org mkdir -p $out/hosted/pub.dev
ln -s ${build} $out/hosted/pub.dartlang.org/build-2.3.1 ln -s ${build} $out/hosted/pub.dev/build-2.3.1
mkdir -p $out/hosted/pub.dartlang.org mkdir -p $out/hosted/pub.dev
ln -s ${build_config} $out/hosted/pub.dartlang.org/build_config-1.1.1 ln -s ${build_config} $out/hosted/pub.dev/build_config-1.1.1
mkdir -p $out/hosted/pub.dartlang.org mkdir -p $out/hosted/pub.dev
ln -s ${build_daemon} $out/hosted/pub.dartlang.org/build_daemon-3.1.0 ln -s ${build_daemon} $out/hosted/pub.dev/build_daemon-3.1.1
mkdir -p $out/hosted/pub.dartlang.org mkdir -p $out/hosted/pub.dev
ln -s ${build_resolvers} $out/hosted/pub.dartlang.org/build_resolvers-2.1.0 ln -s ${build_resolvers} $out/hosted/pub.dev/build_resolvers-2.3.1
mkdir -p $out/hosted/pub.dartlang.org mkdir -p $out/hosted/pub.dev
ln -s ${build_runner} $out/hosted/pub.dartlang.org/build_runner-2.3.2 ln -s ${build_runner} $out/hosted/pub.dev/build_runner-2.3.3
mkdir -p $out/hosted/pub.dartlang.org mkdir -p $out/hosted/pub.dev
ln -s ${build_runner_core} $out/hosted/pub.dartlang.org/build_runner_core-7.2.7 ln -s ${build_runner_core} $out/hosted/pub.dev/build_runner_core-7.2.7+1
mkdir -p $out/hosted/pub.dartlang.org mkdir -p $out/hosted/pub.dev
ln -s ${built_collection} $out/hosted/pub.dartlang.org/built_collection-5.1.1 ln -s ${built_collection} $out/hosted/pub.dev/built_collection-5.1.1
mkdir -p $out/hosted/pub.dartlang.org mkdir -p $out/hosted/pub.dev
ln -s ${built_value} $out/hosted/pub.dartlang.org/built_value-8.4.2 ln -s ${built_value} $out/hosted/pub.dev/built_value-8.6.2
mkdir -p $out/hosted/pub.dartlang.org mkdir -p $out/hosted/pub.dev
ln -s ${checked_yaml} $out/hosted/pub.dartlang.org/checked_yaml-2.0.1 ln -s ${checked_yaml} $out/hosted/pub.dev/checked_yaml-2.0.3
mkdir -p $out/hosted/pub.dartlang.org mkdir -p $out/hosted/pub.dev
ln -s ${code_builder} $out/hosted/pub.dartlang.org/code_builder-4.3.0 ln -s ${code_builder} $out/hosted/pub.dev/code_builder-4.6.0
mkdir -p $out/hosted/pub.dartlang.org mkdir -p $out/hosted/pub.dev
ln -s ${collection} $out/hosted/pub.dartlang.org/collection-1.17.0 ln -s ${collection} $out/hosted/pub.dev/collection-1.18.0
mkdir -p $out/hosted/pub.dartlang.org mkdir -p $out/hosted/pub.dev
ln -s ${convert} $out/hosted/pub.dartlang.org/convert-3.1.1 ln -s ${convert} $out/hosted/pub.dev/convert-3.1.1
mkdir -p $out/hosted/pub.dartlang.org mkdir -p $out/hosted/pub.dev
ln -s ${coverage} $out/hosted/pub.dartlang.org/coverage-1.6.1 ln -s ${coverage} $out/hosted/pub.dev/coverage-1.6.3
mkdir -p $out/hosted/pub.dartlang.org mkdir -p $out/hosted/pub.dev
ln -s ${crypto} $out/hosted/pub.dartlang.org/crypto-3.0.2 ln -s ${crypto} $out/hosted/pub.dev/crypto-3.0.3
mkdir -p $out/hosted/pub.dartlang.org mkdir -p $out/hosted/pub.dev
ln -s ${cryptography} $out/hosted/pub.dartlang.org/cryptography-2.0.5 ln -s ${cryptography} $out/hosted/pub.dev/cryptography-2.5.0
mkdir -p $out/hosted/pub.dartlang.org mkdir -p $out/hosted/pub.dev
ln -s ${dart_style} $out/hosted/pub.dartlang.org/dart_style-2.2.4 ln -s ${dart_style} $out/hosted/pub.dev/dart_style-2.3.2
mkdir -p $out/hosted/pub.dartlang.org mkdir -p $out/hosted/pub.dev
ln -s ${file} $out/hosted/pub.dartlang.org/file-6.1.4 ln -s ${file} $out/hosted/pub.dev/file-6.1.4
mkdir -p $out/hosted/pub.dartlang.org mkdir -p $out/hosted/pub.dev
ln -s ${fixnum} $out/hosted/pub.dartlang.org/fixnum-1.0.1 ln -s ${fixnum} $out/hosted/pub.dev/fixnum-1.1.0
mkdir -p $out/hosted/pub.dartlang.org mkdir -p $out/hosted/pub.dev
ln -s ${freezed} $out/hosted/pub.dartlang.org/freezed-2.1.1 ln -s ${frontend_server_client} $out/hosted/pub.dev/frontend_server_client-3.2.0
mkdir -p $out/hosted/pub.dartlang.org mkdir -p $out/hosted/pub.dev
ln -s ${freezed_annotation} $out/hosted/pub.dartlang.org/freezed_annotation-2.1.0 ln -s ${glob} $out/hosted/pub.dev/glob-2.1.2
mkdir -p $out/hosted/pub.dartlang.org mkdir -p $out/hosted/pub.dev
ln -s ${frontend_server_client} $out/hosted/pub.dartlang.org/frontend_server_client-3.1.0 ln -s ${graphs} $out/hosted/pub.dev/graphs-2.3.1
mkdir -p $out/hosted/pub.dartlang.org mkdir -p $out/hosted/pub.dev
ln -s ${glob} $out/hosted/pub.dartlang.org/glob-2.1.0 ln -s ${hex} $out/hosted/pub.dev/hex-0.2.0
mkdir -p $out/hosted/pub.dartlang.org mkdir -p $out/hosted/pub.dev
ln -s ${graphs} $out/hosted/pub.dartlang.org/graphs-2.2.0 ln -s ${http_multi_server} $out/hosted/pub.dev/http_multi_server-3.2.1
mkdir -p $out/hosted/pub.dartlang.org mkdir -p $out/hosted/pub.dev
ln -s ${hex} $out/hosted/pub.dartlang.org/hex-0.2.0 ln -s ${http_parser} $out/hosted/pub.dev/http_parser-4.0.2
mkdir -p $out/hosted/pub.dartlang.org mkdir -p $out/hosted/pub.dev
ln -s ${http_multi_server} $out/hosted/pub.dartlang.org/http_multi_server-3.2.1 ln -s ${io} $out/hosted/pub.dev/io-1.0.4
mkdir -p $out/hosted/pub.dartlang.org mkdir -p $out/hosted/pub.dev
ln -s ${http_parser} $out/hosted/pub.dartlang.org/http_parser-4.0.2 ln -s ${js} $out/hosted/pub.dev/js-0.6.7
mkdir -p $out/hosted/pub.dartlang.org mkdir -p $out/hosted/pub.dev
ln -s ${io} $out/hosted/pub.dartlang.org/io-1.0.3 ln -s ${json_annotation} $out/hosted/pub.dev/json_annotation-4.8.1
mkdir -p $out/hosted/pub.dartlang.org mkdir -p $out/hosted/pub.dev
ln -s ${js} $out/hosted/pub.dartlang.org/js-0.6.5 ln -s ${json_serializable} $out/hosted/pub.dev/json_serializable-6.6.2
mkdir -p $out/hosted/pub.dartlang.org mkdir -p $out/hosted/pub.dev
ln -s ${json_annotation} $out/hosted/pub.dartlang.org/json_annotation-4.7.0 ln -s ${logging} $out/hosted/pub.dev/logging-1.2.0
mkdir -p $out/hosted/pub.dartlang.org mkdir -p $out/hosted/pub.dev
ln -s ${json_serializable} $out/hosted/pub.dartlang.org/json_serializable-6.5.4 ln -s ${matcher} $out/hosted/pub.dev/matcher-0.12.16
mkdir -p $out/hosted/pub.dartlang.org mkdir -p $out/hosted/pub.dev
ln -s ${logging} $out/hosted/pub.dartlang.org/logging-1.0.2 ln -s ${meta} $out/hosted/pub.dev/meta-1.9.1
mkdir -p $out/hosted/pub.dartlang.org mkdir -p $out/hosted/pub.dev
ln -s ${matcher} $out/hosted/pub.dartlang.org/matcher-0.12.13 ln -s ${mime} $out/hosted/pub.dev/mime-1.0.4
mkdir -p $out/hosted/pub.dartlang.org
ln -s ${meta} $out/hosted/pub.dartlang.org/meta-1.8.0
mkdir -p $out/hosted/pub.dartlang.org
ln -s ${mime} $out/hosted/pub.dartlang.org/mime-1.0.2
mkdir -p $out/hosted/git.polynom.me%47api%47packages%47Moxxy%47pub%47 mkdir -p $out/hosted/git.polynom.me%47api%47packages%47Moxxy%47pub%47
ln -s ${moxlib} $out/hosted/git.polynom.me%47api%47packages%47Moxxy%47pub%47/moxlib-0.1.5 ln -s ${moxlib} $out/hosted/git.polynom.me%47api%47packages%47Moxxy%47pub%47/moxlib-0.2.0
mkdir -p $out/hosted/pub.dartlang.org mkdir -p $out/hosted/pub.dev
ln -s ${node_preamble} $out/hosted/pub.dartlang.org/node_preamble-2.0.1 ln -s ${node_preamble} $out/hosted/pub.dev/node_preamble-2.0.2
mkdir -p $out/hosted/git.polynom.me%47api%47packages%47PapaTutuWawa%47pub%47 mkdir -p $out/hosted/git.polynom.me%47api%47packages%47PapaTutuWawa%47pub%47
ln -s ${omemo_dart} $out/hosted/git.polynom.me%47api%47packages%47PapaTutuWawa%47pub%47/omemo_dart-0.4.3 ln -s ${omemo_dart} $out/hosted/git.polynom.me%47api%47packages%47PapaTutuWawa%47pub%47/omemo_dart-0.5.1
mkdir -p $out/hosted/pub.dartlang.org mkdir -p $out/hosted/pub.dev
ln -s ${package_config} $out/hosted/pub.dartlang.org/package_config-2.1.0 ln -s ${package_config} $out/hosted/pub.dev/package_config-2.1.0
mkdir -p $out/hosted/pub.dartlang.org mkdir -p $out/hosted/pub.dev
ln -s ${path} $out/hosted/pub.dartlang.org/path-1.8.2 ln -s ${path} $out/hosted/pub.dev/path-1.8.3
mkdir -p $out/hosted/pub.dartlang.org mkdir -p $out/hosted/pub.dev
ln -s ${pedantic} $out/hosted/pub.dartlang.org/pedantic-1.11.1 ln -s ${pedantic} $out/hosted/pub.dev/pedantic-1.11.1
mkdir -p $out/hosted/pub.dartlang.org mkdir -p $out/hosted/pub.dev
ln -s ${petitparser} $out/hosted/pub.dartlang.org/petitparser-5.1.0 ln -s ${petitparser} $out/hosted/pub.dev/petitparser-5.4.0
mkdir -p $out/hosted/pub.dartlang.org mkdir -p $out/hosted/pub.dev
ln -s ${pinenacl} $out/hosted/pub.dartlang.org/pinenacl-0.5.1 ln -s ${pinenacl} $out/hosted/pub.dev/pinenacl-0.5.1
mkdir -p $out/hosted/pub.dartlang.org mkdir -p $out/hosted/pub.dev
ln -s ${pool} $out/hosted/pub.dartlang.org/pool-1.5.1 ln -s ${pool} $out/hosted/pub.dev/pool-1.5.1
mkdir -p $out/hosted/pub.dartlang.org mkdir -p $out/hosted/pub.dev
ln -s ${pub_semver} $out/hosted/pub.dartlang.org/pub_semver-2.1.2 ln -s ${protobuf} $out/hosted/pub.dev/protobuf-2.1.0
mkdir -p $out/hosted/pub.dartlang.org mkdir -p $out/hosted/pub.dev
ln -s ${pubspec_parse} $out/hosted/pub.dartlang.org/pubspec_parse-1.2.1 ln -s ${protoc_plugin} $out/hosted/pub.dev/protoc_plugin-20.0.1
mkdir -p $out/hosted/pub.dartlang.org mkdir -p $out/hosted/pub.dev
ln -s ${random_string} $out/hosted/pub.dartlang.org/random_string-2.3.1 ln -s ${pub_semver} $out/hosted/pub.dev/pub_semver-2.1.4
mkdir -p $out/hosted/pub.dartlang.org mkdir -p $out/hosted/pub.dev
ln -s ${saslprep} $out/hosted/pub.dartlang.org/saslprep-1.0.2 ln -s ${pubspec_parse} $out/hosted/pub.dev/pubspec_parse-1.2.3
mkdir -p $out/hosted/pub.dartlang.org mkdir -p $out/hosted/pub.dev
ln -s ${shelf} $out/hosted/pub.dartlang.org/shelf-1.4.0 ln -s ${random_string} $out/hosted/pub.dev/random_string-2.3.1
mkdir -p $out/hosted/pub.dartlang.org mkdir -p $out/hosted/pub.dev
ln -s ${shelf_packages_handler} $out/hosted/pub.dartlang.org/shelf_packages_handler-3.0.1 ln -s ${saslprep} $out/hosted/pub.dev/saslprep-1.0.2
mkdir -p $out/hosted/pub.dartlang.org mkdir -p $out/hosted/pub.dev
ln -s ${shelf_static} $out/hosted/pub.dartlang.org/shelf_static-1.1.1 ln -s ${shelf} $out/hosted/pub.dev/shelf-1.4.1
mkdir -p $out/hosted/pub.dartlang.org mkdir -p $out/hosted/pub.dev
ln -s ${shelf_web_socket} $out/hosted/pub.dartlang.org/shelf_web_socket-1.0.3 ln -s ${shelf_packages_handler} $out/hosted/pub.dev/shelf_packages_handler-3.0.2
mkdir -p $out/hosted/pub.dartlang.org mkdir -p $out/hosted/pub.dev
ln -s ${source_gen} $out/hosted/pub.dartlang.org/source_gen-1.2.6 ln -s ${shelf_static} $out/hosted/pub.dev/shelf_static-1.1.2
mkdir -p $out/hosted/pub.dartlang.org mkdir -p $out/hosted/pub.dev
ln -s ${source_helper} $out/hosted/pub.dartlang.org/source_helper-1.3.3 ln -s ${shelf_web_socket} $out/hosted/pub.dev/shelf_web_socket-1.0.4
mkdir -p $out/hosted/pub.dartlang.org mkdir -p $out/hosted/pub.dev
ln -s ${source_map_stack_trace} $out/hosted/pub.dartlang.org/source_map_stack_trace-2.1.1 ln -s ${source_gen} $out/hosted/pub.dev/source_gen-1.3.2
mkdir -p $out/hosted/pub.dartlang.org mkdir -p $out/hosted/pub.dev
ln -s ${source_maps} $out/hosted/pub.dartlang.org/source_maps-0.10.11 ln -s ${source_helper} $out/hosted/pub.dev/source_helper-1.3.4
mkdir -p $out/hosted/pub.dartlang.org mkdir -p $out/hosted/pub.dev
ln -s ${source_span} $out/hosted/pub.dartlang.org/source_span-1.9.1 ln -s ${source_map_stack_trace} $out/hosted/pub.dev/source_map_stack_trace-2.1.1
mkdir -p $out/hosted/pub.dartlang.org mkdir -p $out/hosted/pub.dev
ln -s ${stack_trace} $out/hosted/pub.dartlang.org/stack_trace-1.11.0 ln -s ${source_maps} $out/hosted/pub.dev/source_maps-0.10.12
mkdir -p $out/hosted/pub.dartlang.org mkdir -p $out/hosted/pub.dev
ln -s ${stream_channel} $out/hosted/pub.dartlang.org/stream_channel-2.1.1 ln -s ${source_span} $out/hosted/pub.dev/source_span-1.10.0
mkdir -p $out/hosted/pub.dartlang.org mkdir -p $out/hosted/pub.dev
ln -s ${stream_transform} $out/hosted/pub.dartlang.org/stream_transform-2.1.0 ln -s ${stack_trace} $out/hosted/pub.dev/stack_trace-1.11.1
mkdir -p $out/hosted/pub.dartlang.org mkdir -p $out/hosted/pub.dev
ln -s ${string_scanner} $out/hosted/pub.dartlang.org/string_scanner-1.2.0 ln -s ${stream_channel} $out/hosted/pub.dev/stream_channel-2.1.2
mkdir -p $out/hosted/pub.dartlang.org mkdir -p $out/hosted/pub.dev
ln -s ${synchronized} $out/hosted/pub.dartlang.org/synchronized-3.0.0+2 ln -s ${stream_transform} $out/hosted/pub.dev/stream_transform-2.1.0
mkdir -p $out/hosted/pub.dartlang.org mkdir -p $out/hosted/pub.dev
ln -s ${term_glyph} $out/hosted/pub.dartlang.org/term_glyph-1.2.1 ln -s ${string_scanner} $out/hosted/pub.dev/string_scanner-1.2.0
mkdir -p $out/hosted/pub.dartlang.org mkdir -p $out/hosted/pub.dev
ln -s ${test} $out/hosted/pub.dartlang.org/test-1.22.0 ln -s ${synchronized} $out/hosted/pub.dev/synchronized-3.1.0
mkdir -p $out/hosted/pub.dartlang.org mkdir -p $out/hosted/pub.dev
ln -s ${test_api} $out/hosted/pub.dartlang.org/test_api-0.4.16 ln -s ${term_glyph} $out/hosted/pub.dev/term_glyph-1.2.1
mkdir -p $out/hosted/pub.dartlang.org mkdir -p $out/hosted/pub.dev
ln -s ${test_core} $out/hosted/pub.dartlang.org/test_core-0.4.20 ln -s ${test} $out/hosted/pub.dev/test-1.24.3
mkdir -p $out/hosted/pub.dartlang.org mkdir -p $out/hosted/pub.dev
ln -s ${timing} $out/hosted/pub.dartlang.org/timing-1.0.0 ln -s ${test_api} $out/hosted/pub.dev/test_api-0.6.0
mkdir -p $out/hosted/pub.dartlang.org mkdir -p $out/hosted/pub.dev
ln -s ${typed_data} $out/hosted/pub.dartlang.org/typed_data-1.3.1 ln -s ${test_core} $out/hosted/pub.dev/test_core-0.5.3
mkdir -p $out/hosted/pub.dartlang.org mkdir -p $out/hosted/pub.dev
ln -s ${unorm_dart} $out/hosted/pub.dartlang.org/unorm_dart-0.2.0 ln -s ${timing} $out/hosted/pub.dev/timing-1.0.1
mkdir -p $out/hosted/pub.dartlang.org mkdir -p $out/hosted/pub.dev
ln -s ${uuid} $out/hosted/pub.dartlang.org/uuid-3.0.5 ln -s ${typed_data} $out/hosted/pub.dev/typed_data-1.3.2
mkdir -p $out/hosted/pub.dartlang.org mkdir -p $out/hosted/pub.dev
ln -s ${very_good_analysis} $out/hosted/pub.dartlang.org/very_good_analysis-3.1.0 ln -s ${unorm_dart} $out/hosted/pub.dev/unorm_dart-0.2.0
mkdir -p $out/hosted/pub.dartlang.org mkdir -p $out/hosted/pub.dev
ln -s ${vm_service} $out/hosted/pub.dartlang.org/vm_service-9.4.0 ln -s ${uuid} $out/hosted/pub.dev/uuid-3.0.7
mkdir -p $out/hosted/pub.dartlang.org mkdir -p $out/hosted/pub.dev
ln -s ${watcher} $out/hosted/pub.dartlang.org/watcher-1.0.2 ln -s ${very_good_analysis} $out/hosted/pub.dev/very_good_analysis-3.1.0
mkdir -p $out/hosted/pub.dartlang.org mkdir -p $out/hosted/pub.dev
ln -s ${web_socket_channel} $out/hosted/pub.dartlang.org/web_socket_channel-2.2.0 ln -s ${vm_service} $out/hosted/pub.dev/vm_service-11.10.0
mkdir -p $out/hosted/pub.dartlang.org mkdir -p $out/hosted/pub.dev
ln -s ${webkit_inspection_protocol} $out/hosted/pub.dartlang.org/webkit_inspection_protocol-1.2.0 ln -s ${watcher} $out/hosted/pub.dev/watcher-1.0.2
mkdir -p $out/hosted/pub.dartlang.org mkdir -p $out/hosted/pub.dev
ln -s ${xml} $out/hosted/pub.dartlang.org/xml-6.2.0 ln -s ${web_socket_channel} $out/hosted/pub.dev/web_socket_channel-2.4.0
mkdir -p $out/hosted/pub.dartlang.org mkdir -p $out/hosted/pub.dev
ln -s ${yaml} $out/hosted/pub.dartlang.org/yaml-3.1.1 ln -s ${webkit_inspection_protocol} $out/hosted/pub.dev/webkit_inspection_protocol-1.2.0
mkdir -p $out/hosted/pub.dev
ln -s ${xml} $out/hosted/pub.dev/xml-6.3.0
mkdir -p $out/hosted/pub.dev
ln -s ${yaml} $out/hosted/pub.dev/yaml-3.1.2
''; '';
} }

View File

@@ -1,7 +1,50 @@
## 0.4.1
- Moved FAST from staging to xep_0484.dart
## 0.4.0
- **BREAKING**: Remove `lastResource` from `XmppConnection`'s `connect` method. Instead, set the `StreamManagementNegotiator`'s `resource` attribute instead. Since the resource can only really be restored by stream management, this is no issue.
- **BREAKING**: Changed order of parameters of `CryptographicHashManager.hashFromData`
- **BREAKING**: Removed support for XEP-0414, as the (supported) hash computations are already implemented by `CryptographicHashManager.hashFromData`.
- The `DiscoManager` now only handled entity capabilities if a `EntityCapabilityManager` is registered.
- The `EntityCapabilityManager` now verifies and validates its data before caching.
- **BREAKING**: Added the `resumed` parameter to `StreamNegotiationsDoneEvent`. Use this to check if the current stream is new or resumed instead of using the `ConnectionStateChangedEvent`.
- **BREAKING**: Remove `DiscoManager.discoInfoCapHashQuery`.
- **BREAKING**: The entity argument of `DiscoManager.discoInfoQuery` and `DiscoManager.discoItemsQuery` are now `JID` instead of `String`.
- **BREAKING**: `PubSubManager` and `UserAvatarManager` now use `JID` instead of `String`.
- **BREAKING**: `XmppConnection.sendStanza` not only takes a `StanzaDetails` argument.
- Sent stanzas are now kept in a queue until sent.
- **BREAKING**: `MessageManager.sendMessage` does not use `MessageDetails` anymore. Instead, use `TypedMap`.
- `MessageManager` now allows registering callbacks for adding data whenever a message is sent.
- **BREAKING**: `MessageEvent` now makes use of `TypedMap`.
- **BREAKING**: Removed `PresenceReceivedEvent`. Use a manager registering handlers with priority greater than `[PresenceManager.presenceHandlerPriority]` instead.
- **BREAKING**: `ChatState.toString()` is now `ChatState.toName()`
- **BREAKING**: Overriding `BaseOmemoManager` is no longer required. `OmemoManager` now takes callback methods instead.
- Removed `ErrorResponseDiscoError` from the possible XEP-0030 errors.
- **BREAKING**: Removed "Extensible File Thumbnails" (The `Thumbnail` type).
- *BREAKING*: Rename `UserAvatarManager`'s `getUserAvatar` to `getUserAvatarData`. It now also requires the id of the avatar to fetch
- *BREAKING*: `UserAvatarManager`'s `getAvatarId` with `getLatestMetadata`.
- The `PubSubManager` now supports PubSub's `max_items` in `getItems`.
- *BREAKING*: `vCardManager`'s `VCardAvatarUpdatedEvent` no longer automatically requests the newest VCard avatar.
- *BREAKING*: `XmppConnection` now tries to ensure that incoming data is processed in-order. The only exception are awaited stanzas as they are allowed to bypass the queue.
- *BREAKING*: If a stanza handler causes an exception, the handler is simply skipped while processing.
- Add better logging around what stanza handler is running and if they end processing early.
## 0.3.1
- Fix some issues with running moxxmpp as a component
## 0.3.0 ## 0.3.0
- **BREAKING**: Removed `connectAwaitable` and merged it with `connect`. - **BREAKING**: Removed `connectAwaitable` and merged it with `connect`.
- **BREAKING**: Removed `allowPlainAuth` from `ConnectionSettings`. If you don't want to use SASL PLAIN, don't register the negotiator. If you want to only conditionally use SASL PLAIN, extend the `SaslPlainNegotiator` and override its `matchesFeature` method to only call the super method when SASL PLAIN should be used. - **BREAKING**: Removed `allowPlainAuth` from `ConnectionSettings`. If you don't want to use SASL PLAIN, don't register the negotiator. If you want to only conditionally use SASL PLAIN, extend the `SaslPlainNegotiator` and override its `matchesFeature` method to only call the super method when SASL PLAIN should be used.
- **BREAKING**: The user avatar's `subscribe` and `unsubscribe` no longer subscribe to the `:data` PubSub nodes
- Renamed `ResourceBindingSuccessEvent` to `ResourceBoundEvent`
- **BREAKING**: Removed `isFeatureSupported` from the manager attributes. The managers now all have a method `isFeatureSupported` that works the same
- The `PresenceManager` is now optional
- **BREAKING**: Removed `setConnectionSettings` and `getConnectionSettings`. Just directly acces the `connectionSettings` field.
- Implement XEP-0114 for implementing components
- **BREAKING**: Remove `useDirectTLS` from `ConnectionSettings`
## 0.1.6+1 ## 0.1.6+1

View File

@@ -9,7 +9,7 @@ Include the following as a dependency in your pubspec file:
``` ```
moxxmpp: moxxmpp:
hosted: https://git.polynom.me/api/packages/Moxxy/pub hosted: https://git.polynom.me/api/packages/Moxxy/pub
version: 0.2.0 version: 0.3.1
``` ```
You can find the documentation [here](https://moxxy.org/developers/docs/moxxmpp/). You can find the documentation [here](https://moxxy.org/developers/docs/moxxmpp/).

View File

@@ -5,6 +5,9 @@ export 'package:moxxmpp/src/connection_errors.dart';
export 'package:moxxmpp/src/connectivity.dart'; export 'package:moxxmpp/src/connectivity.dart';
export 'package:moxxmpp/src/errors.dart'; export 'package:moxxmpp/src/errors.dart';
export 'package:moxxmpp/src/events.dart'; export 'package:moxxmpp/src/events.dart';
export 'package:moxxmpp/src/handlers/base.dart';
export 'package:moxxmpp/src/handlers/client.dart';
export 'package:moxxmpp/src/handlers/component.dart';
export 'package:moxxmpp/src/iq.dart'; export 'package:moxxmpp/src/iq.dart';
export 'package:moxxmpp/src/jid.dart'; export 'package:moxxmpp/src/jid.dart';
export 'package:moxxmpp/src/managers/attributes.dart'; export 'package:moxxmpp/src/managers/attributes.dart';
@@ -15,20 +18,19 @@ export 'package:moxxmpp/src/managers/namespaces.dart';
export 'package:moxxmpp/src/managers/priorities.dart'; export 'package:moxxmpp/src/managers/priorities.dart';
export 'package:moxxmpp/src/message.dart'; export 'package:moxxmpp/src/message.dart';
export 'package:moxxmpp/src/namespaces.dart'; export 'package:moxxmpp/src/namespaces.dart';
export 'package:moxxmpp/src/negotiators/manager.dart';
export 'package:moxxmpp/src/negotiators/namespaces.dart'; export 'package:moxxmpp/src/negotiators/namespaces.dart';
export 'package:moxxmpp/src/negotiators/negotiator.dart'; export 'package:moxxmpp/src/negotiators/negotiator.dart';
export 'package:moxxmpp/src/negotiators/resource_binding.dart';
export 'package:moxxmpp/src/negotiators/sasl/errors.dart';
export 'package:moxxmpp/src/negotiators/sasl/negotiator.dart';
export 'package:moxxmpp/src/negotiators/sasl/plain.dart';
export 'package:moxxmpp/src/negotiators/sasl/scram.dart';
export 'package:moxxmpp/src/negotiators/starttls.dart';
export 'package:moxxmpp/src/ping.dart'; export 'package:moxxmpp/src/ping.dart';
export 'package:moxxmpp/src/presence.dart'; export 'package:moxxmpp/src/presence.dart';
export 'package:moxxmpp/src/reconnect.dart'; export 'package:moxxmpp/src/reconnect.dart';
export 'package:moxxmpp/src/rfcs/rfc_2782.dart'; export 'package:moxxmpp/src/rfcs/rfc_2782.dart';
export 'package:moxxmpp/src/rfcs/rfc_4790.dart'; export 'package:moxxmpp/src/rfcs/rfc_4790.dart';
export 'package:moxxmpp/src/rfcs/rfc_6120/resource_binding.dart';
export 'package:moxxmpp/src/rfcs/rfc_6120/sasl/errors.dart';
export 'package:moxxmpp/src/rfcs/rfc_6120/sasl/negotiator.dart';
export 'package:moxxmpp/src/rfcs/rfc_6120/sasl/plain.dart';
export 'package:moxxmpp/src/rfcs/rfc_6120/sasl/scram.dart';
export 'package:moxxmpp/src/rfcs/rfc_6120/starttls.dart';
export 'package:moxxmpp/src/roster/errors.dart'; export 'package:moxxmpp/src/roster/errors.dart';
export 'package:moxxmpp/src/roster/roster.dart'; export 'package:moxxmpp/src/roster/roster.dart';
export 'package:moxxmpp/src/roster/state.dart'; export 'package:moxxmpp/src/roster/state.dart';
@@ -36,14 +38,17 @@ export 'package:moxxmpp/src/settings.dart';
export 'package:moxxmpp/src/socket.dart'; export 'package:moxxmpp/src/socket.dart';
export 'package:moxxmpp/src/stanza.dart'; export 'package:moxxmpp/src/stanza.dart';
export 'package:moxxmpp/src/stringxml.dart'; export 'package:moxxmpp/src/stringxml.dart';
export 'package:moxxmpp/src/types/result.dart'; export 'package:moxxmpp/src/util/typed_map.dart';
export 'package:moxxmpp/src/xeps/staging/extensible_file_thumbnails.dart';
export 'package:moxxmpp/src/xeps/staging/file_upload_notification.dart'; export 'package:moxxmpp/src/xeps/staging/file_upload_notification.dart';
export 'package:moxxmpp/src/xeps/xep_0004.dart'; export 'package:moxxmpp/src/xeps/xep_0004.dart';
export 'package:moxxmpp/src/xeps/xep_0030/errors.dart'; export 'package:moxxmpp/src/xeps/xep_0030/errors.dart';
export 'package:moxxmpp/src/xeps/xep_0030/helpers.dart'; export 'package:moxxmpp/src/xeps/xep_0030/helpers.dart';
export 'package:moxxmpp/src/xeps/xep_0030/types.dart'; export 'package:moxxmpp/src/xeps/xep_0030/types.dart';
export 'package:moxxmpp/src/xeps/xep_0030/xep_0030.dart'; export 'package:moxxmpp/src/xeps/xep_0030/xep_0030.dart';
export 'package:moxxmpp/src/xeps/xep_0045/errors.dart';
export 'package:moxxmpp/src/xeps/xep_0045/events.dart';
export 'package:moxxmpp/src/xeps/xep_0045/types.dart';
export 'package:moxxmpp/src/xeps/xep_0045/xep_0045.dart';
export 'package:moxxmpp/src/xeps/xep_0054.dart'; export 'package:moxxmpp/src/xeps/xep_0054.dart';
export 'package:moxxmpp/src/xeps/xep_0060/errors.dart'; export 'package:moxxmpp/src/xeps/xep_0060/errors.dart';
export 'package:moxxmpp/src/xeps/xep_0060/helpers.dart'; export 'package:moxxmpp/src/xeps/xep_0060/helpers.dart';
@@ -59,6 +64,7 @@ export 'package:moxxmpp/src/xeps/xep_0198/nonzas.dart';
export 'package:moxxmpp/src/xeps/xep_0198/state.dart'; export 'package:moxxmpp/src/xeps/xep_0198/state.dart';
export 'package:moxxmpp/src/xeps/xep_0198/xep_0198.dart'; export 'package:moxxmpp/src/xeps/xep_0198/xep_0198.dart';
export 'package:moxxmpp/src/xeps/xep_0203.dart'; export 'package:moxxmpp/src/xeps/xep_0203.dart';
export 'package:moxxmpp/src/xeps/xep_0264.dart';
export 'package:moxxmpp/src/xeps/xep_0280.dart'; export 'package:moxxmpp/src/xeps/xep_0280.dart';
export 'package:moxxmpp/src/xeps/xep_0297.dart'; export 'package:moxxmpp/src/xeps/xep_0297.dart';
export 'package:moxxmpp/src/xeps/xep_0300.dart'; export 'package:moxxmpp/src/xeps/xep_0300.dart';
@@ -76,7 +82,12 @@ export 'package:moxxmpp/src/xeps/xep_0384/helpers.dart';
export 'package:moxxmpp/src/xeps/xep_0384/types.dart'; export 'package:moxxmpp/src/xeps/xep_0384/types.dart';
export 'package:moxxmpp/src/xeps/xep_0384/xep_0384.dart'; export 'package:moxxmpp/src/xeps/xep_0384/xep_0384.dart';
export 'package:moxxmpp/src/xeps/xep_0385.dart'; export 'package:moxxmpp/src/xeps/xep_0385.dart';
export 'package:moxxmpp/src/xeps/xep_0414.dart'; export 'package:moxxmpp/src/xeps/xep_0386.dart';
export 'package:moxxmpp/src/xeps/xep_0388/errors.dart';
export 'package:moxxmpp/src/xeps/xep_0388/negotiators.dart';
export 'package:moxxmpp/src/xeps/xep_0388/user_agent.dart';
export 'package:moxxmpp/src/xeps/xep_0388/xep_0388.dart';
export 'package:moxxmpp/src/xeps/xep_0421.dart';
export 'package:moxxmpp/src/xeps/xep_0424.dart'; export 'package:moxxmpp/src/xeps/xep_0424.dart';
export 'package:moxxmpp/src/xeps/xep_0444.dart'; export 'package:moxxmpp/src/xeps/xep_0444.dart';
export 'package:moxxmpp/src/xeps/xep_0446.dart'; export 'package:moxxmpp/src/xeps/xep_0446.dart';
@@ -84,3 +95,4 @@ export 'package:moxxmpp/src/xeps/xep_0447.dart';
export 'package:moxxmpp/src/xeps/xep_0448.dart'; export 'package:moxxmpp/src/xeps/xep_0448.dart';
export 'package:moxxmpp/src/xeps/xep_0449.dart'; export 'package:moxxmpp/src/xeps/xep_0449.dart';
export 'package:moxxmpp/src/xeps/xep_0461.dart'; export 'package:moxxmpp/src/xeps/xep_0461.dart';
export 'package:moxxmpp/src/xeps/xep_0484.dart';

View File

@@ -1,35 +1,13 @@
import 'dart:async'; import 'dart:async';
import 'package:meta/meta.dart';
import 'package:moxxmpp/src/jid.dart';
import 'package:moxxmpp/src/stringxml.dart'; import 'package:moxxmpp/src/stringxml.dart';
import 'package:synchronized/synchronized.dart'; import 'package:synchronized/synchronized.dart';
/// A surrogate key for awaiting stanzas. /// (JID we sent a stanza to, the id of the sent stanza, the tag of the sent stanza).
@immutable // ignore: avoid_private_typedef_functions
class _StanzaSurrogateKey { typedef _StanzaCompositeKey = (String?, String, String);
const _StanzaSurrogateKey(this.sentTo, this.id, this.tag);
/// The JID the original stanza was sent to. We expect the result to come from the /// Callback function that returns the bare JID of the connection as a String.
/// same JID. typedef GetBareJidCallback = String Function();
final String sentTo;
/// The ID of the original stanza. We expect the result to have the same ID.
final String id;
/// The tag name of the stanza.
final String tag;
@override
int get hashCode => sentTo.hashCode ^ id.hashCode ^ tag.hashCode;
@override
bool operator ==(Object other) {
return other is _StanzaSurrogateKey &&
other.sentTo == sentTo &&
other.id == id &&
other.tag == tag;
}
}
/// This class handles the await semantics for stanzas. Stanzas are given a "unique" /// This class handles the await semantics for stanzas. Stanzas are given a "unique"
/// key equal to the tuple (to, id, tag) with which their response is identified. /// key equal to the tuple (to, id, tag) with which their response is identified.
@@ -40,8 +18,12 @@ class _StanzaSurrogateKey {
/// ///
/// This class also handles some "edge cases" of RFC 6120, like an empty "from" attribute. /// This class also handles some "edge cases" of RFC 6120, like an empty "from" attribute.
class StanzaAwaiter { class StanzaAwaiter {
StanzaAwaiter(this._bareJidCallback);
final GetBareJidCallback _bareJidCallback;
/// The pending stanzas, identified by their surrogate key. /// The pending stanzas, identified by their surrogate key.
final Map<_StanzaSurrogateKey, Completer<XMLNode>> _pending = {}; final Map<_StanzaCompositeKey, Completer<XMLNode>> _pending = {};
/// The critical section for accessing [StanzaAwaiter._pending]. /// The critical section for accessing [StanzaAwaiter._pending].
final Lock _lock = Lock(); final Lock _lock = Lock();
@@ -52,30 +34,33 @@ class StanzaAwaiter {
/// [tag] is the stanza's tag name. /// [tag] is the stanza's tag name.
/// ///
/// Returns a future that might resolve to the response to the stanza. /// Returns a future that might resolve to the response to the stanza.
Future<Future<XMLNode>> addPending(String to, String id, String tag) async { Future<Future<XMLNode>> addPending(String? to, String id, String tag) async {
// Check if we want to send a stanza to our bare JID and replace it with null.
final processedTo = to != null && to == _bareJidCallback() ? null : to;
final completer = await _lock.synchronized(() { final completer = await _lock.synchronized(() {
final completer = Completer<XMLNode>(); final completer = Completer<XMLNode>();
_pending[_StanzaSurrogateKey(to, id, tag)] = completer; _pending[(processedTo, id, tag)] = completer;
return completer; return completer;
}); });
return completer.future; return completer.future;
} }
/// Checks if the stanza [stanza] is being awaited. [bareJid] is the bare JID of /// Checks if the stanza [stanza] is being awaited.
/// the connection.
/// If [stanza] is awaited, resolves the future and returns true. If not, returns /// If [stanza] is awaited, resolves the future and returns true. If not, returns
/// false. /// false.
Future<bool> onData(XMLNode stanza, JID bareJid) async { Future<bool> onData(XMLNode stanza) async {
assert(bareJid.isBare(), 'bareJid must be bare');
final id = stanza.attributes['id'] as String?; final id = stanza.attributes['id'] as String?;
if (id == null) return false; if (id == null) return false;
final key = _StanzaSurrogateKey( // Check if we want to send a stanza to our bare JID and replace it with null.
// Section 8.1.2.1 § 3 of RFC 6120 says that an empty "from" indicates that the final from = stanza.attributes['from'] as String?;
// attribute is implicitly from our own bare JID. final processedFrom =
stanza.attributes['from'] as String? ?? bareJid.toString(), from != null && from == _bareJidCallback() ? null : from;
final key = (
processedFrom,
id, id,
stanza.tag, stanza.tag,
); );
@@ -91,4 +76,19 @@ class StanzaAwaiter {
return false; return false;
}); });
} }
/// Checks if [stanza] represents a stanza that is awaited. Returns true, if [stanza]
/// is awaited. False, if not.
Future<bool> isAwaited(XMLNode stanza) async {
final id = stanza.attributes['id'] as String?;
if (id == null) return false;
final key = (
stanza.attributes['from'] as String?,
id,
stanza.tag,
);
return _lock.synchronized(() => _pending.containsKey(key));
}
} }

View File

@@ -1,32 +0,0 @@
import 'dart:async';
import 'package:moxxmpp/src/stringxml.dart';
import 'package:xml/xml.dart';
import 'package:xml/xml_events.dart';
class XmlStreamBuffer extends StreamTransformerBase<String, XMLNode> {
XmlStreamBuffer()
: _streamController = StreamController(),
_decoder = const XmlNodeDecoder();
final StreamController<XMLNode> _streamController;
final XmlNodeDecoder _decoder;
@override
Stream<XMLNode> bind(Stream<String> stream) {
stream
.toXmlEvents()
.selectSubtreeEvents((event) {
return event.qualifiedName != 'stream:stream';
})
.transform(_decoder)
.listen((nodes) {
for (final node in nodes) {
if (node.nodeType == XmlNodeType.ELEMENT) {
_streamController.add(XMLNode.fromXmlElement(node as XmlElement));
}
}
});
return _streamController.stream;
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -4,12 +4,6 @@ import 'package:moxxmpp/src/negotiators/negotiator.dart';
/// The reason a call to `XmppConnection.connect` failed. /// The reason a call to `XmppConnection.connect` failed.
abstract class XmppConnectionError extends XmppError {} abstract class XmppConnectionError extends XmppError {}
/// Returned by `XmppConnection.connect` when a connection is already active.
class ConnectionAlreadyRunningError extends XmppConnectionError {
@override
bool isRecoverable() => true;
}
/// Returned by `XmppConnection.connect` when a negotiator returned an unrecoverable /// Returned by `XmppConnection.connect` when a negotiator returned an unrecoverable
/// error. Only returned when waitUntilLogin is true. /// error. Only returned when waitUntilLogin is true.
class NegotiatorReturnedError extends XmppConnectionError { class NegotiatorReturnedError extends XmppConnectionError {
@@ -52,3 +46,15 @@ class NoAuthenticatorAvailableError extends XmppConnectionError {
@override @override
bool isRecoverable() => false; bool isRecoverable() => false;
} }
/// Returned by the negotiation handler if unexpected data has been received
class UnexpectedDataError extends XmppConnectionError {
@override
bool isRecoverable() => false;
}
/// Returned by the ComponentToServerNegotiator if the handshake is not successful.
class InvalidHandshakeCredentialsError extends XmppConnectionError {
@override
bool isRecoverable() => false;
}

View File

@@ -7,13 +7,6 @@ abstract class XmppError {
bool isRecoverable(); bool isRecoverable();
} }
/// Returned if we could not establish a TCP connection
/// to the server.
class NoConnectionError extends XmppError {
@override
bool isRecoverable() => true;
}
/// Returned if a socket error occured /// Returned if a socket error occured
class SocketError extends XmppError { class SocketError extends XmppError {
SocketError(this.event); SocketError(this.event);

View File

@@ -4,28 +4,20 @@ import 'package:moxxmpp/src/jid.dart';
import 'package:moxxmpp/src/managers/data.dart'; import 'package:moxxmpp/src/managers/data.dart';
import 'package:moxxmpp/src/roster/roster.dart'; import 'package:moxxmpp/src/roster/roster.dart';
import 'package:moxxmpp/src/stanza.dart'; import 'package:moxxmpp/src/stanza.dart';
import 'package:moxxmpp/src/util/typed_map.dart';
import 'package:moxxmpp/src/xeps/xep_0030/types.dart'; import 'package:moxxmpp/src/xeps/xep_0030/types.dart';
import 'package:moxxmpp/src/xeps/xep_0060/xep_0060.dart'; import 'package:moxxmpp/src/xeps/xep_0060/xep_0060.dart';
import 'package:moxxmpp/src/xeps/xep_0066.dart'; import 'package:moxxmpp/src/xeps/xep_0084.dart';
import 'package:moxxmpp/src/xeps/xep_0085.dart'; import 'package:moxxmpp/src/xeps/xep_0333.dart';
import 'package:moxxmpp/src/xeps/xep_0334.dart';
import 'package:moxxmpp/src/xeps/xep_0359.dart';
import 'package:moxxmpp/src/xeps/xep_0385.dart';
import 'package:moxxmpp/src/xeps/xep_0424.dart';
import 'package:moxxmpp/src/xeps/xep_0444.dart';
import 'package:moxxmpp/src/xeps/xep_0446.dart';
import 'package:moxxmpp/src/xeps/xep_0447.dart';
import 'package:moxxmpp/src/xeps/xep_0461.dart';
abstract class XmppEvent {} abstract class XmppEvent {}
/// Triggered when the connection state of the XmppConnection has /// Triggered when the connection state of the XmppConnection has
/// changed. /// changed.
class ConnectionStateChangedEvent extends XmppEvent { class ConnectionStateChangedEvent extends XmppEvent {
ConnectionStateChangedEvent(this.state, this.before, this.resumed); ConnectionStateChangedEvent(this.state, this.before);
final XmppConnectionState before; final XmppConnectionState before;
final XmppConnectionState state; final XmppConnectionState state;
final bool resumed;
/// Indicates whether the connection state switched from a not connected state to a /// Indicates whether the connection state switched from a not connected state to a
/// connected state. /// connected state.
@@ -75,58 +67,42 @@ class RosterUpdatedEvent extends XmppEvent {
/// Triggered when a message is received /// Triggered when a message is received
class MessageEvent extends XmppEvent { class MessageEvent extends XmppEvent {
MessageEvent({ MessageEvent(
required this.body, this.from,
required this.fromJid, this.to,
required this.toJid, this.encrypted,
required this.sid, this.extensions, {
required this.stanzaId, this.id,
required this.isCarbon,
required this.deliveryReceiptRequested,
required this.isMarkable,
required this.encrypted,
required this.other,
this.error,
this.type, this.type,
this.oob, this.error,
this.sfs, this.encryptionError,
this.sims,
this.reply,
this.chatState,
this.fun,
this.funReplacement,
this.funCancellation,
this.messageRetraction,
this.messageCorrectionId,
this.messageReactions,
this.messageProcessingHints,
this.stickerPackId,
}); });
final StanzaError? error;
final String body; /// The from attribute of the message.
final JID fromJid; final JID from;
final JID toJid;
final String sid; /// The to attribute of the message.
final JID to;
/// The id attribute of the message.
final String? id;
/// The type attribute of the message.
final String? type; final String? type;
final StableStanzaId stanzaId;
final bool isCarbon; final StanzaError? error;
final bool deliveryReceiptRequested;
final bool isMarkable; /// Flag indicating whether the message was encrypted.
final OOBData? oob;
final StatelessFileSharingData? sfs;
final StatelessMediaSharingData? sims;
final ReplyData? reply;
final ChatState? chatState;
final FileMetadataData? fun;
final String? funReplacement;
final String? funCancellation;
final bool encrypted; final bool encrypted;
final MessageRetractionData? messageRetraction;
final String? messageCorrectionId; /// The error in case an encryption error occurred.
final MessageReactions? messageReactions; final Object? encryptionError;
final List<MessageProcessingHint>? messageProcessingHints;
final String? stickerPackId; /// Data added by other handlers.
final Map<String, dynamic> other; final TypedMap<StanzaHandlerExtension> extensions;
/// Shorthand for extensions.get<T>().
T? get<T>() => extensions.get<T>();
} }
/// Triggered when a client responds to our delivery receipt request /// Triggered when a client responds to our delivery receipt request
@@ -137,13 +113,19 @@ class DeliveryReceiptReceivedEvent extends XmppEvent {
} }
class ChatMarkerEvent extends XmppEvent { class ChatMarkerEvent extends XmppEvent {
ChatMarkerEvent({ ChatMarkerEvent(
required this.type, this.from,
required this.from, this.type,
required this.id, this.id,
}); );
/// The entity that sent the chat marker.
final JID from; final JID from;
final String type;
/// The type of chat marker that was sent.
final ChatMarker type;
/// The id of the message that the marker applies to.
final String id; final String id;
} }
@@ -160,16 +142,11 @@ class StreamManagementEnabledEvent extends XmppEvent {
} }
/// Triggered when we bound a resource /// Triggered when we bound a resource
class ResourceBindingSuccessEvent extends XmppEvent { class ResourceBoundEvent extends XmppEvent {
ResourceBindingSuccessEvent({required this.resource}); ResourceBoundEvent(this.resource);
final String resource;
}
/// Triggered when we receive presence /// The resource that was just bound.
class PresenceReceivedEvent extends XmppEvent { final String resource;
PresenceReceivedEvent(this.jid, this.presence);
final JID jid;
final Stanza presence;
} }
/// Triggered when we are starting an connection attempt /// Triggered when we are starting an connection attempt
@@ -189,15 +166,31 @@ class SubscriptionRequestReceivedEvent extends XmppEvent {
final JID from; final JID from;
} }
/// Triggered when we receive a new or updated avatar /// Triggered when we receive a new or updated avatar via XEP-0084
class AvatarUpdatedEvent extends XmppEvent { class UserAvatarUpdatedEvent extends XmppEvent {
AvatarUpdatedEvent({ UserAvatarUpdatedEvent(
required this.jid, this.jid,
required this.base64, this.metadata,
required this.hash, );
});
final String jid; /// The JID of the user updating their avatar.
final String base64; final JID jid;
/// The metadata of the avatar.
final List<UserAvatarMetadata> metadata;
}
/// Triggered when we receive a new or updated avatar via XEP-0054
class VCardAvatarUpdatedEvent extends XmppEvent {
VCardAvatarUpdatedEvent(
this.jid,
this.hash,
);
/// The JID of the entity that updated their avatar.
final JID jid;
/// The SHA-1 hash of the avatar.
final String hash; final String hash;
} }
@@ -255,4 +248,10 @@ class NonRecoverableErrorEvent extends XmppEvent {
} }
/// Triggered when the stream negotiations are done. /// Triggered when the stream negotiations are done.
class StreamNegotiationsDoneEvent extends XmppEvent {} class StreamNegotiationsDoneEvent extends XmppEvent {
StreamNegotiationsDoneEvent(this.resumed);
/// Flag indicating whether we resumed a previous stream (true) or are in a completely
/// new stream (false).
final bool resumed;
}

View File

@@ -0,0 +1,132 @@
import 'package:logging/logging.dart';
import 'package:meta/meta.dart';
import 'package:moxxmpp/src/errors.dart';
import 'package:moxxmpp/src/events.dart';
import 'package:moxxmpp/src/negotiators/negotiator.dart';
import 'package:moxxmpp/src/parser.dart';
import 'package:moxxmpp/src/settings.dart';
import 'package:moxxmpp/src/stringxml.dart';
/// A callback for when the [NegotiationsHandler] is done.
typedef NegotiationsDoneCallback = Future<void> Function();
/// A callback for the case that an error occurs while negotiating.
typedef ErrorCallback = Future<void> Function(XmppError);
/// Return true if the current connection is authenticated. If not, return false.
typedef IsAuthenticatedFunction = bool Function();
/// Send a nonza on the stream
typedef SendNonzaFunction = void Function(XMLNode);
/// Returns the connection settings.
typedef GetConnectionSettingsFunction = ConnectionSettings Function();
/// Resets the stream parser's state.
typedef ResetStreamParserFunction = void Function();
/// This class implements the stream feature negotiation for XmppConnection.
abstract class NegotiationsHandler {
@protected
late final Logger log;
/// Map of all negotiators registered against the handler.
@protected
final Map<String, XmppFeatureNegotiatorBase> negotiators = {};
/// Function that is called once the negotiator is done with its stream negotiations.
@protected
late final NegotiationsDoneCallback onNegotiationsDone;
/// XmppConnection's handleError method.
@protected
late final ErrorCallback handleError;
/// Returns true if the connection is authenticated. If not, returns false.
@protected
late final IsAuthenticatedFunction isAuthenticated;
/// Send a nonza over the stream.
@protected
late final SendNonzaFunction sendNonza;
/// Get the connection's settings.
@protected
late final GetConnectionSettingsFunction getConnectionSettings;
@protected
late final ResetStreamParserFunction resetStreamParser;
/// The id included in the last stream header.
@protected
String? streamId;
/// Set the id of the last stream header.
void setStreamHeaderId(String? id) {
streamId = id;
}
/// Returns, if registered, a negotiator with id [id].
T? getNegotiatorById<T extends XmppFeatureNegotiatorBase>(String id) =>
negotiators[id] as T?;
/// Register the parameters as the corresponding methods in this class. Also
/// initializes the logger.
void register(
NegotiationsDoneCallback onNegotiationsDone,
ErrorCallback handleError,
IsAuthenticatedFunction isAuthenticated,
SendNonzaFunction sendNonza,
GetConnectionSettingsFunction getConnectionSettings,
ResetStreamParserFunction resetStreamParser,
) {
this.onNegotiationsDone = onNegotiationsDone;
this.handleError = handleError;
this.isAuthenticated = isAuthenticated;
this.sendNonza = sendNonza;
this.getConnectionSettings = getConnectionSettings;
this.resetStreamParser = resetStreamParser;
log = Logger(toString());
}
/// Returns the xmlns attribute that stanzas should have.
String getStanzaNamespace();
/// Registers the negotiator [negotiator] against this negotiations handler.
void registerNegotiator(XmppFeatureNegotiatorBase negotiator);
/// Sends the stream header.
void sendStreamHeader();
/// Runs the post-register callback of all negotiators.
Future<void> runPostRegisterCallback() async {
for (final negotiator in negotiators.values) {
await negotiator.postRegisterCallback();
}
}
Future<void> sendEventToNegotiators(XmppEvent event) async {
for (final negotiator in negotiators.values) {
await negotiator.onXmppEvent(event);
}
}
/// Remove [feature] from the stream features we are currently negotiating.
void removeNegotiatingFeature(String feature) {}
/// Resets all registered negotiators and the negotiation handler.
@mustCallSuper
void reset() {
streamId = null;
for (final negotiator in negotiators.values) {
negotiator.reset();
}
}
/// Called whenever the stream buffer outputs a new event [event].
Future<void> negotiate(XMPPStreamObject event) async {
if (event is XMPPStreamHeader) {
streamId = event.attributes['id'];
}
}
}

View File

@@ -0,0 +1,227 @@
import 'package:meta/meta.dart';
import 'package:moxxmpp/src/connection_errors.dart';
import 'package:moxxmpp/src/handlers/base.dart';
import 'package:moxxmpp/src/jid.dart';
import 'package:moxxmpp/src/namespaces.dart';
import 'package:moxxmpp/src/negotiators/negotiator.dart';
import 'package:moxxmpp/src/parser.dart';
import 'package:moxxmpp/src/stringxml.dart';
/// "Nonza" describing the XMPP stream header of a client-to-server connection.
class ClientStreamHeaderNonza extends XMLNode {
ClientStreamHeaderNonza(JID jid)
: super(
tag: 'stream:stream',
attributes: <String, String>{
'xmlns': stanzaXmlns,
'version': '1.0',
'xmlns:stream': streamXmlns,
'to': jid.domain,
'from': jid.toBare().toString(),
'xml:lang': 'en',
},
closeTag: false,
);
}
/// This class implements the stream feature negotiation for usage in client to server
/// connections.
class ClientToServerNegotiator extends NegotiationsHandler {
ClientToServerNegotiator() : super();
/// Cached list of stream features.
final List<XMLNode> _streamFeatures = List.empty(growable: true);
/// The currently active negotiator.
XmppFeatureNegotiatorBase? _currentNegotiator;
@override
String getStanzaNamespace() => stanzaXmlns;
@override
void registerNegotiator(XmppFeatureNegotiatorBase negotiator) {
negotiators[negotiator.id] = negotiator;
}
@override
void reset() {
super.reset();
// Prevent leaking the last active negotiator
_currentNegotiator = null;
}
@override
void removeNegotiatingFeature(String feature) {
_streamFeatures.removeWhere((node) {
return node.attributes['xmlns'] == feature;
});
}
@override
void sendStreamHeader() {
resetStreamParser();
sendNonza(
XMLNode(
tag: 'xml',
attributes: {'version': '1.0'},
closeTag: false,
isDeclaration: true,
children: [
ClientStreamHeaderNonza(getConnectionSettings().jid),
],
),
);
}
/// Returns true if all mandatory features in [features] have been negotiated.
/// Otherwise returns false.
bool _isMandatoryNegotiationDone(List<XMLNode> features) {
return features.every((XMLNode feature) {
return feature.firstTag('required') == null &&
feature.tag != 'mechanisms';
});
}
/// Returns true if we can still negotiate. Returns false if no negotiator is
/// matching and ready.
bool _isNegotiationPossible(List<XMLNode> features) {
return getNextNegotiator(features, log: false) != null;
}
/// Returns the next negotiator that matches [features]. Returns null if none can be
/// picked. If [log] is true, then the list of matching negotiators will be logged.
@visibleForTesting
XmppFeatureNegotiatorBase? getNextNegotiator(
List<XMLNode> features, {
bool log = true,
}) {
final matchingNegotiators =
negotiators.values.where((XmppFeatureNegotiatorBase negotiator) {
return negotiator.state == NegotiatorState.ready &&
negotiator.matchesFeature(features);
}).toList()
..sort((a, b) => b.priority.compareTo(a.priority));
if (log) {
this.log.finest(
'List of matching negotiators: ${matchingNegotiators.map((a) => a.id)}',
);
}
if (matchingNegotiators.isEmpty) return null;
return matchingNegotiators.first;
}
Future<void> _executeCurrentNegotiator(XMLNode nonza) async {
// If we don't have a negotiator, get one
_currentNegotiator ??= getNextNegotiator(_streamFeatures);
if (_currentNegotiator == null &&
_isMandatoryNegotiationDone(_streamFeatures) &&
!_isNegotiationPossible(_streamFeatures)) {
log.finest('Negotiations done!');
await onNegotiationsDone();
return;
}
// If we don't have a next negotiator, we have to bail
if (_currentNegotiator == null &&
!_isMandatoryNegotiationDone(_streamFeatures) &&
!_isNegotiationPossible(_streamFeatures)) {
// We failed before authenticating
if (!isAuthenticated()) {
log.severe('No negotiator could be picked while unauthenticated');
await handleError(NoMatchingAuthenticationMechanismAvailableError());
return;
} else {
log.severe(
'No negotiator could be picked while negotiations are not done',
);
await handleError(NoAuthenticatorAvailableError());
return;
}
}
final result = await _currentNegotiator!.negotiate(nonza);
if (result.isType<NegotiatorError>()) {
log.severe('Negotiator returned an error');
await handleError(result.get<NegotiatorError>());
return;
}
final state = result.get<NegotiatorState>();
_currentNegotiator!.state = state;
switch (state) {
case NegotiatorState.ready:
return;
case NegotiatorState.done:
if (_currentNegotiator!.sendStreamHeaderWhenDone) {
_currentNegotiator = null;
_streamFeatures.clear();
sendStreamHeader();
} else {
removeNegotiatingFeature(_currentNegotiator!.negotiatingXmlns);
_currentNegotiator = null;
if (_isMandatoryNegotiationDone(_streamFeatures) &&
!_isNegotiationPossible(_streamFeatures)) {
log.finest('Negotiations done!');
await onNegotiationsDone();
} else {
_currentNegotiator = getNextNegotiator(_streamFeatures);
log.finest('Chose ${_currentNegotiator!.id} as next negotiator');
final fakeStanza = XMLNode(
tag: 'stream:features',
children: _streamFeatures,
);
await _executeCurrentNegotiator(fakeStanza);
}
}
break;
case NegotiatorState.retryLater:
log.finest('Negotiator wants to continue later. Picking new one...');
_currentNegotiator!.state = NegotiatorState.ready;
if (_isMandatoryNegotiationDone(_streamFeatures) &&
!_isNegotiationPossible(_streamFeatures)) {
log.finest('Negotiations done!');
await onNegotiationsDone();
} else {
log.finest('Picking new negotiator...');
_currentNegotiator = getNextNegotiator(_streamFeatures);
log.finest('Chose $_currentNegotiator as next negotiator');
final fakeStanza = XMLNode(
tag: 'stream:features',
children: _streamFeatures,
);
await _executeCurrentNegotiator(fakeStanza);
}
break;
case NegotiatorState.skipRest:
log.finest(
'Negotiator wants to skip the remaining negotiation... Negotiations (assumed) done!',
);
await onNegotiationsDone();
break;
}
}
@override
Future<void> negotiate(XMPPStreamObject event) async {
if (event is XMPPStreamElement) {
if (event.node.tag == 'stream:features') {
// Store the received stream features
_streamFeatures
..clear()
..addAll(event.node.children);
}
await _executeCurrentNegotiator(event.node);
}
}
}

View File

@@ -0,0 +1,121 @@
import 'dart:convert';
import 'package:cryptography/cryptography.dart';
import 'package:hex/hex.dart';
import 'package:moxxmpp/src/connection_errors.dart';
import 'package:moxxmpp/src/handlers/base.dart';
import 'package:moxxmpp/src/jid.dart';
import 'package:moxxmpp/src/namespaces.dart';
import 'package:moxxmpp/src/negotiators/negotiator.dart';
import 'package:moxxmpp/src/parser.dart';
import 'package:moxxmpp/src/stringxml.dart';
/// Nonza describing the XMPP stream header.
class ComponentStreamHeaderNonza extends XMLNode {
ComponentStreamHeaderNonza(JID jid)
: assert(jid.isBare(), 'Component JID must be bare'),
super(
tag: 'stream:stream',
attributes: <String, String>{
'xmlns': componentAcceptXmlns,
'xmlns:stream': streamXmlns,
'to': jid.domain,
},
closeTag: false,
);
}
/// The states the ComponentToServerNegotiator can be in.
enum ComponentToServerState {
/// No data has been sent or received yet
idle,
/// Handshake has been sent
handshakeSent,
}
/// The ComponentToServerNegotiator is a NegotiationsHandler that allows writing
/// components that adhere to XEP-0114.
class ComponentToServerNegotiator extends NegotiationsHandler {
ComponentToServerNegotiator();
/// The state the negotiation handler is currently in
ComponentToServerState _state = ComponentToServerState.idle;
@override
String getStanzaNamespace() => componentAcceptXmlns;
@override
void registerNegotiator(XmppFeatureNegotiatorBase negotiator) {}
@override
void sendStreamHeader() {
resetStreamParser();
sendNonza(
XMLNode(
tag: 'xml',
attributes: {'version': '1.0'},
closeTag: false,
isDeclaration: true,
children: [
ComponentStreamHeaderNonza(getConnectionSettings().jid),
],
),
);
}
Future<String> _computeHandshake(String id) async {
final secret = getConnectionSettings().password;
return HEX.encode(
(await Sha1().hash(utf8.encode('$streamId$secret'))).bytes,
);
}
@override
Future<void> negotiate(XMPPStreamObject event) async {
switch (_state) {
case ComponentToServerState.idle:
if (event is XMPPStreamHeader) {
streamId = event.attributes['id'];
assert(
streamId != null,
'The server must respond with a stream header that contains an id',
);
_state = ComponentToServerState.handshakeSent;
sendNonza(
XMLNode(
tag: 'handshake',
text: await _computeHandshake(streamId!),
),
);
} else {
log.severe('Unexpected data received');
await handleError(UnexpectedDataError());
}
break;
case ComponentToServerState.handshakeSent:
if (event is XMPPStreamElement) {
if (event.node.tag == 'handshake' &&
event.node.children.isEmpty &&
event.node.attributes.isEmpty) {
log.info('Successfully authenticated as component');
await onNegotiationsDone();
} else {
log.warning('Handshake failed');
await handleError(InvalidHandshakeCredentialsError());
}
} else {
log.severe('Unexpected data received');
await handleError(UnexpectedDataError());
}
break;
}
}
@override
void reset() {
_state = ComponentToServerState.idle;
super.reset();
}
}

View File

@@ -23,9 +23,11 @@ Future<void> handleUnhandledStanza(
); );
await conn.sendStanza( await conn.sendStanza(
stanza, StanzaDetails(
awaitable: false, stanza,
forceEncryption: data.encrypted, awaitable: false,
forceEncryption: data.encrypted,
),
); );
} }
} }

View File

@@ -55,14 +55,17 @@ class JID {
/// Converts the JID into a bare JID. /// Converts the JID into a bare JID.
JID toBare() { JID toBare() {
if (isBare()) return this;
return JID(local, domain, ''); return JID(local, domain, '');
} }
/// Converts the JID into one with a resource part of [resource]. /// Converts the JID into one with a resource part of [resource].
JID withResource(String resource) => JID(local, domain, resource); JID withResource(String resource) => JID(local, domain, resource);
/// Convert the JID into the JID of the domain. For example, converts alice@example.org/abc123 to example.org.
JID toDomain() {
return JID('', domain, '');
}
/// Compares the JID with [other]. This function assumes that JID and [other] /// Compares the JID with [other]. This function assumes that JID and [other]
/// are bare, i.e. only the domain- and localparts are compared. If [ensureBare] /// are bare, i.e. only the domain- and localparts are compared. If [ensureBare]
/// is optionally set to true, then [other] MUST be bare. Otherwise, false is returned. /// is optionally set to true, then [other] MUST be bare. Otherwise, false is returned.

View File

@@ -16,7 +16,6 @@ class XmppManagerAttributes {
required this.getManagerById, required this.getManagerById,
required this.sendEvent, required this.sendEvent,
required this.getConnectionSettings, required this.getConnectionSettings,
required this.isFeatureSupported,
required this.getFullJID, required this.getFullJID,
required this.getSocket, required this.getSocket,
required this.getConnection, required this.getConnection,
@@ -24,14 +23,7 @@ class XmppManagerAttributes {
}); });
/// Send a stanza whose response can be awaited. /// Send a stanza whose response can be awaited.
final Future<XMLNode> Function( final Future<XMLNode?> Function(StanzaDetails) sendStanza;
Stanza stanza, {
StanzaFromType addFrom,
bool addId,
bool awaitable,
bool encrypted,
bool forceEncryption,
}) sendStanza;
/// Send a nonza. /// Send a nonza.
final void Function(XMLNode) sendNonza; final void Function(XMLNode) sendNonza;
@@ -45,9 +37,6 @@ class XmppManagerAttributes {
/// (Maybe) Get a Manager attached to the connection by its Id. /// (Maybe) Get a Manager attached to the connection by its Id.
final T? Function<T extends XmppManagerBase>(String) getManagerById; final T? Function<T extends XmppManagerBase>(String) getManagerById;
/// Returns true if a server feature is supported
final bool Function(String) isFeatureSupported;
/// Returns the full JID of the current account /// Returns the full JID of the current account
final JID Function() getFullJID; final JID Function() getFullJID;

View File

@@ -5,7 +5,9 @@ import 'package:moxxmpp/src/managers/attributes.dart';
import 'package:moxxmpp/src/managers/data.dart'; import 'package:moxxmpp/src/managers/data.dart';
import 'package:moxxmpp/src/managers/handlers.dart'; import 'package:moxxmpp/src/managers/handlers.dart';
import 'package:moxxmpp/src/managers/namespaces.dart'; import 'package:moxxmpp/src/managers/namespaces.dart';
import 'package:moxxmpp/src/stanza.dart';
import 'package:moxxmpp/src/stringxml.dart'; import 'package:moxxmpp/src/stringxml.dart';
import 'package:moxxmpp/src/xeps/xep_0030/errors.dart';
import 'package:moxxmpp/src/xeps/xep_0030/types.dart'; import 'package:moxxmpp/src/xeps/xep_0030/types.dart';
import 'package:moxxmpp/src/xeps/xep_0030/xep_0030.dart'; import 'package:moxxmpp/src/xeps/xep_0030/xep_0030.dart';
import 'package:moxxmpp/src/xeps/xep_0198/xep_0198.dart'; import 'package:moxxmpp/src/xeps/xep_0198/xep_0198.dart';
@@ -31,6 +33,28 @@ abstract class XmppManagerBase {
return _managerAttributes; return _managerAttributes;
} }
/// Resolves to true when the server supports the disco feature [xmlns]. Resolves
/// to false when either the disco request fails or the server does not
/// support [xmlns].
/// Note that this function requires a registered DiscoManager.
@protected
Future<bool> isFeatureSupported(String xmlns) async {
final dm = _managerAttributes.getManagerById<DiscoManager>(discoManager);
assert(
dm != null,
'The DiscoManager must be registered for isFeatureSupported to work',
);
final result = await dm!.discoInfoQuery(
_managerAttributes.getConnectionSettings().jid.toDomain(),
);
if (result.isType<DiscoError>()) {
return false;
}
return result.get<DiscoInfo>().features.contains(xmlns);
}
/// Return the StanzaHandlers associated with this manager that deal with stanzas we /// Return the StanzaHandlers associated with this manager that deal with stanzas we
/// send. These are run before the stanza is sent. The higher the value of the /// send. These are run before the stanza is sent. The higher the value of the
/// handler's priority, the earlier it is run. /// handler's priority, the earlier it is run.
@@ -56,6 +80,9 @@ abstract class XmppManagerBase {
/// handler's priority, the earlier it is run. /// handler's priority, the earlier it is run.
List<NonzaHandler> getNonzaHandlers() => []; List<NonzaHandler> getNonzaHandlers() => [];
/// Whenever the socket receives data, this method is called, if it is non-null.
Future<void> onData() async {}
/// Return a list of features that should be included in a disco response. /// Return a list of features that should be included in a disco response.
List<String> getDiscoFeatures() => []; List<String> getDiscoFeatures() => [];
@@ -141,9 +168,11 @@ abstract class XmppManagerBase {
); );
await getAttributes().sendStanza( await getAttributes().sendStanza(
stanza, StanzaDetails(
awaitable: false, stanza,
forceEncryption: data.encrypted, awaitable: false,
forceEncryption: data.encrypted,
),
); );
} }
} }

View File

@@ -1,74 +1,59 @@
import 'package:freezed_annotation/freezed_annotation.dart';
import 'package:moxxmpp/src/stanza.dart'; import 'package:moxxmpp/src/stanza.dart';
import 'package:moxxmpp/src/xeps/xep_0066.dart'; import 'package:moxxmpp/src/util/typed_map.dart';
import 'package:moxxmpp/src/xeps/xep_0085.dart';
import 'package:moxxmpp/src/xeps/xep_0203.dart';
import 'package:moxxmpp/src/xeps/xep_0359.dart';
import 'package:moxxmpp/src/xeps/xep_0380.dart';
import 'package:moxxmpp/src/xeps/xep_0385.dart';
import 'package:moxxmpp/src/xeps/xep_0424.dart';
import 'package:moxxmpp/src/xeps/xep_0444.dart';
import 'package:moxxmpp/src/xeps/xep_0446.dart';
import 'package:moxxmpp/src/xeps/xep_0447.dart';
import 'package:moxxmpp/src/xeps/xep_0461.dart';
part 'data.freezed.dart'; abstract class StanzaHandlerExtension {}
@freezed class StanzaHandlerData {
class StanzaHandlerData with _$StanzaHandlerData { StanzaHandlerData(
factory StanzaHandlerData( this.done,
// Indicates to the runner that processing is now done. This means that all this.cancel,
// pre-processing is done and no other handlers should be consulted. this.stanza,
bool done, this.extensions, {
// Indicates to the runner that processing is to be cancelled and no further handlers this.cancelReason,
// should run. The stanza also will not be sent. this.encryptionError,
bool cancel, this.encrypted = false,
// The reason why we cancelled the processing and sending this.forceEncryption = false,
dynamic cancelReason, this.shouldEncrypt = true,
// The stanza that is being dealt with. SHOULD NOT be overwritten, unless it is absolutely this.skip = false,
// necessary, e.g. with Message Carbons or OMEMO });
Stanza stanza, {
// Whether the stanza is retransmitted. Only useful in the context of outgoing /// Indicates to the runner that processing is now done. This means that all
// stanza handlers. MUST NOT be overwritten. /// pre-processing is done and no other handlers should be consulted.
@Default(false) bool retransmitted, bool done;
StatelessMediaSharingData? sims,
StatelessFileSharingData? sfs, /// Only useful in combination with [done] = true: When [skip] is set to true and
OOBData? oob, /// this [StanzaHandlerData] object is returned from a IncomingPreStanzaHandler, then
StableStanzaId? stableId, /// moxxmpp will skip checking whether the stanza was awaited and will not run any actual
ReplyData? reply, /// IncomingStanzaHandler callbacks.
ChatState? chatState, bool skip;
@Default(false) bool isCarbon,
@Default(false) bool deliveryReceiptRequested, /// Indicates to the runner that processing is to be cancelled and no further handlers
@Default(false) bool isMarkable, /// should run. The stanza also will not be sent.
// File Upload Notifications bool cancel;
// A notification
FileMetadataData? fun, /// The reason why we cancelled the processing and sending.
// The stanza id this replaces Object? cancelReason;
String? funReplacement,
// The stanza id this cancels /// The reason why an encryption or decryption failed.
String? funCancellation, Object? encryptionError;
// Whether the stanza was received encrypted
@Default(false) bool encrypted, /// The stanza that is being dealt with. SHOULD NOT be overwritten, unless it is
// If true, forces the encryption manager to encrypt to the JID, even if it /// absolutely necessary, e.g. with Message Carbons or OMEMO.
// would not normally. In the case of OMEMO: If shouldEncrypt returns false Stanza stanza;
// but forceEncryption is true, then the OMEMO manager will try to encrypt
// to the JID anyway. /// Whether the stanza is already encrypted
@Default(false) bool forceEncryption, bool encrypted;
// The stated type of encryption used, if any was used
ExplicitEncryptionType? encryptionType, // If true, forces the encryption manager to encrypt to the JID, even if it
// Delayed Delivery // would not normally. In the case of OMEMO: If shouldEncrypt returns false
DelayedDelivery? delayedDelivery, // but forceEncryption is true, then the OMEMO manager will try to encrypt
// This is for stanza handlers that are not part of the XMPP library but still need // to the JID anyway.
// pass data around. bool forceEncryption;
@Default(<String, dynamic>{}) Map<String, dynamic> other,
// If non-null, then it indicates the origin Id of the message that should be /// Flag indicating whether a E2EE implementation should encrypt the stanza (true)
// retracted /// or not (false).
MessageRetractionData? messageRetraction, bool shouldEncrypt;
// If non-null, then the message is a correction for the specified stanza Id
String? lastMessageCorrectionSid, /// Additional data from other managers.
// Reactions data final TypedMap<StanzaHandlerExtension> extensions;
MessageReactions? messageReactions,
// The Id of the sticker pack this sticker belongs to
String? stickerPackId,
}) = _StanzaHandlerData;
} }

View File

@@ -1,747 +0,0 @@
// coverage:ignore-file
// GENERATED CODE - DO NOT MODIFY BY HAND
// ignore_for_file: type=lint
// ignore_for_file: unused_element, deprecated_member_use, deprecated_member_use_from_same_package, use_function_type_syntax_for_parameters, unnecessary_const, avoid_init_to_null, invalid_override_different_default_values_named, prefer_expression_function_bodies, annotate_overrides, invalid_annotation_target
part of 'data.dart';
// **************************************************************************
// FreezedGenerator
// **************************************************************************
T _$identity<T>(T value) => value;
final _privateConstructorUsedError = UnsupportedError(
'It seems like you constructed your class using `MyClass._()`. This constructor is only meant to be used by freezed and you are not supposed to need it nor use it.\nPlease check the documentation here for more information: https://github.com/rrousselGit/freezed#custom-getters-and-methods');
/// @nodoc
mixin _$StanzaHandlerData {
// Indicates to the runner that processing is now done. This means that all
// pre-processing is done and no other handlers should be consulted.
bool get done =>
throw _privateConstructorUsedError; // Indicates to the runner that processing is to be cancelled and no further handlers
// should run. The stanza also will not be sent.
bool get cancel =>
throw _privateConstructorUsedError; // The reason why we cancelled the processing and sending
dynamic get cancelReason =>
throw _privateConstructorUsedError; // The stanza that is being dealt with. SHOULD NOT be overwritten, unless it is absolutely
// necessary, e.g. with Message Carbons or OMEMO
Stanza get stanza =>
throw _privateConstructorUsedError; // Whether the stanza is retransmitted. Only useful in the context of outgoing
// stanza handlers. MUST NOT be overwritten.
bool get retransmitted => throw _privateConstructorUsedError;
StatelessMediaSharingData? get sims => throw _privateConstructorUsedError;
StatelessFileSharingData? get sfs => throw _privateConstructorUsedError;
OOBData? get oob => throw _privateConstructorUsedError;
StableStanzaId? get stableId => throw _privateConstructorUsedError;
ReplyData? get reply => throw _privateConstructorUsedError;
ChatState? get chatState => throw _privateConstructorUsedError;
bool get isCarbon => throw _privateConstructorUsedError;
bool get deliveryReceiptRequested => throw _privateConstructorUsedError;
bool get isMarkable =>
throw _privateConstructorUsedError; // File Upload Notifications
// A notification
FileMetadataData? get fun =>
throw _privateConstructorUsedError; // The stanza id this replaces
String? get funReplacement =>
throw _privateConstructorUsedError; // The stanza id this cancels
String? get funCancellation =>
throw _privateConstructorUsedError; // Whether the stanza was received encrypted
bool get encrypted =>
throw _privateConstructorUsedError; // If true, forces the encryption manager to encrypt to the JID, even if it
// would not normally. In the case of OMEMO: If shouldEncrypt returns false
// but forceEncryption is true, then the OMEMO manager will try to encrypt
// to the JID anyway.
bool get forceEncryption =>
throw _privateConstructorUsedError; // The stated type of encryption used, if any was used
ExplicitEncryptionType? get encryptionType =>
throw _privateConstructorUsedError; // Delayed Delivery
DelayedDelivery? get delayedDelivery =>
throw _privateConstructorUsedError; // This is for stanza handlers that are not part of the XMPP library but still need
// pass data around.
Map<String, dynamic> get other =>
throw _privateConstructorUsedError; // If non-null, then it indicates the origin Id of the message that should be
// retracted
MessageRetractionData? get messageRetraction =>
throw _privateConstructorUsedError; // If non-null, then the message is a correction for the specified stanza Id
String? get lastMessageCorrectionSid =>
throw _privateConstructorUsedError; // Reactions data
MessageReactions? get messageReactions =>
throw _privateConstructorUsedError; // The Id of the sticker pack this sticker belongs to
String? get stickerPackId => throw _privateConstructorUsedError;
@JsonKey(ignore: true)
$StanzaHandlerDataCopyWith<StanzaHandlerData> get copyWith =>
throw _privateConstructorUsedError;
}
/// @nodoc
abstract class $StanzaHandlerDataCopyWith<$Res> {
factory $StanzaHandlerDataCopyWith(
StanzaHandlerData value, $Res Function(StanzaHandlerData) then) =
_$StanzaHandlerDataCopyWithImpl<$Res>;
$Res call(
{bool done,
bool cancel,
dynamic cancelReason,
Stanza stanza,
bool retransmitted,
StatelessMediaSharingData? sims,
StatelessFileSharingData? sfs,
OOBData? oob,
StableStanzaId? stableId,
ReplyData? reply,
ChatState? chatState,
bool isCarbon,
bool deliveryReceiptRequested,
bool isMarkable,
FileMetadataData? fun,
String? funReplacement,
String? funCancellation,
bool encrypted,
bool forceEncryption,
ExplicitEncryptionType? encryptionType,
DelayedDelivery? delayedDelivery,
Map<String, dynamic> other,
MessageRetractionData? messageRetraction,
String? lastMessageCorrectionSid,
MessageReactions? messageReactions,
String? stickerPackId});
}
/// @nodoc
class _$StanzaHandlerDataCopyWithImpl<$Res>
implements $StanzaHandlerDataCopyWith<$Res> {
_$StanzaHandlerDataCopyWithImpl(this._value, this._then);
final StanzaHandlerData _value;
// ignore: unused_field
final $Res Function(StanzaHandlerData) _then;
@override
$Res call({
Object? done = freezed,
Object? cancel = freezed,
Object? cancelReason = freezed,
Object? stanza = freezed,
Object? retransmitted = freezed,
Object? sims = freezed,
Object? sfs = freezed,
Object? oob = freezed,
Object? stableId = freezed,
Object? reply = freezed,
Object? chatState = freezed,
Object? isCarbon = freezed,
Object? deliveryReceiptRequested = freezed,
Object? isMarkable = freezed,
Object? fun = freezed,
Object? funReplacement = freezed,
Object? funCancellation = freezed,
Object? encrypted = freezed,
Object? forceEncryption = freezed,
Object? encryptionType = freezed,
Object? delayedDelivery = freezed,
Object? other = freezed,
Object? messageRetraction = freezed,
Object? lastMessageCorrectionSid = freezed,
Object? messageReactions = freezed,
Object? stickerPackId = freezed,
}) {
return _then(_value.copyWith(
done: done == freezed
? _value.done
: done // ignore: cast_nullable_to_non_nullable
as bool,
cancel: cancel == freezed
? _value.cancel
: cancel // ignore: cast_nullable_to_non_nullable
as bool,
cancelReason: cancelReason == freezed
? _value.cancelReason
: cancelReason // ignore: cast_nullable_to_non_nullable
as dynamic,
stanza: stanza == freezed
? _value.stanza
: stanza // ignore: cast_nullable_to_non_nullable
as Stanza,
retransmitted: retransmitted == freezed
? _value.retransmitted
: retransmitted // ignore: cast_nullable_to_non_nullable
as bool,
sims: sims == freezed
? _value.sims
: sims // ignore: cast_nullable_to_non_nullable
as StatelessMediaSharingData?,
sfs: sfs == freezed
? _value.sfs
: sfs // ignore: cast_nullable_to_non_nullable
as StatelessFileSharingData?,
oob: oob == freezed
? _value.oob
: oob // ignore: cast_nullable_to_non_nullable
as OOBData?,
stableId: stableId == freezed
? _value.stableId
: stableId // ignore: cast_nullable_to_non_nullable
as StableStanzaId?,
reply: reply == freezed
? _value.reply
: reply // ignore: cast_nullable_to_non_nullable
as ReplyData?,
chatState: chatState == freezed
? _value.chatState
: chatState // ignore: cast_nullable_to_non_nullable
as ChatState?,
isCarbon: isCarbon == freezed
? _value.isCarbon
: isCarbon // ignore: cast_nullable_to_non_nullable
as bool,
deliveryReceiptRequested: deliveryReceiptRequested == freezed
? _value.deliveryReceiptRequested
: deliveryReceiptRequested // ignore: cast_nullable_to_non_nullable
as bool,
isMarkable: isMarkable == freezed
? _value.isMarkable
: isMarkable // ignore: cast_nullable_to_non_nullable
as bool,
fun: fun == freezed
? _value.fun
: fun // ignore: cast_nullable_to_non_nullable
as FileMetadataData?,
funReplacement: funReplacement == freezed
? _value.funReplacement
: funReplacement // ignore: cast_nullable_to_non_nullable
as String?,
funCancellation: funCancellation == freezed
? _value.funCancellation
: funCancellation // ignore: cast_nullable_to_non_nullable
as String?,
encrypted: encrypted == freezed
? _value.encrypted
: encrypted // ignore: cast_nullable_to_non_nullable
as bool,
forceEncryption: forceEncryption == freezed
? _value.forceEncryption
: forceEncryption // ignore: cast_nullable_to_non_nullable
as bool,
encryptionType: encryptionType == freezed
? _value.encryptionType
: encryptionType // ignore: cast_nullable_to_non_nullable
as ExplicitEncryptionType?,
delayedDelivery: delayedDelivery == freezed
? _value.delayedDelivery
: delayedDelivery // ignore: cast_nullable_to_non_nullable
as DelayedDelivery?,
other: other == freezed
? _value.other
: other // ignore: cast_nullable_to_non_nullable
as Map<String, dynamic>,
messageRetraction: messageRetraction == freezed
? _value.messageRetraction
: messageRetraction // ignore: cast_nullable_to_non_nullable
as MessageRetractionData?,
lastMessageCorrectionSid: lastMessageCorrectionSid == freezed
? _value.lastMessageCorrectionSid
: lastMessageCorrectionSid // ignore: cast_nullable_to_non_nullable
as String?,
messageReactions: messageReactions == freezed
? _value.messageReactions
: messageReactions // ignore: cast_nullable_to_non_nullable
as MessageReactions?,
stickerPackId: stickerPackId == freezed
? _value.stickerPackId
: stickerPackId // ignore: cast_nullable_to_non_nullable
as String?,
));
}
}
/// @nodoc
abstract class _$$_StanzaHandlerDataCopyWith<$Res>
implements $StanzaHandlerDataCopyWith<$Res> {
factory _$$_StanzaHandlerDataCopyWith(_$_StanzaHandlerData value,
$Res Function(_$_StanzaHandlerData) then) =
__$$_StanzaHandlerDataCopyWithImpl<$Res>;
@override
$Res call(
{bool done,
bool cancel,
dynamic cancelReason,
Stanza stanza,
bool retransmitted,
StatelessMediaSharingData? sims,
StatelessFileSharingData? sfs,
OOBData? oob,
StableStanzaId? stableId,
ReplyData? reply,
ChatState? chatState,
bool isCarbon,
bool deliveryReceiptRequested,
bool isMarkable,
FileMetadataData? fun,
String? funReplacement,
String? funCancellation,
bool encrypted,
bool forceEncryption,
ExplicitEncryptionType? encryptionType,
DelayedDelivery? delayedDelivery,
Map<String, dynamic> other,
MessageRetractionData? messageRetraction,
String? lastMessageCorrectionSid,
MessageReactions? messageReactions,
String? stickerPackId});
}
/// @nodoc
class __$$_StanzaHandlerDataCopyWithImpl<$Res>
extends _$StanzaHandlerDataCopyWithImpl<$Res>
implements _$$_StanzaHandlerDataCopyWith<$Res> {
__$$_StanzaHandlerDataCopyWithImpl(
_$_StanzaHandlerData _value, $Res Function(_$_StanzaHandlerData) _then)
: super(_value, (v) => _then(v as _$_StanzaHandlerData));
@override
_$_StanzaHandlerData get _value => super._value as _$_StanzaHandlerData;
@override
$Res call({
Object? done = freezed,
Object? cancel = freezed,
Object? cancelReason = freezed,
Object? stanza = freezed,
Object? retransmitted = freezed,
Object? sims = freezed,
Object? sfs = freezed,
Object? oob = freezed,
Object? stableId = freezed,
Object? reply = freezed,
Object? chatState = freezed,
Object? isCarbon = freezed,
Object? deliveryReceiptRequested = freezed,
Object? isMarkable = freezed,
Object? fun = freezed,
Object? funReplacement = freezed,
Object? funCancellation = freezed,
Object? encrypted = freezed,
Object? forceEncryption = freezed,
Object? encryptionType = freezed,
Object? delayedDelivery = freezed,
Object? other = freezed,
Object? messageRetraction = freezed,
Object? lastMessageCorrectionSid = freezed,
Object? messageReactions = freezed,
Object? stickerPackId = freezed,
}) {
return _then(_$_StanzaHandlerData(
done == freezed
? _value.done
: done // ignore: cast_nullable_to_non_nullable
as bool,
cancel == freezed
? _value.cancel
: cancel // ignore: cast_nullable_to_non_nullable
as bool,
cancelReason == freezed
? _value.cancelReason
: cancelReason // ignore: cast_nullable_to_non_nullable
as dynamic,
stanza == freezed
? _value.stanza
: stanza // ignore: cast_nullable_to_non_nullable
as Stanza,
retransmitted: retransmitted == freezed
? _value.retransmitted
: retransmitted // ignore: cast_nullable_to_non_nullable
as bool,
sims: sims == freezed
? _value.sims
: sims // ignore: cast_nullable_to_non_nullable
as StatelessMediaSharingData?,
sfs: sfs == freezed
? _value.sfs
: sfs // ignore: cast_nullable_to_non_nullable
as StatelessFileSharingData?,
oob: oob == freezed
? _value.oob
: oob // ignore: cast_nullable_to_non_nullable
as OOBData?,
stableId: stableId == freezed
? _value.stableId
: stableId // ignore: cast_nullable_to_non_nullable
as StableStanzaId?,
reply: reply == freezed
? _value.reply
: reply // ignore: cast_nullable_to_non_nullable
as ReplyData?,
chatState: chatState == freezed
? _value.chatState
: chatState // ignore: cast_nullable_to_non_nullable
as ChatState?,
isCarbon: isCarbon == freezed
? _value.isCarbon
: isCarbon // ignore: cast_nullable_to_non_nullable
as bool,
deliveryReceiptRequested: deliveryReceiptRequested == freezed
? _value.deliveryReceiptRequested
: deliveryReceiptRequested // ignore: cast_nullable_to_non_nullable
as bool,
isMarkable: isMarkable == freezed
? _value.isMarkable
: isMarkable // ignore: cast_nullable_to_non_nullable
as bool,
fun: fun == freezed
? _value.fun
: fun // ignore: cast_nullable_to_non_nullable
as FileMetadataData?,
funReplacement: funReplacement == freezed
? _value.funReplacement
: funReplacement // ignore: cast_nullable_to_non_nullable
as String?,
funCancellation: funCancellation == freezed
? _value.funCancellation
: funCancellation // ignore: cast_nullable_to_non_nullable
as String?,
encrypted: encrypted == freezed
? _value.encrypted
: encrypted // ignore: cast_nullable_to_non_nullable
as bool,
forceEncryption: forceEncryption == freezed
? _value.forceEncryption
: forceEncryption // ignore: cast_nullable_to_non_nullable
as bool,
encryptionType: encryptionType == freezed
? _value.encryptionType
: encryptionType // ignore: cast_nullable_to_non_nullable
as ExplicitEncryptionType?,
delayedDelivery: delayedDelivery == freezed
? _value.delayedDelivery
: delayedDelivery // ignore: cast_nullable_to_non_nullable
as DelayedDelivery?,
other: other == freezed
? _value._other
: other // ignore: cast_nullable_to_non_nullable
as Map<String, dynamic>,
messageRetraction: messageRetraction == freezed
? _value.messageRetraction
: messageRetraction // ignore: cast_nullable_to_non_nullable
as MessageRetractionData?,
lastMessageCorrectionSid: lastMessageCorrectionSid == freezed
? _value.lastMessageCorrectionSid
: lastMessageCorrectionSid // ignore: cast_nullable_to_non_nullable
as String?,
messageReactions: messageReactions == freezed
? _value.messageReactions
: messageReactions // ignore: cast_nullable_to_non_nullable
as MessageReactions?,
stickerPackId: stickerPackId == freezed
? _value.stickerPackId
: stickerPackId // ignore: cast_nullable_to_non_nullable
as String?,
));
}
}
/// @nodoc
class _$_StanzaHandlerData implements _StanzaHandlerData {
_$_StanzaHandlerData(this.done, this.cancel, this.cancelReason, this.stanza,
{this.retransmitted = false,
this.sims,
this.sfs,
this.oob,
this.stableId,
this.reply,
this.chatState,
this.isCarbon = false,
this.deliveryReceiptRequested = false,
this.isMarkable = false,
this.fun,
this.funReplacement,
this.funCancellation,
this.encrypted = false,
this.forceEncryption = false,
this.encryptionType,
this.delayedDelivery,
final Map<String, dynamic> other = const <String, dynamic>{},
this.messageRetraction,
this.lastMessageCorrectionSid,
this.messageReactions,
this.stickerPackId})
: _other = other;
// Indicates to the runner that processing is now done. This means that all
// pre-processing is done and no other handlers should be consulted.
@override
final bool done;
// Indicates to the runner that processing is to be cancelled and no further handlers
// should run. The stanza also will not be sent.
@override
final bool cancel;
// The reason why we cancelled the processing and sending
@override
final dynamic cancelReason;
// The stanza that is being dealt with. SHOULD NOT be overwritten, unless it is absolutely
// necessary, e.g. with Message Carbons or OMEMO
@override
final Stanza stanza;
// Whether the stanza is retransmitted. Only useful in the context of outgoing
// stanza handlers. MUST NOT be overwritten.
@override
@JsonKey()
final bool retransmitted;
@override
final StatelessMediaSharingData? sims;
@override
final StatelessFileSharingData? sfs;
@override
final OOBData? oob;
@override
final StableStanzaId? stableId;
@override
final ReplyData? reply;
@override
final ChatState? chatState;
@override
@JsonKey()
final bool isCarbon;
@override
@JsonKey()
final bool deliveryReceiptRequested;
@override
@JsonKey()
final bool isMarkable;
// File Upload Notifications
// A notification
@override
final FileMetadataData? fun;
// The stanza id this replaces
@override
final String? funReplacement;
// The stanza id this cancels
@override
final String? funCancellation;
// Whether the stanza was received encrypted
@override
@JsonKey()
final bool encrypted;
// If true, forces the encryption manager to encrypt to the JID, even if it
// would not normally. In the case of OMEMO: If shouldEncrypt returns false
// but forceEncryption is true, then the OMEMO manager will try to encrypt
// to the JID anyway.
@override
@JsonKey()
final bool forceEncryption;
// The stated type of encryption used, if any was used
@override
final ExplicitEncryptionType? encryptionType;
// Delayed Delivery
@override
final DelayedDelivery? delayedDelivery;
// This is for stanza handlers that are not part of the XMPP library but still need
// pass data around.
final Map<String, dynamic> _other;
// This is for stanza handlers that are not part of the XMPP library but still need
// pass data around.
@override
@JsonKey()
Map<String, dynamic> get other {
// ignore: implicit_dynamic_type
return EqualUnmodifiableMapView(_other);
}
// If non-null, then it indicates the origin Id of the message that should be
// retracted
@override
final MessageRetractionData? messageRetraction;
// If non-null, then the message is a correction for the specified stanza Id
@override
final String? lastMessageCorrectionSid;
// Reactions data
@override
final MessageReactions? messageReactions;
// The Id of the sticker pack this sticker belongs to
@override
final String? stickerPackId;
@override
String toString() {
return 'StanzaHandlerData(done: $done, cancel: $cancel, cancelReason: $cancelReason, stanza: $stanza, retransmitted: $retransmitted, sims: $sims, sfs: $sfs, oob: $oob, stableId: $stableId, reply: $reply, chatState: $chatState, isCarbon: $isCarbon, deliveryReceiptRequested: $deliveryReceiptRequested, isMarkable: $isMarkable, fun: $fun, funReplacement: $funReplacement, funCancellation: $funCancellation, encrypted: $encrypted, forceEncryption: $forceEncryption, encryptionType: $encryptionType, delayedDelivery: $delayedDelivery, other: $other, messageRetraction: $messageRetraction, lastMessageCorrectionSid: $lastMessageCorrectionSid, messageReactions: $messageReactions, stickerPackId: $stickerPackId)';
}
@override
bool operator ==(dynamic other) {
return identical(this, other) ||
(other.runtimeType == runtimeType &&
other is _$_StanzaHandlerData &&
const DeepCollectionEquality().equals(other.done, done) &&
const DeepCollectionEquality().equals(other.cancel, cancel) &&
const DeepCollectionEquality()
.equals(other.cancelReason, cancelReason) &&
const DeepCollectionEquality().equals(other.stanza, stanza) &&
const DeepCollectionEquality()
.equals(other.retransmitted, retransmitted) &&
const DeepCollectionEquality().equals(other.sims, sims) &&
const DeepCollectionEquality().equals(other.sfs, sfs) &&
const DeepCollectionEquality().equals(other.oob, oob) &&
const DeepCollectionEquality().equals(other.stableId, stableId) &&
const DeepCollectionEquality().equals(other.reply, reply) &&
const DeepCollectionEquality().equals(other.chatState, chatState) &&
const DeepCollectionEquality().equals(other.isCarbon, isCarbon) &&
const DeepCollectionEquality().equals(
other.deliveryReceiptRequested, deliveryReceiptRequested) &&
const DeepCollectionEquality()
.equals(other.isMarkable, isMarkable) &&
const DeepCollectionEquality().equals(other.fun, fun) &&
const DeepCollectionEquality()
.equals(other.funReplacement, funReplacement) &&
const DeepCollectionEquality()
.equals(other.funCancellation, funCancellation) &&
const DeepCollectionEquality().equals(other.encrypted, encrypted) &&
const DeepCollectionEquality()
.equals(other.forceEncryption, forceEncryption) &&
const DeepCollectionEquality()
.equals(other.encryptionType, encryptionType) &&
const DeepCollectionEquality()
.equals(other.delayedDelivery, delayedDelivery) &&
const DeepCollectionEquality().equals(other._other, this._other) &&
const DeepCollectionEquality()
.equals(other.messageRetraction, messageRetraction) &&
const DeepCollectionEquality().equals(
other.lastMessageCorrectionSid, lastMessageCorrectionSid) &&
const DeepCollectionEquality()
.equals(other.messageReactions, messageReactions) &&
const DeepCollectionEquality()
.equals(other.stickerPackId, stickerPackId));
}
@override
int get hashCode => Object.hashAll([
runtimeType,
const DeepCollectionEquality().hash(done),
const DeepCollectionEquality().hash(cancel),
const DeepCollectionEquality().hash(cancelReason),
const DeepCollectionEquality().hash(stanza),
const DeepCollectionEquality().hash(retransmitted),
const DeepCollectionEquality().hash(sims),
const DeepCollectionEquality().hash(sfs),
const DeepCollectionEquality().hash(oob),
const DeepCollectionEquality().hash(stableId),
const DeepCollectionEquality().hash(reply),
const DeepCollectionEquality().hash(chatState),
const DeepCollectionEquality().hash(isCarbon),
const DeepCollectionEquality().hash(deliveryReceiptRequested),
const DeepCollectionEquality().hash(isMarkable),
const DeepCollectionEquality().hash(fun),
const DeepCollectionEquality().hash(funReplacement),
const DeepCollectionEquality().hash(funCancellation),
const DeepCollectionEquality().hash(encrypted),
const DeepCollectionEquality().hash(forceEncryption),
const DeepCollectionEquality().hash(encryptionType),
const DeepCollectionEquality().hash(delayedDelivery),
const DeepCollectionEquality().hash(_other),
const DeepCollectionEquality().hash(messageRetraction),
const DeepCollectionEquality().hash(lastMessageCorrectionSid),
const DeepCollectionEquality().hash(messageReactions),
const DeepCollectionEquality().hash(stickerPackId)
]);
@JsonKey(ignore: true)
@override
_$$_StanzaHandlerDataCopyWith<_$_StanzaHandlerData> get copyWith =>
__$$_StanzaHandlerDataCopyWithImpl<_$_StanzaHandlerData>(
this, _$identity);
}
abstract class _StanzaHandlerData implements StanzaHandlerData {
factory _StanzaHandlerData(final bool done, final bool cancel,
final dynamic cancelReason, final Stanza stanza,
{final bool retransmitted,
final StatelessMediaSharingData? sims,
final StatelessFileSharingData? sfs,
final OOBData? oob,
final StableStanzaId? stableId,
final ReplyData? reply,
final ChatState? chatState,
final bool isCarbon,
final bool deliveryReceiptRequested,
final bool isMarkable,
final FileMetadataData? fun,
final String? funReplacement,
final String? funCancellation,
final bool encrypted,
final bool forceEncryption,
final ExplicitEncryptionType? encryptionType,
final DelayedDelivery? delayedDelivery,
final Map<String, dynamic> other,
final MessageRetractionData? messageRetraction,
final String? lastMessageCorrectionSid,
final MessageReactions? messageReactions,
final String? stickerPackId}) = _$_StanzaHandlerData;
@override // Indicates to the runner that processing is now done. This means that all
// pre-processing is done and no other handlers should be consulted.
bool get done;
@override // Indicates to the runner that processing is to be cancelled and no further handlers
// should run. The stanza also will not be sent.
bool get cancel;
@override // The reason why we cancelled the processing and sending
dynamic get cancelReason;
@override // The stanza that is being dealt with. SHOULD NOT be overwritten, unless it is absolutely
// necessary, e.g. with Message Carbons or OMEMO
Stanza get stanza;
@override // Whether the stanza is retransmitted. Only useful in the context of outgoing
// stanza handlers. MUST NOT be overwritten.
bool get retransmitted;
@override
StatelessMediaSharingData? get sims;
@override
StatelessFileSharingData? get sfs;
@override
OOBData? get oob;
@override
StableStanzaId? get stableId;
@override
ReplyData? get reply;
@override
ChatState? get chatState;
@override
bool get isCarbon;
@override
bool get deliveryReceiptRequested;
@override
bool get isMarkable;
@override // File Upload Notifications
// A notification
FileMetadataData? get fun;
@override // The stanza id this replaces
String? get funReplacement;
@override // The stanza id this cancels
String? get funCancellation;
@override // Whether the stanza was received encrypted
bool get encrypted;
@override // If true, forces the encryption manager to encrypt to the JID, even if it
// would not normally. In the case of OMEMO: If shouldEncrypt returns false
// but forceEncryption is true, then the OMEMO manager will try to encrypt
// to the JID anyway.
bool get forceEncryption;
@override // The stated type of encryption used, if any was used
ExplicitEncryptionType? get encryptionType;
@override // Delayed Delivery
DelayedDelivery? get delayedDelivery;
@override // This is for stanza handlers that are not part of the XMPP library but still need
// pass data around.
Map<String, dynamic> get other;
@override // If non-null, then it indicates the origin Id of the message that should be
// retracted
MessageRetractionData? get messageRetraction;
@override // If non-null, then the message is a correction for the specified stanza Id
String? get lastMessageCorrectionSid;
@override // Reactions data
MessageReactions? get messageReactions;
@override // The Id of the sticker pack this sticker belongs to
String? get stickerPackId;
@override
@JsonKey(ignore: true)
_$$_StanzaHandlerDataCopyWith<_$_StanzaHandlerData> get copyWith =>
throw _privateConstructorUsedError;
}

View File

@@ -1,89 +1,109 @@
import 'package:moxlib/moxlib.dart'; import 'package:collection/collection.dart';
import 'package:moxxmpp/src/managers/data.dart'; import 'package:moxxmpp/src/managers/data.dart';
import 'package:moxxmpp/src/namespaces.dart'; import 'package:moxxmpp/src/namespaces.dart';
import 'package:moxxmpp/src/stanza.dart'; import 'package:moxxmpp/src/stanza.dart';
import 'package:moxxmpp/src/stringxml.dart'; import 'package:moxxmpp/src/stringxml.dart';
/// A Handler is responsible for matching any kind of toplevel item in the XML stream
/// (stanzas and Nonzas). For that, its [matches] method is called. What happens
/// next depends on the subclass.
// ignore: one_member_abstracts
abstract class Handler { abstract class Handler {
const Handler(this.matchStanzas, {this.nonzaTag, this.nonzaXmlns});
final String? nonzaTag;
final String? nonzaXmlns;
final bool matchStanzas;
/// Returns true if the node matches the description provided by this [Handler]. /// Returns true if the node matches the description provided by this [Handler].
bool matches(XMLNode node);
}
/// A Handler that specialises in matching Nonzas (and stanzas).
class NonzaHandler extends Handler {
NonzaHandler({
required this.callback,
this.nonzaTag,
this.nonzaXmlns,
});
/// The function to call when a nonza matches the description.
final Future<bool> Function(XMLNode) callback;
/// The expected tag of a matching nonza.
final String? nonzaTag;
// The expected xmlns attribute of a matching nonza.
final String? nonzaXmlns;
@override
bool matches(XMLNode node) { bool matches(XMLNode node) {
var matches = false; var matches = true;
if (nonzaTag == null && nonzaXmlns == null) { if (nonzaTag == null && nonzaXmlns == null) {
matches = true; return true;
} } else {
if (nonzaXmlns != null) {
if (nonzaXmlns != null && nonzaTag != null) { matches &= node.attributes['xmlns'] == nonzaXmlns;
matches = (node.attributes['xmlns'] ?? '') == nonzaXmlns! && }
node.tag == nonzaTag!; if (nonzaTag != null) {
} matches &= node.tag == nonzaTag;
}
if (matchStanzas && nonzaTag == null) {
matches = ['iq', 'presence', 'message'].contains(node.tag);
} }
return matches; return matches;
} }
} }
class NonzaHandler extends Handler { /// A Handler that only matches stanzas.
NonzaHandler({
required this.callback,
String? nonzaTag,
String? nonzaXmlns,
}) : super(
false,
nonzaTag: nonzaTag,
nonzaXmlns: nonzaXmlns,
);
final Future<bool> Function(XMLNode) callback;
}
class StanzaHandler extends Handler { class StanzaHandler extends Handler {
StanzaHandler({ StanzaHandler({
required this.callback, required this.callback,
this.tagXmlns, this.tagXmlns,
this.tagName, this.tagName,
this.priority = 0, this.priority = 0,
String? stanzaTag, this.stanzaTag,
}) : super( this.xmlns,
true, });
nonzaTag: stanzaTag,
nonzaXmlns: stanzaXmlns, /// If specified, then the stanza must contain a direct child with a tag equal to
); /// [tagName].
final String? tagName; final String? tagName;
/// If specified, then the stanza must contain a direct child with a xmlns attribute
/// equal to [tagXmlns]. If [tagName] is also non-null, then the element must also
/// have a tag equal to [tagName].
final String? tagXmlns; final String? tagXmlns;
/// If specified, the matching stanza must have a tag equal to [stanzaTag].
final String? stanzaTag;
/// If specified, then the stanza must have a xmlns attribute equal to [xmlns].
/// This defaults to [stanzaXmlns], but can be set to any other value or null. This
/// is useful, for example, for components.
final String? xmlns;
/// The priority after which [StanzaHandler]s are sorted.
final int priority; final int priority;
/// The function to call when a stanza matches the description.
final Future<StanzaHandlerData> Function(Stanza, StanzaHandlerData) callback; final Future<StanzaHandlerData> Function(Stanza, StanzaHandlerData) callback;
@override @override
bool matches(XMLNode node) { bool matches(XMLNode node) {
var matches = super.matches(node); var matches = ['iq', 'message', 'presence'].contains(node.tag);
if (stanzaTag != null) {
if (matches == false) { matches &= node.tag == stanzaTag;
return false; }
if (xmlns != null) {
matches &= node.xmlns == xmlns;
} }
if (tagName != null) { if (tagName != null) {
final firstTag = node.firstTag(tagName!, xmlns: tagXmlns); final firstTag = node.firstTag(tagName!, xmlns: tagXmlns);
matches &= firstTag != null;
matches = firstTag != null; if (tagXmlns != null) {
matches &= firstTag?.xmlns == tagXmlns;
}
} else if (tagXmlns != null) { } else if (tagXmlns != null) {
return listContains( matches &= node.children.firstWhereOrNull(
node.children, (XMLNode node_) => node_.attributes['xmlns'] == tagXmlns,
(XMLNode node_) => ) !=
node_.attributes.containsKey('xmlns') && null;
node_.attributes['xmlns'] == tagXmlns,
);
}
if (tagName == null && tagXmlns == null) {
matches = true;
} }
return matches; return matches;

View File

@@ -31,3 +31,6 @@ const lastMessageCorrectionManager = 'org.moxxmpp.lastmessagecorrectionmanager';
const messageReactionsManager = 'org.moxxmpp.messagereactionsmanager'; const messageReactionsManager = 'org.moxxmpp.messagereactionsmanager';
const stickersManager = 'org.moxxmpp.stickersmanager'; const stickersManager = 'org.moxxmpp.stickersmanager';
const entityCapabilitiesManager = 'org.moxxmpp.entitycapabilities'; const entityCapabilitiesManager = 'org.moxxmpp.entitycapabilities';
const messageProcessingHintManager = 'org.moxxmpp.messageprocessinghint';
const occupantIdManager = 'org.moxxmpp.occupantidmanager';
const mucManager = 'org.moxxmpp.mucmanager';

View File

@@ -1,325 +1,153 @@
import 'package:moxlib/moxlib.dart'; import 'package:collection/collection.dart';
import 'package:moxxmpp/src/events.dart'; import 'package:moxxmpp/src/events.dart';
import 'package:moxxmpp/src/jid.dart'; import 'package:moxxmpp/src/jid.dart';
import 'package:moxxmpp/src/managers/base.dart'; import 'package:moxxmpp/src/managers/base.dart';
import 'package:moxxmpp/src/managers/data.dart'; import 'package:moxxmpp/src/managers/data.dart';
import 'package:moxxmpp/src/managers/handlers.dart'; import 'package:moxxmpp/src/managers/handlers.dart';
import 'package:moxxmpp/src/managers/namespaces.dart'; import 'package:moxxmpp/src/managers/namespaces.dart';
import 'package:moxxmpp/src/namespaces.dart';
import 'package:moxxmpp/src/stanza.dart'; import 'package:moxxmpp/src/stanza.dart';
import 'package:moxxmpp/src/stringxml.dart'; import 'package:moxxmpp/src/stringxml.dart';
import 'package:moxxmpp/src/xeps/staging/file_upload_notification.dart'; import 'package:moxxmpp/src/util/typed_map.dart';
import 'package:moxxmpp/src/xeps/xep_0066.dart'; import 'package:moxxmpp/src/xeps/xep_0066.dart';
import 'package:moxxmpp/src/xeps/xep_0085.dart';
import 'package:moxxmpp/src/xeps/xep_0184.dart';
import 'package:moxxmpp/src/xeps/xep_0308.dart';
import 'package:moxxmpp/src/xeps/xep_0333.dart';
import 'package:moxxmpp/src/xeps/xep_0334.dart';
import 'package:moxxmpp/src/xeps/xep_0359.dart';
import 'package:moxxmpp/src/xeps/xep_0424.dart';
import 'package:moxxmpp/src/xeps/xep_0444.dart';
import 'package:moxxmpp/src/xeps/xep_0446.dart';
import 'package:moxxmpp/src/xeps/xep_0447.dart'; import 'package:moxxmpp/src/xeps/xep_0447.dart';
import 'package:moxxmpp/src/xeps/xep_0448.dart'; import 'package:moxxmpp/src/xeps/xep_0449.dart';
import 'package:moxxmpp/src/xeps/xep_0461.dart'; import 'package:moxxmpp/src/xeps/xep_0461.dart';
/// Data used to build a message stanza. /// A callback that is called whenever a message is sent using
/// /// [MessageManager.sendMessage]. The input the typed map that is passed to
/// [setOOBFallbackBody] indicates, when using SFS, whether a OOB fallback should be /// sendMessage.
/// added. This is recommended when sharing files but may cause issues when the message typedef MessageSendingCallback = List<XMLNode> Function(
/// stanza should include a SFS element without any fallbacks. TypedMap<StanzaHandlerExtension>,
class MessageDetails { );
const MessageDetails({
required this.to, /// The raw content of the <body /> element.
this.body, class MessageBodyData implements StanzaHandlerExtension {
this.requestDeliveryReceipt = false, const MessageBodyData(this.body);
this.requestChatMarkers = true,
this.id, /// The content of the <body /> element.
this.originId,
this.quoteBody,
this.quoteId,
this.quoteFrom,
this.chatState,
this.sfs,
this.fun,
this.funReplacement,
this.funCancellation,
this.shouldEncrypt = false,
this.messageRetraction,
this.lastMessageCorrectionId,
this.messageReactions,
this.messageProcessingHints,
this.stickerPackId,
this.setOOBFallbackBody = true,
});
final String to;
final String? body; final String? body;
final bool requestDeliveryReceipt;
final bool requestChatMarkers; XMLNode toXML() {
final String? id; return XMLNode(
final String? originId; tag: 'body',
final String? quoteBody; text: body,
final String? quoteId; );
final String? quoteFrom; }
final ChatState? chatState; }
final StatelessFileSharingData? sfs;
final FileMetadataData? fun; /// The id attribute of the message stanza.
final String? funReplacement; class MessageIdData implements StanzaHandlerExtension {
final String? funCancellation; const MessageIdData(this.id);
final bool shouldEncrypt;
final MessageRetractionData? messageRetraction; /// The id attribute of the stanza.
final String? lastMessageCorrectionId; final String id;
final MessageReactions? messageReactions;
final String? stickerPackId;
final List<MessageProcessingHint>? messageProcessingHints;
final bool setOOBFallbackBody;
} }
class MessageManager extends XmppManagerBase { class MessageManager extends XmppManagerBase {
MessageManager() : super(messageManager); MessageManager() : super(messageManager);
/// The priority of the message handler. If a handler should run before this one,
/// which emits the [MessageEvent] event and terminates processing, make sure it
/// has a priority greater than [messageHandlerPriority].
static int messageHandlerPriority = -100;
/// A list of callbacks that are called when a message is sent in order to add
/// appropriate child elements.
final List<MessageSendingCallback> _messageSendingCallbacks =
List<MessageSendingCallback>.empty(growable: true);
void registerMessageSendingCallback(MessageSendingCallback callback) {
_messageSendingCallbacks.add(callback);
}
@override @override
List<StanzaHandler> getIncomingStanzaHandlers() => [ List<StanzaHandler> getIncomingStanzaHandlers() => [
StanzaHandler( StanzaHandler(
stanzaTag: 'message', stanzaTag: 'message',
callback: _onMessage, callback: _onMessage,
priority: -100, priority: messageHandlerPriority,
) ),
]; ];
@override @override
Future<bool> isSupported() async => true; Future<bool> isSupported() async => true;
Future<StanzaHandlerData> _onMessage( Future<StanzaHandlerData> _onMessage(
Stanza _, Stanza stanza,
StanzaHandlerData state, StanzaHandlerData state,
) async { ) async {
final message = state.stanza; final body = stanza.firstTag('body');
final body = message.firstTag('body'); if (body != null) {
state.extensions.set(
final hints = List<MessageProcessingHint>.empty(growable: true); MessageBodyData(body.innerText()),
for (final element );
in message.findTagsByXmlns(messageProcessingHintsXmlns)) {
hints.add(messageProcessingHintFromXml(element));
} }
getAttributes().sendEvent( getAttributes().sendEvent(
MessageEvent( MessageEvent(
body: body != null ? body.innerText() : '', JID.fromString(state.stanza.attributes['from']! as String),
fromJid: JID.fromString(message.attributes['from']! as String), JID.fromString(state.stanza.attributes['to']! as String),
toJid: JID.fromString(message.attributes['to']! as String), state.encrypted,
sid: message.attributes['id']! as String, state.extensions,
stanzaId: state.stableId ?? const StableStanzaId(), id: state.stanza.attributes['id'] as String?,
isCarbon: state.isCarbon, type: state.stanza.attributes['type'] as String?,
deliveryReceiptRequested: state.deliveryReceiptRequested, error: StanzaError.fromStanza(state.stanza),
isMarkable: state.isMarkable, encryptionError: state.encryptionError,
type: message.attributes['type'] as String?,
oob: state.oob,
sfs: state.sfs,
sims: state.sims,
reply: state.reply,
chatState: state.chatState,
fun: state.fun,
funReplacement: state.funReplacement,
funCancellation: state.funCancellation,
encrypted: state.encrypted,
messageRetraction: state.messageRetraction,
messageCorrectionId: state.lastMessageCorrectionSid,
messageReactions: state.messageReactions,
messageProcessingHints: hints.isEmpty ? null : hints,
stickerPackId: state.stickerPackId,
other: state.other,
error: StanzaError.fromStanza(message),
), ),
); );
return state.copyWith(done: true); return state..done = true;
} }
/// Send a message to to with the content body. If deliveryRequest is true, then /// Send an unawaitable message to [to]. [extensions] is a typed map that contains
/// the message will also request a delivery receipt from the receiver. /// data for building the message.
/// If id is non-null, then it will be the id of the message stanza. Future<void> sendMessage(
/// element to this id. If originId is non-null, then it will create an "origin-id" JID to,
/// child in the message stanza and set its id to originId. TypedMap<StanzaHandlerExtension> extensions, {
void sendMessage(MessageDetails details) { String type = 'chat',
assert( }) async {
implies( await getAttributes().sendStanza(
details.quoteBody != null, StanzaDetails(
details.quoteFrom != null && details.quoteId != null, Stanza.message(
to: to.toString(),
id: extensions.get<MessageIdData>()?.id,
type: type,
children: _messageSendingCallbacks
.map((c) => c(extensions))
.flattened
.toList(),
),
extensions: extensions,
awaitable: false,
), ),
'When quoting a message, then quoteFrom and quoteId must also be non-null',
); );
}
final stanza = Stanza.message( List<XMLNode> _messageSendingCallback(
to: details.to, TypedMap<StanzaHandlerExtension> extensions,
type: 'chat', ) {
id: details.id, if (extensions.get<ReplyData>() != null) {
children: [], return [];
); }
if (extensions.get<StickersData>() != null) {
if (details.quoteBody != null) { return [];
final quote = QuoteData.fromBodies(details.quoteBody!, details.body!); }
if (extensions.get<StatelessFileSharingData>() != null) {
stanza return [];
..addChild( }
XMLNode(tag: 'body', text: quote.body), if (extensions.get<OOBData>() != null) {
) return [];
..addChild(
XMLNode.xmlns(
tag: 'reply',
xmlns: replyXmlns,
attributes: {'to': details.quoteFrom!, 'id': details.quoteId!},
),
)
..addChild(
XMLNode.xmlns(
tag: 'fallback',
xmlns: fallbackXmlns,
attributes: {'for': replyXmlns},
children: [
XMLNode(
tag: 'body',
attributes: <String, String>{
'start': '0',
'end': '${quote.fallbackLength}',
},
)
],
),
);
} else {
var body = details.body;
if (details.sfs != null && details.setOOBFallbackBody) {
// TODO(Unknown): Maybe find a better solution
final firstSource = details.sfs!.sources.first;
if (firstSource is StatelessFileSharingUrlSource) {
body = firstSource.url;
} else if (firstSource is StatelessFileSharingEncryptedSource) {
body = firstSource.source.url;
}
} else if (details.messageRetraction?.fallback != null) {
body = details.messageRetraction!.fallback;
}
if (body != null) {
stanza.addChild(
XMLNode(tag: 'body', text: body),
);
}
} }
if (details.requestDeliveryReceipt) { final data = extensions.get<MessageBodyData>();
stanza.addChild(makeMessageDeliveryRequest()); return data != null ? [data.toXML()] : [];
} }
if (details.requestChatMarkers) {
stanza.addChild(makeChatMarkerMarkable());
}
if (details.originId != null) {
stanza.addChild(makeOriginIdElement(details.originId!));
}
if (details.sfs != null) { @override
stanza.addChild(details.sfs!.toXML()); Future<void> postRegisterCallback() async {
await super.postRegisterCallback();
final source = details.sfs!.sources.first; // Register the sending callback
if (source is StatelessFileSharingUrlSource && registerMessageSendingCallback(_messageSendingCallback);
details.setOOBFallbackBody) {
// SFS recommends OOB as a fallback
stanza.addChild(constructOOBNode(OOBData(url: source.url)));
}
}
if (details.chatState != null) {
stanza.addChild(
// TODO(Unknown): Move this into xep_0085.dart
XMLNode.xmlns(
tag: chatStateToString(details.chatState!),
xmlns: chatStateXmlns,
),
);
}
if (details.fun != null) {
stanza.addChild(
XMLNode.xmlns(
tag: 'file-upload',
xmlns: fileUploadNotificationXmlns,
children: [
details.fun!.toXML(),
],
),
);
}
if (details.funReplacement != null) {
stanza.addChild(
XMLNode.xmlns(
tag: 'replaces',
xmlns: fileUploadNotificationXmlns,
attributes: <String, String>{
'id': details.funReplacement!,
},
),
);
}
if (details.messageRetraction != null) {
stanza.addChild(
XMLNode.xmlns(
tag: 'apply-to',
xmlns: fasteningXmlns,
attributes: <String, String>{
'id': details.messageRetraction!.id,
},
children: [
XMLNode.xmlns(
tag: 'retract',
xmlns: messageRetractionXmlns,
),
],
),
);
if (details.messageRetraction!.fallback != null) {
stanza.addChild(
XMLNode.xmlns(
tag: 'fallback',
xmlns: fallbackIndicationXmlns,
),
);
}
}
if (details.lastMessageCorrectionId != null) {
stanza.addChild(
makeLastMessageCorrectionEdit(
details.lastMessageCorrectionId!,
),
);
}
if (details.messageReactions != null) {
stanza.addChild(details.messageReactions!.toXml());
}
if (details.messageProcessingHints != null) {
for (final hint in details.messageProcessingHints!) {
stanza.addChild(hint.toXml());
}
}
if (details.stickerPackId != null) {
stanza.addChild(
XMLNode.xmlns(
tag: 'sticker',
xmlns: stickersXmlns,
attributes: {
'pack': details.stickerPackId!,
},
),
);
}
getAttributes().sendStanza(stanza, awaitable: false);
} }
} }

View File

@@ -9,9 +9,11 @@ const fullStanzaXmlns = 'urn:ietf:params:xml:ns:xmpp-stanzas';
// RFC 6121 // RFC 6121
const rosterXmlns = 'jabber:iq:roster'; const rosterXmlns = 'jabber:iq:roster';
const rosterVersioningXmlns = 'urn:xmpp:features:rosterver'; const rosterVersioningXmlns = 'urn:xmpp:features:rosterver';
const subscriptionPreApprovalXmlns = 'urn:xmpp:features:pre-approval';
// XEP-0004 // XEP-0004
const dataFormsXmlns = 'jabber:x:data'; const dataFormsXmlns = 'jabber:x:data';
const formVarFormType = 'FORM_TYPE';
// XEP-0030 // XEP-0030
const discoInfoXmlns = 'http://jabber.org/protocol/disco#info'; const discoInfoXmlns = 'http://jabber.org/protocol/disco#info';
@@ -20,6 +22,11 @@ const discoItemsXmlns = 'http://jabber.org/protocol/disco#items';
// XEP-0033 // XEP-0033
const extendedAddressingXmlns = 'http://jabber.org/protocol/address'; const extendedAddressingXmlns = 'http://jabber.org/protocol/address';
// XEP-0045
const mucXmlns = 'http://jabber.org/protocol/muc';
const mucUserXmlns = 'http://jabber.org/protocol/muc#user';
const roomInfoFormType = 'http://jabber.org/protocol/muc#roominfo';
// XEP-0054 // XEP-0054
const vCardTempXmlns = 'vcard-temp'; const vCardTempXmlns = 'vcard-temp';
const vCardTempUpdate = 'vcard-temp:x:update'; const vCardTempUpdate = 'vcard-temp:x:update';
@@ -44,6 +51,9 @@ const userAvatarMetadataXmlns = 'urn:xmpp:avatar:metadata';
// XEP-0085 // XEP-0085
const chatStateXmlns = 'http://jabber.org/protocol/chatstates'; const chatStateXmlns = 'http://jabber.org/protocol/chatstates';
// XEP-0114
const componentAcceptXmlns = 'jabber:component:accept';
// XEP-0115 // XEP-0115
const capsXmlns = 'http://jabber.org/protocol/caps'; const capsXmlns = 'http://jabber.org/protocol/caps';
@@ -62,6 +72,9 @@ const delayedDeliveryXmlns = 'urn:xmpp:delay';
// XEP-0234 // XEP-0234
const jingleFileTransferXmlns = 'urn:xmpp:jingle:apps:file-transfer:5'; const jingleFileTransferXmlns = 'urn:xmpp:jingle:apps:file-transfer:5';
// XEP-0264
const jingleContentThumbnailXmlns = 'urn:xmpp:thumbs:1';
// XEP-0280 // XEP-0280
const carbonsXmlns = 'urn:xmpp:carbons:2'; const carbonsXmlns = 'urn:xmpp:carbons:2';
@@ -71,12 +84,6 @@ const forwardedXmlns = 'urn:xmpp:forward:0';
// XEP-0300 // XEP-0300
const hashXmlns = 'urn:xmpp:hashes:2'; const hashXmlns = 'urn:xmpp:hashes:2';
const hashFunctionNameBaseXmlns = 'urn:xmpp:hash-function-text-names'; const hashFunctionNameBaseXmlns = 'urn:xmpp:hash-function-text-names';
const hashSha256 = 'sha-256';
const hashSha512 = 'sha-512';
const hashSha3256 = 'sha3-256';
const hashSha3512 = 'sha3-512';
const hashBlake2b256 = 'blake2b-256';
const hashBlake2b512 = 'blake2b-512';
// XEP-0308 // XEP-0308
const lmcXmlns = 'urn:xmpp:message-correct:0'; const lmcXmlns = 'urn:xmpp:message-correct:0';
@@ -99,7 +106,7 @@ const httpFileUploadXmlns = 'urn:xmpp:http:upload:0';
// XEP-0372 // XEP-0372
const referenceXmlns = 'urn:xmpp:reference:0'; const referenceXmlns = 'urn:xmpp:reference:0';
// XEP-380 // XEP-0380
const emeXmlns = 'urn:xmpp:eme:0'; const emeXmlns = 'urn:xmpp:eme:0';
const emeOtr = 'urn:xmpp:otr:0'; const emeOtr = 'urn:xmpp:otr:0';
const emeLegacyOpenPGP = 'jabber:x:encrypted'; const emeLegacyOpenPGP = 'jabber:x:encrypted';
@@ -116,9 +123,18 @@ const omemoBundlesXmlns = 'urn:xmpp:omemo:2:bundles';
// XEP-0385 // XEP-0385
const simsXmlns = 'urn:xmpp:sims:1'; const simsXmlns = 'urn:xmpp:sims:1';
// XEP-0386
const bind2Xmlns = 'urn:xmpp:bind:0';
// XEP-0388
const sasl2Xmlns = 'urn:xmpp:sasl:2';
// XEP-0420 // XEP-0420
const sceXmlns = 'urn:xmpp:sce:1'; const sceXmlns = 'urn:xmpp:sce:1';
// XEP-0421
const occupantIdXmlns = 'urn:xmpp:occupant-id:0';
// XEP-0422 // XEP-0422
const fasteningXmlns = 'urn:xmpp:fasten:0'; const fasteningXmlns = 'urn:xmpp:fasten:0';
@@ -150,7 +166,9 @@ const stickersXmlns = 'urn:xmpp:stickers:0';
// XEP-0461 // XEP-0461
const replyXmlns = 'urn:xmpp:reply:0'; const replyXmlns = 'urn:xmpp:reply:0';
const fallbackXmlns = 'urn:xmpp:feature-fallback:0';
// ??? // ???
const urlDataXmlns = 'http://jabber.org/protocol/url-data'; const urlDataXmlns = 'http://jabber.org/protocol/url-data';
// XEP-XXXX
const fastXmlns = 'urn:xmpp:fast:0';

View File

@@ -7,3 +7,8 @@ const rosterNegotiator = 'im.moxxmpp.core.roster';
const resourceBindingNegotiator = 'im.moxxmpp.core.resource'; const resourceBindingNegotiator = 'im.moxxmpp.core.resource';
const streamManagementNegotiator = 'im.moxxmpp.xeps.sm'; const streamManagementNegotiator = 'im.moxxmpp.xeps.sm';
const startTlsNegotiator = 'im.moxxmpp.core.starttls'; const startTlsNegotiator = 'im.moxxmpp.core.starttls';
const sasl2Negotiator = 'org.moxxmpp.sasl.sasl2';
const bind2Negotiator = 'org.moxxmpp.bind2';
const saslFASTNegotiator = 'org.moxxmpp.sasl.fast';
const carbonsNegotiator = 'org.moxxmpp.bind2.carbons';
const presenceNegotiator = 'org.moxxmpp.core.presence';

View File

@@ -1,4 +1,7 @@
import 'package:collection/collection.dart';
import 'package:meta/meta.dart';
import 'package:moxlib/moxlib.dart'; import 'package:moxlib/moxlib.dart';
import 'package:moxxmpp/src/connection.dart';
import 'package:moxxmpp/src/errors.dart'; import 'package:moxxmpp/src/errors.dart';
import 'package:moxxmpp/src/events.dart'; import 'package:moxxmpp/src/events.dart';
import 'package:moxxmpp/src/jid.dart'; import 'package:moxxmpp/src/jid.dart';
@@ -6,7 +9,6 @@ import 'package:moxxmpp/src/managers/base.dart';
import 'package:moxxmpp/src/settings.dart'; import 'package:moxxmpp/src/settings.dart';
import 'package:moxxmpp/src/socket.dart'; import 'package:moxxmpp/src/socket.dart';
import 'package:moxxmpp/src/stringxml.dart'; import 'package:moxxmpp/src/stringxml.dart';
import 'package:moxxmpp/src/types/result.dart';
/// The state a negotiator is currently in /// The state a negotiator is currently in
enum NegotiatorState { enum NegotiatorState {
@@ -27,6 +29,7 @@ abstract class NegotiatorError extends XmppError {}
class NegotiatorAttributes { class NegotiatorAttributes {
const NegotiatorAttributes( const NegotiatorAttributes(
this.sendNonza, this.sendNonza,
this.getConnection,
this.getConnectionSettings, this.getConnectionSettings,
this.sendEvent, this.sendEvent,
this.getNegotiatorById, this.getNegotiatorById,
@@ -34,15 +37,21 @@ class NegotiatorAttributes {
this.getFullJID, this.getFullJID,
this.getSocket, this.getSocket,
this.isAuthenticated, this.isAuthenticated,
this.setAuthenticated,
this.setResource,
this.removeNegotiatingFeature,
); );
/// Sends the nonza nonza and optionally redacts it in logs if redact is not null. /// Sends the nonza nonza and optionally redacts it in logs if redact is not null.
final void Function(XMLNode nonza, {String? redact}) sendNonza; final void Function(XMLNode nonza) sendNonza;
/// Returns the connection settings. /// Returns the connection settings.
final ConnectionSettings Function() getConnectionSettings; final ConnectionSettings Function() getConnectionSettings;
/// Send an event event to the connection's event bus /// Returns the connection object.
final XmppConnection Function() getConnection;
/// Send an event event to the connection's event bus.
final Future<void> Function(XmppEvent event) sendEvent; final Future<void> Function(XmppEvent event) sendEvent;
/// Returns the negotiator with id id of the connection or null. /// Returns the negotiator with id id of the connection or null.
@@ -60,6 +69,17 @@ class NegotiatorAttributes {
/// Returns true if the stream is authenticated. Returns false if not. /// Returns true if the stream is authenticated. Returns false if not.
final bool Function() isAuthenticated; final bool Function() isAuthenticated;
/// Sets the resource of the connection. If triggerEvent is true, then a
/// [ResourceBoundEvent] is triggered.
final void Function(String, {bool triggerEvent}) setResource;
/// Sets the authentication state of the connection to true.
final void Function() setAuthenticated;
/// Remove a stream feature from our internal cache. This is useful for when you
/// negotiated a feature for another negotiator, like SASL2.
final void Function(String) removeNegotiatingFeature;
} }
abstract class XmppFeatureNegotiatorBase { abstract class XmppFeatureNegotiatorBase {
@@ -97,13 +117,15 @@ abstract class XmppFeatureNegotiatorBase {
/// Returns true if a feature in [features], which are the children of the /// Returns true if a feature in [features], which are the children of the
/// <stream:features /> nonza, can be negotiated. Otherwise, returns false. /// <stream:features /> nonza, can be negotiated. Otherwise, returns false.
bool matchesFeature(List<XMLNode> features) { bool matchesFeature(List<XMLNode> features) {
return firstWhereOrNull( return features.firstWhereOrNull(
features,
(XMLNode feature) => feature.attributes['xmlns'] == negotiatingXmlns, (XMLNode feature) => feature.attributes['xmlns'] == negotiatingXmlns,
) != ) !=
null; null;
} }
/// Called when an event is triggered in the [XmppConnection].
Future<void> onXmppEvent(XmppEvent event) async {}
/// Called with the currently received nonza [nonza] when the negotiator is active. /// Called with the currently received nonza [nonza] when the negotiator is active.
/// If the negotiator is just elected to be the next one, then [nonza] is equal to /// If the negotiator is just elected to be the next one, then [nonza] is equal to
/// the <stream:features /> nonza. /// the <stream:features /> nonza.
@@ -120,5 +142,10 @@ abstract class XmppFeatureNegotiatorBase {
state = NegotiatorState.ready; state = NegotiatorState.ready;
} }
@protected
NegotiatorAttributes get attributes => _attributes; NegotiatorAttributes get attributes => _attributes;
/// Run after all negotiators are registered. Useful for registering callbacks against
/// other negotiators. By default this function does nothing.
Future<void> postRegisterCallback() async {}
} }

View File

@@ -0,0 +1,169 @@
import 'dart:async';
import 'dart:convert';
import 'package:moxxmpp/src/stringxml.dart';
// ignore: implementation_imports
import 'package:xml/src/xml_events/utils/conversion_sink.dart';
import 'package:xml/xml.dart';
import 'package:xml/xml_events.dart';
/// A result object for XmlStreamBuffer.
abstract class XMPPStreamObject {}
/// A complete XML element returned by the stream buffer.
class XMPPStreamElement extends XMPPStreamObject {
XMPPStreamElement(this.node);
/// The actual [XMLNode].
final XMLNode node;
}
/// Just the stream header of a new XML stream.
class XMPPStreamHeader extends XMPPStreamObject {
XMPPStreamHeader(this.attributes);
/// The headers of the stream header.
final Map<String, String> attributes;
}
/// A wrapper around a [Converter]'s [Converter.startChunkedConversion] method.
class _ChunkedConversionBuffer<S, T> {
/// Use the converter [converter].
_ChunkedConversionBuffer(Converter<S, List<T>> converter) {
_outputSink = ConversionSink<List<T>>(_results.addAll);
_inputSink = converter.startChunkedConversion(_outputSink);
}
/// The results of the converter.
final List<T> _results = List<T>.empty(growable: true);
/// The sink that outputs to [_results].
late ConversionSink<List<T>> _outputSink;
/// The sink that we use for input.
late Sink<S> _inputSink;
/// Close all opened sinks.
void close() {
_inputSink.close();
_outputSink.close();
}
/// Turn the input [input] into a list of [T] according to the initial converter.
List<T> convert(S input) {
_results.clear();
_inputSink.add(input);
return _results;
}
}
/// A buffer to put between a socket's input and a full XML stream.
class XMPPStreamParser
extends StreamTransformerBase<String, List<XMPPStreamObject>> {
final StreamController<List<XMPPStreamObject>> _streamController =
StreamController<List<XMPPStreamObject>>();
/// Turns a String into a list of [XmlEvent]s in a chunked fashion.
_ChunkedConversionBuffer<String, XmlEvent> _eventBuffer =
_ChunkedConversionBuffer<String, XmlEvent>(XmlEventDecoder());
/// Turns a list of [XmlEvent]s into a list of [XmlNode]s in a chunked fashion.
_ChunkedConversionBuffer<List<XmlEvent>, XmlNode> _childBuffer =
_ChunkedConversionBuffer<List<XmlEvent>, XmlNode>(const XmlNodeDecoder());
/// The selectors.
_ChunkedConversionBuffer<List<XmlEvent>, XmlEvent> _childSelector =
_ChunkedConversionBuffer<List<XmlEvent>, XmlEvent>(
XmlSubtreeSelector((event) => event.qualifiedName != 'stream:stream'),
);
_ChunkedConversionBuffer<List<XmlEvent>, XmlEvent> _streamHeaderSelector =
_ChunkedConversionBuffer<List<XmlEvent>, XmlEvent>(
XmlSubtreeSelector((event) => event.qualifiedName == 'stream:stream'),
);
void reset() {
try {
_eventBuffer.close();
} catch (_) {
// Do nothing. A crash here may indicate that we end on invalid XML, which is fine
// since we're not going to use the buffer's output anymore.
}
try {
_childBuffer.close();
} catch (_) {
// Do nothing.
}
try {
_childSelector.close();
} catch (_) {
// Do nothing.
}
try {
_streamHeaderSelector.close();
} catch (_) {
// Do nothing.
}
// Recreate the buffers.
_eventBuffer =
_ChunkedConversionBuffer<String, XmlEvent>(XmlEventDecoder());
_childBuffer = _ChunkedConversionBuffer<List<XmlEvent>, XmlNode>(
const XmlNodeDecoder(),
);
_childSelector = _ChunkedConversionBuffer<List<XmlEvent>, XmlEvent>(
XmlSubtreeSelector((event) => event.qualifiedName != 'stream:stream'),
);
_streamHeaderSelector = _ChunkedConversionBuffer<List<XmlEvent>, XmlEvent>(
XmlSubtreeSelector((event) => event.qualifiedName == 'stream:stream'),
);
}
@override
Stream<List<XMPPStreamObject>> bind(Stream<String> stream) {
// We do not want to use xml's toXmlEvents and toSubtreeEvents methods as they
// create streams we cannot close. We need to be able to destroy and recreate an
// XML parser whenever we start a new connection.
stream.listen((input) {
final events = _eventBuffer.convert(input);
final streamHeaderEvents = _streamHeaderSelector.convert(events);
final objects = List<XMPPStreamObject>.empty(growable: true);
// Process the stream header separately.
for (final event in streamHeaderEvents) {
if (event is! XmlStartElementEvent) {
continue;
}
if (event.name != 'stream:stream') {
continue;
}
objects.add(
XMPPStreamHeader(
Map<String, String>.fromEntries(
event.attributes.map((attr) {
return MapEntry(attr.name, attr.value);
}),
),
),
);
}
// Process the children of the <stream:stream> element.
final childEvents = _childSelector.convert(events);
final children = _childBuffer.convert(childEvents);
for (final node in children) {
if (node.nodeType == XmlNodeType.ELEMENT) {
objects.add(
XMPPStreamElement(
XMLNode.fromXmlElement(node as XmlElement),
),
);
}
}
_streamController.add(objects);
});
return _streamController.stream;
}
}

View File

@@ -1,4 +1,5 @@
import 'package:moxxmpp/src/connection.dart'; import 'dart:async';
import 'package:moxlib/moxlib.dart';
import 'package:moxxmpp/src/events.dart'; import 'package:moxxmpp/src/events.dart';
import 'package:moxxmpp/src/jid.dart'; import 'package:moxxmpp/src/jid.dart';
import 'package:moxxmpp/src/managers/base.dart'; import 'package:moxxmpp/src/managers/base.dart';
@@ -6,14 +7,45 @@ import 'package:moxxmpp/src/managers/data.dart';
import 'package:moxxmpp/src/managers/handlers.dart'; import 'package:moxxmpp/src/managers/handlers.dart';
import 'package:moxxmpp/src/managers/namespaces.dart'; import 'package:moxxmpp/src/managers/namespaces.dart';
import 'package:moxxmpp/src/namespaces.dart'; import 'package:moxxmpp/src/namespaces.dart';
import 'package:moxxmpp/src/negotiators/namespaces.dart';
import 'package:moxxmpp/src/negotiators/negotiator.dart';
import 'package:moxxmpp/src/stanza.dart'; import 'package:moxxmpp/src/stanza.dart';
import 'package:moxxmpp/src/stringxml.dart'; import 'package:moxxmpp/src/stringxml.dart';
import 'package:moxxmpp/src/util/typed_map.dart';
import 'package:moxxmpp/src/xeps/xep_0198/types.dart';
/// A function that will be called when presence, outside of subscription request /// A function that will be called when presence, outside of subscription request
/// management, will be sent. Useful for managers that want to add [XMLNode]s to said /// management, will be sent. Useful for managers that want to add [XMLNode]s to said
/// presence. /// presence.
typedef PresencePreSendCallback = Future<List<XMLNode>> Function(); typedef PresencePreSendCallback = Future<List<XMLNode>> Function();
/// A pseudo-negotiator that does not really negotiate anything. Instead, its purpose
/// is to look for a stream feature indicating that we can pre-approve subscription
/// requests, shown by [PresenceNegotiator.preApprovalSupported].
class PresenceNegotiator extends XmppFeatureNegotiatorBase {
PresenceNegotiator()
: super(11, false, subscriptionPreApprovalXmlns, presenceNegotiator);
/// Flag indicating whether presence subscription pre-approval is supported
bool _supported = false;
bool get preApprovalSupported => _supported;
@override
Future<Result<NegotiatorState, NegotiatorError>> negotiate(
XMLNode nonza,
) async {
_supported = true;
return const Result(NegotiatorState.done);
}
@override
void reset() {
_supported = false;
super.reset();
}
}
/// A mandatory manager that handles initial presence sending, sending of subscription /// A mandatory manager that handles initial presence sending, sending of subscription
/// request management requests and triggers events for incoming presence stanzas. /// request management requests and triggers events for incoming presence stanzas.
class PresenceManager extends XmppManagerBase { class PresenceManager extends XmppManagerBase {
@@ -23,12 +55,18 @@ class PresenceManager extends XmppManagerBase {
final List<PresencePreSendCallback> _presenceCallbacks = final List<PresencePreSendCallback> _presenceCallbacks =
List.empty(growable: true); List.empty(growable: true);
/// The priority of the presence handler. If a handler should run before this one,
/// which terminates processing, make sure the handler has a priority greater than
/// [presenceHandlerPriority].
static int presenceHandlerPriority = -100;
@override @override
List<StanzaHandler> getIncomingStanzaHandlers() => [ List<StanzaHandler> getIncomingStanzaHandlers() => [
StanzaHandler( StanzaHandler(
stanzaTag: 'presence', stanzaTag: 'presence',
callback: _onPresence, callback: _onPresence,
) priority: presenceHandlerPriority,
),
]; ];
@override @override
@@ -42,6 +80,16 @@ class PresenceManager extends XmppManagerBase {
_presenceCallbacks.add(callback); _presenceCallbacks.add(callback);
} }
@override
Future<void> onXmppEvent(XmppEvent event) async {
if (event is StreamNegotiationsDoneEvent) {
// Send initial presence only when we have not resumed the stream
if (!event.resumed) {
await sendInitialPresence();
}
}
}
Future<StanzaHandlerData> _onPresence( Future<StanzaHandlerData> _onPresence(
Stanza presence, Stanza presence,
StanzaHandlerData state, StanzaHandlerData state,
@@ -56,7 +104,7 @@ class PresenceManager extends XmppManagerBase {
from: JID.fromString(presence.from!), from: JID.fromString(presence.from!),
), ),
); );
return state.copyWith(done: true); return state..done = true;
} }
default: default:
break; break;
@@ -65,10 +113,7 @@ class PresenceManager extends XmppManagerBase {
if (presence.from != null) { if (presence.from != null) {
logger.finest("Received presence from '${presence.from}'"); logger.finest("Received presence from '${presence.from}'");
getAttributes().sendEvent( return state..done = true;
PresenceReceivedEvent(JID.fromString(presence.from!), presence),
);
return state.copyWith(done: true);
} }
return state; return state;
@@ -90,65 +135,112 @@ class PresenceManager extends XmppManagerBase {
} }
final attrs = getAttributes(); final attrs = getAttributes();
attrs.sendNonza( await attrs.sendStanza(
Stanza.presence( StanzaDetails(
from: attrs.getFullJID().toString(), Stanza.presence(
children: children, children: children,
),
awaitable: false,
addId: false,
), ),
); );
} }
/// Send an unavailable presence with no 'to' attribute. /// Send an unavailable presence with no 'to' attribute.
void sendUnavailablePresence() { Future<void> sendUnavailablePresence() async {
getAttributes().sendStanza( // Bypass the queue so that this get's sent immediately.
Stanza.presence( // If we do it like this, we can also block the disconnection
type: 'unavailable', // until we're actually ready.
await getAttributes().sendStanza(
StanzaDetails(
Stanza.presence(
type: 'unavailable',
),
awaitable: false,
bypassQueue: true,
postSendExtensions: TypedMap<StanzaHandlerExtension>.fromList([
const StreamManagementData(true, null),
]),
), ),
addFrom: StanzaFromType.full,
); );
} }
/// Sends a subscription request to [to]. /// Similar to [requestSubscription], but it also tells the server to automatically
void sendSubscriptionRequest(String to) { /// accept a subscription request from [to], should it arrive.
getAttributes().sendStanza( /// This requires a [PresenceNegotiator] to be registered as this feature is optional.
Stanza.presence( ///
type: 'subscribe', /// Returns true, when the stanza was sent. Returns false, when the stanza was not sent,
to: to, /// for example because the server does not support subscription pre-approvals.
Future<bool> preApproveSubscription(JID to) async {
final negotiator = getAttributes()
.getNegotiatorById<PresenceNegotiator>(presenceNegotiator);
assert(negotiator != null, 'No PresenceNegotiator registered');
if (!negotiator!.preApprovalSupported) {
return false;
}
await getAttributes().sendStanza(
StanzaDetails(
Stanza.presence(
type: 'subscribed',
to: to.toString(),
),
awaitable: false,
),
);
return true;
}
/// Sends a subscription request to [to].
Future<void> requestSubscription(JID to) async {
await getAttributes().sendStanza(
StanzaDetails(
Stanza.presence(
type: 'subscribe',
to: to.toString(),
),
awaitable: false,
),
);
}
/// Accept a subscription request from [to].
Future<void> acceptSubscriptionRequest(JID to) async {
await getAttributes().sendStanza(
StanzaDetails(
Stanza.presence(
type: 'subscribed',
to: to.toString(),
),
awaitable: false,
),
);
}
/// Send a subscription request rejection to [to].
Future<void> rejectSubscriptionRequest(JID to) async {
await getAttributes().sendStanza(
StanzaDetails(
Stanza.presence(
type: 'unsubscribed',
to: to.toString(),
),
awaitable: false,
), ),
addFrom: StanzaFromType.none,
); );
} }
/// Sends an unsubscription request to [to]. /// Sends an unsubscription request to [to].
void sendUnsubscriptionRequest(String to) { Future<void> unsubscribe(JID to) async {
getAttributes().sendStanza( await getAttributes().sendStanza(
Stanza.presence( StanzaDetails(
type: 'unsubscribe', Stanza.presence(
to: to, type: 'unsubscribe',
to: to.toString(),
),
awaitable: false,
), ),
addFrom: StanzaFromType.none,
);
}
/// Accept a presence subscription request for [to].
void sendSubscriptionRequestApproval(String to) {
getAttributes().sendStanza(
Stanza.presence(
type: 'subscribed',
to: to,
),
addFrom: StanzaFromType.none,
);
}
/// Reject a presence subscription request for [to].
void sendSubscriptionRequestRejection(String to) {
getAttributes().sendStanza(
Stanza.presence(
type: 'unsubscribed',
to: to,
),
addFrom: StanzaFromType.none,
); );
} }
} }

View File

@@ -2,7 +2,6 @@ import 'dart:async';
import 'dart:math'; import 'dart:math';
import 'package:logging/logging.dart'; import 'package:logging/logging.dart';
import 'package:meta/meta.dart'; import 'package:meta/meta.dart';
import 'package:moxxmpp/src/util/queue.dart';
import 'package:synchronized/synchronized.dart'; import 'package:synchronized/synchronized.dart';
/// A callback function to be called when the connection to the server has been lost. /// A callback function to be called when the connection to the server has been lost.
@@ -17,40 +16,54 @@ abstract class ReconnectionPolicy {
/// to perform a reconnection. /// to perform a reconnection.
PerformReconnectFunction? performReconnect; PerformReconnectFunction? performReconnect;
/// Function provided by XmppConnection that allows the policy final Lock _lock = Lock();
/// to say that we lost the connection.
ConnectionLostCallback? triggerConnectionLost; /// Indicate if a reconnection attempt is currently running.
bool _isReconnecting = false;
/// Indicate if should try to reconnect. /// Indicate if should try to reconnect.
bool _shouldAttemptReconnection = false; bool _shouldAttemptReconnection = false;
/// Indicate if a reconnection attempt is currently running.
@protected @protected
bool isReconnecting = false; Future<bool> canTryReconnecting() async =>
_lock.synchronized(() => !_isReconnecting);
/// And the corresponding lock
@protected @protected
final Lock lock = Lock(); Future<bool> getIsReconnecting() async =>
_lock.synchronized(() => _isReconnecting);
/// The lock for accessing [_shouldAttemptReconnection] Future<void> _resetIsReconnecting() async {
@protected await _lock.synchronized(() {
final Lock shouldReconnectLock = Lock(); _isReconnecting = false;
});
}
/// Called by XmppConnection to register the policy. /// Called by XmppConnection to register the policy.
void register( void register(
PerformReconnectFunction performReconnect, PerformReconnectFunction performReconnect,
ConnectionLostCallback triggerConnectionLost,
) { ) {
this.performReconnect = performReconnect; this.performReconnect = performReconnect;
this.triggerConnectionLost = triggerConnectionLost;
unawaited(reset());
} }
/// In case the policy depends on some internal state, this state must be reset /// In case the policy depends on some internal state, this state must be reset
/// to an initial state when reset is called. In case timers run, they must be /// to an initial state when reset is called. In case timers run, they must be
/// terminated. /// terminated.
Future<void> reset(); @mustCallSuper
Future<void> reset() async {
await _resetIsReconnecting();
}
@mustCallSuper
Future<bool> canTriggerFailure() async {
return _lock.synchronized(() {
if (_shouldAttemptReconnection && !_isReconnecting) {
_isReconnecting = true;
return true;
}
return false;
});
}
/// Called by the XmppConnection when the reconnection failed. /// Called by the XmppConnection when the reconnection failed.
Future<void> onFailure() async {} Future<void> onFailure() async {}
@@ -59,27 +72,12 @@ abstract class ReconnectionPolicy {
Future<void> onSuccess(); Future<void> onSuccess();
Future<bool> getShouldReconnect() async { Future<bool> getShouldReconnect() async {
return shouldReconnectLock.synchronized(() => _shouldAttemptReconnection); return _lock.synchronized(() => _shouldAttemptReconnection);
} }
/// Set whether a reconnection attempt should be made. /// Set whether a reconnection attempt should be made.
Future<void> setShouldReconnect(bool value) async { Future<void> setShouldReconnect(bool value) async {
return shouldReconnectLock return _lock.synchronized(() => _shouldAttemptReconnection = value);
.synchronized(() => _shouldAttemptReconnection = value);
}
/// Returns true if the manager is currently triggering a reconnection. If not, returns
/// false.
Future<bool> isReconnectionRunning() async {
return lock.synchronized(() => isReconnecting);
}
/// Set the isReconnecting state to [value].
@protected
Future<void> setIsReconnecting(bool value) async {
await lock.synchronized(() async {
isReconnecting = value;
});
} }
} }
@@ -105,90 +103,77 @@ class RandomBackoffReconnectionPolicy extends ReconnectionPolicy {
/// Backoff timer. /// Backoff timer.
Timer? _timer; Timer? _timer;
final Lock _timerLock = Lock();
/// Logger. /// Logger.
final Logger _log = Logger('RandomBackoffReconnectionPolicy'); final Logger _log = Logger('RandomBackoffReconnectionPolicy');
/// Event queue final Lock _timerLock = Lock();
final AsyncQueue _eventQueue = AsyncQueue();
/// Called when the backoff expired /// Called when the backoff expired
Future<void> _onTimerElapsed() async { @visibleForTesting
_log.fine('Timer elapsed. Waiting for lock'); Future<void> onTimerElapsed() async {
await lock.synchronized(() async { _log.finest('Timer elapsed. Waiting for lock...');
_log.fine('Lock aquired'); final shouldContinue = await _timerLock.synchronized(() async {
_log.finest('Timer lock aquired');
if (_timer == null) {
_log.finest(
'The timer is already set to null. Doing nothing.',
);
return false;
}
if (!(await getIsReconnecting())) {
return false;
}
if (!(await getShouldReconnect())) { if (!(await getShouldReconnect())) {
_log.fine( _log.finest(
'Backoff timer expired but getShouldReconnect() returned false', 'Should not reconnect. Stopping here.',
); );
return; return false;
} }
if (isReconnecting) {
_log.fine(
'Backoff timer expired but a reconnection is running, so doing nothing.',
);
return;
}
_log.fine('Triggering reconnect');
isReconnecting = true;
await performReconnect!();
});
await _timerLock.synchronized(() {
_timer?.cancel();
_timer = null;
});
}
Future<void> _reset() async {
_log.finest('Resetting internal state');
await _timerLock.synchronized(() {
_timer?.cancel(); _timer?.cancel();
_timer = null; _timer = null;
return true;
}); });
await setIsReconnecting(false); if (!shouldContinue) {
return;
}
_log.fine('Triggering reconnect');
await performReconnect!();
} }
@override @override
Future<void> reset() async { Future<void> reset() async {
// ignore: unnecessary_lambdas _log.finest('Resetting internal state');
await _eventQueue.addJob(() => _reset()); await _timerLock.synchronized(() {
} _timer?.cancel();
_timer = null;
Future<void> _onFailure() async {
final shouldContinue = await _timerLock.synchronized(() {
return _timer == null;
}); });
if (!shouldContinue) { await super.reset();
_log.finest(
'_onFailure: Not backing off since _timer is already running',
);
return;
}
final seconds =
Random().nextInt(_maxBackoffTime - _minBackoffTime) + _minBackoffTime;
_log.finest('Failure occured. Starting random backoff with ${seconds}s');
_timer?.cancel();
_timer = Timer(Duration(seconds: seconds), _onTimerElapsed);
} }
@override @override
Future<void> onFailure() async { Future<void> onFailure() async {
// ignore: unnecessary_lambdas final seconds =
await _eventQueue.addJob(() => _onFailure()); Random().nextInt(_maxBackoffTime - _minBackoffTime) + _minBackoffTime;
_log.finest('Failure occured. Starting random backoff with ${seconds}s');
await _timerLock.synchronized(() {
_timer?.cancel();
_timer = Timer(Duration(seconds: seconds), onTimerElapsed);
});
} }
@override @override
Future<void> onSuccess() async { Future<void> onSuccess() async {
await reset(); await reset();
} }
@visibleForTesting
bool isTimerRunning() => _timer != null;
} }
/// A stub reconnection policy for tests. /// A stub reconnection policy for tests.
@@ -203,7 +188,9 @@ class TestingReconnectionPolicy extends ReconnectionPolicy {
Future<void> onFailure() async {} Future<void> onFailure() async {}
@override @override
Future<void> reset() async {} Future<void> reset() async {
await super.reset();
}
} }
/// A reconnection policy for tests that waits a constant number of seconds before /// A reconnection policy for tests that waits a constant number of seconds before
@@ -223,5 +210,7 @@ class TestingSleepReconnectionPolicy extends ReconnectionPolicy {
} }
@override @override
Future<void> reset() async {} Future<void> reset() async {
await super.reset();
}
} }

View File

@@ -1,10 +1,10 @@
import 'package:moxxmpp/src/events.dart'; import 'package:moxlib/moxlib.dart';
import 'package:moxxmpp/src/jid.dart';
import 'package:moxxmpp/src/managers/namespaces.dart'; import 'package:moxxmpp/src/managers/namespaces.dart';
import 'package:moxxmpp/src/namespaces.dart'; import 'package:moxxmpp/src/namespaces.dart';
import 'package:moxxmpp/src/negotiators/namespaces.dart'; import 'package:moxxmpp/src/negotiators/namespaces.dart';
import 'package:moxxmpp/src/negotiators/negotiator.dart'; import 'package:moxxmpp/src/negotiators/negotiator.dart';
import 'package:moxxmpp/src/stringxml.dart'; import 'package:moxxmpp/src/stringxml.dart';
import 'package:moxxmpp/src/types/result.dart';
import 'package:moxxmpp/src/xeps/xep_0198/xep_0198.dart'; import 'package:moxxmpp/src/xeps/xep_0198/xep_0198.dart';
import 'package:uuid/uuid.dart'; import 'package:uuid/uuid.dart';
@@ -30,10 +30,13 @@ class ResourceBindingNegotiator extends XmppFeatureNegotiatorBase {
if (sm != null) { if (sm != null) {
return super.matchesFeature(features) && return super.matchesFeature(features) &&
!sm.streamResumed && !sm.streamResumed &&
attributes.isAuthenticated(); attributes.isAuthenticated() &&
attributes.getConnection().resource.isEmpty;
} }
return super.matchesFeature(features) && attributes.isAuthenticated(); return super.matchesFeature(features) &&
attributes.isAuthenticated() &&
attributes.getConnection().resource.isEmpty;
} }
@override @override
@@ -65,11 +68,9 @@ class ResourceBindingNegotiator extends XmppFeatureNegotiatorBase {
} }
final bind = nonza.firstTag('bind')!; final bind = nonza.firstTag('bind')!;
final jid = bind.firstTag('jid')!; final rawJid = bind.firstTag('jid')!.innerText();
final resource = jid.innerText().split('/')[1]; final resource = JID.fromString(rawJid).resource;
attributes.setResource(resource);
await attributes
.sendEvent(ResourceBindingSuccessEvent(resource: resource));
return const Result(NegotiatorState.done); return const Result(NegotiatorState.done);
} }
} }

View File

@@ -1,4 +1,4 @@
import 'package:moxlib/moxlib.dart'; import 'package:collection/collection.dart';
import 'package:moxxmpp/src/namespaces.dart'; import 'package:moxxmpp/src/namespaces.dart';
import 'package:moxxmpp/src/negotiators/negotiator.dart'; import 'package:moxxmpp/src/negotiators/negotiator.dart';
import 'package:moxxmpp/src/stringxml.dart'; import 'package:moxxmpp/src/stringxml.dart';
@@ -13,15 +13,13 @@ abstract class SaslNegotiator extends XmppFeatureNegotiatorBase {
@override @override
bool matchesFeature(List<XMLNode> features) { bool matchesFeature(List<XMLNode> features) {
// Is SASL advertised? // Is SASL advertised?
final mechanisms = firstWhereOrNull( final mechanisms = features.firstWhereOrNull(
features,
(XMLNode feature) => feature.attributes['xmlns'] == saslXmlns, (XMLNode feature) => feature.attributes['xmlns'] == saslXmlns,
); );
if (mechanisms == null) return false; if (mechanisms == null) return false;
// Is SASL PLAIN advertised? // Is SASL PLAIN advertised?
return firstWhereOrNull( return mechanisms.children.firstWhereOrNull(
mechanisms.children,
(XMLNode mechanism) => mechanism.text == mechanismName, (XMLNode mechanism) => mechanism.text == mechanismName,
) != ) !=
null; null;

View File

@@ -1,23 +1,25 @@
import 'dart:convert'; import 'dart:convert';
import 'package:logging/logging.dart'; import 'package:logging/logging.dart';
import 'package:moxlib/moxlib.dart';
import 'package:moxxmpp/src/events.dart'; import 'package:moxxmpp/src/events.dart';
import 'package:moxxmpp/src/negotiators/namespaces.dart'; import 'package:moxxmpp/src/negotiators/namespaces.dart';
import 'package:moxxmpp/src/negotiators/negotiator.dart'; import 'package:moxxmpp/src/negotiators/negotiator.dart';
import 'package:moxxmpp/src/negotiators/sasl/errors.dart'; import 'package:moxxmpp/src/rfcs/rfc_6120/sasl/errors.dart';
import 'package:moxxmpp/src/negotiators/sasl/negotiator.dart'; import 'package:moxxmpp/src/rfcs/rfc_6120/sasl/nonza.dart';
import 'package:moxxmpp/src/negotiators/sasl/nonza.dart';
import 'package:moxxmpp/src/stringxml.dart'; import 'package:moxxmpp/src/stringxml.dart';
import 'package:moxxmpp/src/types/result.dart'; import 'package:moxxmpp/src/xeps/xep_0388/negotiators.dart';
import 'package:moxxmpp/src/xeps/xep_0388/xep_0388.dart';
import 'package:saslprep/saslprep.dart';
class SaslPlainAuthNonza extends SaslAuthNonza { class SaslPlainAuthNonza extends SaslAuthNonza {
SaslPlainAuthNonza(String username, String password) SaslPlainAuthNonza(String data)
: super( : super(
'PLAIN', 'PLAIN',
base64.encode(utf8.encode('\u0000$username\u0000$password')), data,
); );
} }
class SaslPlainNegotiator extends SaslNegotiator { class SaslPlainNegotiator extends Sasl2AuthenticationNegotiator {
SaslPlainNegotiator() SaslPlainNegotiator()
: _authSent = false, : _authSent = false,
_log = Logger('SaslPlainNegotiator'), _log = Logger('SaslPlainNegotiator'),
@@ -47,17 +49,16 @@ class SaslPlainNegotiator extends SaslNegotiator {
XMLNode nonza, XMLNode nonza,
) async { ) async {
if (!_authSent) { if (!_authSent) {
final settings = attributes.getConnectionSettings(); final data = await getRawStep('');
attributes.sendNonza( attributes.sendNonza(
SaslPlainAuthNonza(settings.jid.local, settings.password), SaslPlainAuthNonza(data),
redact: SaslPlainAuthNonza('******', '******').toXml(),
); );
_authSent = true; _authSent = true;
return const Result(NegotiatorState.ready); return const Result(NegotiatorState.ready);
} else { } else {
final tag = nonza.tag; final tag = nonza.tag;
if (tag == 'success') { if (tag == 'success') {
await attributes.sendEvent(AuthenticationSuccessEvent()); attributes.setAuthenticated();
return const Result(NegotiatorState.done); return const Result(NegotiatorState.done);
} else { } else {
// We assume it's a <failure/> // We assume it's a <failure/>
@@ -76,4 +77,36 @@ class SaslPlainNegotiator extends SaslNegotiator {
super.reset(); super.reset();
} }
@override
Future<void> postRegisterCallback() async {
attributes
.getNegotiatorById<Sasl2Negotiator>(sasl2Negotiator)
?.registerSaslNegotiator(this);
}
@override
Future<String> getRawStep(String input) async {
final settings = attributes.getConnectionSettings();
final prep = Saslprep.saslprep(settings.password);
return base64.encode(
utf8.encode('\u0000${settings.jid.local}\u0000$prep'),
);
}
@override
Future<Result<bool, NegotiatorError>> onSasl2Success(XMLNode response) async {
if (pickedForSasl2) {
state = NegotiatorState.done;
}
return const Result(true);
}
@override
Future<void> onSasl2Failure(XMLNode response) async {}
@override
Future<List<XMLNode>> onSasl2FeaturesReceived(XMLNode sasl2Features) async {
return [];
}
} }

View File

@@ -2,19 +2,32 @@ import 'dart:convert';
import 'dart:math' show Random; import 'dart:math' show Random;
import 'package:cryptography/cryptography.dart'; import 'package:cryptography/cryptography.dart';
import 'package:logging/logging.dart'; import 'package:logging/logging.dart';
import 'package:moxlib/moxlib.dart';
import 'package:moxxmpp/src/events.dart'; import 'package:moxxmpp/src/events.dart';
import 'package:moxxmpp/src/namespaces.dart'; import 'package:moxxmpp/src/namespaces.dart';
import 'package:moxxmpp/src/negotiators/namespaces.dart'; import 'package:moxxmpp/src/negotiators/namespaces.dart';
import 'package:moxxmpp/src/negotiators/negotiator.dart'; import 'package:moxxmpp/src/negotiators/negotiator.dart';
import 'package:moxxmpp/src/negotiators/sasl/errors.dart'; import 'package:moxxmpp/src/rfcs/rfc_6120/sasl/errors.dart';
import 'package:moxxmpp/src/negotiators/sasl/kv.dart'; import 'package:moxxmpp/src/rfcs/rfc_6120/sasl/kv.dart';
import 'package:moxxmpp/src/negotiators/sasl/negotiator.dart'; import 'package:moxxmpp/src/rfcs/rfc_6120/sasl/nonza.dart';
import 'package:moxxmpp/src/negotiators/sasl/nonza.dart';
import 'package:moxxmpp/src/stringxml.dart'; import 'package:moxxmpp/src/stringxml.dart';
import 'package:moxxmpp/src/types/result.dart'; import 'package:moxxmpp/src/xeps/xep_0388/negotiators.dart';
import 'package:moxxmpp/src/xeps/xep_0388/xep_0388.dart';
import 'package:random_string/random_string.dart'; import 'package:random_string/random_string.dart';
import 'package:saslprep/saslprep.dart'; import 'package:saslprep/saslprep.dart';
abstract class SaslScramError extends NegotiatorError {}
class NoAdditionalDataError extends SaslScramError {
@override
bool isRecoverable() => false;
}
class InvalidServerSignatureError extends SaslScramError {
@override
bool isRecoverable() => false;
}
// NOTE: Inspired by https://github.com/vukoye/xmpp_dart/blob/3b1a0588562b9e591488c99d834088391840911d/lib/src/features/sasl/ScramSaslHandler.dart // NOTE: Inspired by https://github.com/vukoye/xmpp_dart/blob/3b1a0588562b9e591488c99d834088391840911d/lib/src/features/sasl/ScramSaslHandler.dart
enum ScramHashType { sha1, sha256, sha512 } enum ScramHashType { sha1, sha256, sha512 }
@@ -95,7 +108,7 @@ enum ScramState { preSent, initialMessageSent, challengeResponseSent, error }
const gs2Header = 'n,,'; const gs2Header = 'n,,';
class SaslScramNegotiator extends SaslNegotiator { class SaslScramNegotiator extends Sasl2AuthenticationNegotiator {
// NOTE: NEVER, and I mean, NEVER set clientNonce or initalMessageNoGS2. They are just there for testing // NOTE: NEVER, and I mean, NEVER set clientNonce or initalMessageNoGS2. They are just there for testing
SaslScramNegotiator( SaslScramNegotiator(
int priority, int priority,
@@ -230,29 +243,26 @@ class SaslScramNegotiator extends SaslNegotiator {
return false; return false;
} }
bool _checkSignature(String base64Signature) {
final signature =
parseKeyValue(utf8.decode(base64.decode(base64Signature)));
_log.finest(
'Expecting signature: "$_serverSignature", got: "${signature["v"]}"',
);
return signature['v']! == _serverSignature;
}
@override @override
Future<Result<NegotiatorState, NegotiatorError>> negotiate( Future<Result<NegotiatorState, NegotiatorError>> negotiate(
XMLNode nonza, XMLNode nonza,
) async { ) async {
switch (_scramState) { switch (_scramState) {
case ScramState.preSent: case ScramState.preSent:
if (clientNonce == null || clientNonce == '') {
clientNonce = randomAlphaNumeric(
40,
provider: CoreRandomProvider.from(Random.secure()),
);
}
initialMessageNoGS2 =
'n=${attributes.getConnectionSettings().jid.local},r=$clientNonce';
_scramState = ScramState.initialMessageSent;
attributes.sendNonza( attributes.sendNonza(
SaslScramAuthNonza( SaslScramAuthNonza(
body: base64.encode(utf8.encode(gs2Header + initialMessageNoGS2)), body: await getRawStep(''),
type: hashType, type: hashType,
), ),
redact: SaslScramAuthNonza(body: '******', type: hashType).toXml(),
); );
return const Result(NegotiatorState.ready); return const Result(NegotiatorState.ready);
case ScramState.initialMessageSent: case ScramState.initialMessageSent:
@@ -266,13 +276,8 @@ class SaslScramNegotiator extends SaslNegotiator {
); );
} }
final challengeBase64 = nonza.innerText();
final response = await calculateChallengeResponse(challengeBase64);
final responseBase64 = base64.encode(utf8.encode(response));
_scramState = ScramState.challengeResponseSent;
attributes.sendNonza( attributes.sendNonza(
SaslScramResponseNonza(body: responseBase64), SaslScramResponseNonza(body: await getRawStep(nonza.innerText())),
redact: SaslScramResponseNonza(body: '******').toXml(),
); );
return const Result(NegotiatorState.ready); return const Result(NegotiatorState.ready);
case ScramState.challengeResponseSent: case ScramState.challengeResponseSent:
@@ -286,10 +291,7 @@ class SaslScramNegotiator extends SaslNegotiator {
); );
} }
// NOTE: This assumes that the string is always "v=..." and contains no other parameters if (!_checkSignature(nonza.innerText())) {
final signature =
parseKeyValue(utf8.decode(base64.decode(nonza.innerText())));
if (signature['v']! != _serverSignature) {
// TODO(Unknown): Notify of a signature mismatch // TODO(Unknown): Notify of a signature mismatch
//final error = nonza.children.first.tag; //final error = nonza.children.first.tag;
//attributes.sendEvent(AuthenticationFailedEvent(error)); //attributes.sendEvent(AuthenticationFailedEvent(error));
@@ -299,7 +301,7 @@ class SaslScramNegotiator extends SaslNegotiator {
); );
} }
await attributes.sendEvent(AuthenticationSuccessEvent()); attributes.setAuthenticated();
return const Result(NegotiatorState.done); return const Result(NegotiatorState.done);
case ScramState.error: case ScramState.error:
return Result( return Result(
@@ -314,4 +316,70 @@ class SaslScramNegotiator extends SaslNegotiator {
super.reset(); super.reset();
} }
@override
Future<String> getRawStep(String input) async {
switch (_scramState) {
case ScramState.preSent:
if (clientNonce == null || clientNonce == '') {
clientNonce = randomAlphaNumeric(
40,
provider: CoreRandomProvider.from(Random.secure()),
);
}
initialMessageNoGS2 =
'n=${attributes.getConnectionSettings().jid.local},r=$clientNonce';
_scramState = ScramState.initialMessageSent;
return base64.encode(utf8.encode(gs2Header + initialMessageNoGS2));
case ScramState.initialMessageSent:
final challengeBase64 = input;
final response = await calculateChallengeResponse(challengeBase64);
final responseBase64 = base64.encode(utf8.encode(response));
_scramState = ScramState.challengeResponseSent;
return responseBase64;
case ScramState.challengeResponseSent:
case ScramState.error:
return '';
}
}
@override
Future<void> postRegisterCallback() async {
attributes
.getNegotiatorById<Sasl2Negotiator>(sasl2Negotiator)
?.registerSaslNegotiator(this);
}
@override
Future<List<XMLNode>> onSasl2FeaturesReceived(XMLNode sasl2Features) async {
return [];
}
@override
Future<void> onSasl2Failure(XMLNode response) async {}
@override
Future<Result<bool, NegotiatorError>> onSasl2Success(XMLNode response) async {
// Don't do anything if we have not been picked for SASL2.
if (!pickedForSasl2) {
return const Result(true);
}
// When we're done with SASL2, check the additional data to verify the server
// signature.
state = NegotiatorState.done;
final additionalData = response.firstTag('additional-data');
if (additionalData == null) {
return Result(NoAdditionalDataError());
}
if (!_checkSignature(additionalData.innerText())) {
return Result(InvalidServerSignatureError());
}
return const Result(true);
}
} }

View File

@@ -1,9 +1,9 @@
import 'package:logging/logging.dart'; import 'package:logging/logging.dart';
import 'package:moxlib/moxlib.dart';
import 'package:moxxmpp/src/namespaces.dart'; import 'package:moxxmpp/src/namespaces.dart';
import 'package:moxxmpp/src/negotiators/namespaces.dart'; import 'package:moxxmpp/src/negotiators/namespaces.dart';
import 'package:moxxmpp/src/negotiators/negotiator.dart'; import 'package:moxxmpp/src/negotiators/negotiator.dart';
import 'package:moxxmpp/src/stringxml.dart'; import 'package:moxxmpp/src/stringxml.dart';
import 'package:moxxmpp/src/types/result.dart';
enum _StartTlsState { ready, requested } enum _StartTlsState { ready, requested }

View File

@@ -1,6 +1,7 @@
import 'dart:async'; import 'dart:async';
import 'package:collection/collection.dart'; import 'package:collection/collection.dart';
import 'package:meta/meta.dart'; import 'package:meta/meta.dart';
import 'package:moxlib/moxlib.dart';
import 'package:moxxmpp/src/jid.dart'; import 'package:moxxmpp/src/jid.dart';
import 'package:moxxmpp/src/managers/attributes.dart'; import 'package:moxxmpp/src/managers/attributes.dart';
import 'package:moxxmpp/src/managers/base.dart'; import 'package:moxxmpp/src/managers/base.dart';
@@ -14,7 +15,6 @@ import 'package:moxxmpp/src/roster/errors.dart';
import 'package:moxxmpp/src/roster/state.dart'; import 'package:moxxmpp/src/roster/state.dart';
import 'package:moxxmpp/src/stanza.dart'; import 'package:moxxmpp/src/stanza.dart';
import 'package:moxxmpp/src/stringxml.dart'; import 'package:moxxmpp/src/stringxml.dart';
import 'package:moxxmpp/src/types/result.dart';
@immutable @immutable
class XmppRosterItem { class XmppRosterItem {
@@ -122,7 +122,7 @@ class RosterManager extends XmppManagerBase {
tagName: 'query', tagName: 'query',
tagXmlns: rosterXmlns, tagXmlns: rosterXmlns,
callback: _onRosterPush, callback: _onRosterPush,
) ),
]; ];
@override @override
@@ -145,7 +145,7 @@ class RosterManager extends XmppManagerBase {
logger.warning( logger.warning(
'Roster push invalid! Unexpected from attribute: ${stanza.toXml()}', 'Roster push invalid! Unexpected from attribute: ${stanza.toXml()}',
); );
return state.copyWith(done: true); return state..done = true;
} }
final query = stanza.firstTag('query', xmlns: rosterXmlns)!; final query = stanza.firstTag('query', xmlns: rosterXmlns)!;
@@ -154,7 +154,7 @@ class RosterManager extends XmppManagerBase {
if (item == null) { if (item == null) {
logger.warning('Received empty roster push'); logger.warning('Received empty roster push');
return state.copyWith(done: true); return state..done = true;
} }
unawaited( unawaited(
@@ -177,13 +177,23 @@ class RosterManager extends XmppManagerBase {
[], [],
); );
return state.copyWith(done: true); return state..done = true;
} }
/// Shared code between requesting rosters without and with roster versioning, if /// Shared code between requesting rosters without and with roster versioning, if
/// the server deems a regular roster response more efficient than n roster pushes. /// the server deems a regular roster response more efficient than n roster pushes.
///
/// [query] is the <query /> child of the iq, if available.
///
/// If roster versioning was used, then [requestedRosterVersion] is the version
/// we requested the roster with.
///
/// Note that if roster versioning is used and the server returns us an empty iq,
/// it means that the roster did not change since the last version. In that case,
/// we do nothing and just return. The roster state manager will not be notified.
Future<Result<RosterRequestResult, RosterError>> _handleRosterResponse( Future<Result<RosterRequestResult, RosterError>> _handleRosterResponse(
XMLNode? query, XMLNode? query,
String? requestedRosterVersion,
) async { ) async {
final List<XmppRosterItem> items; final List<XmppRosterItem> items;
String? rosterVersion; String? rosterVersion;
@@ -204,6 +214,14 @@ class RosterManager extends XmppManagerBase {
.toList(); .toList();
rosterVersion = query.attributes['ver'] as String?; rosterVersion = query.attributes['ver'] as String?;
} else if (requestedRosterVersion != null) {
// Skip the handleRosterFetch call since nothing changed.
return Result(
RosterRequestResult(
[],
requestedRosterVersion,
),
);
} else { } else {
logger.warning( logger.warning(
'Server response to roster request without roster versioning does not contain a <query /> element, while the type is not error. This violates RFC6121', 'Server response to roster request without roster versioning does not contain a <query /> element, while the type is not error. This violates RFC6121',
@@ -223,26 +241,34 @@ class RosterManager extends XmppManagerBase {
return Result(result); return Result(result);
} }
/// Requests the roster following RFC 6121. /// Requests the roster following RFC 6121. If [useRosterVersion] is set to false, then
Future<Result<RosterRequestResult, RosterError>> requestRoster() async { /// roster versioning will not be used, even if the server supports it and we have a last
/// known roster version.
Future<Result<RosterRequestResult, RosterError>> requestRoster({
bool useRosterVersion = true,
}) async {
final attrs = getAttributes(); final attrs = getAttributes();
final query = XMLNode.xmlns( final query = XMLNode.xmlns(
tag: 'query', tag: 'query',
xmlns: rosterXmlns, xmlns: rosterXmlns,
); );
final rosterVersion = await _stateManager.getRosterVersion(); final rosterVersion = await _stateManager.getRosterVersion();
if (rosterVersion != null && rosterVersioningAvailable()) { if (rosterVersion != null &&
rosterVersioningAvailable() &&
useRosterVersion) {
query.attributes['ver'] = rosterVersion; query.attributes['ver'] = rosterVersion;
} }
final response = await attrs.sendStanza( final response = (await attrs.sendStanza(
Stanza.iq( StanzaDetails(
type: 'get', Stanza.iq(
children: [ type: 'get',
query, children: [
], query,
],
),
), ),
); ))!;
if (response.attributes['type'] != 'result') { if (response.attributes['type'] != 'result') {
logger.warning('Error requesting roster: ${response.toXml()}'); logger.warning('Error requesting roster: ${response.toXml()}');
@@ -250,7 +276,7 @@ class RosterManager extends XmppManagerBase {
} }
final responseQuery = response.firstTag('query', xmlns: rosterXmlns); final responseQuery = response.firstTag('query', xmlns: rosterXmlns);
return _handleRosterResponse(responseQuery); return _handleRosterResponse(responseQuery, rosterVersion);
} }
/// Requests a series of roster pushes according to RFC6121. Requires that the server /// Requests a series of roster pushes according to RFC6121. Requires that the server
@@ -258,20 +284,23 @@ class RosterManager extends XmppManagerBase {
Future<Result<RosterRequestResult?, RosterError>> Future<Result<RosterRequestResult?, RosterError>>
requestRosterPushes() async { requestRosterPushes() async {
final attrs = getAttributes(); final attrs = getAttributes();
final result = await attrs.sendStanza( final rosterVersion = await _stateManager.getRosterVersion();
Stanza.iq( final result = (await attrs.sendStanza(
type: 'get', StanzaDetails(
children: [ Stanza.iq(
XMLNode.xmlns( type: 'get',
tag: 'query', children: [
xmlns: rosterXmlns, XMLNode.xmlns(
attributes: { tag: 'query',
'ver': await _stateManager.getRosterVersion() ?? '', xmlns: rosterXmlns,
}, attributes: {
) 'ver': rosterVersion ?? '',
], },
),
],
),
), ),
); ))!;
if (result.attributes['type'] != 'result') { if (result.attributes['type'] != 'result') {
logger.warning('Requesting roster pushes failed: ${result.toXml()}'); logger.warning('Requesting roster pushes failed: ${result.toXml()}');
@@ -279,7 +308,7 @@ class RosterManager extends XmppManagerBase {
} }
final query = result.firstTag('query', xmlns: rosterXmlns); final query = result.firstTag('query', xmlns: rosterXmlns);
return _handleRosterResponse(query); return _handleRosterResponse(query, rosterVersion);
} }
bool rosterVersioningAvailable() { bool rosterVersioningAvailable() {
@@ -296,31 +325,31 @@ class RosterManager extends XmppManagerBase {
List<String>? groups, List<String>? groups,
}) async { }) async {
final attrs = getAttributes(); final attrs = getAttributes();
final response = await attrs.sendStanza( final response = (await attrs.sendStanza(
Stanza.iq( StanzaDetails(
type: 'set', Stanza.iq(
children: [ type: 'set',
XMLNode.xmlns( children: [
tag: 'query', XMLNode.xmlns(
xmlns: rosterXmlns, tag: 'query',
children: [ xmlns: rosterXmlns,
XMLNode( children: [
tag: 'item', XMLNode(
attributes: <String, String>{ tag: 'item',
'jid': jid, attributes: <String, String>{
...title == jid.split('@')[0] 'jid': jid,
? <String, String>{} if (title == jid.split('@')[0]) 'name': title,
: <String, String>{'name': title} },
}, children: (groups ?? [])
children: (groups ?? []) .map((group) => XMLNode(tag: 'group', text: group))
.map((group) => XMLNode(tag: 'group', text: group)) .toList(),
.toList(), ),
) ],
], ),
) ],
], ),
), ),
); ))!;
if (response.attributes['type'] != 'result') { if (response.attributes['type'] != 'result') {
logger.severe('Error adding $jid to roster: $response'); logger.severe('Error adding $jid to roster: $response');
@@ -334,26 +363,28 @@ class RosterManager extends XmppManagerBase {
/// false otherwise. /// false otherwise.
Future<RosterRemovalResult> removeFromRoster(String jid) async { Future<RosterRemovalResult> removeFromRoster(String jid) async {
final attrs = getAttributes(); final attrs = getAttributes();
final response = await attrs.sendStanza( final response = (await attrs.sendStanza(
Stanza.iq( StanzaDetails(
type: 'set', Stanza.iq(
children: [ type: 'set',
XMLNode.xmlns( children: [
tag: 'query', XMLNode.xmlns(
xmlns: rosterXmlns, tag: 'query',
children: [ xmlns: rosterXmlns,
XMLNode( children: [
tag: 'item', XMLNode(
attributes: <String, String>{ tag: 'item',
'jid': jid, attributes: {
'subscription': 'remove' 'jid': jid,
}, 'subscription': 'remove',
) },
], ),
) ],
], ),
],
),
), ),
); ))!;
if (response.attributes['type'] != 'result') { if (response.attributes['type'] != 'result') {
logger.severe('Failed to remove roster item: ${response.toXml()}'); logger.severe('Failed to remove roster item: ${response.toXml()}');

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