/* We have to remember the seq and store proc_seq and version. */ #include #include #include #include #include "MESA_handle_logger.h" #include "common_module.h" #include #include "func.h" #include #include #include #include #include #include #include "manager_service.h" int first_flag=0; int common_init(char *config_path,char *log_path,char *project_name,void *main_logger,char *common_config_name,common_module_t *_common) { int log_lv = 0,pz_type = 0,ret = 0; int write_file = 1, debug_flag=0,zg_switch=0,relibility_switch=0,cpu_check_time=0; char node_topic[MAX_PATH_LENGTH] = {0};char business_name[MAX_PATH_LENGTH]={0}; char net_device[MAX_PATH_LENGTH]={0};char _ip[32]={0}; char run_log_path[MAX_PATH_LENGTH] = "";char pz_log_path[MAX_PATH_LENGTH] = ""; char err_log_path[MAX_PATH_LENGTH] = "";char redis_log_path[MAX_PATH_LENGTH] = ""; char perf_log_path[MAX_PATH_LENGTH] = "";char zg_log_path[MAX_PATH_LENGTH] = ""; sprintf(common_config_name, "%s/%s", config_path, COMMON_CONFIG_NAME); if(access(common_config_name, 0) == -1) { ret = -1; MESA_HANDLE_RUNTIME_LOG(main_logger,RLOG_LV_FATAL,"[TENSOR]","conf %s is not existent!",common_config_name); } ret = MESA_load_profile_int_def (common_config_name, "CONFIG", "log_lv", &log_lv, RLOG_LV_INFO); ret = MESA_load_profile_int_def (common_config_name, "CONFIG", "pz_type", &pz_type,PZ_TYPE_DETERMINANT);// default : soq rc mode ret = MESA_load_profile_int_def (common_config_name, "CONFIG", "debug_switch", &debug_flag, 0); ret = MESA_load_profile_int_def (common_config_name, "CONFIG", "write_file", &write_file, 1); ret = MESA_load_profile_int_def (common_config_name, "CONFIG", "zg_switch", &zg_switch, 0); ret = MESA_load_profile_int_def (common_config_name, "CONFIG", "relibility_switch", &relibility_switch, 0); ret = MESA_load_profile_int_def (common_config_name, "ZG", "cpu_check_time", &cpu_check_time, 600); ret = MESA_load_profile_string_nodef (common_config_name, "CONFIG", "node_topic", node_topic, MAX_PATH_LENGTH); ret = MESA_load_profile_string_nodef (common_config_name, "CONFIG", "business_name", business_name, MAX_PATH_LENGTH); ret = MESA_load_profile_string_nodef (common_config_name, "CONFIG", "net_device", net_device, MAX_PATH_LENGTH); ret = MESA_load_profile_string_nodef (common_config_name, "WIRED_INFO", "REMOTE_DIR", _common->level, MAX_LENGTH); assert(ret >=0); check_file_path (log_path); sprintf (_common->config_path, "%s",config_path); sprintf (_common->log_path, "%s",log_path); sprintf (_common->node_topic,"%s",node_topic); sprintf (run_log_path, "%s/%s",log_path,"runtimelog"); sprintf (pz_log_path, "%s/%s",log_path,"pz_stats"); sprintf (err_log_path, "%s/%s",log_path,"err_stats"); sprintf (redis_log_path, "%s/%s",log_path,"maat_stat"); sprintf (perf_log_path, "%s/%s",log_path,"performance"); sprintf (zg_log_path, "%s/%s",log_path,"zg_stats"); _common->main_logger= main_logger; _common->runtime_logger = MESA_create_runtime_log_handle(run_log_path, log_lv); _common->stat_logger = MESA_create_runtime_log_handle(pz_log_path, log_lv); _common->error_logger = MESA_create_runtime_log_handle(err_log_path, log_lv); _common->maat_logger = MESA_create_runtime_log_handle(redis_log_path, log_lv); _common->perf_logger = MESA_create_runtime_log_handle(perf_log_path, log_lv); _common->zg_logger = MESA_create_runtime_log_handle(zg_log_path, log_lv); //added by zzy _common->debug_switch = debug_flag; _common->write_file = write_file; _common->zg_switch = zg_switch; _common->relibility_switch = relibility_switch; _common->maat_init_type = TENSOR_MAAT_INTI_TYPE_START; memset(_common->redis_ip,0,MAX_IP_LENGTH); //pz_type:0:determinant 1:not_determinant _common->pz_type = pz_type; if((_common->runtime_logger == NULL) || (_common->stat_logger == NULL) || ( _common->error_logger == NULL)|| (_common->maat_logger == NULL) || (_common->perf_logger == NULL) || (_common->zg_logger == NULL)) { printf("cant not open log file: %s\n","./log/*"); return -1; } //register table to get the business table info ret = table_register_init(_common); assert(ret>=0); if( ret < 0) { ret= -1; MESA_HANDLE_RUNTIME_LOG(_common->error_logger ,RLOG_LV_FATAL,"[COMMON]","table_register_init init failed!"); } _common->register_table_num = (_common->registered_table_info).size(); tensor_field_stat_init(_common,common_config_name,log_path); //for zg _common->local_state_for_manager = new local_state_info(); _common->local_state_for_manager->cpu_check_time = cpu_check_time; _common->local_state_for_manager->boot_time = common::Func::curr_time(); _common->local_state_for_manager->zg_log_handler.SendLogInit(_common->config_path, _common->runtime_logger); //added by zzy if(project_name != NULL) //added by zzy _common->local_state_for_manager->app_name.assign(project_name); //added by zzy strcpy (_common->local_state_for_manager->node_topic, node_topic); strcpy (_common->local_state_for_manager->business_name, business_name); common::Func::GetLocalIP(net_device, _ip); strcpy (_common->local_state_for_manager->local_ip_str, _ip); _common->local_state_for_manager->role = get_role(_common); //added by zzy if(!strcmp(business_name, "T1-1")) _common->local_state_for_manager->colombo_user_id = CLMB_USERID_TEXTA; else if(!strcmp(business_name, "T1-2")) _common->local_state_for_manager->colombo_user_id = CLMB_USERID_TEXTB; else if(!strcmp(business_name, "JK")) _common->local_state_for_manager->colombo_user_id = CLMB_USERID_STATIC; else if(!strcmp(business_name, "T1-2_YSP")) _common->local_state_for_manager->colombo_user_id = CLMB_USERID_VEDIO; else if(!strcmp(business_name, "IPZY")) _common->local_state_for_manager->colombo_user_id = CLMB_USERID_IPZY; else if(!strcmp(business_name, "VOIP")) _common->local_state_for_manager->colombo_user_id = CLMB_USERID_VOIP; else if(!strcmp(business_name, "YSP")) _common->local_state_for_manager->colombo_user_id = CLMB_USERID_NONCSVEDIO; else if(!strcmp(business_name, "T2-1")) _common->local_state_for_manager->colombo_user_id = CLMB_USERID_ANALYZE; else { MESA_handle_runtime_log(_common->runtime_logger, RLOG_LV_FATAL, "[COMMON]", "business name: %s is not valid!", business_name); ret = -1; } //added by zzy return 0; } void tensor_field_stat_init(common_module_t *_common,char *common_config_name,char *log_path) { int ret = 0,print_mode = 0,value = 0,index=0; char tensor_fs_log_path[MAX_PATH_LENGTH]; char app_name[MAX_PATH_LENGTH]="Tensor"; char fs_dst_ip[MAX_PATH_LENGTH]={0}; int fs_dst_port = 0; unsigned short int fs_port_short = 0; ret = MESA_load_profile_int_def(common_config_name, "FS_STAT", "print_mode", &print_mode, 1); ret = MESA_load_profile_string_def(common_config_name, "FS_STAT", "dst_ip", fs_dst_ip, MAX_PATH_LENGTH,"127.0.0.1"); ret = MESA_load_profile_int_def(common_config_name, "FS_STAT", "dst_port", &fs_dst_port, 8125); sprintf (tensor_fs_log_path,"%s/%s",log_path,"config_field_stat.log"); //Add by ljp:Field Stat 20180323 _common->stat_handle = FS_create_handle(); FS_set_para(_common->stat_handle,OUTPUT_DEVICE,tensor_fs_log_path,strlen(tensor_fs_log_path)+1); //default is 1 the meaning is 1:Rewrite ,2:Append FS_set_para(_common->stat_handle,PRINT_MODE,&print_mode,sizeof(int)); value = 0; FS_set_para(_common->stat_handle,CREATE_THREAD,&value,sizeof(value)); FS_set_para(_common->stat_handle,APP_NAME,app_name,strlen(app_name)+1); if(_common->run_mode == PRODUCER_MODE) { FS_set_para(_common->stat_handle,STATS_SERVER_IP,fs_dst_ip,strlen(fs_dst_ip)+1); fs_port_short = fs_dst_port; FS_set_para(_common->stat_handle,STATS_SERVER_PORT,&fs_port_short,sizeof(fs_dst_port)); } _common->fs_status_id[STATUS_VERSION] = FS_register(_common->stat_handle,FS_STYLE_STATUS,FS_CALC_CURRENT,"version"); _common->fs_status_id[STATUS_TABLE_NUM] = FS_register(_common->stat_handle,FS_STYLE_STATUS,FS_CALC_CURRENT,"table_num"); _common->fs_status_id[STATUS_TOTAL_NUM] = FS_register(_common->stat_handle,FS_STYLE_STATUS,FS_CALC_CURRENT,"total_rule_num"); if(_common->run_mode == PRODUCER_MODE) { _common->fs_status_id[STATUS_VALID_NUM] = FS_register(_common->stat_handle,FS_STYLE_STATUS,FS_CALC_CURRENT,"total_valid_num"); _common->fs_status_id[STATUS_INVALID_NUM] = FS_register(_common->stat_handle,FS_STYLE_STATUS,FS_CALC_CURRENT,"total_invalid_num"); _common->fs_status_id[STATUS_ERROR_NUM] = FS_register(_common->stat_handle,FS_STYLE_STATUS,FS_CALC_CURRENT,"total_error_num"); } _common->fs_column_id[COLUMN_TABLE_TOTAL_NUM] = FS_register(_common->stat_handle,FS_STYLE_COLUMN,FS_CALC_CURRENT,"total_num"); _common->fs_column_id[COLUMN_TABLE_CORRECT_NUM] = FS_register(_common->stat_handle,FS_STYLE_COLUMN,FS_CALC_CURRENT,"correct_num"); _common->fs_column_id[COLUMN_TABLE_ERROR_NUM] = FS_register(_common->stat_handle,FS_STYLE_COLUMN,FS_CALC_CURRENT,"error_num"); for(set::iterator table = (_common->registered_table_info).begin();\ table!=(_common->registered_table_info).end();\ table++) { _common->fs_line_id[index] = FS_register(_common->stat_handle,FS_STYLE_LINE,FS_CALC_CURRENT,(*table).c_str()); index++; } FS_start(_common->stat_handle); } // generate a vector:registered_table_info int table_register_init(common_module_t *_common) { //TODO: No support for multi business char table_register_file[MAX_PATH_LENGTH]; int ret = snprintf(table_register_file, MAX_PATH_LENGTH, "%s/%s",_common->config_path, COMMON_REDIS_NAME); if(ret == MAX_PATH_LENGTH) { MESA_HANDLE_RUNTIME_LOG(_common->error_logger,RLOG_LV_FATAL,"[table_register]"," config file:maat_redis.conf load , dir exceed the max length!"); return -1; } FILE* table_info_fp=NULL; char line[MAX_ONE_MSG_LEN] = {0}; char file_name[MAX_TABLE_NAME_LEN] = {0}; table_info_fp=fopen(table_register_file, "r"); while(fgets(line, sizeof(line), table_info_fp)) { if(strlen(line)<2) { MESA_HANDLE_RUNTIME_LOG(_common->error_logger,RLOG_LV_FATAL,"[table_register]","table read error ,check the %s!", table_register_file); continue; } // if we read table name from maat_redis.conf ,decline a config file ret = rc_get_field_value(line, 2, 2, '\t', file_name, sizeof(file_name)); if(ret <0){ MESA_HANDLE_RUNTIME_LOG(_common->error_logger, RLOG_LV_FATAL, "[table_register]","rc_get_field_value rc=%d,read file:maat_redis.conf format ERROR",ret); return -1; } _common->registered_table_info.insert(string(file_name)); //cout<<"file_name:"<register_table_num;i++) { FS_operate(common->stat_handle,common->fs_line_id[i],common->fs_column_id[COLUMN_TABLE_TOTAL_NUM],FS_OP_SET,0); FS_operate(common->stat_handle,common->fs_line_id[i],common->fs_column_id[COLUMN_TABLE_CORRECT_NUM],FS_OP_SET,0); FS_operate(common->stat_handle,common->fs_line_id[i],common->fs_column_id[COLUMN_TABLE_ERROR_NUM],FS_OP_SET,0); } } unsigned long get_file_size (const char *file) { struct stat st; if(lstat(file,&st)==0) { return st.st_size; } else { return 0; } return 1; } int get_role(common_module_t * common) { int role=-1; if(common->run_mode == PRODUCER_MODE) { role = 1; } else if(common->run_mode == CONSUMER_MODE) { role = 3; } return role; } static int create_path (char *path) { if(access(path, 0) == -1) { if(mkdir(path, 0777)) { printf("cannnot create path:%s",path); return -1; } } return 0; } static char *jump_over_char (char *src, char c) { while (*src == c) src ++; return src; } int create_path_p (char *path) { char *pos = NULL; char *dest = NULL; char tmp[128] = {0}; int len = 0; dest = path; dest = jump_over_char (dest, '/'); while ((dest != NULL) && ((pos = strchr (dest, '/')) != NULL)) { len = pos - path; strncpy (tmp, path, len); tmp[len] = '\0'; if (create_path (tmp) < 0) { return -1; } dest = pos +1; } if (*dest != '\0') { if (create_path (path) < 0) { return -1; } } return 0; } //added by zzy string get_file_name(const char *file_path) { string s; char *name,fname[255]={0}; strcpy(fname,file_path); if ((name = strrchr (fname, '/')) != NULL) { name += 1; } else { name = fname; } s+= name; return s; } //added by zzy int get_file_name(const char *content, char *file_name, int len) { const char *cur = content; int i = 0; while(cur != 0) { if (*cur == '\t') { break; } if (i>len-1) { break; } file_name[i] = *cur; i++; cur++; } file_name[i] = 0; return i; } bool is_number(const char * str) { const char *p= str; if(*p == '0' && *(p+1) != '0' &&*(p+1)!=0) { return false; } int len=strlen(str); while(p - str < len -1 ) { if(!isdigit(*p)) return false; p++; } //lastest character return ((*p=='\n') ||isdigit(*p)) ; } bool parse_determinant(const char *line) { //"%s\t%d\t%s\t%d\t%d", //123 ssh 123 fbas dishjs vector sub_string; common::Func::split_string(line,'\t',sub_string); if(sub_string.size() != 5) return false; return is_number(sub_string[1].c_str()) && is_number(sub_string[3].c_str()) && is_number(sub_string[4].c_str()) ; } bool parse_indeterminant(const char *line) { //ret=sscanf(line, "%ld\t%s\t%d\t%s\t%s\t%s\t%s" // ssjsjd sjsjd vector sub_string; common::Func::split_string(line,'\t',sub_string); if(sub_string.size() != 7) return false; return is_number(sub_string[0].c_str()) && is_number(sub_string[2].c_str()); } bool topic_check(int run_mode,const char *msg_topic,char *node_topic) { int i,cnt=0; int node_topic_len = 0; if(run_mode == CONSUMER_MODE) node_topic_len = strlen(node_topic); vector sub_string; if(msg_topic == NULL){ return false; } if((run_mode == CONSUMER_MODE)&&(memcmp(msg_topic,"0",1) == 0)) { return true; } common::Func::split_string(msg_topic,',',sub_string); cnt = sub_string.size(); for(i=0;i'9' || sub_string[i][j]<'0'){ return false; } } } else { int len = sub_string[i].size(); len = node_topic_len > len ? node_topic_len:len; if(memcmp(sub_string[i].c_str(),node_topic,len) == 0){ return true; } } } if(run_mode == PRODUCER_MODE) return true; else return false; } int my_scandir_m(const char *dir, struct dirent ***namelist, int(*filter)(const struct dirent *), int(*compar)(const void *, const void *)) { DIR * od; int n = 0; int DIR_ENT_SIZE=ENLARGE_STEP; struct dirent ** list = NULL; struct dirent * p; struct dirent entry,*result; if((dir == NULL) || (namelist == NULL)) return -1; od = opendir(dir); if(od == NULL) return -1; list = (struct dirent **)malloc(DIR_ENT_SIZE*sizeof(struct dirent *)); while(0==readdir_r(od,&entry,&result)) { if(result==NULL) { break; } if( filter && !filter(&entry)) continue; p = (struct dirent *)malloc(sizeof(struct dirent)); memcpy((void *)p,(void *)(&entry),sizeof(struct dirent)); list[n] = p; n++; if(n >= DIR_ENT_SIZE) { DIR_ENT_SIZE+=ENLARGE_STEP; list=(struct dirent **)realloc((void*)list,DIR_ENT_SIZE*sizeof(struct dirent *)); } } closedir(od); *namelist = list; if(compar) qsort((void *)*namelist,n,sizeof(struct dirent *),compar); return n; } int issued_cfg_immediately(char *filename, void *logger) { int is_issued = 0; FILE*fp=fopen(filename, "r"); if(fp==NULL) { MESA_HANDLE_RUNTIME_LOG(logger, RLOG_LV_FATAL, "issued_cfg_immediately", "<%s +%d> index file %s fopen failed.", __FILE__, __LINE__, filename); return 0; } fscanf(fp, "%d\n", &is_issued); fclose(fp); return is_issued; } int filter_fn_m(const struct dirent * ent) { //if(ent->d_type != DT_REG) // return 0; return (strncmp(ent->d_name,"full_config_index",strlen("full_config_index")) == 0|| strncmp(ent->d_name,"inc_config_index",strlen("inc_config_index")) == 0); } int is_expexted_index_format(char *scan_dir, char *filename, char *update_str, unsigned int *config_seq, void *logger) { int sscanf_ret= 0; char index_name[256]; if((strcmp(filename, ".") == 0) || (strcmp(filename, "..") == 0)) { return 0; } if(strlen(filename)>32) { MESA_HANDLE_RUNTIME_LOG(logger,RLOG_LV_FATAL, "filter_index_format" ,"<%s +%d> config file %s filename too long,should like full_config_index.0000000001" __FILE__, __LINE__, filename); return 0; } sscanf_ret=sscanf(filename,"%[a-zA-Z]_config_index.%u", update_str, config_seq); if(sscanf_ret!=2) { MESA_HANDLE_RUNTIME_LOG(logger,RLOG_LV_FATAL, "filter_index_format" ,"<%s +%d> config file %s filename error,should like full_config_index.0000000001" __FILE__, __LINE__, filename); return 0; } snprintf(index_name, sizeof(index_name), "%s/%s", scan_dir, filename); if((!issued_cfg_immediately(index_name, logger))) { MESA_HANDLE_RUNTIME_LOG(logger, RLOG_LV_DEBUG, "filter_index_format" ,"<%s +%d> config file %s don't issued immediately", __FILE__, __LINE__, index_name); return 0; } return 1; } int filter_expected_determinant_index(char *scan_dir, struct dirent **namelist, int original_name_num, unsigned long *version, char *expect_format_name, int idx_name_len, void *logger) { int i = 0; char update_str[32]={0}; unsigned int latest_ful_version=0; unsigned int config_seq=0; unsigned int inc_base_version_next = 0; int inc_file_idx = 0, len = 0; int full_file_idx = 0; for(i = 0; i < original_name_num; i++) { if(!is_expexted_index_format(scan_dir, namelist[i]->d_name, update_str, &config_seq, logger)) { continue; } if(strncasecmp(update_str, "full", strlen(update_str))==0) { if(config_seq > latest_ful_version) {/* find max version and record index of namelist */ latest_ful_version=config_seq; full_file_idx = i; } } else if(strncasecmp(update_str, "inc", strlen(update_str))==0) {/* */ if(config_seq > *version) { if(inc_base_version_next == 0) { inc_base_version_next = config_seq; inc_file_idx = i; break; } if(config_seq < inc_base_version_next) { inc_base_version_next=config_seq; inc_file_idx = i; } } } else { MESA_HANDLE_RUNTIME_LOG(logger,RLOG_LV_FATAL, "filter_expected_determinant_index" ,"<%s +%d> config file %s,not full or inc config" __FILE__, __LINE__, namelist[i]->d_name); return UPDATE_NONE; } } if(inc_base_version_next>*version || latest_ful_version >*version) { if(first_flag == 0 && latest_ful_version > 0) { first_flag = 1; len = MIN((int)strlen(namelist[full_file_idx]->d_name), idx_name_len); memcpy(expect_format_name, namelist[full_file_idx]->d_name, len); *version = latest_ful_version; return UPDATE_TYPE_FULL; } if(latest_ful_version>inc_base_version_next && latest_ful_version >*version) { len = MIN((int)strlen(namelist[full_file_idx]->d_name), idx_name_len); memcpy(expect_format_name, namelist[full_file_idx]->d_name, len); *version = latest_ful_version; return UPDATE_TYPE_FULL; } else { len = MIN((int)strlen(namelist[inc_file_idx]->d_name), idx_name_len); memcpy(expect_format_name, namelist[inc_file_idx]->d_name, len); *version = inc_base_version_next; return UPDATE_TYPE_INC; } } return UPDATE_NONE; } int filter_expected_indeterminant_index(char *scan_dir, struct dirent **namelist, int original_name_num, unsigned long *version, char *expect_format_name, int idx_name_len, void *logger) { int i = 0, len = 0; char update_str[32]={0}; unsigned int config_seq=0; unsigned int full_base_version_next = 0; int full_file_idx = 0; for(i = 0; i < original_name_num; i++) { if(!is_expexted_index_format(scan_dir, namelist[i]->d_name, update_str, &config_seq, logger)) { continue; } if(strncasecmp(update_str, "full", strlen(update_str))==0) { if(config_seq > *version) { if(full_base_version_next == 0) { full_base_version_next = config_seq; full_file_idx = i; break; } if(config_seq < full_base_version_next) { full_base_version_next=config_seq; full_file_idx = i; } } } else { MESA_HANDLE_RUNTIME_LOG(logger,RLOG_LV_FATAL, "filter_expected_determinant_index" ,"<%s +%d> config file %s,not full or inc config" __FILE__, __LINE__, namelist[i]->d_name); return UPDATE_TYPE_INC; } } if(full_base_version_next >*version) { len = MIN((int)strlen(namelist[full_file_idx]->d_name), idx_name_len); memcpy(expect_format_name, namelist[full_file_idx]->d_name, len); *version = full_base_version_next; return UPDATE_TYPE_FULL; } return UPDATE_NONE; } int get_index_name(char *scan_dir, unsigned long *version, char *increase_idx_name, int idx_name_len, int pz_type, void *logger) { int i = 0, index_n = 0; struct dirent **namelist; int meta_type = UPDATE_NONE; index_n = my_scandir_m(scan_dir, &namelist, filter_fn_m, (int (*)(const void*, const void*))alphasort); if(index_n <= 0) { return UPDATE_NONE; } switch(pz_type) { case PZ_TYPE_DETERMINANT: meta_type = filter_expected_determinant_index(scan_dir, namelist, index_n, version, increase_idx_name, idx_name_len, logger); break; case PZ_TYPE_NOT_DETERMINANT: meta_type = filter_expected_indeterminant_index(scan_dir, namelist, index_n, version, increase_idx_name, idx_name_len, logger); break; } for(i = 0; i < index_n; i++) { free(namelist[i]); } free(namelist); return meta_type; } int rc_get_field_value(const char *line, int s_field_location, int e_field_location, char separator, char *outbuf, int outbuf_len) { int i = 0, used_len = 0; const char *s_start = NULL, *s_end = NULL; char *buf = NULL; buf = outbuf; string _line(line); if(line == NULL || buf == NULL || outbuf_len == 0) { return -1; } for(i=1, s_start=line; i<=s_field_location; i++) { s_end = strchr(s_start, separator); if(i == s_field_location) break; if(s_end == NULL) return FORMAT_ERROR; s_start=s_end+1; } if(s_field_location == e_field_location) { sscanf(s_start, "%[^ ]", buf); return 0; } else if(s_field_location > e_field_location) { snprintf(buf, outbuf_len, "%s", s_start); } else { for(i = 0; i <= e_field_location-s_field_location; i++) { s_end = strchr(s_start, separator); if(i> 4) & 0x0f; out_md5[i*2] = hexc[index]; index = md5[i] & 0x0f; out_md5[i*2 +1] = hexc[index]; } return 0; } int file_md5sum (const char *file, char *out_md5) { MD5_CTX ctx; unsigned int i = 0; unsigned char md5[16] = {0}; FILE *fp = NULL; int index = 0; int read_size = 0; char *tmp[10240]; MD5_Init (&ctx); if (NULL == (fp = fopen (file, "r"))) { printf ("fopen file fail (%s)\n", file); memset (out_md5, 0, 32); return -1; } while (0 == feof (fp)) { read_size = fread (tmp, 1, 10240, fp); if (read_size > 0) { MD5_Update (&ctx, tmp, read_size); } else { break; } } fclose (fp); MD5_Final (md5, &ctx); for (i = 0; i < sizeof (md5); i ++) { index = (md5[i] >> 4) & 0x0f; out_md5[i*2] = hexc[index]; index = md5[i] & 0x0f; out_md5[i*2 +1] = hexc[index]; } return 0; } //added by zzy void msg_send_log_destroy (send_log_handle_t *send_log_hd) { if (send_log_hd != NULL) { magellan_logger_destroy(send_log_hd->magellan_logger); free (send_log_hd); } } //added by zzy