1
0
Fork 0
mirror of https://github.com/vanitasvitae/Smack.git synced 2024-11-23 20:42:06 +01:00
This commit is contained in:
vanitasvitae 2017-06-07 23:18:23 +02:00
parent 8240e92c3e
commit bfd3fbdc5b
Signed by: vanitasvitae
GPG key ID: 62BEE9264BF17311
5 changed files with 108 additions and 23 deletions

View file

@ -22,11 +22,22 @@ public class JingleSocks5BytestreamTransport extends JingleContentTransport {
private final String dstAddr; private final String dstAddr;
private final Bytestream.Mode mode; private final Bytestream.Mode mode;
protected JingleSocks5BytestreamTransport(List<JingleContentTransportCandidate> candidates, String streamId, String dstAddr, Bytestream.Mode mode) { private final String candidateUsed;
private final String candidateActivated;
private final boolean candidateError;
private final boolean proxyError;
protected JingleSocks5BytestreamTransport(List<JingleContentTransportCandidate> candidates, String streamId, String dstAddr, Bytestream.Mode mode,
String candidateUsed, String candidateActivated, boolean candidateError, boolean proxyError) {
super(candidates); super(candidates);
this.streamId = streamId; this.streamId = streamId;
this.dstAddr = dstAddr; this.dstAddr = dstAddr;
this.mode = mode; this.mode = mode;
this.candidateUsed = candidateUsed;
this.candidateActivated = candidateActivated;
this.candidateError = candidateError;
this.proxyError = proxyError;
} }
public String getStreamId() { public String getStreamId() {
@ -58,6 +69,12 @@ public class JingleSocks5BytestreamTransport extends JingleContentTransport {
} }
public static class Builder { public static class Builder {
private String candidateUsed;
private String candidateActivated;
private boolean proxyError;
private boolean candidateError;
private String streamId; private String streamId;
private String dstAddr; private String dstAddr;
private Bytestream.Mode mode = Bytestream.Mode.tcp; private Bytestream.Mode mode = Bytestream.Mode.tcp;
@ -83,9 +100,29 @@ public class JingleSocks5BytestreamTransport extends JingleContentTransport {
return this; return this;
} }
public Builder setCandidateUsed(String candidateId) {
this.candidateUsed = candidateId;
return this;
}
public Builder setCandidateActivated(String candidateId) {
this.candidateActivated = candidateId;
return this;
}
public Builder setCandidateError() {
this.candidateError = true;
return this;
}
public Builder setProxyError() {
this.proxyError = true;
return this;
}
public JingleSocks5BytestreamTransport build() { public JingleSocks5BytestreamTransport build() {
StringUtils.requireNotNullOrEmpty(streamId, "sid MUST be neither null, nor empty."); StringUtils.requireNotNullOrEmpty(streamId, "sid MUST be neither null, nor empty.");
return new JingleSocks5BytestreamTransport(candidates, streamId, dstAddr, mode); return new JingleSocks5BytestreamTransport(candidates, streamId, dstAddr, mode, candidateUsed, candidateActivated, candidateError, proxyError);
} }
} }
} }

View file

@ -1,6 +1,5 @@
package org.jivesoftware.smackx.jingle_s5b.elements; package org.jivesoftware.smackx.jingle_s5b.elements;
import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
import org.jivesoftware.smack.util.Objects; import org.jivesoftware.smack.util.Objects;
@ -8,11 +7,10 @@ import org.jivesoftware.smack.util.XmlStringBuilder;
import org.jivesoftware.smackx.jingle.element.JingleContentTransportCandidate; import org.jivesoftware.smackx.jingle.element.JingleContentTransportCandidate;
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.Domainpart;
import org.jxmpp.stringprep.XmppStringprepException; import org.jxmpp.stringprep.XmppStringprepException;
/** /**
* Created by vanitas on 07.06.17. * TransportCandidate for Jingle Socks5Bytestream transports.
*/ */
public class JingleSocks5BytestreamTransportCandidate extends JingleContentTransportCandidate { public class JingleSocks5BytestreamTransportCandidate extends JingleContentTransportCandidate {
@ -94,7 +92,8 @@ public class JingleSocks5BytestreamTransportCandidate extends JingleContentTrans
@Override @Override
public CharSequence toXML() { public CharSequence toXML() {
XmlStringBuilder xml = new XmlStringBuilder(this); XmlStringBuilder xml = new XmlStringBuilder();
xml.halfOpenElement(this);
xml.attribute(ATTR_CID, cid); xml.attribute(ATTR_CID, cid);
xml.attribute(ATTR_HOST, host); xml.attribute(ATTR_HOST, host);
xml.attribute(ATTR_JID, jid); xml.attribute(ATTR_JID, jid);
@ -103,7 +102,8 @@ public class JingleSocks5BytestreamTransportCandidate extends JingleContentTrans
} }
xml.attribute(ATTR_PRIORITY, priority); xml.attribute(ATTR_PRIORITY, priority);
xml.optAttribute(ATTR_TYPE, type); xml.optAttribute(ATTR_TYPE, type);
xml.closeElement(this);
xml.closeEmptyElement();
return xml; return xml;
} }
@ -112,7 +112,6 @@ public class JingleSocks5BytestreamTransportCandidate extends JingleContentTrans
} }
public static class Builder { public static class Builder {
private String cid; private String cid;
private String host; private String host;
private Jid jid; private Jid jid;
@ -134,13 +133,7 @@ public class JingleSocks5BytestreamTransportCandidate extends JingleContentTrans
} }
public Builder setJid(String jid) throws XmppStringprepException { public Builder setJid(String jid) throws XmppStringprepException {
LOGGER.log(Level.INFO, "setJid");
try {
this.jid = JidCreate.from(jid); this.jid = JidCreate.from(jid);
} catch (XmppStringprepException | IllegalArgumentException e) {
this.jid = JidCreate.domainBareFrom(Domainpart.from(jid));
}
LOGGER.log(Level.INFO, "setJid result: " + this.jid);
return this; return this;
} }
@ -175,4 +168,55 @@ public class JingleSocks5BytestreamTransportCandidate extends JingleContentTrans
return new JingleSocks5BytestreamTransportCandidate(cid, host, jid, port, priority, type); return new JingleSocks5BytestreamTransportCandidate(cid, host, jid, port, priority, type);
} }
} }
public static class CandidateUsed extends JingleContentTransportCandidate {
public static final String ELEMENT = "candidate-used";
public static final String ATTR_CID = "cid";
private final String candidateId;
public CandidateUsed(String candidateId) {
this.candidateId = candidateId;
}
@Override
public CharSequence toXML() {
XmlStringBuilder xml = new XmlStringBuilder();
xml.halfOpenElement(this);
xml.attribute(ATTR_CID, candidateId);
xml.closeEmptyElement();
return xml;
}
}
public static class CandidateActivated extends JingleContentTransportCandidate {
public static final String ELEMENT = "candidate-activated";
public static final String ATTR_CID = "cid";
private final String candidateId;
public CandidateActivated(String candidateId) {
this.candidateId = candidateId;
}
@Override
public CharSequence toXML() {
XmlStringBuilder xml = new XmlStringBuilder();
xml.halfOpenElement(this);
xml.attribute(ATTR_CID, candidateId);
xml.closeEmptyElement();
return xml;
}
}
public static class CandidateError extends JingleContentTransportCandidate {
public static final String ELEMENT = "candidate-error";
@Override
public CharSequence toXML() {
return new XmlStringBuilder(this).closeEmptyElement();
}
}
} }

