Maat_cmd适配huge service define.

This commit is contained in:
zhengchao
2018-07-27 17:08:45 +08:00
parent 45f20cccb3
commit 27b93adc33
5 changed files with 44 additions and 5 deletions

View File

@@ -125,6 +125,7 @@ struct Maat_line_t
int expire_after; //expired after $timeout$ seconds, set to 0 for never timeout. 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); 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: which_group 0~group_num
//input: region can be freed after added. //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); void Maat_add_region2cmd(struct Maat_cmd_t* cmd,int which_group,const struct Maat_region_t* region);

View File

@@ -6,7 +6,7 @@
* to reside in the heart) of the departed would reach the paradise of afterlife * to reside in the heart) of the departed would reach the paradise of afterlife
* successfully. * successfully.
* Author: zhengchao@iie.ac.cn,MESA * Author: zhengchao@iie.ac.cn,MESA
* Version 2015-11-09 digest scan * Version 2018-07-27 huge service_define
* NOTE: MUST compile with G++ * NOTE: MUST compile with G++
* All right reserved by Institute of Infomation Engineering,Chinese Academic of Science 2014~2018 * All right reserved by Institute of Infomation Engineering,Chinese Academic of Science 2014~2018
********************************************************* *********************************************************
@@ -49,6 +49,7 @@ 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 struct Maat_rule_t
{ {
int config_id; int config_id;

View File

@@ -28,6 +28,7 @@ struct _Maat_cmd_inner_t
enum MAAT_OPERATION op; enum MAAT_OPERATION op;
int ref_cnt; int ref_cnt;
int region_size[MAX_EXPR_ITEM_NUM]; int region_size[MAX_EXPR_ITEM_NUM];
char* huge_service_defined; //max to 4KB
struct _Maat_cmd_inner_t* next; struct _Maat_cmd_inner_t* next;
}; };
int _wrap_redisGetReply(redisContext *c, redisReply **reply) 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->action
,p_m_rule->do_blacklist ,p_m_rule->do_blacklist
,p_m_rule->do_log ,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); ,cmd->group_num);
set_serial_rule(list+rule_num,MAAT_OP_ADD,cmd->compile.config_id,cmd->label_id,feather->compile_tn,line,timeout); 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
_cmd->region_size[i]=1; _cmd->region_size[i]=1;
} }
return (struct Maat_cmd_t*)_cmd; 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) int Maat_cmd_set_group(Maat_feather_t feather,int group_id, const struct Maat_region_t* region, enum MAAT_OPERATION op)
{ {
@@ -1592,6 +1621,12 @@ void Maat_free_cmd(struct Maat_cmd_t* cmd)
cmd->groups[i].regions=NULL; cmd->groups[i].regions=NULL;
} }
free(cmd->groups); 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; _cmd->next=NULL;
free(_cmd); free(_cmd);

View File

@@ -30,7 +30,7 @@
#include "stream_fuzzy_hash.h" #include "stream_fuzzy_hash.h"
#include "gram_index_engine.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", 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",""}; "unicode_ascii_esc","unicode_ascii_aligned","unicode_ncr_dec","unicode_ncr_hex","url_encode_gb2312","url_encode_utf8",""};

View File

@@ -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_cmd_t* cmd=NULL;
struct Maat_rule_t rule; 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; struct Maat_region_t region;
int group_num=1,ret=0; int group_num=1,ret=0;
memset(&rule,0,sizeof(rule)); 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.expr_type=EXPR_TYPE_AND;
region.expr_rule.match_method=MATCH_METHOD_SUB; region.expr_rule.match_method=MATCH_METHOD_SUB;
region.expr_rule.hex_bin=UNCASE_PLAIN; 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, &region); Maat_add_region2cmd(cmd, 0, &region);
//use pipeline model. //use pipeline model.
ret=Maat_cmd_append(feather, cmd, MAAT_OP_ADD); ret=Maat_cmd_append(feather, cmd, MAAT_OP_ADD);