Search in sources :

Example 1 with JingleContentTransport

use of org.jivesoftware.smackx.jingle.element.JingleContentTransport in project Smack by igniterealtime.

the class JingleProvider method parseJingleContent.

public static JingleContent parseJingleContent(XmlPullParser parser, final int initialDepth) throws XmlPullParserException, IOException, SmackParsingException {
    JingleContent.Builder builder = JingleContent.getBuilder();
    String creatorString = parser.getAttributeValue("", JingleContent.CREATOR_ATTRIBUTE_NAME);
    JingleContent.Creator creator = JingleContent.Creator.valueOf(creatorString);
    builder.setCreator(creator);
    String disposition = parser.getAttributeValue("", JingleContent.DISPOSITION_ATTRIBUTE_NAME);
    builder.setDisposition(disposition);
    String name = parser.getAttributeValue("", JingleContent.NAME_ATTRIBUTE_NAME);
    builder.setName(name);
    String sendersString = parser.getAttributeValue("", JingleContent.SENDERS_ATTRIBUTE_NAME);
    if (sendersString != null) {
        JingleContent.Senders senders = JingleContent.Senders.valueOf(sendersString);
        builder.setSenders(senders);
    }
    outerloop: while (true) {
        XmlPullParser.Event eventType = parser.next();
        switch(eventType) {
            case START_ELEMENT:
                String tagName = parser.getName();
                String namespace = parser.getNamespace();
                switch(tagName) {
                    case JingleContentDescription.ELEMENT:
                        {
                            JingleContentDescription description;
                            JingleContentDescriptionProvider<?> provider = JingleContentProviderManager.getJingleContentDescriptionProvider(namespace);
                            if (provider == null) {
                                StandardExtensionElement standardExtensionElement = StandardExtensionElementProvider.INSTANCE.parse(parser);
                                description = new UnknownJingleContentDescription(standardExtensionElement);
                            } else {
                                description = provider.parse(parser);
                            }
                            builder.setDescription(description);
                            break;
                        }
                    case JingleContentTransport.ELEMENT:
                        {
                            JingleContentTransport transport;
                            JingleContentTransportProvider<?> provider = JingleContentProviderManager.getJingleContentTransportProvider(namespace);
                            if (provider == null) {
                                StandardExtensionElement standardExtensionElement = StandardExtensionElementProvider.INSTANCE.parse(parser);
                                transport = new UnknownJingleContentTransport(standardExtensionElement);
                            } else {
                                transport = provider.parse(parser);
                            }
                            builder.setTransport(transport);
                            break;
                        }
                    default:
                        LOGGER.severe("Unknown Jingle content element: " + tagName);
                        break;
                }
                break;
            case END_ELEMENT:
                if (parser.getDepth() == initialDepth) {
                    break outerloop;
                }
                break;
            default:
                // Catch all for incomplete switch (MissingCasesInEnumSwitch) statement.
                break;
        }
    }
    return builder.build();
}
Also used : UnknownJingleContentDescription(org.jivesoftware.smackx.jingle.element.UnknownJingleContentDescription) JingleContentDescription(org.jivesoftware.smackx.jingle.element.JingleContentDescription) StandardExtensionElement(org.jivesoftware.smack.packet.StandardExtensionElement) UnknownJingleContentDescription(org.jivesoftware.smackx.jingle.element.UnknownJingleContentDescription) JingleContent(org.jivesoftware.smackx.jingle.element.JingleContent) JingleContentTransport(org.jivesoftware.smackx.jingle.element.JingleContentTransport) UnknownJingleContentTransport(org.jivesoftware.smackx.jingle.element.UnknownJingleContentTransport) UnknownJingleContentTransport(org.jivesoftware.smackx.jingle.element.UnknownJingleContentTransport)

Example 2 with JingleContentTransport

use of org.jivesoftware.smackx.jingle.element.JingleContentTransport 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);
}
Also used : Jingle(org.jivesoftware.smackx.jingle.element.Jingle) JingleContentTransport(org.jivesoftware.smackx.jingle.element.JingleContentTransport) EnumSource(org.junit.jupiter.params.provider.EnumSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 3 with JingleContentTransport

use of org.jivesoftware.smackx.jingle.element.JingleContentTransport in project Smack by igniterealtime.

the class JingleTransportSession method processJingle.

public void processJingle(Jingle jingle) {
    if (jingle.getContents().size() == 0) {
        return;
    }
    JingleContent content = jingle.getContents().get(0);
    JingleContentTransport t = content.getTransport();
    if (t != null && t.getNamespace().equals(getNamespace())) {
        setTheirProposal(t);
    }
}
Also used : JingleContent(org.jivesoftware.smackx.jingle.element.JingleContent) JingleContentTransport(org.jivesoftware.smackx.jingle.element.JingleContentTransport)

Example 4 with JingleContentTransport

use of org.jivesoftware.smackx.jingle.element.JingleContentTransport in project Smack by igniterealtime.

the class JingleTransportMethodManager method getTransportManager.

public JingleTransportManager<?> getTransportManager(Jingle request) {
    JingleContent content = request.getContents().get(0);
    if (content == null) {
        return null;
    }
    JingleContentTransport transport = content.getTransport();
    if (transport == null) {
        return null;
    }
    return getTransportManager(transport.getNamespace());
}
Also used : JingleContent(org.jivesoftware.smackx.jingle.element.JingleContent) JingleContentTransport(org.jivesoftware.smackx.jingle.element.JingleContentTransport)

Aggregations

JingleContentTransport (org.jivesoftware.smackx.jingle.element.JingleContentTransport)4 JingleContent (org.jivesoftware.smackx.jingle.element.JingleContent)3 StandardExtensionElement (org.jivesoftware.smack.packet.StandardExtensionElement)1 Jingle (org.jivesoftware.smackx.jingle.element.Jingle)1 JingleContentDescription (org.jivesoftware.smackx.jingle.element.JingleContentDescription)1 UnknownJingleContentDescription (org.jivesoftware.smackx.jingle.element.UnknownJingleContentDescription)1 UnknownJingleContentTransport (org.jivesoftware.smackx.jingle.element.UnknownJingleContentTransport)1 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)1 EnumSource (org.junit.jupiter.params.provider.EnumSource)1