编译表和回调表支持配置生效标签。
This commit is contained in:
@@ -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 2018-07-27 huge service_define
|
||||
* Version 2018-09-21 rule tags
|
||||
* NOTE: MUST compile with G++
|
||||
* All right reserved by Institute of Infomation Engineering,Chinese Academic of Science 2014~2018
|
||||
*********************************************************
|
||||
@@ -156,7 +156,8 @@ enum MAAT_INIT_OPT
|
||||
MAAT_OPT_CUMULATIVE_UPDATE_OFF, //VALUE is NULL,SIZE is 0. Default: CUMMULATIVE UPDATE ON.
|
||||
MAAT_OPT_LOAD_VERSION_FROM, //VALUE is a long long, SIZE=sizeof(long long). Default: Load the Latest. Only valid in redis mode, and maybe failed for too old.
|
||||
//This option also disables background update.
|
||||
MAAT_OPT_ENABLE_UPDATE //VALUE is interger, SIZE=sizeof(int). 1: Enabled, 0:Disabled. DEFAULT: Backgroud update is enabled. Runtime setting is allowed.
|
||||
MAAT_OPT_ENABLE_UPDATE, //VALUE is interger, SIZE=sizeof(int). 1: Enabled, 0:Disabled. DEFAULT: Backgroud update is enabled. Runtime setting is allowed.
|
||||
MAAT_OPT_ACCEPT_TAGS //VALUE is a const char*, MUST end with '\0', SIZE= strlen(string+'\0')+1. Format is a JSON, e.g.{"tags":[{"tag":"location","value":"Beijing/ChaoYang/Huayan/22A"},{"tag":"isp","value":"telecom"}]}
|
||||
};
|
||||
//return -1 if failed, return 0 on success;
|
||||
int Maat_set_feather_opt(Maat_feather_t feather,enum MAAT_INIT_OPT type,const void* value,int size);
|
||||
|
||||
@@ -666,6 +666,13 @@ int Maat_set_feather_opt(Maat_feather_t feather,enum MAAT_INIT_OPT type,const vo
|
||||
"Maat load version from %lld, stops backgroud update."
|
||||
,_feather->load_version_from);
|
||||
break;
|
||||
case MAAT_OPT_ACCEPT_TAGS:
|
||||
_feather->n_tags=parse_accept_tag((const char*) value, &_feather->accept_tags, _feather->logger);
|
||||
if(_feather->n_tags==0)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -695,7 +695,7 @@ int _get_maat_redis_value(redisContext *c,struct serial_rule_t* rule_list,int ru
|
||||
{
|
||||
rule_list[idx].table_line=_maat_strdup(reply->str);
|
||||
}
|
||||
else if(reply->type==REDIS_REPLY_ERROR)//Handle: "Loading Redis is loading the database in memory"
|
||||
else if(reply->type==REDIS_REPLY_ERROR)//Deal with Redis response: "Loading Redis is loading the database in memory"
|
||||
{
|
||||
MESA_handle_runtime_log(logger,RLOG_LV_FATAL,maat_redis_monitor
|
||||
,"Redis cmd=%s Error, Reply type=%d, str=%s",redis_cmd, reply->type, reply->str);
|
||||
|
||||
@@ -20,6 +20,7 @@
|
||||
#include "Maat_rule.h"
|
||||
#include "Maat_rule_internal.h"
|
||||
#include "json2iris.h"
|
||||
#include "cJSON.h"
|
||||
#include "dynamic_array.h"
|
||||
#include "aligment_int64.h"
|
||||
#include "config_monitor.h"
|
||||
@@ -30,7 +31,7 @@
|
||||
#include "stream_fuzzy_hash.h"
|
||||
#include "gram_index_engine.h"
|
||||
|
||||
int MAAT_FRAME_VERSION_2_2_20180808=1;
|
||||
int MAAT_FRAME_VERSION_2_2_20180921=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",""};
|
||||
@@ -319,7 +320,7 @@ error_out:
|
||||
|
||||
return ret;
|
||||
}
|
||||
char* strlwr(char* string)
|
||||
char* str_tolower(char* string)
|
||||
{
|
||||
int i=0;
|
||||
for(i=0;i<(int)strlen(string);i++)
|
||||
@@ -473,7 +474,166 @@ int cnt_maskbits(struct in6_addr mask)
|
||||
}
|
||||
return bits_cnt;
|
||||
}
|
||||
//@param value is a JSON, like {"tags":[{"tag":"location","value":"北京/朝阳/华严北里/甲22号},{"tag":"isp","value":"电信"}]}
|
||||
int parse_accept_tag(const char* value, struct rule_tag** result, void* logger)
|
||||
{
|
||||
cJSON* json=NULL, *array=NULL,*tag=NULL, *tmp=NULL;
|
||||
struct rule_tag* p=NULL;
|
||||
int n_tags=0;
|
||||
json=cJSON_Parse(value);
|
||||
if(!json)
|
||||
{
|
||||
MESA_handle_runtime_log(logger,RLOG_LV_FATAL,maat_module,
|
||||
"MAAT_OPT_ACCEPT_TAGS Error before: %-200.200s",cJSON_GetErrorPtr());
|
||||
return 0;
|
||||
}
|
||||
array=cJSON_GetObjectItem(json, "tags");
|
||||
n_tags=cJSON_GetArraySize(array);
|
||||
p=(struct rule_tag*)calloc(sizeof(struct rule_tag), n_tags);
|
||||
for(int i=0;i<n_tags;i++)
|
||||
{
|
||||
tag=cJSON_GetArrayItem(array, i);
|
||||
tmp=cJSON_GetObjectItem(tag, "tag");
|
||||
p[i].tag_name=_maat_strdup(tmp->valuestring);
|
||||
tmp=cJSON_GetObjectItem(tag, "value");
|
||||
p[i].tag_val=_maat_strdup(tmp->valuestring);
|
||||
}
|
||||
cJSON_Delete(json);
|
||||
*result=p;
|
||||
return n_tags;
|
||||
}
|
||||
static int compare_each_tag(cJSON* tag_obj, const struct rule_tag* accept_tags, int n_accept)
|
||||
{
|
||||
const char* tag_name;
|
||||
const char* tag_val;
|
||||
int n_val;
|
||||
cJSON *tab_name_obj=NULL, *tag_vals_array=NULL, *tag_val_obj=NULL;
|
||||
|
||||
int i=0, j=0, name_matched=0;
|
||||
tab_name_obj=cJSON_GetObjectItem(tag_obj,"tag");
|
||||
if(!tab_name_obj||tab_name_obj->type!=cJSON_String)
|
||||
{
|
||||
goto error_out;
|
||||
}
|
||||
tag_name=tab_name_obj->valuestring;
|
||||
tag_vals_array=cJSON_GetObjectItem(tag_obj,"value");
|
||||
if(!tag_vals_array||tag_vals_array->type!=cJSON_Array)
|
||||
{
|
||||
goto error_out;
|
||||
}
|
||||
n_val=cJSON_GetArraySize(tag_vals_array);
|
||||
for(i=0;i<n_accept;i++)
|
||||
{
|
||||
if(0!=strcmp(accept_tags[i].tag_name, tag_name))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
name_matched++;
|
||||
|
||||
for(j=0; j<n_val; j++)
|
||||
{
|
||||
tag_val_obj=cJSON_GetArrayItem(tag_vals_array, j);
|
||||
if(!tag_val_obj||tag_val_obj->type!=cJSON_String)
|
||||
{
|
||||
goto error_out;
|
||||
}
|
||||
tag_val=tag_val_obj->valuestring;
|
||||
// compare a/b/c with a/b/c/d is a miss.
|
||||
if(strlen(accept_tags[i].tag_val)<strlen(tag_val))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
// compare a1a2/b1/c1 with a1a2/b/ is a miss.
|
||||
//make sure the overlap is ended with a '/'
|
||||
if(0==strncmp(accept_tags[i].tag_val, tag_val, strlen(tag_val))&&
|
||||
(strlen(accept_tags[i].tag_val)==strlen(tag_val)||accept_tags[i].tag_val[strlen(tag_val)]=='/'))
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
//no matched name is considered as a
|
||||
if(name_matched>0)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
error_out:
|
||||
return -1;
|
||||
|
||||
}
|
||||
//@param tag_set likes [{"tag":"location","value":["北京/朝阳/华严北里","上海/浦东/陆家嘴"]},{"tag":"isp","value":["电信","移动"]}]
|
||||
static int compare_each_tag_set(cJSON* tag_set, const struct rule_tag* accept_tags, int n_accept)
|
||||
{
|
||||
cJSON *tag_obj=NULL;
|
||||
int n_tag=0, ret=0, matched=0;
|
||||
n_tag=cJSON_GetArraySize(tag_set);
|
||||
for(int i=0; i<n_tag; i++)
|
||||
{
|
||||
tag_obj=cJSON_GetArrayItem(tag_set, i);
|
||||
if(!tag_obj||tag_obj->type!=cJSON_Object)
|
||||
{
|
||||
goto error_out;
|
||||
}
|
||||
ret=compare_each_tag(tag_obj, accept_tags, n_accept);
|
||||
if(ret<0)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
if(ret==1)
|
||||
{
|
||||
matched++;
|
||||
}
|
||||
}
|
||||
if(matched==n_tag)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
error_out:
|
||||
return -1;
|
||||
}
|
||||
//@param value {"tag_sets":[[{"tag":"location","value":["北京/朝阳/华严北里","上海/浦东/陆家嘴"]},{"tag":"isp","value":["电信","移动"]}],[{"tag":"location","value":["北京"]},{"tag":"isp","value":["联通"]}]]}
|
||||
//@return 1 on match, 0 on not match, -1 on error.
|
||||
static int compare_accept_tag(const char* value,const struct rule_tag* accept_tags, int n_tags)
|
||||
{
|
||||
cJSON *json=NULL;
|
||||
cJSON *tag_set_array=NULL, *tag_set=NULL;
|
||||
int ret=-1, n_set=0;
|
||||
json=cJSON_Parse(value);
|
||||
if(!json)
|
||||
{
|
||||
goto error_out;
|
||||
}
|
||||
tag_set_array=cJSON_GetObjectItem(json, "tag_sets");
|
||||
if(!tag_set_array||tag_set_array->type!=cJSON_Array)
|
||||
{
|
||||
goto error_out;
|
||||
}
|
||||
n_set=cJSON_GetArraySize(tag_set_array);
|
||||
for(int i=0; i<n_set; i++)
|
||||
{
|
||||
tag_set=cJSON_GetArrayItem(tag_set_array,i);
|
||||
if(!tag_set||tag_set->type!=cJSON_Array)
|
||||
{
|
||||
goto error_out;
|
||||
}
|
||||
ret=compare_each_tag_set(tag_set, accept_tags, n_tags);
|
||||
if(ret!=0)//match or error occurs.
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
error_out:
|
||||
cJSON_Delete(json);
|
||||
return ret;
|
||||
}
|
||||
int lqueue_destroy_cb(void *data, long data_len, void *arg)
|
||||
{
|
||||
assert(0);
|
||||
@@ -544,12 +704,12 @@ int read_expr_table_info(const char* line,int line_num,struct _Maat_table_info_t
|
||||
,&(p->cross_cache_size)
|
||||
,quick_str_scan);
|
||||
memset(ret,0,sizeof(ret));
|
||||
ret[0]=map_str2int(string2int_map,strlwr(table_type),(int*)&(p->table_type));
|
||||
ret[1]=map_str2int(string2int_map,strlwr(src_charset),(int*)&(p->src_charset));
|
||||
ret[2]=map_str2int(string2int_map,strlwr(merge),&(p->do_charset_merge));
|
||||
ret[0]=map_str2int(string2int_map,str_tolower(table_type),(int*)&(p->table_type));
|
||||
ret[1]=map_str2int(string2int_map,str_tolower(src_charset),(int*)&(p->src_charset));
|
||||
ret[2]=map_str2int(string2int_map,str_tolower(merge),&(p->do_charset_merge));
|
||||
if(strlen(quick_str_scan)>0)
|
||||
{
|
||||
ret[3]=map_str2int(string2int_map,strlwr(quick_str_scan),&(p->quick_expr_switch));
|
||||
ret[3]=map_str2int(string2int_map,str_tolower(quick_str_scan),&(p->quick_expr_switch));
|
||||
}
|
||||
memset(quick_str_scan,0,sizeof(quick_str_scan));
|
||||
|
||||
@@ -566,7 +726,7 @@ int read_expr_table_info(const char* line,int line_num,struct _Maat_table_info_t
|
||||
sub_token= strtok_r(token,"/", &saveptr);
|
||||
if (sub_token == NULL)
|
||||
break;
|
||||
ret[3]=map_str2int(string2int_map,strlwr(sub_token),(int*)&(p->dst_charset[j]));
|
||||
ret[3]=map_str2int(string2int_map,str_tolower(sub_token),(int*)&(p->dst_charset[j]));
|
||||
if(ret[3]>0)
|
||||
{
|
||||
if(p->dst_charset[j]==p->src_charset)
|
||||
@@ -640,7 +800,7 @@ int read_table_info(struct _Maat_table_info_t** p_table_info,int num,const char*
|
||||
}
|
||||
p=create_table_info(max_thread_num);
|
||||
|
||||
ret=sscanf(line,"%hu\t%s\t%s\t%s",&(p->table_id)
|
||||
ret=sscanf(line,"%hu\t%s\t%s\t%[a-z0-9\t ]",&(p->table_id)
|
||||
,p->table_name[0]
|
||||
,table_type_str
|
||||
,not_care);
|
||||
@@ -650,7 +810,7 @@ int read_table_info(struct _Maat_table_info_t** p_table_info,int num,const char*
|
||||
"Maat read table info %s line %d error: not enough column.",table_info_path,i);
|
||||
continue;
|
||||
}
|
||||
ret=map_str2int(string2int_map,strlwr(table_type_str),(int*)&(p->table_type));
|
||||
ret=map_str2int(string2int_map,str_tolower(table_type_str),(int*)&(p->table_type));
|
||||
if(ret<0)
|
||||
{
|
||||
MESA_handle_runtime_log(logger, RLOG_LV_FATAL,maat_module,
|
||||
@@ -673,7 +833,7 @@ int read_table_info(struct _Maat_table_info_t** p_table_info,int num,const char*
|
||||
case TABLE_TYPE_PLUGIN:
|
||||
p->cb_info=(struct _plugin_table_info*)calloc(sizeof(struct _plugin_table_info),1);
|
||||
p->cb_info->cache_lines=dynamic_array_create(1024,1024);
|
||||
ret=sscanf(not_care,"%d",&(p->valid_flag_column));
|
||||
ret=sscanf(not_care,"%d\t%d",&(p->valid_flag_column), &p->rule_tag_column);
|
||||
if(ret==0||ret==EOF)
|
||||
{
|
||||
p->valid_flag_column=-1;
|
||||
@@ -683,7 +843,7 @@ int read_table_info(struct _Maat_table_info_t** p_table_info,int num,const char*
|
||||
ret=sscanf(not_care,"%[a-z0-9]",user_region_encoding);
|
||||
if(ret>0)
|
||||
{
|
||||
ret=map_str2int(string2int_map,strlwr(user_region_encoding),(int*)&(p->user_region_encoding));
|
||||
ret=map_str2int(string2int_map,str_tolower(user_region_encoding),(int*)&(p->user_region_encoding));
|
||||
}
|
||||
if(ret!=1)
|
||||
{
|
||||
@@ -2657,19 +2817,20 @@ error_out:
|
||||
intval_rule=NULL;
|
||||
}
|
||||
|
||||
void update_compile_rule(struct _Maat_table_info_t* table,const char* table_line,struct _Maat_scanner_t *scanner,void* logger)
|
||||
void update_compile_rule(struct _Maat_table_info_t* table,const char* table_line,struct _Maat_scanner_t *scanner, const struct rule_tag* tags, int n_tags,void* logger)
|
||||
{
|
||||
struct db_compile_rule_t *p_compile=(struct db_compile_rule_t*)calloc(sizeof(struct db_compile_rule_t ),1);
|
||||
struct _head_Maat_rule_t* p_m_rule=&(p_compile->m_rule_head);
|
||||
char user_region[MAX_TABLE_LINE_SIZE]={0};
|
||||
char tag_str[MAX_TABLE_LINE_SIZE]={0};
|
||||
int ret=0;
|
||||
p_compile->declare_grp_num=0;
|
||||
ret=sscanf(table_line,"%d\t%d\t%hhd\t%hhd\t%hhd\t%lld\t%s\t%d\t%d",&(p_m_rule->config_id)
|
||||
ret=sscanf(table_line,"%d\t%d\t%hhd\t%hhd\t%hhd\t%s\t%s\t%d\t%d",&(p_m_rule->config_id)
|
||||
,&(p_m_rule->service_id)
|
||||
,&(p_m_rule->action)
|
||||
,&(p_m_rule->do_blacklist)
|
||||
,&(p_m_rule->do_log)
|
||||
,&(p_compile->effective_range)
|
||||
,tag_str
|
||||
,user_region
|
||||
,&(p_compile->is_valid)
|
||||
,&(p_compile->declare_grp_num));
|
||||
@@ -2678,10 +2839,25 @@ void update_compile_rule(struct _Maat_table_info_t* table,const char* table_line
|
||||
MESA_handle_runtime_log(logger,RLOG_LV_FATAL,maat_module ,
|
||||
"update error,invalid format of compile table %s:%s"
|
||||
,table->table_name[table->updating_name],table_line);
|
||||
free(p_compile);
|
||||
p_compile=NULL;
|
||||
table->udpate_err_cnt++;
|
||||
return;
|
||||
goto no_save;
|
||||
}
|
||||
if(n_tags>0&&strlen(tag_str)>2)
|
||||
{
|
||||
ret=compare_accept_tag(tag_str, tags, n_tags);
|
||||
if(ret<0)
|
||||
{
|
||||
MESA_handle_runtime_log(logger,RLOG_LV_FATAL,maat_module ,
|
||||
"update error,invalid tag format of compile table %s:%s"
|
||||
,table->table_name[table->updating_name],table_line);
|
||||
table->udpate_err_cnt++;
|
||||
goto no_save;
|
||||
}
|
||||
if(ret==0)
|
||||
{
|
||||
table->unmatch_tag_cnt++;
|
||||
goto no_save;
|
||||
}
|
||||
}
|
||||
switch(table->user_region_encoding)
|
||||
{
|
||||
@@ -2702,10 +2878,7 @@ void update_compile_rule(struct _Maat_table_info_t* table,const char* table_line
|
||||
{
|
||||
table->cfg_num--;
|
||||
}
|
||||
free(p_compile->service_defined);
|
||||
p_compile->service_defined=NULL;
|
||||
free(p_compile);
|
||||
p_compile=NULL;
|
||||
goto no_save;
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -2715,12 +2888,8 @@ void update_compile_rule(struct _Maat_table_info_t* table,const char* table_line
|
||||
MESA_handle_runtime_log(logger,RLOG_LV_INFO,maat_module ,
|
||||
"duplicate config of compile table %s config_id=%d"
|
||||
,table->table_name[table->updating_name],p_m_rule->config_id);
|
||||
free(p_compile->service_defined);
|
||||
p_compile->service_defined=NULL;
|
||||
free(p_compile);
|
||||
p_compile=NULL;
|
||||
table->udpate_err_cnt++;
|
||||
|
||||
goto no_save;
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -2728,7 +2897,13 @@ void update_compile_rule(struct _Maat_table_info_t* table,const char* table_line
|
||||
table->cfg_num++;
|
||||
}
|
||||
}
|
||||
return;
|
||||
|
||||
no_save:
|
||||
free(p_compile->service_defined);
|
||||
p_compile->service_defined=NULL;
|
||||
free(p_compile);
|
||||
p_compile=NULL;
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -2901,13 +3076,49 @@ void garbage_bury(MESA_lqueue_head garbage_q,int timeout,void *logger)
|
||||
q_cnt,bury_cnt);
|
||||
}
|
||||
}
|
||||
void plugin_table_callback(struct _Maat_table_info_t* table,const char* table_line,void* logger)
|
||||
void update_plugin_table(struct _Maat_table_info_t* table,const char* table_line, const struct rule_tag* tags, int n_tags, void* logger)
|
||||
{
|
||||
int i=0;
|
||||
int i=0, ret=1;
|
||||
unsigned int len=strlen(table_line)+1;
|
||||
struct _plugin_table_info* p_table_cb=table->cb_info;
|
||||
char *p=NULL;
|
||||
char* copy=NULL;
|
||||
|
||||
char *token=NULL,*sub_token=NULL,*saveptr;
|
||||
if(table->rule_tag_column!=0&&n_tags>0)
|
||||
{
|
||||
copy=_maat_strdup(table_line);
|
||||
for (token = copy, i=0; i<table->rule_tag_column ; token= NULL, i++)
|
||||
{
|
||||
sub_token= strtok_r(token,"\t", &saveptr);
|
||||
if (sub_token == NULL)
|
||||
break;
|
||||
}
|
||||
if(i==table->rule_tag_column&&strlen(sub_token)>2)
|
||||
{
|
||||
ret=compare_accept_tag(sub_token, tags, n_tags);
|
||||
if(ret<0)
|
||||
{
|
||||
MESA_handle_runtime_log(logger,RLOG_LV_FATAL,maat_module ,
|
||||
"update error,invalid tag format of plugin table %s:%s"
|
||||
,table->table_name[table->updating_name],table_line);
|
||||
table->udpate_err_cnt++;
|
||||
}
|
||||
if(ret==0)
|
||||
{
|
||||
table->unmatch_tag_cnt++;
|
||||
}
|
||||
}
|
||||
free(copy);
|
||||
copy=NULL;
|
||||
if(ret!=1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
p_table_cb->acc_line_num++;
|
||||
|
||||
if(p_table_cb->cb_plug_cnt>0)
|
||||
{
|
||||
for(i=0;i<p_table_cb->cb_plug_cnt;i++)
|
||||
@@ -3202,13 +3413,13 @@ int maat_update_cb(const char* table_name,const char* line,void *u_para)
|
||||
update_digest_rule(feather->p_table_info[table_id], line, scanner,feather->logger,feather->GROUP_MODE_ON);
|
||||
break;
|
||||
case TABLE_TYPE_COMPILE:
|
||||
update_compile_rule(feather->p_table_info[table_id], line, scanner,feather->logger);
|
||||
update_compile_rule(feather->p_table_info[table_id], line, scanner, feather->accept_tags, feather->n_tags, feather->logger);
|
||||
break;
|
||||
case TABLE_TYPE_GROUP:
|
||||
update_group_rule(feather->p_table_info[table_id], line, scanner,feather->logger);
|
||||
break;
|
||||
case TABLE_TYPE_PLUGIN:
|
||||
plugin_table_callback(feather->p_table_info[table_id], line,feather->logger);
|
||||
update_plugin_table(feather->p_table_info[table_id], line, feather->accept_tags, feather->n_tags, feather->logger);
|
||||
default:
|
||||
break;
|
||||
|
||||
|
||||
@@ -261,9 +261,11 @@ struct _Maat_table_info_t
|
||||
};
|
||||
struct _plugin_table_info *cb_info;
|
||||
int valid_flag_column; //for plugin table
|
||||
int rule_tag_column; //for plugin table;
|
||||
int user_region_encoding; //for compile table, USER_REGION_ENCODE_xx
|
||||
//for stat>>>>>>>>
|
||||
unsigned long long udpate_err_cnt;
|
||||
unsigned long long unmatch_tag_cnt;
|
||||
unsigned long long iconv_err_cnt;
|
||||
int stat_line_id;
|
||||
mcore_long_t scan_cnt;
|
||||
@@ -329,6 +331,11 @@ struct GIE_aux_t
|
||||
GIE_handle_t* gie_handle;
|
||||
MESA_lqueue_head update_q;
|
||||
};
|
||||
struct rule_tag
|
||||
{
|
||||
char* tag_name;
|
||||
char* tag_val;
|
||||
};
|
||||
struct _Maat_scanner_t
|
||||
{
|
||||
long long version;
|
||||
@@ -399,6 +406,9 @@ struct _Maat_feather_t
|
||||
pthread_mutex_t redis_write_lock; //protect redis_write_ctx
|
||||
long long base_rgn_seq,base_grp_seq,server_time;
|
||||
long long load_version_from;
|
||||
|
||||
struct rule_tag *accept_tags;
|
||||
int n_tags;
|
||||
//internal states
|
||||
long long new_version;
|
||||
int active_plugin_table_num;
|
||||
@@ -451,6 +461,7 @@ struct serial_rule_t //rm= Redis Maat
|
||||
char table_name[256];
|
||||
char* table_line;
|
||||
};
|
||||
int parse_accept_tag(const char* value, struct rule_tag** result, void* logger);
|
||||
void garbage_bagging(enum maat_garbage_type type,void *p,MESA_lqueue_head garbage_q);
|
||||
void garbage_bury(MESA_lqueue_head garbage_q,void *logger);
|
||||
void make_group_set(const struct _Maat_compile_inner_t* compile_rule,universal_bool_expr_t* a_set);
|
||||
|
||||
@@ -8,13 +8,10 @@ CFLAGS = -Wall -g -fPIC
|
||||
CFLAGS += $(OPTFLAGS)
|
||||
#CFLAGS += $(GCOV_FLAGS)
|
||||
LDDICTATOR = -Wl,-wrap,malloc -Wl,-wrap,calloc -Wl,-wrap,free -Wl,-wrap,realloc
|
||||
LDFLAGS = -lMESA_handle_logger -lMESA_htable -lpthread -lrt -lm -lrulescan -lpcre -lMESA_field_stat2 -lcrypto -lhiredis_vip
|
||||
LDFLAGS += -lMESA_handle_logger -lMESA_htable -lpthread -lrt -lm -lrulescan -lpcre -lMESA_field_stat2 -lcrypto -lhiredis_vip
|
||||
#LDFLAGS += $(LDDICTATOR)
|
||||
LDFLAGS += $(GCOV_FLAGS)
|
||||
MAILLIB = ../lib
|
||||
|
||||
G_H_DIR =../inc_internal
|
||||
H_DIR =-I$(G_H_DIR) -I../../inc
|
||||
H_DIR =-I../inc_internal -I../../inc -I/opt/MESA/include/
|
||||
LIBMAAT = libmaatframe.a
|
||||
LIBMAAT_SO = libmaatframe.so
|
||||
|
||||
|
||||
@@ -715,10 +715,11 @@ int write_compile_rule(cJSON *compile,struct iris_description_t *p_iris,void * l
|
||||
compile_cmd[cmd_cnt].json_type=cJSON_Number;
|
||||
cmd_cnt++;
|
||||
|
||||
compile_cmd[cmd_cnt].json_string="effective_range";
|
||||
compile_cmd[cmd_cnt].json_type=cJSON_Number;
|
||||
|
||||
compile_cmd[cmd_cnt].json_string="tags";
|
||||
compile_cmd[cmd_cnt].json_type=cJSON_String;
|
||||
compile_cmd[cmd_cnt].empty_allowed=1;
|
||||
compile_cmd[cmd_cnt].default_int=0;
|
||||
compile_cmd[cmd_cnt].default_string="0";
|
||||
cmd_cnt++;
|
||||
|
||||
compile_cmd[cmd_cnt].json_string="user_region";
|
||||
|
||||
File diff suppressed because one or more lines are too long
@@ -558,7 +558,74 @@ void test_offset_str_scan(Maat_feather_t feather,const char* table_name)
|
||||
test_offset_str_scan_with_chunk(feather,table_name,1460);
|
||||
return;
|
||||
}
|
||||
void test_compile_accept_tags(Maat_feather_t feather)
|
||||
{
|
||||
int ret1=0, ret2=0;
|
||||
int table_id=0;
|
||||
scan_status_t mid=NULL;
|
||||
struct Maat_rule_t result[4];
|
||||
const char* should_hit="string bbb should hit";
|
||||
const char* should_not_hit="string aaa should not hit";
|
||||
const char* table_name="HTTP_URL";
|
||||
table_id=Maat_table_register(feather,table_name);
|
||||
if(table_id==-1)
|
||||
{
|
||||
printf("Database table %s register failed.\n",table_name);
|
||||
return;
|
||||
}
|
||||
|
||||
ret1=Maat_full_scan_string(feather, table_id,CHARSET_GBK, should_not_hit, strlen(should_not_hit),
|
||||
result,NULL, 4,
|
||||
&mid, 0);
|
||||
ret2=Maat_full_scan_string(feather, table_id,CHARSET_GBK, should_hit, strlen(should_hit),
|
||||
result,NULL, 4,
|
||||
&mid, 0);
|
||||
if(ret1<=0&&ret2>0)
|
||||
{
|
||||
printf("Test compile accept tags success.\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("Test compile accept tags failed.\n");
|
||||
}
|
||||
Maat_clean_status(&mid);
|
||||
return;
|
||||
}
|
||||
|
||||
void accept_tags_entry_cb(int table_id,const char* table_line,void* u_para)
|
||||
{
|
||||
char status[32]={0};
|
||||
int entry_id=-1,seq=-1;
|
||||
int is_valid=0;
|
||||
sscanf(table_line,"%d\t%s\t%d\t%d",&seq,status,&entry_id,&is_valid);
|
||||
printf("Test plugin accept tags loading %d %s.\n",seq, status);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
void test_plugin_accept_tags(Maat_feather_t feather)
|
||||
{
|
||||
int table_id=0,ret=0;
|
||||
const char* table_name="TEST_EFFECTIVE_RANGE_TABLE";
|
||||
table_id=Maat_table_register(feather,table_name);
|
||||
if(table_id==-1)
|
||||
{
|
||||
printf("Database table %s register failed.\n",table_name);
|
||||
}
|
||||
else
|
||||
{
|
||||
ret=Maat_table_callback_register(feather, table_id,
|
||||
NULL,
|
||||
accept_tags_entry_cb,
|
||||
NULL,
|
||||
NULL);
|
||||
if(ret<0)
|
||||
{
|
||||
printf("Maat callback register table %s error.\n",table_name);
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
void test_longer_service_define(Maat_feather_t feather, struct Maat_rule_t* rule)
|
||||
{
|
||||
int ret=0;
|
||||
@@ -1009,6 +1076,7 @@ int main(int argc,char* argv[])
|
||||
const char* stat_file="./scan_staus.log";
|
||||
const char* decrypt_key="mesa2017wy";
|
||||
const char* test_digest_file="./testdata/digest_test.data";
|
||||
const char* accept_tags="{\"tags\":[{\"tag\":\"location\",\"value\":\"北京/朝阳/华严北里/甲22号\"},{\"tag\":\"isp\",\"value\":\"移动\"}]}";
|
||||
int scan_interval_ms=1;
|
||||
int effective_interval_ms=0;
|
||||
|
||||
@@ -1065,6 +1133,7 @@ int main(int argc,char* argv[])
|
||||
Maat_set_feather_opt(feather, MAAT_OPT_STAT_ON, NULL, 0);
|
||||
Maat_set_feather_opt(feather, MAAT_OPT_PERF_ON, NULL, 0);
|
||||
Maat_set_feather_opt(feather, MAAT_OPT_SCAN_DETAIL, &scan_detail, sizeof(scan_detail));
|
||||
Maat_set_feather_opt(feather, MAAT_OPT_ACCEPT_TAGS, accept_tags, strlen(accept_tags)+1);
|
||||
Maat_initiate_feather(feather);
|
||||
|
||||
if(feather==NULL)
|
||||
@@ -1122,6 +1191,10 @@ int main(int argc,char* argv[])
|
||||
Maat_clean_status(&mid);
|
||||
|
||||
test_offset_str_scan(feather,"IMAGE_FP");
|
||||
|
||||
test_plugin_accept_tags(feather);
|
||||
test_compile_accept_tags(feather);
|
||||
|
||||
int value=0;
|
||||
if(1==using_redis)
|
||||
{
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
#id name type
|
||||
#
|
||||
#For plugin table
|
||||
#id name type valid_column
|
||||
#id name type valid_column tag_column
|
||||
#
|
||||
#For expr/expr_plus Table
|
||||
#id name type src_charset dst_charset do_merge cross_cache quick_mode
|
||||
@@ -22,8 +22,9 @@
|
||||
3 KEYWORDS_TABLE expr UTF8 GBK/BIG5/UNICODE/UTF8/unicode_ascii_esc/unicode_ascii_aligned/unicode_ncr_dec/unicode_ncr_hex yes 0
|
||||
4 IP_CONFIG ip --
|
||||
5 CONTENT_SIZE intval --
|
||||
6 QD_ENTRY_INFO plugin 4
|
||||
6 QD_ENTRY_INFO plugin 4 --
|
||||
7 FILE_DIGEST digest --
|
||||
8 HTTP_REGION expr_plus GBK GBK no 0
|
||||
9 SIM_URL similar --
|
||||
10 IMAGE_FP expr UTF8 UTF8 yes 128 quickoff
|
||||
11 TEST_EFFECTIVE_RANGE_TABLE plugin 4 5 --
|
||||
Reference in New Issue
Block a user