修改回调表的更新机制,以节约内存。

This commit is contained in:
zhengchao
2015-12-24 17:58:40 +08:00
parent a2adbe25c9
commit 81d9a389cc
4 changed files with 33 additions and 13 deletions

View File

@@ -33,4 +33,12 @@ gb2312;
2) use readdir_r in my_scandir; 2) use readdir_r in my_scandir;
3) fix segmentfault when have no config,again; 3) fix segmentfault when have no config,again;
4) maat_json support plugin table; 4) maat_json support plugin table;
2015-07-03 1)print error when Maat_summon_feather with a dir has no valid
indexfile;
2)check AND_EXPR's match method;
3)remove restriction of IP table's protocol;
4)fix invalid write in insert_set_id function;
2015-07-06 1)handle wrong expr format like "aa&&bb" and "aa&bb&";
2)iconv_convert performance optimized;
2015-10-19 check table_type in callback register; 2015-10-19 check table_type in callback register;
2015-12-24 change plugin table update mechanism to save memory;

View File

@@ -21,7 +21,7 @@
#include "rulescan.h" #include "rulescan.h"
#include "UniversalBoolMatch.h" #include "UniversalBoolMatch.h"
int MAAT_FRAME_VERSION_1_2_20151113=0; int MAAT_FRAME_VERSION_1_2_20151224=1;
const char *maat_module="MAAT Frame"; const char *maat_module="MAAT Frame";
const char* CHARSET_STRING[]={"CHARSET_NONE","GBK","BIG5","UNICODE","UTF-8"}; const char* CHARSET_STRING[]={"CHARSET_NONE","GBK","BIG5","UNICODE","UTF-8"};
@@ -351,6 +351,7 @@ int read_table_info(struct _Maat_table_info_t** p_table_info,int num,const char*
{ {
p->cb_info=(struct _plugin_table_info*)calloc(sizeof(struct _plugin_table_info),1); p->cb_info=(struct _plugin_table_info*)calloc(sizeof(struct _plugin_table_info),1);
p->cb_info->cache_lines=dynamic_array_create(1024,1024); p->cb_info->cache_lines=dynamic_array_create(1024,1024);
pthread_mutex_init(&(p->cb_info->plugin_mutex),NULL);
} }
p_table_info[p->table_id]=p; p_table_info[p->table_id]=p;
table_cnt++; table_cnt++;
@@ -1905,16 +1906,25 @@ void plugin_table_callback(struct _Maat_table_info_t* table,const char* table_li
int i=0; int i=0;
unsigned int len=strlen(table_line)+1; unsigned int len=strlen(table_line)+1;
struct _plugin_table_info* p_table_cb=table->cb_info; struct _plugin_table_info* p_table_cb=table->cb_info;
char *p=NULL;
pthread_mutex_lock(&(p_table_cb->plugin_mutex));
if(p_table_cb->cb_plug_cnt>0)
{
for(i=0;i<p_table_cb->cb_plug_cnt;i++) for(i=0;i<p_table_cb->cb_plug_cnt;i++)
{ {
p_table_cb->cb_plug[i].update(table->table_id,table_line,p_table_cb->cb_plug[i].u_para); p_table_cb->cb_plug[i].update(table->table_id,table_line,p_table_cb->cb_plug[i].u_para);
} }
char *p=(char*)calloc(len,1); }
else
{
p=(char*)calloc(len,1);
memcpy(p,table_line,len); memcpy(p,table_line,len);
p_table_cb->cache_size+=len; p_table_cb->cache_size+=len;
dynamic_array_write(p_table_cb->cache_lines,p_table_cb->line_num,p); dynamic_array_write(p_table_cb->cache_lines,p_table_cb->line_num,p);
p_table_cb->line_num++; p_table_cb->line_num++;
} }
pthread_mutex_unlock(&(p_table_cb->plugin_mutex));
}
void maat_start_cb(unsigned int new_version,int update_type,void*u_para) void maat_start_cb(unsigned int new_version,int update_type,void*u_para)
{ {
struct _Maat_feather_t *feather=(struct _Maat_feather_t *)u_para; struct _Maat_feather_t *feather=(struct _Maat_feather_t *)u_para;
@@ -2592,13 +2602,11 @@ int Maat_table_callback_register(Maat_feather_t feather,short table_id,
{ {
return -1; return -1;
} }
if(p_table->table_type!=TABLE_TYPE_PLUGIN) pthread_mutex_lock(&(p_table->cb_info->plugin_mutex));
{
return -1;
}
idx=p_table->cb_info->cb_plug_cnt; idx=p_table->cb_info->cb_plug_cnt;
if(idx==MAX_PLUGING_NUM) if(idx==MAX_PLUGING_NUM)
{ {
pthread_mutex_unlock(&(p_table->cb_info->plugin_mutex));
return -1; return -1;
} }
p_table->cb_info->cb_plug_cnt++; p_table->cb_info->cb_plug_cnt++;
@@ -2620,6 +2628,7 @@ int Maat_table_callback_register(Maat_feather_t feather,short table_id,
} }
finish(u_para); finish(u_para);
} }
pthread_mutex_unlock(&(p_table->cb_info->plugin_mutex));
return 1; return 1;
} }
int Maat_full_scan_string_detail(Maat_feather_t feather,int table_id int Maat_full_scan_string_detail(Maat_feather_t feather,int table_id

View File

@@ -179,6 +179,7 @@ struct _plugin_table_info
dynamic_array_t *cache_lines; dynamic_array_t *cache_lines;
int line_num; int line_num;
long cache_size; long cache_size;
pthread_mutex_t plugin_mutex;
}; };
struct _Maat_table_info_t struct _Maat_table_info_t
{ {

View File

@@ -5,7 +5,9 @@ CC = g++
CCC = g++ CCC = g++
CFLAGS = -Wall -g -fPIC CFLAGS = -Wall -g -fPIC
CFLAGS += $(OPTFLAGS) CFLAGS += $(OPTFLAGS)
LDDICTATOR = -Wl,-wrap,malloc -Wl,-wrap,calloc -Wl,-wrap,free -Wl,-wrap,realloc
LDFLAGS = -lMESA_handle_logger -lMESA_htable -lpthread LDFLAGS = -lMESA_handle_logger -lMESA_htable -lpthread
#LDFLAGS += $(LDDICTATOR)
MAILLIB = ../lib MAILLIB = ../lib
G_H_DIR =../inc_internal G_H_DIR =../inc_internal