From: André Malo Date: Fri, 22 Aug 2003 21:46:00 +0000 (+0000) Subject: cleanup handle_elif function. It now allow only one argument as well. X-Git-Tag: pre_ajp_proxy~1237 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=2a338e2abaa3bc230c2eefead6585aeb8e34310a;p=apache cleanup handle_elif function. It now allow only one argument as well. git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@101065 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/modules/filters/mod_include.c b/modules/filters/mod_include.c index 3bf2a2b812..dcfca6be75 100644 --- a/modules/filters/mod_include.c +++ b/modules/filters/mod_include.c @@ -2195,74 +2195,87 @@ static apr_status_t handle_if(include_ctx_t *ctx, ap_filter_t *f, return APR_SUCCESS; } +/* + * + */ static apr_status_t handle_elif(include_ctx_t *ctx, ap_filter_t *f, apr_bucket_brigade *bb) { - char *tag = NULL; - char *tag_val = NULL; - char *expr = NULL; - int expr_ret, was_error, was_unmatched; - char debug_buf[MAX_DEBUG_SIZE]; + char *tag = NULL; + char *expr = NULL; request_rec *r = f->r; + char debug_buf[MAX_DEBUG_SIZE]; + int expr_ret, was_error, was_unmatched; - if (!ctx->if_nesting_level) { - while (1) { - ap_ssi_get_tag_and_value(ctx, &tag, &tag_val, SSI_VALUE_RAW); - if (!tag) { - LOG_COND_STATUS(ctx, f, bb, " elif"); - - if (ctx->flags & SSI_FLAG_COND_TRUE) { - ctx->flags &= SSI_FLAG_CLEAR_PRINTING; - return APR_SUCCESS; - } - if (!expr) { - ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, - "missing expr in elif statement: %s", - r->filename); - SSI_CREATE_ERROR_BUCKET(ctx, f, bb); - return APR_SUCCESS; - } - expr_ret = parse_expr(r, ctx, expr, &was_error, - &was_unmatched, debug_buf); - if (was_error) { - SSI_CREATE_ERROR_BUCKET(ctx, f, bb); - return APR_SUCCESS; - } - if (was_unmatched) { - DUMP_PARSE_EXPR_DEBUG("\nUnmatched '\n", f, bb); - } - DUMP_PARSE_EXPR_DEBUG(debug_buf, f, bb); - - if (expr_ret) { - ctx->flags |= (SSI_FLAG_PRINTING | SSI_FLAG_COND_TRUE); - } - else { - ctx->flags &= SSI_FLAG_CLEAR_PRINT_COND; - } - LOG_COND_STATUS(ctx, f, bb, " elif"); - return APR_SUCCESS; - } - else if (!strcmp(tag, "expr")) { - expr = tag_val; + if (ctx->argc != 1) { + ap_log_rerror(APLOG_MARK, + (!(ctx->if_nesting_level)) ? APLOG_ERR : APLOG_WARNING, + 0, r, (ctx->argc) + ? "too many arguments for if element in %s" + : "missing expr argument for if element in %s", + r->filename); + } + + if (ctx->if_nesting_level) { + return APR_SUCCESS; + } + + if (ctx->argc != 1) { + SSI_CREATE_ERROR_BUCKET(ctx, f, bb); + return APR_SUCCESS; + } + + ap_ssi_get_tag_and_value(ctx, &tag, &expr, SSI_VALUE_RAW); + + if (strcmp(tag, "expr")) { + ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, "unknown parameter \"%s\" " + "to tag if in %s", tag, r->filename); + SSI_CREATE_ERROR_BUCKET(ctx, f, bb); + return APR_SUCCESS; + } + + if (!expr) { + ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, "missing expr in elif " + "statement: %s", r->filename); + SSI_CREATE_ERROR_BUCKET(ctx, f, bb); + return APR_SUCCESS; + } #ifdef DEBUG_INCLUDE - if (1) { - apr_bucket *tmp_buck; - apr_size_t d_len = 0; - d_len = sprintf(debug_buf, "**** elif expr=\"%s\"\n", expr); - tmp_buck = apr_bucket_heap_create(debug_buf, d_len, NULL, - r->connection->bucket_alloc); - APR_BRIGADE_INSERT_TAIL(bb, tmp_buck); - } + do { + apr_size_t d_len = 0; + d_len = sprintf(debug_buf, "**** elif expr=\"%s\"\n", expr); + APR_BRIGADE_INSERT_TAIL(bb, apr_bucket_heap_create(debug_buf, d_len, + NULL, f->c->bucket_alloc)); + } while (0); #endif - } - else { - ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, - "unknown parameter \"%s\" to tag if in %s", tag, - r->filename); - SSI_CREATE_ERROR_BUCKET(ctx, f, bb); - } - } + + LOG_COND_STATUS(ctx, f, bb, " elif"); + + if (ctx->flags & SSI_FLAG_COND_TRUE) { + ctx->flags &= SSI_FLAG_CLEAR_PRINTING; + return APR_SUCCESS; + } + + expr_ret = parse_expr(r, ctx, expr, &was_error, &was_unmatched, debug_buf); + + if (was_error) { + SSI_CREATE_ERROR_BUCKET(ctx, f, bb); + return APR_SUCCESS; + } + + if (was_unmatched) { + DUMP_PARSE_EXPR_DEBUG("\nUnmatched '\n", f, bb); } + DUMP_PARSE_EXPR_DEBUG(debug_buf, f, bb); + + if (expr_ret) { + ctx->flags |= (SSI_FLAG_PRINTING | SSI_FLAG_COND_TRUE); + } + else { + ctx->flags &= SSI_FLAG_CLEAR_PRINT_COND; + } + + LOG_COND_STATUS(ctx, f, bb, " elif"); return APR_SUCCESS; }