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);
}
}
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);
}
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());
}
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);
}
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);
}
Aggregations