diff options
| author | 姜鹏辉 <[email protected]> | 2020-11-12 10:07:46 +0800 |
|---|---|---|
| committer | 姜鹏辉 <[email protected]> | 2020-11-12 10:07:46 +0800 |
| commit | f1ddeb28e4cb26b3f480f2383092ddda765c3f90 (patch) | |
| tree | 315dc4263df567938d1767281f4b686999fc40ec | |
| parent | 2599d55acf0637ea2184b68c845dcac880e4b957 (diff) | |
change to http,not finish
| -rw-r--r-- | qq_file_send.c | 286 | ||||
| -rw-r--r-- | qq_file_send.inf | 40 |
2 files changed, 198 insertions, 128 deletions
diff --git a/qq_file_send.c b/qq_file_send.c index e0ee87e..3acef56 100644 --- a/qq_file_send.c +++ b/qq_file_send.c @@ -7,24 +7,31 @@ #include <MESA/MESA_htable.h> #include <MESA/stream.h> #include <nirvana_client.h> +#include "http.h" #define LOG_PATH "./log/qq_file/" #define ONLINE_PUBLIC_SEND 0 #define OFFLINE_SEND 1 #define NAME_SIZE 80 -#define NIRVANA +//#define NIRVANA //#define ONLINE_LOCAL_SEND_SMALL 2 //#define ONLINE_LOCAL_SEND_BIG 3 +int QQ_FILE_SEND_VERSION_1_20201109 = 0; +void qq_file_send_version_1_20201109() +{ + //20201109 http +} + typedef struct { - int separator_flag; int send_type; // OFFLINE_SEND char uuid[36]; int content_len; char filename[NAME_SIZE]; - UCHAR dir; struct nirvana_streaming_asyctx *ctx; + int next_flag; + uchar curdir; }qq_pme_info,*qq_pme_info_p; typedef struct @@ -36,6 +43,8 @@ typedef struct char *uuid_suffix; int uuid_suffix_len; int content_deviation; + char *end_suffix; + int end_suffix_len; }struct_separator_feature; @@ -49,7 +58,7 @@ int file_cnt = 0; struct_separator_feature online_feature,offline_feature; MESA_htable_handle file_htable; -char post_header[NAME_SIZE],save_directory[NAME_SIZE]; +char save_directory[NAME_SIZE]; int locally_save; // save file to local machine void *runtime_log; struct event_base *ev_base; @@ -186,12 +195,12 @@ void str_to_ascii(char *in_str,int str_len,char* out_str) * @param: [IN] feature type eg.ONLINE_PUBLIC_SEND/OFFLINE_SEND * @return: 0 : success - -1: fail + >0: fail */ int read_profile_of_separator(const char *inf_file,struct_separator_feature *p_separator_feature,char *section,int feature_type) { - char *separator_header_array,*uuid_suffix_array; + char *separator_header_array,*uuid_suffix_array,*end_suffix_array; int read_res = 0; p_separator_feature->feature_type = feature_type; @@ -202,8 +211,13 @@ int read_profile_of_separator(const char *inf_file,struct_separator_feature *p_s //header p_separator_feature->separator_header = (char *)malloc(p_separator_feature->header_len); separator_header_array = (char *)malloc(p_separator_feature->uuid_suffix_len<<2); - read_res += MESA_load_profile_string_nodef(inf_file,section,"separator_header",separator_header_array,p_separator_feature->header_len<<2); + if(MESA_load_profile_string_nodef(inf_file,section,"separator_header",separator_header_array,p_separator_feature->header_len<<2)<0) + { + read_res += -1; + MESA_handle_runtime_log(runtime_log,RLOG_LV_FATAL,"init","[%s] separator_header error",section); + } str_to_ascii(separator_header_array,p_separator_feature->header_len,p_separator_feature->separator_header); + free(separator_header_array); //uuid_deviation read_res += MESA_load_profile_int_nodef(inf_file,section,"uuid_deviation",&(p_separator_feature->uuid_deviation)); @@ -214,15 +228,31 @@ int read_profile_of_separator(const char *inf_file,struct_separator_feature *p_s //uuid_suffix p_separator_feature->uuid_suffix = (char *)malloc(p_separator_feature->uuid_suffix_len); uuid_suffix_array = (char *)malloc(p_separator_feature->uuid_suffix_len<<2); - read_res += MESA_load_profile_string_nodef(inf_file,section,"uuid_suffix",uuid_suffix_array,p_separator_feature->uuid_suffix_len<<2); + if(MESA_load_profile_string_nodef(inf_file,section,"uuid_suffix",uuid_suffix_array,p_separator_feature->uuid_suffix_len<<2)<0) + { + read_res += -1; + MESA_handle_runtime_log(runtime_log,RLOG_LV_FATAL,"init","[%s] uuid_suffix error",section); + } str_to_ascii(uuid_suffix_array,p_separator_feature->uuid_suffix_len,p_separator_feature->uuid_suffix); + free(uuid_suffix_array); //content_deviation read_res += MESA_load_profile_int_nodef(inf_file,section,"content_deviation",&(p_separator_feature->content_deviation)); - if (!read_res) - return -1; - return 0; + //end_suffix_len + read_res += MESA_load_profile_int_nodef(inf_file,section,"end_suffix_len",&(p_separator_feature->end_suffix_len)); + + //end_suffix + p_separator_feature->end_suffix = (char *)malloc(p_separator_feature->end_suffix_len); + end_suffix_array = (char *)malloc(p_separator_feature->end_suffix_len<<2); + if(MESA_load_profile_string_nodef(inf_file,section,"end_suffix",end_suffix_array,p_separator_feature->end_suffix_len<<2)<0) + { + read_res += -1; + MESA_handle_runtime_log(runtime_log,RLOG_LV_FATAL,"init","[%s] end_suffix error",section); + } + str_to_ascii(end_suffix_array,p_separator_feature->end_suffix_len,p_separator_feature->end_suffix); + free(end_suffix_array); + return read_res; } @@ -230,9 +260,11 @@ int read_profile_of_separator(const char *inf_file,struct_separator_feature *p_s * @Description: different files have different uuids. modify the filename in pme according to the current uuid * @param: pme - * @return: None + * @return: + 0: not exist + 1: exist */ -void match_uuid(qq_pme_info **pme) +int match_uuid(qq_pme_info **pme) { qq_pme_info_p qq_pme = *pme; file_info* thisfile = (file_info *) MESA_htable_search(file_htable,(u_char *)qq_pme->uuid,strlen(qq_pme->uuid)); @@ -247,6 +279,7 @@ void match_uuid(qq_pme_info **pme) newfile->ctx = qq_pme->ctx; #endif MESA_htable_add(file_htable,(u_char *) qq_pme->uuid,strlen(qq_pme->uuid),(void *)newfile); + return 0; } else { @@ -256,6 +289,7 @@ void match_uuid(qq_pme_info **pme) #ifdef NIRVANA qq_pme->ctx = thisfile->ctx; #endif + return 1; } } @@ -273,10 +307,10 @@ void free_fileinfo(void *thisfile) free(p); } + + /* - * @Description: - * @param: - * @return: + * @Description: free memory of pme */ void free_pme(qq_pme_info **pme) { @@ -285,68 +319,78 @@ void free_pme(qq_pme_info **pme) free(qq_pme); } -char qq_file_send_entry(struct streaminfo *a_tcp,void **pme,int thread_seq,void *a_packet) + +uchar qq_file_send_entry(stSessionInfo* session_info,void **pme,int thread_seq,struct streaminfo *a_tcp,void *a_packet) { - int payload_len; - //char *post_header = "POST /ftn_handler?bmd5="; + int res,url_decoded_len; + char bmd5[33]; + char *url_decoded = NULL; + struct tcpdetail* tcp_detail = a_tcp->ptcpdetail; - payload_len = tcp_detail->datalen; - char *payload =(char *)tcp_detail->pdata; + //int payload_len = tcp_detail->datalen; + //char *payload =(char *)tcp_detail->pdata; + if (*pme == NULL) + { + *pme =(qq_pme_info_p)malloc(sizeof(qq_pme_info)); + } qq_pme_info_p qq_pme = (qq_pme_info_p) *pme; - switch(a_tcp->opstate) + http_infor* a_http = (http_infor *)(session_info->app_info); + + switch(session_info->prot_flag) { - case OP_STATE_PENDING: - - if(!strncmp(post_header,payload,strlen(post_header))) + case HTTP_REQ_LINE: + if(a_http->method!=HTTP_METHOD_POST) { - if (*pme == NULL) - { - *pme =(qq_pme_info_p)malloc(sizeof(qq_pme_info)); - qq_pme = *pme; - } + return PROT_STATE_DROPME; + } + qq_pme->curdir = a_http->curdir; + break; + case HTTP_RES_LINE: + break; + case HTTP_MESSAGE_URL: + url_decoded_len = session_info->buflen; + url_decoded = (char*)malloc(url_decoded_len*sizeof(char)); + memcpy(url_decoded, session_info->buf, session_info->buflen); + //printf("%s\n",url_decoded); + res = sscanf(url_decoded,"%*d.%*d.%*d.%*d:%*d/ftn_handler?bmd5=%32s",bmd5); + if(res>0) + { + //printf("bmd5=%s\n",bmd5); + MESA_handle_runtime_log(runtime_log,RLOG_LV_INFO,"extract","find header,bmd5=%s",bmd5); + //1aa23fc86a9ea7dbea7c987dcb4bea1f 32Byte - UINT32 createtime = tcp_detail->createtime; - char filename[100]; - printf("ip:%u\n",a_tcp->addr.ipv4->saddr); - //printf("ip:%s\n",ip_str); + //printf("ip:%u\n",a_tcp->addr.ipv4->saddr); + //printf("ip:%s\n",ip_str); - // the filename is determined by createtime and md5 - sprintf(filename,"%s/qqfile_%d_%u",save_directory,file_cnt,createtime); - file_cnt ++; - strncpy(qq_pme->filename,filename,strlen(filename)); + qq_pme->next_flag = 0; // separator_flag is 1 means that the next TCP packet contains a separator - qq_pme->separator_flag = 1; - qq_pme->dir = a_tcp->curdir; - printf("start\n"); #ifdef NIRVANA // nirvana section struct nirvana_streaming_asyctx *ctx; union nirvana_progid progid; struct streaming_meta streammeta; struct nvn_opt_unit opt[1]; - int opt_num = 1; - - opt[0].opt_type = NVN_OPT_TYPE_KEY_SINGLE; - opt[0].opt_len = strlen(filename)+1; - opt[0].opt_value = filename; + int opt_num = 0; - streammeta.msg_type = NVN_MSG_TYPE_AV_FRAGMENT; - streammeta.msg_subtype = 0; - streammeta.cont_code = 0; + streammeta.msg_type = NVN_MSG_TYPE_DOC_IM; + streammeta.msg_subtype = NVN_MSG_SUBTYPE_IM_QQ_ONLINE; + //NVN_MSG_SUBTYPE_IM_QQ_OFFLINE streammeta.protocol = NVN_PROTOCOL_HTTP; + + streammeta.cont_code = 0; streammeta.live_streaming = 0; streammeta.cap_IP = 0; streammeta.dir = DIR_C2S; - streammeta.request_single_flow = 1; + streammeta.request_single_flow = 0; calculate_md5_for_progid(filename, strlen(filename), &progid); streammeta.balance_seed = caculate_seed_using_sdbm_hash((char*)&progid, sizeof(progid)); ctx = nirvana_streaming_asyn_update_start(instance_asyn, &progid, &streammeta); if(ctx == NULL) { - return APP_STATE_DROPME; + return PROT_STATE_DROPME; } nirvana_streaming_asyn_update_meta(ctx, opt, opt_num); qq_pme->ctx = ctx; @@ -354,81 +398,87 @@ char qq_file_send_entry(struct streaminfo *a_tcp,void **pme,int thread_seq,void } else { - return APP_STATE_DROPME; + return PROT_STATE_DROPME; } + //printf("%s %s\n",post_content,bmd5); break; - case OP_STATE_DATA: - //printf("dir %d %d %d %d\n",a_tcp->curdir,qq_pme->dir,DIR_C2S,DIR_S2C); - if(a_tcp->curdir != qq_pme->dir) - { - return APP_STATE_GIVEME; - } - if(!strncmp(post_header,payload,strlen(post_header))) + case HTTP_CONTENT: + { + if (qq_pme->curdir != a_http->curdir) { - qq_pme->separator_flag = 1; - return APP_STATE_GIVEME; + // to do ... + break; } - // The next payload contains the separator, which needs to be processed - if(qq_pme->separator_flag == 1) + else { - char **ppayload = &payload; - int parse_res; - parse_res = parse_separator(ppayload,payload_len,offline_feature,&qq_pme); - if(parse_res < 0) + int content_len = session_info->buflen; + char *content = (char *)malloc(content_len); + memcpy(content,session_info->buf,content_len); + if(qq_pme->next_flag == 0) { - // If offline matching fails, the online rule will be matched again - parse_res = parse_separator(ppayload,payload_len,online_feature,&qq_pme); - if(parse_res < 0) + res = parse_separator(&content,content_len,offline_feature,&qq_pme); + if(res < 0) { - // If both matches fail, the rule is wrong or the traffic is wrong -#ifdef NIRVANA - nirvana_streaming_asyn_update_end(qq_pme->ctx); - nirvana_streaming_asyn_update_cancel(qq_pme->ctx); + // If offline matching fails, the online rule will be matched again + 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,"extract","match feature fail,check rule!"); + +#ifdef NIRVANA + nirvana_streaming_asyn_update_end(qq_pme->ctx); + nirvana_streaming_asyn_update_cancel(qq_pme->ctx); #endif - return APP_STATE_DROPME; + return PROT_STATE_DROPME; + } + else + MESA_handle_runtime_log(runtime_log,RLOG_LV_INFO,"extract","match online feature,uuid:%s",qq_pme->uuid); } - } - qq_pme->separator_flag = 0; - match_uuid(&qq_pme); + else + { + MESA_handle_runtime_log(runtime_log,RLOG_LV_INFO,"extract","match offline feature,uuid:%s",qq_pme->uuid); + } + qq_pme->next_flag = 1; + printf("before:%s\n",qq_pme->filename); + if(!match_uuid(&qq_pme)) + { + // a new file catched + UINT32 createtime = tcp_detail->createtime; + // the filename is determined by createtime and md5 + sprintf(qq_pme->filename,"%s/qqfile_%d_%u",save_directory,file_cnt,createtime); + file_cnt++; + + } + printf("after :%s\n--------\n",qq_pme->filename); - printf("%d separa:%s %s\n",thread_seq,qq_pme->filename,qq_pme->uuid); - if(locally_save == 1) - { - FILE *fp = fopen(qq_pme->filename,"ab"); - fwrite(payload,qq_pme->content_len,1,fp); - fclose(fp); } -#ifdef NIRVANA - nirvana_streaming_asyn_update_data(qq_pme->ctx,payload ,qq_pme->content_len); -#endif - } - else - { - //printf("%d file:%s %s\n",thread_seq,qq_pme->filename,qq_pme->uuid); if(locally_save == 1) { + printf("write :%s\n--------\n",qq_pme->filename); FILE *fp = fopen(qq_pme->filename,"ab"); - fwrite(payload,payload_len,1,fp); + fwrite(content,content_len,1,fp); fclose(fp); } #ifdef NIRVANA - nirvana_streaming_asyn_update_data(qq_pme->ctx,payload ,qq_pme->content_len); -#endif + nirvana_streaming_asyn_update_data(qq_pme->ctx,payload ,qq_pme->content_len); +#endif + break; } - - break; + } case OP_STATE_CLOSE: #ifdef NIRVANA nirvana_streaming_asyn_update_end(qq_pme->ctx); nirvana_streaming_asyn_update_cancel(qq_pme->ctx); #endif - MESA_htable_del(file_htable,(u_char *)qq_pme->uuid,strlen(qq_pme->uuid),free_fileinfo); break; + } - return APP_STATE_GIVEME; + return PROT_STATE_GIVEME; } + 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) { char fromip_str[64]; @@ -451,16 +501,31 @@ void nirvana_client_init() void qq_file_send_init() { - printf("qq_file_end init\n"); + printf("qq_file_send init\n"); + int read_res = 0; + runtime_log = MESA_create_runtime_log_handle("./runtime.log", 20); + const char *inf_file = "./plug/protocol/qq_file_send/qq_file_send.inf"; - read_profile_of_separator(inf_file,&online_feature,"ONLINE_FEATURE",ONLINE_PUBLIC_SEND); - read_profile_of_separator(inf_file,&offline_feature,"OFFLINE_FEATURE",OFFLINE_SEND); + read_res += read_profile_of_separator(inf_file,&online_feature,"ONLINE_FEATURE",ONLINE_PUBLIC_SEND); + read_res += read_profile_of_separator(inf_file,&offline_feature,"OFFLINE_FEATURE",OFFLINE_SEND); - MESA_load_profile_string_nodef(inf_file,"CAPTURE","post_header",post_header,NAME_SIZE); - MESA_load_profile_string_nodef(inf_file,"CAPTURE","save_directory",save_directory,NAME_SIZE); + //read_res += MESA_load_profile_string_nodef(inf_file,"CAPTURE","post_header",post_header,NAME_SIZE); 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) + { + read_res += -1; + MESA_handle_runtime_log(runtime_log,RLOG_LV_FATAL,"init","load save directory failed"); + } + } + + 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); + - runtime_log = MESA_create_runtime_log_handle("./runtime.log", 10); #ifdef NIRVANA nirvana_client_init(); #endif @@ -471,16 +536,5 @@ void qq_file_send_init() MESA_htable_set_opt(file_htable,MHO_THREAD_SAFE,psafe,sizeof(int)); MESA_htable_mature(file_htable); MESA_htable_print_crtl(file_htable,0); -} -void GET_PLUGID(unsigned short plugid) -{ - ; -} -long long FLAG_CHANGE(char *flag_str) -{ - return 1; -} -void PROT_FUNSTAT(long long protflag) -{ - ; + }
\ No newline at end of file diff --git a/qq_file_send.inf b/qq_file_send.inf index 292d155..f7ab4ff 100644 --- a/qq_file_send.inf +++ b/qq_file_send.inf @@ -1,32 +1,30 @@ [PLUGINFO] PLUGNAME=QQ_FILE_SEND -SO_PATH=./plug/protocol/qq_file_send/qq_file_send.so +SO_PATH=./plug/business/qq_file_send/qq_file_send.so INIT_FUNC=qq_file_send_init DESTROY_FUNC=QQ_FILE_SEND_DESTROY -GETPLUGID_FUNC=GET_PLUGID -FLAGCHANGE_FUNC=FLAG_CHANGE -FLAGSTATE_FUNC=PROT_FUNSTAT -[TCP] -FUNC_FLAG=ALL +[HTTP] + +FUNC_FLAG=HTTP_REQ_LINE,HTTP_RES_LINE,HTTP_MESSAGE_URL,HTTP_CONT_TYPE,HTTP_CONTENT FUNC_NAME=qq_file_send_entry [CAPTURE] -post_header = POST /ftn_handler?bmd5= +post_header = /ftn_handler?bmd5= locally_save = 1 save_directory = /home/jiangph [ONLINE_FEATURE] separator_header = abcd9876000003ef0000 -#separator_header = [171,205,152,118,0,0,3,239,0,0] header_len = 10 uuid_deviation = 83 uuid_suffix = 0014 -#uuid_suffix = [0,20] uuid_suffix_len = 2 -content_deviation = 161 +content_deviation = 161 +end_suffix_len = 17 +end_suffix = abcd987600000000000000000000000901 [OFFLINE_FEATURE] @@ -38,7 +36,25 @@ uuid_suffix = 3f3f #uuid_suffix = [63,63] uuid_suffix_len = 2 content_deviation = 364 +end_suffix_len = 17 +end_suffix = abcd987600000000000000000000000901 + [NIRVANA] -dest_addr_ip_list=[tcp:192.168.10.90] -dest_addr_port=6230
\ No newline at end of file +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 |
