mod_jk.c

来自「以便Apache与其他服务进行整合 Mod_JK安装」· C语言 代码 · 共 2,094 行 · 第 1/5 页

C
2,094
字号
    jk_server_conf_t *conf =        (jk_server_conf_t *) ap_get_module_config(s->module_config,                                                  &jk_module);    conf->key_size_indicator = ap_pstrdup(cmd->pool, indicator);    return NULL;}/* * JkOptions Directive Handling * * * +ForwardSSLKeySize        => Forward SSL Key Size, to follow 2.3 specs but may broke old TC 3.2 * -ForwardSSLKeySize        => Don't Forward SSL Key Size, will make mod_jk works with all TC release *  ForwardURICompat         => Forward URI normally, less spec compliant but mod_rewrite compatible (old TC) *  ForwardURICompatUnparsed => Forward URI as unparsed, spec compliant but broke mod_rewrite (old TC) *  ForwardURIEscaped        => Forward URI escaped and Tomcat (3.3 rc2) stuff will do the decoding part *  ForwardDirectories       => Forward all directory requests with no index files to Tomcat * +ForwardSSLCertChain      => Forward SSL certificate chain * -ForwardSSLCertChain      => Don't forward SSL certificate chain */const char *jk_set_options(cmd_parms * cmd, void *dummy, const char *line){    int opt = 0;    int mask = 0;    char action;    char *w;    server_rec *s = cmd->server;    jk_server_conf_t *conf =        (jk_server_conf_t *) ap_get_module_config(s->module_config,                                                  &jk_module);    while (line[0] != 0) {        w = ap_getword_conf(cmd->pool, &line);        action = 0;        if (*w == '+' || *w == '-') {            action = *(w++);        }        mask = 0;        if (action == '-' && !strncasecmp(w, "ForwardURI", strlen("ForwardURI")))            return ap_pstrcat(cmd->pool, "JkOptions: Illegal option '-", w,                               "': ForwardURI* options can not be disabled", NULL);        if (!strcasecmp(w, "ForwardURICompat")) {            opt = JK_OPT_FWDURICOMPAT;            mask = JK_OPT_FWDURIMASK;        }        else if (!strcasecmp(w, "ForwardURICompatUnparsed")) {            opt = JK_OPT_FWDURICOMPATUNPARSED;            mask = JK_OPT_FWDURIMASK;        }        else if (!strcasecmp(w, "ForwardURIEscaped")) {            opt = JK_OPT_FWDURIESCAPED;            mask = JK_OPT_FWDURIMASK;        }        else if (!strcasecmp(w, "ForwardURIProxy")) {            opt = JK_OPT_FWDURIPROXY;            mask = JK_OPT_FWDURIMASK;        }        else if (!strcasecmp(w, "ForwardDirectories")) {            opt = JK_OPT_FWDDIRS;        }        else if (!strcasecmp(w, "ForwardLocalAddress")) {            opt = JK_OPT_FWDLOCAL;        }        else if (!strcasecmp(w, "FlushPackets")) {            opt = JK_OPT_FLUSHPACKETS;        }        else if (!strcasecmp(w, "FlushHeader")) {            opt = JK_OPT_FLUSHEADER;        }        else if (!strcasecmp(w, "DisableReuse")) {            opt = JK_OPT_DISABLEREUSE;        }        else if (!strcasecmp(w, "ForwardSSLCertChain")) {            opt = JK_OPT_FWDCERTCHAIN;        }        else if (!strcasecmp(w, "ForwardKeySize")) {            opt = JK_OPT_FWDKEYSIZE;        }        else if (!strcasecmp(w, "RejectUnsafeURI")) {            opt = JK_OPT_REJECTUNSAFE;        }        else            return ap_pstrcat(cmd->pool, "JkOptions: Illegal option '", w,                              "'", NULL);        conf->options &= ~mask;        if (action == '-') {            conf->exclude_options |= opt;        }        else if (action == '+') {            conf->options |= opt;        }        else {                  /* for now +Opt == Opt */            conf->options |= opt;        }    }    return NULL;}/* * JkEnvVar Directive Handling * * JkEnvVar MYOWNDIR */static const char *jk_add_env_var(cmd_parms * cmd,                                  void *dummy,                                  char *env_name, char *default_value){    server_rec *s = cmd->server;    jk_server_conf_t *conf =        (jk_server_conf_t *) ap_get_module_config(s->module_config,                                                  &jk_module);    conf->envvars_in_use = JK_TRUE;    /* env_name is mandatory, default_value is optional.     * No value means send the attribute only, if the env var is set during runtime.     */    ap_table_setn(conf->envvars, env_name, default_value ? default_value : "");    ap_table_setn(conf->envvars_def, env_name, default_value ? "1" : "0");    return NULL;}/* * JkWorkerProperty Directive Handling * * JkWorkerProperty name=value */static const char *jk_set_worker_property(cmd_parms * cmd,                                          void *dummy,                                          const char *line){    server_rec *s = cmd->server;    jk_server_conf_t *conf =        (jk_server_conf_t *) ap_get_module_config(s->module_config,                                                  &jk_module);    if (jk_map_read_property(conf->worker_properties, line,                             JK_MAP_HANDLE_DUPLICATES, conf->log) == JK_FALSE)        return ap_pstrcat(cmd->temp_pool, "Invalid JkWorkerProperty ", line, NULL);    return NULL;}static const command_rec jk_cmds[] = {    /*     * JkWorkersFile specifies a full path to the location of the worker     * properties file.     *     * This file defines the different workers used by apache to redirect     * servlet requests.     */    {"JkWorkersFile", jk_set_worker_file, NULL, RSRC_CONF, TAKE1,     "the name of a worker file for the Tomcat servlet containers"},    /*     * JkMountFile specifies a full path to the location of the     * uriworker properties file.     *     * This file defines the different mapping for workers used by apache     * to redirect servlet requests.     */    {"JkMountFile", jk_set_mount_file, NULL, RSRC_CONF, TAKE1,     "the name of a mount file for the Tomcat servlet uri mappings"},    /*     * JkMountFileReload specifies the reload check interval for the     * uriworker properties file.     *     * Default value is: JK_URIMAP_DEF_RELOAD     */    {"JkMountFileReload", jk_set_mount_file_reload, NULL, RSRC_CONF, TAKE1,     "the reload check interval of the mount file"},    /*     * JkAutoMount specifies that the list of handled URLs must be     * asked to the servlet engine (autoconf feature)     */    {"JkAutoMount", jk_automount_context, NULL, RSRC_CONF, TAKE12,     "automatic mount points to a servlet-engine worker"},    /*     * JkMount mounts a url prefix to a worker (the worker need to be     * defined in the worker properties file.     */    {"JkMount", jk_mount_context, NULL, RSRC_CONF|ACCESS_CONF, TAKE12,     "A mount point from a context to a servlet-engine worker"},    /*     * JkUnMount unmounts a url prefix to a worker (the worker need to be     * defined in the worker properties file.     */    {"JkUnMount", jk_unmount_context, NULL, RSRC_CONF|ACCESS_CONF, TAKE12,     "A no mount point from a context to a servlet-engine worker"},     /*     * JkMountCopy specifies if mod_jk should copy the mount points     * from the main server to the virtual servers.     */    {"JkMountCopy", jk_set_mountcopy, NULL, RSRC_CONF, FLAG,     "Should the base server mounts be copied to the virtual server"},    /*     * JkStripSession specifies if mod_jk should strip the ;jsessionid     * from the unmapped urls     */    {"JkStripSession", jk_set_strip_session, NULL, RSRC_CONF, FLAG,     "Should the server strip the jsessionid from unmapped URLs"},    /*     * JkLogFile & JkLogLevel specifies to where should the plugin log     * its information and how much.     * JkLogStampFormat specify the time-stamp to be used on log     */    {"JkLogFile", jk_set_log_file, NULL, RSRC_CONF, TAKE1,     "Full path to the mod_jk module log file"},    {"JkShmFile", jk_set_shm_file, NULL, RSRC_CONF, TAKE1,     "Full path to the mod_jk module shared memory file"},    {"JkShmSize", jk_set_shm_size, NULL, RSRC_CONF, TAKE1,     "Size of the shared memory file in KBytes"},    {"JkLogLevel", jk_set_log_level, NULL, RSRC_CONF, TAKE1,     "The mod_jk module log level, can be debug, info, request, error, or emerg"},    {"JkLogStampFormat", jk_set_log_fmt, NULL, RSRC_CONF, TAKE1,     "The mod_jk module log format, follow strftime syntax"},    {"JkRequestLogFormat", jk_set_request_log_format, NULL, RSRC_CONF, TAKE1,     "The mod_jk module request log format string"},    /*     * Automatically Alias webapp context directories into the Apache     * document space.     */    {"JkAutoAlias", jk_set_auto_alias, NULL, RSRC_CONF, TAKE1,     "The mod_jk module automatic context apache alias directory"},    /*     * Enable worker name to be set in an environment variable.     * this way one can use LocationMatch together with mod_end,     * mod_setenvif and mod_rewrite to set the target worker.     * Use this in combination with SetHandler jakarta-servlet to     * make mod_jk the handler for the request.     *     */    {"JkWorkerIndicator", jk_set_worker_indicator, NULL, RSRC_CONF, TAKE1,     "Name of the Apache environment that contains the worker name"},    /*     * Apache has multiple SSL modules (for example apache_ssl, stronghold     * IHS ...). Each of these can have a different SSL environment names     * The following properties let the administrator specify the envoiroment     * variables names.     *     * HTTPS - indication for SSL     * CERTS - Base64-Der-encoded client certificates.     * CIPHER - A string specifing the ciphers suite in use.     * SESSION - A string specifing the current SSL session.     * KEYSIZE - Size of Key used in dialogue (#bits are secure)     */    {"JkHTTPSIndicator", jk_set_https_indicator, NULL, RSRC_CONF, TAKE1,     "Name of the Apache environment that contains SSL indication"},    {"JkCERTSIndicator", jk_set_certs_indicator, NULL, RSRC_CONF, TAKE1,     "Name of the Apache environment that contains SSL client certificates"},    {"JkCIPHERIndicator", jk_set_cipher_indicator, NULL, RSRC_CONF, TAKE1,     "Name of the Apache environment that contains SSL client cipher"},    {"JkCERTCHAINPrefix", jk_set_certchain_prefix, NULL, RSRC_CONF, TAKE1,     "Name of the Apache environment (prefix) that contains SSL client chain certificates"},    {"JkSESSIONIndicator", jk_set_session_indicator, NULL, RSRC_CONF, TAKE1,     "Name of the Apache environment that contains SSL session"},    {"JkKEYSIZEIndicator", jk_set_key_size_indicator, NULL, RSRC_CONF, TAKE1,     "Name of the Apache environment that contains SSL key size in use"},    {"JkExtractSSL", jk_set_enable_ssl, NULL, RSRC_CONF, FLAG,     "Turns on SSL processing and information gathering by mod_jk"},    /*     * Options to tune mod_jk configuration     * for now we understand :     * +ForwardSSLKeySize        => Forward SSL Key Size, to follow 2.3 specs but may broke old TC 3.2     * -ForwardSSLKeySize        => Don't Forward SSL Key Size, will make mod_jk works with all TC release     *  ForwardURICompat         => Forward URI normally, less spec compliant but mod_rewrite compatible (old TC)     *  ForwardURICompatUnparsed => Forward URI as unparsed, spec compliant but broke mod_rewrite (old TC)     *  ForwardURIEscaped        => Forward URI escaped and Tomcat (3.3 rc2) stuff will do the decoding part     * +ForwardSSLCertChain      => Forward SSL certificate chain     * -ForwardSSLCertChain      => Don't forward SSL certificate chain     */    {"JkOptions", jk_set_options, NULL, RSRC_CONF, RAW_ARGS,     "Set one of more options to configure the mod_jk module"},    /*     * JkEnvVar let user defines envs var passed from WebServer to     * Servlet Engine     */    {"JkEnvVar", jk_add_env_var, NULL, RSRC_CONF, TAKE12,     "Adds a name of environment variable and an optional value "     "that should be sent to servlet-engine"},    {"JkWorkerProperty", jk_set_worker_property, NULL, RSRC_CONF, RAW_ARGS,     "Set workers.properties formated directive"},    {NULL}};/* ====================================================================== *//* The JK module handlers                                                 *//* ====================================================================== *//* * Called to handle a single request. */static int jk_handler(request_rec * r){    jk_server_conf_t *conf =        (jk_server_conf_t *) ap_get_module_config(r->server->                                                  module_config,                                                  &jk_module);    /* Retrieve the worker name stored by jk_translate() */    const char *worker_name = ap_table_get(r->notes, JK_NOTE_WORKER_NAME);    int rc;    JK_TRACE_ENTER(conf->log);    if (ap_table_get(r->subprocess_env, "no-jk")) {        if (JK_IS_DEBUG_LEVEL(conf->log))            jk_log(conf->log, JK_LOG_DEBUG,                   "Into handler no-jk env var detected for uri=%s, declined",                   r->uri);        JK_TRACE_EXIT(conf->log);        return DECLINED;    }    if (r->proxyreq) {        jk_log(conf->log, JK_LOG_ERROR,               "Request has proxyreq flag set in mod_jk handler - aborting.");        JK_TRACE_EXIT(conf->log);        return HTTP_INTERNAL_SERVER_ERROR;    }    /* Set up r->read_chunked flags for chunked encoding, if present */    if ((rc = ap_setup_client_block(r, REQUEST_CHUNKED_DECHUNK))) {        jk_log(conf->log, JK_LOG_ERROR,               "Could not setup client_block for chunked encoding - aborting");        JK_TRACE_EXIT(conf->log);        return rc;    }    if (worker_name == NULL && r->handler && !strcmp(r->handler, JK_HANDLER)) {        /* we may be here because of a manual directive ( that overrides         * translate and         * sets the handler directly ). We still need to know the worker.         */            if (JK_IS_DEBUG_LEVEL(conf->log))                jk_log(conf->log, JK_LOG_DEBUG,                       "Retrieving environment %s", conf->worker_indicator);        worker_name = (char *)ap_table_get(r->subprocess_env, conf->worker_indicator);        if (worker_name) {          /* The JkWorkerIndicator environment variable has           * been used to explicitely set the worker without JkMount.           * This is useful in combination with LocationMatch or mod_rewrite.           */            if (JK_IS_DEBUG_LEVEL(conf->log))                jk_log(conf->log, JK_LOG_DEBUG,                       "Retrieved worker (%s) from env %s for %s",                       worker_name, conf->worker_indicator, r->uri);        }        else if (worker_env.num_of_workers == 1) {          /* We have a single worker ( the common case ).           * ( lb is a bit special, it should count as a single worker but           * I'm not sure how ). We also have a manual config directive that           * explicitely give control to us.           */            worker_name = worker_env.worker_list[0];            if (JK_IS_DEBUG_LEVEL(conf->log))                jk_log(conf->log, JK_LOG_DEBUG,                       "Single worker (%s) configuration for %s",                       worker_name, r->uri);        }        else if (worker_env.num_of_workers) {            worker_name = worker_env.worker_list[0];            if (JK_IS_DEBUG_LEVEL(conf->log))                jk_log(conf->log, JK_LOG_DEBUG,                       "Using first worker (%s) from %d workers for %s",                       worker_name, worker_env.num_of_workers, r->uri);        }    }    if (worker_name) {        jk_worker_t *worker;        worker = wc_get_worker_for_name(worker_name, conf->log);        if (worker) {#ifndef NO_GETTIMEOFDAY            struct timeval tv_begin, tv_end;#endif            int rc = JK_FALSE;            int is_error = JK_HTTP_SERVER_ERROR;            apache_private_data_t private_data;            jk_ws_service_t s;            jk_pool_atom_t buf[SMALL_POOL_SIZE];            jk_open_pool(&private_data.p, buf, sizeof(buf));            private_data.response_started = JK_FALSE;            private_data.read_body_started = JK_FALSE;            private_data.r = r;            wc_maintain(conf->log);            jk_init_ws_service(&s);            /* Update retries for this wor

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?