| | |
| | | |
| | | #include<dirent.h> |
| | | #include"proxyserver.h" |
| | | #include <syslog.h> |
| | | |
| | | |
| | | #include <libxml/parser.h> |
| | | #include <libxml/tree.h> |
| | | #include <libxml/xpath.h> |
| | | #include <libxml/xpathInternals.h> |
| | | |
| | | int RequestChannel; |
| | | char* gAnalyzerIP; |
| | | char* gUser; |
| | |
| | | int gMySock[16]; |
| | | int threadIdx=0; |
| | | char byte_array[2600]; |
| | | char buff[102400]; |
| | | int gGettingStep=0; |
| | | char uri[300]; |
| | | time_t StartTm,EndTm; |
| | |
| | | int ZipSerFileNum=0; |
| | | int ZipCountidx; |
| | | char NetInfo[128]; |
| | | char EventString[5000 * 1024]; |
| | | EVENT_LOG myEventLogs[1000 * 1024]; |
| | | char EventString[1 * 1024 * 1024]; |
| | | EVENT_LOG myEventLogs[2000]; |
| | | int EventCount=0; |
| | | int EventCountInSearchRange=0; |
| | | |
| | |
| | | } |
| | | char* GetDeviceInfo(char* AnalyserIP) |
| | | { |
| | | memset(EventString,0,100000); |
| | | char buff[102400]; |
| | | memset(EventString,0,sizeof(EventString)); |
| | | gAnalyzerIP = AnalyserIP; |
| | | |
| | | if(AnalyserIP==NULL || AnalyserIP[0]==0) return "Param Error"; |
| | |
| | | length = sprintf(byte_array,"GET /PSIA/System/deviceInfo HTTP/1.1\r\nContent-Type: text/xml\r\nHost: %s\r\nContent-Length: 0\r\nConnection: Keep-Alive\r\n\r\n",AnalyserIP); |
| | | write(GSocket,byte_array,length); |
| | | // printf("%s",byte_array); |
| | | memset(EventString,0,100000); |
| | | memset(EventString,0,sizeof(EventString)); |
| | | while(1){ |
| | | memset(buff,0,sizeof(buff)); |
| | | length=read(GSocket,&buff,sizeof(buff)); |
| | |
| | | return ret; |
| | | |
| | | } |
| | | char* GetAnalyserAll() //9.查询设备 参数:无 返回:分析器的名称和ip |
| | | char* GetAnalyserAll() //9.鏌ヨ璁惧 鍙傛暟锛氭棤 杩斿洖锛氬垎鏋愬櫒鐨勫悕绉板拰ip |
| | | { |
| | | memset(EventString,0,100000); |
| | | memset(EventString,0,sizeof(EventString)); |
| | | int ret = Read_MysqlData(); |
| | | if(ret==0) return EventString; |
| | | else return "fail"; |
| | | } |
| | | char* GetAnalyserNet(void) //5.获取当前转发器的ip 参数:无。返回:当前的ip地址子网掩码和网关 |
| | | char* GetAnalyserNet(void) //5.鑾峰彇褰撳墠杞彂鍣ㄧ殑ip 鍙傛暟锛氭棤銆傝繑鍥烇細褰撳墠鐨刬p鍦板潃瀛愮綉鎺╃爜鍜岀綉鍏? |
| | | { |
| | | memset(NetInfo,0,128); |
| | | /// function |
| | | return NetInfo; |
| | | } |
| | | |
| | | int SetAnalyserNet(char* NetInfo) //6.手动设置转发器的ip 参数:ip,子网掩码,默认网关 。 返回:修改状态(成功或者失败) |
| | | int SetAnalyserNet(char* NetInfo) //6.鎵嬪姩璁剧疆杞彂鍣ㄧ殑ip 鍙傛暟锛歩p锛屽瓙缃戞帺鐮侊紝榛樿缃戝叧 銆?杩斿洖锛氫慨鏀圭姸鎬?鎴愬姛鎴栬€呭け璐? |
| | | { |
| | | int ret=0; |
| | | /// function |
| | |
| | | //// 输出:0(成功), -1(初始化失败),-2(连接失败) |
| | | int RealEventStart(char* AnalyserIP,char* user,char* pass) |
| | | { |
| | | char buff[10240]; |
| | | |
| | | gAnalyzerIP = AnalyserIP; |
| | | gUser = user; |
| | | gPass = pass; |
| | |
| | | { |
| | | int eidx = (int)arg; |
| | | int length; |
| | | char buff[10240]; |
| | | |
| | | puts("Step.2 ========>Equipment Thread is strarted......"); |
| | | |
| | |
| | | char* GetRealEvent(char* AnalyserIP) //3.查看实时监控 参数:分析器IP。返回:信道号及其对应的视频流地址 |
| | | { |
| | | int Idx=FindIdx(AnalyserIP); |
| | | memset(EventString,0,100000); |
| | | memset(EventString,0,sizeof(EventString)); |
| | | if(Idx>=0 && Idx<16 && RealAlarmEventNum[Idx]>0){ |
| | | for (int i=0;i<RealAlarmEventNum[Idx];i++) |
| | | { |
| | |
| | | //// 输出:查询结果。(包括信道号,报警时间,播放地址,等。) |
| | | char* GetPHPSearchMetaInfo(char* AnalyserIP,char* user,char* pass,int Channel,int s_year,int s_month,int s_day,int s_hour,int s_minute,int s_sec,int e_year,int e_month,int e_day,int e_hour,int e_minute,int e_sec) |
| | | { |
| | | openlog("proxyserver", LOG_CONS | LOG_PID, 0); |
| | | |
| | | char* result; |
| | | MyTime mstart_time; |
| | | mstart_time.Year=s_year; |
| | |
| | | char* GetMp4Info(char* AnalyserIP,char* user,char* pass,int Channel,char* path) |
| | | { |
| | | char Pathbuffer[100] = {0}; |
| | | char buff[102400]; |
| | | |
| | | RequestChannel = Channel; |
| | | gAnalyzerIP = AnalyserIP; |
| | |
| | | } |
| | | |
| | | |
| | | |
| | | void DownloadSerFile(const char* uri) |
| | | { |
| | | return; |
| | | char buff[1024]; |
| | | sprintf(buff, "cd " ZIP_HOME "/tmpZip/;" " curl -u supervisor:supervisor 'http://%s%s' -O" , gAnalyzerIP, uri); |
| | | int ret = system(buff); |
| | | printf("DownloadSerFile, ret=%d, %s\n", ret, buff); |
| | | |
| | | } |
| | | |
| | | |
| | | //// 查询报警记录 |
| | |
| | | //// 输出:查询结果。(包括信道号,报警时间,播放地址,等。) |
| | | char* GetSearchMetaInfo(char* AnalyserIP,char* user,char* pass,int Channel,lpMyTime StartTm,lpMyTime EndTm) |
| | | { |
| | | char buff[102400]; |
| | | //reset |
| | | memset(ZipSerFileName, 0, sizeof(ZipSerFileName)); |
| | | ZipSerFileNum=0; |
| | | ZipCountidx; |
| | | EventCount = 0; |
| | | EventCountInSearchRange = 0; |
| | | RequestChannel = -1; |
| | | memset(myEventLogs, 0, sizeof(myEventLogs)); |
| | | memset(EventString, 0, sizeof(EventString)); |
| | | memset(byte_array, 0, sizeof(byte_array)); |
| | | |
| | | RequestChannel = Channel; |
| | | gAnalyzerIP = AnalyserIP; |
| | | gUser = user; |
| | |
| | | if(AnalyserIP==NULL || AnalyserIP[0]==0) return "-1"; |
| | | // if(gGettingStep>0) return -2; |
| | | |
| | | chmod(ZIP_HOME,0777); |
| | | //delete_file(ZIP_HOME "/tmp/tmp.zip"); |
| | | //chmod(ZIP_HOME,0777); |
| | | //delete_file(ZIP_HOME "/tmp.zip"); |
| | | //delete_file(ZIP_HOME "/tmpZip/*"); |
| | | |
| | | struct tm ttm; |
| | |
| | | int length; |
| | | char* httpUri; |
| | | char sss[24],eee[24]; |
| | | chmod("/home",0777);//#todo ZIP_HOME |
| | | chmod(ZIP_HOME,0777); |
| | | const char* folderr; |
| | | const char* filename1; |
| | | folderr="/home/tmpZip"; |
| | | filename1="/home/tmp.zip"; |
| | | folderr=ZIP_HOME "/tmpZip"; |
| | | filename1=ZIP_HOME "/tmp.zip"; |
| | | struct stat sb; |
| | | if(stat(folderr,&sb)==0 && S_ISDIR(sb.st_mode)) |
| | | { |
| | | delete_folder("/home/tmpZip"); |
| | | } |
| | | if (doesFileExist(filename1)) |
| | | { |
| | | delete_file("/home/tmp.zip"); |
| | | } |
| | | //if(stat(folderr,&sb)==0 && S_ISDIR(sb.st_mode)) |
| | | // { |
| | | delete_folder(ZIP_HOME "/tmpZip"); |
| | | // } |
| | | //if (doesFileExist(filename1)) |
| | | // { |
| | | delete_file(ZIP_HOME "/tmp.zip"); |
| | | // } |
| | | if(RequestChannel==0) httpUri= "/PSIA/VIQ/Event/metadata/0/files"; |
| | | if(RequestChannel==1) httpUri= "/PSIA/VIQ/Event/metadata/1/files"; |
| | | if(RequestChannel==2) httpUri= "/PSIA/VIQ/Event/metadata/2/files"; |
| | |
| | | SearchEndTm -= 8 * 60 * 60; |
| | | |
| | | #ifdef DBG_LOG |
| | | printf("stm=%d,etm=%d\n",(int)SearchStartTm,(int)SearchEndTm); |
| | | syslog(LOG_USER | LOG_INFO, "SearchStartTm=%d,SearchEndTm=%d\n",(int)SearchStartTm,(int)SearchEndTm); |
| | | #endif |
| | | |
| | | //for (StepTm=SearchEndTm; StepTm>SearchStartTm; StepTm-=1*3600) |
| | |
| | | struct sockaddr_in servaddr; |
| | | int strlen1=sizeof(servaddr); |
| | | if((GSocket=socket(PF_INET,SOCK_STREAM,0))<0){ |
| | | perror("socket fail2"); |
| | | syslog(LOG_USER | LOG_INFO, "socket fail2"); |
| | | return "-3"; |
| | | } |
| | | memset(&servaddr,0,strlen1); |
| | |
| | | servaddr.sin_port=htons(80); |
| | | |
| | | if(connect(GSocket,(struct sockaddr*)&servaddr,strlen1)<0){ |
| | | printf("Equipment connect fail-%s:%d\n",gAnalyzerIP,80); |
| | | syslog(LOG_USER | LOG_INFO, "Equipment connect fail-%s:%d\n",gAnalyzerIP,80); |
| | | close(GSocket); |
| | | return "-4"; |
| | | } |
| | |
| | | sprintf(eee,"%d-%02d-%02dT%02d:%02d:%02d.000",t->tm_year+1900,t->tm_mon+1,t->tm_mday,t->tm_hour,t->tm_min,t->tm_sec);// = "2016-08-26T07:31:00.000"; |
| | | eee[23]=0; |
| | | #ifdef DBG_LOG |
| | | printf("sss=%s, eee=%s\n", sss, eee); |
| | | syslog(LOG_USER | LOG_INFO, "SearchStartTm=%s, SearchEndTm=%s\n", sss, eee); |
| | | #endif |
| | | RequestMetaFiles(gAnalyzerIP,httpUri,sss,eee); |
| | | write(GSocket,byte_array,strlen(byte_array)); |
| | | |
| | | |
| | | //用以下方法将socket设置为非阻塞方式 |
| | | // int flags = fcntl(GSocket, F_GETFL, 0); |
| | | // fcntl(GSocket, F_SETFL, flags | O_NONBLOCK); |
| | | while(1){ |
| | | memset(buff,0,sizeof(buff)); |
| | | length=read(GSocket,&buff,sizeof(buff)); |
| | | //#test |
| | | { |
| | | length=read(GSocket,&buff,sizeof(buff)); |
| | | |
| | | //#test |
| | | //{ |
| | | // FILE * pFile = fopen ("pro.txt","rb"); |
| | | // length = fread ( buff, 1, sizeof(buff), pFile ); |
| | | // fclose(pFile); |
| | | // bMetadataSaving = 0; |
| | | //} |
| | | |
| | | if(length<=0) |
| | | { |
| | | close(GSocket); |
| | | break; |
| | | syslog(LOG_USER | LOG_INFO, "length<=0"); |
| | | } |
| | | if(memorycmp((unsigned char*)buff,length, "WWW-Authenticate:",17)>0) |
| | | { |
| | | // analyse reception |
| | | MakeAuthorizedPacketSimp111(buff,length,"GET",httpUri,sss,eee); |
| | | write(GSocket,byte_array,strlen(byte_array)); |
| | | continue; |
| | | } |
| | | if(bMetadataSaving==1){ |
| | | memoryband[bandCount] = (unsigned char*)malloc(length); |
| | | memcpy(memoryband[bandCount], buff, length); |
| | | bandsize[bandCount] = length; |
| | | if(bandCount<99) bandCount++; |
| | | int eidx = stringcmp((char*)buff,"</urn:strings></urn:ViqStrings></urn:ViqStringsList>",52); |
| | | if(eidx >=0){ |
| | | bMetadataSaving = 0; |
| | | int SSize=0; |
| | | for (int i=0;i<bandCount;i++) SSize+=bandsize[i]; |
| | | char *tmpp = (char*)malloc(SSize); |
| | | int xx=0; |
| | | for (int i=0;i<bandCount;i++) |
| | | { |
| | | memcpy(&tmpp[xx],memoryband[i],bandsize[i]); |
| | | xx=bandsize[i]; |
| | | free(memoryband[i]); |
| | | } |
| | | memcpy(buff,tmpp,SSize); |
| | | free(tmpp); |
| | | goto lpp123; |
| | | printf("**********Special*******************************ZipSerFileNum = %d",ZipSerFileNum); |
| | | } |
| | | |
| | | //FILE * pFile = fopen ("pro.txt","rb"); |
| | | //length = fread ( buff, 1, sizeof(buff), pFile ); |
| | | |
| | | xmlParserCtxtPtr ctxt; |
| | | char chars[5000]; |
| | | xmlDocPtr doc; /* the resulting document tree */ |
| | | int res,totalres=0; |
| | | |
| | | char* pBuff = buff; |
| | | while ((res = read(GSocket,chars,sizeof(chars))) > 0) |
| | | { |
| | | memcpy(pBuff, chars, res); |
| | | pBuff+=res; |
| | | totalres+=res; |
| | | } |
| | | else{ |
| | | int sidx = stringcmp((char*)buff,"<urn:ViqStringsList urn:version=",32); |
| | | if(sidx >=0){ |
| | | bMetadataSaving = 1; |
| | | bandCount = 0; |
| | | memoryband[bandCount] = (unsigned char*)malloc(length-sidx); |
| | | memcpy(memoryband[bandCount], &buff[sidx], length-sidx); |
| | | bandsize[bandCount] = length-sidx; |
| | | if(bandCount<99) bandCount++; |
| | | int eidx = stringcmp((char*)buff,"</urn:strings></urn:ViqStrings></urn:ViqStringsList>",52); |
| | | if(eidx >=0 && sidx<eidx){ |
| | | free(memoryband[0]); |
| | | bandCount = 0; |
| | | bMetadataSaving = 0; |
| | | buff[eidx]=0; |
| | | int ptr=0; |
| | | ////// analyze buffer |
| | | lpp123: sidx = stringcmp((char*)&buff[ptr],"http://changeit:80/media",24); |
| | | if(sidx >=0){//http://changeit:80/media/metadata/0/2016/8/25/1/2/s_5b4103706a6411e6855e574ec330e01d_20160825_013633_93003.zip |
| | | int zipidx =-1;zipidx = stringcmp((char*)&buff[ptr],".zip",4); |
| | | int seridx =-1;seridx = stringcmp((char*)&buff[ptr],".ser",4); |
| | | int kkk=-1; |
| | | if(zipidx>=0){ |
| | | if(seridx>=0){ |
| | | if(zipidx<seridx) kkk = zipidx; |
| | | else kkk = seridx; |
| | | } |
| | | else kkk = zipidx; |
| | | } |
| | | else{ |
| | | if(seridx>=0) kkk = seridx; |
| | | } |
| | | if(kkk>=0 && kkk>sidx+18) |
| | | { |
| | | //下载metadata |
| | | char pathbuf[250] ; |
| | | strncpy(pathbuf,(char*)&buff[ptr+sidx+18],kkk-sidx-18+4); |
| | | pathbuf[kkk-sidx-18+4]=0; |
| | | int i; |
| | | for (i=0;i<ZipSerFileNum;i++) |
| | | { |
| | | if(strcmp(pathbuf,ZipSerFileName[i])==0) break; |
| | | } |
| | | if(i>=ZipSerFileNum){ |
| | | strcpy(ZipSerFileName[ZipSerFileNum],pathbuf); |
| | | if(ZipSerFileNum<1000-1) ZipSerFileNum++; |
| | | } |
| | | ptr=ptr+kkk+4; |
| | | goto lpp123; |
| | | } |
| | | } |
| | | } |
| | | } |
| | | *pBuff='\0'; |
| | | |
| | | |
| | | //res = fread ( chars, 1, sizeof(chars), pFile ); |
| | | char* urnbegin=strstr(buff, "<urn:"); |
| | | |
| | | //ctxt = xmlCreatePushParserCtxt(NULL, NULL, urnbegin, totalres-(urnbegin-buff), NULL); |
| | | //if (ctxt == NULL) { |
| | | // fprintf(stderr, "Failed to create parser context !\n"); |
| | | //} |
| | | // |
| | | //xmlParseChunk(ctxt, urnbegin, totalres-(urnbegin-buff), 1); |
| | | |
| | | //while ((res = fread ( chars, 1, sizeof(chars), pFile )) > 0) { // fread(chars, 4) |
| | | //while ((res = read(GSocket,chars,sizeof(chars))) > 0) { |
| | | // xmlParseChunk(ctxt, chars, res, 0); |
| | | //} |
| | | |
| | | //doc = ctxt->myDoc; |
| | | doc = xmlParseDoc(urnbegin); |
| | | //res = ctxt->wellFormed; |
| | | //xmlFreeParserCtxt(ctxt); |
| | | |
| | | //if (!res) { |
| | | // fprintf(stderr, "Failed to parse %s\n", "pro.txt"); |
| | | //} |
| | | |
| | | /* Create xpath evaluation context */ |
| | | xmlXPathContextPtr xpathCtx = xmlXPathNewContext(doc); |
| | | if(xpathCtx == NULL) { |
| | | fprintf(stderr,"Error: unable to create new XPath context\n"); |
| | | xmlFreeDoc(doc); |
| | | return(-1); |
| | | } |
| | | }// while end |
| | | |
| | | //xmlNode * root_element = xmlDocGetRootElement(doc); |
| | | //{ |
| | | // xmlNode *cur_node = NULL; |
| | | // |
| | | // for (cur_node = root_element; cur_node; cur_node = cur_node->next) { |
| | | // if (cur_node->type == XML_ELEMENT_NODE) { |
| | | // syslog(LOG_USER | LOG_INFO, "node type: Element, name: %s %s\n", cur_node->ns->prefix,cur_node->ns->href ); |
| | | // } |
| | | // } |
| | | //} |
| | | |
| | | if(xmlXPathRegisterNs(xpathCtx, "urn", "urn:videoiq-com") != 0) { |
| | | fprintf(stderr,"Error: unable to register NS with prefix=\"\" and href=\"\"\n"); |
| | | return(-1); |
| | | } |
| | | |
| | | xmlXPathObjectPtr xpathObj = xmlXPathEvalExpression("//urn:strings", xpathCtx); |
| | | if(xpathObj == NULL) { |
| | | fprintf(stderr,"Error: unable to evaluate xpath expression \"%s\"\n", "urn:strings"); |
| | | xmlXPathFreeContext(xpathCtx); |
| | | xmlFreeDoc(doc); |
| | | return(-1); |
| | | } |
| | | |
| | | ZipSerFileNum=0; |
| | | xmlNodeSetPtr nodes = xpathObj->nodesetval; |
| | | for(int i = 0; i<nodes->nodeNr; i++) |
| | | { |
| | | const char* uri=xmlNodeGetContent(nodes->nodeTab[i]); |
| | | strcpy(ZipSerFileName[ZipSerFileNum], uri+18); |
| | | ZipSerFileNum++; |
| | | syslog(LOG_USER | LOG_INFO, "%s\n", uri+18); |
| | | } |
| | | |
| | | syslog(LOG_USER | LOG_INFO, "ser parse finished\n"); |
| | | |
| | | |
| | | xmlFreeDoc(doc); |
| | | |
| | | |
| | | //fclose(pFile); |
| | | close(GSocket); |
| | | |
| | | |
| | | } |
| | | |
| | | |
| | | }//for |
| | | |
| | | //////// get |
| | | syslog(LOG_USER | LOG_INFO, "ZipSerFileNum=%d\n", ZipSerFileNum); |
| | | |
| | | for(ZipCountidx = 0; ZipCountidx<ZipSerFileNum; ZipCountidx++) |
| | | { |
| | | if(stringcmp((char*)ZipSerFileName[ZipCountidx],".ser",4)>=0) continue; |
| | | syslog(LOG_USER | LOG_INFO, "ZipSerFileName[%d]=%s\n", ZipCountidx, (char*)ZipSerFileName[ZipCountidx]); |
| | | |
| | | if(stringcmp((char*)ZipSerFileName[ZipCountidx],".ser",4)>=0) |
| | | { |
| | | DownloadSerFile(ZipSerFileName[ZipCountidx]); |
| | | continue; |
| | | } |
| | | |
| | | zclock_sleep(200); |
| | | // printf(" ==== Search loop function execution =================%d,%d \n",(int)StepTm,(int)SearchStartTm); |
| | | struct sockaddr_in servaddr; |
| | | int strlen1=sizeof(servaddr); |
| | | if((GSocket=socket(PF_INET,SOCK_STREAM,0))<0){ |
| | | perror("socket fail2"); |
| | | syslog(LOG_USER | LOG_INFO, "socket fail2"); |
| | | return "-3"; |
| | | } |
| | | memset(&servaddr,0,strlen1); |
| | |
| | | servaddr.sin_port=htons(80); |
| | | |
| | | if(connect(GSocket,(struct sockaddr*)&servaddr,strlen1)<0){ |
| | | printf("Equipment connect fail-%s:%d\n",gAnalyzerIP,80); |
| | | syslog(LOG_USER | LOG_INFO, "Equipment connect fail-%s:%d\n",gAnalyzerIP,80); |
| | | close(GSocket); |
| | | return "-4"; |
| | | } |
| | | |
| | | httpUri = ZipSerFileName[ZipCountidx];//"/media/metadata/0/2016/8/25/1/2/s_5b4103706a6411e6855e574ec330e01d_20160825_013633_93003.zip"; |
| | | RequestZipSerFiles(gAnalyzerIP,httpUri); |
| | | RequestZipSerFiles(gAnalyzerIP, httpUri); |
| | | write(GSocket,byte_array,strlen(byte_array)); |
| | | // printf("==========================================================================================================================>>>>>>>>\n"); |
| | | // printf("%s",byte_array); |
| | |
| | | bZipFileSaving = 0; |
| | | close(GSocket); |
| | | //Convert Zip file to Ser file |
| | | system("unzip -o " ZIP_HOME "/tmp.zip -d " ZIP_HOME "/tmpZip"); |
| | | int ret=system("unzip -o " ZIP_HOME "/tmp.zip -d " ZIP_HOME "/tmpZip"); |
| | | #ifdef DBG_LOG |
| | | syslog(LOG_USER | LOG_INFO, "unzip1 ret=%d\n", ret); |
| | | #endif |
| | | } |
| | | } |
| | | else{ |
| | |
| | | bZipFileSaving = 0; |
| | | close(GSocket); |
| | | //Convert Zip file to Ser file |
| | | system("unzip -o " ZIP_HOME "/tmp.zip -d " ZIP_HOME "/tmpZip"); |
| | | int ret=system("unzip -o " ZIP_HOME "/tmp.zip -d " ZIP_HOME "/tmpZip"); |
| | | #ifdef DBG_LOG |
| | | syslog(LOG_USER | LOG_INFO, "unzip0 ret=%d\n", ret); |
| | | #endif |
| | | } |
| | | } |
| | | } |
| | |
| | | char stringpath[1024]; |
| | | unsigned char p_save_buf[6144000]; |
| | | |
| | | for(i=0;i<num;i++) |
| | | for(int i=0;i<num;i++) |
| | | { |
| | | if(filename[i].name[0]=='.') continue; |
| | | memset(stringpath,0,1024); |
| | |
| | | memset(EventString,0,sizeof(EventString)); |
| | | //for(i=0;i<1000;i++) |
| | | #ifdef DBG_LOG |
| | | printf("EventCount===========================%d\n",EventCount); |
| | | printf("EventCountInSearchRange==============%d\n",EventCountInSearchRange); |
| | | syslog(LOG_USER | LOG_INFO, "EventCount===========================%d\n",EventCount); |
| | | syslog(LOG_USER | LOG_INFO, "EventCountInSearchRange==============%d\n",EventCountInSearchRange); |
| | | #endif |
| | | |
| | | strcat(EventString,"["); |
| | | |
| | | for (i=0;i<EventCount;i++) |
| | | for (int i=0;i<EventCount;i++) |
| | | { |
| | | #ifndef DBG_LOG |
| | | if (! myEventLogs[i].InSearchRange) |
| | |
| | | } |
| | | |
| | | strcat(EventString,"]"); |
| | | |
| | | //reset |
| | | //EventCount = 0;//#todo |
| | | //EventCountInSearchRange = 0; |
| | | //RequestChannel = -1; |
| | | //memset(&myEventLogs, 0, sizeof(myEventLogs)); |
| | | |
| | | return EventString; |
| | | //return "333333333333333333333333333333333333333333333333333333333333333333789"; |
| | |
| | | //// 输出:0(成功), -1(初始化失败),-2(连接失败) |
| | | int RestartCommand(char* AnalyserIP,char* user,char* pass) |
| | | { |
| | | char buff[10240]; |
| | | gAnalyzerIP = AnalyserIP; |
| | | gUser = user; |
| | | gPass = pass; |
| | |
| | | struct sockaddr_in servaddr; |
| | | int strlen1=sizeof(servaddr); |
| | | if((GSocket=socket(PF_INET,SOCK_STREAM,0))<0){ |
| | | perror("socket fail2"); |
| | | syslog(LOG_USER | LOG_INFO, "socket fail2"); |
| | | return -1; |
| | | } |
| | | memset(&servaddr,0,strlen1); |
| | |
| | | servaddr.sin_port=htons(80); |
| | | |
| | | if(connect(GSocket,(struct sockaddr*)&servaddr,strlen1)<0){ |
| | | printf("Equipment connect fail-%s:%d\n",gAnalyzerIP,80); |
| | | syslog(LOG_USER | LOG_INFO, "Equipment connect fail-%s:%d\n",gAnalyzerIP,80); |
| | | close(GSocket); |
| | | return -2; |
| | | } |
| | |
| | | |
| | | } |
| | | close(GSocket); |
| | | if (bbbb==0) return -1; |
| | | if (bbbb==0) |
| | | { |
| | | syslog(LOG_USER | LOG_INFO, "bbbb==0"); |
| | | return -1; |
| | | } |
| | | // zclock_sleep(200); |
| | | if((GSocket=socket(PF_INET,SOCK_STREAM,0))<0){ |
| | | perror("socket fail2"); |
| | | syslog(LOG_USER | LOG_INFO, "socket fail2"); |
| | | return -1; |
| | | } |
| | | memset(&servaddr,0,strlen1); |
| | |
| | | servaddr.sin_port=htons(80); |
| | | |
| | | if(connect(GSocket,(struct sockaddr*)&servaddr,strlen1)<0){ |
| | | printf("Equipment connect fail-%s:%d\n",gAnalyzerIP,80); |
| | | syslog(LOG_USER | LOG_INFO, "Equipment connect fail-%s:%d\n",gAnalyzerIP,80); |
| | | close(GSocket); |
| | | return -2; |
| | | } |
| | |
| | | |
| | | void RequestMetaFiles(char* AnaylyIP,char* httpUri,char* Tm1,char* Tm2) |
| | | { |
| | | #ifdef DBG_LOG |
| | | syslog(LOG_USER | LOG_INFO, "RequestMetaFiles, httpUri=%s\n", httpUri); |
| | | #endif |
| | | |
| | | char byte_arrayxxx[1600]; |
| | | int lengthxxx = 0; |
| | | memset(byte_array,0,1600); |
| | | memset(byte_array,0,sizeof(byte_array)); |
| | | |
| | | UrnStringToBytes(byte_arrayxxx,&lengthxxx,Tm1,Tm2);// xml |
| | | int iidx =0,llen=0;; |
| | |
| | | llen = sprintf(&byte_array[iidx],"Host: %s:%d\r\n",AnaylyIP,80); iidx+=llen; |
| | | llen = sprintf(&byte_array[iidx],"%s","Connection: Keep_Alive\r\n\r\n"); iidx+=llen; |
| | | strncpy(&byte_array[iidx],byte_arrayxxx,lengthxxx); iidx+=lengthxxx; |
| | | |
| | | } |
| | | void RequestZipSerFiles(char* AnaylyIP,char* httpUri) |
| | | { |
| | | memset(byte_array,0,1600); |
| | | #ifdef DBG_LOG |
| | | syslog(LOG_USER | LOG_INFO, "RequestZipSerFiles, httpUri=%s\n", httpUri); |
| | | #endif |
| | | |
| | | memset(byte_array,0,sizeof(byte_array)); |
| | | |
| | | int iidx =0,llen=0;; |
| | | llen = sprintf(byte_array,"GET %s %s",httpUri,"HTTP/1.1\r\n"); iidx+=llen; |
| | |
| | | if((myEventLogs[EventCount].DebugMessageE[0]!=0|| myEventLogs[EventCount].DebugMessageS[0]!=0) && myEventLogs[EventCount].Rule[0]==0 && myEventLogs[EventCount].Region[0]==0){ |
| | | memcpy(ttmp,(unsigned char*)p_save_buf,5000); |
| | | } |
| | | if(somewhat && EventCount<200-1){///repair //#todo 12.7 |
| | | if(somewhat && EventCount<2000-1){///repair //#todo 12.7 |
| | | sprintf(myEventLogs[EventCount].Camera,"%d",RequestChannel+1); |
| | | int i; |
| | | for (i=0;i<EventCount;i++) |
| | |
| | | char cmd[30]; |
| | | memset(cmd,0,30); |
| | | sprintf(cmd,"rm -f %s",path); |
| | | system(cmd); |
| | | int ret = system(cmd); |
| | | #ifdef DBG_LOG |
| | | syslog(LOG_USER | LOG_INFO, "delete_file, ret=%d, %s\n", ret, path); |
| | | #endif |
| | | } |
| | | void delete_folder(const char *path) |
| | | { |
| | | char cmd[30]; |
| | | memset(cmd,0,30); |
| | | sprintf(cmd,"rm -r %s",path); |
| | | system(cmd); |
| | | int ret = system(cmd); |
| | | #ifdef DBG_LOG |
| | | syslog(LOG_USER | LOG_INFO, "delete_folder, ret=%d, %s\n", ret, path); |
| | | #endif |
| | | } |
| | | int doesFileExist(const char *filename) |
| | | { |
| | |
| | | return output; |
| | | } |
| | | |
| | | |
| | | void zclock_sleep (int msecs) |
| | | { |
| | | struct timespec t; |
| | | t.tv_sec = msecs / 1000; |
| | | t.tv_nsec = (msecs % 1000) * 1000000; |
| | | nanosleep (&t, NULL); |
| | | } |
| | | |
| | | |