From 91faf9dcc6063ee7510a6c74f83a15550703b936 Mon Sep 17 00:00:00 2001 From: zhengchao Date: Fri, 5 Jul 2019 00:35:03 +0600 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0maat=5Fdebug=5Ftool.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tools/CMakeLists.txt | 5 ++ tools/maat_debug_tool.cpp | 174 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 179 insertions(+) create mode 100644 tools/maat_debug_tool.cpp diff --git a/tools/CMakeLists.txt b/tools/CMakeLists.txt index bbfd508..e235b8b 100644 --- a/tools/CMakeLists.txt +++ b/tools/CMakeLists.txt @@ -8,4 +8,9 @@ target_link_libraries(maat_redis_tool maat_frame_static ${MAAT_DEPEND_DYN_LIB}) target_include_directories(maat_redis_tool PRIVATE ${PROJECT_SOURCE_DIR}/src/inc_internal/) target_include_directories(maat_redis_tool PRIVATE hiredis-vip-static) +add_executable(maat_debug_tool maat_debug_tool.cpp) +add_dependencies(maat_debug_tool maat_frame_shared) +target_link_libraries(maat_debug_tool maat_frame_static ${MAAT_DEPEND_DYN_LIB}) +target_include_directories(maat_debug_tool PRIVATE ${PROJECT_SOURCE_DIR}/src/inc_internal/) + install(TARGETS maat_redis_tool DESTINATION /usr/local/bin/) diff --git a/tools/maat_debug_tool.cpp b/tools/maat_debug_tool.cpp new file mode 100644 index 0000000..5b8d3be --- /dev/null +++ b/tools/maat_debug_tool.cpp @@ -0,0 +1,174 @@ +#include "Maat_rule.h" +#include "Maat_command.h" +#include + +#include /* for printf */ +#include /* for exit */ +#include +#include + + +int debug_maat_str_scan(Maat_feather_t feather, const char* table_name, const char* district, char* data, size_t sz) +{ + int table_id=0,ret=0; + int i=0; + int scan_result_max=64; + struct Maat_rule_t result[scan_result_max]; + scan_status_t mid=NULL; + + + table_id=Maat_table_register(feather, table_name); + if(table_id<0) + { + printf("Unkown table %s\n", table_name); + } + + struct Maat_hit_detail_t *hit_detail=(struct Maat_hit_detail_t *)malloc(sizeof(struct Maat_hit_detail_t)*10); + + enum MAAT_CHARSET maat_charset=CHARSET_UTF8; + + if(strlen(district)>0) + { + ret=Maat_set_scan_status(feather, &mid, MAAT_SET_SCAN_DISTRICT, district, strlen(district)); + } + + ret=Maat_full_scan_string(feather, table_id, maat_charset, data, sz, + result, NULL, scan_result_max, + &mid, 0); + printf("Scan table %s ", table_name); + if(ret==-1) + { + printf("error.\n"); + } + else if(ret==-2) + { + printf("hits group, but not compile.\n"); + } + else if(ret==0) + { + printf("not hit."); + } + else + { + printf("hits "); + for(i=0; i0) + { + Maat_set_feather_opt(feather, MAAT_OPT_DECRYPT_KEY, arg_value[ARG_DECRYPT_KEY], strlen(arg_value[ARG_DECRYPT_KEY])+1); + } + if(strlen(arg_value[ARG_ACCEPT_TAGS])>0) + { + Maat_set_feather_opt(feather, MAAT_OPT_ACCEPT_TAGS, arg_value[ARG_ACCEPT_TAGS], strlen(arg_value[ARG_ACCEPT_TAGS])+1); + } + ret=Maat_set_feather_opt(feather, MAAT_OPT_JSON_FILE_PATH, arg_value[ARG_INPUT_JSON], strlen(arg_value[ARG_INPUT_JSON])+1); + if(ret!=0) + { + printf("Read %s failed, invalid maat json.\n", arg_value[ARG_INPUT_JSON]); + ret=-1; + goto clean_up; + } + Maat_set_feather_opt(feather, MAAT_OPT_SCAN_DETAIL, &scan_detail, sizeof(scan_detail)); + Maat_initiate_feather(feather); + + if(strlen(arg_value[ARG_SCAN_FILE])>0) + { + + if(stat(arg_value[ARG_SCAN_FILE], &file_info)<0) + { + printf("Stat %s failed.\n", arg_value[ARG_SCAN_FILE]); + goto clean_up; + } + file_size=file_info.st_size; + fp=fopen(arg_value[ARG_SCAN_FILE], "r"); + if(fp==NULL) + { + printf("Open %s failed.\n", arg_value[ARG_SCAN_FILE]); + goto clean_up; + } + file_buff=(char*)malloc(file_size); + fread(file_buff,1,file_size,fp); + fclose(fp); + + debug_maat_str_scan(feather, arg_value[ARG_TABLE_NAME], arg_value[ARG_SCAN_DISTRICT], file_buff, file_size); + free(file_buff); + } +clean_up: + Maat_burn_feather(feather); + MESA_destroy_runtime_log_handle(g_logger); + return ret; +} + +