1
0
Fork 0
mirror of https://github.com/vanitasvitae/Smack.git synced 2025-09-09 17:19:39 +02:00

Use Jid (and subclasses) from jxmpp-jid

Fixes SMACK-634
This commit is contained in:
Florian Schmaus 2015-02-14 17:15:02 +01:00
parent 0ee2d9ed1e
commit 5bb4727c57
180 changed files with 1510 additions and 1032 deletions

View file

@ -46,7 +46,8 @@ import org.jivesoftware.smackx.jingleold.nat.TransportCandidate;
import org.jivesoftware.smackx.jingleold.nat.TransportResolver;
import org.jivesoftware.smackx.jingleold.packet.Jingle;
import org.jivesoftware.smackx.jingleold.provider.JingleProvider;
import org.jxmpp.util.XmppStringUtils;
import org.jxmpp.jid.FullJid;
import org.jxmpp.jid.Jid;
/**
* Jingle is a session establishment protocol defined in (XEP-0166).
@ -216,18 +217,18 @@ public class JingleManager implements JingleSessionListener {
Roster.getInstanceFor(connection).addRosterListener(new RosterListener() {
public void entriesAdded(Collection<String> addresses) {
public void entriesAdded(Collection<Jid> addresses) {
}
public void entriesUpdated(Collection<String> addresses) {
public void entriesUpdated(Collection<Jid> addresses) {
}
public void entriesDeleted(Collection<String> addresses) {
public void entriesDeleted(Collection<Jid> addresses) {
}
public void presenceChanged(Presence presence) {
if (!presence.isAvailable()) {
String xmppAddress = presence.getFrom();
Jid xmppAddress = presence.getFrom();
JingleSession aux = null;
for (JingleSession jingleSession : jingleSessions) {
if (jingleSession.getInitiator().equals(xmppAddress) || jingleSession.getResponder().equals(xmppAddress)) {
@ -314,7 +315,7 @@ public class JingleManager implements JingleSessionListener {
* @throws XMPPException
* @throws InterruptedException
*/
public static boolean isServiceEnabled(XMPPConnection connection, String userID) throws XMPPException, SmackException, InterruptedException {
public static boolean isServiceEnabled(XMPPConnection connection, Jid userID) throws XMPPException, SmackException, InterruptedException {
return ServiceDiscoveryManager.getInstanceFor(connection).supportsFeature(userID, Jingle.NAMESPACE);
}
@ -518,12 +519,7 @@ public class JingleManager implements JingleSessionListener {
* user.
* @return The session on which the negotiation can be run.
*/
public JingleSession createOutgoingJingleSession(String responder) throws XMPPException {
if (XmppStringUtils.isFullJID(responder)) {
throw new IllegalArgumentException("The provided user id was not fully qualified");
}
public JingleSession createOutgoingJingleSession(FullJid responder) throws XMPPException {
JingleSession session = new JingleSession(connection, (JingleSessionRequest) null, connection.getUser(), responder, jingleMediaManagers);
triggerSessionCreated(session);

View file

@ -49,6 +49,7 @@ import org.jivesoftware.smackx.jingleold.nat.TransportNegotiator;
import org.jivesoftware.smackx.jingleold.nat.TransportResolver;
import org.jivesoftware.smackx.jingleold.packet.Jingle;
import org.jivesoftware.smackx.jingleold.packet.JingleError;
import org.jxmpp.jid.Jid;
/**
* An abstract Jingle session. <p/> This class contains some basic properties of
@ -69,9 +70,9 @@ public class JingleSession extends JingleNegotiator implements MediaReceivedList
// non-static
private String initiator; // Who started the communication
private Jid initiator; // Who started the communication
private String responder; // The other endpoint
private Jid responder; // The other endpoint
private String sid; // A unique id that identifies this session
@ -107,7 +108,7 @@ public class JingleSession extends JingleNegotiator implements MediaReceivedList
* @param jingleMediaManagers
* the jingleMediaManager
*/
public JingleSession(XMPPConnection conn, String initiator, String responder, String sessionid,
public JingleSession(XMPPConnection conn, Jid initiator, Jid responder, String sessionid,
List<JingleMediaManager> jingleMediaManagers) {
super();
@ -141,7 +142,7 @@ public class JingleSession extends JingleNegotiator implements MediaReceivedList
* @param jingleMediaManagers
* the jingleMediaManager
*/
public JingleSession(XMPPConnection conn, JingleSessionRequest request, String initiator, String responder,
public JingleSession(XMPPConnection conn, JingleSessionRequest request, Jid initiator, Jid responder,
List<JingleMediaManager> jingleMediaManagers) {
this(conn, initiator, responder, generateSessionId(), jingleMediaManagers);
//sessionRequest = request; // unused
@ -152,7 +153,7 @@ public class JingleSession extends JingleNegotiator implements MediaReceivedList
*
* @return the initiator
*/
public String getInitiator() {
public Jid getInitiator() {
return initiator;
}
@ -166,7 +167,7 @@ public class JingleSession extends JingleNegotiator implements MediaReceivedList
* @param initiator
* the initiator to set
*/
public void setInitiator(String initiator) {
public void setInitiator(Jid initiator) {
this.initiator = initiator;
}
@ -193,7 +194,7 @@ public class JingleSession extends JingleNegotiator implements MediaReceivedList
*
* @return the responder
*/
public String getResponder() {
public Jid getResponder() {
return responder;
}
@ -203,7 +204,7 @@ public class JingleSession extends JingleNegotiator implements MediaReceivedList
* @param responder
* the receptor to set
*/
public void setResponder(String responder) {
public void setResponder(Jid responder) {
this.responder = responder;
}
@ -450,8 +451,8 @@ public class JingleSession extends JingleNegotiator implements MediaReceivedList
jout.setSid(getSid());
}
String me = getConnection().getUser();
String other = getResponder().equals(me) ? getInitiator() : getResponder();
Jid me = getConnection().getUser();
Jid other = getResponder().equals(me) ? getInitiator() : getResponder();
if (jout.getTo() == null) {
if (iq != null) {
@ -686,13 +687,13 @@ public class JingleSession extends JingleNegotiator implements MediaReceivedList
if (packet instanceof IQ) {
IQ iq = (IQ) packet;
String me = getConnection().getUser();
Jid me = getConnection().getUser();
if (!iq.getTo().equals(me)) {
return false;
}
String other = getResponder().equals(me) ? getInitiator() : getResponder();
Jid other = getResponder().equals(me) ? getInitiator() : getResponder();
if (iq.getFrom() == null || !iq.getFrom().equals(other == null ? "" : other)) {
return false;
@ -706,7 +707,7 @@ public class JingleSession extends JingleNegotiator implements MediaReceivedList
LOGGER.fine("Ignored Jingle(SID) " + sid + "|" + getSid() + " :" + iq.toXML());
return false;
}
String ini = jin.getInitiator();
Jid ini = jin.getInitiator();
if (!ini.equals(getInitiator())) {
LOGGER.fine("Ignored Jingle(INI): " + iq.toXML());
return false;

View file

@ -22,6 +22,7 @@ import java.util.logging.Logger;
import org.jivesoftware.smack.SmackException;
import org.jivesoftware.smack.XMPPException;
import org.jivesoftware.smackx.jingleold.packet.Jingle;
import org.jxmpp.jid.Jid;
/**
* A Jingle session request.
@ -61,7 +62,7 @@ public class JingleSessionRequest {
* @return Returns the fully-qualified jabber ID of the user that requested
* this session.
*/
public String getFrom() {
public Jid getFrom() {
return jingle.getFrom();
}

View file

@ -32,6 +32,7 @@ import java.util.logging.Logger;
import org.jivesoftware.smack.XMPPConnection;
import org.jivesoftware.smackx.jingleold.JingleSession;
import org.jivesoftware.smackx.jingleold.nat.TransportResolverListener.Checker;
import org.jxmpp.jid.Jid;
/**
* Transport candidate.
@ -608,8 +609,8 @@ public abstract class TransportCandidate {
public class CandidateEcho implements Runnable {
DatagramSocket socket = null;
String localUser = null;
String remoteUser = null;
Jid localUser;
Jid remoteUser;
String id = null;
byte[] send = null;
byte[] receive = null;

View file

@ -19,6 +19,7 @@ package org.jivesoftware.smackx.jingleold.packet;
import org.jivesoftware.smack.packet.IQ;
import org.jivesoftware.smackx.jingleold.JingleActionEnum;
import org.jxmpp.jid.Jid;
import java.util.ArrayList;
import java.util.Collections;
@ -51,9 +52,9 @@ public class Jingle extends IQ {
private JingleActionEnum action; // The action associated to the Jingle
private String initiator; // The initiator as a "user@host/resource"
private Jid initiator; // The initiator as a "user@host/resource"
private String responder; // The responder
private Jid responder; // The responder
// Sub-elements of a Jingle object.
@ -281,7 +282,7 @@ public class Jingle extends IQ {
*
* @return the initiator
*/
public String getInitiator() {
public Jid getInitiator() {
return initiator;
}
@ -292,7 +293,7 @@ public class Jingle extends IQ {
*
* @param initiator the initiator to set
*/
public void setInitiator(final String initiator) {
public void setInitiator(final Jid initiator) {
this.initiator = initiator;
}
@ -303,7 +304,7 @@ public class Jingle extends IQ {
*
* @return the responder
*/
public String getResponder() {
public Jid getResponder() {
return responder;
}
@ -314,7 +315,7 @@ public class Jingle extends IQ {
*
* @param resp the responder to set
*/
public void setResponder(final String resp) {
public void setResponder(final Jid resp) {
responder = resp;
}
@ -325,7 +326,7 @@ public class Jingle extends IQ {
* @param initiator The initiator
* @return A hash key
*/
public static int getSessionHash(final String sid, final String initiator) {
public static int getSessionHash(final String sid, final Jid initiator) {
final int PRIME = 31;
int result = 1;
result = PRIME * result + (initiator == null ? 0 : initiator.hashCode());

View file

@ -22,12 +22,14 @@ import java.io.IOException;
import org.jivesoftware.smack.SmackException;
import org.jivesoftware.smack.provider.IQProvider;
import org.jivesoftware.smack.provider.PacketExtensionProvider;
import org.jivesoftware.smack.util.ParserUtils;
import org.jivesoftware.smackx.jingleold.JingleActionEnum;
import org.jivesoftware.smackx.jingleold.packet.Jingle;
import org.jivesoftware.smackx.jingleold.packet.JingleContent;
import org.jivesoftware.smackx.jingleold.packet.JingleContentInfo;
import org.jivesoftware.smackx.jingleold.packet.JingleDescription;
import org.jivesoftware.smackx.jingleold.packet.JingleTransport;
import org.jxmpp.jid.Jid;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
@ -51,8 +53,8 @@ public class JingleProvider extends IQProvider<Jingle> {
Jingle jingle = new Jingle();
String sid = "";
JingleActionEnum action;
String initiator = "";
String responder = "";
Jid initiator = null;
Jid responder = null;
boolean done = false;
JingleContent currentContent = null;
@ -70,8 +72,8 @@ public class JingleProvider extends IQProvider<Jingle> {
// Get some attributes for the <jingle> element
sid = parser.getAttributeValue("", "sid");
action = JingleActionEnum.getAction(parser.getAttributeValue("", "action"));
initiator = parser.getAttributeValue("", "initiator");
responder = parser.getAttributeValue("", "responder");
initiator = ParserUtils.getJidAttribute(parser, "initiator");
responder = ParserUtils.getJidAttribute(parser, "responder");
jingle.setSid(sid);
jingle.setAction(action);