Search in sources :

Example 6 with ExtensionElement

use of org.jivesoftware.smack.packet.ExtensionElement in project Smack by igniterealtime.

the class PacketParserUtils method addExtensionElement.

public static void addExtensionElement(Collection<ExtensionElement> collection, XmlPullParser parser, String elementName, String namespace) throws Exception {
    ExtensionElement packetExtension = parseExtensionElement(elementName, namespace, parser);
    collection.add(packetExtension);
}
Also used : ExtensionElement(org.jivesoftware.smack.packet.ExtensionElement)

Example 7 with ExtensionElement

use of org.jivesoftware.smack.packet.ExtensionElement in project Smack by igniterealtime.

the class PacketParserUtils method addExtensionElement.

public static void addExtensionElement(Stanza packet, XmlPullParser parser, String elementName, String namespace) throws Exception {
    ExtensionElement packetExtension = parseExtensionElement(elementName, namespace, parser);
    packet.addExtension(packetExtension);
}
Also used : ExtensionElement(org.jivesoftware.smack.packet.ExtensionElement)

Example 8 with ExtensionElement

use of org.jivesoftware.smack.packet.ExtensionElement in project Smack by igniterealtime.

the class AbstractXMPPConnection method parseFeatures.

protected final void parseFeatures(XmlPullParser parser) throws Exception {
    streamFeatures.clear();
    final int initialDepth = parser.getDepth();
    while (true) {
        int eventType = parser.next();
        if (eventType == XmlPullParser.START_TAG && parser.getDepth() == initialDepth + 1) {
            ExtensionElement streamFeature = null;
            String name = parser.getName();
            String namespace = parser.getNamespace();
            switch(name) {
                case StartTls.ELEMENT:
                    streamFeature = PacketParserUtils.parseStartTlsFeature(parser);
                    break;
                case Mechanisms.ELEMENT:
                    streamFeature = new Mechanisms(PacketParserUtils.parseMechanisms(parser));
                    break;
                case Bind.ELEMENT:
                    streamFeature = Bind.Feature.INSTANCE;
                    break;
                case Session.ELEMENT:
                    streamFeature = PacketParserUtils.parseSessionFeature(parser);
                    break;
                case Compress.Feature.ELEMENT:
                    streamFeature = PacketParserUtils.parseCompressionFeature(parser);
                    break;
                default:
                    ExtensionElementProvider<ExtensionElement> provider = ProviderManager.getStreamFeatureProvider(name, namespace);
                    if (provider != null) {
                        streamFeature = provider.parse(parser);
                    }
                    break;
            }
            if (streamFeature != null) {
                addStreamFeature(streamFeature);
            }
        } else if (eventType == XmlPullParser.END_TAG && parser.getDepth() == initialDepth) {
            break;
        }
    }
    if (hasFeature(Mechanisms.ELEMENT, Mechanisms.NAMESPACE)) {
        // Only proceed with SASL auth if TLS is disabled or if the server doesn't announce it
        if (!hasFeature(StartTls.ELEMENT, StartTls.NAMESPACE) || config.getSecurityMode() == SecurityMode.disabled) {
            tlsHandled.reportSuccess();
            saslFeatureReceived.reportSuccess();
        }
    }
    // STARTTLS. We can then report that the last 'stream:features' have been parsed
    if (hasFeature(Bind.ELEMENT, Bind.NAMESPACE)) {
        if (!hasFeature(Compress.Feature.ELEMENT, Compress.NAMESPACE) || !config.isCompressionEnabled()) {
            // This was was last features from the server is either it did not contain
            // compression or if we disabled it
            lastFeaturesReceived.reportSuccess();
        }
    }
    afterFeaturesReceived();
}
Also used : Mechanisms(org.jivesoftware.smack.packet.Mechanisms) ExtensionElement(org.jivesoftware.smack.packet.ExtensionElement)

Example 9 with ExtensionElement

use of org.jivesoftware.smack.packet.ExtensionElement in project Smack by igniterealtime.

