/* Licensed to the Apache Software Foundation (ASF) under one or more *contributorlicenseagreements.SeetheNOTICEfiledistributedwith *thisworkforadditionalinformationregardingcopyrightownership. *TheASFlicensesthisfiletoYouundertheApacheLicense,Version2.0 *(the"License");youmaynotusethisfileexceptincompliancewith *theLicense.YoumayobtainacopyoftheLicenseat * *http://www.apache.org/licenses/LICENSE-2.0 * *Unlessrequiredbyapplicablelaworagreedtoinwriting,software *distributedundertheLicenseisdistributedonan"ASIS"BASIS, *WITHOUTWARRANTIESORCONDITIONSOFANYKIND,eitherexpressorimplied. *SeetheLicenseforthespecificlanguagegoverningpermissionsand *limitationsundertheLicense.
*/
staticint is_header_regex(apr_pool_t *p, constchar* name)
{ /* If a Header name contains characters other than: *-,_,[A-Z\,[a-z]and[0-9]. *assumetheheadernameisaregularexpression.
*/ if (ap_regexec(is_header_regex_regex, name, 0, NULL, 0)) { return1;
}
return0;
}
/* If the input string does not take advantage of regular *expressionmetacharacters,returnapointertoanequivalent *stringthatcanbesearchedusingapr_strmatch().(The *returnedstringwilloftenbetheinputstring.Butif *theinputstringcontainsescapedcharacters,thereturned *stringwillbeacopywiththeescapesremoved.)
*/ staticconstchar *non_regex_pattern(apr_pool_t *p, constchar *s)
{ constchar *src = s; int escapes_found = 0; int in_escape = 0;
/* *Ifwe'vealreadygotasei_entrywiththesamenamewewantto *justcopythenamepointer...sothatlateronwecancompare *twoheadernamesjustbycomparingthepointers.
*/ for (i = 0; i < sconf->conditionals->nelts; ++i) { new = &entries[i]; if (new->name && !strcasecmp(new->name, fname)) {
fname = new->name; break;
}
}
/* if the last entry has an identical headername and regex then *mergewithit
*/
i = sconf->conditionals->nelts - 1;
icase = cmd->info == ICASE_MAGIC; if (i < 0
|| entries[i].name != fname
|| entries[i].icase != icase
|| strcmp(entries[i].regex, regex)) {
/* no match, create a new entry */ new = apr_array_push(sconf->conditionals); new->name = fname; new->regex = regex; new->icase = icase; if ((simple_pattern = non_regex_pattern(cmd->pool, regex))) { new->pattern = apr_strmatch_precompile(cmd->pool,
simple_pattern, !icase); if (new->pattern == NULL) { return apr_pstrcat(cmd->pool, cmd->cmd->name, " pattern could not be compiled.", NULL);
} new->preg = NULL;
} else { new->preg = ap_pregcomp(cmd->pool, regex,
(AP_REG_EXTENDED | (icase ? AP_REG_ICASE : 0))); if (new->preg == NULL) { return apr_pstrcat(cmd->pool, cmd->cmd->name, " regex could not be compiled.", NULL);
} new->pattern = NULL;
} new->features = apr_table_make(cmd->pool, 2);
staticconst command_rec setenvif_module_cmds[] =
{
AP_INIT_RAW_ARGS("SetEnvIf", add_setenvif, NULL, OR_FILEINFO, "A header-name, regex and a list of variables."),
AP_INIT_RAW_ARGS("SetEnvIfNoCase", add_setenvif, ICASE_MAGIC, OR_FILEINFO, "a header-name, regex and a list of variables."),
AP_INIT_RAW_ARGS("SetEnvIfExpr", add_setenvifexpr, NULL, OR_FILEINFO, "an expression and a list of variables."),
AP_INIT_RAW_ARGS("BrowserMatch", add_browser, NULL, OR_FILEINFO, "A browser regex and a list of variables."),
AP_INIT_RAW_ARGS("BrowserMatchNoCase", add_browser, ICASE_MAGIC,
OR_FILEINFO, "A browser regex and a list of variables."),
{ NULL },
};
if (!ap_get_module_config(r->request_config, &setenvif_module)) {
ap_set_module_config(r->request_config, &setenvif_module,
SEI_MAGIC_HEIRLOOM);
sconf = (sei_cfg_rec *) ap_get_module_config(r->server->module_config,
&setenvif_module);
} else {
sconf = (sei_cfg_rec *) ap_get_module_config(r->per_dir_config,
&setenvif_module);
}
entries = (sei_entry *) sconf->conditionals->elts;
last_name = NULL;
val = NULL; for (i = 0; i < sconf->conditionals->nelts; ++i) {
sei_entry *b = &entries[i];
if (!b->expr) { /* Optimize the case where a bunch of directives in a row use the *sameheader.Rememberwedon'tneedtostrcmpthetwoheader *namesbecausewemadesurethepointerswereequalduring *configuration.
*/ if (b->name != last_name) {
last_name = b->name; switch (b->special_type) { case SPECIAL_REMOTE_ADDR:
val = r->useragent_ip; break; case SPECIAL_SERVER_ADDR:
val = r->connection->local_ip; break; case SPECIAL_REMOTE_HOST:
val = ap_get_useragent_host(r, REMOTE_NAME, NULL); break; case SPECIAL_REQUEST_URI:
val = r->uri; break; case SPECIAL_REQUEST_METHOD:
val = r->method; break; case SPECIAL_REQUEST_PROTOCOL:
val = r->protocol; break; case SPECIAL_NOT: if (b->pnamereg) { /* Matching headers_in against a regex. Iterate through *theheaders_inuntilwefindamatchorrunoutof *headers.
*/ const apr_array_header_t
*arr = apr_table_elts(r->headers_in);
elts = (const apr_table_entry_t *) arr->elts;
val = NULL; for (j = 0; j < arr->nelts; ++j) { if (!ap_regexec(b->pnamereg, elts[j].key, 0, NULL, 0)) {
val = elts[j].val;
}
}
} else { /* Not matching against a regex */
val = apr_table_get(r->headers_in, b->name); if (val == NULL) {
val = apr_table_get(r->subprocess_env, b->name);
}
}
}
val_len = val ? strlen(val) : 0;
}
}
/* *ANULLvalueindicatesthattheheaderfieldorspecialentity *wasn'tpresentorisundefined.Representthatasanemptystring *sothatREslike"^$"willworkandallowenvariablesetting *basedonmissingoremptyfield.Thisisalsonecessarytomake *ap_pregsubworkafterevaluatinganap_expr_twhichdoessetthe *regexpbackrefdata.
*/ if (val == NULL) {
val = "";
val_len = 0;
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.