feat(all): Remove StanzaAddFrom

This commit is contained in:
PapaTutuWawa 2023-05-24 20:27:01 +02:00
parent 3163101f82
commit b95e75329d
10 changed files with 24 additions and 56 deletions

View File

@ -49,18 +49,6 @@ enum XmppConnectionState {
error error
} }
/// Metadata for [XmppConnection.sendStanza].
enum StanzaFromType {
/// Add the full JID to the stanza as the from attribute
full,
/// Add the bare JID to the stanza as the from attribute
bare,
/// Add no JID as the from attribute
none,
}
/// This class is a connection to the server. /// This class is a connection to the server.
class XmppConnection { class XmppConnection {
XmppConnection( XmppConnection(
@ -454,25 +442,21 @@ class XmppConnection {
newStanza = newStanza.copyWith(id: generateId()); newStanza = newStanza.copyWith(id: generateId());
} }
// Add a from type, if requested // NOTE: Originally, we handled adding a "from" attribute to the stanza here.
if (details.addFrom != StanzaFromType.none && // However, this is not neccessary as RFC 6120 states:
(newStanza.from == null || newStanza.from == '')) { //
switch (details.addFrom) { // > When a server receives an XML stanza from a connected client, the
case StanzaFromType.full: // > server MUST add a 'from' attribute to the stanza or override the
newStanza = newStanza.copyWith( // > 'from' attribute specified by the client, where the value of the
from: _getJidWithResource().toString(), // > 'from' attribute MUST be the full JID
); // > (<localpart@domainpart/resource>) determined by the server for
break; // > the connected resource that generated the stanza (see
case StanzaFromType.bare: // > Section 4.3.6), or the bare JID (<localpart@domainpart>) in the
newStanza = newStanza.copyWith( // > case of subscription-related presence stanzas (see [XMPP-IM]).
from: connectionSettings.jid.toBare().toString(), //
); // This means that even if we add a "from" attribute, the server will discard
break; // it. If we don't specify it, then the server will add the correct value
case StanzaFromType.none: // itself.
// NOOP
break;
}
}
// Add the correct stanza namespace // Add the correct stanza namespace
newStanza = newStanza.copyWith( newStanza = newStanza.copyWith(

View File

@ -1,5 +1,4 @@
import 'dart:async'; import 'dart:async';
import 'package:moxxmpp/src/connection.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';
@ -105,7 +104,6 @@ class PresenceManager extends XmppManagerBase {
await attrs.sendStanza( await attrs.sendStanza(
StanzaDetails( StanzaDetails(
Stanza.presence( Stanza.presence(
from: attrs.getFullJID().toString(),
children: children, children: children,
), ),
awaitable: false, awaitable: false,
@ -134,7 +132,6 @@ class PresenceManager extends XmppManagerBase {
type: 'subscribe', type: 'subscribe',
to: to, to: to,
), ),
addFrom: StanzaFromType.none,
awaitable: false, awaitable: false,
), ),
); );
@ -148,7 +145,6 @@ class PresenceManager extends XmppManagerBase {
type: 'unsubscribe', type: 'unsubscribe',
to: to, to: to,
), ),
addFrom: StanzaFromType.none,
awaitable: false, awaitable: false,
), ),
); );
@ -162,7 +158,6 @@ class PresenceManager extends XmppManagerBase {
type: 'subscribed', type: 'subscribed',
to: to, to: to,
), ),
addFrom: StanzaFromType.none,
awaitable: false, awaitable: false,
), ),
); );
@ -176,7 +171,6 @@ class PresenceManager extends XmppManagerBase {
type: 'unsubscribed', type: 'unsubscribed',
to: to, to: to,
), ),
addFrom: StanzaFromType.none,
awaitable: false, awaitable: false,
), ),
); );

View File

