From 109ffe9a777658936a38d0c146579a67c60a0d17 Mon Sep 17 00:00:00 2001 From: xuxiuxi <xuxiuxi@454eff88-639b-444f-9e54-f578c98de674> Date: 星期四, 11 五月 2017 17:48:48 +0800 Subject: [PATCH] --- ProxyServer/proxyserver.c | 215 ++++++++++++++++++++++++++++++----------------------- 1 files changed, 123 insertions(+), 92 deletions(-) diff --git a/ProxyServer/proxyserver.c b/ProxyServer/proxyserver.c index c5a81da..6420895 100644 --- a/ProxyServer/proxyserver.c +++ b/ProxyServer/proxyserver.c @@ -10,6 +10,11 @@ #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; @@ -18,7 +23,6 @@ int gMySock[16]; int threadIdx=0; char byte_array[2600]; -char buff[102400]; int gGettingStep=0; char uri[300]; time_t StartTm,EndTm; @@ -47,7 +51,7 @@ #define fileread_buf 128 AlarmInfo RealAlarmEvent[16][1000]; -#define DBG_LOG +//#define DBG_LOG #define ZIP_HOME "/tmp" ///////////////////////////////////////////////// @@ -73,6 +77,7 @@ } char* GetDeviceInfo(char* AnalyserIP) { + char buff[102400]; memset(EventString,0,sizeof(EventString)); gAnalyzerIP = AnalyserIP; @@ -218,6 +223,8 @@ //// 杈撳嚭锛�0锛堟垚鍔燂級, -1(鍒濆鍖栧け璐�),-2(杩炴帴澶辫触) int RealEventStart(char* AnalyserIP,char* user,char* pass) { + char buff[10240]; + gAnalyzerIP = AnalyserIP; gUser = user; gPass = pass; @@ -361,6 +368,7 @@ { int eidx = (int)arg; int length; + char buff[10240]; puts("Step.2 ========>Equipment Thread is strarted......"); @@ -484,6 +492,7 @@ char* GetMp4Info(char* AnalyserIP,char* user,char* pass,int Channel,char* path) { char Pathbuffer[100] = {0}; + char buff[102400]; RequestChannel = Channel; gAnalyzerIP = AnalyserIP; @@ -628,6 +637,7 @@ //// 杈撳嚭锛氭煡璇㈢粨鏋溿�傦紙鍖呮嫭淇¢亾鍙凤紝鎶ヨ鏃堕棿锛屾挱鏀惧湴鍧�锛岀瓑銆傦級 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; @@ -734,117 +744,137 @@ #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; - syslog(LOG_USER | LOG_INFO, "**********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; //meta buff complete - 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; - syslog(LOG_USER | LOG_INFO, "pathbuf=%s\n", pathbuf); - 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 -#ifdef DBG_LOG syslog(LOG_USER | LOG_INFO, "ZipSerFileNum=%d\n", ZipSerFileNum); -#endif for(ZipCountidx = 0; ZipCountidx<ZipSerFileNum; ZipCountidx++) { -#ifdef DBG_LOG syslog(LOG_USER | LOG_INFO, "ZipSerFileName[%d]=%s\n", ZipCountidx, (char*)ZipSerFileName[ZipCountidx]); -#endif if(stringcmp((char*)ZipSerFileName[ZipCountidx],".ser",4)>=0) { @@ -1018,6 +1048,7 @@ //// 杈撳嚭锛�0锛堟垚鍔燂級, -1(鍒濆鍖栧け璐�),-2(杩炴帴澶辫触) int RestartCommand(char* AnalyserIP,char* user,char* pass) { + char buff[10240]; gAnalyzerIP = AnalyserIP; gUser = user; gPass = pass; -- Gitblit v1.8.0