summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author姜鹏辉 <[email protected]>2020-12-16 19:20:00 +0800
committer姜鹏辉 <[email protected]>2020-12-17 17:01:40 +0800
commit45ce25f044c8c444b7aff9743052043b2b088ed0 (patch)
treef922bd5bf9648f5952178308fa82ff301332ce60
parent456bf217ae3d2f3e1112aee763d3df20122e9623 (diff)
fix bugsHEADmaster
-rw-r--r--qq_file_send.c93
-rw-r--r--qq_file_send.conf45
-rw-r--r--qq_file_send.inf51
3 files changed, 102 insertions, 87 deletions
diff --git a/qq_file_send.c b/qq_file_send.c
index e4ec8ba..deccb7e 100644
--- a/qq_file_send.c
+++ b/qq_file_send.c
@@ -30,7 +30,7 @@ typedef struct
uint8_t send_type; // OFFLINE_SEND
char uuid[UUID_LENGTH+1];
uint16_t content_len; // content length in current packet
- char filename[NAME_SIZE];
+ char filename[NAME_SIZE*2];
struct nirvana_streaming_ctx *ctx;
uint8_t next_flag; // 1: next packet contains separator
// 0: not contain
@@ -57,7 +57,7 @@ typedef struct
{
uint id;
uint8_t send_type;
- char filename[NAME_SIZE];
+ char filename[NAME_SIZE*2];
struct nirvana_streaming_ctx *ctx;
uint64_t *file_len; // file length
}file_info;
@@ -72,7 +72,7 @@ void *runtime_log;
struct nirvana_instance *instance_asyn;
/*
- * @Description: use like strncmp
+ * @Description: Use this function instead of strncmp ,because strncmp may have problems matching features
* @param: the main string
* @param: the pattern string to be searched
* @param: the len of pattern sting
@@ -91,10 +91,10 @@ int bicmp(char *str,char *ptn,int len)
}
/*
- * @Description: Processing payload and extracting separator
+ * @Description: Extract the information of private protocols in payload
* @param: payload
- * @param: payload_len
- * @param: Characteristics of separators
+ * @param: payload_len
+ * @param: features of separators
* @param: pme
* @return: =0 : success
<0 : fail
@@ -114,7 +114,7 @@ int parse_separator(char **payload,int payload_len,struct_separator_feature sepa
}
qq_pme_info_p qq_pme = *pme;
strncpy(qq_pme->uuid,(*payload) + separator_feature.uuid_deviation,uuid_len);
- qq_pme->uuid[uuid_len+1] = '\0';
+ qq_pme->uuid[uuid_len] = '\0';
//printf("this uuid:%s\n",qq_pme->uuid);
(*payload)+=separator_feature.content_deviation;
@@ -126,10 +126,12 @@ int parse_separator(char **payload,int payload_len,struct_separator_feature sepa
/*
- * @Description: find end suffix in payload
- * @param:
- * @param:
- * @param:
+ * @Description: find end suffix in response payload
+ if found,means the end of the current file transfer
+ * @param: payload
+ * @param: payload_len
+ * @param: separator_feature
+ * @param: file_id
* @return: =0 : success
<0 : fail
*/
@@ -266,14 +268,16 @@ void free_fileinfo(void *thisfile)
MESA_handle_runtime_log(runtime_log,RLOG_LV_INFO,"offline","save file %d , size: %lld bytes",p->id, *(p->file_len));
else
MESA_handle_runtime_log(runtime_log,RLOG_LV_INFO,"online","save file %d , size: %lld bytes",p->id, *(p->file_len));
- free(p->file_len);
+ if(p->file_len)
+ free(p->file_len);
free(p);
}
/*
* @Description: different files have different uuids.
- modify the filename in pme according to the current uuid
+ Fragments with the same UUID belong to the same file
+ get the pme according to the current uuid
* @param: pme
* @param: content len
* @param: send_type
@@ -296,7 +300,7 @@ int match_uuid(qq_pme_info **pme)
newfile->id = qq_pme->id;
sprintf(qq_pme->filename,"%s/%d-%s",save_directory,qq_pme->id,qq_pme->uuid);
- strncpy(newfile->filename,qq_pme->filename,strlen(qq_pme->filename));
+ strncpy(newfile->filename,qq_pme->filename,NAME_SIZE);
newfile->filename[strlen(qq_pme->filename)] = '\0';
uint64_t *file_len = (uint64_t *)malloc(sizeof(uint64_t));
@@ -371,7 +375,7 @@ void free_pme(qq_pme_info **pme)
uchar qq_file_send_entry(stSessionInfo* session_info,void **pme,int thread_seq,struct streaminfo *a_tcp,void *a_packet)
{
- int res;
+ int res = 0;
uchar rec = PROT_STATE_GIVEME;
//int payload_len = tcp_detail->datalen;
@@ -391,6 +395,7 @@ uchar qq_file_send_entry(stSessionInfo* session_info,void **pme,int thread_seq,s
{
*pme =(qq_pme_info_p)malloc(sizeof(qq_pme_info));
qq_pme = *pme;
+ memset(qq_pme->filename,0,NAME_SIZE);
}
qq_pme->curdir = a_http->curdir;
break;
@@ -402,15 +407,14 @@ uchar qq_file_send_entry(stSessionInfo* session_info,void **pme,int thread_seq,s
break;
case HTTP_MESSAGE_URL:
{
- char bmd5[34];
+ char bmd5[33];
int url_decoded_len;
url_decoded_len = session_info->buflen;
- char *url_decoded = (char*) malloc(url_decoded_len*sizeof(char));
+ char *url_decoded = (char*)calloc(url_decoded_len+1,sizeof(char));
memcpy(url_decoded, session_info->buf, session_info->buflen);
res = sscanf(url_decoded,"%*d.%*d.%*d.%*d:%*d/ftn_handler?bmd5=%32s",bmd5);
if(res>0)
{
- //MESA_handle_runtime_log(runtime_log,RLOG_LV_DEBUG,"extract","find header,bmd5=%s",bmd5);
qq_pme->next_flag = 0;
// separator_flag is 1 means that the next TCP packet contains a separator
}
@@ -445,7 +449,6 @@ uchar qq_file_send_entry(stSessionInfo* session_info,void **pme,int thread_seq,s
}
if(res == 0)
{
-
MESA_htable_del(file_htable,(u_char *)qq_pme->uuid,UUID_LENGTH,free_fileinfo);
}
}
@@ -460,12 +463,17 @@ uchar qq_file_send_entry(stSessionInfo* session_info,void **pme,int thread_seq,s
res = parse_separator(&content,content_len,online_feature,&qq_pme);
if(res < 0)
{
- // If both matches fail, the rule is wrong or the traffic is wrong
- MESA_handle_runtime_log(runtime_log,RLOG_LV_FATAL,"match","feature fail,check rule");
+ // If both matches fail, the rule sis wrong or the traffic is wrong
+ if (res == -1)
+ MESA_handle_runtime_log(runtime_log,RLOG_LV_FATAL,"match","feature fail,check rule");
+ else
+ MESA_handle_runtime_log(runtime_log,RLOG_LV_FATAL,"match","feature fail,unkown type");
// if the current http stream is transferring a file with a half,and the rule matches fail
// there will be a streamctx still open and no way to close
// but this situation seems won't happen
rec = PROT_STATE_DROPME;
+ free(payload);
+ break;
}
else
MESA_handle_runtime_log(runtime_log,RLOG_LV_DEBUG,"match","online feature success,uuid:%s",qq_pme->uuid);
@@ -483,6 +491,7 @@ uchar qq_file_send_entry(stSessionInfo* session_info,void **pme,int thread_seq,s
if(locally_save == 1)
{
//save file to disk
+ MESA_handle_runtime_log(runtime_log,RLOG_LV_DEBUG,"match","file %d saved as %s",qq_pme->id,qq_pme->filename);
FILE *fp = fopen(qq_pme->filename,"ab");
fwrite(content,content_len,1,fp);
fclose(fp);
@@ -504,7 +513,7 @@ uchar qq_file_send_entry(stSessionInfo* session_info,void **pme,int thread_seq,s
free_pme((qq_pme_info **)pme);
}
}
- return PROT_STATE_GIVEME;
+ return rec;
}
int suggestion_inform_callback(struct suggest_receive_info *info, struct nirvana_message_survey *detail, const char *snap_URL, struct nvn_opt_unit *opts, void *privdata)
@@ -521,7 +530,7 @@ int suggestion_inform_callback(struct suggest_receive_info *info, struct nirvana
void nirvana_client_init()
{
struct nirvana_parameter *parameter;
- parameter = nirvana_client_parameter_new("./plug/business/qq_file_send/qq_file_send.inf", "NIRVANA", runtime_log);
+ parameter = nirvana_client_parameter_new("./plug/business/qq_file_send/qq_file_send.conf", "NIRVANA", runtime_log);
//assert(parameter != NULL);
instance_asyn = nirvana_evbase_instance_new(parameter, runtime_log, suggestion_inform_callback, NULL);
//assert(instance_asyn!=NULL);
@@ -529,26 +538,17 @@ void nirvana_client_init()
void QQ_FILE_SEND_DESTROY()
{
- /*
- free(online_feature.separator_header);
- free(offline_feature.separator_header);
-
- free(online_feature.uuid_suffix);
- free(offline_feature.uuid_suffix);
-
- free(online_feature.end_suffix);
- free(offline_feature.end_suffix);
- */
+ MESA_handle_runtime_log(runtime_log,RLOG_LV_INFO,"destroy","------------exit------------");
}
-void qq_file_send_init()
+int qq_file_send_init()
{
printf("qq_file_send init\n");
int read_res = 0;
runtime_log = MESA_create_runtime_log_handle(LOG_PATH, 20);
- char *inf_file = "./plug/business/qq_file_send/qq_file_send.inf";
+ char *inf_file = "./plug/business/qq_file_send/qq_file_send.conf";
read_res += read_profile_of_separator(inf_file,&online_feature,"ONLINE_FEATURE",ONLINE_SEND);
read_res += read_profile_of_separator(inf_file,&offline_feature,"OFFLINE_FEATURE",OFFLINE_SEND);
@@ -556,18 +556,34 @@ void qq_file_send_init()
MESA_load_profile_int_def(inf_file,"CAPTURE","locally_save",&locally_save,0);
if(locally_save == 1)
{
- if(MESA_load_profile_string_nodef(inf_file,"CAPTURE","save_directory",save_directory,NAME_SIZE)<0)
+ if(MESA_load_profile_string_def(inf_file,"CAPTURE","save_directory",save_directory,NAME_SIZE,"./plug/business/qq_file_send/")<0)
{
read_res += -1;
MESA_handle_runtime_log(runtime_log,RLOG_LV_FATAL,"init","load save directory failed");
}
}
+ else
+ {
+ strcpy(save_directory,"./plug/business/qq_file_send/");
+ }
+ if(access(save_directory,W_OK) != 0 && locally_save == 1)
+ {
+ MESA_handle_runtime_log(runtime_log,RLOG_LV_FATAL,"init","save directory %s not found or cannot write\n",save_directory);
+ return -1;
+ }
+ else
+ {
+ MESA_handle_runtime_log(runtime_log,RLOG_LV_DEBUG,"init","save directory is %s",save_directory);
+ }
+
//free(inf_file);
if(read_res == 0)
MESA_handle_runtime_log(runtime_log,RLOG_LV_INFO,"init","------------load feature success------------");
else
- MESA_handle_runtime_log(runtime_log,RLOG_LV_FATAL,"init","-----------load feature failed:%d---------",read_res);
-
+ {
+ MESA_handle_runtime_log(runtime_log,RLOG_LV_FATAL,"init","------------load feature failed:%d------------",read_res);
+ return -1;
+ }
#ifdef NIRVANA
nirvana_client_init();
#endif
@@ -586,4 +602,5 @@ void qq_file_send_init()
htable_args->expire_time = 60;
file_htable = MESA_htable_create(htable_args,1);
MESA_htable_print_crtl(file_htable,0);
+ return 0;
}
diff --git a/qq_file_send.conf b/qq_file_send.conf
new file mode 100644
index 0000000..b30b4f1
--- /dev/null
+++ b/qq_file_send.conf
@@ -0,0 +1,45 @@
+[CAPTURE]
+locally_save = 0
+save_directory = ./plug/business/qq_file_send/
+
+
+[ONLINE_FEATURE]
+header_len = 10
+separator_header = abcd9876000003ef0000
+uuid_deviation = 83
+uuid_suffix = 0014
+uuid_suffix_len = 2
+content_deviation = 161
+end_suffix_len = 17
+end_suffix = abcd987600000000000000000000000901
+
+
+[OFFLINE_FEATURE]
+separator_header = abcd9876000003ef0000
+header_len = 10
+uuid_deviation = 83
+uuid_suffix = 3f3f
+uuid_suffix_len = 2
+content_deviation = 364
+end_suffix_len = 17
+end_suffix = abcd987600000000000000000000000901
+
+
+[NIRVANA]
+udp_server_listen_port=6231
+dest_addr_port=6230
+dest_addr_ip_list=[192.168.10.90]
+
+#Maximum number of connections opened by per host.
+#max_connection_per_host=1
+#max_used_memory_size_mb=500
+#tcp_upload_block_minsize=10000
+#udp_upload_block_maxsize=3072
+
+fsstat_log_appname=SappNvnClient
+fsstat_log_filepath=./log/nvnqq_file_send.fs
+fsstat_log_interval=10
+#0-disable fsstat, 1-rewrite, 2-append
+fsstat_log_print_mode=1
+fsstat_log_dst_ip=127.0.0.1
+fsstat_log_dst_port=8125
diff --git a/qq_file_send.inf b/qq_file_send.inf
index ad5ee69..842cbb6 100644
--- a/qq_file_send.inf
+++ b/qq_file_send.inf
@@ -6,52 +6,5 @@ DESTROY_FUNC=QQ_FILE_SEND_DESTROY
[HTTP]
-FUNC_FLAG=HTTP_REQ_LINE,HTTP_RES_LINE,HTTP_MESSAGE_URL,HTTP_CONT_TYPE,HTTP_CONTENT
-FUNC_NAME=qq_file_send_entry
-
-
-[CAPTURE]
-locally_save = 0
-save_directory = /home/jiangph
-
-
-[ONLINE_FEATURE]
-separator_header = abcd9876000003ef0000
-header_len = 10
-uuid_deviation = 83
-uuid_suffix = 0014
-uuid_suffix_len = 2
-content_deviation = 161
-end_suffix_len = 17
-end_suffix = abcd987600000000000000000000000901
-
-
-[OFFLINE_FEATURE]
-separator_header = abcd9876000003ef0000
-header_len = 10
-uuid_deviation = 83
-uuid_suffix = 3f3f
-uuid_suffix_len = 2
-content_deviation = 364
-end_suffix_len = 17
-end_suffix = abcd987600000000000000000000000901
-
-
-[NIRVANA]
-udp_server_listen_port=6231
-dest_addr_port=6230
-dest_addr_ip_list=[192.168.10.90]
-
-#Maximum number of connections opened by per host.
-#max_connection_per_host=1
-#max_used_memory_size_mb=500
-#tcp_upload_block_minsize=10000
-#udp_upload_block_maxsize=3072
-
-fsstat_log_appname=SappNvnClient
-fsstat_log_filepath=./log/nvnqq_file_send.fs
-fsstat_log_interval=10
-#0-disable fsstat, 1-rewrite, 2-append
-fsstat_log_print_mode=1
-fsstat_log_dst_ip=127.0.0.1
-fsstat_log_dst_port=8125
+FUNC_FLAG=HTTP_REQ_LINE,HTTP_RES_LINE,HTTP_MESSAGE_URL,HTTP_CONTENT
+FUNC_NAME=qq_file_send_entry \ No newline at end of file