the class Node method getSubscriptions.

private List<Subscription> getSubscriptions(List<ExtensionElement> additionalExtensions, Collection<ExtensionElement> returnedExtensions, PubSubNamespace pubSubNamespace) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
    PubSub pubSub = createPubsubPacket(Type.get, new NodeExtension(PubSubElementType.SUBSCRIPTIONS, getId()), pubSubNamespace);
    if (additionalExtensions != null) {
        for (ExtensionElement pe : additionalExtensions) {
            pubSub.addExtension(pe);
        }
    }
    PubSub reply = sendPubsubPacket(pubSub);
    if (returnedExtensions != null) {
        returnedExtensions.addAll(reply.getExtensions());
    }
    SubscriptionsExtension subElem = (SubscriptionsExtension) reply.getExtension(PubSubElementType.SUBSCRIPTIONS);
    return subElem.getSubscriptions();
}
Also used : PubSub(org.jivesoftware.smackx.pubsub.packet.PubSub) ExtensionElement(org.jivesoftware.smack.packet.ExtensionElement)

Example 10 with ExtensionElement

use of org.jivesoftware.smack.packet.ExtensionElement in project Smack by igniterealtime.

the class ItemProvider method parse.

@Override
public Item parse(XmlPullParser parser, int initialDepth) throws Exception {
    String id = parser.getAttributeValue(null, "id");
    String node = parser.getAttributeValue(null, "node");
    int tag = parser.next();
    if (tag == XmlPullParser.END_TAG) {
        return new Item(id, node);
    } else {
        String payloadElemName = parser.getName();
        String payloadNS = parser.getNamespace();
        final ExtensionElementProvider<ExtensionElement> extensionProvider = ProviderManager.getExtensionProvider(payloadElemName, payloadNS);
        if (extensionProvider == null) {
            CharSequence payloadText = PacketParserUtils.parseElement(parser, true);
            return new PayloadItem<SimplePayload>(id, node, new SimplePayload(payloadElemName, payloadNS, payloadText));
        } else {
            return new PayloadItem<ExtensionElement>(id, node, extensionProvider.parse(parser));
        }
    }
}
Also used : PayloadItem(org.jivesoftware.smackx.pubsub.PayloadItem) Item(org.jivesoftware.smackx.pubsub.Item) PayloadItem(org.jivesoftware.smackx.pubsub.PayloadItem) ExtensionElement(org.jivesoftware.smack.packet.ExtensionElement) SimplePayload(org.jivesoftware.smackx.pubsub.SimplePayload)

Aggregations

ExtensionElement (org.jivesoftware.smack.packet.ExtensionElement)32 Test (org.junit.Test)9 XmlPullParser (org.xmlpull.v1.XmlPullParser)9 AccountItem (com.xabber.android.data.account.AccountItem)7 Message (org.jivesoftware.smack.packet.Message)7 Stanza (org.jivesoftware.smack.packet.Stanza)4 LinkedList (java.util.LinkedList)3 DiscoverInfo (org.jivesoftware.smackx.disco.packet.DiscoverInfo)3 TreeSet (java.util.TreeSet)2 XMPPConnection (org.jivesoftware.smack.XMPPConnection)2 Presence (org.jivesoftware.smack.packet.Presence)2 AMPExtension (org.jivesoftware.smackx.amp.packet.AMPExtension)2 AMPExtensionProvider (org.jivesoftware.smackx.amp.provider.AMPExtensionProvider)2 Base64BinaryChunk (org.jivesoftware.smackx.hoxt.packet.Base64BinaryChunk)2 MUCUser (org.jivesoftware.smackx.muc.packet.MUCUser)2 PubSub (org.jivesoftware.smackx.pubsub.packet.PubSub)2 RSMSet (org.jivesoftware.smackx.rsm.packet.RSMSet)2 FormField (org.jivesoftware.smackx.xdata.FormField)2 DataForm (org.jivesoftware.smackx.xdata.packet.DataForm)2 NetworkException (com.xabber.android.data.NetworkException)1