📄 config.c
字号:
AP_CORE_DECLARE(const command_rec *) ap_find_command_in_modules( const char *cmd_name, module **mod){ const command_rec *cmdp; module *modp; for (modp = *mod; modp; modp = modp->next) { if (modp->cmds && (cmdp = ap_find_command(cmd_name, modp->cmds))) { *mod = modp; return cmdp; } } return NULL;}AP_CORE_DECLARE(void *) ap_set_config_vectors(server_rec *server, ap_conf_vector_t *section_vector, const char *section, module *mod, apr_pool_t *pconf){ void *section_config = ap_get_module_config(section_vector, mod); void *server_config = ap_get_module_config(server->module_config, mod); if (!section_config && mod->create_dir_config) { /* ### need to fix the create_dir_config functions' prototype... */ section_config = (*mod->create_dir_config)(pconf, (char *)section); ap_set_module_config(section_vector, mod, section_config); } if (!server_config && mod->create_server_config) { server_config = (*mod->create_server_config)(pconf, server); ap_set_module_config(server->module_config, mod, server_config); } return section_config;}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);static const char *ap_build_config_sub(apr_pool_t *p, apr_pool_t *temp_pool, const char *l, cmd_parms *parms, ap_directive_t **current, ap_directive_t **curr_parent, ap_directive_t **conftree){ const char *retval = NULL; const char *args; char *cmd_name; ap_directive_t *newdir; module *mod = ap_top_module; const command_rec *cmd; if (*l == '#' || *l == '\0') return NULL;#if RESOLVE_ENV_PER_TOKEN args = l;#else args = ap_resolve_env(temp_pool, l);#endif cmd_name = ap_getword_conf(p, &args); if (*cmd_name == '\0') { /* Note: this branch should not occur. An empty line should have * triggered the exit further above. */ return NULL; } if (cmd_name[1] != '/') { char *lastc = cmd_name + strlen(cmd_name) - 1; if (*lastc == '>') { *lastc = '\0' ; } if (cmd_name[0] == '<' && *args == '\0') { args = ">"; } } newdir = apr_pcalloc(p, sizeof(ap_directive_t)); newdir->filename = parms->config_file->name; newdir->line_num = parms->config_file->line_number; newdir->directive = cmd_name; newdir->args = apr_pstrdup(p, args); if ((cmd = ap_find_command_in_modules(cmd_name, &mod)) != NULL) { if (cmd->req_override & EXEC_ON_READ) { ap_directive_t *sub_tree = NULL; parms->err_directive = newdir; retval = execute_now(cmd_name, args, parms, p, temp_pool, &sub_tree, *curr_parent); if (*current) { (*current)->next = sub_tree; } else { *current = sub_tree; if (*curr_parent) { (*curr_parent)->first_child = (*current); } if (*current) { (*current)->parent = (*curr_parent); } } if (*current) { if (!*conftree) { /* Before walking *current to the end of the list, * set the head to *current. */ *conftree = *current; } while ((*current)->next != NULL) { (*current) = (*current)->next; (*current)->parent = (*curr_parent); } } return retval; } } if (cmd_name[0] == '<') { if (cmd_name[1] != '/') { (*current) = ap_add_node(curr_parent, *current, newdir, 1); } else if (*curr_parent == NULL) { parms->err_directive = newdir; return apr_pstrcat(p, cmd_name, " without matching <", cmd_name + 2, " section", NULL); } else { char *bracket = cmd_name + strlen(cmd_name) - 1; if (*bracket != '>') { parms->err_directive = newdir; return apr_pstrcat(p, cmd_name, "> directive missing closing '>'", NULL); } *bracket = '\0'; if (strcasecmp(cmd_name + 2, (*curr_parent)->directive + 1) != 0) { parms->err_directive = newdir; return apr_pstrcat(p, "Expected </", (*curr_parent)->directive + 1, "> but saw ", cmd_name, ">", NULL); } *bracket = '>'; /* done with this section; move up a level */ *current = *curr_parent; *curr_parent = (*current)->parent; } } else { *current = ap_add_node(curr_parent, *current, newdir, 0); } return retval;}AP_DECLARE(const char *) ap_build_cont_config(apr_pool_t *p, apr_pool_t *temp_pool, cmd_parms *parms, ap_directive_t **current, ap_directive_t **curr_parent, char *orig_directive){ char *l; char *bracket; const char *retval; ap_directive_t *sub_tree = NULL; /* Since this function can be called recursively, allocate * the temporary 8k string buffer from the temp_pool rather * than the stack to avoid over-running a fixed length stack. */ l = apr_palloc(temp_pool, MAX_STRING_LEN); bracket = apr_pstrcat(p, orig_directive + 1, ">", NULL); while (!(ap_cfg_getline(l, MAX_STRING_LEN, parms->config_file))) { if (!memcmp(l, "</", 2) && (strcasecmp(l + 2, bracket) == 0) && (*curr_parent == NULL)) { break; } retval = ap_build_config_sub(p, temp_pool, l, parms, current, curr_parent, &sub_tree); if (retval != NULL) return retval; if (sub_tree == NULL && curr_parent != NULL) { sub_tree = *curr_parent; } if (sub_tree == NULL && current != NULL) { sub_tree = *current; } } *current = sub_tree; return NULL;}static const char *ap_walk_config_sub(const ap_directive_t *current, cmd_parms *parms, ap_conf_vector_t *section_vector){ module *mod = ap_top_module; while (1) { const command_rec *cmd; if (!(cmd = ap_find_command_in_modules(current->directive, &mod))) { parms->err_directive = current; return apr_pstrcat(parms->pool, "Invalid command '", current->directive, "', perhaps mis-spelled or defined by a module " "not included in the server configuration", NULL); } else { void *dir_config = ap_set_config_vectors(parms->server, section_vector, parms->path, mod, parms->pool); const char *retval; /* Once was enough? */ if (cmd->req_override & EXEC_ON_READ) { return NULL; } retval = invoke_cmd(cmd, parms, dir_config, current->args); if (retval == NULL) { return NULL; } if (strcmp(retval, DECLINE_CMD) != 0) { /* If the directive in error has already been set, don't * replace it. Otherwise, an error inside a container * will be reported as occuring on the first line of the * container. */ if (!parms->err_directive) { parms->err_directive = current; } return retval; } mod = mod->next; /* Next time around, skip this one */ } } /* NOTREACHED */}AP_DECLARE(const char *) ap_walk_config(ap_directive_t *current, cmd_parms *parms, ap_conf_vector_t *section_vector){ ap_conf_vector_t *oldconfig = parms->context; parms->context = section_vector; /* scan through all directives, executing each one */ for (; current != NULL; current = current->next) { const char *errmsg; parms->directive = current; /* actually parse the command and execute the correct function */ errmsg = ap_walk_config_sub(current, parms, section_vector); if (errmsg != NULL) { /* restore the context (just in case) */ parms->context = oldconfig; return errmsg; } } parms->context = oldconfig; return NULL;}AP_DECLARE(const char *) ap_build_config(cmd_parms *parms, apr_pool_t *p, apr_pool_t *temp_pool, ap_directive_t **conftree){ ap_directive_t *current = *conftree; ap_directive_t *curr_parent = NULL; char *l = apr_palloc (temp_pool, MAX_STRING_LEN); const char *errmsg; if (current != NULL) { while (current->next) { current = current->next; } } while (!(ap_cfg_getline(l, MAX_STRING_LEN, parms->config_file))) { errmsg = ap_build_config_sub(p, temp_pool, l, parms, ¤t, &curr_parent, conftree); if (errmsg != NULL) return errmsg; if (*conftree == NULL && curr_parent != NULL) { *conftree = curr_parent; } if (*conftree == NULL && current != NULL) { *conftree = current; } } if (curr_parent != NULL) { errmsg = ""; while (curr_parent != NULL) { errmsg = apr_psprintf(p, "%s%s%s:%u: %s> was not closed.", errmsg, *errmsg == '\0' ? "" : APR_EOL_STR, curr_parent->filename, curr_parent->line_num, curr_parent->directive); parms->err_directive = curr_parent; curr_parent = curr_parent->parent; } return errmsg; } return NULL;}/* * Generic command functions... */AP_DECLARE_NONSTD(const char *) ap_set_string_slot(cmd_parms *cmd, void *struct_ptr, const char *arg){ int offset = (int)(long)cmd->info; *(const char **)((char *)struct_ptr + offset) = arg; return NULL;}AP_DECLARE_NONSTD(const char *) ap_set_int_slot(cmd_parms *cmd, void *struct_ptr, const char *arg){ char *endptr; char *error_str = NULL; int offset = (int)(long)cmd->info; *(int *)((char*)struct_ptr + offset) = strtol(arg, &endptr, 10); if ((*arg == '\0') || (*endptr != '\0')) { error_str = apr_psprintf(cmd->pool, "Invalid value for directive %s, expected integer", cmd->directive->directive); } return error_str;}AP_DECLARE_NONSTD(const char *) ap_set_string_slot_lower(cmd_parms *cmd, void *struct_ptr, const char *arg_){ char *arg = apr_pstrdup(cmd->pool,arg_); int offset = (int)(long)cmd->info; ap_str_tolower(arg); *(char **)((char *)struct_ptr + offset) = arg; return NULL;}AP_DECLARE_NONSTD(const char *) ap_set_flag_slot(cmd_parms *cmd, void *struct_ptr_v, int arg){ int offset = (int)(long)cmd->info; char *struct_ptr = (char *)struct_ptr_v; *(int *)(struct_ptr + offset) = arg ? 1 : 0; return NULL;}AP_DECLARE_NONSTD(const char *) ap_set_file_slot(cmd_parms *cmd, void *struct_ptr, const char *arg){ /* Prepend server_root to relative arg. * This allows most args to be independent of server_root, * so the server can be moved or mirrored with less pain. */ const char *path;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -