Search in sources :

Example 1 with Open

use of org.jivesoftware.smackx.bytestreams.ibb.packet.Open in project Smack by igniterealtime.

the class InitiationListener method processRequest.

private void processRequest(Stanza packet) throws NotConnectedException, InterruptedException {
    Open ibbRequest = (Open) packet;
    // validate that block size is within allowed range
    if (ibbRequest.getBlockSize() > this.manager.getMaximumBlockSize()) {
        this.manager.replyResourceConstraintPacket(ibbRequest);
        return;
    }
    StreamNegotiator.signal(ibbRequest.getFrom().toString() + '\t' + ibbRequest.getSessionID(), ibbRequest);
    // ignore request if in ignore list
    if (this.manager.getIgnoredBytestreamRequests().remove(ibbRequest.getSessionID()))
        return;
    // build bytestream request from packet
    InBandBytestreamRequest request = new InBandBytestreamRequest(this.manager, ibbRequest);
    // notify listeners for bytestream initiation from a specific user
    BytestreamListener userListener = this.manager.getUserListener(ibbRequest.getFrom());
    if (userListener != null) {
        userListener.incomingBytestreamRequest(request);
    } else if (!this.manager.getAllRequestListeners().isEmpty()) {
        /*
             * if there is no user specific listener inform listeners for all initiation requests
             */
        for (BytestreamListener listener : this.manager.getAllRequestListeners()) {
            listener.incomingBytestreamRequest(request);
        }
    } else {
        /*
             * if there is no listener for this initiation request, reply with reject message
             */
        this.manager.replyRejectPacket(ibbRequest);
    }
}
Also used : BytestreamListener(org.jivesoftware.smackx.bytestreams.BytestreamListener) Open(org.jivesoftware.smackx.bytestreams.ibb.packet.Open)

Example 2 with Open

use of org.jivesoftware.smackx.bytestreams.ibb.packet.Open in project Smack by igniterealtime.

the class OpenIQProvider method parse.

@Override
public Open parse(XmlPullParser parser, int initialDepth) throws XmlPullParserException, IOException {
    String sessionID = parser.getAttributeValue("", "sid");
    int blockSize = Integer.parseInt(parser.getAttributeValue("", "block-size"));
    String stanzaValue = parser.getAttributeValue("", "stanza");
    StanzaType stanza = null;
    if (stanzaValue == null) {
        stanza = StanzaType.IQ;
    } else {
        stanza = StanzaType.valueOf(stanzaValue.toUpperCase(Locale.US));
    }
    parser.next();
    return new Open(sessionID, blockSize, stanza);
}
Also used : StanzaType(org.jivesoftware.smackx.bytestreams.ibb.InBandBytestreamManager.StanzaType) Open(org.jivesoftware.smackx.bytestreams.ibb.packet.Open)

Example 3 with Open

use of org.jivesoftware.smackx.bytestreams.ibb.packet.Open in project Smack by igniterealtime.

the class InBandBytestreamTest method testRespondWithErrorOnInBandBytestreamRequest.

/**
     * Target should respond with not-acceptable error if no listeners for incoming In-Band
     * Bytestream requests are registered.
     * 
     * @throws XMPPException should not happen
     */
public void testRespondWithErrorOnInBandBytestreamRequest() throws XMPPException {
    XMPPConnection targetConnection = getConnection(0);
    XMPPConnection initiatorConnection = getConnection(1);
    Open open = new Open("sessionID", 1024);
    open.setFrom(initiatorConnection.getUser());
    open.setTo(targetConnection.getUser());
    StanzaCollector collector = initiatorConnection.createStanzaCollector(new PacketIDFilter(open.getStanzaId()));
    initiatorConnection.sendStanza(open);
    Packet result = collector.nextResult();
    assertNotNull(result.getError());
    assertEquals(XMPPError.Condition.no_acceptable.toString(), result.getError().getCondition());
}
Also used : Packet(org.jivesoftware.smack.packet.Packet) XMPPConnection(org.jivesoftware.smack.XMPPConnection) StanzaCollector(org.jivesoftware.smack.StanzaCollector) PacketIDFilter(org.jivesoftware.smack.filter.PacketIDFilter) Open(org.jivesoftware.smackx.bytestreams.ibb.packet.Open)

Example 4 with Open

use of org.jivesoftware.smackx.bytestreams.ibb.packet.Open in project Smack by igniterealtime.

the class InBandBytestreamRequestTest method setup.

/**
     * Initialize fields used in the tests.
     */
@Before
public void setup() {
    // mock connection
    connection = mock(XMPPConnection.class);
    // initialize InBandBytestreamManager to get the InitiationListener
    byteStreamManager = InBandBytestreamManager.getByteStreamManager(connection);
    // create a In-Band Bytestream open packet
    initBytestream = new Open(sessionID, 4096);
    initBytestream.setFrom(initiatorJID);
    initBytestream.setTo(targetJID);
}
Also used : XMPPConnection(org.jivesoftware.smack.XMPPConnection) Open(org.jivesoftware.smackx.bytestreams.ibb.packet.Open) Before(org.junit.Before)

Example 5 with Open

use of org.jivesoftware.smackx.bytestreams.ibb.packet.Open in project Smack by igniterealtime.

the class InitiationListenerTest method setup.

/**
     * Initialize fields used in the tests.
     */
@Before
public void setup() {
    // mock connection
    connection = mock(XMPPConnection.class);
    // initialize InBandBytestreamManager to get the InitiationListener
    byteStreamManager = InBandBytestreamManager.getByteStreamManager(connection);
    // get the InitiationListener from InBandByteStreamManager
    initiationListener = Whitebox.getInternalState(byteStreamManager, InitiationListener.class);
    // create a In-Band Bytestream open packet
    initBytestream = new Open(sessionID, 4096);
    initBytestream.setFrom(initiatorJID);
    initBytestream.setTo(targetJID);
}
Also used : XMPPConnection(org.jivesoftware.smack.XMPPConnection) Open(org.jivesoftware.smackx.bytestreams.ibb.packet.Open) Before(org.junit.Before)

Aggregations

Open (org.jivesoftware.smackx.bytestreams.ibb.packet.Open)10 Before (org.junit.Before)4 XMPPConnection (org.jivesoftware.smack.XMPPConnection)3 IQ (org.jivesoftware.smack.packet.IQ)2 Protocol (org.jivesoftware.util.Protocol)2 Test (org.junit.Test)2 StanzaCollector (org.jivesoftware.smack.StanzaCollector)1 PacketIDFilter (org.jivesoftware.smack.filter.PacketIDFilter)1 Message (org.jivesoftware.smack.packet.Message)1 Packet (org.jivesoftware.smack.packet.Packet)1 BytestreamListener (org.jivesoftware.smackx.bytestreams.BytestreamListener)1 StanzaType (org.jivesoftware.smackx.bytestreams.ibb.InBandBytestreamManager.StanzaType)1 Data (org.jivesoftware.smackx.bytestreams.ibb.packet.Data)1 DataPacketExtension (org.jivesoftware.smackx.bytestreams.ibb.packet.DataPacketExtension)1