2007-01-04 18:25:30 +01:00
|
|
|
/**
|
2008-05-20 00:54:19 +02:00
|
|
|
* $RCSfile: JingleProvider.java,v $
|
|
|
|
* $Revision: 1.1 $
|
|
|
|
* $Date: 2007/07/02 17:41:11 $
|
2007-01-04 18:25:30 +01:00
|
|
|
*
|
|
|
|
* 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;
|
2008-05-20 00:54:19 +02:00
|
|
|
import org.jivesoftware.smackx.jingle.JingleActionEnum;
|
|
|
|
import org.jivesoftware.smackx.packet.*;
|
2007-01-04 18:25:30 +01:00
|
|
|
import org.xmlpull.v1.XmlPullParser;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The JingleProvider parses Jingle packets.
|
2008-05-20 00:54:19 +02:00
|
|
|
*
|
2007-01-04 18:25:30 +01:00
|
|
|
* @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 = "";
|
2008-05-20 00:54:19 +02:00
|
|
|
JingleActionEnum action;
|
2007-01-04 18:25:30 +01:00
|
|
|
String initiator = "";
|
|
|
|
String responder = "";
|
|
|
|
boolean done = false;
|
2008-05-20 00:54:19 +02:00
|
|
|
JingleContent currentContent = null;
|
2007-01-04 18:25:30 +01:00
|
|
|
|
|
|
|
// Sub-elements providers
|
2008-05-20 00:54:19 +02:00
|
|
|
JingleContentProvider jcp = new JingleContentProvider();
|
|
|
|
JingleDescriptionProvider jdpAudio = new JingleDescriptionProvider.Audio();
|
2007-01-04 18:25:30 +01:00
|
|
|
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");
|
2008-05-20 00:54:19 +02:00
|
|
|
action = JingleActionEnum.getAction(parser.getAttributeValue("", "action"));
|
2007-01-04 18:25:30 +01:00
|
|
|
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...
|
|
|
|
|
2008-05-20 00:54:19 +02:00
|
|
|
if (elementName.equals(JingleContent.NODENAME)) {
|
|
|
|
// Add a new <content> element to the jingle
|
|
|
|
currentContent = (JingleContent) jcp.parseExtension(parser);
|
|
|
|
jingle.addContent(currentContent);
|
|
|
|
} else if (elementName.equals(JingleDescription.NODENAME) && namespace.equals(JingleDescription.Audio.NAMESPACE)) {
|
|
|
|
// Set the <description> element of the <content>
|
|
|
|
currentContent.setDescription((JingleDescription) jdpAudio.parseExtension(parser));
|
2007-01-04 18:25:30 +01:00
|
|
|
} else if (elementName.equals(JingleTransport.NODENAME)) {
|
2008-05-20 00:54:19 +02:00
|
|
|
// Add all of the <transport> elements to the <content> of the jingle
|
2007-01-04 18:25:30 +01:00
|
|
|
|
|
|
|
// Parse the possible transport namespaces
|
|
|
|
if (namespace.equals(JingleTransport.RawUdp.NAMESPACE)) {
|
2008-05-20 00:54:19 +02:00
|
|
|
currentContent.addJingleTransport((JingleTransport) jtpRawUdp.parseExtension(parser));
|
2007-01-04 18:25:30 +01:00
|
|
|
} else if (namespace.equals(JingleTransport.Ice.NAMESPACE)) {
|
2008-05-20 00:54:19 +02:00
|
|
|
currentContent.addJingleTransport((JingleTransport) jtpIce.parseExtension(parser));
|
2007-01-04 18:25:30 +01:00
|
|
|
} else {
|
2008-05-20 00:54:19 +02:00
|
|
|
throw new XMPPException("Unknown transport namespace \"" + namespace + "\" in Jingle packet.");
|
2007-01-04 18:25:30 +01:00
|
|
|
}
|
|
|
|
} else if (namespace.equals(JingleContentInfo.Audio.NAMESPACE)) {
|
2008-05-20 00:54:19 +02:00
|
|
|
jingle.setContentInfo((JingleContentInfo) jmipAudio.parseExtension(parser));
|
2007-01-04 18:25:30 +01:00
|
|
|
} else {
|
2008-05-20 00:54:19 +02:00
|
|
|
throw new XMPPException("Unknown combination of namespace \"" + namespace + "\" and element name \""
|
|
|
|
+ elementName + "\" in Jingle packet.");
|
2007-01-04 18:25:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
} else if (eventType == XmlPullParser.END_TAG) {
|
|
|
|
if (parser.getName().equals(Jingle.getElementName())) {
|
|
|
|
done = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return jingle;
|
|
|
|
}
|
|
|
|
}
|