📄 config.c
字号:
int offset = (int)(long)cmd->info; path = ap_server_root_relative(cmd->pool, arg); if (!path) { return apr_pstrcat(cmd->pool, "Invalid file path ", arg, NULL); } *(const char **) ((char*)struct_ptr + offset) = path; return NULL;}AP_DECLARE_NONSTD(const char *) ap_set_deprecated(cmd_parms *cmd, void *struct_ptr, const char *arg){ return cmd->cmd->errmsg;}/***************************************************************** * * Reading whole config files... */static cmd_parms default_parms ={NULL, 0, -1, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL};AP_DECLARE(char *) ap_server_root_relative(apr_pool_t *p, const char *file){ char *newpath = NULL; apr_status_t rv; rv = apr_filepath_merge(&newpath, ap_server_root, file, APR_FILEPATH_TRUENAME, p); if (newpath && (rv == APR_SUCCESS || APR_STATUS_IS_EPATHWILD(rv) || APR_STATUS_IS_ENOENT(rv) || APR_STATUS_IS_ENOTDIR(rv))) { return newpath; } else { return NULL; }}AP_DECLARE(const char *) ap_soak_end_container(cmd_parms *cmd, char *directive){ char l[MAX_STRING_LEN]; const char *args; char *cmd_name; while(!(ap_cfg_getline(l, MAX_STRING_LEN, cmd->config_file))) {#if RESOLVE_ENV_PER_TOKEN args = l;#else args = ap_resolve_env(cmd->temp_pool, l);#endif cmd_name = ap_getword_conf(cmd->pool, &args); if (cmd_name[0] == '<') { if (cmd_name[1] == '/') { cmd_name[strlen(cmd_name) - 1] = '\0'; if (strcasecmp(cmd_name + 2, directive + 1) != 0) { return apr_pstrcat(cmd->pool, "Expected </", directive + 1, "> but saw ", cmd_name, ">", NULL); } return NULL; /* found end of container */ } else { const char *msg; if (*args == '\0' && cmd_name[strlen(cmd_name) - 1] == '>') { cmd_name[strlen(cmd_name) - 1] = '\0'; } if ((msg = ap_soak_end_container(cmd, cmd_name)) != NULL) { return msg; } } } } return apr_pstrcat(cmd->pool, "Expected </", directive + 1, "> before end of configuration", NULL);}static const char *execute_now(char *cmd_line, const char *args, cmd_parms *parms, apr_pool_t *p, apr_pool_t *ptemp, ap_directive_t **sub_tree, ap_directive_t *parent){ module *mod = ap_top_module; const command_rec *cmd; if (!(cmd = ap_find_command_in_modules(cmd_line, &mod))) { return apr_pstrcat(parms->pool, "Invalid command '", cmd_line, "', perhaps mis-spelled or defined by a module " "not included in the server configuration", NULL); } else { return invoke_cmd(cmd, parms, sub_tree, args); }}/* This structure and the following functions are needed for the * table-based config file reading. They are passed to the * cfg_open_custom() routine. *//* Structure to be passed to cfg_open_custom(): it contains an * index which is incremented from 0 to nelts on each call to * cfg_getline() (which in turn calls arr_elts_getstr()) * and an apr_array_header_t pointer for the string array. */typedef struct { apr_array_header_t *array; int curr_idx;} arr_elts_param_t;/* arr_elts_getstr() returns the next line from the string array. */static void *arr_elts_getstr(void *buf, size_t bufsiz, void *param){ arr_elts_param_t *arr_param = (arr_elts_param_t *)param; /* End of array reached? */ if (++arr_param->curr_idx > arr_param->array->nelts) return NULL; /* return the line */ apr_cpystrn(buf, ((char **)arr_param->array->elts)[arr_param->curr_idx - 1], bufsiz); return buf;}/* arr_elts_close(): dummy close routine (makes sure no more lines can be read) */static int arr_elts_close(void *param){ arr_elts_param_t *arr_param = (arr_elts_param_t *)param; arr_param->curr_idx = arr_param->array->nelts; return 0;}static void process_command_config(server_rec *s, apr_array_header_t *arr, ap_directive_t **conftree, apr_pool_t *p, apr_pool_t *ptemp){ const char *errmsg; cmd_parms parms; arr_elts_param_t arr_parms; arr_parms.curr_idx = 0; arr_parms.array = arr; parms = default_parms; parms.pool = p; parms.temp_pool = ptemp; parms.server = s; parms.override = (RSRC_CONF | OR_ALL) & ~(OR_AUTHCFG | OR_LIMIT); parms.config_file = ap_pcfg_open_custom(p, "-c/-C directives", &arr_parms, NULL, arr_elts_getstr, arr_elts_close); errmsg = ap_build_config(&parms, p, ptemp, conftree); if (errmsg) { ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL, "Syntax error in -C/-c directive:" APR_EOL_STR "%s", errmsg); exit(1); } ap_cfg_closefile(parms.config_file);}typedef struct { char *fname;} fnames;static int fname_alphasort(const void *fn1, const void *fn2){ const fnames *f1 = fn1; const fnames *f2 = fn2; return strcmp(f1->fname,f2->fname);}static void process_resource_config_nofnmatch(server_rec *s, const char *fname, ap_directive_t **conftree, apr_pool_t *p, apr_pool_t *ptemp, unsigned depth){ cmd_parms parms; ap_configfile_t *cfp; const char *errmsg; if (ap_is_directory(p, fname)) { apr_dir_t *dirp; apr_finfo_t dirent; int current; apr_array_header_t *candidates = NULL; fnames *fnew; apr_status_t rv; char errmsg[120], *path = apr_pstrdup(p, fname); if (++depth > AP_MAX_INCLUDE_DIR_DEPTH) { fprintf(stderr, "%s: Directory %s exceeds the maximum include " "directory nesting level of %u. You have probably a " "recursion somewhere.\n", ap_server_argv0, path, AP_MAX_INCLUDE_DIR_DEPTH); exit(1); } /* * first course of business is to grok all the directory * entries here and store 'em away. Recall we need full pathnames * for this. */ rv = apr_dir_open(&dirp, path, p); if (rv != APR_SUCCESS) { fprintf(stderr, "%s: could not open config directory %s: %s\n", ap_server_argv0, path, apr_strerror(rv, errmsg, sizeof errmsg)); exit(1); } candidates = apr_array_make(p, 1, sizeof(fnames)); while (apr_dir_read(&dirent, APR_FINFO_DIRENT, dirp) == APR_SUCCESS) { /* strip out '.' and '..' */ if (strcmp(dirent.name, ".") && strcmp(dirent.name, "..")) { fnew = (fnames *) apr_array_push(candidates); fnew->fname = ap_make_full_path(p, path, dirent.name); } } apr_dir_close(dirp); if (candidates->nelts != 0) { qsort((void *) candidates->elts, candidates->nelts, sizeof(fnames), fname_alphasort); /* * Now recurse these... we handle errors and subdirectories * via the recursion, which is nice */ for (current = 0; current < candidates->nelts; ++current) { fnew = &((fnames *) candidates->elts)[current]; process_resource_config_nofnmatch(s, fnew->fname, conftree, p, ptemp, depth); } } return; } /* GCC's initialization extensions are soooo nice here... */ parms = default_parms; parms.pool = p; parms.temp_pool = ptemp; parms.server = s; parms.override = (RSRC_CONF | OR_ALL) & ~(OR_AUTHCFG | OR_LIMIT); if (ap_pcfg_openfile(&cfp, p, fname) != APR_SUCCESS) { ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL, "%s: could not open document config file %s", ap_server_argv0, fname); exit(1); } parms.config_file = cfp; errmsg = ap_build_config(&parms, p, ptemp, conftree); if (errmsg != NULL) { ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL, "Syntax error on line %d of %s:", parms.err_directive->line_num, parms.err_directive->filename); ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL, "%s", errmsg); exit(1); } ap_cfg_closefile(cfp); return;}AP_DECLARE(void) ap_process_resource_config(server_rec *s, const char *fname, ap_directive_t **conftree, apr_pool_t *p, apr_pool_t *ptemp){ /* XXX: lstat() won't work on the wildcard pattern... */ /* don't require conf/httpd.conf if we have a -C or -c switch */ if ((ap_server_pre_read_config->nelts || ap_server_post_read_config->nelts) && !(strcmp(fname, ap_server_root_relative(p, SERVER_CONFIG_FILE)))) { apr_finfo_t finfo; if (apr_lstat(&finfo, fname, APR_FINFO_TYPE, p) != APR_SUCCESS) return; } if (!apr_fnmatch_test(fname)) { process_resource_config_nofnmatch(s, fname, conftree, p, ptemp, 0); } else { apr_dir_t *dirp; apr_finfo_t dirent; int current; apr_array_header_t *candidates = NULL; fnames *fnew; apr_status_t rv; char errmsg[120], *path = apr_pstrdup(p, fname), *pattern = NULL; pattern = ap_strrchr(path, '/'); AP_DEBUG_ASSERT(pattern != NULL); /* path must be absolute. */ *pattern++ = '\0'; if (apr_fnmatch_test(path)) { fprintf(stderr, "%s: wildcard patterns not allowed in Include " "%s\n", ap_server_argv0, fname); exit(1); } if (!ap_is_directory(p, path)){ fprintf(stderr, "%s: Include directory '%s' not found", ap_server_argv0, path); exit(1); } if (!apr_fnmatch_test(pattern)) { fprintf(stderr, "%s: must include a wildcard pattern " "for Include %s\n", ap_server_argv0, fname); exit(1); } /* * first course of business is to grok all the directory * entries here and store 'em away. Recall we need full pathnames * for this. */ rv = apr_dir_open(&dirp, path, p); if (rv != APR_SUCCESS) { fprintf(stderr, "%s: could not open config directory %s: %s\n", ap_server_argv0, path, apr_strerror(rv, errmsg, sizeof errmsg)); exit(1); } candidates = apr_array_make(p, 1, sizeof(fnames)); while (apr_dir_read(&dirent, APR_FINFO_DIRENT, dirp) == APR_SUCCESS) { /* strip out '.' and '..' */ if (strcmp(dirent.name, ".") && strcmp(dirent.name, "..") && (apr_fnmatch(pattern, dirent.name, FNM_PERIOD) == APR_SUCCESS)) { fnew = (fnames *) apr_array_push(candidates); fnew->fname = ap_make_full_path(p, path, dirent.name); } } apr_dir_close(dirp); if (candidates->nelts != 0) { qsort((void *) candidates->elts, candidates->nelts, sizeof(fnames), fname_alphasort); /* * Now recurse these... we handle errors and subdirectories * via the recursion, which is nice */ for (current = 0; current < candidates->nelts; ++current) { fnew = &((fnames *) candidates->elts)[current]; process_resource_config_nofnmatch(s, fnew->fname, conftree, p, ptemp, 0); } } } return;}AP_DECLARE(void) ap_process_config_tree(server_rec *s, ap_directive_t *conftree, apr_pool_t *p, apr_pool_t *ptemp){ const char *errmsg; cmd_parms parms; parms = default_parms; parms.pool = p;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -