Search in sources :

Example 1 with Bind

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

the class BindIQProvider method parse.

@Override
public Bind parse(XmlPullParser parser, int initialDepth) throws XmlPullParserException, IOException, SmackException {
    String name;
    Bind bind = null;
    outerloop: while (true) {
        int eventType = parser.next();
        switch(eventType) {
            case XmlPullParser.START_TAG:
                name = parser.getName();
                switch(name) {
                    case "resource":
                        String resourceString = parser.nextText();
                        bind = Bind.newSet(Resourcepart.from(resourceString));
                        break;
                    case "jid":
                        EntityFullJid fullJid = JidCreate.entityFullFrom(parser.nextText());
                        bind = Bind.newResult(fullJid);
                        break;
                }
                break;
            case XmlPullParser.END_TAG:
                if (parser.getDepth() == initialDepth) {
                    break outerloop;
                }
                break;
        }
    }
    return bind;
}
Also used : Bind(org.jivesoftware.smack.packet.Bind) EntityFullJid(org.jxmpp.jid.EntityFullJid)

Example 2 with Bind

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

the class AbstractXMPPConnection method bindResourceAndEstablishSession.

protected void bindResourceAndEstablishSession(Resourcepart resource) throws XMPPErrorException, SmackException, InterruptedException {
    // Wait until either:
    // - the servers last features stanza has been parsed
    // - the timeout occurs
    LOGGER.finer("Waiting for last features to be received before continuing with resource binding");
    lastFeaturesReceived.checkIfSuccessOrWait();
    if (!hasFeature(Bind.ELEMENT, Bind.NAMESPACE)) {
        // server implementations as per RFC6120 7.2
        throw new ResourceBindingNotOfferedException();
    }
    // Resource binding, see RFC6120 7.
    // Note that we can not use IQReplyFilter here, since the users full JID is not yet
    // available. It will become available right after the resource has been successfully bound.
    Bind bindResource = Bind.newSet(resource);
    StanzaCollector packetCollector = createStanzaCollectorAndSend(new StanzaIdFilter(bindResource), bindResource);
    Bind response = packetCollector.nextResultOrThrow();
    // Set the connections user to the result of resource binding. It is important that we don't infer the user
    // from the login() arguments and the configurations service name, as, for example, when SASL External is used,
    // the username is not given to login but taken from the 'external' certificate.
    user = response.getJid();
    xmppServiceDomain = user.asDomainBareJid();
    Session.Feature sessionFeature = getFeature(Session.ELEMENT, Session.NAMESPACE);
    // Only bind the session if it's announced as stream feature by the server, is not optional and not disabled
    // For more information see http://tools.ietf.org/html/draft-cridland-xmpp-session-01
    // TODO remove this suppression once "disable legacy session" code has been removed from Smack
    @SuppressWarnings("deprecation") boolean legacySessionDisabled = getConfiguration().isLegacySessionDisabled();
    if (sessionFeature != null && !sessionFeature.isOptional() && !legacySessionDisabled) {
        Session session = new Session();
        packetCollector = createStanzaCollectorAndSend(new StanzaIdFilter(session), session);
        packetCollector.nextResultOrThrow();
    }
}
Also used : Bind(org.jivesoftware.smack.packet.Bind) ResourceBindingNotOfferedException(org.jivesoftware.smack.SmackException.ResourceBindingNotOfferedException) StanzaIdFilter(org.jivesoftware.smack.filter.StanzaIdFilter) Session(org.jivesoftware.smack.packet.Session)

Aggregations

Bind (org.jivesoftware.smack.packet.Bind)2 ResourceBindingNotOfferedException (org.jivesoftware.smack.SmackException.ResourceBindingNotOfferedException)1 StanzaIdFilter (org.jivesoftware.smack.filter.StanzaIdFilter)1 Session (org.jivesoftware.smack.packet.Session)1 EntityFullJid (org.jxmpp.jid.EntityFullJid)1