[mod_cgi] skip local-redir handling if to self (fixes #2779, #2108)
[lighttpd.git] / src / mod_ssi_exprparser.y
blobee40912bb15d108238ae9a931176383bcd0c2db0
1 %token_prefix TK_
2 %token_type {buffer *}
3 %extra_argument {ssi_ctx_t *ctx}
4 %name ssiexprparser
6 %include {
7 #include "first.h"
8 #include "mod_ssi_expr.h"
9 #include "buffer.h"
11 #include <assert.h>
12 #include <string.h>
15 %parse_failure {
16 ctx->ok = 0;
19 %type expr { ssi_val_t * }
20 %type value { buffer * }
21 %type exprline { ssi_val_t * }
22 %type cond { int }
23 %token_destructor { buffer_free($$); }
25 %left AND.
26 %left OR.
27 %nonassoc EQ NE GT GE LT LE.
28 %right NOT.
30 input ::= exprline(B). {
31 ctx->val.bo = ssi_val_tobool(B);
32 ctx->val.type = SSI_TYPE_BOOL;
34 ssi_val_free(B);
37 exprline(A) ::= expr(B) cond(C) expr(D). {
38 int cmp;
40 if (B->type == SSI_TYPE_STRING &&
41 D->type == SSI_TYPE_STRING) {
42 cmp = strcmp(B->str->ptr, D->str->ptr);
43 } else {
44 cmp = ssi_val_tobool(B) - ssi_val_tobool(D);
47 A = B;
49 switch(C) {
50 case SSI_COND_EQ: A->bo = (cmp == 0) ? 1 : 0; break;
51 case SSI_COND_NE: A->bo = (cmp != 0) ? 1 : 0; break;
52 case SSI_COND_GE: A->bo = (cmp >= 0) ? 1 : 0; break;
53 case SSI_COND_GT: A->bo = (cmp > 0) ? 1 : 0; break;
54 case SSI_COND_LE: A->bo = (cmp <= 0) ? 1 : 0; break;
55 case SSI_COND_LT: A->bo = (cmp < 0) ? 1 : 0; break;
58 A->type = SSI_TYPE_BOOL;
60 ssi_val_free(D);
62 exprline(A) ::= expr(B). {
63 A = B;
65 expr(A) ::= expr(B) AND expr(C). {
66 int e;
68 e = ssi_val_tobool(B) && ssi_val_tobool(C);
70 A = B;
71 A->bo = e;
72 A->type = SSI_TYPE_BOOL;
73 ssi_val_free(C);
76 expr(A) ::= expr(B) OR expr(C). {
77 int e;
79 e = ssi_val_tobool(B) || ssi_val_tobool(C);
81 A = B;
82 A->bo = e;
83 A->type = SSI_TYPE_BOOL;
84 ssi_val_free(C);
87 expr(A) ::= NOT expr(B). {
88 int e;
90 e = !ssi_val_tobool(B);
92 A = B;
93 A->bo = e;
94 A->type = SSI_TYPE_BOOL;
96 expr(A) ::= LPARAN exprline(B) RPARAN. {
97 A = B;
100 expr(A) ::= value(B). {
101 A = ssi_val_init();
102 A->str = B;
103 A->type = SSI_TYPE_STRING;
106 value(A) ::= VALUE(B). {
107 A = B;
110 value(A) ::= value(B) VALUE(C). {
111 A = B;
112 buffer_append_string_buffer(A, C);
113 buffer_free(C);
116 cond(A) ::= EQ. { A = SSI_COND_EQ; }
117 cond(A) ::= NE. { A = SSI_COND_NE; }
118 cond(A) ::= LE. { A = SSI_COND_LE; }
119 cond(A) ::= GE. { A = SSI_COND_GE; }
120 cond(A) ::= LT. { A = SSI_COND_LT; }
121 cond(A) ::= GT. { A = SSI_COND_GT; }