costin 01/06/24 14:17:49
Modified: jk/java/org/apache/ajp Ajp13.java Ajp13Packet.java
Log:
Merged the new methods and code that was added in o.a.ajp.tomcat33.
Revision Changes Path
1.7 +44 -20 jakarta-tomcat-connectors/jk/java/org/apache/ajp/Ajp13.java
Index: Ajp13.java
===================================================================
RCS file: /home/cvs/jakarta-tomcat-connectors/jk/java/org/apache/ajp/Ajp13.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- Ajp13.java 2001/06/09 02:56:22 1.6
+++ Ajp13.java 2001/06/24 21:17:49 1.7
@@ -210,24 +210,17 @@
int blen; // Length of current chunk of body data in buffer
int pos; // Current read position within that buffer
- private int debug = 10;
-
- /**
- * XXX place holder...
- */
- Logger logger = new Logger();
- class Logger {
- void log(String msg) {
- System.out.println("[Ajp13] " + msg);
- }
-
- void log(String msg, Throwable t) {
- System.out.println("[Ajp13] " + msg);
- t.printStackTrace(System.out);
- }
+ public Ajp13() {
+ super();
+ initBuf();
}
- public Ajp13() {
+ /** Will be overriden
+ */
+ public void initBuf() {
+ outBuf = new Ajp13Packet( MAX_PACKET_SIZE );
+ inBuf = new Ajp13Packet( MAX_PACKET_SIZE );
+ hBuf=new Ajp13Packet( MAX_PACKET_SIZE );
}
public void recycle() {
@@ -290,6 +283,15 @@
}
/**
+ * Try to decode Headers - AJP13 will do nothing but descendant will
+ * override this method to handle new headers (ie SSL_KEY_SIZE in AJP14)
+ */
+ int decodeMoreHeaders(AjpRequest req, byte attribute, Ajp13Packet msg)
+ {
+ return 500;
+ }
+
+ /**
* Parse a FORWARD_REQUEST packet from the web server and store its
* properties in the passed-in request object.
*
@@ -300,8 +302,9 @@
*
* @return 200 in case of a successful decoduing, 500 in case of error.
*/
- private int decodeRequest(AjpRequest req, Ajp13Packet msg)
- throws IOException {
+ protected int decodeRequest(AjpRequest req, Ajp13Packet msg)
+ throws IOException
+ {
if (debug > 0) {
logger.log("decodeRequest()");
@@ -413,7 +416,10 @@
break;
default:
- return 500; // Error
+ if (decodeMoreHeaders(req, attributeCode, msg) != 500)
+ break;
+
+ return 500;
}
}
@@ -773,7 +779,7 @@
* @return The number of bytes read on a successful read or -1 if there
* was an error.
**/
- private int receive(Ajp13Packet msg) throws IOException {
+ public int receive(Ajp13Packet msg) throws IOException {
if (debug > 0) {
logger.log("receive()");
}
@@ -851,5 +857,23 @@
if(null !=in) {
in.close();
}
+ }
+
+ // -------------------- Debug --------------------
+ private int debug = 10;
+
+ /**
+ * XXX place holder...
+ */
+ Logger logger = new Logger();
+ class Logger {
+ void log(String msg) {
+ System.out.println("[Ajp13] " + msg);
+ }
+
+ void log(String msg, Throwable t) {
+ System.out.println("[Ajp13] " + msg);
+ t.printStackTrace(System.out);
+ }
}
}
1.8 +91 -2
jakarta-tomcat-connectors/jk/java/org/apache/ajp/Ajp13Packet.java
Index: Ajp13Packet.java
===================================================================
RCS file:
/home/cvs/jakarta-tomcat-connectors/jk/java/org/apache/ajp/Ajp13Packet.java,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- Ajp13Packet.java 2001/06/19 03:15:32 1.7
+++ Ajp13Packet.java 2001/06/24 21:17:49 1.8
@@ -58,6 +58,7 @@
*/
package org.apache.ajp;
+import java.io.IOException;
import java.io.UnsupportedEncodingException;
import org.apache.tomcat.util.buf.MessageBytes;
@@ -69,6 +70,11 @@
* garbage. Understands the format of data types for these packets.
* Can be used (somewhat confusingly) for both incoming and outgoing
* packets.
+ *
+ * @author Dan Milstein [[EMAIL PROTECTED]]
+ * @author Keith Wannamaker [[EMAIL PROTECTED]]
+ * @author Kevin Seguin
+ * @author Costin Manolache
*/
public class Ajp13Packet {
@@ -215,7 +221,7 @@
// ============ Data Writing Methods ===================
/**
- * Write an integer at an arbitrary position in the packet, but don't
+ * Write an 32 bit integer at an arbitrary position in the packet,but don't
* change the write position.
*
* @param bpos The 0-indexed position within the buffer at which to
@@ -267,7 +273,7 @@
byte[] bytes = str.getBytes(encoding);
appendBytes(bytes, 0, bytes.length);
- /*
+ /* XXX XXX XXX XXX Try to add it back.
int strStart=pos;
// This replaces the old ( buggy and slow ) str.length()
@@ -313,7 +319,45 @@
pos += numBytes + 1;
}
+ /**
+ * Write a 32 bits integer at an arbitrary position in the packet, but don't
+ * change the write position.
+ *
+ * @param bpos The 0-indexed position within the buffer at which to
+ * write the integer (where 0 is the beginning of the header).
+ * @param val The integer to write.
+ */
+ private void setLongInt( int bPos, int val ) {
+ buff[bPos] = (byte) ((val >>> 24) & 0xFF);
+ buff[bPos+1] = (byte) ((val >>> 16) & 0xFF);
+ buff[bPos+2] = (byte) ((val >>> 8) & 0xFF);
+ buff[bPos+3] = (byte) (val & 0xFF);
+ }
+
+ public void appendLongInt( int val ) {
+ setLongInt( pos, val );
+ pos += 4;
+ }
+
+ /**
+ * Copy a chunk of bytes into the packet, starting at the current
+ * write position. The chunk of bytes IS NOT ENCODED with ANY length
+ * header.
+ *
+ * @param b The array from which to copy bytes.
+ * @param off The offset into the array at which to start copying
+ * @param len The number of bytes to copy.
+ */
+ public void appendXBytes(byte[] b, int off, int numBytes) {
+ if( pos + numBytes > buff.length ) {
+ System.out.println("appendXBytes - Buffer overflow " + buff.length + " " +
pos + " " + numBytes );
+ // XXX Log
+ }
+ System.arraycopy( b, off, buff, pos, numBytes);
+ pos += numBytes;
+ }
+
// ============ Data Reading Methods ===================
/**
@@ -416,6 +460,51 @@
pos += length;
pos++; // Skip terminating \0 XXX I believe this is wrong but harmless
return length;
+ }
+
+ /**
+ * Read a 32 bits integer from packet, and advance the read position past
+ * it. Integers are encoded as four unsigned bytes with the
+ * high-order byte first, and, as far as I can tell, in
+ * little-endian order within each byte.
+ */
+ public int getLongInt() {
+ int result = peekLongInt();
+ pos += 4;
+ return result;
+ }
+
+ /**
+ * Copy a chunk of bytes from the packet into an array and advance
+ * the read position past the chunk. See appendXBytes() for details
+ * on the encoding.
+ *
+ * @return The number of bytes copied.
+ */
+ public int getXBytes(byte[] dest, int length) {
+ if( length > buff.length ) {
+ // XXX Should be if(pos + length > buff.legth)?
+ System.out.println("XXX Assert failed, buff too small ");
+ }
+
+ System.arraycopy( buff, pos, dest, 0, length );
+ pos += length;
+ return length;
+ }
+
+ /**
+ * Read a 32 bits integer from the packet, but don't advance the read
+ * position past it.
+ */
+ public int peekLongInt() {
+ int b1 = buff[pos] & 0xFF; // No swap, Java order
+ b1 <<= 8;
+ b1 |= (buff[pos + 1] & 0xFF);
+ b1 <<= 8;
+ b1 |= (buff[pos + 2] & 0xFF);
+ b1 <<=8;
+ b1 |= (buff[pos + 3] & 0xFF);
+ return b1;
}
// ============== Debugging code =========================