📄 mod_include.c
字号:
continue; } } if (!current->right->done) { switch (current->right->token.type) { case token_string: parse_string(r, current->right->token.value, buffer, sizeof(buffer), 0); ap_cpystrn(current->right->token.value, buffer, sizeof(current->right->token.value)); current->right->value = (current->right->token.value[0] != '\0'); current->right->done = 1; break; default: current = current->right; continue; } }#ifdef DEBUG_INCLUDE ap_rvputs(r, " Left: ", current->left->value ? "1" : "0", "\n", NULL); ap_rvputs(r, " Right: ", current->right->value ? "1" : "0", "\n", NULL);#endif if (current->token.type == token_and) { current->value = current->left->value && current->right->value; } else { current->value = current->left->value || current->right->value; }#ifdef DEBUG_INCLUDE ap_rvputs(r, " Returning ", current->value ? "1" : "0", "\n", NULL);#endif current->done = 1; current = current->parent; break; case token_eq: case token_ne:#ifdef DEBUG_INCLUDE ap_rputs(" Evaluate eq/ne\n", r);#endif if ((current->left == (struct parse_node *) NULL) || (current->right == (struct parse_node *) NULL) || (current->left->token.type != token_string) || (current->right->token.type != token_string)) { ap_log_rerror(APLOG_MARK, APLOG_NOERRNO|APLOG_ERR, r, "Invalid expression \"%s\" in file %s", expr, r->filename); ap_rputs(error, r); goto RETURN; } parse_string(r, current->left->token.value, buffer, sizeof(buffer), 0); ap_cpystrn(current->left->token.value, buffer, sizeof(current->left->token.value)); parse_string(r, current->right->token.value, buffer, sizeof(buffer), 0); ap_cpystrn(current->right->token.value, buffer, sizeof(current->right->token.value)); if (current->right->token.value[0] == '/') { int len; len = strlen(current->right->token.value); if (current->right->token.value[len - 1] == '/') { current->right->token.value[len - 1] = '\0'; } else { ap_log_rerror(APLOG_MARK, APLOG_NOERRNO|APLOG_ERR, r, "Invalid rexp \"%s\" in file %s", current->right->token.value, r->filename); ap_rputs(error, r); goto RETURN; }#ifdef DEBUG_INCLUDE ap_rvputs(r, " Re Compare (", current->left->token.value, ") with /", ¤t->right->token.value[1], "/\n", NULL);#endif current->value = re_check(r, current->left->token.value, ¤t->right->token.value[1]); } else {#ifdef DEBUG_INCLUDE ap_rvputs(r, " Compare (", current->left->token.value, ") with (", current->right->token.value, ")\n", NULL);#endif current->value = (strcmp(current->left->token.value, current->right->token.value) == 0); } if (current->token.type == token_ne) { current->value = !current->value; }#ifdef DEBUG_INCLUDE ap_rvputs(r, " Returning ", current->value ? "1" : "0", "\n", NULL);#endif current->done = 1; current = current->parent; break; case token_ge: case token_gt: case token_le: case token_lt:#ifdef DEBUG_INCLUDE ap_rputs(" Evaluate ge/gt/le/lt\n", r);#endif if ((current->left == (struct parse_node *) NULL) || (current->right == (struct parse_node *) NULL) || (current->left->token.type != token_string) || (current->right->token.type != token_string)) { ap_log_rerror(APLOG_MARK, APLOG_NOERRNO|APLOG_ERR, r, "Invalid expression \"%s\" in file %s", expr, r->filename); ap_rputs(error, r); goto RETURN; } parse_string(r, current->left->token.value, buffer, sizeof(buffer), 0); ap_cpystrn(current->left->token.value, buffer, sizeof(current->left->token.value)); parse_string(r, current->right->token.value, buffer, sizeof(buffer), 0); ap_cpystrn(current->right->token.value, buffer, sizeof(current->right->token.value));#ifdef DEBUG_INCLUDE ap_rvputs(r, " Compare (", current->left->token.value, ") with (", current->right->token.value, ")\n", NULL);#endif current->value = strcmp(current->left->token.value, current->right->token.value); if (current->token.type == token_ge) { current->value = current->value >= 0; } else if (current->token.type == token_gt) { current->value = current->value > 0; } else if (current->token.type == token_le) { current->value = current->value <= 0; } else if (current->token.type == token_lt) { current->value = current->value < 0; } else { current->value = 0; /* Don't return -1 if unknown token */ }#ifdef DEBUG_INCLUDE ap_rvputs(r, " Returning ", current->value ? "1" : "0", "\n", NULL);#endif current->done = 1; current = current->parent; break; case token_not: if (current->right != (struct parse_node *) NULL) { if (!current->right->done) { current = current->right; continue; } current->value = !current->right->value; } else { current->value = 0; }#ifdef DEBUG_INCLUDE ap_rvputs(r, " Evaluate !: ", current->value ? "1" : "0", "\n", NULL);#endif current->done = 1; current = current->parent; break; case token_group: if (current->right != (struct parse_node *) NULL) { if (!current->right->done) { current = current->right; continue; } current->value = current->right->value; } else { current->value = 1; }#ifdef DEBUG_INCLUDE ap_rvputs(r, " Evaluate (): ", current->value ? "1" : "0", "\n", NULL);#endif current->done = 1; current = current->parent; break; case token_lbrace: ap_log_rerror(APLOG_MARK, APLOG_NOERRNO|APLOG_ERR, r, "Unmatched '(' in \"%s\" in file %s", expr, r->filename); ap_rputs(error, r); goto RETURN; case token_rbrace: ap_log_rerror(APLOG_MARK, APLOG_NOERRNO|APLOG_ERR, r, "Unmatched ')' in \"%s\" in file %s", expr, r->filename); ap_rputs(error, r); goto RETURN; default: ap_log_rerror(APLOG_MARK, APLOG_NOERRNO|APLOG_ERR, r, "bad token type"); ap_rputs(error, r); goto RETURN; } } retval = (root == (struct parse_node *) NULL) ? 0 : root->value; RETURN: ap_destroy_pool(expr_pool); return (retval);}static int handle_if(FILE *in, request_rec *r, const char *error, int *conditional_status, int *printing){ char tag[MAX_STRING_LEN]; char *tag_val; char *expr; expr = NULL; while (1) { tag_val = get_tag(r, in, tag, sizeof(tag), 0); if (!tag_val || *tag == '\0') { return 1; } else if (!strcmp(tag, "done")) { if (expr == NULL) { ap_log_rerror(APLOG_MARK, APLOG_NOERRNO|APLOG_ERR, r, "missing expr in if statement: %s", r->filename); ap_rputs(error, r); return 1; } *printing = *conditional_status = parse_expr(r, expr, error);#ifdef DEBUG_INCLUDE ap_rvputs(r, "**** if conditional_status=\"", *conditional_status ? "1" : "0", "\"\n", NULL);#endif return 0; } else if (!strcmp(tag, "expr")) { expr = tag_val;#ifdef DEBUG_INCLUDE ap_rvputs(r, "**** if expr=\"", expr, "\"\n", NULL);#endif } else { ap_log_rerror(APLOG_MARK, APLOG_NOERRNO|APLOG_ERR, r, "unknown parameter \"%s\" to tag if in %s", tag, r->filename); ap_rputs(error, r); } }}static int handle_elif(FILE *in, request_rec *r, const char *error, int *conditional_status, int *printing){ char tag[MAX_STRING_LEN]; char *tag_val; char *expr; expr = NULL; while (1) { tag_val = get_tag(r, in, tag, sizeof(tag), 0); if (!tag_val || *tag == '\0') { return 1; } else if (!strcmp(tag, "done")) {#ifdef DEBUG_INCLUDE ap_rvputs(r, "**** elif conditional_status=\"", *conditional_status ? "1" : "0", "\"\n", NULL);#endif if (*conditional_status) { *printing = 0; return (0); } if (expr == NULL) { ap_log_rerror(APLOG_MARK, APLOG_NOERRNO|APLOG_ERR, r, "missing expr in elif statement: %s", r->filename); ap_rputs(error, r); return 1; } *printing = *conditional_status = parse_expr(r, expr, error);#ifdef DEBUG_INCLUDE ap_rvputs(r, "**** elif conditional_status=\"", *conditional_status ? "1" : "0", "\"\n", NULL);#endif return 0; } else if (!strcmp(tag, "expr")) { expr = tag_val;#ifdef DEBUG_INCLUDE ap_rvputs(r, "**** if expr=\"", expr, "\"\n", NULL);#endif } else { ap_log_rerror(APLOG_MARK, APLOG_NOERRNO|APLOG_ERR, r, "unknown parameter \"%s\" to tag if in %s", tag, r->filename); ap_rputs(error, r); } }}static int handle_else(FILE *in, request_rec *r, const char *error, int *conditional_status, int *printing){ char tag[MAX_STRING_LEN]; if (!get_tag(r, in, tag, sizeof(tag), 1)) { return 1; } else if (!strcmp(tag, "done")) {#ifdef DEBUG_INCLUDE ap_rvputs(r, "**** else conditional_status=\"", *conditional_status ? "1" : "0", "\"\n", NULL);#endif *printing = !(*conditional_status); *conditional_status = 1; return 0; } else { ap_log_rerror(APLOG_MARK, APLOG_NOERRNO|APLOG_ERR, r, "else directive does not take tags in %s", r->filename); if (*printing) { ap_rputs(error, r); } return -1; }}static int handle_endif(FILE *in, request_rec *r, const char *error, int *conditional_status, int *printing){ char tag[MAX_STRING_LEN]; if (!get_tag(r, in, tag, sizeof(tag), 1)) { return 1; } else if (!strcmp(tag, "done")) {#ifdef DEBUG_INCLUDE ap_rvputs(r, "**** endif conditional_status=\"", *conditional_status ? "1" : "0", "\"\n", NULL);#endif *printing = 1; *conditional_status = 1; return 0; } else { ap_log_rerror(APLOG_MARK, APLOG_NOERRNO|APLOG_ERR, r, "endif directive does not take tags in %s", r->filename); ap_rputs(error, r); return -1; }}static int handle_set(FILE *in, request_rec *r, const char *error){ char tag[MAX_STRING_LEN]; char parsed_string[MAX_STRING_LEN]; char *tag_val; char *var; var = (char *) NULL; while (1) { if (!(tag_val = get_tag(r, in, tag, sizeof(tag), 1))) { return 1; } else if (!strcmp(tag, "done")) { return 0; } else if (!strcmp(tag, "var")) { var = tag_val; } else if (!strcmp(tag, "value")) { if (var == (char *) NULL) { ap_log_rerror(APLOG_MARK, APLOG_NOERRNO|APLOG_ERR, r, "variable must precede value in set directive in %s", r->filename); ap_rputs(error, r); return -1; } parse_string(r, tag_val, parsed_string, sizeof(parsed_string), 0); ap_table_setn(r->subprocess_env, var, ap_pstrdup(r->pool, parsed_string)); } else { ap_log_rerror(APLOG_MARK, APLOG_NOERRNO|APLOG_ERR, r, "Invalid tag for set directive in %s", r->filename); ap_rputs(error, r); return -1; } }}static int handle_printenv(FILE *in, request_rec *r, const char *error){ char tag[MAX_STRING_LEN]; char *tag_val; array_header *arr = ap_table_elts(r->subprocess_env); table_entry *elts = (table_entry *) arr->elts; int i; if (!(tag_val = get_tag(r, in, tag, sizeof(tag), 1))) { return 1; } else if (!strcmp(tag, "done")) { for (i = 0; i < arr->nelts; ++i) { ap_rvputs(r, ap_escape_html(r->pool, elts[i].key), "=", ap_escape_html(r->pool, elts[i].val), "\n", NULL); } return 0; }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -