static int read_registry_init_data()

in native/iis/jk_isapi_plugin.c [2841:2984]


static int read_registry_init_data(jk_log_context_t *l)
{
    char tmpbuf[MAX_PATH];
    int ok = JK_FALSE;
    LPVOID src;
    HKEY hkey;
    int remain;
    jk_map_t *map = NULL;

    remain = jk_check_buffer_size();
    if (remain < 0) {
        jk_log(l, JK_LOG_ERROR,
               "mod_jk: JK_MAX_ATTRIBUTE_NAME_LEN in jk_util.c is too small, "
               "increase by %d", -1 * remain);
    }
    if (jk_map_alloc(&map)) {
        if (jk_map_read_properties(map, jk_environment_map, ini_file_name, NULL,
                                   JK_MAP_HANDLE_DUPLICATES, l)) {
            using_ini_file = JK_TRUE;
            src = map;
        }
        else {
            jk_map_free(&map);
        }
    }
    if (!using_ini_file) {
        long rc = RegOpenKeyEx(HKEY_LOCAL_MACHINE, REGISTRY_LOCATION,
                               (DWORD)0, KEY_READ, &hkey);
        if (ERROR_SUCCESS != rc) {
            return JK_FALSE;
        }
        else {
            src = hkey;
        }
    }
    if (!get_config_parameter(src, JK_LOG_FILE_TAG, log_file, sizeof(log_file)))
        goto cleanup;
    if (is_path_relative(log_file)) {
        char *fp = path_merge(dll_file_path, log_file);
        if (fp) {
            StringCbCopy(log_file, sizeof(log_file), fp);
            free(fp);
        }
    }
    if (get_config_parameter(src, JK_LOG_LEVEL_TAG, tmpbuf, sizeof(tmpbuf))) {
        log_level = jk_parse_log_level(tmpbuf);
    }
    if (get_config_parameter(src, LOG_ROTATION_TIME_TAG, tmpbuf, sizeof(tmpbuf))) {
        log_rotationtime = atol(tmpbuf);
        if (log_rotationtime < 0) {
            log_rotationtime = 0;
        }
    }
    if (get_config_parameter(src, LOG_FILESIZE_TAG, tmpbuf, sizeof(tmpbuf))) {
        int tl = lstrlenA(tmpbuf);
        if (tl > 0) {
            /* rotatelogs has an 'M' suffix on filesize, which we optionally support for consistency */
            if (tmpbuf[tl - 1] == 'M') {
                tmpbuf[tl - 1] = '\0';
            }
            log_filesize = atol(tmpbuf);
            if (log_filesize < 0) {
                log_filesize = 0;
            }
            /* Convert to MB as per Apache rotatelogs */
            log_filesize *= (1000 * 1000);
        }
    }

    if (!get_config_parameter(src, EXTENSION_URI_TAG, extension_uri, sizeof(extension_uri)))
        goto cleanup;
    if (!get_config_parameter(src, JK_WORKER_FILE_TAG, worker_file, sizeof(worker_file)))
        goto cleanup;
    if (is_path_relative(worker_file)) {
        char *fp = path_merge(dll_file_path, worker_file);
        if (fp) {
            StringCbCopy(worker_file, sizeof(worker_file), fp);
            free(fp);
        }
    }
    if (!get_config_parameter(src, JK_MOUNT_FILE_TAG, worker_mount_file, sizeof(worker_mount_file)))
        goto cleanup;
    if (is_path_relative(worker_mount_file)) {
        char *fp = path_merge(dll_file_path, worker_mount_file);
        if (fp) {
            StringCbCopy(worker_mount_file, sizeof(worker_mount_file), fp);
            free(fp);
        }
    }
    if (get_config_parameter(src, URI_REWRITE_TAG, rewrite_rule_file, sizeof(rewrite_rule_file))) {
        if (is_path_relative(rewrite_rule_file)) {
            char *fp = path_merge(dll_file_path, rewrite_rule_file);
            if (fp) {
                StringCbCopy(rewrite_rule_file, sizeof(rewrite_rule_file), fp);
                free(fp);
            }
        }
    }
    if (get_config_parameter(src, URI_SELECT_TAG, tmpbuf, sizeof(tmpbuf))) {
        int opt = parse_uri_select(tmpbuf);
        if (opt >= 0) {
            uri_select_option = opt;
        }
        else {
            jk_log(l, JK_LOG_ERROR, "Invalid value '%s' for configuration item '"
                   URI_SELECT_TAG "'", tmpbuf);
        }
    }
    if (get_config_parameter(src, COLLAPSE_SLASHES_TAG, tmpbuf, sizeof(tmpbuf))) {
        jk_log(l, JK_LOG_ERROR, "Configuration item '" COLLAPSE_SLASHES_TAG
               "' is deprecated and will be ignored");
    }
    shm_config_size = get_config_int(src, SHM_SIZE_TAG, -1);
    worker_mount_reload = get_config_int(src, WORKER_MOUNT_RELOAD_TAG, JK_URIMAP_DEF_RELOAD);
    strip_session = get_config_bool(src, STRIP_SESSION_TAG, JK_FALSE);
    use_auth_notification_flags = get_config_int(src, AUTH_COMPLETE_TAG, 1);
    reject_unsafe = get_config_bool(src, REJECT_UNSAFE_TAG, JK_FALSE);
    watchdog_interval = get_config_int(src, WATCHDOG_INTERVAL_TAG, 0);
    if (watchdog_interval < 0)
        watchdog_interval = 0;
    chunked_encoding_enabled = get_config_bool(src, ENABLE_CHUNKED_ENCODING_TAG, JK_FALSE);
    flush_packets = get_config_bool(src, FLUSH_PACKETS_TAG, JK_FALSE);
    if (get_config_parameter(src, ERROR_PAGE_TAG, error_page_buf, sizeof(error_page_buf))) {
        error_page = error_page_buf;
    }
    if (get_config_parameter(src, REQUEST_ID_HEADER_TAG, request_id_header_buf, sizeof(request_id_header_buf))) {
        size_t size = strlen(request_id_header_buf);
        if (size + 2 <= sizeof(request_id_header_buf)) {
            request_id_header_buf[size + 1] = '\0';
            request_id_header_buf[size] = ':';
        }
        request_id_header = request_id_header_buf;
    }
    ok = JK_TRUE;
cleanup:
    if (using_ini_file) {
        jk_map_free(&map);
    }
    else {
        RegCloseKey(hkey);
    }

    return ok;
}