diff options
| author | 姜鹏辉 <[email protected]> | 2020-11-24 13:12:52 +0800 |
|---|---|---|
| committer | 姜鹏辉 <[email protected]> | 2020-11-24 13:12:52 +0800 |
| commit | c35dbd13686b93b1802535a152e88efccdc169dd (patch) | |
| tree | 5cf8b356d2d7b03f884740d0f86d2285ebfcad3d | |
| parent | 6972454742c518e503113e2974822fd49412d8f8 (diff) | |
some nirvana
| -rw-r--r-- | qq_file_send.c | 82 |
1 files changed, 35 insertions, 47 deletions
diff --git a/qq_file_send.c b/qq_file_send.c index c72e9b8..031c9ac 100644 --- a/qq_file_send.c +++ b/qq_file_send.c @@ -12,52 +12,52 @@ #define ONLINE_SEND 0 #define OFFLINE_SEND 1 -#define NAME_SIZE 80 +#define NAME_SIZE 128 #define MAX_HTABLE_NUM 24 #define NIRVANA - -int QQ_FILE_SEND_VERSION_1_20201109 = 0; -void qq_file_send_version_1_20201109() +int QQ_FILE_SEND_VERSION_1_20201124 = 0; +void qq_file_send_version_1_20201124() { - //20201109 http + //20201124 } + typedef struct { - int send_type; // OFFLINE_SEND + uint8_t send_type; // OFFLINE_SEND char uuid[36]; - int content_len; + uint16_t content_len; char filename[NAME_SIZE]; struct nirvana_streaming_asyctx *ctx; - uint next_flag; - int len; + uint8_t next_flag; + uint64_t file_len; uchar curdir; }qq_pme_info,*qq_pme_info_p; typedef struct { - int feature_type; + uint8_t feature_type; char *separator_header; - int header_len; - int uuid_deviation; + uint header_len; + uint uuid_deviation; char *uuid_suffix; - int uuid_suffix_len; - int content_deviation; + uint uuid_suffix_len; + uint content_deviation; char *end_suffix; - int end_suffix_len; + uint end_suffix_len; }struct_separator_feature; typedef struct { char filename[NAME_SIZE]; - int len; + uint64_t file_len; struct nirvana_streaming_asyctx *ctx; }file_info; -int file_cnt = 0; +uint file_cnt = 0; struct_separator_feature online_feature,offline_feature; MESA_htable_handle file_htable; @@ -268,7 +268,7 @@ void free_fileinfo(void *thisfile) 0: not exist 1: exist */ -int match_uuid(qq_pme_info **pme,int content_len,int send_type) +int match_uuid(qq_pme_info **pme,int content_len) { 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)); @@ -280,7 +280,7 @@ int match_uuid(qq_pme_info **pme,int content_len,int send_type) sprintf(qq_pme->filename,"%s/%d-%s",save_directory,file_cnt,qq_pme->uuid); file_cnt++; strncpy(newfile->filename,qq_pme->filename,strlen(qq_pme->filename)); - newfile->len = content_len; + newfile->file_len = content_len; #ifdef NIRVANA // nirvana section struct nirvana_streaming_asyctx *ctx; @@ -288,9 +288,9 @@ int match_uuid(qq_pme_info **pme,int content_len,int send_type) struct streaming_meta streammeta; struct nvn_opt_unit opt[1]; int opt_num = 0; - + memset(&streammeta,0,sizeof(streammeta)); streammeta.msg_type = NVN_MSG_TYPE_DOC_IM; - if(send_type == ONLINE_SEND) + if(qq_pme->send_type == ONLINE_SEND) streammeta.msg_subtype = NVN_MSG_SUBTYPE_IM_QQ_ONLINE; else streammeta.msg_subtype = NVN_MSG_SUBTYPE_IM_QQ_OFFLINE; @@ -325,9 +325,9 @@ int match_uuid(qq_pme_info **pme,int content_len,int send_type) { // there is a file point in htable // so change the pme - thisfile->len += content_len; + thisfile->file_len += content_len; strncpy(qq_pme->filename,thisfile->filename,strlen(thisfile->filename)); - qq_pme->len = thisfile->len; + qq_pme->file_len = thisfile->file_len; #ifdef NIRVANA qq_pme->ctx = thisfile->ctx; #endif @@ -379,27 +379,17 @@ uchar qq_file_send_entry(stSessionInfo* session_info,void **pme,int thread_seq,s 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_DEBUG,"extract","find header,bmd5=%s",bmd5); - - //1aa23fc86a9ea7dbea7c987dcb4bea1f 32Byte - - //printf("ip:%u\n",a_tcp->addr.ipv4->saddr); - //printf("ip:%s\n",ip_str); - qq_pme->next_flag = 0; // separator_flag is 1 means that the next TCP packet contains a separator - } else { return PROT_STATE_DROPME; } - //printf("%s %s\n",post_content,bmd5); break; case HTTP_CONTENT: { @@ -425,7 +415,7 @@ uchar qq_file_send_entry(stSessionInfo* session_info,void **pme,int thread_seq,s nirvana_streaming_asyn_update_end(qq_pme->ctx); nirvana_streaming_asyn_update_cancel(qq_pme->ctx); #endif - MESA_handle_runtime_log(runtime_log,RLOG_LV_INFO,"finish","save file uuid=%s,size:%d",qq_pme->uuid,qq_pme->len); + MESA_handle_runtime_log(runtime_log,RLOG_LV_INFO,"finish","save file uuid=%s,size:%d",qq_pme->uuid,qq_pme->file_len); MESA_handle_runtime_log(runtime_log,RLOG_LV_INFO,"finish","total get %d file",file_cnt); MESA_htable_del(file_htable,(u_char *)qq_pme->uuid,strlen(qq_pme->uuid),free_fileinfo); } @@ -459,27 +449,23 @@ uchar qq_file_send_entry(stSessionInfo* session_info,void **pme,int thread_seq,s } qq_pme->next_flag = 1; content_len = qq_pme->content_len; - match_uuid(&qq_pme,content_len,qq_pme->send_type); - } - else - { - ;//may be do nothing + match_uuid(&qq_pme,content_len); } if(locally_save == 1) { + //save file to disk FILE *fp = fopen(qq_pme->filename,"ab"); fwrite(content,content_len,1,fp); fclose(fp); } #ifdef NIRVANA - nirvana_streaming_asyn_update_data(qq_pme->ctx,content ,content_len); + nirvana_streaming_asyn_update_data(qq_pme->ctx, content, content_len); #endif } break; } } - return PROT_STATE_GIVEME; } @@ -497,10 +483,10 @@ int suggestion_inform_callback(struct suggest_receive_info *info, struct nirvana void nirvana_client_init() { struct nirvana_parameter *parameter; - ev_base = event_base_new(); - parameter = nirvana_client_parameter_new("./plug/protocol/qq_file_send/qq_file_send.inf", "NIRVANA", runtime_log); - instance_asyn = nirvana_client_instance_new(parameter, ev_base, runtime_log, suggestion_inform_callback, NULL); - event_base_dispatch(ev_base); + parameter = nirvana_client_parameter_new("./plug/business/qq_file_send/qq_file_send.inf", "NIRVANA", runtime_log); + //assert(parameter != NULL); + instance_asyn = nirvana_evbase_instance_new(parameter, runtime_log, suggestion_inform_callback, NULL); + //assert(instance_asyn!=NULL); } void qq_file_send_init() @@ -528,11 +514,12 @@ void qq_file_send_init() 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); #ifdef NIRVANA nirvana_client_init(); #endif + // init a hashtable,key is uuid,value is pme file_htable = MESA_htable_born(); int *psafe = (int *)malloc(sizeof(int)); @@ -540,9 +527,10 @@ void qq_file_send_init() *psafe = 1; *pexpire_time = 60; MESA_htable_set_opt(file_htable,MHO_THREAD_SAFE,psafe,sizeof(int)); + // htable will expire in 60 second MESA_htable_set_opt(file_htable,MHO_EXPIRE_TIME,pexpire_time,sizeof(int)); MESA_htable_mature(file_htable); MESA_htable_print_crtl(file_htable,0); -}
\ No newline at end of file +} |
