Java Code Examples for org.jivesoftware.smack.packet.IQ#createResultIQ()

The following examples show how to use org.jivesoftware.smack.packet.IQ#createResultIQ() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ThreadedDummyConnection.java    From Smack with Apache License 2.0 6 votes vote down vote up
@Override
protected void sendStanzaInternal(Stanza packet) {
    super.sendStanzaInternal(packet);

    if (packet instanceof IQ && !timeout) {
        timeout = false;
        // Set reply packet to match one being sent. We haven't started the
        // other thread yet so this is still safe.
        IQ replyPacket = replyQ.peek();

        // If no reply has been set via addIQReply, then we create a simple reply
        if (replyPacket == null) {
            replyPacket = IQ.createResultIQ((IQ) packet);
            replyQ.add(replyPacket);
        }
        replyPacket.setStanzaId(packet.getStanzaId());
        replyPacket.setTo(packet.getFrom());
        if (replyPacket.getType() == null) {
            replyPacket.setType(Type.result);
        }

        new ProcessQueue(replyQ).start();
    }
}
 
Example 2
Source File: JingleSession.java    From Smack with Apache License 2.0 6 votes vote down vote up
/**
 * Acknowledge a IQ packet.
 *
 * @param iq The IQ to acknowledge.
 * @return the ack IQ.
 */
public IQ createAck(IQ iq) {
    IQ result = null;

    if (iq != null) {
        // Don't acknowledge ACKs, errors...
        if (iq.getType().equals(IQ.Type.set)) {
            IQ ack = IQ.createResultIQ(iq);

            // No! Don't send it.  Let it flow to the normal way IQ results get processed and sent.
            // getConnection().sendStanza(ack);
            result = ack;
        }
    }
    return result;
}
 
Example 3
Source File: InBandBytestreamRequest.java    From Smack with Apache License 2.0 6 votes vote down vote up
/**
 * Accepts the In-Band Bytestream open request and returns the session to
 * send/receive data.
 *
 * @return the session to send/receive data
 * @throws NotConnectedException if the XMPP connection is not connected.
 * @throws InterruptedException if the calling thread was interrupted.
 */
@Override
public InBandBytestreamSession accept() throws NotConnectedException, InterruptedException {
    XMPPConnection connection = this.manager.getConnection();

    // create In-Band Bytestream session and store it
    InBandBytestreamSession ibbSession = new InBandBytestreamSession(connection,
                    this.byteStreamRequest, this.byteStreamRequest.getFrom());
    this.manager.getSessions().put(this.byteStreamRequest.getSessionID(), ibbSession);

    // acknowledge request
    IQ resultIQ = IQ.createResultIQ(this.byteStreamRequest);
    connection.sendStanza(resultIQ);

    return ibbSession;
}
 
Example 4
Source File: JingleS5BTransportSession.java    From Smack with Apache License 2.0 6 votes vote down vote up
@Override
public IQ handleTransportInfo(Jingle transportInfo) {
    JingleS5BTransportInfo info = (JingleS5BTransportInfo) transportInfo.getContents().get(0).getTransport().getInfo();

    switch (info.getElementName()) {
        case JingleS5BTransportInfo.CandidateUsed.ELEMENT:
            return handleCandidateUsed(transportInfo);

        case JingleS5BTransportInfo.CandidateActivated.ELEMENT:
            return handleCandidateActivate(transportInfo);

        case JingleS5BTransportInfo.CandidateError.ELEMENT:
            return handleCandidateError(transportInfo);

        case JingleS5BTransportInfo.ProxyError.ELEMENT:
            return handleProxyError(transportInfo);
    }
    // We should never go here, but lets be gracious...
    return IQ.createResultIQ(transportInfo);
}
 
Example 5
Source File: RosterVersioningTest.java    From Smack with Apache License 2.0 5 votes vote down vote up
private void answerWithEmptyRosterResult() {
    // We expect that the roster request is the only packet sent. This is not part of the specification,
    // but a shortcut in the test implementation.
    Stanza sentPacket = connection.getSentPacket();
    if (sentPacket instanceof RosterPacket) {
        final IQ emptyIQ = IQ.createResultIQ((RosterPacket) sentPacket);
        connection.processStanza(emptyIQ);
    } else {
        assertTrue("Expected to get a RosterPacket ", false);
    }
}
 
