diff --git a/inc/Maat_command.h b/inc/Maat_command.h index 0a65beb..ed06262 100644 --- a/inc/Maat_command.h +++ b/inc/Maat_command.h @@ -125,6 +125,7 @@ struct Maat_line_t int expire_after; //expired after $timeout$ seconds, set to 0 for never timeout. }; struct Maat_cmd_t* Maat_create_cmd(const struct Maat_rule_t* rule, int group_num); +int Maat_cmd_set_opt(struct Maat_cmd_t* cmd, enum MAAT_RULE_OPT type, const char* val, int size); //input: which_group 0~group_num //input: region can be freed after added. void Maat_add_region2cmd(struct Maat_cmd_t* cmd,int which_group,const struct Maat_region_t* region); diff --git a/inc/Maat_rule.h b/inc/Maat_rule.h index 6a83d32..ba9a209 100644 --- a/inc/Maat_rule.h +++ b/inc/Maat_rule.h @@ -6,7 +6,7 @@ * to reside in the heart) of the departed would reach the paradise of afterlife * successfully. * Author: zhengchao@iie.ac.cn,MESA -* Version 2015-11-09 digest scan +* Version 2018-07-27 huge service_define * NOTE: MUST compile with G++ * All right reserved by Institute of Infomation Engineering,Chinese Academic of Science 2014~2018 ********************************************************* @@ -48,7 +48,8 @@ typedef void* stream_para_t; typedef void* Maat_feather_t; -#define MAX_SERVICE_DEFINE_LEN 128 +#define MAX_SERVICE_DEFINE_LEN 128 +#define MAX_HUGE_SERVICE_DEFINE_LEN (1024*4) struct Maat_rule_t { int config_id; diff --git a/src/entry/Maat_command.cpp b/src/entry/Maat_command.cpp index c6ca3c3..a3d81b0 100644 --- a/src/entry/Maat_command.cpp +++ b/src/entry/Maat_command.cpp @@ -28,6 +28,7 @@ struct _Maat_cmd_inner_t enum MAAT_OPERATION op; int ref_cnt; int region_size[MAX_EXPR_ITEM_NUM]; + char* huge_service_defined; //max to 4KB struct _Maat_cmd_inner_t* next; }; int _wrap_redisGetReply(redisContext *c, redisReply **reply) @@ -854,7 +855,7 @@ int build_serial_rule(_Maat_feather_t *feather,struct _Maat_cmd_inner_t* _cmd,st ,p_m_rule->action ,p_m_rule->do_blacklist ,p_m_rule->do_log - ,p_m_rule->service_defined + ,(_cmd->huge_service_defined!=NULL)?(_cmd->huge_service_defined):(p_m_rule->service_defined) ,cmd->group_num); set_serial_rule(list+rule_num,MAAT_OP_ADD,cmd->compile.config_id,cmd->label_id,feather->compile_tn,line,timeout); @@ -1444,6 +1445,34 @@ struct Maat_cmd_t* Maat_create_cmd(const struct Maat_rule_t* rule, int group_num } return (struct Maat_cmd_t*)_cmd; } +int Maat_cmd_set_opt(struct Maat_cmd_t* cmd, enum MAAT_RULE_OPT type, const char* val, int size) +{ + struct _Maat_cmd_inner_t* _cmd=(struct _Maat_cmd_inner_t* )cmd; + int ret=-1; + switch(type) + { + case MAAT_RULE_SERV_DEFINE: + if(size>MAX_HUGE_SERVICE_DEFINE_LEN) + { + ret=-1; + } + else + { + if(_cmd->huge_service_defined!=NULL) + { + free(_cmd->huge_service_defined); + } + _cmd->huge_service_defined=(char*)calloc(sizeof(char),size+1); + memcpy(_cmd->huge_service_defined,val, size); + ret=0; + } + break; + default: + break; + } + return ret; +} + int Maat_cmd_set_group(Maat_feather_t feather,int group_id, const struct Maat_region_t* region, enum MAAT_OPERATION op) { _Maat_feather_t* _feather=(_Maat_feather_t*)feather; @@ -1592,6 +1621,12 @@ void Maat_free_cmd(struct Maat_cmd_t* cmd) } free(cmd->groups); cmd->groups=NULL; + if(_cmd->huge_service_defined!=NULL) + { + free(_cmd->huge_service_defined); + _cmd->huge_service_defined=NULL; + } + _cmd->next=NULL; free(_cmd); return; diff --git a/src/entry/Maat_rule.cpp b/src/entry/Maat_rule.cpp index aedc44a..a74a717 100644 --- a/src/entry/Maat_rule.cpp +++ b/src/entry/Maat_rule.cpp @@ -30,7 +30,7 @@ #include "stream_fuzzy_hash.h" #include "gram_index_engine.h" -int MAAT_FRAME_VERSION_2_2_20180719=1; +int MAAT_FRAME_VERSION_2_2_20180727=1; const char* CHARSET_STRING[]={"NONE","gbk","big5","unicode","utf8","bin", "unicode_ascii_esc","unicode_ascii_aligned","unicode_ncr_dec","unicode_ncr_hex","url_encode_gb2312","url_encode_utf8",""}; diff --git a/test/maat_test.cpp b/test/maat_test.cpp index e5741b8..059451b 100644 --- a/test/maat_test.cpp +++ b/test/maat_test.cpp @@ -636,7 +636,8 @@ int test_add_expr_command(Maat_feather_t feather,const char* region_table,int co { struct Maat_cmd_t* cmd=NULL; struct Maat_rule_t rule; - + char huge_serv_def[1024*2]; + memset(huge_serv_def,'s',sizeof(huge_serv_def)); struct Maat_region_t region; int group_num=1,ret=0; memset(&rule,0,sizeof(rule)); @@ -655,6 +656,7 @@ int test_add_expr_command(Maat_feather_t feather,const char* region_table,int co region.expr_rule.expr_type=EXPR_TYPE_AND; region.expr_rule.match_method=MATCH_METHOD_SUB; region.expr_rule.hex_bin=UNCASE_PLAIN; + Maat_cmd_set_opt(cmd, MAAT_RULE_SERV_DEFINE, huge_serv_def, sizeof(huge_serv_def)); Maat_add_region2cmd(cmd, 0, ®ion); //use pipeline model. ret=Maat_cmd_append(feather, cmd, MAAT_OP_ADD);