@ -1,7 +1,6 @@
import 'dart:async'; import 'dart:async';
import 'dart:collection'; import 'dart:collection';
import 'package:meta/meta.dart'; import 'package:meta/meta.dart';
import 'package:moxxmpp/src/connection.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:synchronized/synchronized.dart'; import 'package:synchronized/synchronized.dart';
@ -9,7 +8,6 @@ import 'package:synchronized/synchronized.dart';
class StanzaDetails { class StanzaDetails {
const StanzaDetails( const StanzaDetails(
this.stanza, { this.stanza, {
this.addFrom = StanzaFromType.full,
this.addId = true, this.addId = true,
this.awaitable = true, this.awaitable = true,
this.encrypted = false, this.encrypted = false,
@ -19,9 +17,6 @@ class StanzaDetails {
/// The stanza to send. /// The stanza to send.
final Stanza stanza; final Stanza stanza;
/// How to set the "from" attribute of the stanza.
final StanzaFromType addFrom;
/// Flag indicating whether a stanza id should be added before sending. /// Flag indicating whether a stanza id should be added before sending.
final bool addId; final bool addId;

View File

@ -33,7 +33,6 @@ class TestingManagerHolder {
Future<XMLNode> _sendStanza( Future<XMLNode> _sendStanza(
stanza, { stanza, {
StanzaFromType addFrom = StanzaFromType.full,
bool addId = true, bool addId = true,
bool awaitable = true, bool awaitable = true,
bool encrypted = false, bool encrypted = false,

View File

@ -98,7 +98,7 @@ List<ExpectationBase> buildAuthenticatedPlay(ConnectionSettings settings) {
ignoreId: true, ignoreId: true,
), ),
StanzaExpectation( StanzaExpectation(
"<presence xmlns='jabber:client' from='${settings.jid.toBare()}/MU29eEZn'><show>chat</show></presence>", "<presence xmlns='jabber:client'><show>chat</show></presence>",
'', '',
), ),
]; ];

View File

@ -58,11 +58,11 @@ void main() {
ignoreId: true, ignoreId: true,
), ),
StanzaExpectation( StanzaExpectation(
"<presence xmlns='jabber:client' from='polynomdivision@test.server/MU29eEZn'><show>chat</show><c xmlns='http://jabber.org/protocol/caps' hash='sha-1' node='http://moxxmpp.example' ver='3QvQ2RAy45XBDhArjxy/vEWMl+E=' /></presence>", "<presence xmlns='jabber:client'><show>chat</show><c xmlns='http://jabber.org/protocol/caps' hash='sha-1' node='http://moxxmpp.example' ver='3QvQ2RAy45XBDhArjxy/vEWMl+E=' /></presence>",
'', '',
), ),
StanzaExpectation( StanzaExpectation(
"<iq type='get' id='ec325efc-9924-4c48-93f8-ed34a2b0e5fc' to='romeo@montague.lit/orchard' from='polynomdivision@test.server/MU29eEZn' xmlns='jabber:client'><query xmlns='http://jabber.org/protocol/disco#info' /></iq>", "<iq type='get' id='ec325efc-9924-4c48-93f8-ed34a2b0e5fc' to='romeo@montague.lit/orchard' xmlns='jabber:client'><query xmlns='http://jabber.org/protocol/disco#info' /></iq>",
'', '',
ignoreId: true, ignoreId: true,
), ),

View File

@ -92,7 +92,7 @@ void main() {
[ [
StanzaExpectation( StanzaExpectation(
''' '''
<iq type="get" to="pubsub.server.example.org" id="a" from="testuser@example.org/MU29eEZn" xmlns="jabber:client"> <iq type="get" to="pubsub.server.example.org" id="a" xmlns="jabber:client">
<query xmlns="http://jabber.org/protocol/disco#info" /> <query xmlns="http://jabber.org/protocol/disco#info" />
</iq> </iq>
''', ''',
@ -110,7 +110,7 @@ void main() {
), ),
StanzaExpectation( StanzaExpectation(
''' '''
<iq type="get" to="pubsub.server.example.org" id="a" from="testuser@example.org/MU29eEZn" xmlns="jabber:client"> <iq type="get" to="pubsub.server.example.org" id="a" xmlns="jabber:client">
<query xmlns="http://jabber.org/protocol/disco#items" node="princely_musings" /> <query xmlns="http://jabber.org/protocol/disco#items" node="princely_musings" />
</iq> </iq>
''', ''',
@ -124,7 +124,7 @@ void main() {
), ),
StanzaExpectation( StanzaExpectation(
''' '''
<iq type="set" to="pubsub.server.example.org" id="a" from="testuser@example.org/MU29eEZn" xmlns="jabber:client"> <iq type="set" to="pubsub.server.example.org" id="a" xmlns="jabber:client">
<pubsub xmlns='http://jabber.org/protocol/pubsub'> <pubsub xmlns='http://jabber.org/protocol/pubsub'>
<publish node='princely_musings'> <publish node='princely_musings'>
<item id="current"> <item id="current">

View File

@ -381,7 +381,7 @@ void main() {
'<enabled xmlns="urn:xmpp:sm:3" id="some-long-sm-id" resume="true" />', '<enabled xmlns="urn:xmpp:sm:3" id="some-long-sm-id" resume="true" />',
), ),
StanzaExpectation( StanzaExpectation(
"<presence xmlns='jabber:client' from='polynomdivision@test.server/MU29eEZn'><show>chat</show></presence>", "<presence xmlns='jabber:client'><show>chat</show></presence>",
'<iq type="result" />', '<iq type="result" />',
), ),
StringExpectation( StringExpectation(
@ -671,7 +671,7 @@ void main() {
"<resumed xmlns='urn:xmpp:sm:3' h='id-1' h='12' />", "<resumed xmlns='urn:xmpp:sm:3' h='id-1' h='12' />",
), ),
StanzaExpectation( StanzaExpectation(
"<iq to='localhost' type='get' from='polynomdivision@test.server/abc123' xmlns='jabber:client' />", "<iq to='localhost' type='get' xmlns='jabber:client' />",
'', '',
ignoreId: true, ignoreId: true,
), ),
@ -724,7 +724,7 @@ void main() {
"<resumed xmlns='urn:xmpp:sm:3' h='id-1' h='12' />", "<resumed xmlns='urn:xmpp:sm:3' h='id-1' h='12' />",
), ),
StanzaExpectation( StanzaExpectation(
"<iq to='localhost' type='get' from='polynomdivision@test.server/abc123' xmlns='jabber:client' />", "<iq to='localhost' type='get' xmlns='jabber:client' />",
'', '',
ignoreId: true, ignoreId: true,
), ),

View File

@ -39,7 +39,6 @@ void main() {
XmppManagerAttributes( XmppManagerAttributes(
sendStanza: ( sendStanza: (
_, { _, {
StanzaFromType addFrom = StanzaFromType.full,
bool addId = true, bool addId = true,
bool retransmitted = false, bool retransmitted = false,
bool awaitable = true, bool awaitable = true,
@ -78,7 +77,6 @@ void main() {
XmppManagerAttributes( XmppManagerAttributes(
sendStanza: ( sendStanza: (
_, { _, {
StanzaFromType addFrom = StanzaFromType.full,
bool addId = true, bool addId = true,
bool retransmitted = false, bool retransmitted = false,
bool awaitable = true, bool awaitable = true,

View File

@ -16,7 +16,6 @@ Future<bool> testRosterManager(
XmppManagerAttributes( XmppManagerAttributes(
sendStanza: ( sendStanza: (
_, { _, {
StanzaFromType addFrom = StanzaFromType.full,
bool addId = true, bool addId = true,
bool retransmitted = false, bool retransmitted = false,
bool awaitable = true, bool awaitable = true,
@ -267,7 +266,6 @@ void main() {
XmppManagerAttributes( XmppManagerAttributes(
sendStanza: ( sendStanza: (
_, { _, {
StanzaFromType addFrom = StanzaFromType.full,
bool addId = true, bool addId = true,
bool retransmitted = false, bool retransmitted = false,
bool awaitable = true, bool awaitable = true,