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...@apache.org on 2001/12/04 20:44:24 UTC
cvs commit: jakarta-tomcat-connectors/jk/native/common Makefile.in jk_ajp14.c jk_ajp14.h jk_ajp14_worker.c jk_ajp_common.c jk_ajp_common.h jk_global.h jk_jni_worker.c jk_lb_worker.c jk_map.c jk_map.h jk_msg_buff.c jk_service.h jk_uri_worker_map.c jk_uri_worker_map.h jk_util.c jk_worker.c jk_worker.h list.mk.in
costin 01/12/04 11:44:24
Modified: jk/native/common Makefile.in jk_ajp14.c jk_ajp14.h
jk_ajp14_worker.c jk_ajp_common.c jk_ajp_common.h
jk_global.h jk_jni_worker.c jk_lb_worker.c jk_map.c
jk_map.h jk_msg_buff.c jk_service.h
jk_uri_worker_map.c jk_uri_worker_map.h jk_util.c
jk_worker.c jk_worker.h list.mk.in
Log:
Rolling back.
Revision Changes Path
1.6 +0 -1 jakarta-tomcat-connectors/jk/native/common/Makefile.in
Index: Makefile.in
===================================================================
RCS file: /home/cvs/jakarta-tomcat-connectors/jk/native/common/Makefile.in,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- Makefile.in 2001/11/02 18:42:25 1.5
+++ Makefile.in 2001/12/04 19:44:23 1.6
@@ -1,7 +1,6 @@
#### XXXX DO we need this Makefile ????
OEXT=.lo
include list.mk
-include @APACHE_CONFIG_VARS@
JAVA_INCL=-I @JAVA_HOME@/include -I @JAVA_HOME@/include/@OS@
CFLAGS=@apache_include@ @CFLAGS@ ${JAVA_INCL}
1.16 +470 -0 jakarta-tomcat-connectors/jk/native/common/jk_ajp14.c
Index: jk_ajp14.c
===================================================================
RCS file: /home/cvs/jakarta-tomcat-connectors/jk/native/common/jk_ajp14.c,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -r1.15 -r1.16
--- jk_ajp14.c 2001/11/26 17:03:25 1.15
+++ jk_ajp14.c 2001/12/04 19:44:23 1.16
@@ -59,7 +59,7 @@
/***************************************************************************
* Description: Next generation bi-directional protocol handler. *
* Author: Henri Gomez <hg...@slib.fr> *
- * Version: $Revision: 1.15 $ *
+ * Version: $Revision: 1.16 $ *
***************************************************************************/
@@ -70,7 +70,191 @@
#include "jk_ajp14.h"
#include "jk_md5.h"
+/*
+ * Compute the MD5 with ENTROPY / SECRET KEY
+ */
+
+void ajp14_compute_md5(jk_login_service_t *s,
+ jk_logger_t *l)
+{
+ jk_md5((const unsigned char *)s->entropy, (const unsigned char *)s->secret_key, s->computed_key);
+
+ jk_log(l, JK_LOG_DEBUG, "Into ajp14_compute_md5 (%s/%s) -> (%s)\n", s->entropy, s->secret_key, s->computed_key);
+}
+
+
+/*
+ * Build the Login Init Command
+ *
+ * +-------------------------+---------------------------+---------------------------+
+ * | LOGIN INIT CMD (1 byte) | NEGOCIATION DATA (32bits) | WEB SERVER INFO (CString) |
+ * +-------------------------+---------------------------+---------------------------+
+ *
+ */
+
+int ajp14_marshal_login_init_into_msgb(jk_msg_buf_t *msg,
+ jk_login_service_t *s,
+ jk_logger_t *l)
+{
+ jk_log(l, JK_LOG_DEBUG, "Into ajp14_marshal_login_init_into_msgb\n");
+
+ /* To be on the safe side */
+ jk_b_reset(msg);
+
+ /*
+ * LOGIN
+ */
+ if (jk_b_append_byte(msg, AJP14_LOGINIT_CMD))
+ return JK_FALSE;
+
+ /*
+ * NEGOCIATION FLAGS
+ */
+ if (jk_b_append_long(msg, s->negociation))
+ return JK_FALSE;
+
+ /*
+ * WEB-SERVER NAME
+ */
+ if (jk_b_append_string(msg, s->web_server_name)) {
+ jk_log(l, JK_LOG_ERROR, "Error ajp14_marshal_login_init_into_msgb - Error appending the web_server_name string\n");
+ return JK_FALSE;
+ }
+
+ return JK_TRUE;
+}
+
+
+/*
+ * Decode the Login Seed Command
+ *
+ * +-------------------------+---------------------------+
+ * | LOGIN SEED CMD (1 byte) | MD5 of entropy (32 chars) |
+ * +-------------------------+---------------------------+
+ *
+ */
+
+int ajp14_unmarshal_login_seed(jk_msg_buf_t *msg,
+ jk_login_service_t *s,
+ jk_logger_t *l)
+{
+ if (jk_b_get_bytes(msg, (unsigned char *)s->entropy, AJP14_ENTROPY_SEED_LEN) < 0) {
+ jk_log(l, JK_LOG_ERROR, "Error ajp14_unmarshal_login_seed - can't get seed\n");
+ return JK_FALSE;
+ }
+ s->entropy[AJP14_ENTROPY_SEED_LEN] = 0; /* Just to have a CString */
+ return JK_TRUE;
+}
+
+/*
+ * Build the Login Computed Command
+ *
+ * +-------------------------+---------------------------------------+
+ * | LOGIN COMP CMD (1 byte) | MD5 of RANDOM + SECRET KEY (32 chars) |
+ * +-------------------------+---------------------------------------+
+ *
+ */
+
+int ajp14_marshal_login_comp_into_msgb(jk_msg_buf_t *msg,
+ jk_login_service_t *s,
+ jk_logger_t *l)
+{
+ jk_log(l, JK_LOG_DEBUG, "Into ajp14_marshal_login_comp_into_msgb\n");
+
+ /* To be on the safe side */
+ jk_b_reset(msg);
+
+ /*
+ * LOGIN
+ */
+ if (jk_b_append_byte(msg, AJP14_LOGCOMP_CMD))
+ return JK_FALSE;
+
+ /*
+ * COMPUTED-SEED
+ */
+ if (jk_b_append_bytes(msg, (const unsigned char *)s->computed_key, AJP14_COMPUTED_KEY_LEN)) {
+ jk_log(l, JK_LOG_ERROR, "Error ajp14_marshal_login_comp_into_msgb - Error appending the COMPUTED MD5 bytes\n");
+ return JK_FALSE;
+ }
+
+ return JK_TRUE;
+}
+
+
+/*
+ * Decode the LogOk Command
+ *
+ * +--------------------+------------------------+-------------------------------+
+ * | LOGOK CMD (1 byte) | NEGOCIED DATA (32bits) | SERVLET ENGINE INFO (CString) |
+ * +--------------------+------------------------+-------------------------------+
+ *
+ */
+
+int ajp14_unmarshal_log_ok(jk_msg_buf_t *msg,
+ jk_login_service_t *s,
+ jk_logger_t *l)
+{
+ unsigned long nego;
+ char * sname;
+
+ nego = jk_b_get_long(msg);
+
+ if (nego == 0xFFFFFFFF) {
+ jk_log(l, JK_LOG_ERROR, "Error ajp14_unmarshal_log_ok - can't get negociated data\n");
+ return JK_FALSE;
+ }
+
+ sname = (char *)jk_b_get_string(msg);
+
+ if (! sname) {
+ jk_log(l, JK_LOG_ERROR, "Error ajp14_unmarshal_log_ok - can't get servlet engine name\n");
+ return JK_FALSE;
+ }
+
+ if (s->servlet_engine_name) /* take care of removing previously allocated data */
+ free(s->servlet_engine_name);
+
+ s->servlet_engine_name = strdup(sname);
+
+ if (! s->servlet_engine_name) {
+ jk_log(l, JK_LOG_ERROR, "Error ajp14_unmarshal_log_ok - can't malloc servlet engine name\n");
+ return JK_FALSE;
+ }
+
+ return JK_TRUE;
+}
+
+
+/*
+ * Decode the Log Nok Command
+ *
+ * +---------------------+-----------------------+
+ * | LOGNOK CMD (1 byte) | FAILURE CODE (32bits) |
+ * +---------------------+-----------------------+
+ *
+ */
+
+int ajp14_unmarshal_log_nok(jk_msg_buf_t *msg,
+ jk_logger_t *l)
+{
+ unsigned long status;
+
+ jk_log(l, JK_LOG_DEBUG, "Into ajp14_unmarshal_log_nok\n");
+
+ status = jk_b_get_long(msg);
+
+ if (status == 0xFFFFFFFF) {
+ jk_log(l, JK_LOG_ERROR, "Error ajp14_unmarshal_log_nok - can't get failure code\n");
+ return JK_FALSE;
+ }
+
+ jk_log(l, JK_LOG_INFO, "Can't Log with servlet engine - code %08lx", status);
+ return JK_TRUE;
+}
+
+
/*
* Build the Shutdown Cmd
*
@@ -172,5 +356,291 @@
}
return JK_TRUE;
+}
+
+/*
+ * Build the Context Query Cmd (autoconf)
+ *
+ * +--------------------------+---------------------------------+
+ * | CONTEXT QRY CMD (1 byte) | VIRTUAL HOST NAME (CString (*)) |
+ * +--------------------------+---------------------------------+
+ *
+ */
+
+int ajp14_marshal_context_query_into_msgb(jk_msg_buf_t *msg,
+ char *virtual,
+ jk_logger_t *l)
+{
+ jk_log(l, JK_LOG_DEBUG, "Into ajp14_marshal_context_query_into_msgb\n");
+
+ /* To be on the safe side */
+ jk_b_reset(msg);
+
+ /*
+ * CONTEXT QUERY CMD
+ */
+ if (jk_b_append_byte(msg, AJP14_CONTEXT_QRY_CMD))
+ return JK_FALSE;
+
+ /*
+ * VIRTUAL HOST CSTRING
+ */
+ if (jk_b_append_string(msg, virtual)) {
+ jk_log(l, JK_LOG_ERROR, "Error ajp14_marshal_context_query_into_msgb - Error appending the virtual host string\n");
+ return JK_FALSE;
+ }
+
+ return JK_TRUE;
+}
+
+
+/*
+ * Decode the Context Info Cmd (Autoconf)
+ *
+ * The Autoconf feature of AJP14, let us know which URL/URI could
+ * be handled by the servlet-engine
+ *
+ * +---------------------------+---------------------------------+----------------------------+-------------------------------+-----------+
+ * | CONTEXT INFO CMD (1 byte) | VIRTUAL HOST NAME (CString (*)) | CONTEXT NAME (CString (*)) | URL1 [\n] URL2 [\n] URL3 [\n] | NEXT CTX. |
+ * +---------------------------+---------------------------------+----------------------------+-------------------------------+-----------+
+ */
+
+int ajp14_unmarshal_context_info(jk_msg_buf_t *msg,
+ jk_context_t *c,
+ jk_logger_t *l)
+{
+ char *vname;
+ char *cname;
+ char *uri;
+
+ vname = (char *)jk_b_get_string(msg);
+
+ jk_log(l, JK_LOG_DEBUG, "ajp14_unmarshal_context_info - get virtual %s for virtual %s\n", vname, c->virtual);
+
+ if (! vname) {
+ jk_log(l, JK_LOG_ERROR, "Error ajp14_unmarshal_context_info - can't get virtual hostname\n");
+ return JK_FALSE;
+ }
+
+ /* Check if we get the correct virtual host */
+ if (c->virtual != NULL &&
+ vname != NULL &&
+ strcmp(c->virtual, vname)) {
+ /* set the virtual name, better to add to a virtual list ? */
+
+ if (context_set_virtual(c, vname) == JK_FALSE) {
+ jk_log(l, JK_LOG_ERROR, "Error ajp14_unmarshal_context_info - can't malloc virtual hostname\n");
+ return JK_FALSE;
+ }
+ }
+
+ for (;;) {
+
+ cname = (char *)jk_b_get_string(msg);
+
+ if (! cname) {
+ jk_log(l, JK_LOG_ERROR, "Error ajp14_unmarshal_context_info - can't get context\n");
+ return JK_FALSE;
+ }
+
+ jk_log(l, JK_LOG_DEBUG, "ajp14_unmarshal_context_info - get context %s for virtual %s\n", cname, vname);
+
+ /* grab all contexts up to empty one which indicate end of contexts */
+ if (! strlen(cname))
+ break;
+
+ /* create new context base (if needed) */
+
+ if (context_add_base(c, cname) == JK_FALSE) {
+ jk_log(l, JK_LOG_ERROR, "Error ajp14_unmarshal_context_info - can't add/set context %s\n", cname);
+ return JK_FALSE;
+ }
+
+ for (;;) {
+
+ uri = (char *)jk_b_get_string(msg);
+
+ if (!uri) {
+ jk_log(l, JK_LOG_ERROR, "Error ajp14_unmarshal_context_info - can't get URI\n");
+ return JK_FALSE;
+ }
+
+ if (! strlen(uri)) {
+ jk_log(l, JK_LOG_DEBUG, "No more URI for context %s", cname);
+ break;
+ }
+
+ jk_log(l, JK_LOG_INFO, "Got URI (%s) for virtualhost %s and context %s\n", uri, vname, cname);
+
+ if (context_add_uri(c, cname, uri) == JK_FALSE) {
+ jk_log(l, JK_LOG_ERROR, "Error ajp14_unmarshal_context_info - can't add/set uri (%s) for context %s\n", uri, cname);
+ return JK_FALSE;
+ }
+ }
+ }
+
+ return JK_TRUE;
+}
+
+
+/*
+ * Build the Context State Query Cmd
+ *
+ * We send the list of contexts where we want to know state, empty string end context list*
+ * If cname is set, only ask about THIS context
+ *
+ * +----------------------------+----------------------------------+----------------------------+----+
+ * | CONTEXT STATE CMD (1 byte) | VIRTUAL HOST NAME (CString (*)) | CONTEXT NAME (CString (*)) | .. |
+ * +----------------------------+----------------------------------+----------------------------+----+
+ *
+ */
+
+int ajp14_marshal_context_state_into_msgb(jk_msg_buf_t *msg,
+ jk_context_t *c,
+ char *cname,
+ jk_logger_t *l)
+{
+ jk_context_item_t *ci;
+ int i;
+
+ jk_log(l, JK_LOG_DEBUG, "Into ajp14_marshal_context_state_into_msgb\n");
+
+ /* To be on the safe side */
+ jk_b_reset(msg);
+
+ /*
+ * CONTEXT STATE CMD
+ */
+ if (jk_b_append_byte(msg, AJP14_CONTEXT_STATE_CMD))
+ return JK_FALSE;
+
+ /*
+ * VIRTUAL HOST CSTRING
+ */
+ if (jk_b_append_string(msg, c->virtual)) {
+ jk_log(l, JK_LOG_ERROR, "Error ajp14_marshal_context_state_into_msgb - Error appending the virtual host string\n");
+ return JK_FALSE;
+ }
+
+ if (cname) {
+
+ ci = context_find_base(c, cname);
+
+ if (! ci) {
+ jk_log(l, JK_LOG_ERROR, "Warning ajp14_marshal_context_state_into_msgb - unknown context %s\n", cname);
+ return JK_FALSE;
+ }
+
+ /*
+ * CONTEXT CSTRING
+ */
+
+ if (jk_b_append_string(msg, cname )) {
+ jk_log(l, JK_LOG_ERROR, "Error ajp14_marshal_context_state_into_msgb - Error appending the context string %s\n", cname);
+ return JK_FALSE;
+ }
+ }
+ else { /* Grab all contexts name */
+
+ for (i = 0; i < c->size; i++) {
+
+ /*
+ * CONTEXT CSTRING
+ */
+ if (jk_b_append_string(msg, c->contexts[i]->cbase )) {
+ jk_log(l, JK_LOG_ERROR, "Error ajp14_marshal_context_state_into_msgb - Error appending the context string\n");
+ return JK_FALSE;
+ }
+ }
+ }
+
+ /* End of context list, an empty string */
+
+ if (jk_b_append_string(msg, "")) {
+ jk_log(l, JK_LOG_ERROR, "Error ajp14_marshal_context_state_into_msgb - Error appending end of contexts\n");
+ return JK_FALSE;
+ }
+
+ return JK_TRUE;
+}
+
+
+/*
+ * Decode the Context State Reply Cmd
+ *
+ * We get update of contexts list, empty string end context list*
+ *
+ * +----------------------------------+---------------------------------+----------------------------+------------------+----+
+ * | CONTEXT STATE REPLY CMD (1 byte) | VIRTUAL HOST NAME (CString (*)) | CONTEXT NAME (CString (*)) | UP/DOWN (1 byte) | .. |
+ * +----------------------------------+---------------------------------+----------------------------+------------------+----+
+ *
+ */
+
+int ajp14_unmarshal_context_state_reply(jk_msg_buf_t *msg,
+ jk_context_t *c,
+ jk_logger_t *l)
+{
+ char *vname;
+ char *cname;
+ jk_context_item_t *ci;
+
+ /* get virtual name */
+ vname = (char *)jk_b_get_string(msg);
+
+ if (! vname) {
+ jk_log(l, JK_LOG_ERROR, "Error ajp14_unmarshal_context_state_reply - can't get virtual hostname\n");
+ return JK_FALSE;
+ }
+
+ /* Check if we speak about the correct virtual */
+ if (strcmp(c->virtual, vname)) {
+ jk_log(l, JK_LOG_ERROR, "Error ajp14_unmarshal_context_state_reply - incorrect virtual %s instead of %s\n",
+ vname, c->virtual);
+ return JK_FALSE;
+ }
+
+ for (;;) {
+
+ /* get context name */
+ cname = (char *)jk_b_get_string(msg);
+
+ if (! cname) {
+ jk_log(l, JK_LOG_ERROR, "Error ajp14_unmarshal_context_state_reply - can't get context\n");
+ return JK_FALSE;
+ }
+
+ if (! strlen(cname))
+ break;
+
+ ci = context_find_base(c, cname);
+
+ if (! ci) {
+ jk_log(l, JK_LOG_ERROR, "Error ajp14_unmarshal_context_state_reply - unknow context %s for virtual %s\n",
+ cname, vname);
+ return JK_FALSE;
+ }
+
+ ci->status = jk_b_get_int(msg);
+
+ jk_log(l, JK_LOG_DEBUG, "ajp14_unmarshal_context_state_reply - updated context %s to state %d\n", cname, ci->status);
+ }
+
+ return JK_TRUE;
+}
+
+/*
+ * Decode the Context Update Cmd
+ *
+ * +-----------------------------+---------------------------------+----------------------------+------------------+
+ * | CONTEXT UPDATE CMD (1 byte) | VIRTUAL HOST NAME (CString (*)) | CONTEXT NAME (CString (*)) | UP/DOWN (1 byte) |
+ * +-----------------------------+---------------------------------+----------------------------+------------------+
+ *
+ */
+
+int ajp14_unmarshal_context_update_cmd(jk_msg_buf_t *msg,
+ jk_context_t *c,
+ jk_logger_t *l)
+{
+ return (ajp14_unmarshal_context_state_reply(msg, c, l));
}
1.9 +141 -83 jakarta-tomcat-connectors/jk/native/common/jk_ajp14.h
Index: jk_ajp14.h
===================================================================
RCS file: /home/cvs/jakarta-tomcat-connectors/jk/native/common/jk_ajp14.h,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- jk_ajp14.h 2001/11/26 17:19:16 1.8
+++ jk_ajp14.h 2001/12/04 19:44:23 1.9
@@ -58,7 +58,7 @@
/***************************************************************************
* Description: Next generation bi-directional protocol handler. *
* Author: Henri Gomez <hg...@slib.fr> *
- * Version: $Revision: 1.8 $ *
+ * Version: $Revision: 1.9 $ *
***************************************************************************/
#ifndef JK_AJP14_H
#define JK_AJP14_H
@@ -72,54 +72,80 @@
#define AJP14_PROTO 14
-#define AJP14_DEF_HOST ("localhost")
-#define AJP14_DEF_PORT (8011)
-#define AJP14_READ_BUF_SIZEd (8*1024)
-#define AJP14_DEF_RETRY_ATTEMPTS (1)
-#define AJP14_DEF_CACHE_SZ (1)
-#define AJP14_MAX_SEND_BODY_SZ (DEF_BUFFER_SZ - 6)
-#define AJP14_HEADER_LEN (4)
-#define AJP14_HEADER_SZ_LEN (2)
+#define AJP14_WS_HEADER 0x1235
+#define AJP14_SW_HEADER 0x1235 /* AJP14 use now the same header in both directions */
+#define AJP14_DEF_HOST ("localhost")
+#define AJP14_DEF_PORT (8011)
+#define AJP14_READ_BUF_SIZE (8*1024)
+#define AJP14_DEF_RETRY_ATTEMPTS (1)
+#define AJP14_DEF_CACHE_SZ (1)
+#define AJP14_MAX_SEND_BODY_SZ (DEF_BUFFER_SZ - 6)
+#define AJP14_HEADER_LEN (4)
+#define AJP14_HEADER_SZ_LEN (2)
+
+/*
+ * Initial Login Phase (web server -> servlet engine)
+ */
+#define AJP14_LOGINIT_CMD (unsigned char)0x10
+
+/*
+ * Second Login Phase (servlet engine -> web server), md5 seed is received
+ */
+#define AJP14_LOGSEED_CMD (unsigned char)0x11
+
+/*
+ * Third Login Phase (web server -> servlet engine), md5 of seed + secret is sent
+ */
+#define AJP14_LOGCOMP_CMD (unsigned char)0x12
+
/*
+ * Login Accepted (servlet engine -> web server)
+ */
+#define AJP14_LOGOK_CMD (unsigned char)0x13
+
+/*
+ * Login Rejected (servlet engine -> web server), will be logged
+ */
+#define AJP14_LOGNOK_CMD (unsigned char)0x14
+
+/*
* Context Query (web server -> servlet engine), which URI are handled by servlet engine ?
*/
-#define AJP14_CONTEXT_QRY_CMD (unsigned char)0x15
+#define AJP14_CONTEXT_QRY_CMD (unsigned char)0x15
/*
* Context Info (servlet engine -> web server), URI handled response
*/
-#define AJP14_CONTEXT_INFO_CMD (unsigned char)0x16
+#define AJP14_CONTEXT_INFO_CMD (unsigned char)0x16
/*
* Context Update (servlet engine -> web server), status of context changed
*/
-#define AJP14_CONTEXT_UPDATE_CMD (unsigned char)0x17
+#define AJP14_CONTEXT_UPDATE_CMD (unsigned char)0x17
/*
* Servlet Engine Status (web server -> servlet engine), what's the status of the servlet engine ?
*/
-#define AJP14_STATUS_CMD (unsigned char)0x18
+#define AJP14_STATUS_CMD (unsigned char)0x18
/*
- * Secure Shutdown command (web server -> servlet engine),
- * please servlet stop yourself.
+ * Secure Shutdown command (web server -> servlet engine), please servlet stop yourself.
*/
-#define AJP14_SHUTDOWN_CMD (unsigned char)0x19
+#define AJP14_SHUTDOWN_CMD (unsigned char)0x19
/*
* Secure Shutdown command Accepted (servlet engine -> web server)
*/
-#define AJP14_SHUTOK_CMD (unsigned char)0x1A
+#define AJP14_SHUTOK_CMD (unsigned char)0x1A
/*
* Secure Shutdown Rejected (servlet engine -> web server)
*/
-#define AJP14_SHUTNOK_CMD (unsigned char)0x1B
+#define AJP14_SHUTNOK_CMD (unsigned char)0x1B
/*
- * Context Status (web server -> servlet engine), what's
- * the status of the context ?
+ * Context Status (web server -> servlet engine), what's the status of the context ?
*/
#define AJP14_CONTEXT_STATE_CMD (unsigned char)0x1C
@@ -129,8 +155,7 @@
#define AJP14_CONTEXT_STATE_REP_CMD (unsigned char)0x1D
/*
- * Unknown Packet Reply (web server <-> servlet engine),
- * when a packet couldn't be decoded
+ * Unknown Packet Reply (web server <-> servlet engine), when a packet couldn't be decoded
*/
#define AJP14_UNKNOW_PACKET_CMD (unsigned char)0x1E
@@ -190,11 +215,21 @@
#define AJP14_PROTO_SUPPORT_AJP14_NEG 0x00010000
/*
+ * communication could use AJP15
+ */
+#define AJP14_PROTO_SUPPORT_AJP15_NEG 0x00020000
+
+/*
+ * communication could use AJP16
+ */
+#define AJP14_PROTO_SUPPORT_AJP16_NEG 0x00040000
+
+/*
* Some failure codes
*/
-#define AJP14_BAD_KEY_ERR 0xFFFFFFFF
-#define AJP14_ENGINE_DOWN_ERR 0xFFFFFFFE
-#define AJP14_RETRY_LATER_ERR 0xFFFFFFFD
+#define AJP14_BAD_KEY_ERR 0xFFFFFFFF
+#define AJP14_ENGINE_DOWN_ERR 0xFFFFFFFE
+#define AJP14_RETRY_LATER_ERR 0xFFFFFFFD
#define AJP14_SHUT_AUTHOR_FAILED_ERR 0xFFFFFFFC
/*
@@ -218,75 +253,98 @@
struct jk_login_service {
/*
- * Pointer to web-server name
+ * Pointer to web-server name
*/
char * web_server_name;
-
- /*
- * Pointer to servlet-engine name
- */
- char * servlet_engine_name;
-
- /*
- * Pointer to secret key
- */
- char * secret_key;
-
- /*
- * Received entropy seed
- */
- char entropy[AJP14_ENTROPY_SEED_LEN + 1];
-
- /*
- * Computed key
- */
- char computed_key[AJP14_COMPUTED_KEY_LEN + 1];
-
+
+ /*
+ * Pointer to servlet-engine name
+ */
+ char * servlet_engine_name;
+
+ /*
+ * Pointer to secret key
+ */
+ char * secret_key;
+
+ /*
+ * Received entropy seed
+ */
+ char entropy[AJP14_ENTROPY_SEED_LEN + 1];
+
+ /*
+ * Computed key
+ */
+ char computed_key[AJP14_COMPUTED_KEY_LEN + 1];
+
/*
* What we want to negociate
*/
unsigned long negociation;
-
- /*
- * What we received from servlet engine
+
+ /*
+ * What we received from servlet engine
*/
- unsigned long negociated;
+ unsigned long negociated;
};
-
+
/*
* functions defined here
*/
-int ajp14_marshal_shutdown_into_msgb(jk_msg_buf_t *msg,
- jk_login_service_t *s,
- jk_logger_t *l);
-
-int ajp14_unmarshal_shutdown_nok(jk_msg_buf_t *msg,
- jk_logger_t *l);
-
-int ajp14_marshal_unknown_packet_into_msgb(jk_msg_buf_t *msg,
- jk_msg_buf_t *unk,
- jk_logger_t *l);
-
-int ajp14_marshal_context_query_into_msgb(jk_msg_buf_t *msg,
- char *virtual,
- jk_logger_t *l);
-
-int ajp14_unmarshal_context_info(jk_msg_buf_t *msg,
- jk_context_t *context,
- jk_logger_t *l);
-
-int ajp14_marshal_context_state_into_msgb(jk_msg_buf_t *msg,
- jk_context_t *context,
- char *cname,
- jk_logger_t *l);
-
-int ajp14_unmarshal_context_state_reply(jk_msg_buf_t *msg,
- jk_context_t *context,
- jk_logger_t *l);
-
-int ajp14_unmarshal_context_update_cmd(jk_msg_buf_t *msg,
- jk_context_t *context,
- jk_logger_t *l);
+
+void ajp14_compute_md5(jk_login_service_t *s,
+ jk_logger_t *l);
+
+int ajp14_marshal_login_init_into_msgb(jk_msg_buf_t *msg,
+ jk_login_service_t *s,
+ jk_logger_t *l);
+
+int ajp14_unmarshal_login_seed(jk_msg_buf_t *msg,
+ jk_login_service_t *s,
+ jk_logger_t *l);
+
+int ajp14_marshal_login_comp_into_msgb(jk_msg_buf_t *msg,
+ jk_login_service_t *s,
+ jk_logger_t *l);
+
+int ajp14_unmarshal_log_ok(jk_msg_buf_t *msg,
+ jk_login_service_t *s,
+ jk_logger_t *l);
+
+int ajp14_unmarshal_log_nok(jk_msg_buf_t *msg,
+ jk_logger_t *l);
+
+int ajp14_marshal_shutdown_into_msgb(jk_msg_buf_t *msg,
+ jk_login_service_t *s,
+ jk_logger_t *l);
+
+int ajp14_unmarshal_shutdown_nok(jk_msg_buf_t *msg,
+ jk_logger_t *l);
+
+int ajp14_marshal_unknown_packet_into_msgb(jk_msg_buf_t *msg,
+ jk_msg_buf_t *unk,
+ jk_logger_t *l);
+
+int ajp14_marshal_context_query_into_msgb(jk_msg_buf_t *msg,
+ char *virtual,
+ jk_logger_t *l);
+
+int ajp14_unmarshal_context_info(jk_msg_buf_t *msg,
+ jk_context_t *context,
+ jk_logger_t *l);
+
+int ajp14_marshal_context_state_into_msgb(jk_msg_buf_t *msg,
+ jk_context_t *context,
+ char *cname,
+ jk_logger_t *l);
+
+int ajp14_unmarshal_context_state_reply(jk_msg_buf_t *msg,
+ jk_context_t *context,
+ jk_logger_t *l);
+
+int ajp14_unmarshal_context_update_cmd(jk_msg_buf_t *msg,
+ jk_context_t *context,
+ jk_logger_t *l);
#ifdef __cplusplus
}
1.16 +293 -144 jakarta-tomcat-connectors/jk/native/common/jk_ajp14_worker.c
Index: jk_ajp14_worker.c
===================================================================
RCS file: /home/cvs/jakarta-tomcat-connectors/jk/native/common/jk_ajp14_worker.c,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -r1.15 -r1.16
--- jk_ajp14_worker.c 2001/11/26 17:06:05 1.15
+++ jk_ajp14_worker.c 2001/12/04 19:44:23 1.16
@@ -55,77 +55,242 @@
* *
* ========================================================================= */
-/**
- * Description: AJP14 next generation Bi-directional protocol.
- * Backward compatible with Ajp13
- * Author: Henri Gomez <hg...@slib.fr>
- * Author: Costin <co...@costin.dnt.ro>
- * Author: Gal Shachor <sh...@il.ibm.com>
- */
+/***************************************************************************
+ * Description: AJP14 next generation Bi-directional protocol. *
+ * Author: Henri Gomez <hg...@slib.fr> *
+ * Version: $Revision: 1.16 $ *
+ ***************************************************************************/
-#include "jk_global.h"
#include "jk_context.h"
-#include "jk_pool.h"
-#include "jk_util.h"
-#include "jk_msg_buff.h"
-#include "jk_ajp_common.h"
-#include "jk_ajp14.h"
-#include "jk_logger.h"
-#include "jk_service.h"
+#include "jk_ajp14_worker.h"
-int JK_METHOD ajp14_worker_factory(jk_worker_t **w,
- const char *name,
- jk_logger_t *l);
+/*
+ * AJP14 Autoconf Phase
+ *
+ * CONTEXT QUERY / REPLY
+ */
+
+#define MAX_URI_SIZE 512
+
+static int handle_discovery(ajp_endpoint_t *ae,
+ jk_worker_env_t *we,
+ jk_msg_buf_t *msg,
+ jk_logger_t *l)
+{
+ int cmd;
+ int i,j;
+ jk_login_service_t *jl = ae->worker->login;
+ jk_context_item_t *ci;
+ jk_context_t *c;
+ char *buf;
+
+#ifndef TESTME
+
+ ajp14_marshal_context_query_into_msgb(msg, we->virtual, l);
+
+ jk_log(l, JK_LOG_DEBUG, "Into ajp14:discovery - send query\n");
+
+ if (ajp_connection_tcp_send_message(ae, msg, l) != JK_TRUE)
+ return JK_FALSE;
+
+ jk_log(l, JK_LOG_DEBUG, "Into ajp14:discovery - wait context reply\n");
+
+ jk_b_reset(msg);
+
+ if (ajp_connection_tcp_get_message(ae, msg, l) != JK_TRUE)
+ return JK_FALSE;
+
+ if ((cmd = jk_b_get_byte(msg)) != AJP14_CONTEXT_INFO_CMD) {
+ jk_log(l, JK_LOG_ERROR, "Error ajp14:discovery - awaited command %d, received %d\n", AJP14_CONTEXT_INFO_CMD, cmd);
+ return JK_FALSE;
+ }
+
+ if (context_alloc(&c, we->virtual) != JK_TRUE) {
+ jk_log(l, JK_LOG_ERROR, "Error ajp14:discovery - can't allocate context room\n");
+ return JK_FALSE;
+ }
+
+ if (ajp14_unmarshal_context_info(msg, c, l) != JK_TRUE) {
+ jk_log(l, JK_LOG_ERROR, "Error ajp14:discovery - can't get context reply\n");
+ return JK_FALSE;
+ }
+
+ jk_log(l, JK_LOG_DEBUG, "Into ajp14:discovery - received context\n");
+
+ buf = malloc(MAX_URI_SIZE); /* Really a very long URI */
+
+ if (! buf) {
+ jk_log(l, JK_LOG_ERROR, "Error ajp14:discovery - can't alloc buf\n");
+ return JK_FALSE;
+ }
+
+ for (i = 0; i < c->size; i++) {
+ ci = c->contexts[i];
+ for (j = 0; j < ci->size; j++) {
+
+#ifndef USE_SPRINTF
+ snprintf(buf, MAX_URI_SIZE - 1, "/%s/%s", ci->cbase, ci->uris[j]);
+#else
+ sprintf(buf, "/%s/%s", ci->cbase, ci->uris[j]);
+#endif
+
+ jk_log(l, JK_LOG_INFO, "Into ajp14:discovery - worker %s will handle uri %s in context %s [%s]\n",
+ ae->worker->name, ci->uris[j], ci->cbase, buf);
+
+ uri_worker_map_add(we->uri_to_worker, buf, ae->worker->name, l);
+ }
+ }
+
+ free(buf);
+ context_free(&c);
+
+#else
+
+ uri_worker_map_add(we->uri_to_worker, "/examples/servlet/*", ae->worker->name, l);
+ uri_worker_map_add(we->uri_to_worker, "/examples/*.jsp", ae->worker->name, l);
+ uri_worker_map_add(we->uri_to_worker, "/examples/*.gif", ae->worker->name, l);
+
+#endif
+
+ return JK_TRUE;
+}
+
+/*
+ * AJP14 Logon Phase
+ *
+ * INIT + REPLY / NEGO + REPLY
+ */
+
+static int handle_logon(ajp_endpoint_t *ae,
+ jk_msg_buf_t *msg,
+ jk_logger_t *l)
+{
+ int cmd;
+
+ jk_login_service_t *jl = ae->worker->login;
+
+ ajp14_marshal_login_init_into_msgb(msg, jl, l);
+
+ jk_log(l, JK_LOG_DEBUG, "Into ajp14:logon - send init\n");
+
+ if (ajp_connection_tcp_send_message(ae, msg, l) != JK_TRUE)
+ return JK_FALSE;
+
+ jk_log(l, JK_LOG_DEBUG, "Into ajp14:logon - wait init reply\n");
+
+ jk_b_reset(msg);
+
+ if (ajp_connection_tcp_get_message(ae, msg, l) != JK_TRUE)
+ return JK_FALSE;
+
+ if ((cmd = jk_b_get_byte(msg)) != AJP14_LOGSEED_CMD) {
+ jk_log(l, JK_LOG_ERROR, "Error ajp14:logon: awaited command %d, received %d\n", AJP14_LOGSEED_CMD, cmd);
+ return JK_FALSE;
+ }
+
+ if (ajp14_unmarshal_login_seed(msg, jl, l) != JK_TRUE)
+ return JK_FALSE;
+
+ jk_log(l, JK_LOG_DEBUG, "Into ajp14:logon - received entropy %s\n", jl->entropy);
+
+ ajp14_compute_md5(jl, l);
+
+ if (ajp14_marshal_login_comp_into_msgb(msg, jl, l) != JK_TRUE)
+ return JK_FALSE;
+
+ if (ajp_connection_tcp_send_message(ae, msg, l) != JK_TRUE)
+ return JK_FALSE;
+
+ jk_b_reset(msg);
+
+ if (ajp_connection_tcp_get_message(ae, msg, l) != JK_TRUE)
+ return JK_FALSE;
+
+ switch (jk_b_get_byte(msg)) {
+
+ case AJP14_LOGOK_CMD :
+ if (ajp14_unmarshal_log_ok(msg, jl, l) == JK_TRUE) {
+ jk_log(l, JK_LOG_DEBUG, "Successfully connected to servlet-engine %s\n", jl->servlet_engine_name);
+ return JK_TRUE;
+ }
+ break;
+
+ case AJP14_LOGNOK_CMD :
+ ajp14_unmarshal_log_nok(msg, l);
+ break;
+ }
+
+ return JK_FALSE;
+}
+
+static int logon(ajp_endpoint_t *ae,
+ jk_logger_t *l)
+{
+ jk_pool_t *p = &ae->pool;
+ jk_msg_buf_t *msg;
+ int rc;
+
+ jk_log(l, JK_LOG_DEBUG, "Into ajp14:logon\n");
+
+ msg = jk_b_new(p);
+ jk_b_set_buffer_size(msg, DEF_BUFFER_SZ);
+
+ if ((rc = handle_logon(ae, msg, l)) == JK_FALSE)
+ ajp_close_endpoint(ae, l);
+
+ return rc;
+}
-/* Ajp14 methods - XXX move to handler abstraction */
-int logon(ajp_endpoint_t *ae,
- jk_logger_t *l);
+static int discovery(ajp_endpoint_t *ae,
+ jk_worker_env_t *we,
+ jk_logger_t *l)
+{
+ jk_pool_t *p = &ae->pool;
+ jk_msg_buf_t *msg;
+ int rc;
-int discovery(ajp_endpoint_t *ae,
- jk_worker_env_t *we,
- jk_logger_t *l);
+ jk_log(l, JK_LOG_DEBUG, "Into ajp14:discovery\n");
+ msg = jk_b_new(p);
+ jk_b_set_buffer_size(msg, DEF_BUFFER_SZ);
+
+ if ((rc = handle_discovery(ae, we, msg, l)) == JK_FALSE)
+ ajp_close_endpoint(ae, l);
+
+ return rc;
+}
+
/* -------------------- Method -------------------- */
static int JK_METHOD validate(jk_worker_t *pThis,
jk_map_t *props,
jk_worker_env_t *we,
jk_logger_t *l)
{
- ajp_worker_t *aw;
- char * secret_key;
- int proto=AJP14_PROTO;
+ ajp_worker_t *aw;
+ char * secret_key;
- aw = pThis->worker_private;
- secret_key = jk_get_worker_secret_key(props, aw->name);
-
- if ((!secret_key) || (!strlen(secret_key))) {
- jk_log(l, JK_LOG_ERROR,
- "No secretkey, defaulting to unauthenticated AJP13\n");
- proto=AJP13_PROTO;
- aw->proto= AJP13_PROTO;
- aw->logon= NULL;
- }
-
- if (ajp_validate(pThis, props, we, l, proto) == JK_FALSE)
- return JK_FALSE;
-
- /* jk_log(l, JK_LOG_DEBUG,
- "Into ajp14:validate - secret_key=%s\n", secret_key); */
- return JK_TRUE;
+ if (ajp_validate(pThis, props, we, l, AJP14_PROTO) == JK_FALSE)
+ return JK_FALSE;
+
+ aw = pThis->worker_private;
+
+ secret_key = jk_get_worker_secret_key(props, aw->name);
+
+ if ((!secret_key) || (!strlen(secret_key))) {
+ jk_log(l, JK_LOG_ERROR, "validate error, empty or missing secretkey\n");
+ return JK_FALSE;
+ }
+
+ /* jk_log(l, JK_LOG_DEBUG, "Into ajp14:validate - secret_key=%s\n", secret_key); */
+ return JK_TRUE;
}
static int JK_METHOD get_endpoint(jk_worker_t *pThis,
jk_endpoint_t **pend,
jk_logger_t *l)
{
- ajp_worker_t *aw=pThis->worker_private;
-
- if( aw->login->secret_key ==NULL ) {
- return (ajp_get_endpoint(pThis, pend, l, AJP13_PROTO));
- } else {
- return (ajp_get_endpoint(pThis, pend, l, AJP14_PROTO));
- }
+ return (ajp_get_endpoint(pThis, pend, l, AJP14_PROTO));
}
static int JK_METHOD init(jk_worker_t *pThis,
@@ -133,85 +298,73 @@
jk_worker_env_t *we,
jk_logger_t *l)
{
- ajp_worker_t *aw=pThis->worker_private;
- ajp_endpoint_t *ae;
- jk_endpoint_t *je;
+ ajp_worker_t *aw;
+ ajp_endpoint_t *ae;
+ jk_endpoint_t *je;
int rc;
- char * secret_key;
- int proto=AJP14_PROTO;
-
- secret_key = jk_get_worker_secret_key(props, aw->name);
-
- if( secret_key==NULL ) {
- proto=AJP13_PROTO;
- aw->proto= AJP13_PROTO;
- aw->logon= NULL;
- } else {
- /* Set Secret Key (used at logon time) */
- aw->login->secret_key = strdup(secret_key);
- }
- if (ajp_init(pThis, props, we, l, proto) == JK_FALSE)
- return JK_FALSE;
-
- if (aw->login->secret_key == NULL) {
- /* No extra initialization for AJP13 */
- return JK_TRUE;
- }
+ if (ajp_init(pThis, props, we, l, AJP14_PROTO) == JK_FALSE)
+ return JK_FALSE;
- /* -------------------- Ajp14 discovery -------------------- */
-
- /* Set WebServerName (used at logon time) */
- aw->login->web_server_name = strdup(we->server_name);
-
- if (aw->login->web_server_name == NULL) {
- jk_log(l, JK_LOG_ERROR, "can't malloc web_server_name\n");
- return JK_FALSE;
- }
-
- if (get_endpoint(pThis, &je, l) == JK_FALSE)
- return JK_FALSE;
-
- ae = je->endpoint_private;
-
- if (ajp_connect_to_endpoint(ae, l) == JK_TRUE) {
-
+ aw = pThis->worker_private;
+
+ /* Set Secret Key (used at logon time) */
+ aw->login->secret_key = strdup(jk_get_worker_secret_key(props, aw->name));
+
+ if (aw->login->secret_key == NULL) {
+ jk_log(l, JK_LOG_ERROR, "can't malloc secret_key\n");
+ return JK_FALSE;
+ }
+
+ /* Set WebServerName (used at logon time) */
+ aw->login->web_server_name = strdup(we->server_name);
+
+ if (aw->login->web_server_name == NULL) {
+ jk_log(l, JK_LOG_ERROR, "can't malloc web_server_name\n");
+ return JK_FALSE;
+ }
+
+ if (get_endpoint(pThis, &je, l) == JK_FALSE)
+ return JK_FALSE;
+
+ ae = je->endpoint_private;
+
+ if (ajp_connect_to_endpoint(ae, l) == JK_TRUE) {
+
/* connection stage passed - try to get context info
* this is the long awaited autoconf feature :)
*/
rc = discovery(ae, we, l);
- ajp_close_endpoint(ae, l);
+ ajp_close_endpoint(ae, l);
return rc;
- }
-
- return JK_TRUE;
-}
+ }
+ return JK_TRUE;
+}
+
static int JK_METHOD destroy(jk_worker_t **pThis,
jk_logger_t *l)
{
- ajp_worker_t *aw = (*pThis)->worker_private;
-
- if (aw->login != NULL &&
- aw->login->secret_key != NULL ) {
- /* Ajp14-specific initialization */
- if (aw->login->web_server_name) {
- free(aw->login->web_server_name);
- aw->login->web_server_name = NULL;
- }
-
- if (aw->login->secret_key) {
- free(aw->login->secret_key);
- aw->login->secret_key = NULL;
- }
-
- free(aw->login);
- aw->login = NULL;
- return (ajp_destroy(pThis, l, AJP14_PROTO));
- } else {
- return (ajp_destroy(pThis, l, AJP13_PROTO));
- }
+ ajp_worker_t *aw = (*pThis)->worker_private;
+
+ if (aw->login) {
+
+ if (aw->login->web_server_name) {
+ free(aw->login->web_server_name);
+ aw->login->web_server_name = NULL;
+ }
+
+ if (aw->login->secret_key) {
+ free(aw->login->secret_key);
+ aw->login->secret_key = NULL;
+ }
+
+ free(aw->login);
+ aw->login = NULL;
+ }
+
+ return (ajp_destroy(pThis, l, AJP14_PROTO));
}
int JK_METHOD ajp14_worker_factory(jk_worker_t **w,
@@ -228,47 +381,43 @@
}
if (! aw) {
- jk_log(l, JK_LOG_ERROR,
- "In ajp14_worker_factory, malloc of private data failed\n");
+ jk_log(l, JK_LOG_ERROR, "In ajp14_worker_factory, malloc of private data failed\n");
return JK_FALSE;
}
aw->name = strdup(name);
-
+
if (! aw->name) {
free(aw);
- jk_log(l, JK_LOG_ERROR,
- "In ajp14_worker_factory, malloc failed for name\n");
+ jk_log(l, JK_LOG_ERROR, "In ajp14_worker_factory, malloc failed for name\n");
return JK_FALSE;
}
- aw->proto= AJP14_PROTO;
+ aw->proto = AJP14_PROTO;
- aw->login= (jk_login_service_t *)malloc(sizeof(jk_login_service_t));
+ aw->login = (jk_login_service_t *)malloc(sizeof(jk_login_service_t));
- if (aw->login == NULL) {
- jk_log(l, JK_LOG_ERROR,
- "In ajp14_worker_factory, malloc failed for login area\n");
- return JK_FALSE;
- }
+ if (aw->login == NULL) {
+ jk_log(l, JK_LOG_ERROR, "In ajp14_worker_factory, malloc failed for login area\n");
+ return JK_FALSE;
+ }
- memset(aw->login, 0, sizeof(jk_login_service_t));
-
- aw->login->negociation=
- (AJP14_CONTEXT_INFO_NEG | AJP14_PROTO_SUPPORT_AJP14_NEG);
- aw->login->web_server_name=NULL; /* must be set in init */
-
- aw->ep_cache_sz= 0;
- aw->ep_cache= NULL;
- aw->connect_retry_attempts= AJP_DEF_RETRY_ATTEMPTS;
- aw->worker.worker_private= aw;
+ memset(aw->login, 0, sizeof(jk_login_service_t));
+
+ aw->login->negociation = (AJP14_CONTEXT_INFO_NEG | AJP14_PROTO_SUPPORT_AJP14_NEG);
+ aw->login->web_server_name = NULL; /* must be set in init */
+
+ aw->ep_cache_sz = 0;
+ aw->ep_cache = NULL;
+ aw->connect_retry_attempts = AJP_DEF_RETRY_ATTEMPTS;
+ aw->worker.worker_private = aw;
- aw->worker.validate= validate;
- aw->worker.init= init;
- aw->worker.get_endpoint= get_endpoint;
- aw->worker.destroy=destroy;
- aw->logon= logon;
+ aw->worker.validate = validate;
+ aw->worker.init = init;
+ aw->worker.get_endpoint = get_endpoint;
+ aw->worker.destroy = destroy;
+ aw->logon = logon; /* LogOn Handler for AJP14 */
*w = &aw->worker;
return JK_TRUE;
}
1.21 +245 -363 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.20
retrieving revision 1.21
diff -u -r1.20 -r1.21
--- jk_ajp_common.c 2001/11/20 16:58:46 1.20
+++ jk_ajp_common.c 2001/12/04 19:44:23 1.21
@@ -59,17 +59,16 @@
* Description: common stuff for bi-directional protocols ajp13/ajp14. *
* Author: Gal Shachor <sh...@il.ibm.com> *
* Author: Henri Gomez <hg...@slib.fr> *
- * Version: $Revision: 1.20 $ *
+ * Version: $Revision: 1.21 $ *
***************************************************************************/
#include "jk_global.h"
#include "jk_util.h"
-#include "jk_ajp_common.h"
+#include "jk_ajp13.h"
#include "jk_ajp14.h"
+#include "jk_ajp_common.h"
#include "jk_connect.h"
-#include "jk_channel.h"
-#include "jk_env.h"
const char *response_trans_headers[] = {
@@ -407,28 +406,6 @@
return JK_TRUE;
}
-int ajp13_marshal_shutdown_into_msgb(jk_msg_buf_t *msg,
- jk_pool_t *p,
- jk_logger_t *l)
-{
- jk_log(l, JK_LOG_DEBUG, "Into ajp13_marshal_shutdown_into_msgb\n");
-
- /* To be on the safe side */
- jk_b_reset(msg);
-
- /*
- * Just a single byte with s/d command.
- */
- if (jk_b_append_byte(msg, JK_AJP13_SHUTDOWN)) {
- jk_log(l, JK_LOG_ERROR, "ajp13_marshal_shutdown_into_msgb: "
- "Error appending shutdown message\n");
- return JK_FALSE;
- }
-
- return JK_TRUE;
-}
-
-
/*
AJPV13_RESPONSE/AJPV14_RESPONSE:=
response_prefix (2)
@@ -547,38 +524,30 @@
void ajp_close_endpoint(ajp_endpoint_t *ae,
jk_logger_t *l)
{
- jk_log(l, JK_LOG_DEBUG, "In jk_endpoint_t::ajp_close_endpoint\n");
+ jk_log(l, JK_LOG_DEBUG, "In jk_endpoint_t::ajp_close_endpoint\n");
ajp_reset_endpoint(ae);
jk_close_pool(&(ae->pool));
-#ifdef CHANNEL
- {
- jk_channel_t *channel=ae->worker->worker.channel;
- int err=channel->close( channel, &ae->endpoint );
- }
-#else
if (ae->sd > 0) {
- jk_close_socket(ae->sd);
- jk_log(l, JK_LOG_DEBUG, "In jk_endpoint_t::ajp_close_endpoint, closed sd = %d\n", ae->sd);
- ae->sd = -1; /* just to avoid twice close */
- }
-#endif
+ jk_close_socket(ae->sd);
+ jk_log(l, JK_LOG_DEBUG, "In jk_endpoint_t::ajp_close_endpoint, closed sd = %d\n", ae->sd);
+ ae->sd = -1; /* just to avoid twice close */
+ }
free(ae);
}
-#ifndef CHANNEL
+
/*
* Try to reuse a previous connection
*/
+
static void ajp_reuse_connection(ajp_endpoint_t *ae,
jk_logger_t *l)
{
ajp_worker_t *aw = ae->worker;
-
- if (aw==NULL )
- return;
+
if (aw->ep_cache_sz) {
int rc;
JK_ENTER_CS(&aw->cs, rc);
@@ -598,7 +567,6 @@
}
}
}
-#endif
int ajp_connect_to_endpoint(ajp_endpoint_t *ae,
@@ -607,26 +575,20 @@
unsigned attempt;
for(attempt = 0 ; attempt < ae->worker->connect_retry_attempts ; attempt++) {
-#ifdef CHANNEL
- jk_channel_t *channel=ae->worker->worker.channel;
- int err=channel->open( channel, &ae->endpoint );
- jk_log(l, JK_LOG_DEBUG, "ajp_connect_to_endpoint: connected %lx\n", &ae->endpoint );
- if( err == JK_TRUE ) {
-#else
ae->sd = jk_open_socket(&ae->worker->worker_inet_addr, JK_TRUE, l);
if(ae->sd >= 0) {
jk_log(l, JK_LOG_DEBUG, "In jk_endpoint_t::ajp_connect_to_endpoint, connected sd = %d\n", ae->sd);
-#endif
- /* Check if we must execute a logon after the physical connect */
- if (ae->worker->logon != NULL)
- return (ae->worker->logon(ae, l));
-
- return JK_TRUE;
+
+ /* Check if we must execute a logon after the physical connect */
+ if (ae->worker->logon != NULL)
+ return (ae->worker->logon(ae, l));
+
+ return JK_TRUE;
}
}
jk_log(l, JK_LOG_ERROR, "In jk_endpoint_t::ajp_connect_to_endpoint, failed errno = %d\n", errno);
- return JK_FALSE;
+ return JK_FALSE;
}
/*
@@ -637,24 +599,22 @@
jk_msg_buf_t *msg,
jk_logger_t *l)
{
- jk_b_end(msg, AJP13_WS_HEADER);
- jk_dump_buff(l, JK_LOG_DEBUG, "sending to ajp13", msg);
-#ifdef CHANNEL
- {
- int err;
- jk_channel_t *channel=ae->worker->worker.channel;
-
- err=channel->send( channel, &ae->endpoint,
- jk_b_get_buff(msg), jk_b_get_len(msg) );
- if( err!=JK_TRUE ) {
- return err;
+ if (ae->proto == AJP13_PROTO) {
+ jk_b_end(msg, AJP13_WS_HEADER);
+ jk_dump_buff(l, JK_LOG_DEBUG, "sending to ajp13", msg);
}
- }
-#else
+ else if (ae->proto == AJP14_PROTO) {
+ jk_b_end(msg, AJP14_WS_HEADER);
+ jk_dump_buff(l, JK_LOG_DEBUG, "sending to ajp14", msg);
+ }
+ else {
+ jk_log(l, JK_LOG_ERROR, "In jk_endpoint_t::ajp_connection_tcp_send_message, unknown protocol %d, supported are AJP13/AJP14\n", ae->proto);
+ return JK_FALSE;
+ }
+
if(0 > jk_tcp_socket_sendfull(ae->sd, jk_b_get_buff(msg), jk_b_get_len(msg))) {
return JK_FALSE;
}
-#endif
return JK_TRUE;
}
@@ -670,37 +630,45 @@
unsigned char head[AJP_HEADER_LEN];
int rc;
int msglen;
- unsigned int header;
+ unsigned int header;
- if ((ae->proto != AJP13_PROTO) && (ae->proto != AJP14_PROTO)) {
- jk_log(l, JK_LOG_ERROR, "ajp_connection_tcp_get_message:"
- " Can't handle unknown protocol %d\n", ae->proto);
- return JK_FALSE;
- }
-#ifdef CHANNEL
- {
- jk_channel_t *channel=ae->worker->worker.channel;
-
- rc=channel->recv( channel, &ae->endpoint,
- head, AJP_HEADER_LEN );
- }
-#else
+ if ((ae->proto != AJP13_PROTO) && (ae->proto != AJP14_PROTO)) {
+ jk_log(l, JK_LOG_ERROR, "ajp_connection_tcp_get_message: Can't handle unknown protocol %d\n", ae->proto);
+ return JK_FALSE;
+ }
+
rc = jk_tcp_socket_recvfull(ae->sd, head, AJP_HEADER_LEN);
-#endif
if(rc < 0) {
jk_log(l, JK_LOG_ERROR, "ajp_connection_tcp_get_message: Error - jk_tcp_socket_recvfull failed\n");
return JK_FALSE;
}
- header = ((unsigned int)head[0] << 8) | head[1];
-
- if (header != AJP13_SW_HEADER) {
- jk_log(l, JK_LOG_ERROR, "ajp_connection_tcp_get_message:"
- "Error - Wrong message format 0x%04x\n", header);
- return JK_FALSE;
- }
+ header = ((unsigned int)head[0] << 8) | head[1];
+
+ if (ae->proto == AJP13_PROTO) {
+ if (header != AJP13_SW_HEADER) {
+
+ if (header == AJP14_SW_HEADER)
+ jk_log(l, JK_LOG_ERROR, "ajp_connection_tcp_get_message: Error - received AJP14 reply on an AJP13 connection\n");
+ else
+ jk_log(l, JK_LOG_ERROR, "ajp_connection_tcp_get_message: Error - Wrong message format 0x%04x\n", header);
+
+ return JK_FALSE;
+ }
+ }
+ else if (ae->proto == AJP14_PROTO) {
+ if (header != AJP14_SW_HEADER) {
+
+ if (header == AJP13_SW_HEADER)
+ jk_log(l, JK_LOG_ERROR, "ajp_connection_tcp_get_message: Error - received AJP13 reply on an AJP14 connection\n");
+ else
+ jk_log(l, JK_LOG_ERROR, "ajp_connection_tcp_get_message: Error - Wrong message format 0x%04x\n", header);
+ return JK_FALSE;
+ }
+ }
+
msglen = ((head[2]&0xff)<<8);
msglen += (head[3] & 0xFF);
@@ -712,26 +680,17 @@
jk_b_set_len(msg, msglen);
jk_b_set_pos(msg, 0);
-#ifdef CHANNEL
- {
- jk_channel_t *channel=ae->worker->worker.channel;
-
- rc=channel->recv( channel, &ae->endpoint,
- jk_b_get_buff(msg), msglen);
- }
-#else
rc = jk_tcp_socket_recvfull(ae->sd, jk_b_get_buff(msg), msglen);
-#endif
if(rc < 0) {
jk_log(l, JK_LOG_ERROR, "ajp_connection_tcp_get_message: Error - jk_tcp_socket_recvfull failed\n");
return JK_FALSE;
}
- if (ae->proto == AJP13_PROTO)
+ if (ae->proto == AJP13_PROTO)
jk_dump_buff(l, JK_LOG_DEBUG, "received from ajp13", msg);
- else if (ae->proto == AJP14_PROTO)
- jk_dump_buff(l, JK_LOG_DEBUG, "received from ajp14", msg);
-
+ else if (ae->proto == AJP14_PROTO)
+ jk_dump_buff(l, JK_LOG_DEBUG, "received from ajp14", msg);
+
return JK_TRUE;
}
@@ -841,106 +800,89 @@
* repmsg is the reply msg buffer which could be scratched
*/
static int ajp_send_request(jk_endpoint_t *e,
- jk_ws_service_t *s,
- jk_logger_t *l,
- ajp_endpoint_t *ae,
- ajp_operation_t *op)
+ jk_ws_service_t *s,
+ jk_logger_t *l,
+ ajp_endpoint_t *ae,
+ ajp_operation_t *op)
{
- int err=JK_TRUE;
-
- /* Up to now, we can recover */
- op->recoverable = JK_TRUE;
+ /* Up to now, we can recover */
+ op->recoverable = JK_TRUE;
- /*
- * First try to reuse open connections...
- */
-#ifdef CHANNEL
- {
- jk_channel_t *channel=ae->worker->worker.channel;
- err=ajp_connection_tcp_send_message(ae, op->request, l);
- if( err != JK_TRUE ) {
- jk_log(l, JK_LOG_ERROR, "Error sending request, close endpoint\n");
- channel->close( channel, &ae->endpoint );
- }
- }
-#else
- while ((ae->sd > 0) && ! ajp_connection_tcp_send_message(ae, op->request, l)) {
- jk_log(l, JK_LOG_ERROR, "Error sending request try another pooled connection\n");
- jk_close_socket(ae->sd);
- ae->sd = -1;
- ajp_reuse_connection(ae, l);
- }
- if (ae->sd < 0)
- err=JK_FALSE;
-#endif
+ /*
+ * First try to reuse open connections...
+ */
+ while ((ae->sd > 0) && ! ajp_connection_tcp_send_message(ae, op->request, l)) {
+ jk_log(l, JK_LOG_ERROR, "Error sending request try another pooled connection\n");
+ jk_close_socket(ae->sd);
+ ae->sd = -1;
+ ajp_reuse_connection(ae, l);
+ }
- /*
- * If we failed to reuse a connection, try to reconnect.
- */
- if( err != JK_TRUE ) {
- err=ajp_connect_to_endpoint(ae, l);
- if ( err != JK_TRUE) {
- jk_log(l, JK_LOG_ERROR, "Error connecting to the Tomcat process.\n");
- return JK_FALSE;
- }
- /*
- * After we are connected, each error that we are going to
- * have is probably unrecoverable
- */
- err=ajp_connection_tcp_send_message(ae, op->request, l);
- if (err != JK_TRUE) {
- jk_log(l, JK_LOG_ERROR, "Error sending request on a fresh connection\n");
- return JK_FALSE;
- }
- }
-
- /*
- * From now on an error means that we have an internal server error
- * or Tomcat crashed. In any case we cannot recover this.
- */
-
- jk_log(l, JK_LOG_DEBUG, "ajp_send_request 2: request body to send %d - request body to resend %d\n",
- ae->left_bytes_to_send, jk_b_get_len(op->reply) - AJP_HEADER_LEN);
-
- /*
- * POST recovery job is done here.
- * It's not very fine to have posted data in reply but that's the only easy
- * way to do that for now. Sharing the reply is really a bad solution but
- * it will works for POST DATA less than 8k.
- * We send here the first part of data which was sent previously to the
- * remote Tomcat
- */
- if (jk_b_get_len(op->post) > AJP_HEADER_LEN) {
- err=ajp_connection_tcp_send_message(ae, op->post, l);
- if(err != JK_TRUE) {
- jk_log(l, JK_LOG_ERROR, "Error resending request body\n");
- return JK_FALSE;
+ /*
+ * If we failed to reuse a connection, try to reconnect.
+ */
+ if (ae->sd < 0) {
+ if (ajp_connect_to_endpoint(ae, l) == JK_TRUE) {
+ /*
+ * After we are connected, each error that we are going to
+ * have is probably unrecoverable
+ */
+ if (!ajp_connection_tcp_send_message(ae, op->request, l)) {
+ jk_log(l, JK_LOG_ERROR, "Error sending request on a fresh connection\n");
+ return JK_FALSE;
+ }
+ } else {
+ jk_log(l, JK_LOG_ERROR, "Error connecting to the Tomcat process.\n");
+ return JK_FALSE;
+ }
}
- } else {
- /* We never sent any POST data and we check it we have to send at
- * least of block of data (max 8k). These data will be kept in reply
- * for resend if the remote Tomcat is down, a fact we will learn only
- * doing a read (not yet)
+
+ /*
+ * From now on an error means that we have an internal server error
+ * or Tomcat crashed. In any case we cannot recover this.
*/
- if (s->is_chunked || ae->left_bytes_to_send > 0) {
- unsigned len = ae->left_bytes_to_send;
- if (len > AJP13_MAX_SEND_BODY_SZ)
- len = AJP13_MAX_SEND_BODY_SZ;
- len = ajp_read_into_msg_buff(ae, s, op->post, len, l);
- if (len < 0) {
- /* the browser stop sending data, no need to recover */
- op->recoverable = JK_FALSE;
- return JK_FALSE;
- }
- s->content_read = len;
- err=ajp_connection_tcp_send_message(ae, op->post, l);
- if (err!=JK_TRUE) {
- jk_log(l, JK_LOG_ERROR, "Error sending request body\n");
- return JK_FALSE;
- }
+
+ jk_log(l, JK_LOG_DEBUG, "ajp_send_request 2: request body to send %d - request body to resend %d\n",
+ ae->left_bytes_to_send, jk_b_get_len(op->reply) - AJP_HEADER_LEN);
+
+ /*
+ * POST recovery job is done here.
+ * It's not very fine to have posted data in reply but that's the only easy
+ * way to do that for now. Sharing the reply is really a bad solution but
+ * it will works for POST DATA less than 8k.
+ * We send here the first part of data which was sent previously to the
+ * remote Tomcat
+ */
+ if (jk_b_get_len(op->post) > AJP_HEADER_LEN) {
+ if(!ajp_connection_tcp_send_message(ae, op->post, l)) {
+ jk_log(l, JK_LOG_ERROR, "Error resending request body\n");
+ return JK_FALSE;
+ }
}
- }
- return (JK_TRUE);
+ else
+ {
+ /* We never sent any POST data and we check it we have to send at
+ * least of block of data (max 8k). These data will be kept in reply
+ * for resend if the remote Tomcat is down, a fact we will learn only
+ * doing a read (not yet)
+ */
+ if (s->is_chunked || ae->left_bytes_to_send > 0) {
+ unsigned len = ae->left_bytes_to_send;
+ if (len > AJP13_MAX_SEND_BODY_SZ)
+ len = AJP13_MAX_SEND_BODY_SZ;
+ if ((len = ajp_read_into_msg_buff(ae, s, op->post, len, l)) < 0) {
+ /* the browser stop sending data, no need to recover */
+ op->recoverable = JK_FALSE;
+ return JK_FALSE;
+ }
+ s->content_read = len;
+ if (!ajp_connection_tcp_send_message(ae, op->post, l)) {
+ jk_log(l, JK_LOG_ERROR, "Error sending request body\n");
+ return JK_FALSE;
+ }
+ }
+ }
+ return (JK_TRUE);
}
/*
@@ -1026,7 +968,6 @@
default:
jk_log(l, JK_LOG_ERROR, "Error ajp_process_callback - Invalid code: %d\n", code);
- jk_dump_buff(l, JK_LOG_ERROR, "Message: ", msg);
return JK_AJP13_ERROR;
}
@@ -1119,120 +1060,95 @@
jk_logger_t *l,
int *is_recoverable_error)
{
- int i;
- int err;
- ajp_operation_t oper;
- ajp_operation_t *op = &oper;
- ajp_endpoint_t *p;
-
- jk_log(l, JK_LOG_DEBUG, "Into jk_endpoint_t::service\n");
+ int i;
+ ajp_operation_t oper;
+ ajp_operation_t *op = &oper;
+
+ jk_log(l, JK_LOG_DEBUG, "Into jk_endpoint_t::service\n");
+
+ if(e && e->endpoint_private && s && is_recoverable_error) {
+ ajp_endpoint_t *p = e->endpoint_private;
+ op->request = jk_b_new(&(p->pool));
+ jk_b_set_buffer_size(op->request, DEF_BUFFER_SZ);
+ jk_b_reset(op->request);
+
+ op->reply = jk_b_new(&(p->pool));
+ jk_b_set_buffer_size(op->reply, DEF_BUFFER_SZ);
+ jk_b_reset(op->reply);
+
+ op->post = jk_b_new(&(p->pool));
+ jk_b_set_buffer_size(op->post, DEF_BUFFER_SZ);
+ jk_b_reset(op->post);
+
+ op->recoverable = JK_TRUE;
+ op->uploadfd = -1; /* not yet used, later ;) */
+
+ p->left_bytes_to_send = s->content_length;
+ p->reuse = JK_FALSE;
+ *is_recoverable_error = JK_TRUE;
+
+ /*
+ * We get here initial request (in reqmsg)
+ */
+ if (!ajp_marshal_into_msgb(op->request, s, l, p)) {
+ *is_recoverable_error = JK_FALSE;
+ return JK_FALSE;
+ }
- if( ( e== NULL ) || ( e->endpoint_private==NULL )
- || ( s == NULL ) || ! is_recoverable_error ) {
- jk_log(l, JK_LOG_ERROR, "jk_endpoint_t::service: NULL parameters\n");
- return JK_FALSE;
- }
-
- p = e->endpoint_private;
- op->request = jk_b_new(&(p->pool));
- jk_b_set_buffer_size(op->request, DEF_BUFFER_SZ);
- jk_b_reset(op->request);
-
- op->reply = jk_b_new(&(p->pool));
- jk_b_set_buffer_size(op->reply, DEF_BUFFER_SZ);
- jk_b_reset(op->reply);
-
- op->post = jk_b_new(&(p->pool));
- jk_b_set_buffer_size(op->post, DEF_BUFFER_SZ);
- jk_b_reset(op->post);
-
- op->recoverable = JK_TRUE;
- op->uploadfd = -1; /* not yet used, later ;) */
-
- p->left_bytes_to_send = s->content_length;
- p->reuse = JK_FALSE;
- *is_recoverable_error = JK_TRUE;
-
- /*
- * We get here initial request (in reqmsg)
- */
- if (!ajp_marshal_into_msgb(op->request, s, l, p)) {
- *is_recoverable_error = JK_FALSE;
- jk_log(l, JK_LOG_ERROR, "jk_endpoint_t::service: error marshaling\n");
- return JK_FALSE;
- }
-
- /*
- * JK_RETRIES could be replaced by the number of workers in
- * a load-balancing configuration
- */
- for (i = 0; i < JK_RETRIES; i++) {
- /*
- * We're using reqmsg which hold initial request
- * if Tomcat is stopped or restarted, we will pass reqmsg
- * to next valid tomcat.
- */
- err=ajp_send_request(e, s, l, p, op);
- if (err!=JK_TRUE ) {
- jk_log(l, JK_LOG_ERROR,
- "In jk_endpoint_t::service, ajp_send_request"
- "failed in send loop %d\n", i);
+ /*
+ * JK_RETRIES could be replaced by the number of workers in
+ * a load-balancing configuration
+ */
+ for (i = 0; i < JK_RETRIES; i++)
+ {
+ /*
+ * We're using reqmsg which hold initial request
+ * if Tomcat is stopped or restarted, we will pass reqmsg
+ * to next valid tomcat.
+ */
+ if (ajp_send_request(e, s, l, p, op)) {
+
+ /* If we have the no recoverable error, it's probably because the sender (browser)
+ * stop sending data before the end (certainly in a big post)
+ */
+ if (! op->recoverable) {
+ *is_recoverable_error = JK_FALSE;
+ jk_log(l, JK_LOG_ERROR, "In jk_endpoint_t::service, ajp_send_request failed without recovery in send loop %d\n", i);
+ return JK_FALSE;
+ }
+
+ /* Up to there we can recover */
+ *is_recoverable_error = JK_TRUE;
+ op->recoverable = JK_TRUE;
+
+ if (ajp_get_reply(e, s, l, p, op))
+ return (JK_TRUE);
+
+ /* if we can't get reply, check if no recover flag was set
+ * if is_recoverable_error is cleared, we have started received
+ * upload data and we must consider that operation is no more recoverable
+ */
+ if (! op->recoverable) {
+ *is_recoverable_error = JK_FALSE;
+ jk_log(l, JK_LOG_ERROR, "In jk_endpoint_t::service, ajp_get_reply failed without recovery in send loop %d\n", i);
+ return JK_FALSE;
+ }
+
+ jk_log(l, JK_LOG_ERROR, "In jk_endpoint_t::service, ajp_get_reply failed in send loop %d\n", i);
+ }
+ else
+ jk_log(l, JK_LOG_ERROR, "In jk_endpoint_t::service, ajp_send_request failed in send loop %d\n", i);
+
+ jk_close_socket(p->sd);
+ p->sd = -1;
+ ajp_reuse_connection(p, l);
+ }
} else {
- /* If we have the no recoverable error, it's probably because the sender (browser)
- * stop sending data before the end (certainly in a big post)
- */
- if (! op->recoverable) {
- *is_recoverable_error = JK_FALSE;
- jk_log(l, JK_LOG_ERROR, "In jk_endpoint_t::service,"
- "ajp_send_request failed without recovery in send loop %d\n", i);
- return JK_FALSE;
- }
-
- /* Up to there we can recover */
- *is_recoverable_error = JK_TRUE;
- op->recoverable = JK_TRUE;
-
- if (ajp_get_reply(e, s, l, p, op))
- return (JK_TRUE);
-
- /* if we can't get reply, check if no recover flag was set
- * if is_recoverable_error is cleared, we have started received
- * upload data and we must consider that operation is no more recoverable
- */
- if (! op->recoverable) {
- *is_recoverable_error = JK_FALSE;
- jk_log(l, JK_LOG_ERROR, "In jk_endpoint_t::service,"
- "ajp_get_reply failed without recovery in send loop %d\n", i);
- return JK_FALSE;
- }
-
- jk_log(l, JK_LOG_ERROR, "In jk_endpoint_t::service,"
- "ajp_get_reply failed in send loop %d\n", i);
- }
- /* Try again to connect */
-#ifdef CHANNEL
- {
- jk_channel_t *channel=p->worker->worker.channel;
-
- jk_log(l, JK_LOG_ERROR, "Error sending request, reconnect\n");
- err=channel->close( channel, &p->endpoint );
- err=channel->open( channel, &p->endpoint );
- if( err != JK_TRUE ) {
- jk_log(l, JK_LOG_ERROR, "Reconnect failed\n");
- return err;
- }
+ jk_log(l, JK_LOG_ERROR, "In jk_endpoint_t::service, NULL parameters\n");
}
-#else
- jk_log(l, JK_LOG_ERROR, "Error sending request try another pooled connection\n");
- jk_close_socket(p->sd);
- p->sd = -1;
- ajp_reuse_connection(p, l);
-#endif
- }
-
- return JK_FALSE;
-}
+ return JK_FALSE;
+}
/*
* Validate the worker (ajp13/ajp14)
*/
@@ -1241,56 +1157,28 @@
jk_map_t *props,
jk_worker_env_t *we,
jk_logger_t *l,
- int proto)
+ int proto)
{
- int port;
- char * host;
- int err;
- ajp_worker_t *p = pThis->worker_private;
+ int port;
+ char * host;
jk_log(l, JK_LOG_DEBUG, "Into jk_worker_t::validate\n");
- if( ( pThis==NULL ) || ( pThis->worker_private==NULL ) )
- return JK_FALSE;
-
- if (proto == AJP13_PROTO) {
- port = AJP13_DEF_PORT;
- host = AJP13_DEF_HOST;
- } else if (proto == AJP14_PROTO) {
- port = AJP14_DEF_PORT;
- host = AJP14_DEF_HOST;
- } else {
- jk_log(l, JK_LOG_DEBUG, "In jk_worker_t::validate unknown protocol %d\n", proto);
- return JK_FALSE;
- }
-#ifdef CHANNEL
- if( pThis->channel == NULL ) {
- /* Create a default channel */
- jk_env_t *env=jk_env_getEnv( NULL );
-
- jk_env_objectFactory_t fac =
- (jk_env_objectFactory_t)env->getFactory(env, "channel", "socket" );
- jk_log( l, JK_LOG_DEBUG, "Got socket channel factory \n");
-
- err=fac( env, (void **)&pThis->channel, "channel", "socket" );
- if( err != JK_TRUE ) {
- jk_log(l, JK_LOG_ERROR, "Error creating socket factory\n");
- return err;
+ if (proto == AJP13_PROTO) {
+ port = AJP13_DEF_PORT;
+ host = AJP13_DEF_HOST;
}
- jk_log(l, JK_LOG_ERROR, "Got channel %lx\n", pThis->channel);
- }
-
- pThis->channel->setProperty( pThis->channel, "defaultPort", "8007" );
+ else if (proto == AJP14_PROTO) {
+ port = AJP14_DEF_PORT;
+ host = AJP14_DEF_HOST;
+ }
+ else {
+ jk_log(l, JK_LOG_DEBUG, "In jk_worker_t::validate unknown protocol %d\n", proto);
+ return JK_FALSE;
+ }
- err=pThis->channel->init( pThis->channel, props, p->name, pThis, l );
- if( err != JK_TRUE ) {
- jk_log(l, JK_LOG_ERROR, "In jk_worker_t::validate, resolve failed\n");
- return err;
- }
-
- return JK_TRUE;
-#else
- if (pThis->worker_private) {
+ if (pThis && pThis->worker_private) {
+ ajp_worker_t *p = pThis->worker_private;
port = jk_get_worker_port(props, p->name, port);
host = jk_get_worker_host(props, p->name, host);
@@ -1306,8 +1194,8 @@
} else {
jk_log(l, JK_LOG_ERROR, "In jk_worker_t::validate, NULL parameters\n");
}
+
return JK_FALSE;
-#endif
}
@@ -1423,7 +1311,6 @@
}
JK_LEAVE_CS(&w->cs, rc);
if(i < w->ep_cache_sz) {
- jk_log(l, JK_LOG_DEBUG, "Return endpoint to pool\n");
return JK_TRUE;
}
}
@@ -1443,7 +1330,7 @@
int ajp_get_endpoint(jk_worker_t *pThis,
jk_endpoint_t **je,
jk_logger_t *l,
- int proto)
+ int proto)
{
jk_log(l, JK_LOG_DEBUG, "Into jk_worker_t::get_endpoint\n");
@@ -1466,7 +1353,6 @@
}
JK_LEAVE_CS(&aw->cs, rc);
if (ae) {
- jk_log(l, JK_LOG_DEBUG, "Reusing endpoint\n");
*je = &ae->endpoint;
return JK_TRUE;
}
@@ -1475,16 +1361,12 @@
ae = (ajp_endpoint_t *)malloc(sizeof(ajp_endpoint_t));
if (ae) {
-#ifndef CHANNEL
ae->sd = -1;
-#endif
ae->reuse = JK_FALSE;
jk_open_pool(&ae->pool, ae->buf, sizeof(ae->buf));
ae->worker = pThis->worker_private;
ae->endpoint.endpoint_private = ae;
- ae->proto = proto;
- ae->proto = proto;
- ae->endpoint.channelData = NULL;
+ ae->proto = proto;
ae->endpoint.service = ajp_service;
ae->endpoint.done = ajp_done;
*je = &ae->endpoint;
1.13 +2 -68 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.12
retrieving revision 1.13
diff -u -r1.12 -r1.13
--- jk_ajp_common.h 2001/11/20 16:58:46 1.12
+++ jk_ajp_common.h 2001/12/04 19:44:23 1.13
@@ -59,7 +59,7 @@
* Description: common stuff for bi-directional protocol ajp13/ajp14. *
* Author: Gal Shachor <sh...@il.ibm.com> *
* Author: Henri Gomez <hg...@slib.fr> *
- * Version: $Revision: 1.12 $ *
+ * Version: $Revision: 1.13 $ *
***************************************************************************/
#ifndef JK_AJP_COMMON_H
@@ -216,70 +216,7 @@
#define AJP_HEADER_SZ_LEN (2)
#define CHUNK_BUFFER_PAD (12)
-#define AJP13_PROTO 13
-#define AJP13_WS_HEADER 0x1234
-#define AJP13_SW_HEADER 0x4142 /* 'AB' */
-
-#define AJP13_DEF_HOST ("localhost")
-#define AJP13_DEF_PORT (8009)
-#define AJP13_READ_BUF_SIZE (8*1024)
-#define AJP13_DEF_CACHE_SZ (1)
-#define JK_INTERNAL_ERROR (-2)
-#define JK_FATAL_ERROR (-3)
-#define JK_CLIENT_ERROR (-4)
-#define AJP13_MAX_SEND_BODY_SZ (DEF_BUFFER_SZ - 6)
-/*
- * Message does not have a response (for example, JK_AJP13_END_RESPONSE)
- */
-#define JK_AJP13_ERROR -1
-/*
- * Message does not have a response (for example, JK_AJP13_END_RESPONSE)
- */
-#define JK_AJP13_NO_RESPONSE 0
-/*
- * Message have a response.
- */
-#define JK_AJP13_HAS_RESPONSE 1
-
-/*
- * Forward a request from the web server to the servlet container.
- */
-#define JK_AJP13_FORWARD_REQUEST (unsigned char)2
-
-/*
- * Write a body chunk from the servlet container to the web server
- */
-#define JK_AJP13_SEND_BODY_CHUNK (unsigned char)3
-
-/*
- * Send response headers from the servlet container to the web server.
- */
-#define JK_AJP13_SEND_HEADERS (unsigned char)4
-
-/*
- * Marks the end of response.
- */
-#define JK_AJP13_END_RESPONSE (unsigned char)5
-
-/*
- * Marks the end of response.
- */
-#define JK_AJP13_GET_BODY_CHUNK (unsigned char)6
-
-/*
- * Asks the container to shutdown
- */
-#define JK_AJP13_SHUTDOWN (unsigned char)7
-
-/*
- * Functions
- */
-int ajp13_marshal_shutdown_into_msgb(jk_msg_buf_t *msg,
- jk_pool_t *p,
- jk_logger_t *l);
-
-
struct jk_res_data {
int status;
const char *msg;
@@ -316,12 +253,9 @@
unsigned ep_cache_sz;
ajp_endpoint_t **ep_cache;
- /* PROTOCOL USED AJP13/AJP14
- XXX "version" - the API version to use
- */
- int proto;
+ int proto; /* PROTOCOL USED AJP13/AJP14 */
- jk_login_service_t *login;
+ jk_login_service_t *login;
jk_worker_t worker;
1.16 +1 -8 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.15
retrieving revision 1.16
diff -u -r1.15 -r1.16
--- jk_global.h 2001/11/26 19:34:00 1.15
+++ jk_global.h 2001/12/04 19:44:23 1.16
@@ -59,7 +59,7 @@
* Description: Global definitions and include files that should exist *
* anywhere *
* Author: Gal Shachor <sh...@il.ibm.com> *
- * Version: $Revision: 1.15 $ *
+ * Version: $Revision: 1.16 $ *
***************************************************************************/
#ifndef JK_GLOBAL_H
@@ -102,13 +102,6 @@
#include <sys/time.h>
#include <sys/ioctl.h>
#endif
-
-#ifdef WIN32
-/* define snprint to match windows version */
-#define snprintf _snprintf
-#endif
-
-
#ifdef __cplusplus
extern "C" {
1.7 +3 -11 jakarta-tomcat-connectors/jk/native/common/jk_jni_worker.c
Index: jk_jni_worker.c
===================================================================
RCS file: /home/cvs/jakarta-tomcat-connectors/jk/native/common/jk_jni_worker.c,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- jk_jni_worker.c 2001/11/17 06:00:24 1.6
+++ jk_jni_worker.c 2001/12/04 19:44:23 1.7
@@ -59,7 +59,7 @@
* Description: In process JNI worker *
* Author: Gal Shachor <sh...@il.ibm.com> *
* Based on: *
- * Version: $Revision: 1.6 $ *
+ * Version: $Revision: 1.7 $ *
***************************************************************************/
#if !defined(WIN32) && !defined(NETWARE)
@@ -69,6 +69,7 @@
#include <jni.h>
#include "jk_pool.h"
+#include "jk_jni_worker.h"
#include "jk_util.h"
#if defined LINUX && defined APACHE2_SIGHACK
@@ -81,15 +82,7 @@
#include <nwthread.h>
#include <nwadv.h>
#endif
-#include "jk_logger.h"
-#include "jk_service.h"
-int JK_METHOD jni_worker_factory(jk_worker_t **w,
- const char *name,
- jk_logger_t *l);
-
-
-
#ifndef JNI_VERSION_1_1
#define JNI_VERSION_1_1 0x00010001
#endif
@@ -557,13 +550,12 @@
}
if(p) {
- p->attached = JK_FALSE;
+ p->attached = JK_FALSE;
p->env = NULL;
p->worker = pThis->worker_private;
p->endpoint.endpoint_private = p;
p->endpoint.service = service;
p->endpoint.done = done;
- p->endpoint.channelData = NULL;
*pend = &p->endpoint;
return JK_TRUE;
1.7 +2 -9 jakarta-tomcat-connectors/jk/native/common/jk_lb_worker.c
Index: jk_lb_worker.c
===================================================================
RCS file: /home/cvs/jakarta-tomcat-connectors/jk/native/common/jk_lb_worker.c,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- jk_lb_worker.c 2001/11/17 06:00:24 1.6
+++ jk_lb_worker.c 2001/12/04 19:44:23 1.7
@@ -60,20 +60,14 @@
* several workers. *
* Author: Gal Shachor <sh...@il.ibm.com> *
* Based on: *
- * Version: $Revision: 1.6 $ *
+ * Version: $Revision: 1.7 $ *
***************************************************************************/
#include "jk_pool.h"
#include "jk_service.h"
#include "jk_util.h"
#include "jk_worker.h"
-#include "jk_logger.h"
-#include "jk_service.h"
-
-int JK_METHOD lb_worker_factory(jk_worker_t **w,
- const char *name,
- jk_logger_t *l);
-
+#include "jk_lb_worker.h"
/*
* The load balancing code in this
@@ -496,7 +490,6 @@
p->endpoint.endpoint_private = p;
p->endpoint.service = service;
p->endpoint.done = done;
- p->endpoint.channelData = NULL;
*pend = &p->endpoint;
return JK_TRUE;
1.9 +0 -43 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.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- jk_map.c 2001/11/26 17:12:38 1.8
+++ jk_map.c 2001/12/04 19:44:23 1.9
@@ -58,7 +58,7 @@
/***************************************************************************
* Description: General purpose map object *
* Author: Gal Shachor <sh...@il.ibm.com> *
- * Version: $Revision: 1.8 $ *
+ * Version: $Revision: 1.9 $ *
***************************************************************************/
#include "jk_global.h"
@@ -481,48 +481,5 @@
}
return rc;
-}
-
-
-/** Get a string property, using the worker's style
- for properties.
- Example worker.ajp13.host=localhost.
-*/
-char *map_getStrProp(jk_map_t *m,
- char *objType,
- char *objName,
- char *pname,
- char *def)
-{
- char buf[1024];
-
- if( m==NULL ||
- objType==NULL ||
- objName==NULL ||
- pname==NULL ) {
- return def;
- }
-
- sprintf(buf, "%s.%s.%s", objType, objName, pname);
- return map_get_string(m, buf, NULL);
-}
-
-int map_getIntProp(jk_map_t *m,
- char *objType,
- char *objName,
- char *pname,
- int def)
-{
- char buf[1024];
-
- if( m==NULL ||
- objType==NULL ||
- objName==NULL ||
- pname==NULL ) {
- return def;
- }
-
- sprintf(buf, "%s.%s.%s", objType, objName, pname);
- return map_get_int(m, buf, def);
}
1.6 +0 -16 jakarta-tomcat-connectors/jk/native/common/jk_map.h
Index: jk_map.h
===================================================================
RCS file: /home/cvs/jakarta-tomcat-connectors/jk/native/common/jk_map.h,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- jk_map.h 2001/11/26 17:12:38 1.5
+++ jk_map.h 2001/12/04 19:44:23 1.6
@@ -58,7 +58,7 @@
/***************************************************************************
* Description: Map object header file *
* Author: Gal Shachor <sh...@il.ibm.com> *
- * Version: $Revision: 1.5 $ *
+ * Version: $Revision: 1.6 $ *
***************************************************************************/
#ifndef JK_MAP_H
@@ -124,23 +124,7 @@
*/
char *map_replace_properties(const char *value, jk_map_t *m);
-/** Get a string property, using the worker's style
- for properties.
- Example worker.ajp13.host=localhost.
-*/
-char *map_getStrProp(jk_map_t *m,
- char *objType,
- char *objName,
- char *pname,
- char *def);
-
-int map_getIntProp(jk_map_t *m,
- char *objType,
- char *objName,
- char *pname,
- int def);
-
#ifdef __cplusplus
}
#endif /* __cplusplus */
1.10 +3 -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.9
retrieving revision 1.10
diff -u -r1.9 -r1.10
--- jk_msg_buff.c 2001/11/17 06:00:24 1.9
+++ jk_msg_buff.c 2001/12/04 19:44:23 1.10
@@ -60,11 +60,13 @@
* Author: Costin <co...@costin.dnt.ro> *
* Author: Gal Shachor <sh...@il.ibm.com> *
* Author: Henri Gomez <hg...@slib.fr> *
- * Version: $Revision: 1.9 $ *
+ * Version: $Revision: 1.10 $ *
***************************************************************************/
#include "jk_pool.h"
+#include "jk_connect.h"
#include "jk_util.h"
+#include "jk_sockbuf.h"
#include "jk_msg_buff.h"
#include "jk_logger.h"
1.12 +175 -4 jakarta-tomcat-connectors/jk/native/common/jk_service.h
Index: jk_service.h
===================================================================
RCS file: /home/cvs/jakarta-tomcat-connectors/jk/native/common/jk_service.h,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -r1.11 -r1.12
--- jk_service.h 2001/11/21 00:15:15 1.11
+++ jk_service.h 2001/12/04 19:44:23 1.12
@@ -63,7 +63,7 @@
* Author: Gal Shachor <sh...@il.ibm.com> *
* Author: Dan Milstein <da...@shore.net> *
* Author: Henri Gomez <hg...@slib.fr> *
- * Version: $Revision: 1.11 $ *
+ * Version: $Revision: 1.12 $ *
***************************************************************************/
#ifndef JK_SERVICE_H
@@ -74,8 +74,6 @@
#include "jk_logger.h"
#include "jk_pool.h"
#include "jk_uri_worker_map.h"
-#include "jk_worker.h"
-#include "jk_endpoint.h"
#ifdef __cplusplus
extern "C" {
@@ -106,8 +104,9 @@
struct jk_ws_service;
struct jk_endpoint;
struct jk_worker;
-struct jk_channel;
typedef struct jk_ws_service jk_ws_service_t;
+typedef struct jk_endpoint jk_endpoint_t;
+typedef struct jk_worker jk_worker_t;
/*
* The web server service 'class'. An instance of this class is created
@@ -263,6 +262,178 @@
const void *buffer,
unsigned len);
};
+
+/*
+ * The endpoint 'class', which represents one end of a connection to the
+ * servlet engine. Basically, supports nothing other than forwarding the
+ * request to the servlet engine. Endpoints can be persistent (as with
+ * ajp13/ajp14, where a single connection is reused many times), or can last for a
+ * single request (as with ajp12, where a new connection is created for
+ * every request).
+ *
+ * An endpoint for a given protocol is obtained by the web server plugin
+ * from a worker object for that protocol. See below for details.
+ *
+ * As with all the core jk classes, this is essentially an abstract base
+ * class which is implemented/extended by classes which are specific to a
+ * particular protocol. By using an abstract base class in this manner,
+ * plugins can be written for different servers (e.g. IIS, Apache) without
+ * the plugins having to worry about which protocol they are talking.
+ *
+ * This particular OO-in-C system uses a 'endpoint_private' pointer to
+ * point to the protocol-specific data/functions. So in the subclasses, the
+ * methods do most of their work by getting their hands on the
+ * endpoint_private pointer and then using that to get at the functions for
+ * their protocol.
+ *
+ * Try imagining this as a 'public abstract class', and the
+ * endpoint_private pointer as a sort of extra 'this' reference. Or
+ * imagine that you are seeing the internal vtables of your favorite OO
+ * language. Whatever works for you.
+ *
+ * See jk_ajp13_worker.c/jk_ajp14_worker.c and jk_ajp12_worker.c for examples.
+ */
+struct jk_endpoint {
+
+ /*
+ * A 'this' pointer which is used by the subclasses of this class to
+ * point to data/functions which are specific to a given protocol
+ * (e.g. ajp12 or ajp13 or ajp14).
+ */
+ void *endpoint_private;
+
+ /*
+ * Forward a request to the servlet engine. The request is described
+ * by the jk_ws_service_t object. I'm not sure exactly how
+ * is_recoverable_error is being used.
+ */
+ int (JK_METHOD *service)(jk_endpoint_t *e,
+ jk_ws_service_t *s,
+ jk_logger_t *l,
+ int *is_recoverable_error);
+
+ /*
+ * Called when this particular endpoint has finished processing a
+ * request. For some protocols (e.g. ajp12), this frees the memory
+ * associated with the endpoint. For others (e.g. ajp13/ajp14), this can
+ * return the endpoint to a cache of already opened endpoints.
+ *
+ * Note that the first argument is *not* a 'this' pointer, but is
+ * rather a pointer to a 'this' pointer. This is necessary, because
+ * we may need to free this object.
+ */
+ int (JK_METHOD *done)(jk_endpoint_t **p,
+ jk_logger_t *l);
+};
+
+/*
+ * The worker 'class', which represents something to which the web server
+ * can delegate requests.
+ *
+ * This can mean communicating with a particular servlet engine instance,
+ * using a particular protocol. A single web server instance may have
+ * multiple workers communicating with a single servlet engine (it could be
+ * using ajp12 for some requests and ajp13/ajp14 for others). Or, a single web
+ * server instance could have multiple workers communicating with different
+ * servlet engines using the same protocol (it could be load balancing
+ * among many engines, using ajp13/ajp14 for all communication).
+ *
+ * There is also a load balancing worker (jk_lb_worker.c), which itself
+ * manages a group of workers.
+ *
+ * Web servers are configured to forward requests to a given worker. To
+ * handle those requests, the worker's get_endpoint method is called, and
+ * then the service() method of that endpoint is called.
+ *
+ * As with all the core jk classes, this is essentially an abstract base
+ * class which is implemented/extended by classes which are specific to a
+ * particular protocol (or request-handling system). By using an abstract
+ * base class in this manner, plugins can be written for different servers
+ * (e.g. IIS, Apache) without the plugins having to worry about which
+ * protocol they are talking.
+ *
+ * This particular OO-in-C system uses a 'worker_private' pointer to
+ * point to the protocol-specific data/functions. So in the subclasses, the
+ * methods do most of their work by getting their hands on the
+ * worker_private pointer and then using that to get at the functions for
+ * their protocol.
+ *
+ * Try imagining this as a 'public abstract class', and the
+ * worker_private pointer as a sort of extra 'this' reference. Or
+ * imagine that you are seeing the internal vtables of your favorite OO
+ * language. Whatever works for you.
+ *
+ * See jk_ajp14_worker.c, jk_ajp13_worker.c and jk_ajp12_worker.c for examples.
+ */
+struct jk_worker {
+
+ /*
+ * A 'this' pointer which is used by the subclasses of this class to
+ * point to data/functions which are specific to a given protocol
+ * (e.g. ajp12 or ajp13 or ajp14).
+ */
+ void *worker_private;
+
+ /*
+ * For all of the below (except destroy), the first argument is
+ * essentially a 'this' pointer.
+ */
+
+ /*
+ * Given a worker which is in the process of being created, and a list
+ * of configuration options (or 'properties'), check to see if it the
+ * options are. This will always be called before the init() method.
+ * The init/validate distinction is a bit hazy to me.
+ * See jk_ajp13_worker.c/jk_ajp14_worker.c and jk_worker.c->wc_create_worker()
+ */
+ int (JK_METHOD *validate)(jk_worker_t *w,
+ jk_map_t *props,
+ jk_worker_env_t *we,
+ jk_logger_t *l);
+
+ /*
+ * Do whatever initialization needs to be done to start this worker up.
+ * Configuration options are passed in via the props parameter.
+ */
+ int (JK_METHOD *init)(jk_worker_t *w,
+ jk_map_t *props,
+ jk_worker_env_t *we,
+ jk_logger_t *l);
+
+
+ /*
+ * Obtain an endpoint to service a particular request. A pointer to
+ * the endpoint is stored in pend.
+ */
+ int (JK_METHOD *get_endpoint)(jk_worker_t *w,
+ jk_endpoint_t **pend,
+ jk_logger_t *l);
+
+ /*
+ * Shutdown this worker. The first argument is not a 'this' pointer,
+ * but rather a pointer to 'this', so that the object can be free'd (I
+ * think -- though that doesn't seem to be happening. Hmmm).
+ */
+ int (JK_METHOD *destroy)(jk_worker_t **w,
+ jk_logger_t *l);
+};
+
+/*
+ * Essentially, an abstract base class (or factory class) with a single
+ * method -- think of it as createWorker() or the Factory Method Design
+ * Pattern. There is a different worker_factory function for each of the
+ * different types of workers. The set of all these functions is created
+ * at startup from the list in jk_worker_list.h, and then the correct one
+ * is chosen in jk_worker.c->wc_create_worker(). See jk_worker.c and
+ * jk_ajp13_worker.c/jk_ajp14_worker.c for examples.
+ *
+ * This allows new workers to be written without modifing the plugin code
+ * for the various web servers (since the only link is through
+ * jk_worker_list.h).
+ */
+typedef int (JK_METHOD *worker_factory)(jk_worker_t **w,
+ const char *name,
+ jk_logger_t *l);
#ifdef __cplusplus
}
1.12 +15 -66 jakarta-tomcat-connectors/jk/native/common/jk_uri_worker_map.c
Index: jk_uri_worker_map.c
===================================================================
RCS file: /home/cvs/jakarta-tomcat-connectors/jk/native/common/jk_uri_worker_map.c,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -r1.11 -r1.12
--- jk_uri_worker_map.c 2001/11/16 22:37:13 1.11
+++ jk_uri_worker_map.c 2001/12/04 19:44:23 1.12
@@ -67,7 +67,7 @@
* servlet container. *
* *
* Author: Gal Shachor <sh...@il.ibm.com> *
- * Version: $Revision: 1.11 $ *
+ * Version: $Revision: 1.12 $ *
***************************************************************************/
#include "jk_pool.h"
@@ -77,7 +77,6 @@
#define MATCH_TYPE_EXACT (0)
#define MATCH_TYPE_CONTEXT (1)
#define MATCH_TYPE_SUFFIX (2)
-#define MATCH_TYPE_GENERAL_SUFFIX (3) /* match all URIs of the form *ext */
struct uri_worker_record {
/* Original uri for logging */
@@ -118,13 +117,7 @@
unsigned capacity;
};
-int uri_worker_map_size(jk_uri_worker_map_t *uw_map ) {
- if( uw_map == NULL )
- return 0;
- return uw_map->size;
-}
-
/*
* We are now in a security nightmare, it maybe that somebody sent
* us a uri that looks like /top-secret.jsp. and the web server will
@@ -290,31 +283,18 @@
uwr->suffix = asterisk + 3;
uwr->match_type = MATCH_TYPE_SUFFIX;
jk_log(l, JK_LOG_DEBUG,
- "Into jk_uri_worker_map_t::uri_worker_map_open, "
- "suffix rule %s.%s=%s was added\n",
- uri, asterisk + 3, worker);
- } else if ('\0' != asterisk[2]) {
- /* general suffix rule */
- asterisk[1] = '\0';
- uwr->worker_name = worker;
- uwr->context = uri;
- uwr->suffix = asterisk + 2;
- uwr->match_type = MATCH_TYPE_GENERAL_SUFFIX;
- jk_log(l, JK_LOG_DEBUG,
- "Into jk_uri_worker_map_t::uri_worker_map_open, "
- "general suffix rule %s*%s=%s was added\n",
- uri, asterisk + 2, worker);
- } else {
- /* context based */
- asterisk[1] = '\0';
- uwr->worker_name = worker;
- uwr->context = uri;
- uwr->suffix = NULL;
- uwr->match_type = MATCH_TYPE_CONTEXT;
- jk_log(l, JK_LOG_DEBUG,
- "Into jk_uri_worker_map_t::uri_worker_map_open, "
- "match rule %s=%s was added\n",
- uri, worker);
+ "Into jk_uri_worker_map_t::uri_worker_map_open, suffix rule %s.%s=%s was added\n",
+ uri, asterisk + 3, worker);
+ } else {
+ /* context based */
+ asterisk[1] = '\0';
+ uwr->worker_name = worker;
+ uwr->context = uri;
+ uwr->suffix = NULL;
+ uwr->match_type = MATCH_TYPE_CONTEXT;
+ jk_log(l, JK_LOG_DEBUG,
+ "Into jk_uri_worker_map_t::uri_worker_map_open, match rule %s=%s was added\n",
+ uri, worker);
}
} else {
/* Something like : JkMount /servlets/exampl* ajp13 */
@@ -416,18 +396,6 @@
return rc;
}
-/* returns the index of the last occurrence of the 'ch' character
- if ch=='\0' returns the length of the string str */
-int last_index_of(const char *str,char ch)
-{
- const char *str_minus_one=str-1;
- const char *s=str+strlen(str);
- while(s!=str_minus_one && ch!=*s) {
- --s;
- }
- return (s-str);
-}
-
int uri_worker_map_close(jk_uri_worker_map_t *uw_map,
jk_logger_t *l)
{
@@ -450,9 +418,6 @@
const char *uri,
jk_logger_t *l)
{
- if( uri_worker_map_size( uw_map ) <= 0 )
- return NULL;
-
jk_log(l, JK_LOG_DEBUG,
"Into jk_uri_worker_map_t::map_uri_to_worker\n");
@@ -485,8 +450,7 @@
if(strlen(uri) == uwr->ctxt_len) {
jk_log(l,
JK_LOG_DEBUG,
- "jk_uri_worker_map_t::map_uri_to_worker, "
- "Found an exact match %s -> %s\n",
+ "jk_uri_worker_map_t::map_uri_to_worker, Found an exact match %s -> %s\n",
uwr->worker_name,
uwr->context );
jk_reset_pool(&uw_map->tp);
@@ -496,26 +460,11 @@
if(uwr->ctxt_len > longest_match) {
jk_log(l,
JK_LOG_DEBUG,
- "jk_uri_worker_map_t::map_uri_to_worker, "
- "Found a context match %s -> %s\n",
+ "jk_uri_worker_map_t::map_uri_to_worker, Found a context match %s -> %s\n",
uwr->worker_name,
uwr->context );
longest_match = uwr->ctxt_len;
best_match = i;
- }
- } else if(MATCH_TYPE_GENERAL_SUFFIX == uwr->match_type) {
- int suffix_start=last_index_of(uri,uwr->suffix[0]);
- if (suffix_start>=0 && 0==strcmp(uri+suffix_start,uwr->suffix)) {
- if(uwr->ctxt_len >= longest_match) {
- jk_log(l,
- JK_LOG_DEBUG,
- "jk_uri_worker_map_t::map_uri_to_worker, "
- "Found a general suffix match %s -> *%s\n",
- uwr->worker_name,
- uwr->suffix );
- longest_match = uwr->ctxt_len;
- best_match = i;
- }
}
} else /* suffix match */ {
int suffix_start;
1.5 +0 -3 jakarta-tomcat-connectors/jk/native/common/jk_uri_worker_map.h
Index: jk_uri_worker_map.h
===================================================================
RCS file: /home/cvs/jakarta-tomcat-connectors/jk/native/common/jk_uri_worker_map.h,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- jk_uri_worker_map.h 2001/11/16 22:37:13 1.4
+++ jk_uri_worker_map.h 2001/12/04 19:44:23 1.5
@@ -58,7 +58,7 @@
/***************************************************************************
* Description: URI to worker mapper header file *
* Author: Gal Shachor <sh...@il.ibm.com> *
- * Version: $Revision: 1.4 $ *
+ * Version: $Revision: 1.5 $ *
***************************************************************************/
#ifndef JK_URI_WORKER_MAP_H
@@ -91,9 +91,6 @@
char *puri,
char *pworker,
jk_logger_t *l);
-
-int uri_worker_map_size(jk_uri_worker_map_t *uw_map );
-
int uri_worker_map_close(jk_uri_worker_map_t *uw_map,
jk_logger_t *l);
1.11 +200 -3 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.10
retrieving revision 1.11
diff -u -r1.10 -r1.11
--- jk_util.c 2001/11/26 17:11:40 1.10
+++ jk_util.c 2001/12/04 19:44:23 1.11
@@ -59,11 +59,12 @@
* Description: Utility functions (mainly configuration) *
* Author: Gal Shachor <sh...@il.ibm.com> *
* Author: Henri Gomez <hg...@slib.fr> *
- * Version: $Revision: 1.10 $ *
+ * Version: $Revision: 1.11 $ *
***************************************************************************/
#include "jk_util.h"
+#include "jk_ajp12_worker.h"
#define SYSPROPS_OF_WORKER ("sysprops")
#define STDERR_OF_WORKER ("stderr")
@@ -83,13 +84,192 @@
#define LOAD_FACTOR_OF_WORKER ("lbfactor")
#define BALANCED_WORKERS ("balanced_workers")
#define WORKER_AJP12 ("ajp12")
-#define DEFAULT_WORKER_TYPE ("ajp13")
+#define DEFAULT_WORKER_TYPE JK_AJP12_WORKER_NAME
#define SECRET_KEY_OF_WORKER ("secretkey")
-#define DEFAULT_WORKER ("ajp13")
+#define DEFAULT_WORKER JK_AJP12_WORKER_NAME
#define WORKER_LIST_PROPERTY_NAME ("worker.list")
#define DEFAULT_LB_FACTOR (1.0)
+#define LOG_FORMAT ("log_format")
+#define HUGE_BUFFER_SIZE (8*1024)
+#define LOG_LINE_SIZE (1024)
+
+struct file_logger {
+ FILE *logfile;
+};
+typedef struct file_logger file_logger_t;
+
+/*
+ * define the log format, we're using by default the one from error.log
+ *
+ * [Mon Mar 26 19:44:48 2001] [jk_uri_worker_map.c (155)]: Into jk_uri_worker_map_t::uri_worker_map_alloc
+ * log format used by apache in error.log
+ */
+#ifndef JK_TIME_FORMAT
+#define JK_TIME_FORMAT "[%a %b %d %H:%M:%S %Y] "
+#endif
+
+const char * jk_log_fmt = JK_TIME_FORMAT;
+
+static void set_time_str(char * str, int len)
+{
+ time_t t = time(NULL);
+ struct tm *tms;
+
+ tms = localtime(&t);
+ strftime(str, len, jk_log_fmt, tms);
+}
+
+static int JK_METHOD log_to_file(jk_logger_t *l,
+ int level,
+ const char *what)
+{
+ if(l && l->level <= level && l->logger_private && what) {
+ unsigned sz = strlen(what);
+ if(sz) {
+ file_logger_t *p = l->logger_private;
+ fwrite(what, 1, sz, p->logfile);
+ /* [V] Flush the dam' thing! */
+ fflush(p->logfile);
+ }
+
+ return JK_TRUE;
+ }
+
+ return JK_FALSE;
+}
+
+int jk_parse_log_level(const char *level)
+{
+ if(0 == strcasecmp(level, JK_LOG_INFO_VERB)) {
+ return JK_LOG_INFO_LEVEL;
+ }
+
+ if(0 == strcasecmp(level, JK_LOG_ERROR_VERB)) {
+ return JK_LOG_ERROR_LEVEL;
+ }
+
+ if(0 == strcasecmp(level, JK_LOG_EMERG_VERB)) {
+ return JK_LOG_EMERG_LEVEL;
+ }
+
+ return JK_LOG_DEBUG_LEVEL;
+}
+
+int jk_open_file_logger(jk_logger_t **l,
+ const char *file,
+ int level)
+{
+ if(l && file) {
+ jk_logger_t *rc = (jk_logger_t *)malloc(sizeof(jk_logger_t));
+ file_logger_t *p = (file_logger_t *)malloc(sizeof(file_logger_t));
+ if(rc && p) {
+ rc->log = log_to_file;
+ rc->level = level;
+ rc->logger_private = p;
+ p->logfile = fopen(file, "a+");
+ if(p->logfile) {
+ *l = rc;
+ return JK_TRUE;
+ }
+ }
+ if(rc) {
+ free(rc);
+ }
+ if(p) {
+ free(p);
+ }
+
+ *l = NULL;
+ }
+ return JK_FALSE;
+}
+
+int jk_close_file_logger(jk_logger_t **l)
+{
+ if(l && *l) {
+ file_logger_t *p = (*l)->logger_private;
+ fflush(p->logfile);
+ fclose(p->logfile);
+ free(p);
+ free(*l);
+ *l = NULL;
+
+ return JK_TRUE;
+ }
+ return JK_FALSE;
+}
+
+int jk_log(jk_logger_t *l,
+ const char *file,
+ int line,
+ int level,
+ const char *fmt, ...)
+{
+ int rc = 0;
+ if(!l || !file || !fmt) {
+ return -1;
+ }
+
+ if(l->level <= level) {
+#ifdef NETWARE
+/* On NetWare, this can get called on a thread that has a limited stack so */
+/* we will allocate and free the temporary buffer in this function */
+ char *buf;
+#else
+ char buf[HUGE_BUFFER_SIZE];
+#endif
+ char *f = (char *)(file + strlen(file) - 1);
+ va_list args;
+ int used = 0;
+
+ while(f != file && '\\' != *f && '/' != *f) {
+ f--;
+ }
+ if(f != file) {
+ f++;
+ }
+
+#ifdef WIN32
+ set_time_str(buf, HUGE_BUFFER_SIZE);
+ used = strlen(buf);
+ used += _snprintf(&buf[used], HUGE_BUFFER_SIZE, " [%s (%d)]: ", f, line);
+#elif defined(NETWARE) /* until we get a snprintf function */
+ buf = (char *) malloc(HUGE_BUFFER_SIZE);
+ if (NULL == buf)
+ return -1;
+
+ set_time_str(buf, HUGE_BUFFER_SIZE);
+ used = strlen(buf);
+ used += sprintf(&buf[used], " [%s (%d)]: ", f, line);
+#else
+ set_time_str(buf, HUGE_BUFFER_SIZE);
+ used = strlen(buf);
+ used += snprintf(&buf[used], HUGE_BUFFER_SIZE, " [%s (%d)]: ", f, line);
+#endif
+ if(used < 0) {
+ return 0; /* [V] not sure what to return... */
+ }
+
+ va_start(args, fmt);
+#ifdef WIN32
+ rc = _vsnprintf(buf + used, HUGE_BUFFER_SIZE - used, fmt, args);
+#elif defined(NETWARE) /* until we get a vsnprintf function */
+ rc = vsprintf(buf + used, fmt, args);
+#else
+ rc = vsnprintf(buf + used, HUGE_BUFFER_SIZE - used, fmt, args);
+#endif
+ va_end(args);
+ l->log(l, level, buf);
+#ifdef NETWARE
+ free(buf);
+#endif
+ }
+
+ return rc;
+}
+
char *jk_get_worker_type(jk_map_t *m,
const char *wname)
{
@@ -222,6 +402,11 @@
return JK_FALSE;
}
+void jk_set_log_format(const char * logformat)
+{
+ jk_log_fmt = (logformat) ? logformat : JK_TIME_FORMAT;
+}
+
double jk_get_lb_factor(jk_map_t *m,
const char *wname)
{
@@ -369,6 +554,18 @@
}
}
+ return JK_FALSE;
+}
+
+
+int jk_file_exists(const char *f)
+{
+ if(f) {
+ struct stat st;
+ if((0 == stat(f, &st)) && (st.st_mode & S_IFREG)) {
+ return JK_TRUE;
+ }
+ }
return JK_FALSE;
}
1.11 +21 -14 jakarta-tomcat-connectors/jk/native/common/jk_worker.c
Index: jk_worker.c
===================================================================
RCS file: /home/cvs/jakarta-tomcat-connectors/jk/native/common/jk_worker.c,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -r1.10 -r1.11
--- jk_worker.c 2001/11/21 00:15:15 1.10
+++ jk_worker.c 2001/12/04 19:44:23 1.11
@@ -60,22 +60,17 @@
* Description: Workers controller *
* Author: Gal Shachor <sh...@il.ibm.com> *
* Author: Henri Gomez <hg...@slib.fr> *
- * Version: $Revision: 1.10 $ *
+ * Version: $Revision: 1.11 $ *
***************************************************************************/
-/* #define _PLACE_WORKER_LIST_HERE */
-/* #include "jk_worker_list.h" */
-#include "jk_env.h"
+#define _PLACE_WORKER_LIST_HERE
+#include "jk_worker_list.h"
#include "jk_worker.h"
#include "jk_util.h"
-/* from jk_worker_list */
-static jk_map_t *worker_map;
-
-
static void close_workers(jk_logger_t *l);
-/* static worker_factory get_factory_for(char *type); */
+static worker_factory get_factory_for(char *type);
static int build_worker_map(jk_map_t *init_data,
char **worker_list,
@@ -113,7 +108,7 @@
we->num_of_workers=num_of_workers;
we->first_worker=worker_list[0];
- jk_log(l, JK_LOG_DEBUG, "wc_open, done %d %s\n", num_of_workers, worker_list[0]);
+ jk_log(l, JK_LOG_DEBUG, "wc_open, done %d\n", num_of_workers);
return JK_TRUE;
}
@@ -154,9 +149,7 @@
if(rc) {
char *type = jk_get_worker_type(init_data, name);
- jk_env_t *env=jk_env_getEnv( NULL );
- /* worker_factory fac = get_factory_for(type); */
- worker_factory fac = (worker_factory)env->getFactory(env, "worker", type );
+ worker_factory fac = get_factory_for(type);
jk_worker_t *w = NULL;
*rc = NULL;
@@ -191,7 +184,7 @@
}
*rc = w;
- jk_log(l, JK_LOG_DEBUG, "wc_create_worker, done\n");
+ jk_log(l, JK_LOG_DEBUG, "wc_create_worker, done\n");
return JK_TRUE;
}
@@ -256,4 +249,18 @@
jk_log(l, JK_LOG_DEBUG, "build_worker_map, done\n");
return JK_TRUE;
+}
+
+static worker_factory get_factory_for(char *type)
+{
+ worker_factory_record_t *factory = &worker_factories[0];
+ while(factory->name) {
+ if(0 == strcmp(factory->name, type)) {
+ return factory->fac;
+ }
+
+ factory ++;
+ }
+
+ return NULL;
}
1.7 +2 -124 jakarta-tomcat-connectors/jk/native/common/jk_worker.h
Index: jk_worker.h
===================================================================
RCS file: /home/cvs/jakarta-tomcat-connectors/jk/native/common/jk_worker.h,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- jk_worker.h 2001/11/21 00:15:15 1.6
+++ jk_worker.h 2001/12/04 19:44:23 1.7
@@ -58,7 +58,7 @@
/***************************************************************************
* Description: Workers controller header file *
* Author: Gal Shachor <sh...@il.ibm.com> *
- * Version: $Revision: 1.6 $ *
+ * Version: $Revision: 1.7 $ *
***************************************************************************/
#ifndef JK_WORKER_H
@@ -66,7 +66,6 @@
#include "jk_logger.h"
#include "jk_service.h"
-#include "jk_endpoint.h"
#include "jk_map.h"
#include "jk_uri_worker_map.h"
@@ -74,129 +73,8 @@
extern "C" {
#endif /* __cplusplus */
-struct jk_worker;
-struct jk_endpoint;
-struct jk_worker_env;
-typedef struct jk_worker jk_worker_t;
-
-/*
- * The worker 'class', which represents something to which the web server
- * can delegate requests.
- *
- * This can mean communicating with a particular servlet engine instance,
- * using a particular protocol. A single web server instance may have
- * multiple workers communicating with a single servlet engine (it could be
- * using ajp12 for some requests and ajp13/ajp14 for others). Or, a single web
- * server instance could have multiple workers communicating with different
- * servlet engines using the same protocol (it could be load balancing
- * among many engines, using ajp13/ajp14 for all communication).
- *
- * There is also a load balancing worker (jk_lb_worker.c), which itself
- * manages a group of workers.
- *
- * Web servers are configured to forward requests to a given worker. To
- * handle those requests, the worker's get_endpoint method is called, and
- * then the service() method of that endpoint is called.
- *
- * As with all the core jk classes, this is essentially an abstract base
- * class which is implemented/extended by classes which are specific to a
- * particular protocol (or request-handling system). By using an abstract
- * base class in this manner, plugins can be written for different servers
- * (e.g. IIS, Apache) without the plugins having to worry about which
- * protocol they are talking.
- *
- * This particular OO-in-C system uses a 'worker_private' pointer to
- * point to the protocol-specific data/functions. So in the subclasses, the
- * methods do most of their work by getting their hands on the
- * worker_private pointer and then using that to get at the functions for
- * their protocol.
- *
- * Try imagining this as a 'public abstract class', and the
- * worker_private pointer as a sort of extra 'this' reference. Or
- * imagine that you are seeing the internal vtables of your favorite OO
- * language. Whatever works for you.
- *
- * See jk_ajp14_worker.c, jk_ajp13_worker.c and jk_ajp12_worker.c for examples.
- */
-struct jk_worker {
-
- /*
- * A 'this' pointer which is used by the subclasses of this class to
- * point to data/functions which are specific to a given protocol
- * (e.g. ajp12 or ajp13 or ajp14).
- */
- void *worker_private;
-
- /* XXX Add name and all other common properties !!!
- */
-
- /** Communication channle used by the worker
- */
- struct jk_channel *channel;
-
- /*
- * For all of the below (except destroy), the first argument is
- * essentially a 'this' pointer.
- */
-
- /*
- * Given a worker which is in the process of being created, and a list
- * of configuration options (or 'properties'), check to see if it the
- * options are. This will always be called before the init() method.
- * The init/validate distinction is a bit hazy to me.
- * See jk_ajp13_worker.c/jk_ajp14_worker.c and jk_worker.c->wc_create_worker()
- */
- int (JK_METHOD *validate)(jk_worker_t *w,
- jk_map_t *props,
- struct jk_worker_env *we,
- jk_logger_t *l);
-
- /*
- * Do whatever initialization needs to be done to start this worker up.
- * Configuration options are passed in via the props parameter.
- */
- int (JK_METHOD *init)(jk_worker_t *w,
- jk_map_t *props,
- struct jk_worker_env *we,
- jk_logger_t *l);
-
-
- /*
- * Obtain an endpoint to service a particular request. A pointer to
- * the endpoint is stored in pend.
- */
- int (JK_METHOD *get_endpoint)(jk_worker_t *w,
- struct jk_endpoint **pend,
- jk_logger_t *l);
-
- /*
- * Shutdown this worker. The first argument is not a 'this' pointer,
- * but rather a pointer to 'this', so that the object can be free'd (I
- * think -- though that doesn't seem to be happening. Hmmm).
- */
- int (JK_METHOD *destroy)(jk_worker_t **w,
- jk_logger_t *l);
-};
-
-/*
- * Essentially, an abstract base class (or factory class) with a single
- * method -- think of it as createWorker() or the Factory Method Design
- * Pattern. There is a different worker_factory function for each of the
- * different types of workers. The set of all these functions is created
- * at startup from the list in jk_worker_list.h, and then the correct one
- * is chosen in jk_worker.c->wc_create_worker(). See jk_worker.c and
- * jk_ajp13_worker.c/jk_ajp14_worker.c for examples.
- *
- * This allows new workers to be written without modifing the plugin code
- * for the various web servers (since the only link is through
- * jk_worker_list.h).
- */
-typedef int (JK_METHOD *worker_factory)(jk_worker_t **w,
- const char *name,
- jk_logger_t *l);
-
int wc_open(jk_map_t *init_data,
- struct jk_worker_env *we,
+ jk_worker_env_t *we,
jk_logger_t *l);
void wc_close(jk_logger_t *l);
@@ -207,7 +85,7 @@
int wc_create_worker(const char *name,
jk_map_t *init_data,
jk_worker_t **rc,
- struct jk_worker_env *we,
+ jk_worker_env_t *we,
jk_logger_t *l);
1.7 +9 -20 jakarta-tomcat-connectors/jk/native/common/list.mk.in
Index: list.mk.in
===================================================================
RCS file: /home/cvs/jakarta-tomcat-connectors/jk/native/common/list.mk.in,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- list.mk.in 2001/11/26 17:08:48 1.6
+++ list.mk.in 2001/12/04 19:44:23 1.7
@@ -1,21 +1,10 @@
## Object needed for mod_jk for Apache-1.3
-APACHE_OBJECTS= ${JK}jk_connect${OEXT} \
- ${JK}jk_msg_buff${OEXT} \
- ${JK}jk_util${OEXT} \
- ${JK}jk_pool${OEXT} \
- ${JK}jk_worker${OEXT} \
- ${JK}jk_lb_worker${OEXT} \
- ${JK}jk_map${OEXT} \
- ${JK}jk_uri_worker_map${OEXT} \
- ${JK}jk_ajp14${OEXT} \
- ${JK}jk_ajp14_worker${OEXT} \
- ${JK}jk_channel_socket${OEXT} \
- ${JK}jk_registry${OEXT} \
- ${JK}jk_env${OEXT} \
- ${JK}jk_handler_discovery${OEXT} \
- ${JK}jk_handler_logon${OEXT} \
- ${JK}jk_logger${OEXT} \
- ${JK}jk_md5${OEXT} \
- @JK_JNI_WORKER@ \
- ${JK}jk_ajp_common${OEXT} \
- ${JK}jk_context${OEXT}
+APACHE_OBJECTS= ${JK}jk_ajp12_worker${OEXT} ${JK}jk_connect${OEXT} \
+ ${JK}jk_msg_buff${OEXT} ${JK}jk_util${OEXT} \
+ ${JK}jk_ajp13${OEXT} ${JK}jk_pool${OEXT} \
+ ${JK}jk_worker${OEXT} ${JK}jk_ajp13_worker${OEXT} \
+ ${JK}jk_lb_worker${OEXT} ${JK}jk_sockbuf${OEXT} \
+ ${JK}jk_map${OEXT} ${JK}jk_uri_worker_map${OEXT} \
+ ${JK}jk_ajp14${OEXT} ${JK}jk_ajp14_worker${OEXT} \
+ ${JK}jk_md5${OEXT} @JK_JNI_WORKER@ \
+ ${JK}jk_ajp_common${OEXT} ${JK}jk_context${OEXT}
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>