Example 6
Source File: JingleSession.java    From Smack with Apache License 2.0 5 votes vote down vote up
@Override
public IQ handleJingleSessionRequest(Jingle jingle) {
    switch (jingle.getAction()) {
    case content_accept:
        return handleContentAccept(jingle);
    case content_add:
        return handleContentAdd(jingle);
    case content_modify:
        return handleContentModify(jingle);
    case content_reject:
        return handleContentReject(jingle);
    case content_remove:
        return handleContentRemove(jingle);
    case description_info:
        return handleDescriptionInfo(jingle);
    case session_info:
        return handleSessionInfo(jingle);
    case security_info:
        return handleSecurityInfo(jingle);
    case session_accept:
        return handleSessionAccept(jingle);
    case transport_accept:
        return handleTransportAccept(jingle);
    case transport_info:
        return transportSession.handleTransportInfo(jingle);
    case session_initiate:
        return handleSessionInitiate(jingle);
    case transport_reject:
        return handleTransportReject(jingle);
    case session_terminate:
        return handleSessionTerminate(jingle);
    case transport_replace:
        return handleTransportReplace(jingle);
    default:
        return IQ.createResultIQ(jingle);
    }
}
 
Example 7
Source File: JingleS5BTransportSession.java    From Smack with Apache License 2.0 5 votes vote down vote up
public IQ handleCandidateActivate(Jingle jingle) {
    LOGGER.log(Level.INFO, "handleCandidateActivate");
    Socks5BytestreamSession bs = new Socks5BytestreamSession(ourChoice.socket,
            ourChoice.candidate.getJid().asBareJid().equals(jingleSession.getRemote().asBareJid()));
    callback.onSessionInitiated(bs);
    return IQ.createResultIQ(jingle);
}
 
Example 8
Source File: JingleS5BTransportSession.java    From Smack with Apache License 2.0 5 votes vote down vote up
public IQ handleCandidateUsed(Jingle jingle) {
    JingleS5BTransportInfo info = (JingleS5BTransportInfo) jingle.getContents().get(0).getTransport().getInfo();
    String candidateId = ((JingleS5BTransportInfo.CandidateUsed) info).getCandidateId();
    theirChoice = new UsedCandidate(ourProposal, ourProposal.getCandidate(candidateId), null);

    if (theirChoice.candidate == null) {
        /*
        TODO: Booooooh illegal candidateId!! Go home!!!!11elf
         */
    }

    connectIfReady();

    return IQ.createResultIQ(jingle);
}
 
Example 9
Source File: JingleSession.java    From Smack with Apache License 2.0 4 votes vote down vote up
protected IQ handleDescriptionInfo(Jingle descriptionInfo) {
    return IQ.createResultIQ(descriptionInfo);
}
 
Example 10
Source File: JingleSession.java    From Smack with Apache License 2.0 4 votes vote down vote up
protected IQ handleTransportReplace(Jingle transportReplace) {
    return IQ.createResultIQ(transportReplace);
}
 
Example 11
Source File: JingleSession.java    From Smack with Apache License 2.0 4 votes vote down vote up
protected IQ handleTransportReject(Jingle transportReject) {
    return IQ.createResultIQ(transportReject);
}
 
Example 12
Source File: JingleSession.java    From Smack with Apache License 2.0 4 votes vote down vote up
protected IQ handleContentReject(Jingle contentReject) {
    return IQ.createResultIQ(contentReject);
}
 
Example 13
Source File: JingleSession.java    From Smack with Apache License 2.0 4 votes vote down vote up
protected IQ handleSecurityInfo(Jingle securityInfo) {
    return IQ.createResultIQ(securityInfo);
}
 
Example 14
Source File: JingleS5BTransportSession.java    From Smack with Apache License 2.0 4 votes vote down vote up
public IQ handleCandidateError(Jingle jingle) {
    theirChoice = CANDIDATE_FAILURE;
    connectIfReady();
    return IQ.createResultIQ(jingle);
}
 
Example 15
Source File: JingleSession.java    From Smack with Apache License 2.0 4 votes vote down vote up
protected IQ handleSessionTerminate(Jingle sessionTerminate) {
    return IQ.createResultIQ(sessionTerminate);
}
 
Example 16
Source File: JingleSession.java    From Smack with Apache License 2.0 4 votes vote down vote up
protected IQ handleSessionInitiate(Jingle sessionInitiate) {
    return IQ.createResultIQ(sessionInitiate);
}
 
