diff --git a/macros.cmake b/macros.cmake index 63bbd23d3..30c4307f4 100644 --- a/macros.cmake +++ b/macros.cmake @@ -66,6 +66,9 @@ macro(set_variables) # Build packages set(PACKAGE FALSE CACHE BOOL "Enable package building (this disables local installation of system files)") + # Build extra tools + set(BUILD_TOOLS FALSE CACHE BOOL "Build extra utility tools") + endmacro() macro(check_deps) diff --git a/server/core/CMakeLists.txt b/server/core/CMakeLists.txt index 6a481d370..4bdf615e7 100644 --- a/server/core/CMakeLists.txt +++ b/server/core/CMakeLists.txt @@ -1,4 +1,4 @@ -if(BUILD_TESTS) +if(BUILD_TESTS OR BUILD_TOOLS) file(GLOB FULLCORE_SRC *.c) add_library(fullcore STATIC ${FULLCORE_SRC}) target_link_libraries(fullcore ${CURL_LIBRARIES} log_manager utils pthread ${EMBEDDED_LIB} ssl aio rt crypt dl crypto inih z m stdc++) diff --git a/server/core/test/testservice.c b/server/core/test/testservice.c index ca6fe6618..f45fd2afc 100644 --- a/server/core/test/testservice.c +++ b/server/core/test/testservice.c @@ -56,7 +56,7 @@ DCB *dcb; int result; int argc = 3; -init_test_env(); +init_test_env(NULL); /* char* argv[] = */ /* { */ /* "log_manager", */ diff --git a/server/include/test_utils.h b/server/include/test_utils.h index 538c5d101..48bda023c 100644 --- a/server/include/test_utils.h +++ b/server/include/test_utils.h @@ -6,7 +6,7 @@ #include #include -void init_test_env() +void init_test_env(char *path) { int argc = 3; @@ -14,7 +14,7 @@ void init_test_env() { "log_manager", "-j", - TEST_LOG_DIR, + path? path:TEST_LOG_DIR, NULL }; diff --git a/server/modules/filter/CMakeLists.txt b/server/modules/filter/CMakeLists.txt index 3febf4ff5..0af1ea566 100644 --- a/server/modules/filter/CMakeLists.txt +++ b/server/modules/filter/CMakeLists.txt @@ -40,6 +40,13 @@ if(BUILD_SLAVELAG) install(TARGETS slavelag DESTINATION modules) endif() +if(BUILD_TOOLS) + add_executable(ruleparser dbfwfilter.c) + target_compile_definitions(ruleparser PUBLIC "BUILD_RULE_PARSER") + target_link_libraries(ruleparser ${EMBEDDED_LIB} log_manager utils query_classifier fullcore) + install(TARGETS ruleparser DESTINATION tools) +endif() + add_subdirectory(hint) if(BUILD_TESTS) diff --git a/server/modules/filter/dbfwfilter.c b/server/modules/filter/dbfwfilter.c index b200e5580..2f02c0efe 100644 --- a/server/modules/filter/dbfwfilter.c +++ b/server/modules/filter/dbfwfilter.c @@ -2100,3 +2100,72 @@ diagnostic(FILTER *instance, void *fsession, DCB *dcb) spinlock_release(my_instance->lock); } } + +#ifdef BUILD_RULE_PARSER +#include + +int main(int argc, char** argv) +{ + char ch; + bool have_icase = false; + char *home; + char cwd[PATH_MAX]; + char* opts[2] = {NULL,NULL}; + FILTER_PARAMETER ruleparam; + FILTER_PARAMETER* paramlist[2]; + + while((ch = getopt(argc,argv,"ih?")) != -1) + { + switch(ch) + { + case 'i': + opts[0] = strdup("ignorecase"); + break; + case '?': + case 'h': + printf("Usage: %s [OPTION]... RULEFILE\n" + "-?\tPrint this information\n", + argv[0]); + return 0; + } + } + + if(argc < 2) + { + printf("Usage: %s [OPTION]... RULEFILE\n" + "-?\tPrint this information\n", + argv[0]); + return 1; + } + + if((home = getenv("MAXSCALE_HOME")) == NULL) + { + home = malloc(sizeof(char)*(PATH_MAX+1)); + if(getcwd(home,PATH_MAX) == NULL) + { + free(home); + home = NULL; + } + } + + init_test_env(home); + ruleparam.name = strdup("rules"); + ruleparam.value = strdup(argv[1]); + paramlist[0] = &ruleparam; + paramlist[1] = NULL; + + if(createInstance(opts,paramlist)) + { + printf("Rule parsing was successful.\n"); + } + else + { + printf("Failed to parse rule. Read the error log for the reason of the failure.\n"); + } + + skygw_log_sync_all(); + + return 0; +} + +#endif