pier 01/07/25 15:32:05 Modified: webapp/java WarpPacket.java WarpRequest.java WarpRequestHandler.java webapp/lib pr_warp.c pr_warp.h pr_warp_network.c wa_config.c Log: Fixing bug 1245/2777: POST data not transmitted correctly over WARP. Revision Changes Path 1.14 +1 -1 jakarta-tomcat-connectors/webapp/java/WarpPacket.java Index: WarpPacket.java =================================================================== RCS file: /home/cvs/jakarta-tomcat-connectors/webapp/java/WarpPacket.java,v retrieving revision 1.13 retrieving revision 1.14 diff -u -r1.13 -r1.14 --- WarpPacket.java 2001/07/25 01:30:46 1.13 +++ WarpPacket.java 2001/07/25 22:32:05 1.14 @@ -66,7 +66,7 @@ protected int size=0; /* Pointer to the last byte read in the buffer */ - private int pointer=0; + protected int pointer=0; /* Type of this packet */ private int type=-1; /* Maximum value for a 16 bit unsigned value (0x0ffff +1) */ 1.9 +92 -0 jakarta-tomcat-connectors/webapp/java/WarpRequest.java Index: WarpRequest.java =================================================================== RCS file: /home/cvs/jakarta-tomcat-connectors/webapp/java/WarpRequest.java,v retrieving revision 1.8 retrieving revision 1.9 diff -u -r1.8 -r1.9 --- WarpRequest.java 2001/07/25 01:30:46 1.8 +++ WarpRequest.java 2001/07/25 22:32:05 1.9 @@ -56,15 +56,25 @@ * ========================================================================= */ package org.apache.catalina.connector.warp; +import java.io.*; + import org.apache.catalina.Context; import org.apache.catalina.Host; import org.apache.catalina.connector.HttpRequestBase; public class WarpRequest extends HttpRequestBase { + /** The local stream */ + private Stream localstream; + + /** The connection to which we are associated */ + private WarpConnection connection; + private Host host=null; public WarpRequest() { super(); + this.localstream=new Stream(this); + this.setStream(this.localstream); } public void setHost(Host host) { @@ -73,5 +83,87 @@ public Host getHost() { return(this.host); + } + + /** + * Recycle this <code>WarpResponse</code> instance. + */ + public void recycle() { + // Recycle our parent + super.recycle(); + // Recycle the stream + this.localstream.recycle(); + // Tell the parent that a stream is already in use. + this.setStream(localstream); + } + + /** + * Associate this <code>WarpResponse</code> instance with a specific + * <code>WarpConnection</code> instance. + */ + public void setConnection(WarpConnection connection) { + this.connection=connection; + } + + /** + * Return the <code>WarpConnection</code> associated this instance of + * <code>WarpResponse</code>. + */ + public WarpConnection getConnection() { + return(this.connection); + } + + protected class Stream extends InputStream { + + /** The response associated with this stream instance. */ + private WarpRequest request=null; + /** The packet used by this stream instance. */ + private WarpPacket packet=null; + /** Wether <code>close()</code> was called or not. */ + private boolean closed=false; + + protected Stream(WarpRequest request) { + super(); + this.request=request; + this.packet=new WarpPacket(); + this.packet.setType(Constants.TYPE_CBK_DATA); + } + + public int read() + throws IOException { + if (closed) throw new IOException("Stream closed"); + + if (packet.getType()==Constants.TYPE_CBK_DONE) return(-1); + + if (packet.getType()!=Constants.TYPE_CBK_DATA) + throw new IOException("Invalid WARP packet type for body"); + + if (this.packet.pointer<this.packet.size) + return((int)this.packet.buffer[this.packet.pointer++]); + + this.packet.reset(); + this.packet.setType(Constants.TYPE_CBK_READ); + this.packet.writeUnsignedShort(65535); + this.request.getConnection().send(packet); + packet.reset(); + + this.request.getConnection().recv(packet); + return(this.read()); + } + + public void close() + throws IOException { + if (closed) throw new IOException("Stream closed"); + this.packet.reset(); + this.packet.setType(Constants.TYPE_CBK_DONE); + this.closed=true; + } + + public void recycle() { + this.packet.reset(); + this.packet.setType(Constants.TYPE_CBK_DATA); + this.closed=false; + } + } } 1.14 +2 -0 jakarta-tomcat-connectors/webapp/java/WarpRequestHandler.java Index: WarpRequestHandler.java =================================================================== RCS file: /home/cvs/jakarta-tomcat-connectors/webapp/java/WarpRequestHandler.java,v retrieving revision 1.13 retrieving revision 1.14 diff -u -r1.13 -r1.14 --- WarpRequestHandler.java 2001/07/25 03:52:02 1.13 +++ WarpRequestHandler.java 2001/07/25 22:32:05 1.14 @@ -89,6 +89,7 @@ response.setRequest(request); response.setConnection(connection); response.setPacket(packet); + request.setConnection(connection); // Prepare the Proceed packet packet.reset(); @@ -120,6 +121,7 @@ request.setRequestURI(ruri); request.setQueryString(args); request.setProtocol(prot); + request.setConnection(connection); Context ctx=connector.applicationContext(id); if (ctx!=null) { request.setContext(ctx); 1.12 +21 -1 jakarta-tomcat-connectors/webapp/lib/pr_warp.c Index: pr_warp.c =================================================================== RCS file: /home/cvs/jakarta-tomcat-connectors/webapp/lib/pr_warp.c,v retrieving revision 1.11 retrieving revision 1.12 diff -u -r1.11 -r1.12 --- pr_warp.c 2001/07/25 03:30:42 1.11 +++ pr_warp.c 2001/07/25 22:32:05 1.12 @@ -54,7 +54,7 @@ * * * ========================================================================= */ -/* @version $Id: pr_warp.c,v 1.11 2001/07/25 03:30:42 pier Exp $ */ +/* @version $Id: pr_warp.c,v 1.12 2001/07/25 22:32:05 pier Exp $ */ #include "pr_warp.h" /* Initialize this provider. */ @@ -385,6 +385,26 @@ case TYPE_RES_DONE: { wa_debug(WA_MARK,"=== DONE ==="); return(status); + break; + } + case TYPE_CBK_READ: { + int size=-1; + p_read_ushort(pack,&size); + p_reset(pack); + size=wa_rread(r,pack->buff,size); + if (size==0) { + pack->type=TYPE_CBK_DONE; + } else if (size>0) { + pack->type=TYPE_CBK_DATA; + pack->size=size; + } else { + pack->type=TYPE_ERROR; + p_write_string(pack,"Transfer interrupted"); + } + if (n_send(conf->sock,pack)!=wa_true) { + n_disconnect(conn); + return(wa_rerror(WA_MARK,r,500,"Communitcation interrupted")); + } break; } case TYPE_ERROR: { 1.6 +5 -1 jakarta-tomcat-connectors/webapp/lib/pr_warp.h Index: pr_warp.h =================================================================== RCS file: /home/cvs/jakarta-tomcat-connectors/webapp/lib/pr_warp.h,v retrieving revision 1.5 retrieving revision 1.6 diff -u -r1.5 -r1.6 --- pr_warp.h 2001/07/25 03:30:42 1.5 +++ pr_warp.h 2001/07/25 22:32:05 1.6 @@ -54,7 +54,7 @@ * * * ========================================================================= */ -/* @version $Id: pr_warp.h,v 1.5 2001/07/25 03:30:42 pier Exp $ */ +/* @version $Id: pr_warp.h,v 1.6 2001/07/25 22:32:05 pier Exp $ */ #ifndef _PR_WARP_H_ #define _PR_WARP_H_ @@ -130,6 +130,10 @@ #define TYPE_RES_COMMIT 0x2f #define TYPE_RES_BODY 0x30 #define TYPE_RES_DONE 0x3f + +#define TYPE_CBK_READ 0x40 +#define TYPE_CBK_DATA 0x41 +#define TYPE_CBK_DONE 0x42 /* ************************************************************************* */ 1.4 +2 -2 jakarta-tomcat-connectors/webapp/lib/pr_warp_network.c Index: pr_warp_network.c =================================================================== RCS file: /home/cvs/jakarta-tomcat-connectors/webapp/lib/pr_warp_network.c,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- pr_warp_network.c 2001/07/19 04:24:15 1.3 +++ pr_warp_network.c 2001/07/25 22:32:05 1.4 @@ -54,7 +54,7 @@ * * * ========================================================================= */ -/* @version $Id: pr_warp_network.c,v 1.3 2001/07/19 04:24:15 pier Exp $ */ +/* @version $Id: pr_warp_network.c,v 1.4 2001/07/25 22:32:05 pier Exp $ */ #include "pr_warp.h" wa_boolean n_recv(apr_socket_t *sock, warp_packet *pack) { @@ -94,7 +94,7 @@ } } - wa_debug(WA_MARK,"WARP <<< TYP=%d LEN=%d",pack->type,pack->size); + wa_debug(WA_MARK,"WARP <<< TYP=%02X LEN=%d",pack->type,pack->size); return(wa_true); } 1.4 +2 -1 jakarta-tomcat-connectors/webapp/lib/wa_config.c Index: wa_config.c =================================================================== RCS file: /home/cvs/jakarta-tomcat-connectors/webapp/lib/wa_config.c,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- wa_config.c 2001/07/19 04:21:38 1.3 +++ wa_config.c 2001/07/25 22:32:05 1.4 @@ -55,7 +55,7 @@ * * * ========================================================================= */ -/* @version $Id: wa_config.c,v 1.3 2001/07/19 04:21:38 pier Exp $ */ +/* @version $Id: wa_config.c,v 1.4 2001/07/25 22:32:05 pier Exp $ */ #include <wa.h> /* Allocate and set up a <code>wa_application</code> member. */ @@ -118,6 +118,7 @@ /* Set up parameters */ host->name=apr_pstrdup(wa_pool,n); host->port=p; + host->apps=NULL; /* Done! :) */ wa_debug(WA_MARK,"Created virtual host \"%s:%d\"",host->name,host->port);