use of org.jivesoftware.smackx.jingle.element.Jingle in project Smack by igniterealtime.
the class JingleProviderTest method testParseUnknownJingleContentDescrption.
@ParameterizedTest
@EnumSource(SmackTestUtil.XmlPullParserKind.class)
public void testParseUnknownJingleContentDescrption(SmackTestUtil.XmlPullParserKind parserKind) throws XmlPullParserException, IOException, SmackParsingException {
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
CharSequence xml = createTestJingle(unknownJingleContentDescription);
Jingle jingle = SmackTestUtil.parse(xml, JingleProvider.class, parserKind);
JingleContentDescription jingleContentDescription = jingle.getSoleContentOrThrow().getDescription();
String parsedUnknownJingleContentDescriptionNamespace = jingleContentDescription.getNamespace();
assertEquals(unknownJingleContentDescriptionNamespace, parsedUnknownJingleContentDescriptionNamespace);
}
use of org.jivesoftware.smackx.jingle.element.Jingle in project Smack by igniterealtime.
the class JingleProviderTest method testParseUnknownJingleContentTransport.
@ParameterizedTest
@EnumSource(SmackTestUtil.XmlPullParserKind.class)
public void testParseUnknownJingleContentTransport(SmackTestUtil.XmlPullParserKind parserKind) throws XmlPullParserException, IOException, SmackParsingException {
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
CharSequence xml = createTestJingle(unknownJingleContentTransport);
Jingle jingle = SmackTestUtil.parse(xml, JingleProvider.class, parserKind);
JingleContentTransport jingleContentTransport = jingle.getSoleContentOrThrow().getTransport();
String parsedUnknownJingleContentTransportNamespace = jingleContentTransport.getNamespace();
assertEquals(unknownJingleContentTransportNamespace, parsedUnknownJingleContentTransportNamespace);
}
use of org.jivesoftware.smackx.jingle.element.Jingle in project Smack by igniterealtime.
the class JingleProviderTest method testReasonElementWithExtraElement.
@ParameterizedTest
@EnumSource(SmackTestUtil.XmlPullParserKind.class)
public void testReasonElementWithExtraElement(SmackTestUtil.XmlPullParserKind parserKind) throws XmlPullParserException, IOException, SmackParsingException {
String xml = "<iq from='juliet@capulet.lit/balcony'" + " id='le71fa63'" + " to='romeo@montague.lit/orchard'" + " type='set'>" + "<jingle xmlns='urn:xmpp:jingle:1'" + " action='session-terminate'" + " sid='a73sjjvkla37jfea'>" + "<reason>" + "<success/>" + "<my-element xmlns='https://example.org' foo='bar'/>" + "</reason>" + "</jingle>" + "</iq>";
Jingle jingle = SmackTestUtil.parse(xml, JingleProvider.class, parserKind);
JingleReason jingleReason = jingle.getReason();
assertEquals(JingleReason.Reason.success, jingleReason.asEnum());
XmlElement element = jingleReason.getElement();
// TODO: Use JUnit 5.8's assertInstanceOf when possible
// assertInstanceOf(StandardExtesionElement.class, extraElement);
assertTrue(element instanceof StandardExtensionElement);
StandardExtensionElement extraElement = (StandardExtensionElement) element;
assertEquals("https://example.org", extraElement.getNamespace());
assertEquals("bar", extraElement.getAttributes().get("foo"));
}
use of org.jivesoftware.smackx.jingle.element.Jingle in project Smack by igniterealtime.
the class JingleS5BTransportSession method initiateSession.
private void initiateSession() {
Socks5Proxy.getSocks5Proxy().addTransfer(createTransport().getDestinationAddress());
JingleContent content = jingleSession.getContents().get(0);
UsedCandidate usedCandidate = chooseFromProposedCandidates(theirProposal);
if (usedCandidate == null) {
ourChoice = CANDIDATE_FAILURE;
Jingle candidateError = transportManager().createCandidateError(jingleSession.getRemote(), jingleSession.getInitiator(), jingleSession.getSessionId(), content.getSenders(), content.getCreator(), content.getName(), theirProposal.getStreamId());
try {
jingleSession.getConnection().sendStanza(candidateError);
} catch (SmackException.NotConnectedException | InterruptedException e) {
LOGGER.log(Level.WARNING, "Could not send candidate-error.", e);
}
} else {
ourChoice = usedCandidate;
Jingle jingle = transportManager().createCandidateUsed(jingleSession.getRemote(), jingleSession.getInitiator(), jingleSession.getSessionId(), content.getSenders(), content.getCreator(), content.getName(), theirProposal.getStreamId(), ourChoice.candidate.getCandidateId());
try {
jingleSession.getConnection().sendIqRequestAndWaitForResponse(jingle);
} catch (InterruptedException | XMPPException.XMPPErrorException | SmackException.NotConnectedException | SmackException.NoResponseException e) {
LOGGER.log(Level.WARNING, "Could not send candidate-used.", e);
}
}
connectIfReady();
}
use of org.jivesoftware.smackx.jingle.element.Jingle in project Smack by igniterealtime.
the class JingleS5BTransportSession method connectIfReady.
/**
* Determine, which candidate (ours/theirs) is the nominated one.
* Connect to this candidate. If it is a proxy and it is ours, activate it and connect.
* If its a proxy and it is theirs, wait for activation.
* If it is not a proxy, just connect.
*/
private void connectIfReady() {
JingleContent content = jingleSession.getContents().get(0);
if (ourChoice == null || theirChoice == null) {
// Not yet ready.
LOGGER.log(Level.INFO, "Not ready.");
return;
}
if (ourChoice == CANDIDATE_FAILURE && theirChoice == CANDIDATE_FAILURE) {
LOGGER.log(Level.INFO, "Failure.");
jingleSession.onTransportMethodFailed(getNamespace());
return;
}
LOGGER.log(Level.INFO, "Ready.");
// Determine nominated candidate.
UsedCandidate nominated;
if (ourChoice != CANDIDATE_FAILURE && theirChoice != CANDIDATE_FAILURE) {
if (ourChoice.candidate.getPriority() > theirChoice.candidate.getPriority()) {
nominated = ourChoice;
} else if (ourChoice.candidate.getPriority() < theirChoice.candidate.getPriority()) {
nominated = theirChoice;
} else {
nominated = jingleSession.isInitiator() ? ourChoice : theirChoice;
}
} else if (ourChoice != CANDIDATE_FAILURE) {
nominated = ourChoice;
} else {
nominated = theirChoice;
}
if (nominated == theirChoice) {
LOGGER.log(Level.INFO, "Their choice, so our proposed candidate is used.");
boolean isProxy = nominated.candidate.getType() == JingleS5BTransportCandidate.Type.proxy;
try {
nominated = connectToOurCandidate(nominated.candidate);
} catch (InterruptedException | IOException | XMPPException | SmackException | TimeoutException e) {
LOGGER.log(Level.INFO, "Could not connect to our candidate.", e);
// TODO: Proxy-Error
return;
}
if (isProxy) {
LOGGER.log(Level.INFO, "Is external proxy. Activate it.");
Bytestream activate = new Bytestream(ourProposal.getStreamId());
activate.setMode(null);
activate.setType(IQ.Type.set);
activate.setTo(nominated.candidate.getJid());
activate.setToActivate(jingleSession.getRemote());
activate.setFrom(jingleSession.getLocal());
try {
jingleSession.getConnection().sendIqRequestAndWaitForResponse(activate);
} catch (InterruptedException | XMPPException.XMPPErrorException | SmackException.NotConnectedException | SmackException.NoResponseException e) {
LOGGER.log(Level.WARNING, "Could not activate proxy.", e);
return;
}
LOGGER.log(Level.INFO, "Send candidate-activate.");
Jingle candidateActivate = transportManager().createCandidateActivated(jingleSession.getRemote(), jingleSession.getInitiator(), jingleSession.getSessionId(), content.getSenders(), content.getCreator(), content.getName(), nominated.transport.getStreamId(), nominated.candidate.getCandidateId());
try {
jingleSession.getConnection().sendIqRequestAndWaitForResponse(candidateActivate);
} catch (InterruptedException | XMPPException.XMPPErrorException | SmackException.NotConnectedException | SmackException.NoResponseException e) {
LOGGER.log(Level.WARNING, "Could not send candidate-activated", e);
return;
}
}
LOGGER.log(Level.INFO, "Start transmission.");
Socks5BytestreamSession bs = new Socks5BytestreamSession(nominated.socket, !isProxy);
callback.onSessionInitiated(bs);
} else // Our choice
{
LOGGER.log(Level.INFO, "Our choice, so their candidate was used.");
boolean isProxy = nominated.candidate.getType() == JingleS5BTransportCandidate.Type.proxy;
if (!isProxy) {
LOGGER.log(Level.INFO, "Direct connection.");
Socks5BytestreamSession bs = new Socks5BytestreamSession(nominated.socket, true);
callback.onSessionInitiated(bs);
} else {
LOGGER.log(Level.INFO, "Our choice was their external proxy. wait for candidate-activate.");
}
}
}
Aggregations