2007-03-03 06:20:17 +01:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
* Copyright 2003-2005 Jive Software.
|
|
|
|
*
|
2014-02-17 18:57:38 +01:00
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
2007-03-03 06:20:17 +01:00
|
|
|
* 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.
|
|
|
|
*/
|
2014-08-20 00:25:57 +02:00
|
|
|
package org.jivesoftware.smackx.jingleold.provider;
|
2007-01-04 18:25:30 +01:00
|
|
|
|
2014-10-07 21:15:20 +02:00
|
|
|
import java.io.IOException;
|
|
|
|
|
2019-02-15 23:21:30 +01:00
|
|
|
import org.jivesoftware.smack.packet.XmlEnvironment;
|
2015-02-26 18:41:17 +01:00
|
|
|
import org.jivesoftware.smack.provider.ExtensionElementProvider;
|
2019-05-06 22:06:13 +02:00
|
|
|
import org.jivesoftware.smack.xml.XmlPullParser;
|
|
|
|
import org.jivesoftware.smack.xml.XmlPullParserException;
|
2017-06-14 17:12:43 +02:00
|
|
|
|
2014-08-20 00:25:57 +02:00
|
|
|
import org.jivesoftware.smackx.jingleold.nat.ICECandidate;
|
|
|
|
import org.jivesoftware.smackx.jingleold.nat.TransportCandidate;
|
|
|
|
import org.jivesoftware.smackx.jingleold.packet.JingleTransport;
|
|
|
|
import org.jivesoftware.smackx.jingleold.packet.JingleTransport.JingleTransportCandidate;
|
2017-06-14 17:12:43 +02:00
|
|
|
|
2007-01-04 18:25:30 +01:00
|
|
|
/**
|
2015-03-29 12:15:32 +02:00
|
|
|
* Provider for a Jingle transport element.
|
2007-01-04 18:25:30 +01:00
|
|
|
*
|
2017-12-25 12:51:41 +01:00
|
|
|
* @author Alvaro Saurin
|
2007-01-04 18:25:30 +01:00
|
|
|
*/
|
2015-02-26 18:41:17 +01:00
|
|
|
public abstract class JingleTransportProvider extends ExtensionElementProvider<JingleTransport> {
|
2007-01-04 18:25:30 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Obtain the corresponding TransportNegotiator instance.
|
|
|
|
*
|
|
|
|
* @return a new TransportNegotiator instance
|
|
|
|
*/
|
|
|
|
protected JingleTransport getInstance() {
|
|
|
|
return new JingleTransport();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Parse a iq/jingle/transport element.
|
|
|
|
*
|
|
|
|
* @param parser the structure to parse
|
|
|
|
* @return a transport element.
|
2019-08-30 12:08:30 +02:00
|
|
|
* @throws IOException if an I/O error occured.
|
|
|
|
* @throws XmlPullParserException if an error in the XML parser occured.
|
2007-01-04 18:25:30 +01:00
|
|
|
*/
|
2014-10-07 21:15:20 +02:00
|
|
|
@Override
|
2019-02-15 23:21:30 +01:00
|
|
|
public JingleTransport parse(XmlPullParser parser, int initialDepth, XmlEnvironment xmlEnvironment) throws XmlPullParserException, IOException {
|
2007-01-04 18:25:30 +01:00
|
|
|
boolean done = false;
|
|
|
|
JingleTransport trans = getInstance();
|
|
|
|
|
|
|
|
while (!done) {
|
2019-05-06 22:06:13 +02:00
|
|
|
XmlPullParser.Event eventType = parser.next();
|
2007-01-04 18:25:30 +01:00
|
|
|
String name = parser.getName();
|
|
|
|
|
2019-05-06 22:06:13 +02:00
|
|
|
if (eventType == XmlPullParser.Event.START_ELEMENT) {
|
2007-01-04 18:25:30 +01:00
|
|
|
if (name.equals(JingleTransportCandidate.NODENAME)) {
|
|
|
|
JingleTransportCandidate jtc = parseCandidate(parser);
|
|
|
|
if (jtc != null) trans.addCandidate(jtc);
|
2007-01-30 00:45:13 +01:00
|
|
|
}
|
|
|
|
else {
|
2019-02-05 10:41:50 +01:00
|
|
|
// TODO: Should be SmackParseException.
|
|
|
|
throw new IOException("Unknown tag \"" + name + "\" in transport element.");
|
2007-01-04 18:25:30 +01:00
|
|
|
}
|
2007-01-30 00:45:13 +01:00
|
|
|
}
|
2019-05-06 22:06:13 +02:00
|
|
|
else if (eventType == XmlPullParser.Event.END_ELEMENT) {
|
2007-01-04 18:25:30 +01:00
|
|
|
if (name.equals(JingleTransport.NODENAME)) {
|
|
|
|
done = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return trans;
|
|
|
|
}
|
|
|
|
|
2018-03-28 14:02:21 +02:00
|
|
|
protected abstract JingleTransportCandidate parseCandidate(XmlPullParser parser);
|
2007-01-04 18:25:30 +01:00
|
|
|
|
|
|
|
/**
|
2015-03-29 12:15:32 +02:00
|
|
|
* RTP-ICE profile.
|
2007-01-04 18:25:30 +01:00
|
|
|
*/
|
|
|
|
public static class Ice extends JingleTransportProvider {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Defauls constructor.
|
|
|
|
*/
|
|
|
|
public Ice() {
|
|
|
|
super();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Obtain the corresponding TransportNegotiator.Ice instance.
|
|
|
|
*
|
|
|
|
* @return a new TransportNegotiator.Ice instance
|
|
|
|
*/
|
2017-02-11 16:16:41 +01:00
|
|
|
@Override
|
2007-01-04 18:25:30 +01:00
|
|
|
protected JingleTransport getInstance() {
|
|
|
|
return new JingleTransport.Ice();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Parse a iq/jingle/transport/candidate element.
|
|
|
|
*
|
|
|
|
* @param parser the structure to parse
|
|
|
|
* @return a candidate element
|
|
|
|
*/
|
2017-02-11 16:16:41 +01:00
|
|
|
@Override
|
2014-10-07 21:15:20 +02:00
|
|
|
protected JingleTransportCandidate parseCandidate(XmlPullParser parser) {
|
2007-02-22 20:14:18 +01:00
|
|
|
ICECandidate mt = new ICECandidate();
|
2007-01-04 18:25:30 +01:00
|
|
|
|
|
|
|
String channel = parser.getAttributeValue("", "channel");
|
|
|
|
String generation = parser.getAttributeValue("", "generation");
|
|
|
|
String ip = parser.getAttributeValue("", "ip");
|
|
|
|
String name = parser.getAttributeValue("", "name");
|
|
|
|
String network = parser.getAttributeValue("", "network");
|
|
|
|
String username = parser.getAttributeValue("", "username");
|
|
|
|
String password = parser.getAttributeValue("", "password");
|
|
|
|
String port = parser.getAttributeValue("", "port");
|
|
|
|
String preference = parser.getAttributeValue("", "preference");
|
|
|
|
String proto = parser.getAttributeValue("", "proto");
|
2007-01-30 00:45:13 +01:00
|
|
|
String type = parser.getAttributeValue("", "type");
|
2007-01-04 18:25:30 +01:00
|
|
|
|
|
|
|
if (channel != null) {
|
|
|
|
mt.setChannel(new TransportCandidate.Channel(channel));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (generation != null) {
|
|
|
|
try {
|
|
|
|
mt.setGeneration(Integer.parseInt(generation));
|
2007-01-30 00:45:13 +01:00
|
|
|
}
|
|
|
|
catch (Exception e) {
|
2007-01-04 18:25:30 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ip != null) {
|
|
|
|
mt.setIp(ip);
|
2007-01-30 00:45:13 +01:00
|
|
|
}
|
|
|
|
else {
|
2007-01-04 18:25:30 +01:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (name != null) {
|
|
|
|
mt.setName(name);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (network != null) {
|
|
|
|
try {
|
|
|
|
mt.setNetwork(Integer.parseInt(network));
|
2007-01-30 00:45:13 +01:00
|
|
|
}
|
|
|
|
catch (Exception e) {
|
2007-01-04 18:25:30 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (username != null) {
|
|
|
|
mt.setUsername(username);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (password != null) {
|
|
|
|
mt.setPassword(password);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (port != null) {
|
|
|
|
try {
|
|
|
|
mt.setPort(Integer.parseInt(port));
|
2007-01-30 00:45:13 +01:00
|
|
|
}
|
|
|
|
catch (Exception e) {
|
2007-01-04 18:25:30 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (preference != null) {
|
|
|
|
try {
|
|
|
|
mt.setPreference(Integer.parseInt(preference));
|
2007-01-30 00:45:13 +01:00
|
|
|
}
|
|
|
|
catch (Exception e) {
|
2007-01-04 18:25:30 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (proto != null) {
|
|
|
|
mt.setProto(new TransportCandidate.Protocol(proto));
|
|
|
|
}
|
|
|
|
|
2007-01-30 00:45:13 +01:00
|
|
|
if (type != null) {
|
2007-04-16 17:44:55 +02:00
|
|
|
mt.setType(ICECandidate.Type.valueOf(type));
|
2007-01-30 00:45:13 +01:00
|
|
|
}
|
|
|
|
|
2007-01-04 18:25:30 +01:00
|
|
|
return new JingleTransport.Ice.Candidate(mt);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2015-03-29 12:15:32 +02:00
|
|
|
* Raw UDP profile.
|
2007-01-04 18:25:30 +01:00
|
|
|
*/
|
|
|
|
public static class RawUdp extends JingleTransportProvider {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Defauls constructor.
|
|
|
|
*/
|
|
|
|
public RawUdp() {
|
|
|
|
super();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Obtain the corresponding TransportNegotiator.RawUdp instance.
|
|
|
|
*
|
|
|
|
* @return a new TransportNegotiator.RawUdp instance
|
|
|
|
*/
|
2017-02-11 16:16:41 +01:00
|
|
|
@Override
|
2007-01-04 18:25:30 +01:00
|
|
|
protected JingleTransport getInstance() {
|
|
|
|
return new JingleTransport.RawUdp();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Parse a iq/jingle/transport/candidate element.
|
|
|
|
*
|
|
|
|
* @param parser the structure to parse
|
|
|
|
* @return a candidate element
|
|
|
|
*/
|
2017-02-11 16:16:41 +01:00
|
|
|
@Override
|
2014-10-07 21:15:20 +02:00
|
|
|
protected JingleTransportCandidate parseCandidate(XmlPullParser parser) {
|
2007-01-04 18:25:30 +01:00
|
|
|
TransportCandidate.Fixed mt = new TransportCandidate.Fixed();
|
|
|
|
|
|
|
|
String generation = parser.getAttributeValue("", "generation");
|
|
|
|
String ip = parser.getAttributeValue("", "ip");
|
|
|
|
String name = parser.getAttributeValue("", "name");
|
|
|
|
String port = parser.getAttributeValue("", "port");
|
|
|
|
|
2017-11-20 08:53:19 +01:00
|
|
|
// LOGGER.debug();
|
2007-01-04 18:25:30 +01:00
|
|
|
|
|
|
|
if (generation != null) {
|
|
|
|
try {
|
|
|
|
mt.setGeneration(Integer.parseInt(generation));
|
2007-01-30 00:45:13 +01:00
|
|
|
}
|
|
|
|
catch (Exception e) {
|
2007-01-04 18:25:30 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ip != null) {
|
|
|
|
mt.setIp(ip);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (name != null) {
|
|
|
|
mt.setName(name);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (port != null) {
|
|
|
|
try {
|
|
|
|
mt.setPort(Integer.parseInt(port));
|
2007-01-30 00:45:13 +01:00
|
|
|
}
|
|
|
|
catch (Exception e) {
|
2007-01-04 18:25:30 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return new JingleTransport.RawUdp.Candidate(mt);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|