Example 17
Source File: InBandBytestreamSession.java    From Smack with Apache License 2.0 4 votes vote down vote up
@Override
protected StanzaListener getDataPacketListener() {
    return new StanzaListener() {

        private long lastSequence = -1;

        @Override
        public void processStanza(Stanza packet) throws NotConnectedException, InterruptedException {
            // get data packet extension
            DataPacketExtension data = ((Data) packet).getDataPacketExtension();

            /*
             * check if sequence was not used already (see XEP-0047 Section 2.2)
             */
            if (data.getSeq() <= this.lastSequence) {
                IQ unexpectedRequest = IQ.createErrorResponse((IQ) packet,
                                StanzaError.Condition.unexpected_request);
                connection.sendStanza(unexpectedRequest);
                return;

            }

            // check if encoded data is valid (see XEP-0047 Section 2.2)
            if (data.getDecodedData() == null) {
                // data is invalid; respond with bad-request error
                IQ badRequest = IQ.createErrorResponse((IQ) packet,
                                StanzaError.Condition.bad_request);
                connection.sendStanza(badRequest);
                return;
            }

            // data is valid; add to data queue
            dataQueue.offer(data);

            // confirm IQ
            IQ confirmData = IQ.createResultIQ((IQ) packet);
            connection.sendStanza(confirmData);

            // set last seen sequence
            this.lastSequence = data.getSeq();
            if (this.lastSequence == 65535) {
                this.lastSequence = -1;
            }

        }

    };
}
 
Example 18
Source File: JingleUtil.java    From Smack with Apache License 2.0 4 votes vote down vote up
public IQ createAck(Jingle jingle) {
    return IQ.createResultIQ(jingle);
}
 
Example 19
Source File: JingleS5BTransportSession.java    From Smack with Apache License 2.0 4 votes vote down vote up
public IQ handleProxyError(Jingle jingle) {
    // TODO
    return IQ.createResultIQ(jingle);
}
 
Example 20
Source File: Roster.java    From Smack with Apache License 2.0 4 votes vote down vote up
@Override
public IQ handleIQRequest(IQ iqRequest) {
    final XMPPConnection connection = connection();
    RosterPacket rosterPacket = (RosterPacket) iqRequest;

    EntityFullJid ourFullJid = connection.getUser();
    if (ourFullJid == null) {
        LOGGER.warning("Ignoring roster push " + iqRequest + " while " + connection
                        + " has no bound resource. This may be a server bug.");
        return null;
    }

    // Roster push (RFC 6121, 2.1.6)
    // A roster push with a non-empty from not matching our address MUST be ignored
    EntityBareJid ourBareJid = ourFullJid.asEntityBareJid();
    Jid from = rosterPacket.getFrom();
    if (from != null) {
        if (from.equals(ourFullJid)) {
            // Since RFC 6121 roster pushes are no longer allowed to
            // origin from the full JID as it was the case with RFC
            // 3921. Log a warning an continue processing the push.
            // See also SMACK-773.
            LOGGER.warning(
                    "Received roster push from full JID. This behavior is since RFC 6121 not longer standard compliant. "
                            + "Please ask your server vendor to fix this and comply to RFC 6121 ยง 2.1.6. IQ roster push stanza: "
                            + iqRequest);
        } else if (!from.equals(ourBareJid)) {
            LOGGER.warning("Ignoring roster push with a non matching 'from' ourJid='" + ourBareJid + "' from='"
                    + from + "'");
            return IQ.createErrorResponse(iqRequest, Condition.service_unavailable);
        }
    }

    // A roster push must contain exactly one entry
    Collection<Item> items = rosterPacket.getRosterItems();
    if (items.size() != 1) {
        LOGGER.warning("Ignoring roster push with not exactly one entry. size=" + items.size());
        return IQ.createErrorResponse(iqRequest, Condition.bad_request);
    }

    Collection<Jid> addedEntries = new ArrayList<>();
    Collection<Jid> updatedEntries = new ArrayList<>();
    Collection<Jid> deletedEntries = new ArrayList<>();
    Collection<Jid> unchangedEntries = new ArrayList<>();

    // We assured above that the size of items is exactly 1, therefore we are able to
    // safely retrieve this single item here.
    Item item = items.iterator().next();
    RosterEntry entry = new RosterEntry(item, Roster.this, connection);
    String version = rosterPacket.getVersion();

    if (item.getItemType().equals(RosterPacket.ItemType.remove)) {
        deleteEntry(deletedEntries, entry);
        if (rosterStore != null) {
            rosterStore.removeEntry(entry.getJid(), version);
        }
    }
    else if (hasValidSubscriptionType(item)) {
        addUpdateEntry(addedEntries, updatedEntries, unchangedEntries, item, entry);
        if (rosterStore != null) {
            rosterStore.addEntry(item, version);
        }
    }

    removeEmptyGroups();

    // Fire event for roster listeners.
    fireRosterChangedEvent(addedEntries, updatedEntries, deletedEntries);

    return IQ.createResultIQ(rosterPacket);
}