Search in sources :

Example 6 with IQ

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

the class PrivacyProviderTest method parsePrivacyList.

@Test
public void parsePrivacyList() throws Exception {
    // @formatter:off
    final String xmlPrivacyList = "<iq type='result' id='getlist2' to='romeo@example.net/orchard'>" + "<query xmlns='jabber:iq:privacy'>" + "<list name='public'>" + "<item type='jid'" + "value='tybalt@example.com'" + "action='deny'" + "order='1'/>" + "<item action='allow' order='2'/>" + "</list>" + "</query>" + "</iq>";
    // @formatter:on
    IQ iqPrivacyList = (IQ) PacketParserUtils.parseStanza(xmlPrivacyList);
    assertTrue(iqPrivacyList instanceof Privacy);
    Privacy privacyList = (Privacy) iqPrivacyList;
    List<PrivacyItem> pl = privacyList.getPrivacyList("public");
    PrivacyItem first = pl.get(0);
    assertEquals(PrivacyItem.Type.jid, first.getType());
    assertEquals("tybalt@example.com", first.getValue());
    assertEquals(false, first.isAllow());
    assertEquals(1, first.getOrder());
    PrivacyItem second = pl.get(1);
    assertEquals(true, second.isAllow());
    assertEquals(2, second.getOrder());
}
Also used : Privacy(org.jivesoftware.smackx.privacy.packet.Privacy) IQ(org.jivesoftware.smack.packet.IQ) PrivacyItem(org.jivesoftware.smackx.privacy.packet.PrivacyItem) Test(org.junit.Test)

Example 7 with IQ

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

the class RSMSetProviderTest method testRsmSetProvider.

@Test
public void testRsmSetProvider() throws Exception {
    // @formatter:off
    final String rsmset = "<iq type='get' id='iqget'>" + "<pubsub xmlns='http://jabber.org/protocol/pubsub'>" + "<set xmlns='http://jabber.org/protocol/rsm'>" + "<after>aftervalue</after>" + "<before>beforevalue</before>" + "<count>1</count>" + "<first index='2'>foo@bar.com</first>" + "<index>3</index>" + "<last>lastvalue</last>" + "<max>4</max>" + "</set>" + "</pubsub>" + "</iq>";
    // @formatter:on
    IQ iqWithRsm = (IQ) PacketParserUtils.parseStanza(rsmset);
    RSMSet rsm = (RSMSet) iqWithRsm.getExtension(RSMSet.ELEMENT, RSMSet.NAMESPACE);
    assertNotNull(rsm);
    assertEquals("aftervalue", rsm.getAfter());
    assertEquals("beforevalue", rsm.getBefore());
    assertEquals(1, rsm.getCount());
    assertEquals(2, rsm.getFirstIndex());
    assertEquals("foo@bar.com", rsm.getFirst());
    assertEquals(3, rsm.getIndex());
    assertEquals("lastvalue", rsm.getLast());
    assertEquals(4, rsm.getMax());
}
Also used : RSMSet(org.jivesoftware.smackx.rsm.packet.RSMSet) IQ(org.jivesoftware.smack.packet.IQ) Test(org.junit.Test)

Example 8 with IQ

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

the class InBandBytestreamSession method closeByPeer.

/**
     * This method is invoked if a request to close the In-Band Bytestream has been received.
     * 
     * @param closeRequest the close request from the remote peer
     * @throws NotConnectedException 
     * @throws InterruptedException 
     */
protected void closeByPeer(Close closeRequest) throws NotConnectedException, InterruptedException {
    /*
         * close streams without flushing them, because stream is already considered closed on the
         * remote peers side
         */
    this.inputStream.closeInternal();
    this.inputStream.cleanup();
    this.outputStream.closeInternal(false);
    // acknowledge close request
    IQ confirmClose = IQ.createResultIQ(closeRequest);
    this.connection.sendStanza(confirmClose);
}
Also used : IQ(org.jivesoftware.smack.packet.IQ)

