use of org.apache.tomcat.util.buf.CharChunk in project tomcat by apache.
the class CoyoteAdapter method checkNormalize.
/**
* Check that the URI is normalized following character decoding. This
* method checks for "\", 0, "//", "/./" and "/../".
*
* @param uriMB URI to be checked (should be chars)
*
* @return <code>false</code> if sequences that are supposed to be
* normalized are still present in the URI, otherwise
* <code>true</code>
*/
public static boolean checkNormalize(MessageBytes uriMB) {
CharChunk uriCC = uriMB.getCharChunk();
char[] c = uriCC.getChars();
int start = uriCC.getStart();
int end = uriCC.getEnd();
int pos = 0;
// Check for '\' and 0
for (pos = start; pos < end; pos++) {
if (c[pos] == '\\') {
return false;
}
if (c[pos] == 0) {
return false;
}
}
// Check for "//"
for (pos = start; pos < (end - 1); pos++) {
if (c[pos] == '/') {
if (c[pos + 1] == '/') {
return false;
}
}
}
// Check for ending with "/." or "/.."
if (((end - start) >= 2) && (c[end - 1] == '.')) {
if ((c[end - 2] == '/') || ((c[end - 2] == '.') && (c[end - 3] == '/'))) {
return false;
}
}
// Check for "/./"
if (uriCC.indexOf("/./", 0, 3, 0) >= 0) {
return false;
}
// Check for "/../"
if (uriCC.indexOf("/../", 0, 4, 0) >= 0) {
return false;
}
return true;
}
use of org.apache.tomcat.util.buf.CharChunk in project tomcat70 by apache.
the class AjpMessage method appendBytes.
/**
* Write a MessageBytes out at the current write position.
* A null MessageBytes is encoded as a string with length 0.
*/
public void appendBytes(MessageBytes mb) {
if (mb == null) {
log.error(sm.getString("ajpmessage.null"), new NullPointerException());
appendInt(0);
appendByte(0);
return;
}
if (mb.getType() == MessageBytes.T_BYTES) {
ByteChunk bc = mb.getByteChunk();
appendByteChunk(bc);
} else if (mb.getType() == MessageBytes.T_CHARS) {
CharChunk cc = mb.getCharChunk();
appendCharChunk(cc);
} else {
appendString(mb.toString());
}
}
use of org.apache.tomcat.util.buf.CharChunk in project tomcat70 by apache.
the class CoyoteAdapter method convertMB.
/**
* Character conversion of the a US-ASCII MessageBytes.
*/
protected void convertMB(MessageBytes mb) {
// This is of course only meaningful for bytes
if (mb.getType() != MessageBytes.T_BYTES) {
return;
}
ByteChunk bc = mb.getByteChunk();
CharChunk cc = mb.getCharChunk();
int length = bc.getLength();
cc.allocate(length, -1);
// Default encoding: fast conversion
byte[] bbuf = bc.getBuffer();
char[] cbuf = cc.getBuffer();
int start = bc.getStart();
for (int i = 0; i < length; i++) {
cbuf[i] = (char) (bbuf[i + start] & 0xff);
}
mb.setChars(cbuf, 0, length);
}
use of org.apache.tomcat.util.buf.CharChunk in project tomcat70 by apache.
the class InputBuffer method recycle.
// --------------------------------------------------------- Public Methods
/**
* Recycle the output buffer.
*/
public void recycle() {
state = INITIAL_STATE;
// If usage of mark made the buffer too big, reallocate it
if (cb.getChars().length > size) {
cb = new CharChunk(size);
cb.setLimit(size);
cb.setOptimizedWrite(false);
cb.setCharInputChannel(this);
cb.setCharOutputChannel(this);
} else {
cb.recycle();
}
markPos = -1;
bb.recycle();
closed = false;
if (conv != null) {
conv.recycle();
}
gotEnc = false;
enc = null;
}
use of org.apache.tomcat.util.buf.CharChunk in project tomcat70 by apache.
the class TesterBase64Performance method testDecode.
@SuppressWarnings("deprecation")
@Test
public void testDecode() throws Exception {
List<ByteChunk> inputs = new ArrayList<ByteChunk>(SIZE);
for (int i = 0; i < SIZE; i++) {
String decodedString = "abc" + Integer.valueOf(i) + ":abc" + Integer.valueOf(i);
byte[] decodedBytes = decodedString.getBytes(B2CConverter.ISO_8859_1);
String encodedString = DatatypeConverter.printBase64Binary(decodedBytes);
byte[] encodedBytes = encodedString.getBytes(B2CConverter.ISO_8859_1);
ByteChunk bc = new ByteChunk(encodedBytes.length);
bc.append(encodedBytes, 0, encodedBytes.length);
inputs.add(bc);
}
long startTomcat = System.currentTimeMillis();
for (ByteChunk bc : inputs) {
CharChunk cc = new CharChunk(bc.getLength());
Base64.decode(bc, cc);
}
long stopTomcat = System.currentTimeMillis();
System.out.println("Tomcat: " + (stopTomcat - startTomcat) + " ms");
long startCodec = System.currentTimeMillis();
for (ByteChunk bc : inputs) {
org.apache.tomcat.util.codec.binary.Base64.decodeBase64(bc.getBuffer(), bc.getOffset(), bc.getLength());
}
long stopCodec = System.currentTimeMillis();
System.out.println("Codec: " + (stopCodec - startCodec) + " ms");
}
Aggregations