feat(xep): Allow changing the SASL2 user agent

This commit is contained in:
PapaTutuWawa 2023-06-11 16:30:49 +02:00
parent f2d8c6a009
commit aa71d3ed5d
9 changed files with 36 additions and 55 deletions

View File

@ -44,13 +44,12 @@ void main() {
FASTSaslNegotiator(), FASTSaslNegotiator(),
Bind2Negotiator(), Bind2Negotiator(),
StartTlsNegotiator(), StartTlsNegotiator(),
Sasl2Negotiator( Sasl2Negotiator()
userAgent: const UserAgent( ..userAgent = const UserAgent(
id: 'd4565fa7-4d72-4749-b3d3-740edbf87770', id: 'd4565fa7-4d72-4749-b3d3-740edbf87770',
software: 'moxxmpp', software: 'moxxmpp',
device: "PapaTutuWawa's awesome device", device: "PapaTutuWawa's awesome device",
), ),
),
]); ]);
final result = await conn.connect( final result = await conn.connect(

View File

@ -1,6 +1,6 @@
import 'package:moxxmpp/src/stringxml.dart'; import 'package:moxxmpp/src/stringxml.dart';
/// A data class describing the user agent. See https://dyn.eightysoft.de/final/xep-0388.html#initiation /// A data class describing the user agent. See https://xmpp.org/extensions/xep-0388.html#initiation.
class UserAgent { class UserAgent {
const UserAgent({ const UserAgent({
this.id, this.id,
@ -24,11 +24,9 @@ class UserAgent {
); );
return XMLNode( return XMLNode(
tag: 'user-agent', tag: 'user-agent',
attributes: id != null attributes: {
? { if (id != null) 'id': id,
'id': id, },
}
: {},
children: [ children: [
if (software != null) if (software != null)
XMLNode( XMLNode(

View File

@ -20,12 +20,10 @@ enum Sasl2State {
/// A negotiator that implements XEP-0388 SASL2. Alone, it does nothing. Has to be /// A negotiator that implements XEP-0388 SASL2. Alone, it does nothing. Has to be
/// registered with other negotiators that register themselves against this one. /// registered with other negotiators that register themselves against this one.
class Sasl2Negotiator extends XmppFeatureNegotiatorBase { class Sasl2Negotiator extends XmppFeatureNegotiatorBase {
Sasl2Negotiator({ Sasl2Negotiator() : super(100, false, sasl2Xmlns, sasl2Negotiator);
this.userAgent,
}) : super(100, false, sasl2Xmlns, sasl2Negotiator);
/// The user agent data that will be sent to the server when authenticating. /// The user agent data that will be sent to the server when authenticating.
final UserAgent? userAgent; UserAgent? userAgent;
/// List of callbacks that are registered against us. Will be called once we get /// List of callbacks that are registered against us. Will be called once we get
/// SASL2 features. /// SASL2 features.

View File

@ -850,13 +850,12 @@ void main() {
SaslPlainNegotiator(), SaslPlainNegotiator(),
ResourceBindingNegotiator(), ResourceBindingNegotiator(),
StreamManagementNegotiator()..resource = 'test-resource', StreamManagementNegotiator()..resource = 'test-resource',
Sasl2Negotiator( Sasl2Negotiator()
userAgent: const UserAgent( ..userAgent = const UserAgent(
id: 'd4565fa7-4d72-4749-b3d3-740edbf87770', id: 'd4565fa7-4d72-4749-b3d3-740edbf87770',
software: 'moxxmpp', software: 'moxxmpp',
device: "PapaTutuWawa's awesome device", device: "PapaTutuWawa's awesome device",
), ),
),
]); ]);
final result = await conn.connect( final result = await conn.connect(
@ -948,13 +947,12 @@ void main() {
ResourceBindingNegotiator(), ResourceBindingNegotiator(),
StreamManagementNegotiator()..resource = 'test-resource', StreamManagementNegotiator()..resource = 'test-resource',
Bind2Negotiator(), Bind2Negotiator(),
Sasl2Negotiator( Sasl2Negotiator()
userAgent: const UserAgent( ..userAgent = const UserAgent(
id: 'd4565fa7-4d72-4749-b3d3-740edbf87770', id: 'd4565fa7-4d72-4749-b3d3-740edbf87770',
software: 'moxxmpp', software: 'moxxmpp',
device: "PapaTutuWawa's awesome device", device: "PapaTutuWawa's awesome device",
), ),
),
]); ]);
final result = await conn.connect( final result = await conn.connect(
@ -1051,13 +1049,12 @@ void main() {
ResourceBindingNegotiator(), ResourceBindingNegotiator(),
smn, smn,
Bind2Negotiator(), Bind2Negotiator(),
Sasl2Negotiator( Sasl2Negotiator()
userAgent: const UserAgent( ..userAgent = const UserAgent(
id: 'd4565fa7-4d72-4749-b3d3-740edbf87770', id: 'd4565fa7-4d72-4749-b3d3-740edbf87770',
software: 'moxxmpp', software: 'moxxmpp',
device: "PapaTutuWawa's awesome device", device: "PapaTutuWawa's awesome device",
), ),
),
]); ]);
final result = await conn.connect( final result = await conn.connect(

View File

@ -114,13 +114,12 @@ void main() {
ResourceBindingNegotiator(), ResourceBindingNegotiator(),
CarbonsNegotiator(), CarbonsNegotiator(),
Bind2Negotiator(), Bind2Negotiator(),
Sasl2Negotiator( Sasl2Negotiator()
userAgent: const UserAgent( ..userAgent = const UserAgent(
id: 'd4565fa7-4d72-4749-b3d3-740edbf87770', id: 'd4565fa7-4d72-4749-b3d3-740edbf87770',
software: 'moxxmpp', software: 'moxxmpp',
device: "PapaTutuWawa's awesome device", device: "PapaTutuWawa's awesome device",
), ),
),
]); ]);
final result = await conn.connect( final result = await conn.connect(

View File

@ -184,13 +184,12 @@ void main() {
FASTSaslNegotiator(), FASTSaslNegotiator(),
Bind2Negotiator(), Bind2Negotiator(),
CSINegotiator(), CSINegotiator(),
Sasl2Negotiator( Sasl2Negotiator()
userAgent: const UserAgent( ..userAgent = const UserAgent(
id: 'd4565fa7-4d72-4749-b3d3-740edbf87770', id: 'd4565fa7-4d72-4749-b3d3-740edbf87770',
software: 'moxxmpp', software: 'moxxmpp',
device: "PapaTutuWawa's awesome device", device: "PapaTutuWawa's awesome device",
), ),
),
]); ]);
final result = await conn.connect( final result = await conn.connect(

View File

@ -59,13 +59,12 @@ void main() {
SaslPlainNegotiator(), SaslPlainNegotiator(),
ResourceBindingNegotiator(), ResourceBindingNegotiator(),
Bind2Negotiator(), Bind2Negotiator(),
Sasl2Negotiator( Sasl2Negotiator()
userAgent: const UserAgent( ..userAgent = const UserAgent(
id: 'd4565fa7-4d72-4749-b3d3-740edbf87770', id: 'd4565fa7-4d72-4749-b3d3-740edbf87770',
software: 'moxxmpp', software: 'moxxmpp',
device: "PapaTutuWawa's awesome device", device: "PapaTutuWawa's awesome device",
), ),
),
]); ]);
final result = await conn.connect( final result = await conn.connect(
@ -129,13 +128,12 @@ void main() {
SaslPlainNegotiator(), SaslPlainNegotiator(),
ResourceBindingNegotiator(), ResourceBindingNegotiator(),
Bind2Negotiator()..tag = 'moxxmpp', Bind2Negotiator()..tag = 'moxxmpp',
Sasl2Negotiator( Sasl2Negotiator()
userAgent: const UserAgent( ..userAgent = const UserAgent(
id: 'd4565fa7-4d72-4749-b3d3-740edbf87770', id: 'd4565fa7-4d72-4749-b3d3-740edbf87770',
software: 'moxxmpp', software: 'moxxmpp',
device: "PapaTutuWawa's awesome device", device: "PapaTutuWawa's awesome device",
), ),
),
]); ]);
final result = await conn.connect( final result = await conn.connect(

View File

@ -115,13 +115,12 @@ void main() {
await conn.registerFeatureNegotiators([ await conn.registerFeatureNegotiators([
SaslPlainNegotiator(), SaslPlainNegotiator(),
ResourceBindingNegotiator(), ResourceBindingNegotiator(),
Sasl2Negotiator( Sasl2Negotiator()
userAgent: const UserAgent( ..userAgent = const UserAgent(
id: 'd4565fa7-4d72-4749-b3d3-740edbf87770', id: 'd4565fa7-4d72-4749-b3d3-740edbf87770',
software: 'moxxmpp', software: 'moxxmpp',
device: "PapaTutuWawa's awesome device", device: "PapaTutuWawa's awesome device",
), ),
),
]); ]);
final result = await conn.connect( final result = await conn.connect(
@ -199,13 +198,12 @@ void main() {
ScramHashType.sha256, ScramHashType.sha256,
), ),
ResourceBindingNegotiator(), ResourceBindingNegotiator(),
Sasl2Negotiator( Sasl2Negotiator()
userAgent: const UserAgent( ..userAgent = const UserAgent(
id: 'd4565fa7-4d72-4749-b3d3-740edbf87770', id: 'd4565fa7-4d72-4749-b3d3-740edbf87770',
software: 'moxxmpp', software: 'moxxmpp',
device: "PapaTutuWawa's awesome device", device: "PapaTutuWawa's awesome device",
), ),
),
]); ]);
final result = await conn.connect( final result = await conn.connect(
@ -276,13 +274,12 @@ void main() {
ScramHashType.sha256, ScramHashType.sha256,
), ),
ResourceBindingNegotiator(), ResourceBindingNegotiator(),
Sasl2Negotiator( Sasl2Negotiator()
userAgent: const UserAgent( ..userAgent = const UserAgent(
id: 'd4565fa7-4d72-4749-b3d3-740edbf87770', id: 'd4565fa7-4d72-4749-b3d3-740edbf87770',
software: 'moxxmpp', software: 'moxxmpp',
device: "PapaTutuWawa's awesome device", device: "PapaTutuWawa's awesome device",
), ),
),
]); ]);
final result = await conn.connect( final result = await conn.connect(
@ -356,13 +353,12 @@ void main() {
SaslPlainNegotiator(), SaslPlainNegotiator(),
ResourceBindingNegotiator(), ResourceBindingNegotiator(),
ExampleNegotiator(), ExampleNegotiator(),
Sasl2Negotiator( Sasl2Negotiator()
userAgent: const UserAgent( ..userAgent = const UserAgent(
id: 'd4565fa7-4d72-4749-b3d3-740edbf87770', id: 'd4565fa7-4d72-4749-b3d3-740edbf87770',
software: 'moxxmpp', software: 'moxxmpp',
device: "PapaTutuWawa's awesome device", device: "PapaTutuWawa's awesome device",
), ),
),
]); ]);
final result = await conn.connect( final result = await conn.connect(
@ -439,13 +435,12 @@ void main() {
SaslPlainNegotiator(), SaslPlainNegotiator(),
ResourceBindingNegotiator(), ResourceBindingNegotiator(),
ExampleNegotiator(), ExampleNegotiator(),
Sasl2Negotiator( Sasl2Negotiator()
userAgent: const UserAgent( ..userAgent = const UserAgent(
id: 'd4565fa7-4d72-4749-b3d3-740edbf87770', id: 'd4565fa7-4d72-4749-b3d3-740edbf87770',
software: 'moxxmpp', software: 'moxxmpp',
device: "PapaTutuWawa's awesome device", device: "PapaTutuWawa's awesome device",
), ),
),
]); ]);
final result = await conn.connect( final result = await conn.connect(

View File

@ -121,13 +121,12 @@ void main() {
SaslPlainNegotiator(), SaslPlainNegotiator(),
ResourceBindingNegotiator(), ResourceBindingNegotiator(),
FASTSaslNegotiator(), FASTSaslNegotiator(),
Sasl2Negotiator( Sasl2Negotiator()
userAgent: const UserAgent( ..userAgent = const UserAgent(
id: 'd4565fa7-4d72-4749-b3d3-740edbf87770', id: 'd4565fa7-4d72-4749-b3d3-740edbf87770',
software: 'moxxmpp', software: 'moxxmpp',
device: "PapaTutuWawa's awesome device", device: "PapaTutuWawa's awesome device",
), ),
),
]); ]);
final result1 = await conn.connect( final result1 = await conn.connect(
@ -238,13 +237,12 @@ void main() {
'WXZzciBwYmFmdmZnZiBqdmd1IGp2eXFhcmZm', 'WXZzciBwYmFmdmZnZiBqdmd1IGp2eXFhcmZm',
'2020-03-12T14:36:15Z', '2020-03-12T14:36:15Z',
), ),
Sasl2Negotiator( Sasl2Negotiator()
userAgent: const UserAgent( ..userAgent = const UserAgent(
id: 'd4565fa7-4d72-4749-b3d3-740edbf87770', id: 'd4565fa7-4d72-4749-b3d3-740edbf87770',
software: 'moxxmpp', software: 'moxxmpp',
device: "PapaTutuWawa's awesome device", device: "PapaTutuWawa's awesome device",
), ),
),
]); ]);
final result1 = await conn.connect( final result1 = await conn.connect(