mod_jk.c

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

C
2,094
字号
                                    char *worker){    server_rec *s = cmd->server;    jk_server_conf_t *conf =        (jk_server_conf_t *) ap_get_module_config(s->module_config,                                                  &jk_module);    const char *c, *w;    if (worker != NULL && cmd->path == NULL ) {        c = context;        w = worker;    }    else if (worker == NULL && cmd->path != NULL) {        c = cmd->path;        w = context;    }    else {        if (worker == NULL)            return "JkMount needs a path when not defined in a location";        else            return "JkMount can not have a path when defined in a location";    }    if (c[0] != '/')        return "JkMount context should start with /";    /*     * Add the new worker to the alias map.     */    jk_map_put(conf->uri_to_context, c, w, NULL);    return NULL;}/* * JkUnMount directive handling * * JkUnMount URI(context) worker */static const char *jk_unmount_context(cmd_parms * cmd,                                      void *dummy,                                      const char *context,                                      const char *worker){    server_rec *s = cmd->server;    jk_server_conf_t *conf =        (jk_server_conf_t *) ap_get_module_config(s->module_config,                                                  &jk_module);    char *uri;    const char *c, *w;    if (worker != NULL && cmd->path == NULL ) {        c = context;        w = worker;    }    else if (worker == NULL && cmd->path != NULL) {        c = cmd->path;        w = context;    }    else {        if (worker == NULL)            return "JkUnMount needs a path when not defined in a location";        else            return "JkUnMount can not have a path when defined in a location";    }    if (c[0] != '/')        return "JkUnMount context should start with /";    uri = ap_pstrcat(cmd->temp_pool, "!", c, NULL);    /*     * Add the new worker to the alias map.     */    jk_map_put(conf->uri_to_context, uri, w, NULL);    return NULL;}/* * JkAutoMount directive handling * * JkAutoMount worker [virtualhost] */static const char *jk_automount_context(cmd_parms * cmd,                                        void *dummy,                                        char *worker, char *virtualhost){    server_rec *s = cmd->server;    jk_server_conf_t *conf =        (jk_server_conf_t *) ap_get_module_config(s->module_config,                                                  &jk_module);    /*     * Add the new automount to the auto map.     */    jk_map_put(conf->automount, worker, virtualhost, NULL);    return NULL;}/* * JkWorkersFile Directive Handling * * JkWorkersFile file */static const char *jk_set_worker_file(cmd_parms * cmd,                                      void *dummy, char *worker_file){    server_rec *s = cmd->server;    struct stat statbuf;    jk_server_conf_t *conf =        (jk_server_conf_t *) ap_get_module_config(s->module_config,                                                  &jk_module);    /* we need an absolute path */    conf->worker_file = ap_server_root_relative(cmd->pool, worker_file);#ifdef CHROOTED_APACHE    ap_server_strip_chroot(conf->worker_file, 0);#endif    if (conf->worker_file == worker_file)        conf->worker_file = ap_pstrdup(cmd->pool, worker_file);    if (conf->worker_file == NULL)        return "JkWorkersFile file name invalid";    if (stat(conf->worker_file, &statbuf) == -1)        return "Can't find the workers file specified";    return NULL;}/* * JkMountFile Directive Handling * * JkMountFile file */static const char *jk_set_mount_file(cmd_parms * cmd,                                     void *dummy, char *mount_file){    server_rec *s = cmd->server;    struct stat statbuf;    jk_server_conf_t *conf =        (jk_server_conf_t *) ap_get_module_config(s->module_config,                                                  &jk_module);    /* we need an absolute path (ap_server_root_relative does the ap_pstrdup) */    conf->mount_file = ap_server_root_relative(cmd->pool, mount_file);#ifdef CHROOTED_APACHE    ap_server_strip_chroot(conf->mount_file, 0);#endif    if (conf->mount_file == NULL)        return "JkMountFile file name invalid";    if (stat(conf->mount_file, &statbuf) == -1)        return "Can't find the mount file specified";    return NULL;}/* * JkMountFileReload Directive Handling * * JkMountFileReload seconds */static const char *jk_set_mount_file_reload(cmd_parms * cmd,                                            void *dummy, char *mount_file_reload){    server_rec *s = cmd->server;    int interval;    jk_server_conf_t *conf =        (jk_server_conf_t *) ap_get_module_config(s->module_config,                                                  &jk_module);    interval = atoi(mount_file_reload);    if (interval < 0) {        interval = 0;    }    conf->mount_file_reload = interval;    return NULL;}/* * JkLogFile Directive Handling * * JkLogFile file */static const char *jk_set_log_file(cmd_parms * cmd,                                   void *dummy, char *log_file){    server_rec *s = cmd->server;    jk_server_conf_t *conf =        (jk_server_conf_t *) ap_get_module_config(s->module_config,                                                  &jk_module);    /* we need an absolute path */    if (*log_file != '|') {        conf->log_file = ap_server_root_relative(cmd->pool, log_file);#ifdef CHROOTED_APACHE        ap_server_strip_chroot(conf->log_file, 0);#endif    }    else        conf->log_file = ap_pstrdup(cmd->pool, log_file);    if (conf->log_file == NULL)        return "JkLogFile file name invalid";    return NULL;}/* * JkShmFile Directive Handling * * JkShmFile file */static const char *jk_set_shm_file(cmd_parms * cmd,                                   void *dummy, char *shm_file){    /* we need an absolute path */    jk_shm_file = ap_server_root_relative(cmd->pool, shm_file);#ifdef CHROOTED_APACHE    ap_server_strip_chroot(jk_shm_file, 0);#endif    if (jk_shm_file == shm_file)        jk_shm_file = ap_pstrdup(cmd->pool, shm_file);    if (jk_shm_file == NULL)        return "JkShmFile file name invalid";    return NULL;}/* * JkShmSize Directive Handling * * JkShmSize size in kilobytes */static const char *jk_set_shm_size(cmd_parms * cmd,                                   void *dummy, const char *shm_size){    int sz = 0;    /* we need an absolute path */    sz = atoi(shm_size) * 1024;    if (sz < JK_SHM_DEF_SIZE)        sz = JK_SHM_DEF_SIZE;    else        sz = JK_SHM_ALIGN(sz);    jk_shm_size = (size_t)sz;    return NULL;}/* * JkLogLevel Directive Handling * * JkLogLevel debug/info/request/error/emerg */static const char *jk_set_log_level(cmd_parms * cmd,                                    void *dummy, char *log_level){    server_rec *s = cmd->server;    jk_server_conf_t *conf =        (jk_server_conf_t *) ap_get_module_config(s->module_config,                                                  &jk_module);    conf->log_level = jk_parse_log_level(log_level);    return NULL;}/* * JkLogStampFormat Directive Handling * * JkLogStampFormat "[%a %b %d %H:%M:%S %Y] " */static const char *jk_set_log_fmt(cmd_parms * cmd,                                  void *dummy, char *log_format){    server_rec *s = cmd->server;    jk_server_conf_t *conf =        (jk_server_conf_t *) ap_get_module_config(s->module_config,                                                  &jk_module);    conf->stamp_format_string = ap_pstrdup(cmd->pool, log_format);    return NULL;}/* * JkAutoAlias Directive Handling * * JkAutoAlias application directory */static const char *jk_set_auto_alias(cmd_parms * cmd,                                     void *dummy, char *directory){    server_rec *s = cmd->server;    jk_server_conf_t *conf =        (jk_server_conf_t *) ap_get_module_config(s->module_config,                                                  &jk_module);    conf->alias_dir = directory;    if (conf->alias_dir == NULL)        return "JkAutoAlias directory invalid";    return NULL;}/* * JkStripSession directive handling * * JkStripSession On/Off */static const char *jk_set_strip_session(cmd_parms * cmd, void *dummy, int flag){    server_rec *s = cmd->server;    jk_server_conf_t *conf =        (jk_server_conf_t *) ap_get_module_config(s->module_config,                                                  &jk_module);    /* Set up our value */    conf->strip_session = flag ? JK_TRUE : JK_FALSE;    return NULL;}/***************************************************************** * * Actually logging. */typedef const char *(*item_key_func) (request_rec *, char *);typedef struct{    item_key_func func;    char *arg;} request_log_format_item;static const char *process_item(request_rec * r,                                request_log_format_item * item){    const char *cp;    cp = (*item->func) (r, item->arg);    return cp ? cp : "-";}static void request_log_transaction(request_rec * r, jk_server_conf_t * conf){    request_log_format_item *items;    char *str, *s;    int i;    int len = 0;    const char **strs;    int *strl;    array_header *format = conf->format;    strs = ap_palloc(r->pool, sizeof(char *) * (format->nelts));    strl = ap_palloc(r->pool, sizeof(int) * (format->nelts));    items = (request_log_format_item *) format->elts;    for (i = 0; i < format->nelts; ++i) {        strs[i] = process_item(r, &items[i]);    }    for (i = 0; i < format->nelts; ++i) {        len += strl[i] = strlen(strs[i]);    }    str = ap_palloc(r->pool, len + 1);    for (i = 0, s = str; i < format->nelts; ++i) {        memcpy(s, strs[i], strl[i]);        s += strl[i];    }    *s = 0;    jk_log(conf->log, JK_LOG_REQUEST, "%s", str);}/***************************************************************** * * Parsing the log format string */static char *format_integer(pool * p, int i){    return ap_psprintf(p, "%d", i);}static char *pfmt(pool * p, int i){    if (i <= 0) {        return "-";    }    else {        return format_integer(p, i);    }}static const char *constant_item(request_rec * dummy, char *stuff){

⌨️ 快捷键说明

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