📄 config.c
字号:
/* This could be called from an AddModule httpd.conf command, * after the file has been linked and the module structure within it * teased out... */ if (m->version != MODULE_MAGIC_NUMBER_MAJOR) { ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL, "%s: module \"%s\" is not compatible with this " "version of Apache (found %d, need %d).", ap_server_argv0, m->name, m->version, MODULE_MAGIC_NUMBER_MAJOR); ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL, "Please contact the vendor for the correct version."); exit(1); } if (m->next == NULL) { m->next = ap_top_module; ap_top_module = m; } if (m->module_index == -1) { m->module_index = total_modules++; dynamic_modules++; if (dynamic_modules > DYNAMIC_MODULE_LIMIT) { ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL, "%s: module \"%s\" could not be loaded, because" " the dynamic", ap_server_argv0, m->name); ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL, "module limit was reached. Please increase " "DYNAMIC_MODULE_LIMIT and recompile."); exit(1); } } /* Some C compilers put a complete path into __FILE__, but we want * only the filename (e.g. mod_includes.c). So check for path * components (Unix and DOS), and remove them. */ if (ap_strrchr_c(m->name, '/')) m->name = 1 + ap_strrchr_c(m->name, '/'); if (ap_strrchr_c(m->name, '\\')) m->name = 1 + ap_strrchr_c(m->name, '\\');#ifdef _OSD_POSIX /* __FILE__ = * "*POSIX(/home/martin/apache/src/modules/standard/mod_info.c)" */ /* We cannot fix the string in-place, because it's const */ if (m->name[strlen(m->name)-1] == ')') { char *tmp = strdup(m->name); /* FIXME: memory leak, albeit a small one */ tmp[strlen(tmp)-1] = '\0'; m->name = tmp; }#endif /*_OSD_POSIX*/ /* FIXME: is this the right place to call this? * It doesn't appear to be */ ap_register_hooks(m, p);}/* * remove_module undoes what add_module did. There are some caveats: * when the module is removed, its slot is lost so all the current * per-dir and per-server configurations are invalid. So we should * only ever call this function when you are invalidating almost * all our current data. I.e. when doing a restart. */AP_DECLARE(void) ap_remove_module(module *m){ module *modp; modp = ap_top_module; if (modp == m) { /* We are the top module, special case */ ap_top_module = modp->next; m->next = NULL; } else { /* Not the top module, find use. When found modp will * point to the module _before_ us in the list */ while (modp && modp->next != m) { modp = modp->next; } if (!modp) { /* Uh-oh, this module doesn't exist */ ap_log_error(APLOG_MARK, APLOG_ERR, 0, NULL, "Cannot remove module %s: not found in module list", m->name); return; } /* Eliminate us from the module list */ modp->next = modp->next->next; } m->module_index = -1; /* simulate being unloaded, should * be unnecessary */ dynamic_modules--; total_modules--;}AP_DECLARE(void) ap_add_loaded_module(module *mod, apr_pool_t *p){ module **m; /* * Add module pointer to top of chained module list */ ap_add_module(mod, p); /* * And module pointer to list of loaded modules * * Notes: 1. ap_add_module() would already complain if no more space * exists for adding a dynamically loaded module * 2. ap_add_module() accepts double inclusion, so we have * to accept this, too. */ for (m = ap_loaded_modules; *m != NULL; m++) ; *m++ = mod; *m = NULL;}AP_DECLARE(void) ap_remove_loaded_module(module *mod){ module **m; module **m2; int done; /* * Remove module pointer from chained module list */ ap_remove_module(mod); /* * Remove module pointer from list of loaded modules * * Note: 1. We cannot determine if the module was successfully * removed by ap_remove_module(). * 2. We have not to complain explicity when the module * is not found because ap_remove_module() did it * for us already. */ for (m = m2 = ap_loaded_modules, done = 0; *m2 != NULL; m2++) { if (*m2 == mod && done == 0) done = 1; else *m++ = *m2; } *m = NULL;}AP_DECLARE(void) ap_setup_prelinked_modules(process_rec *process){ module **m; module **m2; apr_hook_global_pool=process->pconf; /* * Initialise total_modules variable and module indices */ total_modules = 0; for (m = ap_preloaded_modules; *m != NULL; m++) (*m)->module_index = total_modules++; /* * Initialise list of loaded modules */ ap_loaded_modules = (module **)apr_palloc(process->pool, sizeof(module *) * (total_modules + DYNAMIC_MODULE_LIMIT + 1)); if (ap_loaded_modules == NULL) { ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL, "Ouch! Out of memory in ap_setup_prelinked_modules()!"); } for (m = ap_preloaded_modules, m2 = ap_loaded_modules; *m != NULL; ) *m2++ = *m++; *m2 = NULL; /* * Initialize chain of linked (=activate) modules */ for (m = ap_prelinked_modules; *m != NULL; m++) ap_add_module(*m, process->pconf); apr_hook_sort_all();}AP_DECLARE(const char *) ap_find_module_name(module *m){ return m->name;}AP_DECLARE(module *) ap_find_linked_module(const char *name){ module *modp; for (modp = ap_top_module; modp; modp = modp->next) { if (strcmp(modp->name, name) == 0) return modp; } return NULL;}/* Add a named module. Returns 1 if module found, 0 otherwise. */AP_DECLARE(int) ap_add_named_module(const char *name, apr_pool_t *p){ module *modp; int i = 0; for (modp = ap_loaded_modules[i]; modp; modp = ap_loaded_modules[++i]) { if (strcmp(modp->name, name) == 0) { /* Only add modules that are not already enabled. */ if (modp->next == NULL) { ap_add_module(modp, p); } return 1; } } return 0;}/***************************************************************** * * Resource, access, and .htaccess config files now parsed by a common * command loop. * * Let's begin with the basics; parsing the line and * invoking the function... */static const char *invoke_cmd(const command_rec *cmd, cmd_parms *parms, void *mconfig, const char *args){ char *w, *w2, *w3; const char *errmsg = NULL; if ((parms->override & cmd->req_override) == 0) return apr_pstrcat(parms->pool, cmd->name, " not allowed here", NULL); parms->info = cmd->cmd_data; parms->cmd = cmd; switch (cmd->args_how) { case RAW_ARGS:#ifdef RESOLVE_ENV_PER_TOKEN args = ap_resolve_env(parms->pool,args);#endif return cmd->AP_RAW_ARGS(parms, mconfig, args); case NO_ARGS: if (*args != 0) return apr_pstrcat(parms->pool, cmd->name, " takes no arguments", NULL); return cmd->AP_NO_ARGS(parms, mconfig); case TAKE1: w = ap_getword_conf(parms->pool, &args); if (*w == '\0' || *args != 0) return apr_pstrcat(parms->pool, cmd->name, " takes one argument", cmd->errmsg ? ", " : NULL, cmd->errmsg, NULL); return cmd->AP_TAKE1(parms, mconfig, w); case TAKE2: w = ap_getword_conf(parms->pool, &args); w2 = ap_getword_conf(parms->pool, &args); if (*w == '\0' || *w2 == '\0' || *args != 0) return apr_pstrcat(parms->pool, cmd->name, " takes two arguments", cmd->errmsg ? ", " : NULL, cmd->errmsg, NULL); return cmd->AP_TAKE2(parms, mconfig, w, w2); case TAKE12: w = ap_getword_conf(parms->pool, &args); w2 = ap_getword_conf(parms->pool, &args); if (*w == '\0' || *args != 0) return apr_pstrcat(parms->pool, cmd->name, " takes 1-2 arguments", cmd->errmsg ? ", " : NULL, cmd->errmsg, NULL); return cmd->AP_TAKE2(parms, mconfig, w, *w2 ? w2 : NULL); case TAKE3: w = ap_getword_conf(parms->pool, &args); w2 = ap_getword_conf(parms->pool, &args); w3 = ap_getword_conf(parms->pool, &args); if (*w == '\0' || *w2 == '\0' || *w3 == '\0' || *args != 0) return apr_pstrcat(parms->pool, cmd->name, " takes three arguments", cmd->errmsg ? ", " : NULL, cmd->errmsg, NULL); return cmd->AP_TAKE3(parms, mconfig, w, w2, w3); case TAKE23: w = ap_getword_conf(parms->pool, &args); w2 = ap_getword_conf(parms->pool, &args); w3 = *args ? ap_getword_conf(parms->pool, &args) : NULL; if (*w == '\0' || *w2 == '\0' || *args != 0) return apr_pstrcat(parms->pool, cmd->name, " takes two or three arguments", cmd->errmsg ? ", " : NULL, cmd->errmsg, NULL); return cmd->AP_TAKE3(parms, mconfig, w, w2, w3); case TAKE123: w = ap_getword_conf(parms->pool, &args); w2 = *args ? ap_getword_conf(parms->pool, &args) : NULL; w3 = *args ? ap_getword_conf(parms->pool, &args) : NULL; if (*w == '\0' || *args != 0) return apr_pstrcat(parms->pool, cmd->name, " takes one, two or three arguments", cmd->errmsg ? ", " : NULL, cmd->errmsg, NULL); return cmd->AP_TAKE3(parms, mconfig, w, w2, w3); case TAKE13: w = ap_getword_conf(parms->pool, &args); w2 = *args ? ap_getword_conf(parms->pool, &args) : NULL; w3 = *args ? ap_getword_conf(parms->pool, &args) : NULL; if (*w == '\0' || (w2 && *w2 && !w3) || *args != 0) return apr_pstrcat(parms->pool, cmd->name, " takes one or three arguments", cmd->errmsg ? ", " : NULL, cmd->errmsg, NULL); return cmd->AP_TAKE3(parms, mconfig, w, w2, w3); case ITERATE: while (*(w = ap_getword_conf(parms->pool, &args)) != '\0') { errmsg = cmd->AP_TAKE1(parms, mconfig, w); if (errmsg && strcmp(errmsg, DECLINE_CMD) != 0) return errmsg; } return errmsg; case ITERATE2: w = ap_getword_conf(parms->pool, &args); if (*w == '\0' || *args == 0) return apr_pstrcat(parms->pool, cmd->name, " requires at least two arguments", cmd->errmsg ? ", " : NULL, cmd->errmsg, NULL); while (*(w2 = ap_getword_conf(parms->pool, &args)) != '\0') { errmsg = cmd->AP_TAKE2(parms, mconfig, w, w2); if (errmsg && strcmp(errmsg, DECLINE_CMD) != 0) return errmsg; } return errmsg; case FLAG: w = ap_getword_conf(parms->pool, &args); if (*w == '\0' || (strcasecmp(w, "on") && strcasecmp(w, "off"))) return apr_pstrcat(parms->pool, cmd->name, " must be On or Off", NULL); return cmd->AP_FLAG(parms, mconfig, strcasecmp(w, "off") != 0); default: return apr_pstrcat(parms->pool, cmd->name, " is improperly configured internally (server bug)", NULL); }}AP_CORE_DECLARE(const command_rec *) ap_find_command(const char *name, const command_rec *cmds){ while (cmds->name) { if (!strcasecmp(name, cmds->name)) return cmds; ++cmds; } return NULL;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -