Added a rule parsing tool for the dbfwfilter. The tool can be build with the -DBUILD_TOOLS=Y flag for CMake.
This commit is contained in:
parent
e13ab6689d
commit
89ca0f420a
@ -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)
|
||||
|
@ -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++)
|
||||
|
@ -56,7 +56,7 @@ DCB *dcb;
|
||||
int result;
|
||||
int argc = 3;
|
||||
|
||||
init_test_env();
|
||||
init_test_env(NULL);
|
||||
/* char* argv[] = */
|
||||
/* { */
|
||||
/* "log_manager", */
|
||||
|
@ -6,7 +6,7 @@
|
||||
#include <maxscale_test.h>
|
||||
#include <log_manager.h>
|
||||
|
||||
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
|
||||
};
|
||||
|
||||
|
@ -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)
|
||||
|
@ -2100,3 +2100,72 @@ diagnostic(FILTER *instance, void *fsession, DCB *dcb)
|
||||
spinlock_release(my_instance->lock);
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef BUILD_RULE_PARSER
|
||||
#include <test_utils.h>
|
||||
|
||||
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
|
||||
|
Loading…
x
Reference in New Issue
Block a user