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

Make MUC invitations 'from' value an EntityJid

instead of an EntityFullJid, because according to XEP-0045 § 7.8.1.:

"The <room@service> itself MUST then add a 'from' address to the
<invite/> element whose value is the bare JID, full JID, or occupant
JID of the inviter …"
This commit is contained in:
Florian Schmaus 2017-01-20 17:06:06 +01:00
parent a4ae941a7c
commit af1bde4fd0
6 changed files with 37 additions and 13 deletions

View file

@ -1,6 +1,6 @@
/** /**
* *
* Copyright © 2014 Florian Schmaus * Copyright © 2014-2017 Florian Schmaus
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with 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.jivesoftware.smack.SmackException;
import org.jxmpp.jid.EntityBareJid; import org.jxmpp.jid.EntityBareJid;
import org.jxmpp.jid.EntityFullJid; import org.jxmpp.jid.EntityFullJid;
import org.jxmpp.jid.EntityJid;
import org.jxmpp.jid.Jid; import org.jxmpp.jid.Jid;
import org.jxmpp.jid.impl.JidCreate; import org.jxmpp.jid.impl.JidCreate;
import org.jxmpp.jid.parts.Resourcepart; import org.jxmpp.jid.parts.Resourcepart;
@ -98,6 +99,24 @@ public class ParserUtils {
return JidCreate.entityFullFrom(jidString); 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 { public static Resourcepart getResourcepartAttribute(XmlPullParser parser, String name) throws XmppStringprepException {
final String resourcepartString = parser.getAttributeValue("", name); final String resourcepartString = parser.getAttributeValue("", name);
if (resourcepartString == null) { if (resourcepartString == null) {

View file

@ -20,7 +20,7 @@ package org.jivesoftware.smackx.muc;
import org.jivesoftware.smack.XMPPConnection; import org.jivesoftware.smack.XMPPConnection;
import org.jivesoftware.smack.packet.Message; import org.jivesoftware.smack.packet.Message;
import org.jivesoftware.smackx.muc.packet.MUCUser; 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. * 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 message the message used by the inviter to send the invitation.
* @param invitation the raw invitation received with the message. * @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); String password, Message message, MUCUser.Invite invitation);
} }

View file

@ -1,6 +1,6 @@
/** /**
* *
* Copyright © 2014-2016 Florian Schmaus * Copyright © 2014-2017 Florian Schmaus
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with 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.MUCInitialPresence;
import org.jivesoftware.smackx.muc.packet.MUCUser; import org.jivesoftware.smackx.muc.packet.MUCUser;
import org.jxmpp.jid.EntityBareJid; import org.jxmpp.jid.EntityBareJid;
import org.jxmpp.jid.EntityFullJid;
import org.jxmpp.jid.DomainBareJid; import org.jxmpp.jid.DomainBareJid;
import org.jxmpp.jid.Jid; import org.jxmpp.jid.Jid;
import org.jxmpp.jid.parts.Resourcepart; import org.jxmpp.jid.parts.Resourcepart;
@ -165,7 +164,7 @@ public final class MultiUserChatManager extends Manager {
final MultiUserChat muc = getMultiUserChat(mucJid); final MultiUserChat muc = getMultiUserChat(mucJid);
final XMPPConnection connection = connection(); final XMPPConnection connection = connection();
final MUCUser.Invite invite = mucUser.getInvite(); final MUCUser.Invite invite = mucUser.getInvite();
final EntityFullJid from = invite.getFrom(); final EntityJid from = invite.getFrom();
final String reason = invite.getReason(); final String reason = invite.getReason();
final String password = mucUser.getPassword(); final String password = mucUser.getPassword();
for (final InvitationListener listener : invitationsListeners) { for (final InvitationListener listener : invitationsListeners) {

View file

@ -29,6 +29,7 @@ import org.jivesoftware.smack.packet.ExtensionElement;
import org.jivesoftware.smack.util.XmlStringBuilder; import org.jivesoftware.smack.util.XmlStringBuilder;
import org.jxmpp.jid.EntityBareJid; import org.jxmpp.jid.EntityBareJid;
import org.jxmpp.jid.EntityFullJid; import org.jxmpp.jid.EntityFullJid;
import org.jxmpp.jid.EntityJid;
/** /**
* Represents extended presence information about roles, affiliations, full JIDs, * Represents extended presence information about roles, affiliations, full JIDs,
@ -247,7 +248,12 @@ public class MUCUser implements ExtensionElement {
public static final String ELEMENT ="invite"; public static final String ELEMENT ="invite";
private final String reason; 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; private final EntityBareJid to;
public Invite(String reason, EntityFullJid from) { public Invite(String reason, EntityFullJid from) {
@ -258,7 +264,7 @@ public class MUCUser implements ExtensionElement {
this(reason, null, to); this(reason, null, to);
} }
public Invite(String reason, EntityFullJid from, EntityBareJid to) { public Invite(String reason, EntityJid from, EntityBareJid to) {
this.reason = reason; this.reason = reason;
this.from = from; this.from = from;
this.to = to; this.to = to;
@ -270,7 +276,7 @@ public class MUCUser implements ExtensionElement {
* *
* @return the room's occupant that sent the invitation. * @return the room's occupant that sent the invitation.
*/ */
public EntityFullJid getFrom() { public EntityJid getFrom() {
return from; return from;
} }