Example 9 with IQ

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

the class Socks5BytestreamManager method replyRejectPacket.

/**
     * Responses to the given packet's sender with an XMPP error that a SOCKS5 Bytestream is not
     * accepted.
     * <p>
     * Specified in XEP-65 5.3.1 (Example 13)
     * </p>
     * 
     * @param packet Stanza(/Packet) that should be answered with a not-acceptable error
     * @throws NotConnectedException 
     * @throws InterruptedException 
     */
protected void replyRejectPacket(IQ packet) throws NotConnectedException, InterruptedException {
    XMPPError.Builder xmppError = XMPPError.getBuilder(XMPPError.Condition.not_acceptable);
    IQ errorIQ = IQ.createErrorResponse(packet, xmppError);
    connection().sendStanza(errorIQ);
}
Also used : IQ(org.jivesoftware.smack.packet.IQ) XMPPError(org.jivesoftware.smack.packet.XMPPError)

Example 10 with IQ

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

the class StreamNegotiator method initiateIncomingStream.

protected final IQ initiateIncomingStream(final XMPPConnection connection, StreamInitiation initiation) throws NoResponseException, XMPPErrorException, NotConnectedException {
    final StreamInitiation response = createInitiationAccept(initiation, getNamespaces());
    newStreamInitiation(initiation.getFrom(), initiation.getSessionID());
    final String eventKey = initiation.getFrom().toString() + '\t' + initiation.getSessionID();
    IQ streamMethodInitiation;
    try {
        streamMethodInitiation = initationSetEvents.performActionAndWaitForEvent(eventKey, connection.getReplyTimeout(), new Callback<NotConnectedException>() {

            @Override
            public void action() throws NotConnectedException {
                try {
                    connection.sendStanza(response);
                } catch (InterruptedException e) {
                // Ignore
                }
            }
        });
    } catch (InterruptedException e) {
        // TODO remove this try/catch once merged into 4.2's master branch
        throw new IllegalStateException(e);
    }
    if (streamMethodInitiation == null) {
        throw NoResponseException.newWith(connection, "stream initiation");
    }
    XMPPErrorException.ifHasErrorThenThrow(streamMethodInitiation);
    return streamMethodInitiation;
}
Also used : StreamInitiation(org.jivesoftware.smackx.si.packet.StreamInitiation) Callback(org.jivesoftware.smack.util.EventManger.Callback) IQ(org.jivesoftware.smack.packet.IQ)

Aggregations

IQ (org.jivesoftware.smack.packet.IQ)138 Test (org.junit.Test)57 ErrorIQ (org.jivesoftware.smack.packet.ErrorIQ)12 Stanza (org.jivesoftware.smack.packet.Stanza)12 InputStream (java.io.InputStream)11 StanzaListener (org.jivesoftware.smack.StanzaListener)10 XMPPErrorException (org.jivesoftware.smack.XMPPException.XMPPErrorException)10 Data (org.jivesoftware.smackx.bytestreams.ibb.packet.Data)10 DataPacketExtension (org.jivesoftware.smackx.bytestreams.ibb.packet.DataPacketExtension)10 OutputStream (java.io.OutputStream)9 ArrayList (java.util.ArrayList)9 Bytestream (org.jivesoftware.smackx.bytestreams.socks5.packet.Bytestream)8 XMPPError (org.jivesoftware.smack.packet.XMPPError)7 Jid (org.jxmpp.jid.Jid)7 NetworkException (com.xabber.android.data.NetworkException)6 OnResponseListener (com.xabber.android.data.connection.OnResponseListener)6 IOException (java.io.IOException)6 XMPPConnection (org.jivesoftware.smack.XMPPConnection)6 EmptyResultIQ (org.jivesoftware.smack.packet.EmptyResultIQ)6 DiscoverInfo (org.jivesoftware.smackx.disco.packet.DiscoverInfo)6