FindData Archive::get_file_info(UInt32 index) { if (file_list.empty()) make_index(); FindData file_info; memzero(file_info); wcscpy(file_info.cFileName, file_list[index].name.c_str()); file_info.dwFileAttributes = get_attr(index); file_info.set_size(get_size(index)); file_info.ftCreationTime = get_ctime(index); file_info.ftLastWriteTime = get_mtime(index); file_info.ftLastAccessTime = get_atime(index); return file_info; }
int headers_to_stat(GList *headers, struct stat *stbuf) { GList *head = NULL, *next = NULL; head = g_list_first(headers); while(head != NULL) { next = head->next; HTTP_HEADER *header = head->data; // TODO: clean this up. if(strcmp(header->key, "x-amz-meta-uid") == 0) stbuf->st_uid = get_uid(header->value); else if(strcmp(header->key, "x-amz-meta-gid") == 0) stbuf->st_gid = get_gid(header->value); else if(strcmp(header->key, "x-amz-meta-ctime") == 0) stbuf->st_ctime = get_ctime(header->value); else if(strcmp(header->key, "x-amz-meta-mtime") == 0) stbuf->st_mtime = get_mtime(header->value); else if(strcmp(header->key, "x-amz-meta-rdev") == 0) stbuf->st_rdev = get_rdev(header->value); else if(strcmp(header->key, "Last-Modified") == 0 && stbuf->st_mtime == 0) stbuf->st_mtime = get_mtime(header->value); else if(strcmp(header->key, "x-amz-meta-mode") == 0) stbuf->st_mode = get_mode(header->value); else if(strcmp(header->key, "Content-Length") == 0) stbuf->st_size = get_size(header->value); else if(strcmp(header->key, "Content-Type") == 0) if(strstr(header->value, "x-directory")) stbuf->st_mode |= S_IFDIR; head = next; } return 0; }
void srch_msg(char *filename) { int fd, len=0, gz_flag = 0, ret; int tot_msg=0, tot_found=0, tot_written=0; char tmp_filename[MAX_FILENAME_LEN+1], command[128], *ptr; st_LogFileHead file_head; st_LogDataHead data_head; st_MsgQ qmsg; st_AAAREQ stAAA; struct stat statbuf; time_t start_time; memset( &qmsg, 0x00, sizeof(st_MsgQ) ); if (stat(filename,&statbuf) < 0) { fprintf(stderr,"ERROR: stat(%s) error(%s)!!!\n",filename,strerror(errno)); return; } if (SRCHINFO.srchtype == SRCHTYPE_TIME) { if (XFLAG == 0 && statbuf.st_mtime < SRCHINFO.starttime) { /* fprintf(stderr,"DEBUG: %s, file end(%d) before start time(%d)\n", filename,statbuf.st_mtime,SRCHINFO.starttime); */ return; } if ((start_time=get_ctime(filename)) > SRCHINFO.endtime) { /* fprintf(stderr,"DEBUG: %s, file start(%d) after end time(%d), 1\n", filename,start_time,SRCHINFO.starttime); */ return; } } len = strlen(filename); if (!strcmp(filename+len-3,".gz")) { strncpy(tmp_filename,filename,len-3); tmp_filename[len-3] = 0; sprintf(command,"gunzip %s.gz",tmp_filename); system(command); gz_flag = 1; } else strcpy(tmp_filename,filename); if ((fd=open(tmp_filename,O_RDONLY)) < 0) { fprintf(stderr,"ERROR: file(%s) open error(%s)!!!\n",tmp_filename,strerror(errno)); if (gz_flag == 1) { sprintf(command,"gzip %s",tmp_filename); system(command); } return; } if ((len=read(fd,(void *)&file_head,sizeof(st_LogFileHead))) <= 0) { fprintf(stderr,"ERROR: file(%s) read error(%s)!!!\n",tmp_filename,strerror(errno)); close(fd); if (gz_flag == 1) { sprintf(command,"gzip %s",tmp_filename); system(command); } return; } if (SRCHINFO.srchtype == SRCHTYPE_TIME && XFLAG == 1 && file_head.tStartTime > SRCHINFO.endtime) { /* fprintf(stderr,"DEBUG: %s, file start(%d) after end time(%d), 2\n", filename,file_head.tStartTime,SRCHINFO.endtime); */ return; } /* if (SRCHINFO.srchtype == SRCHTYPE_TIME && file_head.tStartTime > SRCHINFO.endtime) { //fprintf(stderr,"DEBUG: %s, file start(%d) after end time(%d), 2\n",filename,file_head.tStartTime,SRCHINFO.endtime); return; } */ SRCHINFO.tot_file++; fprintf(stderr," : FILE : %s\n",filename); while(1) { len = read(fd,(void *)&data_head,sizeof(st_LogDataHead)); if (len <= 0) { if (len < 0) fprintf(stderr,"ERROR_1: file(%s) read error(%s)!!!\n", filename,strerror(errno)); close(fd); break; } len = read(fd, (void*)&qmsg, CVT_INT_CP(data_head.uiLogLen)); if (len <= 0 || len != CVT_INT_CP(data_head.uiLogLen)) { if (len < 0) fprintf(stderr,"ERROR_2: file(%s) read error(%s)!!!\n", filename,strerror(errno)); else if (len != CVT_INT_CP(data_head.uiLogLen)) fprintf(stderr,"ERROR: file(%s) read length mismatch!!!\n",filename); close(fd); break; } /* if (CVT_SHORT_CP(data_head.usMType) == DEF_SVC) { len = read(fd, (void*)&qmsg, CVT_INT_CP(data_head.uiLogLen)); if (len <= 0 || len != CVT_INT_CP(data_head.uiLogLen)) { if (len < 0) fprintf(stderr,"ERROR_2: file(%s) read error(%s)!!!\n", filename,strerror(errno)); else if (len != CVT_INT_CP(data_head.uiLogLen)) fprintf(stderr,"ERROR: file(%s) read length mismatch!!!\n",filename); close(fd); break; } } else { fprintf(stderr,"ERROR: datahead's MType(%d) is not DEF_SVC time(%s)!!!\n", CVT_SHORT_CP(data_head.usMType), str_time(CVT_INT(data_head.stTmval.tv_sec))); continue; } */ SRCHINFO.tot_msg++; tot_msg++; if (SRCHINFO.srchtype == SRCHTYPE_TIME) { if ((CVT_INT_CP(data_head.stTmval.tv_sec) < SRCHINFO.starttime) || (CVT_INT_CP(data_head.stTmval.tv_sec) > SRCHINFO.endtime)) continue; } switch (SRCHINFO.numtype) { case NUMTYPE_IMSI: /* if (qmsg.szMIN[0] == 0) fprintf(stderr,"ERROR: MSID not exist in log header\n"); */ if (!strcmp( SRCHINFO.imsi, (char *)qmsg.szMIN) ) { SRCHINFO.tot_found++; tot_found++; if ((ret=write_msg(&data_head,&qmsg)) == 0) { SRCHINFO.tot_written++; tot_written++; } else if (ret == -1) { fprintf(SRCHINFO.err_fp,"FILENAME: %s",filename); //print_hex_log(SRCHINFO.err_fp, qmsg.szBody, qmsg.usBodyLen); } } break; case NUMTYPE_MSISDN: if (qmsg.szExtra[0] == 0) fprintf(stderr,"ERROR: MDN not exist in log header\n"); if (!strcmp(SRCHINFO.msisdn, (char *)qmsg.szExtra)) { SRCHINFO.tot_found++; tot_found++; if ((ret=write_msg(&data_head,&qmsg)) == 0) { SRCHINFO.tot_written++; tot_written++; } else if (ret == -1) { fprintf(SRCHINFO.err_fp,"FILENAME: %s",filename); //print_hex_log(SRCHINFO.err_fp, qmsg.szBody, qmsg.usBodyLen); } } break; default: SRCHINFO.tot_found++; tot_found++; if ((ret=write_msg(&data_head,&qmsg)) == 0) { SRCHINFO.tot_written++; tot_written++; } else if (ret == -1) { fprintf(SRCHINFO.err_fp,"FILENAME: %s",filename); //print_hex_log(SRCHINFO.err_fp, qmsg.szBody, qmsg.usBodyLen); } break; } } close(fd); if (gz_flag == 1) { sprintf(command,"gzip %s",tmp_filename); system(command); } if ((ptr=strrchr(filename,'/')) == NULL) ptr = filename; else ptr += 1; fprintf(stderr," : %-15s : MESSAGE=%d FOUND=%d WRITTEN=%d\n", ptr,tot_msg,tot_found,tot_written); return; }
void rx_goodput(int src, int dst, int application){ if (otg_info->rx_num_bytes[src][dst][application]>0) otg_info->rx_goodput[src][dst][application]=((double)otg_info->rx_num_bytes[src][dst][application]*1000*8)/(get_ctime()*1024); // unit kB/sec, if ctime in ms if (otg_info->rx_num_bytes_background[src][dst]>0) otg_info->rx_goodput_background[src][dst]=((double)otg_info->rx_num_bytes_background[src][dst] *1000*8)/(get_ctime()*1024); // unit kB/sec, if ctime in ms if (otg_multicast_info->rx_num_bytes[src][dst][application]>0){ otg_multicast_info->rx_goodput[src][dst]=((double)otg_multicast_info->rx_num_bytes[src][dst][application] *1000*8)/(get_ctime()*1024); // unit kB/sec, if ctime in ms LOG_I(OTG,"otg_multicast_info->rx_num_bytes[i=%d,j=%d,k=%d] = %.d\n", src,dst,application,otg_multicast_info->rx_num_bytes[src][dst][application]); } }
void tx_throughput(int src, int dst, int application){ if (otg_info->tx_num_bytes[src][dst][application]>0) otg_info->tx_throughput[src][dst][application]=((double)otg_info->tx_num_bytes[src][dst][application] *1000*8)/ (get_ctime()*1024); // unit Kbit/sec, if ctime in ms if (otg_info->tx_num_bytes_background[src][dst]>0) otg_info->tx_throughput_background[src][dst]=((double)otg_info->tx_num_bytes_background[src][dst]*1000*8)/ (get_ctime()*1024); // unit Kbit/sec, if ctime in ms if (otg_multicast_info->tx_num_bytes[src][dst][application]>0){ if (application < 2) otg_multicast_info->tx_throughput[src][dst]=((double)otg_multicast_info->tx_num_bytes[src][dst][application]*1000*8)/ (get_ctime()*1024); // unit Kbit/sec, if ctime in ms //otg_multicast_info->tx_num_bytes[src][dst][app] is 3 dimension param in otg_tx.c, only use [app]=0 // LOG_I(OTG,"DUY, get_ctime() [i=%d,j=%d,k=%d] = %.d\n", src,dst,application,get_ctime()); LOG_I(OTG,"otg_multicast_info->tx_num_bytes[i=%d,j=%d,k=%d] = %.d\n", src,dst,application,otg_multicast_info->tx_num_bytes[src][dst][application]); } }
int srch_msg(char *filename, SRCH_INFO *pSRCHINFO, char *szResBuf) { int fd, len, ret; int tot_msg=0, tot_found=0, tot_written=0; char tmp_filename[MAX_FILENAME_LEN+1], command[128], *ptr; char statBuf[256]; st_MsgQ qmsg; st_AAAREQ stAAA; st_DumpInfo stUdrDumpInfo; int iRet = 0; CHAR tmpStart[256]; char tmpStop[256]; struct stat statbuf; time_t start_time; int dOffset = 0; memset( &qmsg, 0x00, sizeof(st_MsgQ) ); memset(&stUdrDumpInfo, 0x00, sizeof(st_DumpInfo)); PASS_EXCEPTION(stat(filename,&statbuf) < 0, STAT_ERROR); if (pSRCHINFO->srchtype == SRCHTYPE_TIME) { PASS_EXCEPTION(statbuf.st_mtime < pSRCHINFO->starttime, FILE_END_ERR); PASS_EXCEPTION((start_time = get_ctime(filename)) > pSRCHINFO->endtime, FILE_START_ERR); } len = strlen(filename); strcpy(tmp_filename,filename); PASS_EXCEPTION((fd=open(tmp_filename,O_RDONLY)) < 0, FILE_OPEN_ERR); PASS_EXCEPTION((len=read(fd,(void *)&stUdrDumpInfo,sizeof(st_DumpInfo))) <= 0, FILE_READ_ERR); // PASS_EXCEPTION(pSRCHINFO->srchtype == SRCHTYPE_TIME && // stUdrDumpInfo.udr_crt_time > pSRCHINFO->endtime, START_AFTER_END_ERR); while(1) { len = read(fd, (void *)&stAAA, sizeof(st_AAAREQ)); //fprintf(stderr, "ReadLen[%d], st_AAAREQSize[%d]\n", len, sizeof(st_AAAREQ)); if( len <= 0 ) { if( len < 0 ) { fprintf(stderr,"ERROR: file(%s) read error(%s)!!!\n", filename,strerror(errno)); } close(fd); break; } ConvertAllMsg(&stAAA); pSRCHINFO->tot_msg++; tot_msg++; if( pSRCHINFO->srchtype == SRCHTYPE_TIME ) { if( (stAAA.stInfo.uiTimeStamp < pSRCHINFO->starttime ) || (stAAA.stInfo.uiTimeStamp > pSRCHINFO->endtime )) { continue; } } if( pSRCHINFO->ucUdrSeqF == 1 ) { if( stAAA.stInfo.uiUDRSeq != pSRCHINFO->uiUdrSeq ) { continue; } } switch (pSRCHINFO->numtype) { case NUMTYPE_IMSI: if (stAAA.stInfo.szMIN[0] == 0) { fprintf(stdout,"ERROR: MSID not exist in log header\n"); break; } if (!strcmp( pSRCHINFO->imsi, (char *)stAAA.stInfo.szMIN) ) { pSRCHINFO->tot_found++; tot_found++; if ((ret=write_msg(&stAAA, pSRCHINFO)) == 0) { pSRCHINFO->tot_written++; tot_written++; } else if (ret == -1) { fprintf(pSRCHINFO->err_fp,"FILENAME: %s",filename); //print_hex_log(pSRCHINFO->err_fp, qmsg.szBody, qmsg.usBodyLen); } } break; case NUMTYPE_UDRSEQ: if (stAAA.stInfo.ucUDRSeqF == 0) fprintf(stdout,"ERROR: UDRSequence not exist in log header\n"); if ( pSRCHINFO->uiUdrSeq == stAAA.stInfo.uiUDRSeq) { pSRCHINFO->tot_found++; tot_found++; if ((ret=write_msg(&stAAA, pSRCHINFO)) == 0) { pSRCHINFO->tot_written++; tot_written++; } else if (ret == -1) { fprintf(pSRCHINFO->err_fp,"FILENAME: %s",filename); //print_hex_log(pSRCHINFO->err_fp, qmsg.szBody, qmsg.usBodyLen); } } break; default: pSRCHINFO->tot_found++; tot_found++; if ((ret=write_msg(&stAAA, pSRCHINFO)) == 0) { pSRCHINFO->tot_written++; tot_written++; } else if (ret == -1) { fprintf(pSRCHINFO->err_fp,"FILENAME: %s",filename); //print_hex_log(pSRCHINFO->err_fp, qmsg.szBody, qmsg.usBodyLen); } break; } } close(fd); if ((ptr=strrchr(filename,'/')) == NULL) { ptr = filename; } else { ptr += 1; } // dOffset = strlen(szResBuf); // sprintf(&szResBuf[dOffset]," %-15s : MESSAGE=%d FOUND=%d WRITTEN=%d\n", // ptr,tot_msg,tot_found,tot_written); sprintf(statBuf," %-15s : MESSAGE=%d FOUND=%d WRITTEN=%d\n", ptr,tot_msg,tot_found,tot_written); fputs(statBuf, pSRCHINFO->err_fp); fflush(pSRCHINFO->err_fp); PASS_CATCH(STAT_ERROR) fprintf(stderr,"ERROR: stat(%s) error(%s)!!!\n",filename,strerror(errno)); iRet = -1; PASS_CATCH(FILE_END_ERR) iRet = -1; PASS_CATCH(FILE_START_ERR) strftime( tmpStart, 256, "%Y-%m-%d %T %a", localtime(&start_time)); strftime( tmpStop, 256, "%Y-%m-%d %T %a", localtime(&pSRCHINFO->endtime)); iRet = -1; PASS_CATCH(FILE_OPEN_ERR) fprintf(stderr,"ERROR: file(%s) open error(%s)!!!\n",tmp_filename,strerror(errno)); iRet = -1; PASS_CATCH(FILE_READ_ERR) fprintf(stderr,"ERROR: file(%s) read error(%s)!!!\n",tmp_filename,strerror(errno)); close(fd); iRet = -1; PASS_CATCH(START_AFTER_END_ERR); iRet = -1; PASS_CATCH_END; return iRet; }