use of org.apache.mina.core.buffer.IoBuffer in project zm-mailbox by Zimbra.
the class MilterHandlerTest method testParseMicro.
@Test
public void testParseMicro() throws IOException {
String to = "To" + '\0' + "admin@example.com; admin2@example.com";
byte[] b = to.getBytes("iso-8859-1");
IoBuffer buf = getIoBuffer(b);
Map<String, String> address = MilterHandler.parseMacros(buf);
Assert.assertEquals(1, address.size());
}
use of org.apache.mina.core.buffer.IoBuffer in project zm-mailbox by Zimbra.
the class MilterHandlerTest method testParseMicroNonAscii.
@Test
public void testParseMicroNonAscii() throws IOException {
String to = "To" + '\0' + "R\u00e9\u4f60\u597d <toadmin@example.com>";
byte[] b = to.getBytes("iso-8859-1");
IoBuffer buf = getIoBuffer(b);
Map<String, String> address = MilterHandler.parseMacros(buf);
Assert.assertEquals(0, address.size());
}
use of org.apache.mina.core.buffer.IoBuffer in project zm-mailbox by Zimbra.
the class SaslFilter method messageReceived.
@Override
public void messageReceived(NextFilter nextFilter, IoSession session, Object message) throws IOException {
IoBuffer buf = (IoBuffer) message;
debug("messageReceived: size = %d", buf.remaining());
synchronized (mInputBuffer) {
// Read and decrypt cipher blocks from input buffer
while (buf.hasRemaining()) {
debug("messageReceived: remaining = %d", buf.remaining());
mInputBuffer.put(buf);
debug("messageReceived: remaining = %d", buf.remaining());
debug("messageReceived: length = %d", mInputBuffer.getLength());
if (mInputBuffer.isComplete()) {
debug("messageReceived: input complete");
byte[] b = mInputBuffer.unwrap(mSecurityLayer);
nextFilter.messageReceived(session, IoBuffer.wrap(b));
mInputBuffer.clear();
}
}
}
buf.clear();
}
use of org.apache.mina.core.buffer.IoBuffer in project zm-mailbox by Zimbra.
the class SaslFilter method filterWrite.
@Override
public void filterWrite(NextFilter nextFilter, IoSession session, WriteRequest writeRequest) throws IOException {
IoBuffer buf = (IoBuffer) writeRequest.getMessage();
// has been sent to client.
if (session.containsAttribute(DISABLE_ENCRYPTION_ONCE)) {
debug("filterWrite: before encryption size = %d", buf.remaining());
session.removeAttribute(DISABLE_ENCRYPTION_ONCE);
nextFilter.filterWrite(session, writeRequest);
return;
}
// Encrypt input buffer
debug("filterWrite: message size = %d", buf.remaining());
if (buf.remaining() == 0) {
// Some clients (i.e. imtest) choke upon receiving an empty block
debug("filterWrite: skipping encryption of empty buffer");
nextFilter.filterWrite(session, writeRequest);
return;
}
List<IoBuffer> buffers = encrypt(buf);
buf.clear();
// Create and send new WriteRequest for each output buffer. The last
// request includes the WriteFuture from the original request, and this
// ensures correctness of the WriteFuture since the earlier requests
// will have been written before the last.
int size = buffers.size();
for (int i = 0; i < size - 1; i++) {
nextFilter.filterWrite(session, new DefaultWriteRequest(buffers.get(i)));
}
nextFilter.filterWrite(session, new DefaultWriteRequest(buffers.get(size - 1), writeRequest.getFuture()));
}
use of org.apache.mina.core.buffer.IoBuffer in project Openfire by igniterealtime.
the class XMLLightweightParserTest method testOF2329OpenAndCloseWithNewline.
/**
* Asserts that a start-tag name can be parsed when it is followed by a newline character.
*
* This test checks for a variation of the issue described in OF-2329.
*
* @see <a href="https://igniterealtime.atlassian.net/browse/OF-2329">OF-2329: XML parsing bug when tag-name is not followed by space or '>'</a>
*/
@Test
public void testOF2329OpenAndCloseWithNewline() throws Exception {
// Setup test fixture.
final String input = "<presence\n to='foo@example.org'></presence>";
final IoBuffer buffer = IoBuffer.allocate(input.length(), false);
buffer.putString(input, StandardCharsets.UTF_8.newEncoder());
buffer.flip();
final XMLLightweightParser parser = new XMLLightweightParser(StandardCharsets.UTF_8);
// Execute system under test.
parser.read(buffer);
final String[] result = parser.getMsgs();
// Verify results.
assertNotNull(result);
assertEquals(1, result.length);
}
Aggregations