From af1bde4fd00457c3f79658a9021df3092a875d0b Mon Sep 17 00:00:00 2001 From: Florian Schmaus Date: Fri, 20 Jan 2017 17:06:06 +0100 Subject: [PATCH] Make MUC invitations 'from' value an EntityJid MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit instead of an EntityFullJid, because according to XEP-0045 § 7.8.1.: "The itself MUST then add a 'from' address to the element whose value is the bare JID, full JID, or occupant JID of the inviter …" --- .../jivesoftware/smack/util/ParserUtils.java | 21 ++++++++++++++++++- .../smackx/muc/InvitationListener.java | 4 ++-- .../smackx/muc/MultiUserChatManager.java | 5 ++--- .../smackx/muc/packet/MUCUser.java | 12 ++++++++--- .../smackx/muc/provider/MUCUserProvider.java | 4 ++-- .../smackx/workgroup/user/Workgroup.java | 4 ++-- 6 files changed, 37 insertions(+), 13 deletions(-) diff --git a/smack-core/src/main/java/org/jivesoftware/smack/util/ParserUtils.java b/smack-core/src/main/java/org/jivesoftware/smack/util/ParserUtils.java index bd4c722fc..5a67c720e 100644 --- a/smack-core/src/main/java/org/jivesoftware/smack/util/ParserUtils.java +++ b/smack-core/src/main/java/org/jivesoftware/smack/util/ParserUtils.java @@ -1,6 +1,6 @@ /** * - * Copyright © 2014 Florian Schmaus + * Copyright © 2014-2017 Florian Schmaus * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -26,6 +26,7 @@ import java.util.Locale; import org.jivesoftware.smack.SmackException; import org.jxmpp.jid.EntityBareJid; import org.jxmpp.jid.EntityFullJid; +import org.jxmpp.jid.EntityJid; import org.jxmpp.jid.Jid; import org.jxmpp.jid.impl.JidCreate; import org.jxmpp.jid.parts.Resourcepart; @@ -98,6 +99,24 @@ public class ParserUtils { return JidCreate.entityFullFrom(jidString); } + public static EntityJid getEntityJidAttribute(XmlPullParser parser, String name) throws XmppStringprepException { + final String jidString = parser.getAttributeValue("", name); + if (jidString == null) { + return null; + } + Jid jid = JidCreate.from(jidString); + + if (!jid.hasLocalpart()) return null; + + EntityFullJid fullJid = jid.asEntityFullJidIfPossible(); + if (fullJid != null) { + return fullJid; + } + + EntityBareJid bareJid = jid.asEntityBareJidIfPossible(); + return bareJid; + } + public static Resourcepart getResourcepartAttribute(XmlPullParser parser, String name) throws XmppStringprepException { final String resourcepartString = parser.getAttributeValue("", name); if (resourcepartString == null) { diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/muc/InvitationListener.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/muc/InvitationListener.java index 4c9289050..8b1ead939 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/muc/InvitationListener.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/muc/InvitationListener.java @@ -20,7 +20,7 @@ package org.jivesoftware.smackx.muc; import org.jivesoftware.smack.XMPPConnection; import org.jivesoftware.smack.packet.Message; import org.jivesoftware.smackx.muc.packet.MUCUser; -import org.jxmpp.jid.EntityFullJid; +import org.jxmpp.jid.EntityJid; /** * A listener that is fired anytime an invitation to join a MUC room is received. @@ -43,7 +43,7 @@ public interface InvitationListener { * @param message the message used by the inviter to send the invitation. * @param invitation the raw invitation received with the message. */ - public abstract void invitationReceived(XMPPConnection conn, MultiUserChat room, EntityFullJid inviter, String reason, + public abstract void invitationReceived(XMPPConnection conn, MultiUserChat room, EntityJid inviter, String reason, String password, Message message, MUCUser.Invite invitation); } diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/muc/MultiUserChatManager.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/muc/MultiUserChatManager.java index ae6556cbd..9b556ce41 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/muc/MultiUserChatManager.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/muc/MultiUserChatManager.java @@ -1,6 +1,6 @@ /** * - * Copyright © 2014-2016 Florian Schmaus + * Copyright © 2014-2017 Florian Schmaus * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -55,7 +55,6 @@ import org.jivesoftware.smackx.muc.MultiUserChatException.NotAMucServiceExceptio import org.jivesoftware.smackx.muc.packet.MUCInitialPresence; import org.jivesoftware.smackx.muc.packet.MUCUser; import org.jxmpp.jid.EntityBareJid; -import org.jxmpp.jid.EntityFullJid; import org.jxmpp.jid.DomainBareJid; import org.jxmpp.jid.Jid; import org.jxmpp.jid.parts.Resourcepart; @@ -165,7 +164,7 @@ public final class MultiUserChatManager extends Manager { final MultiUserChat muc = getMultiUserChat(mucJid); final XMPPConnection connection = connection(); final MUCUser.Invite invite = mucUser.getInvite(); - final EntityFullJid from = invite.getFrom(); + final EntityJid from = invite.getFrom(); final String reason = invite.getReason(); final String password = mucUser.getPassword(); for (final InvitationListener listener : invitationsListeners) { diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/muc/packet/MUCUser.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/muc/packet/MUCUser.java index e8dcdd5e1..00abd698e 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/muc/packet/MUCUser.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/muc/packet/MUCUser.java @@ -29,6 +29,7 @@ import org.jivesoftware.smack.packet.ExtensionElement; import org.jivesoftware.smack.util.XmlStringBuilder; import org.jxmpp.jid.EntityBareJid; import org.jxmpp.jid.EntityFullJid; +import org.jxmpp.jid.EntityJid; /** * Represents extended presence information about roles, affiliations, full JIDs, @@ -247,7 +248,12 @@ public class MUCUser implements ExtensionElement { public static final String ELEMENT ="invite"; private final String reason; - private final EntityFullJid from; + + /** + * From XEP-0045 § 7.8.2: "… whose value is the bare JID, full JID, or occupant JID of the inviter …" + */ + private final EntityJid from; + private final EntityBareJid to; public Invite(String reason, EntityFullJid from) { @@ -258,7 +264,7 @@ public class MUCUser implements ExtensionElement { this(reason, null, to); } - public Invite(String reason, EntityFullJid from, EntityBareJid to) { + public Invite(String reason, EntityJid from, EntityBareJid to) { this.reason = reason; this.from = from; this.to = to; @@ -270,7 +276,7 @@ public class MUCUser implements ExtensionElement { * * @return the room's occupant that sent the invitation. */ - public EntityFullJid getFrom() { + public EntityJid getFrom() { return from; } diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/muc/provider/MUCUserProvider.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/muc/provider/MUCUserProvider.java index 638145e20..787be13b6 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/muc/provider/MUCUserProvider.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/muc/provider/MUCUserProvider.java @@ -24,7 +24,7 @@ import org.jivesoftware.smack.provider.ExtensionElementProvider; import org.jivesoftware.smack.util.ParserUtils; import org.jivesoftware.smackx.muc.packet.MUCUser; import org.jxmpp.jid.EntityBareJid; -import org.jxmpp.jid.EntityFullJid; +import org.jxmpp.jid.EntityJid; import org.xmlpull.v1.XmlPullParser; import org.xmlpull.v1.XmlPullParserException; @@ -86,7 +86,7 @@ public class MUCUserProvider extends ExtensionElementProvider { private static MUCUser.Invite parseInvite(XmlPullParser parser) throws XmlPullParserException, IOException { String reason = null; EntityBareJid to = ParserUtils.getBareJidAttribute(parser, "to"); - EntityFullJid from = ParserUtils.getFullJidAttribute(parser, "from"); + EntityJid from = ParserUtils.getEntityJidAttribute(parser, "from"); outerloop: while (true) { int eventType = parser.next(); diff --git a/smack-legacy/src/main/java/org/jivesoftware/smackx/workgroup/user/Workgroup.java b/smack-legacy/src/main/java/org/jivesoftware/smackx/workgroup/user/Workgroup.java index 4b0e737e6..6e75abcb6 100644 --- a/smack-legacy/src/main/java/org/jivesoftware/smackx/workgroup/user/Workgroup.java +++ b/smack-legacy/src/main/java/org/jivesoftware/smackx/workgroup/user/Workgroup.java @@ -58,7 +58,7 @@ import org.jivesoftware.smackx.workgroup.settings.WorkgroupProperties; import org.jivesoftware.smackx.xdata.Form; import org.jivesoftware.smackx.xdata.FormField; import org.jivesoftware.smackx.xdata.packet.DataForm; -import org.jxmpp.jid.EntityFullJid; +import org.jxmpp.jid.EntityJid; import org.jxmpp.jid.DomainBareJid; import org.jxmpp.jid.Jid; @@ -133,7 +133,7 @@ public class Workgroup { MultiUserChatManager.getInstanceFor(connection).addInvitationListener( new org.jivesoftware.smackx.muc.InvitationListener() { @Override - public void invitationReceived(XMPPConnection conn, org.jivesoftware.smackx.muc.MultiUserChat room, EntityFullJid inviter, + public void invitationReceived(XMPPConnection conn, org.jivesoftware.smackx.muc.MultiUserChat room, EntityJid inviter, String reason, String password, Message message, MUCUser.Invite invitation) { inQueue = false; queuePosition = -1;