Browse Source

[mod_ssi] remove mod_ssi parser generator file

master
Glenn Strauss 3 months ago
parent
commit
457362cbe3
  1. 4
      src/CMakeLists.txt
  2. 20
      src/Makefile.am
  3. 3
      src/SConscript
  4. 8
      src/meson.build
  5. 36
      src/mod_ssi_expr.c
  6. 35
      src/mod_ssi_expr.h
  7. 120
      src/mod_ssi_exprparser.y
  8. 3
      src/t/test_mod_ssi.c

4
src/CMakeLists.txt

@ -783,7 +783,6 @@ add_executable(lemon lemon.c)
## Build parsers by using lemon...
lemon_parser(configparser.y)
lemon_parser(mod_ssi_exprparser.y)
set(L_INSTALL_TARGETS)
@ -839,7 +838,7 @@ add_and_install_library(mod_secdownload "mod_secdownload.c;algo_hmac.c")
add_and_install_library(mod_setenv mod_setenv.c)
add_and_install_library(mod_simple_vhost mod_simple_vhost.c)
add_and_install_library(mod_sockproxy mod_sockproxy.c)
add_and_install_library(mod_ssi "mod_ssi_exprparser.c;mod_ssi_expr.c;mod_ssi.c")
add_and_install_library(mod_ssi "mod_ssi_expr.c;mod_ssi.c")
add_and_install_library(mod_staticfile mod_staticfile.c)
add_and_install_library(mod_status mod_status.c)
add_and_install_library(mod_uploadprogress mod_uploadprogress.c)
@ -961,7 +960,6 @@ add_test(NAME test_mod_simple_vhost COMMAND test_mod_simple_vhost)
add_executable(test_mod_ssi
t/test_mod_ssi.c
mod_ssi_exprparser.c
request.c
base64.c
buffer.c

20
src/Makefile.am

@ -64,15 +64,10 @@ configparser.c: $(srcdir)/configparser.y $(srcdir)/lempar.c lemon$(BUILD_EXEEXT)
rm -f configparser.h
$(LEMON) -q $(srcdir)/configparser.y $(srcdir)/lempar.c
mod_ssi_exprparser.h: mod_ssi_exprparser.c
mod_ssi_exprparser.c: $(srcdir)/mod_ssi_exprparser.y $(srcdir)/lempar.c lemon$(BUILD_EXEEXT)
rm -f mod_ssi_exprparser.h
$(LEMON) -q $(srcdir)/mod_ssi_exprparser.y $(srcdir)/lempar.c
parsers: configparser.c mod_ssi_exprparser.c
parsers: configparser.c
BUILT_SOURCES = parsers versionstamp
MAINTAINERCLEANFILES = configparser.c configparser.h mod_ssi_exprparser.c mod_ssi_exprparser.h
MAINTAINERCLEANFILES = configparser.c configparser.h
CLEANFILES = versionstamp.h versionstamp.h.tmp lemon$(BUILD_EXEEXT)
common_src=base64.c buffer.c burl.c log.c \
@ -287,7 +282,7 @@ mod_sockproxy_la_LDFLAGS = $(common_module_ldflags)
mod_sockproxy_la_LIBADD = $(common_libadd)
lib_LTLIBRARIES += mod_ssi.la
mod_ssi_la_SOURCES = mod_ssi_exprparser.c mod_ssi_expr.c mod_ssi.c
mod_ssi_la_SOURCES = mod_ssi_expr.c mod_ssi.c
mod_ssi_la_LDFLAGS = $(common_module_ldflags)
mod_ssi_la_LIBADD = $(common_libadd)
@ -483,9 +478,9 @@ hdr = base64.h buffer.h burl.h network.h log.h http_kv.h keyvalue.h \
plugin.h plugin_config.h \
http_etag.h array.h vector.h \
fdevent_impl.h network_write.h configfile.h \
mod_ssi.h mod_ssi_expr.h \
mod_ssi.h \
sock_addr_cache.h \
configparser.h mod_ssi_exprparser.h \
configparser.h \
rand.h \
sys-crypto.h sys-crypto-md.h \
sys-endian.h sys-mmap.h sys-socket.h sys-strings.h sys-time.h \
@ -533,7 +528,7 @@ lighttpd_SOURCES = \
mod_secdownload.c algo_hmac.c \
mod_setenv.c \
mod_simple_vhost.c \
mod_ssi_exprparser.c mod_ssi_expr.c mod_ssi.c \
mod_ssi_expr.c mod_ssi.c \
mod_staticfile.c \
mod_status.c \
mod_uploadprogress.c \
@ -672,8 +667,6 @@ t_test_mod_indexfile_LDADD = $(LIBUNWIND_LIBS) $(FAM_LIBS)
t_test_mod_simple_vhost_SOURCES = t/test_mod_simple_vhost.c buffer.c array.c log.c fdlog.c ck.c
t_test_mod_simple_vhost_LDADD = $(LIBUNWIND_LIBS)
t_test_mod_ssi_CPPFLAGS = -DINCLUDE_MOD_SSI_EXPRPARSER_C
t_test_mod_ssi_DEPENDENCIES = mod_ssi_exprparser.h
t_test_mod_ssi_SOURCES = t/test_mod_ssi.c request.c base64.c buffer.c burl.c array.c chunk.c fdevent.c http-header-glue.c http_cgi.c http_chunk.c http_date.c http_etag.c http_header.c http_kv.c log.c fdlog.c sock_addr.c stat_cache.c fdevent_fdnode.c algo_splaytree.c ck.c
t_test_mod_ssi_LDADD = $(LIBUNWIND_LIBS) $(FAM_LIBS)
@ -691,7 +684,6 @@ EXTRA_DIST = \
t/README \
mod_skeleton.c \
configparser.y \
mod_ssi_exprparser.y \
lemon.c \
lempar.c \
SConscript \

3
src/SConscript

@ -91,7 +91,6 @@ def Lemon(env, input):
env.Depends(parser, lemon)
configparser = Lemon(env, 'configparser.y')
mod_ssi_exprparser = Lemon(env, 'mod_ssi_exprparser.y')
## the modules and how they are built
modules = {
@ -120,7 +119,7 @@ modules = {
'mod_setenv' : { 'src' : [ 'mod_setenv.c' ] },
'mod_simple_vhost' : { 'src' : [ 'mod_simple_vhost.c' ] },
'mod_sockproxy' : { 'src' : [ 'mod_sockproxy.c' ] },
'mod_ssi' : { 'src' : [ 'mod_ssi_exprparser.c', 'mod_ssi_expr.c', 'mod_ssi.c' ] },
'mod_ssi' : { 'src' : [ 'mod_ssi_expr.c', 'mod_ssi.c' ] },
'mod_staticfile' : { 'src' : [ 'mod_staticfile.c' ] },
'mod_status' : { 'src' : [ 'mod_status.c' ] },
'mod_uploadprogress' : { 'src' : [ 'mod_uploadprogress.c' ] },

8
src/meson.build

@ -779,11 +779,6 @@ configparser = custom_target('configparser',
output: ['configparser.c', 'configparser.h'],
command: [lemon, '-q', 'o=@OUTDIR@', '@INPUT0@', '@INPUT1@'],
)
ssi_exprparser = custom_target('mod_ssi_exprparser',
input: ['mod_ssi_exprparser.y', 'lempar.c'],
output: ['mod_ssi_exprparser.c', 'mod_ssi_exprparser.h'],
command: [lemon, '-q', 'o=@OUTDIR@', '@INPUT0@', '@INPUT1@'],
)
common_cflags = defs + [
'-DHAVE_CONFIG_H',
@ -997,7 +992,6 @@ test('test_mod_simple_vhost', executable('test_mod_simple_vhost',
test('test_mod_ssi', executable('test_mod_ssi',
sources: [
't/test_mod_ssi.c',
ssi_exprparser,
'request.c',
'base64.c',
'buffer.c',
@ -1123,7 +1117,7 @@ modules = [
[ 'mod_setenv', [ 'mod_setenv.c' ] ],
[ 'mod_simple_vhost', [ 'mod_simple_vhost.c' ] ],
[ 'mod_sockproxy', [ 'mod_sockproxy.c' ] ],
[ 'mod_ssi', [ ssi_exprparser, 'mod_ssi_expr.c', 'mod_ssi.c' ], libws2_32 ],
[ 'mod_ssi', [ 'mod_ssi_expr.c', 'mod_ssi.c' ], libws2_32 ],
[ 'mod_staticfile', [ 'mod_staticfile.c' ] ],
[ 'mod_status', [ 'mod_status.c' ] ],
[ 'mod_uploadprogress', [ 'mod_uploadprogress.c' ] ],

36
src/mod_ssi_expr.c

@ -3,13 +3,24 @@
#include "buffer.h"
#include "log.h"
#include "mod_ssi.h"
#include "mod_ssi_expr.h"
#include "mod_ssi_exprparser.h"
#include <ctype.h>
#include <stdlib.h>
#include <string.h>
#define TK_AND 1
#define TK_OR 2
#define TK_EQ 3
#define TK_NE 4
#define TK_GT 5
#define TK_GE 6
#define TK_LT 7
#define TK_LE 8
#define TK_NOT 9
#define TK_LPARAN 10
#define TK_RPARAN 11
#define TK_VALUE 12
typedef struct {
const char *input;
size_t offset;
@ -20,24 +31,15 @@ typedef struct {
handler_ctx *p;
} ssi_tokenizer_t;
ssi_val_t *ssi_val_init(void) {
ssi_val_t *s;
s = calloc(1, sizeof(*s));
force_assert(s);
s->str = buffer_init();
return s;
}
void ssi_val_free(ssi_val_t *s) {
if (s->str) buffer_free(s->str);
typedef struct {
enum { SSI_TYPE_UNSET, SSI_TYPE_BOOL, SSI_TYPE_STRING } type;
free(s);
}
buffer *str;
int bo;
} ssi_val_t;
__attribute_pure__
int ssi_val_tobool(const ssi_val_t *B) {
static int ssi_val_tobool(const ssi_val_t *B) {
return B->type == SSI_TYPE_BOOL ? B->bo : !buffer_is_blank(B->str);
}

35
src/mod_ssi_expr.h

@ -1,35 +0,0 @@
#ifndef _MOD_SSI_EXPR_H_
#define _MOD_SSI_EXPR_H_
#include "first.h"
#include "buffer.h"
typedef struct {
enum { SSI_TYPE_UNSET, SSI_TYPE_BOOL, SSI_TYPE_STRING } type;
buffer *str;
int bo;
} ssi_val_t;
typedef struct {
int ok;
ssi_val_t val;
} ssi_ctx_t;
typedef enum { SSI_COND_UNSET, SSI_COND_LE, SSI_COND_GE, SSI_COND_EQ, SSI_COND_NE, SSI_COND_LT, SSI_COND_GT } ssi_expr_cond;
void *ssiexprparserAlloc(void *(*mallocProc)(size_t));
void ssiexprparserFree(void *p, void (*freeProc)(void*));
void ssiexprparser(void *yyp, int yymajor, buffer *yyminor, ssi_ctx_t *ctx);
__attribute_pure__
int ssi_val_tobool(const ssi_val_t *B);
__attribute_malloc__
__attribute_returns_nonnull__
ssi_val_t *ssi_val_init(void);
void ssi_val_free(ssi_val_t *s);
#endif

120
src/mod_ssi_exprparser.y

@ -1,120 +0,0 @@
%token_prefix TK_
%token_type {buffer *}
%extra_argument {ssi_ctx_t *ctx}
%name ssiexprparser
%include {
#include "first.h"
#include "mod_ssi_expr.h"
#include "buffer.h"
#include <string.h>
}
%parse_failure {
ctx->ok = 0;
}
%type expr { ssi_val_t * }
%type value { buffer * }
%type exprline { ssi_val_t * }
%type cond { int }
%token_destructor { buffer_free($$); }
%left AND.
%left OR.
%nonassoc EQ NE GT GE LT LE.
%right NOT.
input ::= exprline(B). {
ctx->val.bo = ssi_val_tobool(B);
ctx->val.type = SSI_TYPE_BOOL;
ssi_val_free(B);
}
exprline(A) ::= expr(B) cond(C) expr(D). {
int cmp;
if (B->type == SSI_TYPE_STRING &&
D->type == SSI_TYPE_STRING) {
cmp = strcmp(B->str->ptr, D->str->ptr);
} else {
cmp = ssi_val_tobool(B) - ssi_val_tobool(D);
}
A = B;
switch(C) {
case SSI_COND_EQ: A->bo = (cmp == 0) ? 1 : 0; break;
case SSI_COND_NE: A->bo = (cmp != 0) ? 1 : 0; break;
case SSI_COND_GE: A->bo = (cmp >= 0) ? 1 : 0; break;
case SSI_COND_GT: A->bo = (cmp > 0) ? 1 : 0; break;
case SSI_COND_LE: A->bo = (cmp <= 0) ? 1 : 0; break;
case SSI_COND_LT: A->bo = (cmp < 0) ? 1 : 0; break;
}
A->type = SSI_TYPE_BOOL;
ssi_val_free(D);
}
exprline(A) ::= expr(B). {
A = B;
}
expr(A) ::= expr(B) AND expr(C). {
int e;
e = ssi_val_tobool(B) && ssi_val_tobool(C);
A = B;
A->bo = e;
A->type = SSI_TYPE_BOOL;
ssi_val_free(C);
}
expr(A) ::= expr(B) OR expr(C). {
int e;
e = ssi_val_tobool(B) || ssi_val_tobool(C);
A = B;
A->bo = e;
A->type = SSI_TYPE_BOOL;
ssi_val_free(C);
}
expr(A) ::= NOT expr(B). {
int e;
e = !ssi_val_tobool(B);
A = B;
A->bo = e;
A->type = SSI_TYPE_BOOL;
}
expr(A) ::= LPARAN exprline(B) RPARAN. {
A = B;
}
expr(A) ::= value(B). {
A = ssi_val_init();
A->str = B;
A->type = SSI_TYPE_STRING;
}
value(A) ::= VALUE(B). {
A = B;
}
value(A) ::= value(B) VALUE(C). {
A = B;
buffer_append_string_buffer(A, C);
buffer_free(C);
}
cond(A) ::= EQ. { A = SSI_COND_EQ; }
cond(A) ::= NE. { A = SSI_COND_NE; }
cond(A) ::= LE. { A = SSI_COND_LE; }
cond(A) ::= GE. { A = SSI_COND_GE; }
cond(A) ::= LT. { A = SSI_COND_LT; }
cond(A) ::= GT. { A = SSI_COND_GT; }

3
src/t/test_mod_ssi.c

@ -9,9 +9,6 @@
#include "mod_ssi.c"
#include "mod_ssi_expr.c"
#ifdef INCLUDE_MOD_SSI_EXPRPARSER_C
#include "mod_ssi_exprparser.c"
#endif
#include "fdlog.h"
static void test_mod_ssi_reset (request_st * const r, handler_ctx * const hctx)

Loading…
Cancel
Save