hgomez 2002/09/04 04:31:33 Modified: jk/native/apache-2.0 mod_jk.c jk/native/common jk_ajp12_worker.c jk_ajp_common.c jk_ajp_common.h jk_connect.c jk_global.h jk_map.c jk_msg_buff.c jk_msg_buff.h jk_pool.c jk_pool.h jk_util.c Log: Patches to make mod_jk works on iSeries (AS/400) and Apache 2.0. These patches have been provided by IBM Rochester labs. Nota: You'll need an OS400 V5R1 or V5R2, both with latest PTF containing Apache 2.0.39 Apache 2.0.39 PTFs for V5R1 are scheduled in mid-september. Many thanks to IBMers, Walt, Jim and Brian. Revision Changes Path 1.55 +41 -2 jakarta-tomcat-connectors/jk/native/apache-2.0/mod_jk.c Index: mod_jk.c =================================================================== RCS file: /home/cvs/jakarta-tomcat-connectors/jk/native/apache-2.0/mod_jk.c,v retrieving revision 1.54 retrieving revision 1.55 diff -u -r1.54 -r1.55 --- mod_jk.c 24 Jul 2002 04:48:52 -0000 1.54 +++ mod_jk.c 4 Sep 2002 11:31:32 -0000 1.55 @@ -79,6 +79,10 @@ #include "http_main.h" #include "http_log.h" #include "util_script.h" +#ifdef AS400 +#include "ap_charset.h" +#include "util_charset.h" /* ap_hdrs_from_ascii */ +#endif /* moved to apr since http-2.0.19-dev */ #if (MODULE_MAGIC_NUMBER_MAJOR < 20010523) @@ -230,6 +234,11 @@ ap_content_type_tolower(tmp); r->content_type = tmp; } else if(!strcasecmp(header_names[h], "Location")) { +#ifdef AS400 + /* Fix escapes in Location Header URL*/ + ap_fixup_escapes((char *)header_values[h], + strlen(header_values[h]), ap_hdrs_from_ascii); +#endif apr_table_set(r->headers_out, header_names[h], header_values[h]); } else if(!strcasecmp(header_names[h], "Content-Length")) { @@ -283,7 +292,18 @@ } if(p->read_body_started) { - long rv; +#ifdef AS400 + int long rv = OK; + if (rv = ap_change_request_body_xlate(p->r, 65535, 65535)) /* turn off request body translation*/ + { + ap_log_error(APLOG_MARK, APLOG_STARTUP | APLOG_NOERRNO, 0, + NULL, "mod_jk: Error on ap_change_request_body_xlate, rc=%d \n", rv); + return JK_FALSE; + } +#else + long rv; +#endif + if ((rv = ap_get_client_block(p->r, b, len)) < 0) { *actually_read = 0; } else { @@ -315,6 +335,10 @@ const void *b, unsigned l) { +#ifdef AS400 + int rc; +#endif + if(s && s->ws_private && b) { apache_private_data_t *p = s->ws_private; @@ -332,6 +356,14 @@ return JK_FALSE; } } +#ifdef AS400 + rc = ap_change_response_body_xlate(p->r, 65535, 65535); /* turn off response body translation*/ + if(rc){ + ap_log_error(APLOG_MARK, APLOG_STARTUP | APLOG_NOERRNO, 0, + NULL, "mod_jk: Error on ap_change_response_body_xlate, rc=%d \n", rc); + return JK_FALSE; + } +#endif /* Debug - try to get around rwrite */ while( ll > 0 ) { @@ -351,11 +383,13 @@ /* * To allow server push. After writing full buffers */ +#ifndef AS400 if(ap_rflush(p->r) != APR_SUCCESS) { ap_log_error(APLOG_MARK, APLOG_STARTUP | APLOG_NOERRNO, 0, NULL, "mod_jk: Error flushing \n" ); return JK_FALSE; } +#endif } @@ -459,7 +493,12 @@ s->content_length = get_content_length(r); s->is_chunked = r->read_chunked; s->no_more_chunks = 0; +#ifdef AS400 + /* Get the query string that is not translated to EBCDIC */ + s->query_string = ap_get_original_query_string(r); +#else s->query_string = r->args; +#endif /* * The 2.2 servlet spec errata says the uri from 1.8 +65 -3 jakarta-tomcat-connectors/jk/native/common/jk_ajp12_worker.c Index: jk_ajp12_worker.c =================================================================== RCS file: /home/cvs/jakarta-tomcat-connectors/jk/native/common/jk_ajp12_worker.c,v retrieving revision 1.7 retrieving revision 1.8 diff -u -r1.7 -r1.8 --- jk_ajp12_worker.c 25 Jun 2002 07:08:47 -0000 1.7 +++ jk_ajp12_worker.c 4 Sep 2002 11:31:32 -0000 1.8 @@ -67,6 +67,10 @@ #include "jk_connect.h" #include "jk_util.h" #include "jk_sockbuf.h" +#ifdef AS400 +#include "util_ebcdic.h" +#include <string.h> +#endif #define AJP_DEF_HOST ("localhost") #define AJP_DEF_PORT (8007) @@ -95,8 +99,18 @@ static int ajpv12_mark(ajp12_endpoint_t *p, unsigned char type); +#ifdef AS400 +static int ajpv12_sendasciistring(ajp12_endpoint_t *p, + char *buffer); +#endif + +#ifdef AS400 +static int ajpv12_sendstring(ajp12_endpoint_t *p, + char *buffer); +#else static int ajpv12_sendstring(ajp12_endpoint_t *p, const char *buffer); +#endif static int ajpv12_sendint(ajp12_endpoint_t *p, int d); @@ -272,7 +286,7 @@ (ajp12_worker_t *)malloc(sizeof(ajp12_worker_t)); if(private_data) { - private_data->name = strdup(name); + private_data->name = strdup(name); if(private_data->name) { private_data->connect_retry_attempts= DEF_RETRY_ATTEMPTS; @@ -318,13 +332,35 @@ } } +#ifdef AS400 +static int ajpv12_sendasciistring(ajp12_endpoint_t *p, + char *buffer) +{ + int bufferlen; + + if(buffer && (bufferlen = strlen(buffer))) { + return ajpv12_sendnbytes(p, buffer, bufferlen); + } else { + return ajpv12_sendnbytes(p, NULL, 0); + } +} +#endif + +#ifdef AS400 +static int ajpv12_sendstring(ajp12_endpoint_t *p, + char *buffer) +#else static int ajpv12_sendstring(ajp12_endpoint_t *p, const char *buffer) +#endif { int bufferlen; if(buffer && (bufferlen = strlen(buffer))) { - return ajpv12_sendnbytes(p, buffer, bufferlen); +#ifdef AS400 + jk_xlate_to_ascii(buffer, bufferlen); +#endif + return ajpv12_sendnbytes(p, buffer, bufferlen); } else { return ajpv12_sendnbytes(p, NULL, 0); } @@ -373,17 +409,29 @@ ajpv12_sendstring(p, 0) && /* doc root */ ajpv12_sendstring(p, 0) && /* path info */ ajpv12_sendstring(p, 0) && /* path translated */ +#ifdef AS400 + ajpv12_sendasciistring(p, s->query_string) && +#else ajpv12_sendstring(p, s->query_string)&& +#endif ajpv12_sendstring(p, s->remote_addr) && ajpv12_sendstring(p, s->remote_host) && ajpv12_sendstring(p, s->remote_user) && ajpv12_sendstring(p, s->auth_type) && ajpv12_sendint(p, s->server_port) && +#ifdef AS400 + ajpv12_sendasciistring(p, s->method) && +#else ajpv12_sendstring(p, s->method) && +#endif ajpv12_sendstring(p, s->req_uri) && ajpv12_sendstring(p, 0) && /* */ ajpv12_sendstring(p, 0) && /* SCRIPT_NAME */ +#ifdef AS400 + ajpv12_sendasciistring(p, s->server_name) && +#else ajpv12_sendstring(p, s->server_name) && +#endif ajpv12_sendint(p, s->server_port) && ajpv12_sendstring(p, s->protocol) && ajpv12_sendstring(p, 0) && /* SERVER_SIGNATURE */ @@ -503,11 +551,17 @@ char *line = NULL; char *name = NULL; char *value = NULL; +#ifdef AS400 + char *lasts; +#endif if(!jk_sb_gets(&p->sb, &line)) { jk_log(l, JK_LOG_ERROR, "ajpv12_handle_response, error reading header line\n"); return JK_FALSE; } +#ifdef AS400 + jk_xlate_from_ascii(line, strlen(line)); +#endif jk_log(l, JK_LOG_DEBUG, "ajpv12_handle_response, read %s\n", line); if(0 == strlen(line)) { @@ -539,14 +593,22 @@ jk_log(l, JK_LOG_DEBUG, "ajpv12_handle_response, read %s=%s\n", name, value); if(0 == strcmp("Status", name)) { +#ifdef AS400 + char *numeric = strtok_r(value, " \t", &lasts); +#else char *numeric = strtok(value, " \t"); +#endif status = atoi(numeric); if(status < 100 || status > 999) { jk_log(l, JK_LOG_ERROR, "ajpv12_handle_response, invalid status code\n"); return JK_FALSE; } +#ifdef AS400 + reason = jk_pool_strdup(s->pool, strtok_r(NULL, " \t", &lasts)); +#else reason = jk_pool_strdup(s->pool, strtok(NULL, " \t")); +#endif } else { if(headers_capacity == headers_len) { jk_log(l, JK_LOG_DEBUG, "ajpv12_handle_response, allocating header arrays\n"); 1.29 +8 -1 jakarta-tomcat-connectors/jk/native/common/jk_ajp_common.c Index: jk_ajp_common.c =================================================================== RCS file: /home/cvs/jakarta-tomcat-connectors/jk/native/common/jk_ajp_common.c,v retrieving revision 1.28 retrieving revision 1.29 diff -u -r1.28 -r1.29 --- jk_ajp_common.c 26 Aug 2002 09:54:34 -0000 1.28 +++ jk_ajp_common.c 4 Sep 2002 11:31:32 -0000 1.29 @@ -69,6 +69,9 @@ #include "jk_ajp14.h" #include "jk_ajp_common.h" #include "jk_connect.h" +#ifdef AS400 +#include "util_ebcdic.h" +#endif const char *response_trans_headers[] = { @@ -357,7 +360,11 @@ } if (s->query_string) { if (jk_b_append_byte(msg, SC_A_QUERY_STRING) || +#ifdef AS400 + jk_b_append_asciistring(msg, s->query_string)) { +#else jk_b_append_string(msg, s->query_string)) { +#endif jk_log(l, JK_LOG_ERROR, "Error ajp_marshal_into_msgb - Error appending the query string\n"); return JK_FALSE; } 1.17 +5 -1 jakarta-tomcat-connectors/jk/native/common/jk_ajp_common.h Index: jk_ajp_common.h =================================================================== RCS file: /home/cvs/jakarta-tomcat-connectors/jk/native/common/jk_ajp_common.h,v retrieving revision 1.16 retrieving revision 1.17 diff -u -r1.16 -r1.17 --- jk_ajp_common.h 26 Aug 2002 09:54:34 -0000 1.16 +++ jk_ajp_common.h 4 Sep 2002 11:31:33 -0000 1.17 @@ -233,7 +233,11 @@ struct jk_res_data { int status; +#ifdef AS400 + char *msg; +#else const char *msg; +#endif unsigned num_headers; char **header_names; char **header_values; 1.5 +17 -2 jakarta-tomcat-connectors/jk/native/common/jk_connect.c Index: jk_connect.c =================================================================== RCS file: /home/cvs/jakarta-tomcat-connectors/jk/native/common/jk_connect.c,v retrieving revision 1.4 retrieving revision 1.5 diff -u -r1.4 -r1.5 --- jk_connect.c 25 Jun 2002 07:07:14 -0000 1.4 +++ jk_connect.c 4 Sep 2002 11:31:33 -0000 1.5 @@ -78,6 +78,9 @@ int x; u_long laddr; +#ifdef AS400 + memset(rc, 0, sizeof(struct sockaddr_in)); +#endif rc->sin_port = htons((short)port); rc->sin_family = AF_INET; @@ -89,11 +92,23 @@ } if(host[x] != '\0') { - /* If we found also characters we use gethostbyname()*/ +#ifdef AS400 + /* If we found also characters we use gethostbyname_r()*/ + struct hostent hostentry; + struct hostent *hoste = &hostentry; + struct hostent_data hd; + memset( &hd, 0, sizeof(struct hostent_data) ); + if ( (gethostbyname_r( host, hoste, &hd )) != 0 ) { + return JK_FALSE; + } +#else /* If we found also characters we use gethostbyname()*/ + /* XXX : WARNING : We should really use gethostbyname_r in multi-threaded env */ + /* take a look at APR which handle gethostbyname in apr/network_io/unix/sa_common.c */ struct hostent *hoste = gethostbyname(host); if(!hoste) { return JK_FALSE; } +#endif laddr = ((struct in_addr *)hoste->h_addr_list[0])->s_addr; } else { 1.21 +7 -1 jakarta-tomcat-connectors/jk/native/common/jk_global.h Index: jk_global.h =================================================================== RCS file: /home/cvs/jakarta-tomcat-connectors/jk/native/common/jk_global.h,v retrieving revision 1.20 retrieving revision 1.21 diff -u -r1.20 -r1.21 --- jk_global.h 28 Aug 2002 09:55:11 -0000 1.20 +++ jk_global.h 4 Sep 2002 11:31:33 -0000 1.21 @@ -74,6 +74,12 @@ #include <errno.h> #include <time.h> #include <ctype.h> +#ifdef AS400 +#include "ap_config.h" +#include "apr_strings.h" +#include "apr_lib.h" +extern char *strdup (const char *str); +#endif #include <sys/types.h> #include <sys/stat.h> 1.10 +26 -3 jakarta-tomcat-connectors/jk/native/common/jk_map.c Index: jk_map.c =================================================================== RCS file: /home/cvs/jakarta-tomcat-connectors/jk/native/common/jk_map.c,v retrieving revision 1.9 retrieving revision 1.10 diff -u -r1.9 -r1.10 --- jk_map.c 4 Dec 2001 19:44:23 -0000 1.9 +++ jk_map.c 4 Sep 2002 11:31:33 -0000 1.10 @@ -60,6 +60,9 @@ * Author: Gal Shachor <[EMAIL PROTECTED]> * * Version: $Revision$ * ***************************************************************************/ +#ifdef AS400 +#include "apr_xlate.h" +#endif #include "jk_global.h" #include "jk_map.h" @@ -211,6 +214,9 @@ { char *l = map_get_string(m, name, def); char **ar = NULL; +#ifdef AS400 + char *lasts; +#endif *list_len = 0; @@ -227,10 +233,17 @@ * GS, in addition to VG's patch, we now need to * strtok also by a "*" */ - +#ifdef AS400 + for(l = strtok_r(v, " \t,*", &lasts) ; + l ; + l = strtok_r(NULL, " \t,*",&lasts)) +#else for(l = strtok(v, " \t,*") ; l ; - l = strtok(NULL, " \t,*")) { + l = strtok(NULL, " \t,*")) +#endif + + { if(idex == capacity) { ar = jk_pool_realloc(&m->p, @@ -292,7 +305,11 @@ int rc = JK_FALSE; if(m && f) { +#ifdef AS400 + FILE *fp = fopen(f, "r, o_ccsid=0"); +#else FILE *fp = fopen(f, "r"); +#endif if(fp) { char buf[LENGTH_OF_LINE + 1]; @@ -379,7 +396,13 @@ static void trim_prp_comment(char *prp) { +#ifdef AS400 + char *comment; + /* lots of lines that translate a '#' realtime deleted */ + comment = strchr(prp, *APR_NUMBERSIGN); +#else char *comment = strchr(prp, '#'); +#endif if(comment) { *comment = '\0'; } 1.11 +28 -1 jakarta-tomcat-connectors/jk/native/common/jk_msg_buff.c Index: jk_msg_buff.c =================================================================== RCS file: /home/cvs/jakarta-tomcat-connectors/jk/native/common/jk_msg_buff.c,v retrieving revision 1.10 retrieving revision 1.11 diff -u -r1.10 -r1.11 --- jk_msg_buff.c 4 Dec 2001 19:44:23 -0000 1.10 +++ jk_msg_buff.c 4 Sep 2002 11:31:33 -0000 1.11 @@ -272,6 +272,33 @@ return msg->maxlen; } +#ifdef AS400 +int jk_b_append_asciistring(jk_msg_buf_t *msg, + const char *param) +{ + int len; + + if(!param) { + 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, (unsigned short )len); + + /* We checked for space !! */ + strncpy((char *)msg->buf + msg->len , param, len+1); /* including \0 */ + msg->len += len + 1; + + return 0; +} +#endif + int jk_b_append_string(jk_msg_buf_t *msg, const char *param) { 1.6 +6 -1 jakarta-tomcat-connectors/jk/native/common/jk_msg_buff.h Index: jk_msg_buff.h =================================================================== RCS file: /home/cvs/jakarta-tomcat-connectors/jk/native/common/jk_msg_buff.h,v retrieving revision 1.5 retrieving revision 1.6 diff -u -r1.5 -r1.6 --- jk_msg_buff.h 18 Jun 2001 14:15:55 -0000 1.5 +++ jk_msg_buff.h 4 Sep 2002 11:31:33 -0000 1.6 @@ -171,6 +171,11 @@ int jk_b_append_string(jk_msg_buf_t *msg, const char *param); +#ifdef AS400 +int jk_b_append_asciistring(jk_msg_buf_t *msg, + const char *param); +#endif + int jk_b_append_bytes(jk_msg_buf_t *msg, const unsigned char *param, int len); 1.4 +7 -2 jakarta-tomcat-connectors/jk/native/common/jk_pool.c Index: jk_pool.c =================================================================== RCS file: /home/cvs/jakarta-tomcat-connectors/jk/native/common/jk_pool.c,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- jk_pool.c 30 Oct 2001 21:08:39 -0000 1.3 +++ jk_pool.c 4 Sep 2002 11:31:33 -0000 1.4 @@ -115,9 +115,14 @@ if(p && size > 0) { /* Round size to the upper mult of 8. */ - size -= 1; + size--; +#ifdef AS400 + size /= 16; + size = (size + 1) * 16; +#else size /= 8; size = (size + 1) * 8; +#endif if((p->size - p->pos) >= size) { rc = &(p->buf[p->pos]); p->pos += size; 1.4 +3 -1 jakarta-tomcat-connectors/jk/native/common/jk_pool.h Index: jk_pool.h =================================================================== RCS file: /home/cvs/jakarta-tomcat-connectors/jk/native/common/jk_pool.h,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- jk_pool.h 30 Oct 2001 21:08:39 -0000 1.3 +++ jk_pool.h 4 Sep 2002 11:31:33 -0000 1.4 @@ -104,6 +104,8 @@ typedef long long jk_pool_atom_t; #elif defined(IRIX) typedef long long jk_pool_atom_t; +#elif defined(AS400) + typedef void * jk_pool_atom_t; #else typedef long long jk_pool_atom_t; #endif 1.17 +20 -1 jakarta-tomcat-connectors/jk/native/common/jk_util.c Index: jk_util.c =================================================================== RCS file: /home/cvs/jakarta-tomcat-connectors/jk/native/common/jk_util.c,v retrieving revision 1.16 retrieving revision 1.17 diff -u -r1.16 -r1.17 --- jk_util.c 25 Jun 2002 07:06:42 -0000 1.16 +++ jk_util.c 4 Sep 2002 11:31:33 -0000 1.17 @@ -177,7 +177,11 @@ rc->log = log_to_file; rc->level = level; rc->logger_private = p; +#ifdef AS400 + p->logfile = fopen(file, "a+, o_ccsid=0"); +#else p->logfile = fopen(file, "a+"); +#endif if(p->logfile) { *l = rc; return JK_TRUE; @@ -658,7 +662,11 @@ { if(f) { struct stat st; +#ifdef AS400 + if((0 == stat(f, &st)) && (st.st_mode & _S_IFREG)) { +#else if((0 == stat(f, &st)) && (st.st_mode & S_IFREG)) { +#endif return JK_TRUE; } } @@ -770,6 +778,9 @@ const char *sysprops) { char **rc = NULL; +#ifdef AS400 + char *lasts; +#endif if(p && sysprops) { char *prps = jk_pool_strdup(p, sysprops); @@ -785,11 +796,19 @@ rc = jk_pool_alloc(p, (num_of_prps + 1) * sizeof(char *)); if(rc) { unsigned i = 0; +#ifdef AS400 + char *tmp = strtok_r(prps, "*", &lasts); +#else char *tmp = strtok(prps, "*"); +#endif while(tmp && i < num_of_prps) { rc[i] = tmp; +#ifdef AS400 + tmp = strtok_r(NULL, "*", &lasts); +#else tmp = strtok(NULL, "*"); +#endif i++; } rc[i] = NULL;
-- To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]> For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>