Lines Matching refs:ctx

57 static const char *ap_expr_eval_string_func(ap_expr_eval_ctx_t *ctx,
60 static const char *ap_expr_eval_re_backref(ap_expr_eval_ctx_t *ctx,
62 static const char *ap_expr_eval_var(ap_expr_eval_ctx_t *ctx,
78 static int inc_rec(ap_expr_eval_ctx_t *ctx)
80 if (ctx->reclvl < AP_EXPR_MAX_RECURSION) {
81 ctx->reclvl++;
84 *ctx->err = "Recursion limit reached";
86 ctx->reclvl = INT_MAX;
90 static const char *ap_expr_eval_word(ap_expr_eval_ctx_t *ctx,
94 if (inc_rec(ctx))
102 result = ap_expr_eval_var(ctx, (ap_expr_var_func_t *)node->node_arg1,
108 const char *s1 = ap_expr_eval_word(ctx, node->node_arg1);
109 const char *s2 = ap_expr_eval_word(ctx, node->node_arg2);
115 result = apr_pstrcat(ctx->p, s1, s2, NULL);
126 vec = apr_palloc(ctx->p, i * sizeof(struct iovec));
131 vec[i].iov_base = (void *)ap_expr_eval_word(ctx,
137 vec[i].iov_base = (void *)ap_expr_eval_word(ctx, nodep);
139 result = apr_pstrcatv(ctx->p, vec, n, NULL);
149 vec = apr_palloc(ctx->p, i * sizeof(struct iovec));
153 vec[i].iov_base = (void *)ap_expr_eval_word(ctx,
159 vec[i].iov_base = (void *)ap_expr_eval_word(ctx, nodep);
162 result = apr_pstrcatv(ctx->p, vec, i, NULL);
168 result = ap_expr_eval_string_func(ctx, info, args);
173 result = ap_expr_eval_re_backref(ctx, *np);
177 *ctx->err = "Internal evaluation error: Unknown word expression node";
182 ctx->reclvl--;
186 static const char *ap_expr_eval_var(ap_expr_eval_ctx_t *ctx,
192 return (*func)(ctx, data);
195 static const char *ap_expr_eval_re_backref(ap_expr_eval_ctx_t *ctx, unsigned int n)
199 if (!ctx->re_pmatch || !ctx->re_source || *ctx->re_source == '\0' ||
200 ctx->re_nmatch < n + 1)
203 len = ctx->re_pmatch[n].rm_eo - ctx->re_pmatch[n].rm_so;
207 return apr_pstrndup(ctx->p, *ctx->re_source + ctx->re_pmatch[n].rm_so, len);
210 static const char *ap_expr_eval_string_func(ap_expr_eval_ctx_t *ctx,
222 apr_array_header_t *args = apr_array_make(ctx->p, 2, sizeof(char *));
226 *new = ap_expr_eval_word(ctx, val);
231 return (*func)(ctx, data, args);
235 return (*func)(ctx, data, ap_expr_eval_word(ctx, arg));
252 static int ap_expr_eval_comp(ap_expr_eval_ctx_t *ctx, const ap_expr_t *node)
258 return (intstrcmp(ap_expr_eval_word(ctx, e1), ap_expr_eval_word(ctx, e2)) == 0);
260 return (intstrcmp(ap_expr_eval_word(ctx, e1), ap_expr_eval_word(ctx, e2)) != 0);
262 return (intstrcmp(ap_expr_eval_word(ctx, e1), ap_expr_eval_word(ctx, e2)) < 0);
264 return (intstrcmp(ap_expr_eval_word(ctx, e1), ap_expr_eval_word(ctx, e2)) <= 0);
266 return (intstrcmp(ap_expr_eval_word(ctx, e1), ap_expr_eval_word(ctx, e2)) > 0);
268 return (intstrcmp(ap_expr_eval_word(ctx, e1), ap_expr_eval_word(ctx, e2)) >= 0);
270 return (strcmp(ap_expr_eval_word(ctx, e1), ap_expr_eval_word(ctx, e2)) == 0);
272 return (strcmp(ap_expr_eval_word(ctx, e1), ap_expr_eval_word(ctx, e2)) != 0);
274 return (strcmp(ap_expr_eval_word(ctx, e1), ap_expr_eval_word(ctx, e2)) < 0);
276 return (strcmp(ap_expr_eval_word(ctx, e1), ap_expr_eval_word(ctx, e2)) <= 0);
278 return (strcmp(ap_expr_eval_word(ctx, e1), ap_expr_eval_word(ctx, e2)) > 0);
280 return (strcmp(ap_expr_eval_word(ctx, e1), ap_expr_eval_word(ctx, e2)) >= 0);
282 const char *needle = ap_expr_eval_word(ctx, e1);
287 if (strcmp(needle, ap_expr_eval_word(ctx, val)) == 0)
300 haystack = (*func)(ctx, info->node_arg2, ap_expr_eval_word(ctx, arg));
312 const char *word = ap_expr_eval_word(ctx, e1);
321 result = (0 == ap_regexec(regex, word, ctx->re_nmatch,
322 ctx->re_pmatch, 0));
323 *ctx->re_source = result ? word : NULL;
335 *ctx->err = "Internal evaluation error: Unknown comp expression node";
364 static int ssl_expr_eval_comp(ap_expr_eval_ctx_t *ctx, const ap_expr_t *node)
371 return (strcmplex(ap_expr_eval_word(ctx, e1), ap_expr_eval_word(ctx, e2)) == 0);
374 return (strcmplex(ap_expr_eval_word(ctx, e1), ap_expr_eval_word(ctx, e2)) != 0);
377 return (strcmplex(ap_expr_eval_word(ctx, e1), ap_expr_eval_word(ctx, e2)) < 0);
380 return (strcmplex(ap_expr_eval_word(ctx, e1), ap_expr_eval_word(ctx, e2)) <= 0);
383 return (strcmplex(ap_expr_eval_word(ctx, e1), ap_expr_eval_word(ctx, e2)) > 0);
386 return (strcmplex(ap_expr_eval_word(ctx, e1), ap_expr_eval_word(ctx, e2)) >= 0);
388 return ap_expr_eval_comp(ctx, node);
401 ap_expr_parse_ctx_t ctx;
404 ctx.pool = pool;
405 ctx.ptemp = ptemp;
406 ctx.inputbuf = expr;
407 ctx.inputlen = strlen(expr);
408 ctx.inputptr = ctx.inputbuf;
409 ctx.expr = NULL;
410 ctx.error = NULL; /* generic bison error message (XXX: usually not very useful, should be axed) */
411 ctx.error2 = NULL; /* additional error message */
412 ctx.flags = info->flags;
413 ctx.scan_del = '\0';
414 ctx.scan_buf[0] = '\0';
415 ctx.scan_ptr = ctx.scan_buf;
416 ctx.lookup_fn = lookup_fn ? lookup_fn : ap_expr_lookup_default;
417 ctx.at_start = 1;
419 ap_expr_yylex_init(&ctx.scanner);
420 ap_expr_yyset_extra(&ctx, ctx.scanner);
421 rc = ap_expr_yyparse(&ctx);
422 ap_expr_yylex_destroy(ctx.scanner);
423 if (ctx.error) {
424 if (ctx.error2)
425 return apr_psprintf(pool, "%s: %s", ctx.error, ctx.error2);
427 return ctx.error;
429 else if (ctx.error2) {
430 return ctx.error2;
437 if (ctx.expr)
438 expr_dump_tree(ctx.expr, NULL, APLOG_NOTICE, 2);
441 info->root_node = ctx.expr;
467 ap_expr_parse_ctx_t *ctx)
469 ap_expr_t *node = apr_palloc(ctx->pool, sizeof(ap_expr_t));
477 ap_expr_parse_ctx_t *ctx,
480 ap_expr_t *info = apr_palloc(ctx->pool, sizeof(ap_expr_t));
483 parms.flags = ctx->flags;
484 parms.pool = ctx->pool;
485 parms.ptemp = ctx->ptemp;
489 parms.err = &ctx->error2;
509 if (ctx->lookup_fn(&parms) != OK)
515 ap_expr_parse_ctx_t *ctx)
517 ap_expr_t *info = ap_expr_info_make(AP_EXPR_FUNC_STRING, name, ctx, arg);
522 return ap_expr_make(op_StringFuncCall, info, arg, ctx);
526 ap_expr_parse_ctx_t *ctx)
528 ap_expr_t *info = ap_expr_info_make(AP_EXPR_FUNC_LIST, name, ctx, arg);
533 return ap_expr_make(op_ListFuncCall, info, arg, ctx);
537 ap_expr_parse_ctx_t *ctx)
539 ap_expr_t *info = ap_expr_info_make(AP_EXPR_FUNC_OP_UNARY, name, ctx, arg);
544 return ap_expr_make(op_UnaryOpCall, info, arg, ctx);
548 const ap_expr_t *arg2, ap_expr_parse_ctx_t *ctx)
551 ap_expr_t *info = ap_expr_info_make(AP_EXPR_FUNC_OP_BINARY, name, ctx,
557 args = ap_expr_make(op_BinaryOpArgs, arg1, arg2, ctx);
558 return ap_expr_make(op_BinaryOpCall, info, args, ctx);
562 ap_expr_t *ap_expr_var_make(const char *name, ap_expr_parse_ctx_t *ctx)
564 ap_expr_t *node = ap_expr_info_make(AP_EXPR_FUNC_VAR, name, ctx, NULL);
742 static int ap_expr_eval_unary_op(ap_expr_eval_ctx_t *ctx, const ap_expr_t *info,
751 return (*op_func)(ctx, data, ap_expr_eval_word(ctx, arg));
754 static int ap_expr_eval_binary_op(ap_expr_eval_ctx_t *ctx,
767 return (*op_func)(ctx, data, ap_expr_eval_word(ctx, a1),
768 ap_expr_eval_word(ctx, a2));
772 static int ap_expr_eval(ap_expr_eval_ctx_t *ctx, const ap_expr_t *node)
777 if (inc_rec(ctx))
794 if (!ap_expr_eval(ctx, e1->node_arg1)) {
800 if (ap_expr_eval(ctx, e1)) {
812 if (ap_expr_eval(ctx, e1->node_arg1)) {
818 if (!ap_expr_eval(ctx, e1)) {
828 result ^= ap_expr_eval_unary_op(ctx, e1, e2);
831 result ^= ap_expr_eval_binary_op(ctx, e1, e2);
834 if (ctx->info->flags & AP_EXPR_FLAG_SSL_EXPR_COMPAT)
835 result ^= ssl_expr_eval_comp(ctx, e1);
837 result ^= ap_expr_eval_comp(ctx, e1);
840 *ctx->err = "Internal evaluation error: Unknown expression node";
847 ctx->reclvl--;
857 AP_DECLARE(int) ap_expr_exec_ctx(ap_expr_eval_ctx_t *ctx)
861 AP_DEBUG_ASSERT(ctx->p != NULL);
863 AP_DEBUG_ASSERT(ctx->r != NULL);
864 AP_DEBUG_ASSERT(ctx->c != NULL);
865 AP_DEBUG_ASSERT(ctx->s != NULL);
866 AP_DEBUG_ASSERT(ctx->err != NULL);
867 AP_DEBUG_ASSERT(ctx->info != NULL);
868 if (ctx->re_pmatch) {
869 AP_DEBUG_ASSERT(ctx->re_source != NULL);
870 AP_DEBUG_ASSERT(ctx->re_nmatch > 0);
872 ctx->reclvl = 0;
874 *ctx->err = NULL;
875 if (ctx->info->flags & AP_EXPR_FLAG_STRING_RESULT) {
876 *ctx->result_string = ap_expr_eval_word(ctx, ctx->info->root_node);
877 if (*ctx->err != NULL) {
878 ap_log_rerror(LOG_MARK(ctx->info), APLOG_ERR, 0, ctx->r,
880 ctx->info->filename, ctx->info->line_number, *ctx->err);
883 ap_log_rerror(LOG_MARK(ctx->info), APLOG_TRACE4, 0, ctx->r,
885 ctx->info->filename, ctx->info->line_number,
886 *ctx->result_string);
891 rc = ap_expr_eval(ctx, ctx->info->root_node);
892 if (*ctx->err != NULL) {
893 ap_log_rerror(LOG_MARK(ctx->info), APLOG_ERR, 0, ctx->r,
895 ctx->info->filename, ctx->info->line_number, *ctx->err);
899 ap_log_rerror(LOG_MARK(ctx->info), APLOG_TRACE4, 0, ctx->r,
901 ctx->info->filename, ctx->info->line_number, rc);
903 if (ctx->vary_this && *ctx->vary_this)
904 apr_table_merge(ctx->r->headers_out, "Vary", *ctx->vary_this);
915 ap_expr_eval_ctx_t ctx;
922 ctx.r = r;
923 ctx.c = r->connection;
924 ctx.s = r->server;
925 ctx.p = r->pool;
926 ctx.err = err;
927 ctx.info = info;
928 ctx.re_nmatch = nmatch;
929 ctx.re_pmatch = pmatch;
930 ctx.re_source = source;
931 ctx.vary_this = dont_vary ? NULL : &vary_this;
932 ctx.data = NULL;
935 ctx.re_nmatch = AP_MAX_REG_MATCH;
936 ctx.re_pmatch = tmp_pmatch;
937 ctx.re_source = &tmp_source;
940 return ap_expr_exec_ctx(&ctx);
950 ap_expr_eval_ctx_t ctx;
969 ctx.r = r;
970 ctx.c = r->connection;
971 ctx.s = r->server;
972 ctx.p = r->pool;
973 ctx.err = err;
974 ctx.info = info;
975 ctx.re_nmatch = nmatch;
976 ctx.re_pmatch = pmatch;
977 ctx.re_source = source;
978 ctx.vary_this = dont_vary ? NULL : &vary_this;
979 ctx.data = NULL;
980 ctx.result_string = &result;
983 ctx.re_nmatch = AP_MAX_REG_MATCH;
984 ctx.re_pmatch = tmp_pmatch;
985 ctx.re_source = &tmp_source;
988 rc = ap_expr_exec_ctx(&ctx);
1007 static void add_vary(ap_expr_eval_ctx_t *ctx, const char *name)
1009 if (!ctx->vary_this)
1012 if (*ctx->vary_this) {
1013 *ctx->vary_this = apr_pstrcat(ctx->p, *ctx->vary_this, ", ", name,
1017 *ctx->vary_this = name;
1021 static const char *req_table_func(ap_expr_eval_ctx_t *ctx, const void *data,
1026 if (!ctx->r)
1031 const char *v = apr_table_get(ctx->r->headers_out, arg);
1035 t = ctx->r->err_headers_out;
1038 t = ctx->r->notes;
1040 t = ctx->r->subprocess_env;
1042 t = ctx->r->headers_in;
1044 t = ctx->r->headers_in;
1045 add_vary(ctx, arg);
1050 static const char *env_func(ap_expr_eval_ctx_t *ctx, const void *data,
1055 if (ctx->r) {
1056 if ((res = apr_table_get(ctx->r->notes, arg)) != NULL)
1058 else if ((res = apr_table_get(ctx->r->subprocess_env, arg)) != NULL)
1064 static const char *osenv_func(ap_expr_eval_ctx_t *ctx, const void *data,
1070 static const char *tolower_func(ap_expr_eval_ctx_t *ctx, const void *data,
1073 char *result = apr_pstrdup(ctx->p, arg);
1078 static const char *toupper_func(ap_expr_eval_ctx_t *ctx, const void *data,
1081 char *result = apr_pstrdup(ctx->p, arg);
1086 static const char *escape_func(ap_expr_eval_ctx_t *ctx, const void *data,
1089 return ap_escape_uri(ctx->p, arg);
1092 static const char *base64_func(ap_expr_eval_ctx_t *ctx, const void *data,
1095 return ap_pbase64encode(ctx->p, (char *)arg);
1098 static const char *unbase64_func(ap_expr_eval_ctx_t *ctx, const void *data,
1101 return ap_pbase64decode(ctx->p, arg);
1104 static const char *sha1_func(ap_expr_eval_ctx_t *ctx, const void *data,
1111 out = apr_palloc(ctx->p, APR_SHA1_DIGESTSIZE*2+1);
1122 static const char *md5_func(ap_expr_eval_ctx_t *ctx, const void *data,
1125 return ap_md5(ctx->p, (const unsigned char *)arg);
1129 static const char *ldap_func(ap_expr_eval_ctx_t *ctx, const void *data,
1132 return apr_pescape_ldap(ctx->p, arg, APR_ESCAPE_STRING, APR_ESCAPE_LDAP_ALL);
1151 static const char *replace_func(ap_expr_eval_ctx_t *ctx, const void *data,
1162 *ctx->err = apr_psprintf(ctx->p, "replace() function needs "
1174 ap_varbuf_init(ctx->p, &vb, 0);
1187 return ap_varbuf_pdup(ctx->p, &vb, NULL, 0, buff, bytes, &len);
1191 static const char *file_func(ap_expr_eval_ctx_t *ctx, const void *data,
1201 APR_OS_DEFAULT, ctx->p) != APR_SUCCESS) {
1202 *ctx->err = apr_psprintf(ctx->p, "Cannot open file %s", arg);
1207 *ctx->err = apr_psprintf(ctx->p, "File %s too large", arg);
1217 if ((buf = (char *)apr_palloc(ctx->p, sizeof(char)*(len+1))) == NULL) {
1218 *ctx->err = "Cannot allocate memory";
1225 *ctx->err = apr_psprintf(ctx->p, "Cannot read from file %s", arg);
1235 static const char *filesize_func(ap_expr_eval_ctx_t *ctx, const void *data,
1239 if (apr_stat(&sb, arg, APR_FINFO_MIN, ctx->p) == APR_SUCCESS
1241 return apr_psprintf(ctx->p, "%" APR_OFF_T_FMT, sb.size);
1246 static const char *filemod_func(ap_expr_eval_ctx_t *ctx, const void *data,
1250 if (apr_stat(&sb, arg, APR_FINFO_MIN, ctx->p) == APR_SUCCESS
1252 return apr_psprintf(ctx->p, "%" APR_OFF_T_FMT, sb.mtime);
1258 static const char *unescape_func(ap_expr_eval_ctx_t *ctx, const void *data,
1261 char *result = apr_pstrdup(ctx->p, arg);
1265 ap_log_rerror(LOG_MARK(ctx->info), APLOG_DEBUG, 0, ctx->r, APLOGNO(00538)
1268 ctx->info->filename, ctx->info->line_number);
1272 static int op_nz(ap_expr_eval_ctx_t *ctx, const void *data, const char *arg)
1281 static int op_file_min(ap_expr_eval_ctx_t *ctx, const void *data, const char *arg)
1285 if (apr_stat(&sb, arg, APR_FINFO_MIN, ctx->p) != APR_SUCCESS)
1302 static int op_file_link(ap_expr_eval_ctx_t *ctx, const void *data, const char *arg)
1306 if (apr_stat(&sb, arg, APR_FINFO_MIN | APR_FINFO_LINK, ctx->p) == APR_SUCCESS
1314 static int op_file_xbit(ap_expr_eval_ctx_t *ctx, const void *data, const char *arg)
1317 if (apr_stat(&sb, arg, APR_FINFO_PROT| APR_FINFO_LINK, ctx->p) == APR_SUCCESS
1324 static int op_url_subr(ap_expr_eval_ctx_t *ctx, const void *data, const char *arg)
1327 request_rec *rsub, *r = ctx->r;
1338 ap_log_rerror(LOG_MARK(ctx->info), APLOG_TRACE5, 0, r,
1340 arg, ctx->info->filename, ctx->info->line_number,
1346 static int op_file_subr(ap_expr_eval_ctx_t *ctx, const void *data, const char *arg)
1350 request_rec *rsub, *r = ctx->r;
1356 apr_stat(&sb, rsub->filename, APR_FINFO_MIN, ctx->p) == APR_SUCCESS) {
1359 ap_log_rerror(LOG_MARK(ctx->info), APLOG_TRACE5, 0, r,
1361 arg, ctx->info->filename, ctx->info->line_number,
1379 static const char *conn_var_fn(ap_expr_eval_ctx_t *ctx, const void *data)
1382 conn_rec *c = ctx->c;
1451 static const char *request_var_fn(ap_expr_eval_ctx_t *ctx, const void *data)
1454 request_rec *r = ctx->r;
1479 return apr_psprintf(ctx->p, "%u", ap_get_server_port(r));
1506 apr_uid_name_get(&result, r->finfo.user, ctx->p);
1513 apr_gid_name_get(&result, r->finfo.group, ctx->p);
1522 return apr_psprintf(ctx->p, "%02d%02d%02d%02d%02d%02d%02d",
1532 return r->status ? apr_psprintf(ctx->p, "%d", r->status) : "";
1541 return apr_psprintf(ctx->p, "%d", r->proto_num);
1547 return apr_psprintf(ctx->p, "%d", HTTP_VERSION_MAJOR(r->proto_num));
1554 return apr_psprintf(ctx->p, "%d", HTTP_VERSION_MINOR(r->proto_num));
1582 static const char *req_header_var_fn(ap_expr_eval_ctx_t *ctx, const void *data)
1589 if (!ctx->r)
1593 add_vary(ctx, name);
1594 return apr_table_get(ctx->r->headers_in, name);
1611 static const char *misc_var_fn(ap_expr_eval_ctx_t *ctx, const void *data)
1619 return apr_psprintf(ctx->p, "%02d%02d", (tm.tm_year / 100) + 19,
1622 return apr_psprintf(ctx->p, "%02d", tm.tm_mon+1);
1624 return apr_psprintf(ctx->p, "%02d", tm.tm_mday);
1626 return apr_psprintf(ctx->p, "%02d", tm.tm_hour);
1628 return apr_psprintf(ctx->p, "%02d", tm.tm_min);
1630 return apr_psprintf(ctx->p, "%02d", tm.tm_sec);
1632 return apr_psprintf(ctx->p, "%d", tm.tm_wday);
1634 return apr_psprintf(ctx->p, "%02d%02d%02d%02d%02d%02d%02d",
1641 return apr_itoa(ctx->p, MODULE_MAGIC_NUMBER_MAJOR);
1679 static int op_ipmatch(ap_expr_eval_ctx_t *ctx, const void *data, const char *arg1,
1688 if (apr_sockaddr_info_get(&saddr, arg1, APR_UNSPEC, 0, 0, ctx->p) != APR_SUCCESS)
1694 static int op_R(ap_expr_eval_ctx_t *ctx, const void *data, const char *arg1)
1700 if (!ctx->r)
1703 return apr_ipsubnet_test(subnet, ctx->r->useragent_addr);
1706 static int op_T(ap_expr_eval_ctx_t *ctx, const void *data, const char *arg)
1727 static int op_fnmatch(ap_expr_eval_ctx_t *ctx, const void *data,
1733 static int op_strmatch(ap_expr_eval_ctx_t *ctx, const void *data,
1739 static int op_strcmatch(ap_expr_eval_ctx_t *ctx, const void *data,