mirror of
https://codeberg.org/Mercury-IM/Smack
synced 2025-12-06 13:11:08 +01:00
Jingle Extension added to Smack Repository
git-svn-id: http://svn.igniterealtime.org/svn/repos/smack/trunk@6517 b35dd754-fafc-0310-a699-88a17e54d16e
This commit is contained in:
parent
f1972c2571
commit
4b6de6647b
104 changed files with 16411 additions and 0 deletions
|
|
@ -0,0 +1,125 @@
|
|||
package org.jivesoftware.smackx.provider;
|
||||
|
||||
import org.jivesoftware.smack.packet.PacketExtension;
|
||||
import org.jivesoftware.smack.provider.PacketExtensionProvider;
|
||||
import org.jivesoftware.smackx.jingle.media.PayloadType;
|
||||
import org.jivesoftware.smackx.packet.JingleContentDescription;
|
||||
import org.jivesoftware.smackx.packet.JingleContentDescription.JinglePayloadType;
|
||||
import org.xmlpull.v1.XmlPullParser;
|
||||
|
||||
/**
|
||||
* Parser for a Jingle description
|
||||
*
|
||||
* @author Alvaro Saurin <alvaro.saurin@gmail.com>
|
||||
*/
|
||||
public abstract class JingleContentDescriptionProvider implements PacketExtensionProvider {
|
||||
|
||||
/**
|
||||
* Default constructor
|
||||
*/
|
||||
public JingleContentDescriptionProvider() {
|
||||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse a iq/jingle/description/payload-type element.
|
||||
*
|
||||
* @param parser the input to parse
|
||||
* @return a payload type element
|
||||
* @throws Exception
|
||||
*/
|
||||
protected JinglePayloadType parsePayload(final XmlPullParser parser)
|
||||
throws Exception {
|
||||
int ptId = 0;
|
||||
String ptName;
|
||||
int ptChannels = 0;
|
||||
|
||||
try {
|
||||
ptId = Integer.parseInt(parser.getAttributeValue("", "id"));
|
||||
} catch (Exception e) {
|
||||
}
|
||||
|
||||
ptName = parser.getAttributeValue("", "name");
|
||||
|
||||
try {
|
||||
ptChannels = Integer.parseInt(parser.getAttributeValue("", "channels"));
|
||||
} catch (Exception e) {
|
||||
}
|
||||
|
||||
return new JinglePayloadType(new PayloadType(ptId, ptName, ptChannels));
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse a iq/jingle/description element.
|
||||
*
|
||||
* @param parser the input to parse
|
||||
* @return a description element
|
||||
* @throws Exception
|
||||
*/
|
||||
public PacketExtension parseExtension(final XmlPullParser parser) throws Exception {
|
||||
boolean done = false;
|
||||
JingleContentDescription desc = getInstance();
|
||||
|
||||
while (!done) {
|
||||
int eventType = parser.next();
|
||||
String name = parser.getName();
|
||||
|
||||
if (eventType == XmlPullParser.START_TAG) {
|
||||
if (name.equals(JingleContentDescription.JinglePayloadType.NODENAME)) {
|
||||
desc.addJinglePayloadType(parsePayload(parser));
|
||||
} else {
|
||||
throw new Exception("Unknow element \"" + name + "\" in content.");
|
||||
}
|
||||
} else if (eventType == XmlPullParser.END_TAG) {
|
||||
if (name.equals(JingleContentDescription.NODENAME)) {
|
||||
done = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return desc;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a new instance of this class. Subclasses must overwrite this
|
||||
* method.
|
||||
*/
|
||||
protected abstract JingleContentDescription getInstance();
|
||||
|
||||
/**
|
||||
* Jingle audio
|
||||
*/
|
||||
public static class Audio extends JingleContentDescriptionProvider {
|
||||
|
||||
/**
|
||||
* Default constructor
|
||||
*/
|
||||
public Audio() {
|
||||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse an audio payload type.
|
||||
*/
|
||||
public JinglePayloadType parsePayload(final XmlPullParser parser)
|
||||
throws Exception {
|
||||
JinglePayloadType pte = super.parsePayload(parser);
|
||||
PayloadType.Audio pt = new PayloadType.Audio(pte.getPayloadType());
|
||||
int ptClockRate = 0;
|
||||
|
||||
try {
|
||||
ptClockRate = Integer.parseInt(parser.getAttributeValue("", "clockrate"));
|
||||
} catch (Exception e) {
|
||||
}
|
||||
pt.setClockRate(ptClockRate);
|
||||
|
||||
return new JinglePayloadType.Audio(pt);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a new instance of this object.
|
||||
*/
|
||||
protected JingleContentDescription getInstance() {
|
||||
return new JingleContentDescription.Audio();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,106 @@
|
|||
package org.jivesoftware.smackx.provider;
|
||||
|
||||
import org.jivesoftware.smack.packet.PacketExtension;
|
||||
import org.jivesoftware.smack.provider.PacketExtensionProvider;
|
||||
import org.jivesoftware.smackx.jingle.media.ContentInfo;
|
||||
import org.jivesoftware.smackx.packet.JingleContentInfo;
|
||||
import org.xmlpull.v1.XmlPullParser;
|
||||
|
||||
/**
|
||||
* Jingle Audio jmf-info provider
|
||||
*
|
||||
* @author Alvaro Saurin
|
||||
*/
|
||||
public class JingleContentInfoProvider implements PacketExtensionProvider {
|
||||
|
||||
/**
|
||||
* Creates a new provider. ProviderManager requires that every
|
||||
* PacketExtensionProvider has a public, no-argument constructor
|
||||
*/
|
||||
public JingleContentInfoProvider() {
|
||||
super();
|
||||
}
|
||||
|
||||
public PacketExtension parseExtension(final XmlPullParser parser) throws Exception {
|
||||
// This method must be overwritten by subclasses...
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* JingleContentDescription.Audio info provider
|
||||
*/
|
||||
public static class Audio extends JingleContentInfoProvider {
|
||||
|
||||
private PacketExtension audioInfo;
|
||||
|
||||
/**
|
||||
* Empty constructor.
|
||||
*/
|
||||
public Audio() {
|
||||
this(null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor with an audio info.
|
||||
*
|
||||
* @param audioInfo the jmf info
|
||||
*/
|
||||
public Audio(final PacketExtension audioInfo) {
|
||||
super();
|
||||
this.audioInfo = audioInfo;
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse a JingleContentDescription.Audio extension.
|
||||
*/
|
||||
public PacketExtension parseExtension(final XmlPullParser parser)
|
||||
throws Exception {
|
||||
PacketExtension result = null;
|
||||
|
||||
if (audioInfo != null) {
|
||||
result = audioInfo;
|
||||
} else {
|
||||
String elementName = parser.getName();
|
||||
|
||||
// Try to get an Audio content info
|
||||
ContentInfo mi = ContentInfo.Audio.fromString(elementName);
|
||||
if (mi != null) {
|
||||
result = new JingleContentInfo.Audio(mi);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
// Sub-elements
|
||||
|
||||
public static class Busy extends Audio {
|
||||
public Busy() {
|
||||
super(new JingleContentInfo.Audio.Busy());
|
||||
}
|
||||
}
|
||||
|
||||
public static class Hold extends Audio {
|
||||
public Hold() {
|
||||
super(new JingleContentInfo.Audio.Hold());
|
||||
}
|
||||
}
|
||||
|
||||
public static class Mute extends Audio {
|
||||
public Mute() {
|
||||
super(new JingleContentInfo.Audio.Mute());
|
||||
}
|
||||
}
|
||||
|
||||
public static class Queued extends Audio {
|
||||
public Queued() {
|
||||
super(new JingleContentInfo.Audio.Queued());
|
||||
}
|
||||
}
|
||||
|
||||
public static class Ringing extends Audio {
|
||||
public Ringing() {
|
||||
super(new JingleContentInfo.Audio.Ringing());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,128 @@
|
|||
/**
|
||||
* $RCSfile$
|
||||
* $Revision$
|
||||
* $Date$
|
||||
*
|
||||
* Copyright 2003-2005 Jive Software.
|
||||
*
|
||||
* All rights reserved. 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.provider;
|
||||
|
||||
import org.jivesoftware.smack.XMPPException;
|
||||
import org.jivesoftware.smack.packet.IQ;
|
||||
import org.jivesoftware.smack.provider.IQProvider;
|
||||
import org.jivesoftware.smackx.packet.Jingle;
|
||||
import org.jivesoftware.smackx.packet.JingleContentDescription;
|
||||
import org.jivesoftware.smackx.packet.JingleContentInfo;
|
||||
import org.jivesoftware.smackx.packet.JingleTransport;
|
||||
import org.xmlpull.v1.XmlPullParser;
|
||||
|
||||
/**
|
||||
* The JingleProvider parses Jingle packets.
|
||||
*
|
||||
* @author Alvaro Saurin
|
||||
*/
|
||||
public class JingleProvider implements IQProvider {
|
||||
|
||||
/**
|
||||
* Creates a new provider. ProviderManager requires that every
|
||||
* PacketExtensionProvider has a public, no-argument constructor
|
||||
*/
|
||||
public JingleProvider() {
|
||||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse a iq/jingle element.
|
||||
*/
|
||||
public IQ parseIQ(final XmlPullParser parser) throws Exception {
|
||||
|
||||
Jingle jingle = new Jingle();
|
||||
String sid = "";
|
||||
Jingle.Action action;
|
||||
String initiator = "";
|
||||
String responder = "";
|
||||
boolean done = false;
|
||||
|
||||
// Sub-elements providers
|
||||
JingleContentDescriptionProvider jdpAudio = new JingleContentDescriptionProvider.Audio();
|
||||
JingleTransportProvider jtpRawUdp = new JingleTransportProvider.RawUdp();
|
||||
JingleTransportProvider jtpIce = new JingleTransportProvider.Ice();
|
||||
JingleContentInfoProvider jmipAudio = new JingleContentInfoProvider.Audio();
|
||||
|
||||
int eventType;
|
||||
String elementName;
|
||||
String namespace;
|
||||
|
||||
// Get some attributes for the <jingle> element
|
||||
sid = parser.getAttributeValue("", "sid");
|
||||
action = Jingle.Action.getAction(parser.getAttributeValue("", "action"));
|
||||
initiator = parser.getAttributeValue("", "initiator");
|
||||
responder = parser.getAttributeValue("", "responder");
|
||||
|
||||
jingle.setSid(sid);
|
||||
jingle.setAction(action);
|
||||
jingle.setInitiator(initiator);
|
||||
jingle.setResponder(responder);
|
||||
|
||||
// Start processing sub-elements
|
||||
while (!done) {
|
||||
eventType = parser.next();
|
||||
elementName = parser.getName();
|
||||
namespace = parser.getNamespace();
|
||||
|
||||
if (eventType == XmlPullParser.START_TAG) {
|
||||
|
||||
// Parse some well know subelements, depending on the namespaces
|
||||
// and element names...
|
||||
|
||||
if (elementName.equals(JingleContentDescription.NODENAME)
|
||||
&& namespace.equals(JingleContentDescription.Audio.NAMESPACE)) {
|
||||
jingle.addDescription((JingleContentDescription) jdpAudio
|
||||
.parseExtension(parser));
|
||||
} else if (elementName.equals(JingleTransport.NODENAME)) {
|
||||
|
||||
// Parse the possible transport namespaces
|
||||
if (namespace.equals(JingleTransport.RawUdp.NAMESPACE)) {
|
||||
jingle.addTransport((JingleTransport) jtpRawUdp
|
||||
.parseExtension(parser));
|
||||
} else if (namespace.equals(JingleTransport.Ice.NAMESPACE)) {
|
||||
jingle.addTransport((JingleTransport) jtpIce
|
||||
.parseExtension(parser));
|
||||
} else {
|
||||
throw new XMPPException("Unknown transport namespace \""
|
||||
+ namespace + "\" in Jingle packet.");
|
||||
}
|
||||
} else if (namespace.equals(JingleContentInfo.Audio.NAMESPACE)) {
|
||||
jingle.setContentInfo((JingleContentInfo) jmipAudio
|
||||
.parseExtension(parser));
|
||||
} else if (elementName.equals("content")) {
|
||||
//TODO Separate Contents (XEP-0166)
|
||||
} else {
|
||||
throw new XMPPException("Unknown combination of namespace \""
|
||||
+ namespace + "\" and element name \"" + elementName
|
||||
+ "\" in Jingle packet.");
|
||||
}
|
||||
|
||||
} else if (eventType == XmlPullParser.END_TAG) {
|
||||
if (parser.getName().equals(Jingle.getElementName())) {
|
||||
done = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return jingle;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,231 @@
|
|||
package org.jivesoftware.smackx.provider;
|
||||
|
||||
import org.jivesoftware.smack.packet.PacketExtension;
|
||||
import org.jivesoftware.smack.provider.PacketExtensionProvider;
|
||||
import org.jivesoftware.smackx.jingle.nat.TransportCandidate;
|
||||
import org.jivesoftware.smackx.packet.JingleTransport;
|
||||
import org.jivesoftware.smackx.packet.JingleTransport.JingleTransportCandidate;
|
||||
import org.xmlpull.v1.XmlPullParser;
|
||||
|
||||
/**
|
||||
* Provider for a Jingle transport element
|
||||
*
|
||||
* @author Alvaro Saurin <alvaro.saurin@gmail.com>
|
||||
*/
|
||||
public abstract class JingleTransportProvider implements PacketExtensionProvider {
|
||||
|
||||
/**
|
||||
* Creates a new provider. ProviderManager requires that every
|
||||
* PacketExtensionProvider has a public, no-argument constructor
|
||||
*/
|
||||
public JingleTransportProvider() {
|
||||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
* 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.
|
||||
* @throws Exception
|
||||
*/
|
||||
public PacketExtension parseExtension(final XmlPullParser parser) throws Exception {
|
||||
boolean done = false;
|
||||
JingleTransport trans = getInstance();
|
||||
|
||||
while (!done) {
|
||||
int eventType = parser.next();
|
||||
String name = parser.getName();
|
||||
|
||||
if (eventType == XmlPullParser.START_TAG) {
|
||||
if (name.equals(JingleTransportCandidate.NODENAME)) {
|
||||
JingleTransportCandidate jtc = parseCandidate(parser);
|
||||
if (jtc != null) trans.addCandidate(jtc);
|
||||
} else {
|
||||
throw new Exception("Unknown tag \"" + name + "\" in transport element.");
|
||||
}
|
||||
} else if (eventType == XmlPullParser.END_TAG) {
|
||||
if (name.equals(JingleTransport.NODENAME)) {
|
||||
done = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return trans;
|
||||
}
|
||||
|
||||
protected abstract JingleTransportCandidate parseCandidate(final XmlPullParser parser)
|
||||
throws Exception;
|
||||
|
||||
/**
|
||||
* RTP-ICE profile
|
||||
*/
|
||||
public static class Ice extends JingleTransportProvider {
|
||||
|
||||
/**
|
||||
* Defauls constructor.
|
||||
*/
|
||||
public Ice() {
|
||||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
* Obtain the corresponding TransportNegotiator.Ice instance.
|
||||
*
|
||||
* @return a new TransportNegotiator.Ice instance
|
||||
*/
|
||||
protected JingleTransport getInstance() {
|
||||
return new JingleTransport.Ice();
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse a iq/jingle/transport/candidate element.
|
||||
*
|
||||
* @param parser the structure to parse
|
||||
* @return a candidate element
|
||||
* @throws Exception
|
||||
*/
|
||||
protected JingleTransportCandidate parseCandidate(XmlPullParser parser) throws Exception {
|
||||
TransportCandidate.Ice mt = new TransportCandidate.Ice();
|
||||
|
||||
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");
|
||||
|
||||
if (channel != null) {
|
||||
mt.setChannel(new TransportCandidate.Channel(channel));
|
||||
}
|
||||
|
||||
if (generation != null) {
|
||||
try {
|
||||
mt.setGeneration(Integer.parseInt(generation));
|
||||
} catch (Exception e) {
|
||||
}
|
||||
}
|
||||
|
||||
if (ip != null) {
|
||||
mt.setIp(ip);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (name != null) {
|
||||
mt.setName(name);
|
||||
}
|
||||
|
||||
if (network != null) {
|
||||
try {
|
||||
mt.setNetwork(Integer.parseInt(network));
|
||||
} catch (Exception e) {
|
||||
}
|
||||
}
|
||||
|
||||
if (username != null) {
|
||||
mt.setUsername(username);
|
||||
}
|
||||
|
||||
if (password != null) {
|
||||
mt.setPassword(password);
|
||||
}
|
||||
|
||||
if (port != null) {
|
||||
try {
|
||||
mt.setPort(Integer.parseInt(port));
|
||||
} catch (Exception e) {
|
||||
}
|
||||
}
|
||||
|
||||
if (preference != null) {
|
||||
try {
|
||||
mt.setPreference(Integer.parseInt(preference));
|
||||
} catch (Exception e) {
|
||||
}
|
||||
}
|
||||
|
||||
if (proto != null) {
|
||||
mt.setProto(new TransportCandidate.Protocol(proto));
|
||||
}
|
||||
|
||||
return new JingleTransport.Ice.Candidate(mt);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Raw UDP profile
|
||||
*/
|
||||
public static class RawUdp extends JingleTransportProvider {
|
||||
|
||||
/**
|
||||
* Defauls constructor.
|
||||
*/
|
||||
public RawUdp() {
|
||||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
* Obtain the corresponding TransportNegotiator.RawUdp instance.
|
||||
*
|
||||
* @return a new TransportNegotiator.RawUdp instance
|
||||
*/
|
||||
protected JingleTransport getInstance() {
|
||||
return new JingleTransport.RawUdp();
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse a iq/jingle/transport/candidate element.
|
||||
*
|
||||
* @param parser the structure to parse
|
||||
* @return a candidate element
|
||||
* @throws Exception
|
||||
*/
|
||||
protected JingleTransportCandidate parseCandidate(XmlPullParser parser) throws Exception {
|
||||
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");
|
||||
|
||||
//System.out.println();
|
||||
|
||||
if (generation != null) {
|
||||
try {
|
||||
mt.setGeneration(Integer.parseInt(generation));
|
||||
} catch (Exception e) {
|
||||
}
|
||||
}
|
||||
|
||||
if (ip != null) {
|
||||
mt.setIp(ip);
|
||||
}
|
||||
|
||||
if (name != null) {
|
||||
mt.setName(name);
|
||||
}
|
||||
|
||||
if (port != null) {
|
||||
try {
|
||||
mt.setPort(Integer.parseInt(port));
|
||||
} catch (Exception e) {
|
||||
}
|
||||
}
|
||||
return new JingleTransport.RawUdp.Candidate(mt);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1 @@
|
|||
<body>Provides pluggable parsing logic for Smack extensions.</body>
|
||||
Loading…
Add table
Add a link
Reference in a new issue