You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by co...@locus.apache.org on 2000/04/25 02:31:00 UTC

cvs commit: jakarta-tomcat/src/native/jk jk_msg_buff.c jk_msg_buff.h jk_ajp23_worker.c

costin      00/04/24 17:31:00

  Modified:    src/native/apache2.0 mod_jk.c
               src/native/jk jk_ajp23_worker.c
  Added:       src/native/apache2.0 Makefile.linux
               src/native/jk jk_msg_buff.c jk_msg_buff.h
  Log:
  - Fixed apache2.0 connector to work with the latest Apache 2.0 ( they
  replaced ap_context back with ap_pool )
  
  - Added Makefile.linux - we'll have to build a configure or something
  better, now you have to edit the file, etc
  
  - Added the right hook for linux ( child_init instead of post_config)
  
  - separate the "marshalling" code out of ajp23 ( now it's in jk_msg_buf)
  
  Revision  Changes    Path
  1.2       +46 -6     jakarta-tomcat/src/native/apache2.0/mod_jk.c
  
  Index: mod_jk.c
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat/src/native/apache2.0/mod_jk.c,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- mod_jk.c	2000/04/13 13:07:08	1.1
  +++ mod_jk.c	2000/04/25 00:30:59	1.2
  @@ -496,7 +496,7 @@
       return HTTP_INTERNAL_SERVER_ERROR;
   }
   
  -static void *create_jk_config(ap_context_t *p, server_rec *s)
  +static void *create_jk_config(ap_pool_t *p, server_rec *s)
   {
       jk_server_conf_t *c =
           (jk_server_conf_t *) ap_pcalloc(p, sizeof(jk_server_conf_t));
  @@ -517,7 +517,7 @@
   }
   
   
  -static void *merge_jk_config(ap_context_t *p, 
  +static void *merge_jk_config(ap_pool_t *p, 
                                void *basev, 
                                void *overridesv)
   {
  @@ -554,9 +554,42 @@
       return overrides;
   }
   
  -static void jk_post_config(ap_context_t *pconf, 
  -                           ap_context_t *plog, 
  -                           ap_context_t *ptemp, 
  +static void jk_child_init(ap_pool_t *pconf, 
  +			  server_rec *s)
  +{
  +    char *p = getenv("WAS_BORN_BY_APACHE");
  +    jk_map_t *init_map = NULL;
  +    jk_server_conf_t *conf =
  +        (jk_server_conf_t *)ap_get_module_config(s->module_config, &jk_module);
  +
  +    fprintf(stdout, "jk_post_config %s\n", p ? p : "NULL"); fflush(stdout);
  +        
  +    if(conf->log_file && conf->log_level >= 0) {
  +        if(!jk_open_file_logger(&(conf->log), conf->log_file, conf->log_level)) {
  +            conf->log = NULL;
  +        } else {
  +            main_log = conf->log;
  +        }
  +    }
  +    
  +    if(!uri_worker_map_alloc(&(conf->uw_map), conf->uri_to_context, conf->log)) {
  +        jk_error_exit(APLOG_MARK, APLOG_EMERG, s, "Memory error");
  +    }
  +
  +    if(map_alloc(&init_map)) {
  +        if(map_read_properties(init_map, conf->worker_file)) {
  +	    if(wc_open(init_map, conf->log)) {
  +		return;
  +                }            
  +        }
  +    }
  +
  +    jk_error_exit(APLOG_MARK, APLOG_EMERG, s, "Error while opening the workers");
  +}
  +
  +static void jk_post_config(ap_pool_t *pconf, 
  +                           ap_pool_t *plog, 
  +                           ap_pool_t *ptemp, 
                              server_rec *s)
   {
       char *p = getenv("WAS_BORN_BY_APACHE");
  @@ -618,11 +651,18 @@
   
   static void jk_register_hooks(void)
   {
  -    ap_hook_post_config(jk_post_config,
  +#ifdef LINUX
  +        ap_hook_child_init(jk_child_init,
                           NULL,
                           NULL,
                           HOOK_MIDDLE);    
   
  +#else
  +       ap_hook_post_config(jk_post_config,
  +                        NULL,
  +                        NULL,
  +                        HOOK_MIDDLE);    
  +#endif
       ap_hook_translate_name(jk_translate,
                              NULL,
                              NULL,
  
  
  
  1.1                  jakarta-tomcat/src/native/apache2.0/Makefile.linux
  
  Index: Makefile.linux
  ===================================================================
  ## You need to edit this file - configure later :-)
  
  APACHE_HOME=/usr/local/apache-2.0
  OS=linux
  ## I assume this one is set up already
  # JAVA_HOME=
  
  ## 
  
  AP20_INCL=-I${APACHE_HOME}/include/apr  -I${APACHE_HOME}/include
  JAVA_INCL=-I${JAVA_HOME}/include -I${JAVA_HOME}/include/${OS}
  JAVA_LIB=-L${JAVA_HOME}/jre/lib/${ARCH} -L${JAVA_HOME}/lib/${ARCH}/native_threads
  
  
  ## 
  AP20_SRC=/home/costin/src/jakarta/apache-2.0/src
  AP20SRC_INCL=-I. -I${AP20_SRC}/modules/standard -I${AP20_SRC} -I${AP20_SRC}/include -I${AP20_SRC}/lib/apr/include -I${AP20_SRC}/os/unix
  
  CFLAGS=-DHAVE_CONFIG_H -g -fpic  -DSHARED_MODULE -O2 -D_REENTRANT -pthread -DLINUX
  
  SRCS=jk_ajp12_worker.c jk_connect.c  jk_lb_worker.c  \
       jk_map.c  jk_pool.c jk_sockbuf.c jk_uri_worker_map.c jk_util.c jk_worker.c \
       jk_ajp23_worker.c jk_msg_buff.c jk_jni_worker.c
  
  OBJS=${patsubst %.c,%.o,${SRCS}}
  
  %.o: ../jk/%.c 
  	${CC} -c ${CFLAGS} ${JAVA_INCL} ${AP20SRC_INCL}  $< -o $@
  
  .c.o:
  	${CC} -c ${CFLAGS} ${JAVA_INCL} ${AP20SRC_INCL} -I../jk $<
  
  
  
  all: mod_jk.so
  
  mod_jk.so: ${OBJS} mod_jk.o
  	$(CC) -shared -o mod_jk.so ${OBJS} mod_jk.o
  
  clean:
  	rm *.o *.so
  
  
  
  
  1.2       +54 -257   jakarta-tomcat/src/native/jk/jk_ajp23_worker.c
  
  Index: jk_ajp23_worker.c
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat/src/native/jk/jk_ajp23_worker.c,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- jk_ajp23_worker.c	2000/04/17 09:47:23	1.1
  +++ jk_ajp23_worker.c	2000/04/25 00:30:59	1.2
  @@ -64,6 +64,7 @@
   #include "jk_pool.h"
   #include "jk_connect.h"
   #include "jk_util.h"
  +#include "jk_msg_buff.h"
   #include "jk_sockbuf.h"
   
   #define AJP_DEF_HOST            ("localhost")
  @@ -152,26 +153,6 @@
   /* // XXX replace all return values with error codes */
   #define ERR_BAD_PACKET -5
   
  -/* Data marshaling.
  -   Uses a Buffer ( iovect later ), with 1 copy.
  -   Simple marshaling, based on Ajp21.
  - */
  -
  -/* strbuf ? */
  -struct MsgBuffer_Simple {
  -    jk_pool_t *pool;
  -
  -    unsigned char *buf;
  -    int pos; /* XXX MT */
  -    int len;
  -    int maxlen;
  -};
  -
  -typedef struct MsgBuffer_Simple MsgBuffer;
  -
  -MsgBuffer *new_MsgBuffer();
  -
  -
   /* -------------------- Method -------------------- */
   static int JK_METHOD validate(jk_worker_t *pThis,
                                 jk_map_t *props,                            
  @@ -250,202 +231,18 @@
       jk_log(l, JK_LOG_ERROR, "In jk_endpoint_t::done, NULL parameters\n");
       return JK_FALSE;
   }
  -
  -
  -// ---------------------------------------- START MARSHALL ----------------------------------------
  -
  -
  -/* XXX what's above this line can go to .h XXX */
  -static void b_dump( MsgBuffer *msg, char *err ) {
  -        int i=0;
  -	printf("%s %d/%d/%d %x %x %x %x - %x %x %x %x - %x %x %x %x - %x %x %x %x\n", err, msg->pos, msg->len, msg->maxlen,  
  -	       msg->buf[i++],msg->buf[i++],msg->buf[i++],msg->buf[i++],
  -	       msg->buf[i++],msg->buf[i++],msg->buf[i++],msg->buf[i++],
  -	       msg->buf[i++],msg->buf[i++],msg->buf[i++],msg->buf[i++],
  -	       msg->buf[i++],msg->buf[i++],msg->buf[i++],msg->buf[i++]);
  -
  -	i=msg->pos - 4;
  -	if( i<0 ) i=0;
  -	
  -        printf("        %x %x %x %x - %x %x %x %x --- %x %x %x %x - %x %x %x %x\n", 
  -	       msg->buf[i++],msg->buf[i++],msg->buf[i++],msg->buf[i++],
  -	       msg->buf[i++],msg->buf[i++],msg->buf[i++],msg->buf[i++],
  -	       msg->buf[i++],msg->buf[i++],msg->buf[i++],msg->buf[i++],
  -	       msg->buf[i++],msg->buf[i++],msg->buf[i++],msg->buf[i++]);
  -
  -}
  -
  -static void b_reset( MsgBuffer *msg ) {
  -    msg->len =4;
  -    msg->pos =4;
  -}
  -
  -static void b_set_int( MsgBuffer *msg, int pos, unsigned int val ) {
  -    /* XXX optimize - swap if needed or just copyb */
  -    /* #if SWAP */
  -    /*     swap_16( (unsigned char *)&val, msg->buf ) */
  -    /* #else */
  -    /*     ???	 */
  -    /* #endif  */
  -    msg->buf[pos++]=(unsigned char) ( (val >> 8) & 0xff );
  -    msg->buf[pos]= (unsigned char) ( val & 0xff );
  -}
  -
  -static int b_append_int( MsgBuffer *msg, unsigned int val ) {
  -    if( msg->len + 2 > msg->maxlen ) 
  -	return -1;
  -
  -    b_set_int( msg, msg->len, val );
  -    msg->len +=2;
  -    return 0;
  -}
  -
  -
  -static void b_end(MsgBuffer *msg) {
  -    /* Ugly way to set the size in the right position */
  -    b_set_int( msg, 2, msg->len - 4 ); /* see protocol */
  -    b_set_int( msg, 0, 0x1234 );
  -}
  -
  -
  -/* XXX optimize it ( less function calls, macros )
  -   Ugly pointer arithmetic code
  - */
  -/* XXX io_vec ? XXX just send/map the pool !!! */
  -
  -static MsgBuffer *b_new(jk_pool_t *p) {
  -    MsgBuffer *msg=(MsgBuffer *)jk_pool_alloc( p, sizeof ( MsgBuffer ));
  -    msg->pool=p;
  -    if(msg==NULL) return NULL;
  -}
  -
  -static int b_set_buffer( MsgBuffer *msg, char *data, int buffSize ) {
  -    if(msg==NULL) return -1;
  -
  -    msg->len=0;
  -    msg->buf=data;
  -    msg->maxlen=buffSize;
  -    /* XXX error checking !!! */
  -    
  -    return 0;
  -}
  -
  -
  -static int b_set_buffer_size( MsgBuffer *msg, int buffSize ) {
  -
  -    unsigned char *data=(unsigned char *)jk_pool_alloc( msg->pool, buffSize );
  -    if( data==NULL ) {
  -	/* Free - sub-pools */
  -	return -1;
  -    }
  -
  -    b_set_buffer( msg, data, buffSize );
  -}
  -
  -static unsigned char *b_get_buff( MsgBuffer *msg ) {
  -    return msg->buf;
  -}
  -
  -static unsigned int b_get_pos( MsgBuffer *msg ) {
  -    return msg->pos;
  -}
  -
  -static unsigned int b_get_len( MsgBuffer *msg ) {
  -    return msg->len;
  -}
  -
  -static  void b_set_len( MsgBuffer *msg, int len ) {
  -    msg->len=len;
  -}
  -
  -static int b_get_size( MsgBuffer *msg ) {
  -    return msg->maxlen;
  -}
  -
  -/** Shame-less copy from somewhere.
  -    assert (src != dst)
  - */
  -static void swap_16( unsigned char *src, unsigned char *dst) {
  -    *dst++ = *(src + 1 );
  -    *dst= *src;
  -}
  -
  -static int b_append_string( MsgBuffer *msg, char *param ) {
  -    int len;
  -
  -    if( param==NULL ) {
  -	b_append_int( msg, 0xFFFF );
  -	return 0; 
  -    }
  -
  -    len=strlen(param);
  -    if( msg->len + len + 2  > msg->maxlen )
  -	return -1;
  -
  -    // ignore error - we checked once
  -    b_append_int( msg, len );
  -
  -    // We checked for space !! 
  -    strncpy( msg->buf + msg->len , param, len+1 ); // including \0
  -    msg->len += len + 1;
  -    return 0;
  -}
  -
  -static int b_get_int( MsgBuffer *msg) {
  -    int i;
  -    if( msg->pos + 1 > msg->len ) {
  -	printf( "Read after end \n");
  -	return 0;
  -    }
  -    i= ((msg->buf[msg->pos++]&0xff)<<8);
  -    i+= (msg->buf[(msg->pos++)] & 0xFF);
  -    return i;
  -}
  -
  -static int b_pget_int( MsgBuffer *msg, int pos) {
  -    int i= ((msg->buf[pos++]&0xff)<<8);
  -    i+= (msg->buf[pos] & 0xFF);
  -    return i;
  -}
  -
  -
  -static int b_getCode( MsgBuffer *msg ) {
  -    return b_pget_int( msg, 0 );
  -}
  -
  -static unsigned char *b_get_string( MsgBuffer *msg) {
  -    int size, start;
  -    char *str;
  -
  -    /*     b_dump(msg, "Before GS: "); */
  -    
  -    size=b_get_int(msg);
  -    start=msg->pos;
  -    if(( size < 0 ) || ( size + start > msg->maxlen ) ) { 
  -	b_dump(msg, "After get int"); 
  -	printf("ERROR\n" );
  -	return "ERROR"; /* XXX */
  -    }
  -
  -    msg->pos += size;
  -    msg->pos++; // end 0
  -    str= msg->buf + start;
  -    /*     printf( "Get_string %lx %lx %x\n", msg->buf,  str, size ); */
  -    /*     printf( "Get_string %s \n", str ); */
  -    return (unsigned char *)(msg->buf + start); 
  -}
   
  -static int b_append_headers( MsgBuffer *msg, jk_ws_service_t *s, jk_logger_t *l) {
  +static int jk_b_append_headers( MsgBuffer *msg, jk_ws_service_t *s, jk_logger_t *l) {
       /* Send the request headers */
  -    int err=b_append_int( msg, s->num_headers);
  +    int err=jk_b_append_int( msg, s->num_headers);
       if(err<0) return err;
   
       if(s->num_headers) {
           unsigned  i;
           for(i = 0 ; i < s->num_headers ; ++i) {
  -	    err=b_append_string( msg, s->headers_names[i] );
  +	    err=jk_b_append_string( msg, s->headers_names[i] );
   	    if (err<0)  return err;
  -	    err=b_append_string( msg, s->headers_values[i] );
  +	    err=jk_b_append_string( msg, s->headers_values[i] );
   	    if (err<0)  return err;
   	}
       }
  @@ -491,26 +288,26 @@
      the method _name_ follows 
   */
   static void encode_env(  MsgBuffer *msg, jk_ws_service_t *r ) {
  -    //    b_append_table( msg, r->subprocess_env );
  +    //    jk_b_append_table( msg, r->subprocess_env );
       /* XXX use r instead of env */
  -    b_append_int( msg, 6 );
  -    b_append_string( msg, "REQUEST_METHOD" );
  -    b_append_string( msg, r->method );
  +    jk_b_append_int( msg, 6 );
  +    jk_b_append_string( msg, "REQUEST_METHOD" );
  +    jk_b_append_string( msg, r->method );
   
  -    b_append_string( msg, "SERVER_PROTOCOL");
  -    b_append_string( msg, r->protocol );
  +    jk_b_append_string( msg, "SERVER_PROTOCOL");
  +    jk_b_append_string( msg, r->protocol );
   
  -    b_append_string( msg, "REQUEST_URI" );
  -    b_append_string( msg, r->req_uri );
  +    jk_b_append_string( msg, "REQUEST_URI" );
  +    jk_b_append_string( msg, r->req_uri );
   
  -    b_append_string( msg, "QUERY_STRING" );
  -    b_append_string( msg, r->query_string );
  +    jk_b_append_string( msg, "QUERY_STRING" );
  +    jk_b_append_string( msg, r->query_string );
   
  -    b_append_string( msg, "SERVER_PORT" );
  -    b_append_string( msg, "8080" );
  +    jk_b_append_string( msg, "SERVER_PORT" );
  +    jk_b_append_string( msg, "8080" );
   
  -    b_append_string( msg, "REMOTE_ADDR");
  -    b_append_string( msg, r->remote_addr );
  +    jk_b_append_string( msg, "REMOTE_ADDR");
  +    jk_b_append_string( msg, r->remote_addr );
   
   }
   
  @@ -522,20 +319,20 @@
   */
   static void encode_request( MsgBuffer *msg, jk_ws_service_t *r, jk_logger_t *l ) {
   
  -    b_append_int( msg, REQUEST_FORWARD ); 
  +    jk_b_append_int( msg, REQUEST_FORWARD ); 
       encode_env( msg, r );
  -    b_append_headers( msg, r, l );
  +    jk_b_append_headers( msg, r, l );
   
   /*     // Append first chunk of request body ( up to the buffer size ) */
       /*     printf("Encode request \n"); */
   /*     if ( ! ap_should_client_block(r)) { */
   /* 	// no body, send 0 */
   	/* printf("No body\n"); */
  -	b_append_int( msg, 0 );
  +	jk_b_append_int( msg, 0 );
   /*     } else { */
  -/*         int maxsize=b_get_size( msg ); */
  -/* 	char *buffer=b_get_buff(msg); */
  -/* 	int posLen= b_get_len( msg ); */
  +/*         int maxsize=jk_b_get_size( msg ); */
  +/* 	char *buffer=jk_b_get_buff(msg); */
  +/* 	int posLen= jk_b_get_len( msg ); */
   /* 	int pos=posLen +2 ; */
   /*         long rd; */
   
  @@ -546,10 +343,10 @@
   /* 	    pos=pos + rd; */
   /*         } */
   	/* 	printf( "End reading %d %d %d \n", posLen, pos, maxsize ); */
  -/* 	b_set_int( msg, posLen, pos - posLen -2 ); */
  -/* 	b_set_len( msg, pos ); */
  -	/* 	b_dump(msg, "Post ");  */
  -    /*     b_dump(msg, "Encode req"); */
  +/* 	jk_b_set_int( msg, posLen, pos - posLen -2 ); */
  +/* 	jk_b_set_len( msg, pos ); */
  +	/* 	jk_b_dump(msg, "Post ");  */
  +    /*     jk_b_dump(msg, "Encode req"); */
   }
   
   /** 
  @@ -564,14 +361,14 @@
       int status=200;
       
   
  -    count= b_get_int( msg  );
  +    count= jk_b_get_int( msg  );
       names=(char **) jk_pool_alloc( r->pool, ( count + 1 ) * sizeof( char * ));
       values=(char **) jk_pool_alloc( r->pool, ( count + 1 ) * sizeof( char * ));
   
       //    printf( "Header count: %x %x %x %x\n", count, pos, (int)msg[2], (int)msg[3] );
       for( i=0; i< count; i++ ) {
  -	char *n=b_get_string( msg );
  -	char *v=b_get_string( msg );
  +	char *n=jk_b_get_string( msg );
  +	char *v=jk_b_get_string( msg );
   	names[i]=n;
   	values[i]=v;
   
  @@ -599,17 +396,17 @@
       int count;
   
       /* No parameters, send body */
  -    b_reset( msg );
  -    b_append_int( msg, SEND_BODY_CHUNK );
  +    jk_b_reset( msg );
  +    jk_b_append_int( msg, SEND_BODY_CHUNK );
       
   /*     if ( ! ap_should_client_block(r)) { */
   /* 	// no body, send 0 */
   /* 	printf("No body\n"); */
  -/* 	b_append_int( msg, 0 ); */
  +/* 	jk_b_append_int( msg, 0 ); */
   /*     } else { */
  -/*         int maxsize=b_get_size( msg ); */
  -/* 	char *buffer=b_get_buff(msg); */
  -/* 	int posLen= b_get_len( msg ); */
  +/*         int maxsize=jk_b_get_size( msg ); */
  +/* 	char *buffer=jk_b_get_buff(msg); */
  +/* 	int posLen= jk_b_get_len( msg ); */
   /* 	int pos=posLen +2 ; */
   /*         long rd; */
   	
  @@ -620,9 +417,9 @@
   /* 	    pos=pos + rd; */
   /*         } */
   /* 	printf( "End reading %d %d %d \n", posLen, pos, maxsize ); */
  -/* 	b_set_int( msg, posLen, pos - posLen -2 ); */
  -/* 	b_set_len( msg, pos ); */
  -/* 	b_dump(msg, "Post additional data");  */
  +/* 	jk_b_set_int( msg, posLen, pos - posLen -2 ); */
  +/* 	jk_b_set_len( msg, pos ); */
  +/* 	jk_b_dump(msg, "Post additional data");  */
   /*     } */
       
       return HAS_RESPONSE;
  @@ -635,13 +432,13 @@
   int process_callback( MsgBuffer *msg, jk_ws_service_t *r, jk_logger_t *l) {
       int len;
   
  -    /*     printf("Callback %x\n", b_getCode(msg)); */
  -    switch( b_getCode(msg) ) {
  +    /*     printf("Callback %x\n", jk_b_getCode(msg)); */
  +    switch( jk_b_pget_int(msg,0 ) ) {
       case SET_HEADERS:
   	setHeaders( msg , r, l);
   	break;
       case SEND_BODY_CHUNK:
  -	len=b_get_int( msg );
  +	len=jk_b_get_int( msg );
   	r->write( r, msg->buf + msg->pos, len);
   	break;
       case GET_BODY_CHUNK:
  @@ -651,9 +448,9 @@
       case END_RESPONSE:
   	break;
       default:
  -	b_dump( msg , "Invalid code");
  +	jk_b_dump( msg , "Invalid code");
   	jk_log( l, JK_LOG_ERROR,
  -		"Invalid code: %d\n", b_getCode(msg));
  +		"Invalid code: %d\n", jk_b_pget_int(msg,0));
   	return -1;
       }
       
  @@ -667,7 +464,7 @@
       int sent=0;
       int i;
       
  -    b_end( msg );
  +    jk_b_end( msg );
       /*     printf("Sending %x %x %x %x\n", msg->buf[0],msg->buf[1],msg->buf[2],msg->buf[3]) ;  */
       while( sent < msg->len ) {
   	i=write( con->sd, msg->buf + sent , msg->len - sent );
  @@ -748,7 +545,7 @@
   
       /* printf( "Packet len %d %x\n", msglen, msglen ); */
   
  -    if(msglen > b_get_size(msg) ) {
  +    if(msglen > jk_b_get_size(msg) ) {
   	printf("Message too long ");
   	return -5; /* XXX */
   	/* 	sreq->message=(char *)ap_palloc( p, sreq->msglen ); */
  @@ -761,7 +558,7 @@
       i=read_full(con, msg->buf, msglen, l );
       if( i<0) return i;
       
  -    /*     b_dump( msg, " RCV: " ); */
  +    /*     jk_b_dump( msg, " RCV: " ); */
       return 0;
   }
   
  @@ -802,10 +599,10 @@
               *is_recoverable_error = JK_FALSE;
               jk_sb_open(&p->sb, p->sd);
   
  -	    msg = b_new( s->pool );
  -	    b_set_buffer_size( msg, 2048); 
  +	    msg = jk_b_new( s->pool );
  +	    jk_b_set_buffer_size( msg, 2048); 
   
  -	    b_reset( msg );
  +	    jk_b_reset( msg );
   	    encode_request( msg , s, l );
       
   	    err= connection_tcp_send_message( p, msg, l );
  @@ -819,14 +616,14 @@
   
   	    while( 1 ) {
   		int err=connection_tcp_get_message( p, msg, l );
  -		/* 	b_dump(msg, "Get Message: " ); */
  +		/* 	jk_b_dump(msg, "Get Message: " ); */
   		if( err < 0 ) {
   		    jk_log( l, JK_LOG_ERROR,
   				  "Error reading request %d\n", err);
   		    // XXX cleanup, close connection if packet error
   		    return JK_FALSE;
   		}
  -		if( b_getCode( msg ) == END_RESPONSE )
  +		if( jk_b_pget_int( msg, 0 ) == END_RESPONSE )
   		    break;
   		err=process_callback( msg, s, l );
   		if( err == HAS_RESPONSE ) {
  
  
  
  1.1                  jakarta-tomcat/src/native/jk/jk_msg_buff.c
  
  Index: jk_msg_buff.c
  ===================================================================
  /*
   * Copyright (c) 1997-1999 The Java Apache Project.  All rights reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. All advertising materials mentioning features or use of this
   *    software must display the following acknowledgment:
   *    "This product includes software developed by the Java Apache 
   *    Project for use in the Apache JServ servlet engine project
   *    <http://java.apache.org/>."
   *
   * 4. The names "Apache JServ", "Apache JServ Servlet Engine" and 
   *    "Java Apache Project" must not be used to endorse or promote products 
   *    derived from this software without prior written permission.
   *
   * 5. Products derived from this software may not be called "Apache JServ"
   *    nor may "Apache" nor "Apache JServ" appear in their names without 
   *    prior written permission of the Java Apache Project.
   *
   * 6. Redistributions of any form whatsoever must retain the following
   *    acknowledgment:
   *    "This product includes software developed by the Java Apache 
   *    Project for use in the Apache JServ servlet engine project
   *    <http://java.apache.org/>."
   *    
   * THIS SOFTWARE IS PROVIDED BY THE JAVA APACHE PROJECT "AS IS" AND ANY
   * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
   * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
   * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE JAVA APACHE PROJECT OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
   * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
   * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
   * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
   * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
   * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
   * OF THE POSSIBILITY OF SUCH DAMAGE.
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Java Apache Group. For more information
   * on the Java Apache Project and the Apache JServ Servlet Engine project,
   * please see <http://java.apache.org/>.
   *
   */
  
  /** 
      Simple marshaling code.
  */
  
  #include "jk_pool.h"
  #include "jk_connect.h"
  #include "jk_util.h"
  #include "jk_sockbuf.h"
  #include "jk_msg_buff.h"
  
  
  
  /* XXX what's above this line can go to .h XXX */
  void jk_b_dump( MsgBuffer *msg, char *err ) {
          int i=0;
  	printf("%s %d/%d/%d %x %x %x %x - %x %x %x %x - %x %x %x %x - %x %x %x %x\n", err, msg->pos, msg->len, msg->maxlen,  
  	       msg->buf[i++],msg->buf[i++],msg->buf[i++],msg->buf[i++],
  	       msg->buf[i++],msg->buf[i++],msg->buf[i++],msg->buf[i++],
  	       msg->buf[i++],msg->buf[i++],msg->buf[i++],msg->buf[i++],
  	       msg->buf[i++],msg->buf[i++],msg->buf[i++],msg->buf[i++]);
  
  	i=msg->pos - 4;
  	if( i<0 ) i=0;
  	
          printf("        %x %x %x %x - %x %x %x %x --- %x %x %x %x - %x %x %x %x\n", 
  	       msg->buf[i++],msg->buf[i++],msg->buf[i++],msg->buf[i++],
  	       msg->buf[i++],msg->buf[i++],msg->buf[i++],msg->buf[i++],
  	       msg->buf[i++],msg->buf[i++],msg->buf[i++],msg->buf[i++],
  	       msg->buf[i++],msg->buf[i++],msg->buf[i++],msg->buf[i++]);
  
  }
  
  void jk_b_reset( MsgBuffer *msg ) {
      msg->len =4;
      msg->pos =4;
  }
  
  void jk_b_set_int( MsgBuffer *msg, int pos, unsigned int val ) {
      /* XXX optimize - swap if needed or just copyb */
      /* #if SWAP */
      /*     swap_16( (unsigned char *)&val, msg->buf ) */
      /* #else */
      /*     ???	 */
      /* #endif  */
      msg->buf[pos++]=(unsigned char) ( (val >> 8) & 0xff );
      msg->buf[pos]= (unsigned char) ( val & 0xff );
  }
  
  int jk_b_append_int( MsgBuffer *msg, unsigned int val ) {
      if( msg->len + 2 > msg->maxlen ) 
  	return -1;
  
      jk_b_set_int( msg, msg->len, val );
      msg->len +=2;
      return 0;
  }
  
  
  void jk_b_end(MsgBuffer *msg) {
      /* Ugly way to set the size in the right position */
      jk_b_set_int( msg, 2, msg->len - 4 ); /* see protocol */
      jk_b_set_int( msg, 0, 0x1234 );
  }
  
  
  /* XXX optimize it ( less function calls, macros )
     Ugly pointer arithmetic code
   */
  /* XXX io_vec ? XXX just send/map the pool !!! */
  
  MsgBuffer *jk_b_new(jk_pool_t *p) {
      MsgBuffer *msg=(MsgBuffer *)jk_pool_alloc( p, sizeof ( MsgBuffer ));
      msg->pool=p;
      if(msg==NULL) return NULL;
  }
  
  int jk_b_set_buffer( MsgBuffer *msg, char *data, int buffSize ) {
      if(msg==NULL) return -1;
  
      msg->len=0;
      msg->buf=data;
      msg->maxlen=buffSize;
      /* XXX error checking !!! */
      
      return 0;
  }
  
  
  int jk_b_set_buffer_size( MsgBuffer *msg, int buffSize ) {
  
      unsigned char *data=(unsigned char *)jk_pool_alloc( msg->pool, buffSize );
      if( data==NULL ) {
  	/* Free - sub-pools */
  	return -1;
      }
  
      jk_b_set_buffer( msg, data, buffSize );
  }
  
  unsigned char *jk_b_get_buff( MsgBuffer *msg ) {
      return msg->buf;
  }
  
  unsigned int jk_b_get_pos( MsgBuffer *msg ) {
      return msg->pos;
  }
  
  unsigned int jk_b_get_len( MsgBuffer *msg ) {
      return msg->len;
  }
  
  void jk_b_set_len( MsgBuffer *msg, int len ) {
      msg->len=len;
  }
  
  int jk_b_get_size( MsgBuffer *msg ) {
      return msg->maxlen;
  }
  
  /** Shame-less copy from somewhere.
      assert (src != dst)
   */
  static void swap_16( unsigned char *src, unsigned char *dst) {
      *dst++ = *(src + 1 );
      *dst= *src;
  }
  
  int jk_b_append_string( MsgBuffer *msg, char *param ) {
      int len;
  
      if( param==NULL ) {
  	jk_b_append_int( msg, 0xFFFF );
  	return 0; 
      }
  
      len=strlen(param);
      if( msg->len + len + 2  > msg->maxlen )
  	return -1;
  
      // ignore error - we checked once
      jk_b_append_int( msg, len );
  
      // We checked for space !! 
      strncpy( msg->buf + msg->len , param, len+1 ); // including \0
      msg->len += len + 1;
      return 0;
  }
  
  int jk_b_get_int( MsgBuffer *msg) {
      int i;
      if( msg->pos + 1 > msg->len ) {
  	printf( "Read after end \n");
  	return 0;
      }
      i= ((msg->buf[msg->pos++]&0xff)<<8);
      i+= (msg->buf[(msg->pos++)] & 0xFF);
      return i;
  }
  
  int jk_b_pget_int( MsgBuffer *msg, int pos) {
      int i= ((msg->buf[pos++]&0xff)<<8);
      i+= (msg->buf[pos] & 0xFF);
      return i;
  }
  
  
  /* int jk_b_getCode( MsgBuffer *msg ) { */
  /*     return jk_b_pget_int( msg, 0 ); */
  /* } */
  
  unsigned char *jk_b_get_string( MsgBuffer *msg) {
      int size, start;
      char *str;
  
      /*     jk_b_dump(msg, "Before GS: "); */
      
      size=jk_b_get_int(msg);
      start=msg->pos;
      if(( size < 0 ) || ( size + start > msg->maxlen ) ) { 
  	jk_b_dump(msg, "After get int"); 
  	printf("ERROR\n" );
  	return "ERROR"; /* XXX */
      }
  
      msg->pos += size;
      msg->pos++; // end 0
      str= msg->buf + start;
      /*     printf( "Get_string %lx %lx %x\n", msg->buf,  str, size ); */
      /*     printf( "Get_string %s \n", str ); */
      return (unsigned char *)(msg->buf + start); 
  }
  
  
  
  
  
  
  
  1.1                  jakarta-tomcat/src/native/jk/jk_msg_buff.h
  
  Index: jk_msg_buff.h
  ===================================================================
  /*
   * Copyright (c) 1997-1999 The Java Apache Project.  All rights reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. All advertising materials mentioning features or use of this
   *    software must display the following acknowledgment:
   *    "This product includes software developed by the Java Apache 
   *    Project for use in the Apache JServ servlet engine project
   *    <http://java.apache.org/>."
   *
   * 4. The names "Apache JServ", "Apache JServ Servlet Engine" and 
   *    "Java Apache Project" must not be used to endorse or promote products 
   *    derived from this software without prior written permission.
   *
   * 5. Products derived from this software may not be called "Apache JServ"
   *    nor may "Apache" nor "Apache JServ" appear in their names without 
   *    prior written permission of the Java Apache Project.
   *
   * 6. Redistributions of any form whatsoever must retain the following
   *    acknowledgment:
   *    "This product includes software developed by the Java Apache 
   *    Project for use in the Apache JServ servlet engine project
   *    <http://java.apache.org/>."
   *    
   * THIS SOFTWARE IS PROVIDED BY THE JAVA APACHE PROJECT "AS IS" AND ANY
   * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
   * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
   * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE JAVA APACHE PROJECT OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
   * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
   * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
   * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
   * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
   * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
   * OF THE POSSIBILITY OF SUCH DAMAGE.
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Java Apache Group. For more information
   * on the Java Apache Project and the Apache JServ Servlet Engine project,
   * please see <http://java.apache.org/>.
   *
   */
  
  /** 
      Simple marshaling code.
  */
  
  #include "jk_pool.h"
  #include "jk_util.h"
  
  
  /* // XXX replace all return values with error codes */
  #define ERR_BAD_PACKET -5
  
  /*
  RPC details:
  
    - one parameter  - use a structure for more. The method
      is encoded as part of the request
    - one or no result
    - 
  
  
  
   */
  
  /* Data marshaling. Like XDR *
   */
  struct MsgBuffer_Simple {
      jk_pool_t *pool;
  
      unsigned char *buf;
      int pos; /* XXX MT */
      int len;
      int maxlen;
  };
  
  
  typedef struct MsgBuffer_Simple MsgBuffer;
  
  /* -------------------- Setup routines -------------------- */
  
  /** Allocate a buffer.
   */
  MsgBuffer *jk_b_new(jk_pool_t *p); 
  
  /** Set up a buffer with an existing buffer
   */
  int jk_b_set_buffer( MsgBuffer *msg, char *data, int buffSize );
  
  /** Set up a buffer with a new buffer of buffSize
   */
  int jk_b_set_buffer_size( MsgBuffer *msg, int buffSize );
  
  /** Finalize the buffer before sending - set length fields, etc
   */
  void jk_b_end(MsgBuffer *msg);
  
  /** Recycle the buffer - prepare for a new invocation 
   */
  void jk_b_reset( MsgBuffer *msg );
  
  /** Return the buffer body 
   */ 
  unsigned char *jk_b_get_buff( MsgBuffer *msg );
  
  /** Return the current reading position
   */
  unsigned int jk_b_get_pos( MsgBuffer *msg );
  
  /** Buffer size 
  */
  int jk_b_get_size( MsgBuffer *msg );
  
  void jk_b_set_len( MsgBuffer *msg, int len );
  
  /** Get the  message length for incomming buffers
      or the current length for outgoing
  */
  unsigned int jk_b_get_len( MsgBuffer *msg );
  
  /** Dump the buffer header
      @param err Message text
  */
  void jk_b_dump( MsgBuffer *msg, char *err ); 
  
  /* -------------------- Real encoding -------------------- */
  
  
  void jk_b_set_int( MsgBuffer *msg, int pos, unsigned int val );
  
  int jk_b_append_int( MsgBuffer *msg, unsigned int val );
  
  int jk_b_append_string( MsgBuffer *msg, char *param );
  
  
  /* -------------------- Decoding -------------------- */
  
  unsigned char *jk_b_get_string( MsgBuffer *msg);
  
  /** Get an int from an arbitrary position 
   */
  int jk_b_pget_int( MsgBuffer *msg, int pos);
  
  int jk_b_get_int( MsgBuffer *msg);