jk_util.c

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

C
1,959
字号
        type = jk_map_get_string(m, buf, NULL);        if (type) {            if (!strcasecmp(type, TOMCAT32_BRIDGE_NAME))                *bt = TC32_BRIDGE_TYPE;            else if (!strcasecmp(type, TOMCAT33_BRIDGE_NAME))                *bt = TC33_BRIDGE_TYPE;            else if (!strcasecmp(type, TOMCAT40_BRIDGE_NAME))                *bt = TC40_BRIDGE_TYPE;            else if (!strcasecmp(type, TOMCAT41_BRIDGE_NAME))                *bt = TC41_BRIDGE_TYPE;            else if (!strcasecmp(type, TOMCAT50_BRIDGE_NAME))                *bt = TC50_BRIDGE_TYPE;            return JK_TRUE;        }    }    return JK_FALSE;}int jk_get_worker_jvm_path(jk_map_t *m, const char *wname, const char **vm_path){    char buf[1024];    if (m && vm_path && wname) {        MAKE_WORKER_PARAM(JVM_OF_WORKER);        *vm_path = jk_map_get_string(m, buf, NULL);        if (*vm_path) {            return JK_TRUE;        }    }    return JK_FALSE;}/* [V] This is unused. currently. */int jk_get_worker_callback_dll(jk_map_t *m, const char *wname, const char **cb_path){    char buf[1024];    if (m && cb_path && wname) {        MAKE_WORKER_PARAM(NATIVE_LIB_OF_WORKER);        *cb_path = jk_map_get_string(m, buf, NULL);        if (*cb_path) {            return JK_TRUE;        }    }    return JK_FALSE;}int jk_get_worker_cmd_line(jk_map_t *m, const char *wname, const char **cmd_line){    char buf[1024];    if (m && cmd_line && wname) {        MAKE_WORKER_PARAM(CMD_LINE_OF_WORKER);        *cmd_line = jk_map_get_string(m, buf, NULL);        if (*cmd_line) {            return JK_TRUE;        }    }    return JK_FALSE;}int jk_stat(const char *f, struct stat * statbuf){  int rc;/** * i5/OS V5R4 expect filename in ASCII for fopen but required them in EBCDIC for stat() */#ifdef AS400_UTF8  char *ptr;  ptr = (char *)malloc(strlen(f) + 1);  jk_ascii2ebcdic((char *)f, ptr);  rc = stat(ptr, statbuf);  free(ptr);#else  rc = stat(f, statbuf);#endif  return (rc);}int jk_file_exists(const char *f){    if (f) {        struct stat st;        if ((0 == jk_stat(f, &st)) && (st.st_mode & S_IFREG))      return JK_TRUE;    }    return JK_FALSE;}static int jk_is_some_property(const char *prp_name, const char *suffix, const char *sep){    char buf[1024];    if (prp_name && suffix) {        size_t prp_name_len;        size_t suffix_len;        strcpy(buf, sep);        strcat(buf, suffix);        prp_name_len = strlen(prp_name);        suffix_len = strlen(buf);        if (prp_name_len >= suffix_len) {            const char *prp_suffix = prp_name + prp_name_len - suffix_len;            if (0 == strcmp(buf, prp_suffix)) {                return JK_TRUE;            }        }    }    return JK_FALSE;}int jk_is_path_property(const char *prp_name){    return jk_is_some_property(prp_name, "path", "_");}int jk_is_cmd_line_property(const char *prp_name){    return jk_is_some_property(prp_name, CMD_LINE_OF_WORKER, ".");}int jk_is_list_property(const char *prp_name){    const char **props = &list_properties[0];    while (*props) {        if (jk_is_some_property(prp_name, *props, "."))            return JK_TRUE;        props++;    }    return JK_FALSE;}int jk_is_unique_property(const char *prp_name){    const char **props = &unique_properties[0];    while (*props) {        if (jk_is_some_property(prp_name, *props, "."))            return JK_TRUE;        props++;    }    return JK_FALSE;}int jk_is_deprecated_property(const char *prp_name){    const char **props = &deprecated_properties[0];    while (*props) {        if (jk_is_some_property(prp_name, *props, "."))            return JK_TRUE;        props++;    }    return JK_FALSE;}/* * Check that property is a valid one (to prevent user typos). * Only property starting with worker. */int jk_is_valid_property(const char *prp_name){    const char **props;    if (memcmp(prp_name, "worker.", 7))        return JK_TRUE;    props = &supported_properties[0];    while (*props) {        if (jk_is_some_property(prp_name, *props, "."))            return JK_TRUE;        props++;    }    return JK_FALSE;}int jk_get_worker_stdout(jk_map_t *m, const char *wname, const char **stdout_name){    char buf[1024];    if (m && stdout_name && wname) {        MAKE_WORKER_PARAM(STDOUT_OF_WORKER);        *stdout_name = jk_map_get_string(m, buf, NULL);        if (*stdout_name) {            return JK_TRUE;        }    }    return JK_FALSE;}int jk_get_worker_stderr(jk_map_t *m, const char *wname, const char **stderr_name){    char buf[1024];    if (m && stderr_name && wname) {        MAKE_WORKER_PARAM(STDERR_OF_WORKER);        *stderr_name = jk_map_get_string(m, buf, NULL);        if (*stderr_name) {            return JK_TRUE;        }    }    return JK_FALSE;}int jk_get_worker_sysprops(jk_map_t *m, const char *wname, const char **sysprops){    char buf[1024];    if (m && sysprops && wname) {        MAKE_WORKER_PARAM(SYSPROPS_OF_WORKER);        *sysprops = jk_map_get_string(m, buf, NULL);        if (*sysprops) {            return JK_TRUE;        }    }    return JK_FALSE;}int jk_get_worker_libpath(jk_map_t *m, const char *wname, const char **libpath){    char buf[1024];    if (m && libpath && wname) {        MAKE_WORKER_PARAM(LIBPATH_OF_WORKER);        *libpath = jk_map_get_string(m, buf, NULL);        if (*libpath) {            return JK_TRUE;        }    }    return JK_FALSE;}char **jk_parse_sysprops(jk_pool_t *p, const char *sysprops){    char **rc = NULL;#ifdef _REENTRANT    char *lasts;#endif    if (p && sysprops) {        char *prps = jk_pool_strdup(p, sysprops);        if (prps && strlen(prps)) {            unsigned num_of_prps;            for (num_of_prps = 1; *sysprops; sysprops++) {                if ('*' == *sysprops) {                    num_of_prps++;                }            }            rc = jk_pool_alloc(p, (num_of_prps + 1) * sizeof(char *));            if (rc) {                unsigned i = 0;#ifdef _REENTRANT                char *tmp = strtok_r(prps, "*", &lasts);#else                char *tmp = strtok(prps, "*");#endif                while (tmp && i < num_of_prps) {                    rc[i] = tmp;#ifdef _REENTRANT                    tmp = strtok_r(NULL, "*", &lasts);#else                    tmp = strtok(NULL, "*");#endif                    i++;                }                rc[i] = NULL;            }        }    }    return rc;}void jk_append_libpath(jk_pool_t *p, const char *libpath){    char *env = NULL;    char *current = getenv(PATH_ENV_VARIABLE);    if (current) {        env = jk_pool_alloc(p, strlen(PATH_ENV_VARIABLE) +                            strlen(current) + strlen(libpath) + 5);        if (env) {            sprintf(env, "%s=%s%c%s",                    PATH_ENV_VARIABLE, libpath, PATH_SEPERATOR, current);        }    }    else {        env = jk_pool_alloc(p, strlen(PATH_ENV_VARIABLE) +                            strlen(libpath) + 5);        if (env) {            sprintf(env, "%s=%s", PATH_ENV_VARIABLE, libpath);        }    }    if (env) {        putenv(env);    }}void jk_init_ws_service(jk_ws_service_t *s){    s->ws_private = NULL;    s->pool = NULL;    s->method = NULL;    s->protocol = NULL;    s->req_uri = NULL;    s->remote_addr = NULL;    s->remote_host = NULL;    s->remote_user = NULL;    s->auth_type = NULL;    s->query_string = NULL;    s->server_name = NULL;    s->server_port = 80;    s->server_software = NULL;    s->content_length = 0;    s->is_chunked = 0;    s->no_more_chunks = 0;    s->content_read = 0;    s->is_ssl = JK_FALSE;    s->ssl_cert = NULL;    s->ssl_cert_len = 0;    s->ssl_cipher = NULL;    s->ssl_session = NULL;    s->headers_names = NULL;    s->headers_values = NULL;    s->num_headers = 0;    s->attributes_names = NULL;    s->attributes_values = NULL;    s->num_attributes = 0;    s->route = NULL;    s->retries = JK_RETRIES;    s->add_log_items = NULL;}#ifdef _MT_CODE_PTHREADjk_uint32_t jk_gettid(){    union {        pthread_t tid;        jk_uint64_t alignme;    } u;#ifdef AS400    /* OS400 use 64 bits ThreadId */    pthread_id_np_t       tid;#endif /* AS400 */    u.tid = pthread_self();#ifdef AS400    /* Get only low 32 bits for now */    pthread_getunique_np(&(u.tid), &tid);    return ((jk_uint32_t)(tid.intId.lo & 0xFFFFFFFF));#else    switch(sizeof(pthread_t)) {    case sizeof(jk_uint32_t):        return *(jk_uint32_t *)&u.tid;    case sizeof(jk_uint64_t):        return (*(jk_uint64_t *)&u.tid) & 0xFFFFFFFF;    default:        return 0;    }#endif /* AS400 */}#endif/*** * ASCII <-> EBCDIC conversions * * For now usefull only in i5/OS V5R4 where UTF and EBCDIC mode are mixed */#ifdef AS400_UTF8/* EBCDIC to ASCII translation table */static u_char ebcdic_to_ascii[256] ={  0x00,0x01,0x02,0x03,0x20,0x09,0x20,0x7f, /* 00-07 */  0x20,0x20,0x20,0x0b,0x0c,0x0d,0x0e,0x0f, /* 08-0f */  0x10,0x11,0x12,0x13,0x20,0x0a,0x08,0x20, /* 10-17 */  0x18,0x19,0x20,0x20,0x20,0x1d,0x1e,0x1f, /* 18-1f */  0x20,0x20,0x1c,0x20,0x20,0x0a,0x17,0x1b, /* 20-27 */  0x20,0x20,0x20,0x20,0x20,0x05,0x06,0x07, /* 28-2f */  0x20,0x20,0x16,0x20,0x20,0x20,0x20,0x04, /* 30-37 */  0x20,0x20,0x20,0x20,0x14,0x15,0x20,0x1a, /* 38-3f */  0x20,0x20,0x83,0x84,0x85,0xa0,0xc6,0x86, /* 40-47 */  0x87,0xa4,0xbd,0x2e,0x3c,0x28,0x2b,0x7c, /* 48-4f */  0x26,0x82,0x88,0x89,0x8a,0xa1,0x8c,0x8b, /* 50-57 */  0x8d,0xe1,0x21,0x24,0x2a,0x29,0x3b,0xaa, /* 58-5f */  0x2d,0x2f,0xb6,0x8e,0xb7,0xb5,0xc7,0x8f, /* 60-67 */  0x80,0xa5,0xdd,0x2c,0x25,0x5f,0x3e,0x3f, /* 68-6f */  0x9b,0x90,0xd2,0xd3,0xd4,0xd6,0xd7,0xd8, /* 70-77 */  0xde,0x60,0x3a,0x23,0x40,0x27,0x3d,0x22, /* 78-7f */  0x9d,0x61,0x62,0x63,0x64,0x65,0x66,0x67, /* 80-87 */  0x68,0x69,0xae,0xaf,0xd0,0xec,0xe7,0xf1, /* 88-8f */  0xf8,0x6a,0x6b,0x6c,0x6d,0x6e,0x6f,0x70, /* 90-97 */  0x71,0x72,0xa6,0xa7,0x91,0xf7,0x92,0xcf, /* 98-9f */  0xe6,0x7e,0x73,0x74,0x75,0x76,0x77,0x78, /* a8-a7 */  0x79,0x7a,0xad,0xa8,0xd1,0xed,0xe8,0xa9, /* a8-af */  0x5e,0x9c,0xbe,0xfa,0xb8,0x15,0x14,0xac, /* b0-b7 */  0xab,0xf3,0x5b,0x5d,0xee,0xf9,0xef,0x9e, /* b8-bf */  0x7b,0x41,0x42,0x43,0x44,0x45,0x46,0x47, /* c0-c7 */  0x48,0x49,0xf0,0x93,0x94,0x95,0xa2,0xe4, /* c8-cf */  0x7d,0x4a,0x4b,0x4c,0x4d,0x4e,0x4f,0x50, /* d0-d7 */  0x51,0x52,0xfb,0x96,0x81,0x97,0xa3,0x98, /* d8-df */  0x5c,0xf6,0x53,0x54,0x55,0x56,0x57,0x58, /* e0-e7 */  0x59,0x5a,0xfc,0xe2,0x99,0xe3,0xe0,0xe5, /* e8-ef */  0x30,0x31,0x32,0x33,0x34,0x35,0x36,0x37, /* f0-f7 */  0x38,0x39,0xfd,0xea,0x9a,0xeb,0xe9,0xff  /* f8-ff */};/* ASCII to EBCDIC translation table */static u_char ascii_to_ebcdic[256] ={  0x00,0x01,0x02,0x03,0x37,0x2d,0x2e,0x2f, /* 00-07 */  0x16,0x05,0x25,0x0b,0x0c,0x0d,0x0e,0x0f, /* 08-0f */  0x10,0x11,0x12,0x13,0x3c,0x3d,0x32,0x26, /* 10-17 */  0x18,0x19,0x3f,0x27,0x22,0x1d,0x1e,0x1f, /* 18-1f */  0x40,0x5a,0x7f,0x7b,0x5b,0x6c,0x50,0x7d, /* 20-27 */  0x4d,0x5d,0x5c,0x4e,0x6b,0x60,0x4b,0x61, /* 28-2f */  0xf0,0xf1,0xf2,0xf3,0xf4,0xf5,0xf6,0xf7, /* 30-37 */  0xf8,0xf9,0x7a,0x5e,0x4c,0x7e,0x6e,0x6f, /* 38-3f */  0x7c,0xc1,0xc2,0xc3,0xc4,0xc5,0xc6,0xc7, /* 40-47 */  0xc8,0xc9,0xd1,0xd2,0xd3,0xd4,0xd5,0xd6, /* 48-4f */  0xd7,0xd8,0xd9,0xe2,0xe3,0xe4,0xe5,0xe6, /* 50-57 */  0xe7,0xe8,0xe9,0xba,0xe0,0xbb,0xb0,0x6d, /* 58-5f */  0x79,0x81,0x82,0x83,0x84,0x85,0x86,0x87, /* 60-67 */  0x88,0x89,0x91,0x92,0x93,0x94,0x95,0x96, /* 68-6f */  0x97,0x98,0x99,0xa2,0xa3,0xa4,0xa5,0xa6, /* 70-77 */  0xa7,0xa8,0xa9,0xc0,0x4f,0xd0,0xa1,0x07, /* 78-7f */  0x68,0xdc,0x51,0x42,0x43,0x44,0x47,0x48, /* 80-87 */  0x52,0x53,0x54,0x57,0x56,0x58,0x63,0x67, /* 88-8f */  0x71,0x9c,0x9e,0xcb,0xcc,0xcd,0xdb,0xdd, /* 90-97 */  0xdf,0xec,0xfc,0x70,0xb1,0x80,0xbf,0x40, /* 98-9f */  0x45,0x55,0xee,0xde,0x49,0x69,0x9a,0x9b, /* a8-a7 */  0xab,0xaf,0x5f,0xb8,0xb7,0xaa,0x8a,0x8b, /* a8-af */  0x40,0x40,0x40,0x40,0x40,0x65,0x62,0x64, /* b0-b7 */  0xb4,0x40,0x40,0x40,0x40,0x4a,0xb2,0x40, /* b8-bf */  0x40,0x40,0x40,0x40,0x40,0x40,0x46,0x66, /* c0-c7 */  0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x9f, /* c8-cf */  0x8c,0xac,0x72,0x73,0x74,0x89,0x75,0x76, /* d0-d7 */  0x77,0x40,0x40,0x40,0x40,0x6a,0x78,0x40, /* d8-df */  0xee,0x59,0xeb,0xed,0xcf,0xef,0xa0,0x8e, /* e0-e7 */  0xae,0xfe,0xfb,0xfd,0x8d,0xad,0xbc,0xbe, /* e8-ef */  0xca,0x8f,0x40,0xb9,0xb6,0xb5,0xe1,0x9d, /* f0-f7 */  0x90,0xbd,0xb3,0xda,0xea,0xfa,0x40,0x40  /* f8-ff */};void jk_ascii2ebcdic(char *src, char *dst) {    char c;    while ((c = *src++) != 0) {        *dst++ = ascii_to_ebcdic[(unsigned int)c];    }    *dst = 0;}void jk_ebcdic2ascii(char *src, char *dst) {    char c;    while ((c = *src++) != 0) {        *dst++ = ebcdic_to_ascii[(unsigned int)c];    }    *dst = 0;}#endif

⌨️ 快捷键说明

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