View file

@ -0,0 +1,8 @@
package org.jivesoftware.smackx.jingle_s5b.elements;
import org.jivesoftware.smack.util.XmlStringBuilder;
import org.jivesoftware.smackx.jingle.element.JingleContentTransportCandidate;
/**
* Created by vanitas on 07.06.17.
*/

View file

@ -28,24 +28,18 @@ public class JingleSocks5BytestreamTransportProvider extends JingleContentTransp
private static final Logger LOGGER = Logger.getLogger(JingleSocks5BytestreamTransportProvider.class.getName()); private static final Logger LOGGER = Logger.getLogger(JingleSocks5BytestreamTransportProvider.class.getName());
@Override @Override
public JingleSocks5BytestreamTransport parse(XmlPullParser parser, int initialDepth) throws Exception { public JingleSocks5BytestreamTransport parse(XmlPullParser parser, int initialDepth) throws Exception {
parser.next();
String namespace = JingleSocks5BytestreamTransport.NAMESPACE_V1; String namespace = JingleSocks5BytestreamTransport.NAMESPACE_V1;
JingleSocks5BytestreamTransport.Builder builder = JingleSocks5BytestreamTransport.getBuilder(); JingleSocks5BytestreamTransport.Builder builder = JingleSocks5BytestreamTransport.getBuilder();
int count = parser.getAttributeCount();
for (int i = 0; i < count; i++) {
LOGGER.log(Level.INFO, i + " " + parser.getNamespace() + " " + parser.getAttributeName(i));
LOGGER.log(Level.INFO, parser.getAttributeValue(parser.getNamespace(), parser.getAttributeName(i)));
}
String streamId = parser.getAttributeValue(null, JingleSocks5BytestreamTransport.ATTR_SID); String streamId = parser.getAttributeValue(null, JingleSocks5BytestreamTransport.ATTR_SID);
LOGGER.log(Level.INFO, "streamId: " + streamId); LOGGER.log(Level.INFO, "streamId: " + streamId);
builder.setStreamId(streamId); builder.setStreamId(streamId);
String dstAddr = parser.getAttributeValue(namespace, JingleSocks5BytestreamTransport.ATTR_DSTADDR); String dstAddr = parser.getAttributeValue(null, JingleSocks5BytestreamTransport.ATTR_DSTADDR);
LOGGER.log(Level.INFO, "dstAddr: " + dstAddr); LOGGER.log(Level.INFO, "dstAddr: " + dstAddr);
builder.setDestinationAddress(dstAddr); builder.setDestinationAddress(dstAddr);
String mode = parser.getAttributeValue(namespace, JingleSocks5BytestreamTransport.ATTR_MODE); String mode = parser.getAttributeValue(null, JingleSocks5BytestreamTransport.ATTR_MODE);
LOGGER.log(Level.INFO, "Mode: " + mode); LOGGER.log(Level.INFO, "Mode: " + mode);
if (mode != null) { if (mode != null) {
builder.setMode(mode.equals(udp.toString()) ? udp : tcp); builder.setMode(mode.equals(udp.toString()) ? udp : tcp);

View file

@ -82,5 +82,7 @@ public class JingleSocks5BytestreamTransportTest extends SmackTestSuite {
assertEquals(7625, candidate3.getPort()); assertEquals(7625, candidate3.getPort());
assertEquals(7878787, candidate3.getPriority()); assertEquals(7878787, candidate3.getPriority());
assertEquals(JingleSocks5BytestreamTransportCandidate.Type.proxy, candidate3.getType()); assertEquals(JingleSocks5BytestreamTransportCandidate.Type.proxy, candidate3.getType());
assertEquals(xml, transport.toXML().toString());
} }
} }