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-07-17 20:18:08 +02:00
parent 59e79ef668
commit 7658369d63
Signed by: vanitasvitae
GPG key ID: 62BEE9264BF17311
26 changed files with 268 additions and 356 deletions

View file

@ -271,6 +271,11 @@ public class XmlStringBuilder implements Appendable, CharSequence {
return attribute(name, String.valueOf(value));
}
public XmlStringBuilder attribute(String name, long value) {
assert name != null;
return attribute(name, String.valueOf(value));
}
public XmlStringBuilder optAttribute(String name, String value) {
if (value != null) {
attribute(name, value);
@ -278,6 +283,13 @@ public class XmlStringBuilder implements Appendable, CharSequence {
return this;
}
public XmlStringBuilder optAttribute(String name, Long value) {
if (value != null) {
attribute(name, value);
}
return this;
}
/**
* Add a new attribute to this builder, with the {@link java.util.Date} instance as its value,
* which will get formated with {@link XmppDateTime#formatXEP0082Date(Date)}

View file

@ -33,8 +33,8 @@ import javax.crypto.spec.SecretKeySpec;
import org.jivesoftware.smack.Manager;
import org.jivesoftware.smack.XMPPConnection;
import org.jivesoftware.smack.packet.Element;
import org.jivesoftware.smack.packet.ExtensionElement;
import org.jivesoftware.smackx.jet.element.JetSecurityElement;
import org.jivesoftware.smackx.jingle.JingleManager;
import org.jivesoftware.smackx.jingle.JingleUtil;
import org.jivesoftware.smackx.jingle.element.Jingle;
@ -140,14 +140,25 @@ public final class JetManager extends Manager {
return null;
}
String contentName = JingleManager.randomId();
ExtensionElement encryptionExtension = encryptionMethod.encryptJingleTransfer(recipient, keyAndIv);
JetSecurityElement securityElement = new JetSecurityElement(contentName, encryptionExtension);
OutgoingJingleFileOffer offer = new OutgoingJingleFileOffer(connection(), recipient);
JingleFileTransferChild fileTransferChild = JingleFileTransferChild.getBuilder().setFile(file).build();
JingleFileTransfer fileTransfer = new JingleFileTransfer(Collections.<JingleContentDescriptionChildElement>singletonList(fileTransferChild));
Jingle initiate = jutil.createSessionInitiateFileOffer(recipient, JingleManager.randomId(), JingleContent.Creator.initiator,
JingleManager.randomId(), fileTransfer, offer.getTransportSession().createTransport(), Collections.<Element>singletonList(encryptionExtension));
JingleContent content = JingleContent.getBuilder()
.setCreator(JingleContent.Creator.initiator)
.setName(contentName)
.setTransport(offer.getTransportSession().createTransport())
.setSecurity(securityElement)
.setDescription(fileTransfer)
.build();
Jingle initiate = jutil.createSessionInitiate(recipient, JingleManager.randomId(), content);
return offer;
}

View file

@ -1,3 +1,19 @@
/**
*
* Copyright 2017 Paul Schaub
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jivesoftware.smackx.jet;
import java.io.File;

View file

@ -19,28 +19,30 @@ package org.jivesoftware.smackx.jet.element;
import org.jivesoftware.smack.packet.ExtensionElement;
import org.jivesoftware.smack.util.XmlStringBuilder;
import org.jivesoftware.smackx.jet.JetManager;
import org.jivesoftware.smackx.jingle.element.JingleContentSecurity;
/**
* Implementation of the Jingle security element as specified in XEP-XXXX (Jingle Encrypted Transfers).
* <jingle>
* <content>
* <description/>
* <transport/>
* <security/> <- You are here.
* </content>
* </jingle>
*/
public class SecurityElement implements ExtensionElement {
public static final String ELEMENT = "security";
public class JetSecurityElement extends JingleContentSecurity {
public static final String ATTR_NAME = "name";
public static final String ATTR_TYPE = "type";
private final ExtensionElement child;
private final String name;
public SecurityElement(String name, ExtensionElement child) {
public JetSecurityElement(String name, ExtensionElement child) {
this.name = name;
this.child = child;
}
@Override
public String getElementName() {
return ELEMENT;
}
@Override
public CharSequence toXML() {
XmlStringBuilder xml = new XmlStringBuilder(this);

View file

@ -24,20 +24,20 @@ import org.jivesoftware.smack.provider.ExtensionElementProvider;
import org.jivesoftware.smack.util.Objects;
import org.jivesoftware.smackx.jet.JetManager;
import org.jivesoftware.smackx.jet.JingleEncryptionMethodManager;
import org.jivesoftware.smackx.jet.element.SecurityElement;
import org.jivesoftware.smackx.jet.element.JetSecurityElement;
import org.xmlpull.v1.XmlPullParser;
/**
* Provider for the Jingle security element for XEP-XXXX (Jingle Encrypted Transfers).
*/
public class SecurityProvider extends ExtensionElementProvider<SecurityElement> {
private static final Logger LOGGER = Logger.getLogger(SecurityProvider.class.getName());
public class JetSecurityProvider extends ExtensionElementProvider<JetSecurityElement> {
private static final Logger LOGGER = Logger.getLogger(JetSecurityProvider.class.getName());
@Override
public SecurityElement parse(XmlPullParser parser, int initialDepth) throws Exception {
String name = parser.getAttributeValue(JetManager.NAMESPACE, SecurityElement.ATTR_NAME);
String type = parser.getAttributeValue(JetManager.NAMESPACE, SecurityElement.ATTR_TYPE);
public JetSecurityElement parse(XmlPullParser parser, int initialDepth) throws Exception {
String name = parser.getAttributeValue(JetManager.NAMESPACE, JetSecurityElement.ATTR_NAME);
String type = parser.getAttributeValue(JetManager.NAMESPACE, JetSecurityElement.ATTR_TYPE);
ExtensionElement child;
Objects.requireNonNull(type);
@ -48,10 +48,10 @@ public class SecurityProvider extends ExtensionElementProvider<SecurityElement>
if (encryptionElementProvider != null) {
child = encryptionElementProvider.parse(parser);
} else {
LOGGER.log(Level.WARNING, "Unknown child element in SecurityElement: " + type);
LOGGER.log(Level.WARNING, "Unknown child element in JetSecurityElement: " + type);
return null;
}
return new SecurityElement(name, child);
return new JetSecurityElement(name, child);
}
}

View file

@ -105,7 +105,7 @@ public class IncomingJingleFileOffer extends JingleFileTransferSession implement
if (transportManager == null) {
//No usable transports.
LOGGER.log(Level.WARNING, "No usable transports.");
jutil.sendSessionTerminateUnsupportedTransports(getInitiator(), getSessionId());
connection.createStanzaCollectorAndSend(jutil.createSessionTerminateUnsupportedTransports(getInitiator(), getSessionId()));
state = State.terminated;
return jutil.createAck(initiate);
}
@ -167,7 +167,7 @@ public class IncomingJingleFileOffer extends JingleFileTransferSession implement
LOGGER.log(Level.INFO, "Unsupported transport. Reject transport-replace.");
jutil.sendTransportReject(transportReplace.getFrom().asFullJidOrThrow(), transportReplace.getInitiator(),
transportReplace.getSid(), getContents().get(0).getCreator(),
getContents().get(0).getName(), transportReplace.getContents().get(0).getJingleTransport());
getContents().get(0).getName(), transportReplace.getContents().get(0).getTransport());
}
} catch (InterruptedException | XMPPException.XMPPErrorException | SmackException.NotConnectedException | SmackException.NoResponseException e) {
LOGGER.log(Level.SEVERE, "Help me please!", e);

View file

@ -184,7 +184,7 @@ public class OutgoingJingleFileOffer extends JingleFileTransferSession {
LOGGER.log(Level.INFO, "Unsupported transport. Reject transport-replace.");
jutil.sendTransportReject(transportReplace.getFrom().asFullJidOrThrow(), transportReplace.getInitiator(),
transportReplace.getSid(), getContents().get(0).getCreator(),
getContents().get(0).getName(), transportReplace.getContents().get(0).getJingleTransport());
getContents().get(0).getName(), transportReplace.getContents().get(0).getTransport());
}
} catch (InterruptedException | XMPPException.XMPPErrorException | SmackException.NotConnectedException | SmackException.NoResponseException e) {
LOGGER.log(Level.SEVERE, "Help me please!", e);

View file

@ -29,22 +29,22 @@ public class Range implements NamedElement {
public static final String ATTR_OFFSET = "offset";
public static final String ATTR_LENGTH = "length";
private final int offset, length;
private final Long offset, length;
private final HashElement hash;
/**
* Create a Range element with default values.
*/
public Range() {
this(0, -1, null);
this(null, null, null);
}
/**
* Create a Range element with specified length.
* @param length length of the transmitted data in bytes.
*/
public Range(int length) {
this(0, length, null);
public Range(Long length) {
this(null, length, null);
}
/**
@ -52,7 +52,7 @@ public class Range implements NamedElement {
* @param offset offset in bytes from the beginning of the transmitted data.
* @param length number of bytes that shall be transferred.
*/
public Range(int offset, int length) {
public Range(Long offset, Long length) {
this(offset, length, null);
}
@ -62,7 +62,7 @@ public class Range implements NamedElement {
* @param length number of bytes that shall be transferred.
* @param hash hash of the bytes in the specified range.
*/
public Range(int offset, int length, HashElement hash) {
public Range(Long offset, Long length, HashElement hash) {
this.offset = offset;
this.length = length;
this.hash = hash;
@ -73,7 +73,7 @@ public class Range implements NamedElement {
* This marks the begin of the specified range.
* @return offset
*/
public int getOffset() {
public Long getOffset() {
return offset;
}
@ -81,7 +81,7 @@ public class Range implements NamedElement {
* Return the length of the range.
* @return length
*/
public int getLength() {
public Long getLength() {
return length;
}
@ -102,12 +102,8 @@ public class Range implements NamedElement {
public CharSequence toXML() {
XmlStringBuilder sb = new XmlStringBuilder(this);
if (offset > 0) {
sb.attribute(ATTR_OFFSET, offset);
}
if (length > 0) {
sb.attribute(ATTR_LENGTH, length);
}
sb.optAttribute(ATTR_OFFSET, offset);
sb.optAttribute(ATTR_LENGTH, length);
if (hash != null) {
sb.rightAngleBracket();

View file

@ -20,6 +20,7 @@ import static org.xmlpull.v1.XmlPullParser.END_TAG;
import static org.xmlpull.v1.XmlPullParser.START_TAG;
import org.jivesoftware.smack.provider.ExtensionElementProvider;
import org.jivesoftware.smack.util.ParserUtils;
import org.jivesoftware.smackx.hashes.element.HashElement;
import org.jivesoftware.smackx.hashes.provider.HashElementProvider;
import org.jivesoftware.smackx.jingle.element.JingleContent;
@ -59,11 +60,9 @@ public class ChecksumProvider extends ExtensionElementProvider<Checksum> {
break;
case Range.ELEMENT:
String offset = parser.getAttributeValue(null, Range.ATTR_OFFSET);
String length = parser.getAttributeValue(null, Range.ATTR_LENGTH);
int o = offset == null ? 0 : Integer.parseInt(offset);
int l = length == null ? -1 : Integer.parseInt(length);
range = new Range(o, l);
Long offset = ParserUtils.getLongAttribute(parser, Range.ATTR_OFFSET);
Long length = ParserUtils.getLongAttribute(parser, Range.ATTR_LENGTH);
range = new Range(offset, length);
}
} else if (tag == END_TAG) {
switch (n) {

View file

@ -21,6 +21,7 @@ import static org.xmlpull.v1.XmlPullParser.START_TAG;
import java.util.ArrayList;
import org.jivesoftware.smack.util.ParserUtils;
import org.jivesoftware.smackx.hashes.element.HashElement;
import org.jivesoftware.smackx.hashes.provider.HashElementProvider;
import org.jivesoftware.smackx.jingle.element.JingleContentDescriptionChildElement;
@ -44,10 +45,7 @@ public class JingleFileTransferProvider
boolean inRange = false;
JingleFileTransferChild.Builder builder = JingleFileTransferChild.getBuilder();
HashElement inRangeHash = null;
int offset = 0;
int length = -1;
Long length = null, offset = null;
while (true) {
int tag = parser.nextTag();
@ -77,10 +75,8 @@ public class JingleFileTransferProvider
case Range.ELEMENT:
inRange = true;
String offsetString = parser.getAttributeValue(null, Range.ATTR_OFFSET);
String lengthString = parser.getAttributeValue(null, Range.ATTR_LENGTH);
offset = (offsetString != null ? Integer.parseInt(offsetString) : 0);
length = (lengthString != null ? Integer.parseInt(lengthString) : -1);
offset = ParserUtils.getLongAttribute(parser, Range.ATTR_OFFSET);
length = ParserUtils.getLongAttribute(parser, Range.ATTR_LENGTH);
if (parser.isEmptyElementTag()) {
inRange = false;

View file

@ -50,7 +50,7 @@ public class ChecksumTest extends SmackTestSuite {
assertXMLEqual(xml, checksum.toXML().toString());
assertXMLEqual(xml, new ChecksumProvider().parse(TestUtils.getParser(xml)).toXML().toString());
Range range = new Range(12,34);
Range range = new Range(12L,34L);
file = new JingleFileTransferChild(null, null, hash, null, null, -1, range);
checksum = new Checksum(JingleContent.Creator.initiator, "name", file);

View file

@ -118,7 +118,7 @@ public class JingleUtilFileTransferTest extends SmackTestSuite {
assertEquals(1337, file.getSize());
assertNull(file.getRange());
assertEquals(transport, content.getJingleTransport());
assertEquals(transport, content.getTransport());
assertEquals("transid", transport.getSessionId());
assertEquals(JingleIBBTransport.DEFAULT_BLOCK_SIZE, transport.getBlockSize());

View file

@ -83,7 +83,7 @@ public final class JingleTransportMethodManager extends Manager {
return null;
}
JingleContentTransport transport = content.getJingleTransport();
JingleContentTransport transport = content.getTransport();
if (transport == null) {
return null;
}

View file

@ -16,12 +16,10 @@
*/
package org.jivesoftware.smackx.jingle;
import java.util.Collections;
import java.util.List;
import org.jivesoftware.smack.SmackException;
import org.jivesoftware.smack.XMPPConnection;
import org.jivesoftware.smack.XMPPException;
import org.jivesoftware.smack.packet.Element;
import org.jivesoftware.smack.packet.IQ;
import org.jivesoftware.smack.packet.XMPPError;
import org.jivesoftware.smackx.jingle.element.Jingle;
@ -50,150 +48,68 @@ public class JingleUtil {
* XEP-0166 Example 10.
* @param recipient recipient of the stanza.
* @param sessionId sessionId
* @param contentCreator creator of the content.
* @param contentName name of the content.
* @param contentSenders sender of the content.
* @param description description of the content.
* @param transport used transport.
* @param content content
* @return session-initiate stanza.
*/
public Jingle createSessionInitiate(FullJid recipient,
String sessionId,
JingleContent.Creator contentCreator,
String contentName,
JingleContent.Senders contentSenders,
JingleContentDescription description,
JingleContentTransport transport,
List<Element> additionalElements) {
JingleContent content) {
return createSessionInitiate(recipient, sessionId, Collections.singletonList(content));
}
Jingle.Builder jb = Jingle.getBuilder();
jb.setAction(JingleAction.session_initiate)
public Jingle createSessionInitiate(FullJid recipient,
String sessionId,
List<JingleContent> contents) {
Jingle.Builder builder = Jingle.getBuilder();
builder.setAction(JingleAction.session_initiate)
.setSessionId(sessionId)
.setInitiator(connection.getUser());
JingleContent.Builder cb = JingleContent.getBuilder();
cb.setCreator(contentCreator)
.setName(contentName)
.setSenders(contentSenders)
.setDescription(description)
.setTransport(transport)
.addAdditionalElements(additionalElements);
for (JingleContent content : contents) {
builder.addJingleContent(content);
}
Jingle jingle = jb.addJingleContent(cb.build()).build();
Jingle jingle = builder.build();
jingle.setFrom(connection.getUser());
jingle.setTo(recipient);
return jingle;
}
/**
* Initiate a file transfer session.
* XEP-0234 Example 1.
* @param recipient recipient of the file transfer.
* @param sessionId sessionId.
* @param contentCreator creator of the content.
* @param contentName name of the content.
* @param description description of the content.
* @param transport used transport.
* @return session-initiate stanza.
*/
public Jingle createSessionInitiateFileOffer(FullJid recipient,
String sessionId,
JingleContent.Creator contentCreator,
String contentName,
JingleContentDescription description,
JingleContentTransport transport,
List<Element> additionalElements) {
return createSessionInitiate(recipient, sessionId, contentCreator, contentName,
JingleContent.Senders.initiator, description, transport, additionalElements);
}
public IQ sendSessionInitiateFileOffer(FullJid recipient,
String sessionId,
JingleContent.Creator contentCreator,
String contentName,
JingleContentDescription description,
JingleContentTransport transport,
List<Element> additionalElements)
throws SmackException.NotConnectedException, InterruptedException,
XMPPException.XMPPErrorException, SmackException.NoResponseException {
Jingle jingle = createSessionInitiateFileOffer(recipient, sessionId, contentCreator, contentName, description, transport, additionalElements);
return connection.createStanzaCollectorAndSend(jingle).nextResultOrThrow();
}
public IQ sendSessionInitiate(FullJid recipient,
String sessionId,
JingleContent.Creator contentCreator,
String contentName,
JingleContent.Senders contentSenders,
JingleContentDescription description,
JingleContentTransport transport,
List<Element> additionalElements)
throws SmackException.NotConnectedException, InterruptedException,
XMPPException.XMPPErrorException, SmackException.NoResponseException {
Jingle jingle = createSessionInitiate(recipient, sessionId, contentCreator, contentName, contentSenders,
description, transport, additionalElements);
return connection.createStanzaCollectorAndSend(jingle).nextResult();
}
/**
* Accept a session.
* XEP-0166 Example 17.
* @param recipient recipient of the stanza.
* @param sessionId sessionId.
* @param contentCreator creator of the content.
* @param contentName name of the content.
* @param contentSenders sender of the content.
* @param description description of the content.
* @param transport proposed transport.
* @param content content
* @return session-accept stanza.
*/
public Jingle createSessionAccept(FullJid recipient,
String sessionId,
JingleContent.Creator contentCreator,
String contentName,
JingleContent.Senders contentSenders,
JingleContentDescription description,
JingleContentTransport transport) {
JingleContent content) {
return createSessionAccept(recipient, sessionId, Collections.singletonList(content));
}
public Jingle createSessionAccept(FullJid recipient,
String sessionId,
List<JingleContent> contents) {
Jingle.Builder jb = Jingle.getBuilder();
jb.setResponder(connection.getUser())
.setAction(JingleAction.session_accept)
.setSessionId(sessionId);
JingleContent.Builder cb = JingleContent.getBuilder();
cb.setCreator(contentCreator)
.setName(contentName)
.setSenders(contentSenders)
.setDescription(description)
.setTransport(transport);
for (JingleContent content : contents) {
jb.addJingleContent(content);
}
Jingle jingle = jb.addJingleContent(cb.build()).build();
Jingle jingle = jb.build();
jingle.setTo(recipient);
jingle.setFrom(connection.getUser());
return jingle;
}
public IQ sendSessionAccept(FullJid recipient,
String sessionId,
JingleContent.Creator contentCreator,
String contentName,
JingleContent.Senders contentSenders,
JingleContentDescription description,
JingleContentTransport transport)
throws SmackException.NotConnectedException, InterruptedException,
XMPPException.XMPPErrorException, SmackException.NoResponseException {
Jingle jingle = createSessionAccept(recipient, sessionId, contentCreator, contentName, contentSenders,
description, transport);
return connection.createStanzaCollectorAndSend(jingle).nextResult();
}
/**
* Create a session-terminate stanza.
* XEP-0166 §6.7.
@ -227,22 +143,6 @@ public class JingleUtil {
return createSessionTerminate(recipient, sessionId, new JingleReason(reason));
}
private IQ sendSessionTerminate(FullJid recipient, String sessionId, JingleReason.Reason reason)
throws SmackException.NotConnectedException, InterruptedException,
XMPPException.XMPPErrorException, SmackException.NoResponseException {
return sendSessionTerminate(recipient, sessionId, new JingleReason(reason));
}
private IQ sendSessionTerminate(FullJid recipient, String sessionId, JingleReason reason)
throws SmackException.NotConnectedException, InterruptedException,
XMPPException.XMPPErrorException, SmackException.NoResponseException {
Jingle jingle = createSessionTerminate(recipient, sessionId, reason);
return connection.createStanzaCollectorAndSend(jingle).nextResultOrThrow();
}
/**
* Terminate the session by declining.
* XEP-0166 Example 21.
@ -254,14 +154,6 @@ public class JingleUtil {
return createSessionTerminate(recipient, sessionId, JingleReason.Reason.decline);
}
public IQ sendSessionTerminateDecline(FullJid recipient, String sessionId)
throws SmackException.NotConnectedException, InterruptedException,
XMPPException.XMPPErrorException, SmackException.NoResponseException {
Jingle jingle = createSessionTerminateDecline(recipient, sessionId);
return connection.createStanzaCollectorAndSend(jingle).nextResultOrThrow();
}
/**
* Terminate the session due to success.
* XEP-0166 Example 19.
@ -273,14 +165,6 @@ public class JingleUtil {
return createSessionTerminate(recipient, sessionId, JingleReason.Reason.success);
}
public IQ sendSessionTerminateSuccess(FullJid recipient, String sessionId)
throws InterruptedException, XMPPException.XMPPErrorException,
SmackException.NotConnectedException, SmackException.NoResponseException {
Jingle jingle = createSessionTerminateSuccess(recipient, sessionId);
return connection.createStanzaCollectorAndSend(jingle).nextResultOrThrow();
}
/**
* Terminate the session due to being busy.
* XEP-0166 Example 20.
@ -292,14 +176,6 @@ public class JingleUtil {
return createSessionTerminate(recipient, sessionId, JingleReason.Reason.busy);
}
public IQ sendSessionTerminateBusy(FullJid recipient, String sessionId)
throws InterruptedException, XMPPException.XMPPErrorException,
SmackException.NotConnectedException, SmackException.NoResponseException {
Jingle jingle = createSessionTerminateBusy(recipient, sessionId);
return connection.createStanzaCollectorAndSend(jingle).nextResultOrThrow();
}
/**
* Terminate the session due to the existence of an alternative session.
* XEP-0166 Example 22.
@ -312,14 +188,6 @@ public class JingleUtil {
return createSessionTerminate(recipient, sessionId, JingleReason.AlternativeSession(altSessionId));
}
public IQ sendSessionTerminateAlternativeSession(FullJid recipient, String sessionId, String altSessionId)
throws InterruptedException, XMPPException.XMPPErrorException,
SmackException.NotConnectedException, SmackException.NoResponseException {
Jingle jingle = createSessionTerminateAlternativeSession(recipient, sessionId, altSessionId);
return connection.createStanzaCollectorAndSend(jingle).nextResultOrThrow();
}
/**
* Cancel all active transfers of the session.
* XEP-0234 Example 9.
@ -331,15 +199,6 @@ public class JingleUtil {
return createSessionTerminate(recipient, sessionId, JingleReason.Reason.cancel);
}
public IQ sendSessionTerminateCancel(FullJid recipient,
String sessionId)
throws InterruptedException, XMPPException.XMPPErrorException,
SmackException.NotConnectedException, SmackException.NoResponseException {
Jingle jingle = createSessionTerminateCancel(recipient, sessionId);
return connection.createStanzaCollectorAndSend(jingle).nextResultOrThrow();
}
/**
* Cancel a single contents transfer.
* XEP-0234 Example 10.
@ -365,14 +224,6 @@ public class JingleUtil {
return jingle;
}
public IQ sendSessionTerminateContentCancel(FullJid recipient, String sessionId,
JingleContent.Creator contentCreator, String contentName)
throws SmackException.NotConnectedException, InterruptedException,
XMPPException.XMPPErrorException, SmackException.NoResponseException {
Jingle jingle = createSessionTerminateContentCancel(recipient, sessionId, contentCreator, contentName);
return connection.createStanzaCollectorAndSend(jingle).nextResultOrThrow();
}
/**
* Terminate the session due to unsupported transport methods.
* XEP-0166 Example 23.
@ -384,13 +235,6 @@ public class JingleUtil {
return createSessionTerminate(recipient, sessionId, JingleReason.Reason.unsupported_transports);
}
public IQ sendSessionTerminateUnsupportedTransports(FullJid recipient, String sessionId)
throws InterruptedException, XMPPException.XMPPErrorException,
SmackException.NotConnectedException, SmackException.NoResponseException {
Jingle jingle = createSessionTerminateUnsupportedTransports(recipient, sessionId);
return connection.createStanzaCollectorAndSend(jingle).nextResultOrThrow();
}
/**
* Terminate the session due to failed transports.
* XEP-0166 Example 24.
@ -402,13 +246,6 @@ public class JingleUtil {
return createSessionTerminate(recipient, sessionId, JingleReason.Reason.failed_transport);
}
public IQ sendSessionTerminateFailedTransport(FullJid recipient, String sessionId)
throws InterruptedException, XMPPException.XMPPErrorException,
SmackException.NotConnectedException, SmackException.NoResponseException {
Jingle jingle = createSessionTerminateFailedTransport(recipient, sessionId);
return connection.createStanzaCollectorAndSend(jingle).nextResultOrThrow();
}
/**
* Terminate the session due to unsupported applications.
* XEP-0166 Example 25.
@ -420,13 +257,6 @@ public class JingleUtil {
return createSessionTerminate(recipient, sessionId, JingleReason.Reason.unsupported_applications);
}
public IQ sendSessionTerminateUnsupportedApplications(FullJid recipient, String sessionId)
throws InterruptedException, XMPPException.XMPPErrorException,
SmackException.NotConnectedException, SmackException.NoResponseException {
Jingle jingle = createSessionTerminateUnsupportedApplications(recipient, sessionId);
return connection.createStanzaCollectorAndSend(jingle).nextResultOrThrow();
}
/**
* Terminate the session due to failed application.
* XEP-0166 Example 26.
@ -438,13 +268,6 @@ public class JingleUtil {
return createSessionTerminate(recipient, sessionId, JingleReason.Reason.failed_application);
}
public IQ sendSessionTerminateFailedApplication(FullJid recipient, String sessionId)
throws InterruptedException, XMPPException.XMPPErrorException,
SmackException.NotConnectedException, SmackException.NoResponseException {
Jingle jingle = createSessionTerminateFailedApplication(recipient, sessionId);
return connection.createStanzaCollectorAndSend(jingle).nextResultOrThrow();
}
/**
* Terminate session due to incompatible parameters.
* XEP-0166 Example 27.
@ -456,13 +279,6 @@ public class JingleUtil {
return createSessionTerminate(recipient, sessionId, JingleReason.Reason.incompatible_parameters);
}
public IQ sendSessionTerminateIncompatibleParameters(FullJid recipient, String sessionId)
throws InterruptedException, XMPPException.XMPPErrorException,
SmackException.NotConnectedException, SmackException.NoResponseException {
Jingle jingle = createSessionTerminateIncompatibleParameters(recipient, sessionId);
return connection.createStanzaCollectorAndSend(jingle).nextResultOrThrow();
}
public IQ sendContentRejectFileNotAvailable(FullJid recipient, String sessionId, JingleContentDescription description) {
return null; //TODO Later
}
@ -486,13 +302,6 @@ public class JingleUtil {
return jingle;
}
public IQ sendSessionPing(FullJid recipient, String sessionId)
throws SmackException.NotConnectedException, InterruptedException,
XMPPException.XMPPErrorException, SmackException.NoResponseException {
Jingle jingle = createSessionPing(recipient, sessionId);
return connection.createStanzaCollectorAndSend(jingle).nextResultOrThrow();
}
/**
* Acknowledge the receipt of a stanza.
* XEP-0166 Example 5.
@ -503,10 +312,6 @@ public class JingleUtil {
return IQ.createResultIQ(jingle);
}
public void sendAck(Jingle jingle) throws SmackException.NotConnectedException, InterruptedException {
connection.sendStanza(createAck(jingle));
}
/**
* Replace a transport with another one.
* XEP-0260 Example 15.
@ -536,15 +341,6 @@ public class JingleUtil {
return jingle;
}
public IQ sendTransportReplace(FullJid recipient, FullJid initiator, String sessionId,
JingleContent.Creator contentCreator, String contentName,
JingleContentTransport transport)
throws SmackException.NotConnectedException, InterruptedException,
XMPPException.XMPPErrorException, SmackException.NoResponseException {
Jingle jingle = createTransportReplace(recipient, initiator, sessionId, contentCreator, contentName, transport);
return connection.createStanzaCollectorAndSend(jingle).nextResultOrThrow();
}
/**
* Accept a transport.
* XEP-0260 Example 17.
@ -574,15 +370,6 @@ public class JingleUtil {
return jingle;
}
public IQ sendTransportAccept(FullJid recipient, FullJid initiator, String sessionId,
JingleContent.Creator contentCreator, String contentName,
JingleContentTransport transport)
throws SmackException.NotConnectedException, InterruptedException,
XMPPException.XMPPErrorException, SmackException.NoResponseException {
Jingle jingle = createTransportAccept(recipient, initiator, sessionId, contentCreator, contentName, transport);
return connection.createStanzaCollectorAndSend(jingle).nextResultOrThrow();
}
/**
* Reject a transport.
* XEP-0166 §7.2.14.
@ -612,15 +399,6 @@ public class JingleUtil {
return jingle;
}
public IQ sendTransportReject(FullJid recipient, FullJid initiator, String sessionId,
JingleContent.Creator contentCreator, String contentName,
JingleContentTransport transport)
throws SmackException.NotConnectedException, InterruptedException,
XMPPException.XMPPErrorException, SmackException.NoResponseException {
Jingle jingle = createTransportReject(recipient, initiator, sessionId, contentCreator, contentName, transport);
return connection.createStanzaCollectorAndSend(jingle).nextResultOrThrow();
}
/*
* ####################################################################################################
*/
@ -638,11 +416,6 @@ public class JingleUtil {
return IQ.createErrorResponse(request, error);
}
public void sendErrorUnknownSession(Jingle request)
throws SmackException.NotConnectedException, InterruptedException {
connection.sendStanza(createErrorUnknownSession(request));
}
/**
* Create an error response to a request coming from a unknown initiator.
* XEP-0166 Example 12.
@ -654,11 +427,6 @@ public class JingleUtil {
return IQ.createErrorResponse(request, b);
}
public void sendErrorUnknownInitiator(Jingle request)
throws SmackException.NotConnectedException, InterruptedException {
connection.sendStanza(createErrorUnknownInitiator(request));
}
/**
* Create an error response to a request with an unsupported info.
* XEP-0166 Example 31.
@ -672,11 +440,6 @@ public class JingleUtil {
return IQ.createErrorResponse(request, error);
}
public void sendErrorUnsupportedInfo(Jingle request)
throws SmackException.NotConnectedException, InterruptedException {
connection.sendStanza(createErrorUnsupportedInfo(request));
}
/**
* Create an error response to a tie-breaking request.
* XEP-0166 Example 34.
@ -690,11 +453,6 @@ public class JingleUtil {
return IQ.createErrorResponse(request, error);
}
public void sendErrorTieBreak(Jingle request)
throws SmackException.NotConnectedException, InterruptedException {
connection.sendStanza(createErrorTieBreak(request));
}
/**
* Create an error response to a request that was out of order.
* TODO: Find example.
@ -708,11 +466,6 @@ public class JingleUtil {
return IQ.createErrorResponse(request, error);
}
public void sendErrorOutOfOrder(Jingle request)
throws SmackException.NotConnectedException, InterruptedException {
connection.sendStanza(createErrorOutOfOrder(request));
}
/**
* Create an error response to a malformed request.
* XEP-0166 Ex. 16
@ -725,9 +478,4 @@ public class JingleUtil {
error.setCondition(XMPPError.Condition.bad_request);
return IQ.createErrorResponse(request, error);
}
public void sendErrorMalformedRequest(Jingle request)
throws SmackException.NotConnectedException, InterruptedException {
connection.sendStanza(createErrorMalformedRequest(request));
}
}

View file

@ -16,10 +16,6 @@
*/
package org.jivesoftware.smackx.jingle.element;
import java.util.ArrayList;
import java.util.List;
import org.jivesoftware.smack.packet.Element;
import org.jivesoftware.smack.packet.NamedElement;
import org.jivesoftware.smack.util.Objects;
import org.jivesoftware.smack.util.StringUtils;
@ -27,6 +23,11 @@ import org.jivesoftware.smack.util.XmlStringBuilder;
/**
* Jingle content element.
* <jingle>
* <content> <- Me.
* ...
* </content>
* </jingle>
*/
public final class JingleContent implements NamedElement {
@ -72,22 +73,20 @@ public final class JingleContent implements NamedElement {
private final JingleContentTransport transport;
private final List<Element> additionalElements = new ArrayList<>();
private final JingleContentSecurity security;
/**
* Creates a content description..
*/
private JingleContent(Creator creator, String disposition, String name, Senders senders,
JingleContentDescription description, JingleContentTransport transport, List<Element> additionalElements) {
JingleContentDescription description, JingleContentTransport transport, JingleContentSecurity security) {
this.creator = Objects.requireNonNull(creator, "Jingle content creator must not be null");
this.disposition = disposition;
this.name = StringUtils.requireNotNullOrEmpty(name, "Jingle content name must not be null or empty");
this.senders = senders;
this.description = description;
this.transport = transport;
if (additionalElements != null) {
this.additionalElements.addAll(additionalElements);
}
this.security = security;
}
public Creator getCreator() {
@ -120,12 +119,12 @@ public final class JingleContent implements NamedElement {
*
* @return an Iterator for the JingleTransports in the packet.
*/
public JingleContentTransport getJingleTransport() {
public JingleContentTransport getTransport() {
return transport;
}
public List<Element> getAdditionalElements() {
return additionalElements;
public JingleContentSecurity getSecurity() {
return security;
}
@Override
@ -144,10 +143,7 @@ public final class JingleContent implements NamedElement {
xml.optAppend(description);
xml.optElement(transport);
for (Element element : additionalElements) {
xml.element(element);
}
xml.optElement(security);
xml.closeElement(this);
return xml;
@ -170,7 +166,7 @@ public final class JingleContent implements NamedElement {
private JingleContentTransport transport;
private List<Element> additionalElements = new ArrayList<>();
private JingleContentSecurity security;
private Builder() {
}
@ -208,15 +204,13 @@ public final class JingleContent implements NamedElement {
return this;
}
public Builder addAdditionalElements(List<Element> elements) {
if (elements != null) {
additionalElements.addAll(elements);
}
public Builder setSecurity(JingleContentSecurity element) {
this.security = element;
return this;
}
public JingleContent build() {
return new JingleContent(creator, disposition, name, senders, description, transport, additionalElements);
return new JingleContent(creator, disposition, name, senders, description, transport, security);
}
}
}

View file

@ -24,6 +24,13 @@ import org.jivesoftware.smack.util.XmlStringBuilder;
/**
* Jingle content description.
* <jingle>
* <content>
* <description/> <- This element is us.
* <transport/>
* <security/>
* </content>
* </jingle>
*
*/
public abstract class JingleContentDescription implements ExtensionElement {

View file

@ -20,6 +20,15 @@ import org.jivesoftware.smack.packet.NamedElement;
/**
* An element found usually in 'description' elements.
* <jingle>
* <content>
* <description>
* <XYZ/> <- We live here.
* </description>
* <transport/>
* <security/>
* </content>
* </jingle>
*
*/
public abstract class JingleContentDescriptionChildElement implements NamedElement {

View file

@ -0,0 +1,40 @@
/**
*
* Copyright 2017 Paul Schaub
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jivesoftware.smackx.jingle.element;
import org.jivesoftware.smack.packet.ExtensionElement;
/**
* Jingle security element.
* <jingle>
* <content>
* <description/>
* <transport/>
* <security/> <- That's me :)
* </content>
* </jingle>
*/
public abstract class JingleContentSecurity implements ExtensionElement {
public static final String ELEMENT = "security";
@Override
public String getElementName() {
return ELEMENT;
}
}

View file

@ -24,6 +24,13 @@ import org.jivesoftware.smack.util.XmlStringBuilder;
/**
* A jingle transport extension.
* <jingle>
* <content>
* <description/>
* <transport/> <- Voila.
* <security/>
* </content>
* </jingle>
*
*/
public abstract class JingleContentTransport implements ExtensionElement {

View file

@ -20,6 +20,15 @@ import org.jivesoftware.smack.packet.NamedElement;
/**
* An element found usually in Jingle 'transport' elements.
* <jingle>
* <content>
* <description/>
* <transport>
* <candidate/> <- We are those guys.
* <candidate/> <-/
* </transport>
* </content>
* </jingle>
*
*/
public abstract class JingleContentTransportCandidate implements NamedElement {

View file

@ -20,6 +20,17 @@ import org.jivesoftware.smack.packet.NamedElement;
/**
* Abstract JingleContentTransportInfo element.
* The JingleContentTransportInfo element can have certain states defined by the respective Transport XEP.
* Examples are Jingle Socks5Bytestream's <candidate-used/> (Example 5), <candidate-error/> (Example 7) etc.
* <jingle>
* <content>
* <description/>
* <transport>
* <xyz/> <- This is us.
* </transport>
* <security/>
* </content>
* </jingle>
*/
public abstract class JingleContentTransportInfo implements NamedElement {

View file

@ -41,7 +41,7 @@ public abstract class JingleTransportSession<T extends JingleContentTransport> {
}
JingleContent content = jingle.getContents().get(0);
JingleContentTransport t = content.getJingleTransport();
JingleContentTransport t = content.getTransport();
if (t != null && t.getNamespace().equals(getNamespace())) {
setTheirProposal(t);

View file

@ -189,7 +189,7 @@ public class JingleS5BTransportSession extends JingleTransportSession<JingleS5BT
@Override
public IQ handleTransportInfo(Jingle transportInfo) {
JingleS5BTransportInfo info = (JingleS5BTransportInfo) transportInfo.getContents().get(0).getJingleTransport().getInfo();
JingleS5BTransportInfo info = (JingleS5BTransportInfo) transportInfo.getContents().get(0).getTransport().getInfo();
switch (info.getElementName()) {
case JingleS5BTransportInfo.CandidateUsed.ELEMENT:
@ -209,7 +209,7 @@ public class JingleS5BTransportSession extends JingleTransportSession<JingleS5BT
}
public IQ handleCandidateUsed(Jingle jingle) {
JingleS5BTransportInfo info = (JingleS5BTransportInfo) jingle.getContents().get(0).getJingleTransport().getInfo();
JingleS5BTransportInfo info = (JingleS5BTransportInfo) jingle.getContents().get(0).getTransport().getInfo();
String candidateId = ((JingleS5BTransportInfo.CandidateUsed) info).getCandidateId();
theirChoice = new UsedCandidate(ourProposal, ourProposal.getCandidate(candidateId), null);

View file

@ -0,0 +1,13 @@
package org.jivesoftware.smackx.jingle3;
import java.util.ArrayList;
import org.jivesoftware.smackx.jingle.element.JingleContent;
/**
* Created by vanitas on 17.07.17.
*/
public class JingleSession {
private final ArrayList<JingleContent> contents
}

View file

@ -0,0 +1,42 @@
package org.jivesoftware.smackx.jingle3;
import org.jivesoftware.smackx.jingle.element.JingleContent;
import org.jivesoftware.smackx.jingle.element.JingleContentDescription;
import org.jivesoftware.smackx.jingle.element.JingleContentSecurity;
import org.jivesoftware.smackx.jingle.element.JingleContentTransport;
/**
* Internal class that holds the state of a content in a modifiable form.
*/
public class JingleSessionContent {
private JingleContent.Creator creator;
private String name;
private JingleContent.Senders senders;
private JingleContentDescription description;
private JingleContentTransport transport;
private JingleContentSecurity security;
public JingleContent.Creator getCreator() {
return creator;
}
public String getName() {
return name;
}
public JingleContent.Senders getSenders() {
return senders;
}
public JingleContentDescription getDescription() {
return description;
}
public JingleContentTransport getTransport() {
return transport;
}
public JingleContentSecurity getSecurity() {
return security;
}
}

View file

@ -252,7 +252,7 @@ public class ContentNegotiator extends JingleNegotiator {
// // with the audio payload type and the transport
// // candidate
// result.setDescription(new JingleDescription.Audio(new PayloadType(bestCommonAudioPt)));
// result.addJingleTransport(this.getTransportNegotiator().getJingleTransport(bestRemoteCandidate));
// result.addJingleTransport(this.getTransportNegotiator().getTransport(bestRemoteCandidate));
if (mediaNeg != null) {
result.setDescription(mediaNeg.getJingleDescription());
}