View file

@ -24,7 +24,7 @@ import org.jivesoftware.smack.provider.ExtensionElementProvider;
import org.jivesoftware.smack.util.ParserUtils; import org.jivesoftware.smack.util.ParserUtils;
import org.jivesoftware.smackx.muc.packet.MUCUser; import org.jivesoftware.smackx.muc.packet.MUCUser;
import org.jxmpp.jid.EntityBareJid; import org.jxmpp.jid.EntityBareJid;
import org.jxmpp.jid.EntityFullJid; import org.jxmpp.jid.EntityJid;
import org.xmlpull.v1.XmlPullParser; import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException; import org.xmlpull.v1.XmlPullParserException;
@ -86,7 +86,7 @@ public class MUCUserProvider extends ExtensionElementProvider<MUCUser> {
private static MUCUser.Invite parseInvite(XmlPullParser parser) throws XmlPullParserException, IOException { private static MUCUser.Invite parseInvite(XmlPullParser parser) throws XmlPullParserException, IOException {
String reason = null; String reason = null;
EntityBareJid to = ParserUtils.getBareJidAttribute(parser, "to"); EntityBareJid to = ParserUtils.getBareJidAttribute(parser, "to");
EntityFullJid from = ParserUtils.getFullJidAttribute(parser, "from"); EntityJid from = ParserUtils.getEntityJidAttribute(parser, "from");
outerloop: while (true) { outerloop: while (true) {
int eventType = parser.next(); int eventType = parser.next();

View file

@ -58,7 +58,7 @@ import org.jivesoftware.smackx.workgroup.settings.WorkgroupProperties;
import org.jivesoftware.smackx.xdata.Form; import org.jivesoftware.smackx.xdata.Form;
import org.jivesoftware.smackx.xdata.FormField; import org.jivesoftware.smackx.xdata.FormField;
import org.jivesoftware.smackx.xdata.packet.DataForm; 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.DomainBareJid;
import org.jxmpp.jid.Jid; import org.jxmpp.jid.Jid;
@ -133,7 +133,7 @@ public class Workgroup {
MultiUserChatManager.getInstanceFor(connection).addInvitationListener( MultiUserChatManager.getInstanceFor(connection).addInvitationListener(
new org.jivesoftware.smackx.muc.InvitationListener() { new org.jivesoftware.smackx.muc.InvitationListener() {
@Override @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) { String reason, String password, Message message, MUCUser.Invite invitation) {
inQueue = false; inQueue = false;
queuePosition = -1; queuePosition = -1;