mirror of
https://github.com/vanitasvitae/Smack.git
synced 2025-09-10 17:49:38 +02:00
Merge flowdalic/master
This commit is contained in:
commit
9712dc1df7
40 changed files with 714 additions and 544 deletions
|
@ -20,6 +20,7 @@ import java.util.Collections;
|
|||
import java.util.List;
|
||||
|
||||
import org.jivesoftware.smack.packet.ExtensionElement;
|
||||
import org.jivesoftware.smack.packet.NamedElement;
|
||||
import org.jivesoftware.smack.util.XmlStringBuilder;
|
||||
|
||||
/**
|
||||
|
@ -37,9 +38,9 @@ public abstract class JingleContentDescriptionElement implements ExtensionElemen
|
|||
|
||||
public static final String ELEMENT = "description";
|
||||
|
||||
private final List<JingleContentDescriptionChildElement> payloads;
|
||||
private final List<NamedElement> payloads;
|
||||
|
||||
protected JingleContentDescriptionElement(List<JingleContentDescriptionChildElement> payloads) {
|
||||
protected JingleContentDescriptionElement(List<? extends NamedElement> payloads) {
|
||||
if (payloads != null) {
|
||||
this.payloads = Collections.unmodifiableList(payloads);
|
||||
}
|
||||
|
@ -53,7 +54,7 @@ public abstract class JingleContentDescriptionElement implements ExtensionElemen
|
|||
return ELEMENT;
|
||||
}
|
||||
|
||||
public List<JingleContentDescriptionChildElement> getJingleContentDescriptionChildren() {
|
||||
public List<NamedElement> getJingleContentDescriptionChildren() {
|
||||
return payloads;
|
||||
}
|
||||
|
||||
|
@ -66,7 +67,7 @@ public abstract class JingleContentDescriptionElement implements ExtensionElemen
|
|||
}
|
||||
|
||||
@Override
|
||||
public final XmlStringBuilder toXML() {
|
||||
public XmlStringBuilder toXML() {
|
||||
XmlStringBuilder xml = new XmlStringBuilder(this);
|
||||
addExtraAttributes(xml);
|
||||
xml.rightAngleBracket();
|
||||
|
|
|
@ -115,9 +115,8 @@ public final class JingleContentElement implements NamedElement {
|
|||
}
|
||||
|
||||
/**
|
||||
* Returns an Iterator for the JingleTransports in the packet.
|
||||
*
|
||||
* @return an Iterator for the JingleTransports in the packet.
|
||||
* Return the transport of the content.
|
||||
* @return transport.
|
||||
*/
|
||||
public JingleContentTransportElement getTransport() {
|
||||
return transport;
|
||||
|
|
|
@ -72,7 +72,7 @@ public abstract class JingleContentTransportElement implements ExtensionElement
|
|||
}
|
||||
|
||||
@Override
|
||||
public final XmlStringBuilder toXML() {
|
||||
public XmlStringBuilder toXML() {
|
||||
XmlStringBuilder xml = new XmlStringBuilder(this);
|
||||
addExtraAttributes(xml);
|
||||
|
||||
|
|
|
@ -136,6 +136,18 @@ public final class JingleElement extends IQ {
|
|||
return contents;
|
||||
}
|
||||
|
||||
public JingleContentElement getSoleContentOrThrow() {
|
||||
if (contents.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (contents.size() == 1) {
|
||||
return contents.get(0);
|
||||
}
|
||||
|
||||
throw new IllegalStateException("More than one content is present.");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected IQChildElementXmlStringBuilder getIQChildElementBuilder(IQChildElementXmlStringBuilder xml) {
|
||||
xml.optAttribute(INITIATOR_ATTRIBUTE_NAME, getInitiator());
|
||||
|
|
|
@ -0,0 +1,49 @@
|
|||
/**
|
||||
*
|
||||
* Copyright 2017 Florian Schmaus, 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.StandardExtensionElement;
|
||||
import org.jivesoftware.smack.util.XmlStringBuilder;
|
||||
|
||||
public final class UnknownJingleContentDescriptionElement extends JingleContentDescriptionElement {
|
||||
|
||||
private final StandardExtensionElement standardExtensionElement;
|
||||
|
||||
public UnknownJingleContentDescriptionElement(StandardExtensionElement standardExtensionElement) {
|
||||
super(standardExtensionElement.getElements());
|
||||
this.standardExtensionElement = standardExtensionElement;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getElementName() {
|
||||
return standardExtensionElement.getElementName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getNamespace() {
|
||||
return standardExtensionElement.getNamespace();
|
||||
}
|
||||
|
||||
@Override
|
||||
public XmlStringBuilder toXML() {
|
||||
return standardExtensionElement.toXML();
|
||||
}
|
||||
|
||||
public StandardExtensionElement getStandardExtensionElement() {
|
||||
return standardExtensionElement;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,61 @@
|
|||
/**
|
||||
*
|
||||
* Copyright 2017 Florian Schmaus, 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 java.util.List;
|
||||
|
||||
import org.jivesoftware.smack.packet.StandardExtensionElement;
|
||||
import org.jivesoftware.smack.util.XmlStringBuilder;
|
||||
|
||||
public final class UnknownJingleContentTransportElement extends JingleContentTransportElement {
|
||||
|
||||
private final StandardExtensionElement standardExtensionElement;
|
||||
|
||||
public UnknownJingleContentTransportElement(StandardExtensionElement standardExtensionElement) {
|
||||
super(null, null);
|
||||
this.standardExtensionElement = standardExtensionElement;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getElementName() {
|
||||
return standardExtensionElement.getElementName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getNamespace() {
|
||||
return standardExtensionElement.getNamespace();
|
||||
}
|
||||
|
||||
@Override
|
||||
public XmlStringBuilder toXML() {
|
||||
return standardExtensionElement.toXML();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<JingleContentTransportCandidateElement> getCandidates() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public JingleContentTransportInfoElement getInfo() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
public StandardExtensionElement getStandardExtensionElement() {
|
||||
return standardExtensionElement;
|
||||
}
|
||||
}
|
|
@ -18,16 +18,19 @@ package org.jivesoftware.smackx.jingle.provider;
|
|||
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import org.jivesoftware.smack.packet.StandardExtensionElement;
|
||||
import org.jivesoftware.smack.parsing.StandardExtensionElementProvider;
|
||||
import org.jivesoftware.smack.provider.IQProvider;
|
||||
import org.jivesoftware.smack.util.ParserUtils;
|
||||
import org.jivesoftware.smackx.jingle.JingleManager;
|
||||
import org.jivesoftware.smackx.jingle.element.JingleAction;
|
||||
import org.jivesoftware.smackx.jingle.element.JingleContentDescriptionElement;
|
||||
import org.jivesoftware.smackx.jingle.element.JingleContentElement;
|
||||
import org.jivesoftware.smackx.jingle.element.JingleContentSecurityElement;
|
||||
import org.jivesoftware.smackx.jingle.element.JingleContentTransportElement;
|
||||
import org.jivesoftware.smackx.jingle.element.JingleElement;
|
||||
import org.jivesoftware.smackx.jingle.element.JingleReasonElement;
|
||||
import org.jivesoftware.smackx.jingle.element.UnknownJingleContentDescriptionElement;
|
||||
import org.jivesoftware.smackx.jingle.element.UnknownJingleContentTransportElement;
|
||||
|
||||
import org.jxmpp.jid.FullJid;
|
||||
import org.xmlpull.v1.XmlPullParser;
|
||||
|
@ -117,48 +120,45 @@ public class JingleProvider extends IQProvider<JingleElement> {
|
|||
outerloop: while (true) {
|
||||
int eventType = parser.next();
|
||||
switch (eventType) {
|
||||
case XmlPullParser.START_TAG:
|
||||
String tagName = parser.getName();
|
||||
String namespace = parser.getNamespace();
|
||||
switch (tagName) {
|
||||
case JingleContentDescriptionElement.ELEMENT: {
|
||||
JingleContentDescriptionProvider<?> provider = JingleManager.getJingleDescriptionProvider(namespace);
|
||||
if (provider == null) {
|
||||
// TODO handle this case (DefaultExtensionElement wrapped in something?)
|
||||
break;
|
||||
}
|
||||
JingleContentDescriptionElement description = provider.parse(parser);
|
||||
builder.setDescription(description);
|
||||
break;
|
||||
}
|
||||
case JingleContentTransportElement.ELEMENT: {
|
||||
JingleContentTransportProvider<?> provider = JingleManager.getJingleTransportProvider(namespace);
|
||||
if (provider == null) {
|
||||
// TODO handle this case (DefaultExtensionElement wrapped in something?)
|
||||
break;
|
||||
}
|
||||
JingleContentTransportElement transport = provider.parse(parser);
|
||||
builder.setTransport(transport);
|
||||
break;
|
||||
}
|
||||
case JingleContentSecurityElement.ELEMENT: {
|
||||
JingleContentSecurityProvider<?> provider = JingleManager.getJingleSecurityProvider(namespace);
|
||||
if (provider == null) {
|
||||
//TODO: handle this case (see above)
|
||||
}
|
||||
JingleContentSecurityElement security = provider.parse(parser);
|
||||
builder.setSecurity(security);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
LOGGER.severe("Unknown Jingle content element: " + tagName);
|
||||
break;
|
||||
case XmlPullParser.START_TAG:
|
||||
String tagName = parser.getName();
|
||||
String namespace = parser.getNamespace();
|
||||
switch (tagName) {
|
||||
case JingleContentDescriptionElement.ELEMENT: {
|
||||
JingleContentDescriptionElement description;
|
||||
JingleContentDescriptionProvider<?> provider = JingleManager.getJingleDescriptionProvider(namespace);
|
||||
if (provider == null) {
|
||||
StandardExtensionElement standardExtensionElement = StandardExtensionElementProvider.INSTANCE.parse(parser);
|
||||
description = new UnknownJingleContentDescriptionElement(standardExtensionElement);
|
||||
}
|
||||
else {
|
||||
description = provider.parse(parser);
|
||||
}
|
||||
builder.setDescription(description);
|
||||
break;
|
||||
case XmlPullParser.END_TAG:
|
||||
if (parser.getDepth() == initialDepth) {
|
||||
break outerloop;
|
||||
}
|
||||
case JingleContentTransportElement.ELEMENT: {
|
||||
JingleContentTransportElement transport;
|
||||
JingleContentTransportProvider<?> provider = JingleManager.getJingleTransportProvider(namespace);
|
||||
if (provider == null) {
|
||||
StandardExtensionElement standardExtensionElement = StandardExtensionElementProvider.INSTANCE.parse(parser);
|
||||
transport = new UnknownJingleContentTransportElement(standardExtensionElement);
|
||||
}
|
||||
else {
|
||||
transport = provider.parse(parser);
|
||||
}
|
||||
builder.setTransport(transport);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
LOGGER.severe("Unknown Jingle content element: " + tagName);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case XmlPullParser.END_TAG:
|
||||
if (parser.getDepth() == initialDepth) {
|
||||
break outerloop;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -65,7 +65,7 @@ public final class JingleS5BTransportManager extends Manager implements JingleTr
|
|||
private List<Bytestream.StreamHost> localStreamHosts = null;
|
||||
private List<Bytestream.StreamHost> availableStreamHosts = null;
|
||||
|
||||
private static boolean useLocalCandidates = false;
|
||||
private static boolean useLocalCandidates = true;
|
||||
private static boolean useExternalCandidates = true;
|
||||
|
||||
static {
|
||||
|
@ -222,19 +222,19 @@ public final class JingleS5BTransportManager extends Manager implements JingleTr
|
|||
}
|
||||
|
||||
JingleElement createCandidateUsed(JingleS5BTransport transport, JingleS5BTransportCandidate candidate) {
|
||||
return createTransportInfo(transport, JingleS5BTransportInfoElement.CandidateUsed(candidate.getCandidateId()));
|
||||
return createTransportInfo(transport, new JingleS5BTransportInfoElement.CandidateUsed(candidate.getCandidateId()));
|
||||
}
|
||||
|
||||
JingleElement createCandidateError(JingleS5BTransport transport) {
|
||||
return createTransportInfo(transport, JingleS5BTransportInfoElement.CandidateError());
|
||||
return createTransportInfo(transport, JingleS5BTransportInfoElement.CandidateError.INSTANCE);
|
||||
}
|
||||
|
||||
JingleElement createProxyError(JingleS5BTransport transport) {
|
||||
return createTransportInfo(transport, JingleS5BTransportInfoElement.ProxyError());
|
||||
return createTransportInfo(transport, JingleS5BTransportInfoElement.ProxyError.INSTANCE);
|
||||
}
|
||||
|
||||
JingleElement createCandidateActivated(JingleS5BTransport transport, JingleS5BTransportCandidate candidate) {
|
||||
return createTransportInfo(transport, JingleS5BTransportInfoElement.CandidateActivated(candidate.getCandidateId()));
|
||||
return createTransportInfo(transport, new JingleS5BTransportInfoElement.CandidateActivated(candidate.getCandidateId()));
|
||||
}
|
||||
|
||||
public static void setUseLocalCandidates(boolean localCandidates) {
|
||||
|
|
|
@ -135,5 +135,23 @@ public class JingleS5BTransportElement extends JingleContentTransportElement {
|
|||
public JingleS5BTransportElement build() {
|
||||
return new JingleS5BTransportElement(streamId, candidates, info, dstAddr, mode);
|
||||
}
|
||||
|
||||
public Builder setCandidateUsed(String candidateId) {
|
||||
return setTransportInfo(new JingleS5BTransportInfoElement.CandidateUsed(candidateId));
|
||||
}
|
||||
|
||||
public Builder setCandidateActivated(String candidateId) {
|
||||
return setTransportInfo(new JingleS5BTransportInfoElement.CandidateActivated(candidateId));
|
||||
}
|
||||
|
||||
public Builder setCandidateError() {
|
||||
return setTransportInfo(JingleS5BTransportInfoElement.CandidateError.INSTANCE);
|
||||
}
|
||||
|
||||
public Builder setProxyError() {
|
||||
return setTransportInfo(JingleS5BTransportInfoElement.ProxyError.INSTANCE);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -24,112 +24,76 @@ import org.jivesoftware.smackx.jingle.element.JingleContentTransportInfoElement;
|
|||
*/
|
||||
public abstract class JingleS5BTransportInfoElement extends JingleContentTransportInfoElement {
|
||||
|
||||
private static CandidateError CEI;
|
||||
private static ProxyError PEI;
|
||||
|
||||
public static CandidateUsed CandidateUsed(String candidateId) {
|
||||
return new CandidateUsed(candidateId);
|
||||
}
|
||||
|
||||
public static CandidateActivated CandidateActivated(String candidateId) {
|
||||
return new CandidateActivated(candidateId);
|
||||
}
|
||||
|
||||
public static CandidateError CandidateError() {
|
||||
if (CEI == null) {
|
||||
CEI = new CandidateError();
|
||||
}
|
||||
return CEI;
|
||||
}
|
||||
|
||||
public static ProxyError ProxyError() {
|
||||
if (PEI == null) {
|
||||
PEI = new ProxyError();
|
||||
}
|
||||
return PEI;
|
||||
}
|
||||
|
||||
public static final class CandidateActivated extends JingleS5BTransportInfoElement {
|
||||
public static final String ELEMENT = "candidate-activated";
|
||||
public static abstract class JingleS5BCandidateTransportInfoElement extends JingleS5BTransportInfoElement {
|
||||
public static final String ATTR_CID = "cid";
|
||||
|
||||
private final String candidateId;
|
||||
|
||||
protected JingleS5BCandidateTransportInfoElement(String candidateId) {
|
||||
this.candidateId = candidateId;
|
||||
}
|
||||
|
||||
public final String getCandidateId() {
|
||||
return candidateId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final XmlStringBuilder toXML() {
|
||||
XmlStringBuilder xml = new XmlStringBuilder();
|
||||
xml.halfOpenElement(this);
|
||||
xml.attribute(ATTR_CID, getCandidateId());
|
||||
xml.closeEmptyElement();
|
||||
return xml;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final boolean equals(Object other) {
|
||||
if (!(other instanceof JingleS5BCandidateTransportInfoElement)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
JingleS5BCandidateTransportInfoElement otherCandidateTransportInfo = (JingleS5BCandidateTransportInfoElement) other;
|
||||
return toXML().equals(otherCandidateTransportInfo.toXML());
|
||||
}
|
||||
|
||||
@Override
|
||||
public final int hashCode() {
|
||||
return getCandidateId().hashCode();
|
||||
}
|
||||
}
|
||||
|
||||
public static final class CandidateActivated extends JingleS5BCandidateTransportInfoElement {
|
||||
public static final String ELEMENT = "candidate-activated";
|
||||
|
||||
public CandidateActivated(String candidateId) {
|
||||
this.candidateId = candidateId;
|
||||
}
|
||||
|
||||
public String getCandidateId() {
|
||||
return candidateId;
|
||||
super(candidateId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getElementName() {
|
||||
return ELEMENT;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CharSequence toXML() {
|
||||
XmlStringBuilder xml = new XmlStringBuilder();
|
||||
xml.halfOpenElement(this);
|
||||
xml.attribute(ATTR_CID, candidateId);
|
||||
xml.closeEmptyElement();
|
||||
return xml;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object other) {
|
||||
return other instanceof CandidateActivated &&
|
||||
((CandidateActivated) other).getCandidateId().equals(candidateId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return toXML().toString().hashCode();
|
||||
}
|
||||
}
|
||||
|
||||
public static final class CandidateUsed extends JingleS5BTransportInfoElement {
|
||||
public static final String ELEMENT = "candidate-used";
|
||||
public static final String ATTR_CID = "cid";
|
||||
|
||||
private final String candidateId;
|
||||
public static final class CandidateUsed extends JingleS5BCandidateTransportInfoElement {
|
||||
public static final String ELEMENT = "candidate-used";
|
||||
|
||||
public CandidateUsed(String candidateId) {
|
||||
this.candidateId = candidateId;
|
||||
}
|
||||
|
||||
public String getCandidateId() {
|
||||
return candidateId;
|
||||
super(candidateId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getElementName() {
|
||||
return ELEMENT;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CharSequence toXML() {
|
||||
XmlStringBuilder xml = new XmlStringBuilder();
|
||||
xml.halfOpenElement(this);
|
||||
xml.attribute(ATTR_CID, candidateId);
|
||||
xml.closeEmptyElement();
|
||||
return xml;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object other) {
|
||||
return other instanceof CandidateUsed &&
|
||||
((CandidateUsed) other).getCandidateId().equals(candidateId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return toXML().toString().hashCode();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static final class CandidateError extends JingleS5BTransportInfoElement {
|
||||
|
||||
public static final CandidateError INSTANCE = new CandidateError();
|
||||
|
||||
public static final String ELEMENT = "candidate-error";
|
||||
|
||||
private CandidateError() {
|
||||
|
@ -142,7 +106,7 @@ public abstract class JingleS5BTransportInfoElement extends JingleContentTranspo
|
|||
}
|
||||
|
||||
@Override
|
||||
public CharSequence toXML() {
|
||||
public XmlStringBuilder toXML() {
|
||||
XmlStringBuilder xml = new XmlStringBuilder();
|
||||
xml.halfOpenElement(this);
|
||||
xml.closeEmptyElement();
|
||||
|
@ -151,7 +115,7 @@ public abstract class JingleS5BTransportInfoElement extends JingleContentTranspo
|
|||
|
||||
@Override
|
||||
public boolean equals(Object other) {
|
||||
return other instanceof CandidateError;
|
||||
return other == INSTANCE;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -160,7 +124,10 @@ public abstract class JingleS5BTransportInfoElement extends JingleContentTranspo
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
public static final class ProxyError extends JingleS5BTransportInfoElement {
|
||||
public static final ProxyError INSTANCE = new ProxyError();
|
||||
|
||||
public static final String ELEMENT = "proxy-error";
|
||||
|
||||
private ProxyError() {
|
||||
|
@ -173,7 +140,7 @@ public abstract class JingleS5BTransportInfoElement extends JingleContentTranspo
|
|||
}
|
||||
|
||||
@Override
|
||||
public CharSequence toXML() {
|
||||
public XmlStringBuilder toXML() {
|
||||
XmlStringBuilder xml = new XmlStringBuilder();
|
||||
xml.halfOpenElement(this);
|
||||
xml.closeEmptyElement();
|
||||
|
@ -182,7 +149,7 @@ public abstract class JingleS5BTransportInfoElement extends JingleContentTranspo
|
|||
|
||||
@Override
|
||||
public boolean equals(Object other) {
|
||||
return other instanceof ProxyError;
|
||||
return other == INSTANCE;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -85,23 +85,23 @@ public class JingleS5BTransportProvider extends JingleContentTransportProvider<J
|
|||
break;
|
||||
|
||||
case JingleS5BTransportInfoElement.CandidateActivated.ELEMENT:
|
||||
builder.setTransportInfo(JingleS5BTransportInfoElement.CandidateActivated(
|
||||
builder.setTransportInfo(new JingleS5BTransportInfoElement.CandidateActivated(
|
||||
parser.getAttributeValue(null,
|
||||
JingleS5BTransportInfoElement.CandidateActivated.ATTR_CID)));
|
||||
JingleS5BTransportInfoElement.JingleS5BCandidateTransportInfoElement.ATTR_CID)));
|
||||
break;
|
||||
|
||||
case JingleS5BTransportInfoElement.CandidateUsed.ELEMENT:
|
||||
builder.setTransportInfo(JingleS5BTransportInfoElement.CandidateUsed(
|
||||
builder.setTransportInfo(new JingleS5BTransportInfoElement.CandidateUsed(
|
||||
parser.getAttributeValue(null,
|
||||
JingleS5BTransportInfoElement.CandidateUsed.ATTR_CID)));
|
||||
JingleS5BTransportInfoElement.JingleS5BCandidateTransportInfoElement.ATTR_CID)));
|
||||
break;
|
||||
|
||||
case JingleS5BTransportInfoElement.CandidateError.ELEMENT:
|
||||
builder.setTransportInfo(JingleS5BTransportInfoElement.CandidateError());
|
||||
builder.setTransportInfo(JingleS5BTransportInfoElement.CandidateError.INSTANCE);
|
||||
break;
|
||||
|
||||
case JingleS5BTransportInfoElement.ProxyError.ELEMENT:
|
||||
builder.setTransportInfo(JingleS5BTransportInfoElement.ProxyError());
|
||||
builder.setTransportInfo(JingleS5BTransportInfoElement.ProxyError.INSTANCE);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,12 +14,13 @@
|
|||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.jivesoftware.smackx.jingle;
|
||||
package org.jivesoftware.smackx.jingle.provider;
|
||||
|
||||
import static junit.framework.TestCase.assertEquals;
|
||||
import static junit.framework.TestCase.assertNull;
|
||||
|
||||
import org.jivesoftware.smack.test.util.SmackTestSuite;
|
||||
import org.jivesoftware.smackx.jingle.JingleManager;
|
||||
import org.jivesoftware.smackx.jingle.transport.jingle_ibb.JingleIBBTransport;
|
||||
import org.jivesoftware.smackx.jingle.transport.jingle_ibb.provider.JingleIBBTransportProvider;
|
||||
import org.jivesoftware.smackx.jingle.transport.jingle_s5b.JingleS5BTransport;
|
|
@ -0,0 +1,121 @@
|
|||
/**
|
||||
*
|
||||
* Copyright 2017 Florian Schmaus, 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.provider;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import org.jivesoftware.smack.util.PacketParserUtils;
|
||||
import org.jivesoftware.smackx.jingle.element.JingleContentDescriptionElement;
|
||||
import org.jivesoftware.smackx.jingle.element.JingleContentTransportElement;
|
||||
import org.jivesoftware.smackx.jingle.element.JingleElement;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.xmlpull.v1.XmlPullParser;
|
||||
import org.xmlpull.v1.XmlPullParserException;
|
||||
|
||||
public class JingleProviderTest {
|
||||
|
||||
@Test
|
||||
public void testParseUnknownJingleContentDescrption() throws Exception {
|
||||
final String unknownJingleContentDescriptionNamespace = "urn:xmpp:jingle:unknown-description:5";
|
||||
final String unknownJingleContentDescription =
|
||||
// @formatter:off
|
||||
"<description xmlns='" + unknownJingleContentDescriptionNamespace + "'>" +
|
||||
"<file>" +
|
||||
"<date>1969-07-21T02:56:15Z</date>" +
|
||||
"<desc>This is a test. If this were a real file...</desc>" +
|
||||
"<media-type>text/plain</media-type>" +
|
||||
"<name>test.txt</name>" +
|
||||
"<range/>" +
|
||||
"<size>6144</size>" +
|
||||
"<hash xmlns='urn:xmpp:hashes:2'" +
|
||||
" algo='sha-1'>w0mcJylzCn+AfvuGdqkty2+KP48=</hash>" +
|
||||
"</file>" +
|
||||
"</description>";
|
||||
// @formatter:on
|
||||
XmlPullParser parser = createTestJingle(unknownJingleContentDescription);
|
||||
JingleElement jingle = (JingleElement) PacketParserUtils.parseIQ(parser);
|
||||
|
||||
JingleContentDescriptionElement jingleContentDescription = jingle.getSoleContentOrThrow().getDescription();
|
||||
|
||||
String parsedUnknownJingleContentDescrptionNamespace = jingleContentDescription.getNamespace();
|
||||
assertEquals(unknownJingleContentDescriptionNamespace, parsedUnknownJingleContentDescrptionNamespace);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testParseUnknownJingleContentTransport() throws Exception {
|
||||
final String unknownJingleContentTransportNamespace = "urn:xmpp:jingle:unknown-transport:foo:1";
|
||||
final String unknownJingleContentTransport =
|
||||
// @formatter:off
|
||||
"<transport xmlns='" + unknownJingleContentTransportNamespace + "'" +
|
||||
" mode='tcp'" +
|
||||
" sid='vj3hs98y'>" +
|
||||
"<candidate cid='hft54dqy'" +
|
||||
" host='192.168.4.1'" +
|
||||
" jid='romeo@montague.example/dr4hcr0st3lup4c'" +
|
||||
" port='5086'" +
|
||||
" priority='8257636'" +
|
||||
" type='direct'/>" +
|
||||
"<candidate cid='hutr46fe'" +
|
||||
" host='24.24.24.1'" +
|
||||
" jid='romeo@montague.example/dr4hcr0st3lup4c'" +
|
||||
" port='5087'" +
|
||||
" priority='8258636'" +
|
||||
" type='direct'/>" +
|
||||
"</transport>";
|
||||
// @formatter:on
|
||||
XmlPullParser parser = createTestJingle(unknownJingleContentTransport);
|
||||
JingleElement jingle = (JingleElement) PacketParserUtils.parseIQ(parser);
|
||||
|
||||
JingleContentTransportElement jingleContentTransport = jingle.getSoleContentOrThrow().getTransport();
|
||||
|
||||
String parsedUnknownJingleContentTransportNamespace = jingleContentTransport.getNamespace();
|
||||
assertEquals(unknownJingleContentTransportNamespace, parsedUnknownJingleContentTransportNamespace);
|
||||
}
|
||||
|
||||
private static XmlPullParser createTestJingle(String... childs) throws XmlPullParserException, IOException {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append(// @formatter:off
|
||||
"<iq from='romeo@montague.example/dr4hcr0st3lup4c'" +
|
||||
" id='nzu25s8'" +
|
||||
" to='juliet@capulet.example/yn0cl4bnw0yr3vym'" +
|
||||
" type='set'>" +
|
||||
"<jingle xmlns='urn:xmpp:jingle:1' " +
|
||||
" action='session-initiate' " +
|
||||
" initiator='romeo@montague.example/dr4hcr0st3lup4c' " +
|
||||
" sid='851ba2'>" +
|
||||
"<content creator='initiator' name='a-file-offer' senders='initiator'>"
|
||||
// @formatter:on
|
||||
);
|
||||
for (String child : childs) {
|
||||
sb.append(child);
|
||||
}
|
||||
sb.append(// @formatter:off
|
||||
"</content>" +
|
||||
"</jingle>" +
|
||||
"</iq>"
|
||||
// @formatter:on
|
||||
);
|
||||
|
||||
String jingleStanza = sb.toString();
|
||||
|
||||
XmlPullParser parser = PacketParserUtils.getParserFor(jingleStanza);
|
||||
return parser;
|
||||
}
|
||||
}
|
|
@ -163,7 +163,7 @@ public class JingleS5BTransportTest extends SmackTestSuite {
|
|||
assertNull(candidateErrorTransport.getDestinationAddress());
|
||||
assertNotNull(candidateErrorTransport.getInfo());
|
||||
assertEquals("vj3hs98y", candidateErrorTransport.getSid());
|
||||
assertEquals(JingleS5BTransportInfoElement.CandidateError(),
|
||||
assertEquals(JingleS5BTransportInfoElement.CandidateError.INSTANCE,
|
||||
candidateErrorTransport.getInfo());
|
||||
assertEquals(candidateError, candidateErrorTransport.toXML().toString());
|
||||
|
||||
|
@ -177,7 +177,7 @@ public class JingleS5BTransportTest extends SmackTestSuite {
|
|||
assertNotNull(proxyErrorTransport.getInfo());
|
||||
assertNotNull(candidateErrorTransport.getInfo());
|
||||
assertEquals("vj3hs98y", proxyErrorTransport.getSid());
|
||||
assertEquals(JingleS5BTransportInfoElement.ProxyError(),
|
||||
assertEquals(JingleS5BTransportInfoElement.ProxyError.INSTANCE,
|
||||
proxyErrorTransport.getInfo());
|
||||
assertEquals(proxyError, proxyErrorTransport.toXML().toString());
|
||||
|
||||
|
@ -188,7 +188,7 @@ public class JingleS5BTransportTest extends SmackTestSuite {
|
|||
JingleS5BTransportElement candidateUsedTransport = new JingleS5BTransportProvider()
|
||||
.parse(TestUtils.getParser(candidateUsed));
|
||||
assertNotNull(candidateUsedTransport.getInfo());
|
||||
assertEquals(JingleS5BTransportInfoElement.CandidateUsed("hr65dqyd"),
|
||||
assertEquals(new JingleS5BTransportInfoElement.CandidateUsed("hr65dqyd"),
|
||||
candidateUsedTransport.getInfo());
|
||||
assertEquals("hr65dqyd",
|
||||
((JingleS5BTransportInfoElement.CandidateUsed)
|
||||
|
@ -204,7 +204,7 @@ public class JingleS5BTransportTest extends SmackTestSuite {
|
|||
assertNotNull(candidateActivatedTransport.getInfo());
|
||||
assertNotNull(candidateErrorTransport.getInfo());
|
||||
|
||||
assertEquals(JingleS5BTransportInfoElement.CandidateActivated("hr65dqyd"),
|
||||
assertEquals(new JingleS5BTransportInfoElement.CandidateActivated("hr65dqyd"),
|
||||
candidateActivatedTransport.getInfo());
|
||||
assertEquals("hr65dqyd",
|
||||
((JingleS5BTransportInfoElement.CandidateActivated)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue