1
0
Fork 0
mirror of https://github.com/vanitasvitae/Smack.git synced 2024-11-22 20:12:07 +01:00

Add FromMode regarding 'from' attribute of outgoing stanzas

XMPP Servers should ignore the 'from' attribute of outgoing
stanzas. Makes the behavior how Smack populates the 'from' attribute of
outgoing stanzas configurable. Fixes SMACK-547
This commit is contained in:
Florian Schmaus 2014-04-14 09:07:42 +02:00
parent c3cb98a116
commit 61fd3c9dd0
2 changed files with 52 additions and 1 deletions

View file

@ -184,6 +184,11 @@ public abstract class XMPPConnection {
*/
private String serviceCapsNode;
/**
* Defines how the from attribute of outgoing stanzas should be handled.
*/
private FromMode fromMode = FromMode.OMITTED;
/**
* Stores whether the server supports rosterVersioning
*/
@ -426,6 +431,17 @@ public abstract class XMPPConnection {
if (packet == null) {
throw new NullPointerException("Packet is null.");
}
switch (fromMode) {
case OMITTED:
packet.setFrom(null);
break;
case USER:
packet.setFrom(getUser());
break;
case UNCHANGED:
default:
break;
}
// Invoke interceptors for the new packet that is about to be sent. Interceptors may modify
// the content of the packet.
firePacketInterceptors(packet);
@ -1104,4 +1120,40 @@ public abstract class XMPPConnection {
public int getConnectionCounter() {
return connectionCounterValue;
}
public static enum FromMode {
/**
* Leave the 'from' attribute unchanged. This is the behavior of Smack < 4.0
*/
UNCHANGED,
/**
* Omit the 'from' attribute. According to RFC 6120 8.1.2.1 1. XMPP servers "MUST (...)
* override the 'from' attribute specified by the client". It is therefore safe to specify
* FromMode.OMITTED here.
*/
OMITTED,
/**
* Set the from to the clients full JID. This is usually not required.
*/
USER
}
/**
* Set the FromMode for this connection instance. Defines how the 'from' attribute of outgoing
* stanzas should be populated by Smack.
*
* @param fromMode
*/
public void setFromMode(FromMode fromMode) {
this.fromMode = fromMode;
}
/**
* Get the currently active FromMode.
*
* @return the currently active {@link FromMode}
*/
public FromMode getFromMode() {
return this.fromMode;
}
}

View file

@ -67,7 +67,6 @@ public class PingTest extends InitExtensions {
assertTrue(pongPacket instanceof IQ);
IQ pong = (IQ) pongPacket;
assertEquals("juliet@capulet.lit/balcony", pong.getFrom());
assertEquals("capulet.lit", pong.getTo());
assertEquals("s2c1", pong.getPacketID());
assertEquals(IQ.Type.RESULT, pong.getType());