📄 jk_worker_ajp13.c
字号:
/* ========================================================================= * * * * The Apache Software License, Version 1.1 * * * * Copyright (c) 1999-2002 The Apache Software Foundation. * * All rights reserved. * * * * ========================================================================= * * * * Redistribution and use in source and binary forms, with or without modi- * * fication, are permitted provided that the following conditions are met: * * * * 1. Redistributions of source code must retain the above copyright notice * * notice, this list of conditions and the following disclaimer. * * * * 2. Redistributions in binary form must reproduce the above copyright * * notice, this list of conditions and the following disclaimer in the * * documentation and/or other materials provided with the distribution. * * * * 3. The end-user documentation included with the redistribution, if any, * * must include the following acknowlegement: * * * * "This product includes software developed by the Apache Software * * Foundation <http://www.apache.org/>." * * * * Alternately, this acknowlegement may appear in the software itself, if * * and wherever such third-party acknowlegements normally appear. * * * * 4. The names "The Jakarta Project", "Jk", and "Apache Software * * Foundation" must not be used to endorse or promote products derived * * from this software without prior written permission. For written * * permission, please contact <apache@apache.org>. * * * * 5. Products derived from this software may not be called "Apache" nor may * * "Apache" appear in their names without prior written permission of the * * Apache Software Foundation. * * * * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED WARRANTIES * * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY * * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL * * THE APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY * * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN * * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * * POSSIBILITY OF SUCH DAMAGE. * * * * ========================================================================= * * * * This software consists of voluntary contributions made by many indivi- * * duals on behalf of the Apache Software Foundation. For more information * * on the Apache Software Foundation, please see <http://www.apache.org/>. * * * * ========================================================================= *//** * Description: AJP13 next generation Bi-directional protocol. * Backward compatible with Ajp13 * Author: Henri Gomez <hgomez@slib.fr> * Author: Costin <costin@costin.dnt.ro> * Author: Gal Shachor <shachor@il.ibm.com> */#include "jk_global.h"#include "jk_pool.h"#include "jk_channel.h"#include "jk_msg.h"#include "jk_logger.h"#include "jk_handler.h"#include "jk_service.h"#include "jk_env.h"#include "jk_objCache.h"#include "jk_requtil.h"#include "jk_registry.h"#define AJP_DEF_RETRY_ATTEMPTS (2)#define AJP13_PROTO 13#define AJP13_DEF_HOST ("localhost")#define AJP13_DEF_PORT (8009)/* -------------------- Impl -------------------- */static char *jk2_worker_ajp13_getAttributeInfo[]={ "lb_factor", "lb_value", "route", "errorState", "graceful", "epCount", "errorTime", NULL };static char *jk2_worker_ajp13_multiValueInfo[]={"group", NULL };static char *jk2_worker_ajp13_setAttributeInfo[]={"debug", "channel", "route", "lb_factor", "level", NULL };static void * JK_METHOD jk2_worker_ajp13_getAttribute(jk_env_t *env, jk_bean_t *bean, char *name ) { jk_worker_t *worker=(jk_worker_t *)bean->object; if( strcmp( name, "channelName" )==0 ) { if( worker->channel != NULL ) return worker->channel->mbean->name; else return worker->channelName; } else if (strcmp( name, "route" )==0 ) { return worker->route; } else if (strcmp( name, "errorTime" )==0 ) { char *buf=env->tmpPool->calloc( env, env->tmpPool, 20 ); sprintf( buf, "%d", worker->error_time ); return buf; } else if (strcmp( name, "lb_value" )==0 ) { char *buf=env->tmpPool->calloc( env, env->tmpPool, 20 ); sprintf( buf, "%d", worker->lb_value ); return buf; } else if (strcmp( name, "lb_factor" )==0 ) { char *buf=env->tmpPool->calloc( env, env->tmpPool, 20 ); sprintf( buf, "%d", worker->lb_factor ); return buf; } else if (strcmp( name, "errorState" )==0 ) { if( worker->in_error_state ) return "Y"; else return "N"; } else if (strcmp( name, "graceful" )==0 ) { if( worker->mbean->disabled != 0) return "Y"; else return "N"; } else if (strcmp( name, "epCount" )==0 ) { char *result; if( worker->endpointCache==NULL ) return "0"; result=env->tmpPool->calloc( env, env->tmpPool, 6 ); sprintf( result, "%d", worker->endpointCache->count ); return result; } else { return NULL; }}/* * Initialize the worker */static int JK_METHOD jk2_worker_ajp13_setAttribute(jk_env_t *env, jk_bean_t *mbean, char *name, void *valueP ){ jk_worker_t *ajp13=(jk_worker_t *)mbean->object; char *value=(char *)valueP; if( strcmp( name, "secretkey" )==0 ) { ajp13->secret = value; } else if( strcmp( name, "tomcatId" )==0 ) { ajp13->route=value; } else if( strcmp( name, "route" )==0 ) { ajp13->route=value; } else if( strcmp( name, "group" )==0 ) { ajp13->groups->add( env, ajp13->groups, value, ajp13 ); } else if( strcmp( name, "lb_factor" )==0 ) { ajp13->lb_factor=atoi( value ); } else if( strcmp( name, "level" )==0 ) { ajp13->level=atoi( value ); } else if( strcmp( name, "channel" )==0 ) { ajp13->channelName=value; } else if( strcmp( name, "max_connections" )==0 ) { ajp13->maxEndpoints=atoi(value); } else { return JK_ERR; } return JK_OK;}#define JK_AJP13_PING (unsigned char)8/* * Build the ping cmd. Tomcat will get control and will be able * to send any command. * * +-----------------------+ * | PING CMD (1 byte) | * +-----------------------+ * * XXX Add optional Key/Value set . * */int jk2_serialize_ping(jk_env_t *env, jk_msg_t *msg, jk_endpoint_t *ae){ int rc; /* To be on the safe side */ msg->reset(env, msg); rc= msg->appendByte( env, msg, JK_AJP13_PING); if (rc!=JK_OK ) return JK_ERR; return JK_OK;}/* * Close the endpoint (clean buf and close socket) */static void jk2_close_endpoint(jk_env_t *env, jk_endpoint_t *ae){ if( ae->worker->mbean->debug > 0 ) env->l->jkLog(env, env->l, JK_LOG_DEBUG, "endpoint.close() %s\n", ae->worker->mbean->name); /* ae->reuse = JK_FALSE; */ if( ae->worker->channel != NULL ) ae->worker->channel->close( env, ae->worker->channel, ae ); ae->sd=-1; ae->recoverable=JK_TRUE; ae->cPool->reset( env, ae->cPool ); /* ae->cPool->close( env, ae->cPool ); */ /* Don't touch the ae->pool, the object has important statistics */ /* ae->pool->reset( env, ae->pool ); */ /* ae->pool->close( env, ae->pool ); */}/** Connect a channel, implementing the logging protocol if ajp13 */static int jk2_worker_ajp13_connect(jk_env_t *env, jk_endpoint_t *ae) { jk_channel_t *channel=ae->worker->channel; jk_msg_t *msg; int err; if( channel==NULL ) { env->l->jkLog(env, env->l, JK_LOG_ERROR, "ajp13.connect() no channel %s\n", ae->worker->mbean->name ); return JK_ERR; } if( ae->worker->mbean->debug > 0 ) env->l->jkLog(env, env->l, JK_LOG_DEBUG, "ajp13.connect() %s %s\n", ae->worker->channelName, channel->mbean->name ); err=channel->open( env, channel, ae ); if( err != JK_OK ) { env->l->jkLog(env, env->l, JK_LOG_ERROR, "ajp13.connect() failed %s\n", ae->worker->mbean->name ); return JK_ERR; } /* We just reconnected, reset error state */ ae->worker->in_error_state=JK_FALSE;#ifdef HAS_APR ae->stats->connectedTime=apr_time_now();#endif /** XXX use a 'connected' field */ if( ae->sd == -1 ) ae->sd=0; /* Check if we must execute a logon after the physical connect */ if (ae->worker->secret == NULL) return JK_OK; /* Do the logon process */ env->l->jkLog(env, env->l, JK_LOG_INFO, "ajp13.connect() logging in\n" ); /* use the reply buffer - it's a new channel, it is cetainly not in use. The request and post buffers are probably in use if this is a reconnect */ msg=ae->reply; jk2_serialize_ping( env, msg, ae ); err = ae->worker->channel->send( env, ae->worker->channel, ae, msg ); /* Move to 'slave' mode, listening to messages */ err=ae->worker->workerEnv->processCallbacks( env, ae->worker->workerEnv, ae, NULL); /* Anything but OK - the login failed */ if( err != JK_OK ) { jk2_close_endpoint( env, ae ); } return err;}/** There is no point of trying multiple times - each channel may have built-in recovery mechanisms*/#define JK_RETRIES 2static int JK_METHODjk2_worker_ajp13_forwardStream(jk_env_t *env, jk_worker_t *worker, jk_ws_service_t *s,
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -