日期:2014-05-16 浏览次数:20717 次
/* pSrc: 原 chunked 数据包 nSize: 数据包大小 pDes: 解析完成后的数据 */ int DecodeChunked(const char* pSrc,int nSize, char** pDes) { int nRetSize = 0, nLeftSize = 0; printf("total data length=%d; /n",nSize); *pDes = (unsigned char*)malloc(nSize); if(pDes == NULL) return -1; char *pBegin = strstr(pSrc,"/r/n/r/n");//程序运行到这里pBegin为空,大家说怎么办 if (pBegin == NULL) return -1; pBegin += 4; while(1) { int ChunkedSize = 0; sscanf(pBegin,"%x",&ChunkedSize); if( 0==ChunkedSize ) { puts("endof chunkeds"); break; } pBegin = strstr(pBegin,"/r/n"); if (pBegin == NULL) return -1; pBegin += 2; // /r/n nLeftSize = nSize - (pBegin - pSrc); if (ChunkedSize > nLeftSize) ChunkedSize = nLeftSize; memcpy(*pDes+nRetSize,pBegin,ChunkedSize); nRetSize += ChunkedSize; if (ChunkedSize == nLeftSize) /* 数据包不全 */ break; pBegin += ChunkedSize; if (strstr(pBegin,"/r/n") != NULL) pBegin += 2; // /r/n else break; } return nRetSize; }
Breakpoint 1, need_to_parse_chunked_data (data=0xbffddbbc "a\r\n\037\213\b", len=15, buf=0xbffbdbbc "") at http.c:281 281 char strlength[10]={0}; (gdb) n 283 char * temp = buf; (gdb) 284 int total =0, length = 0, nBytes = 0; (gdb) 286 pTemp = strstr(pStart, "\r\n"); (gdb) n 287 if( NULL == pTemp ) (gdb) p data $1 = 0xbffddbbc "a\r\n\037\213\b" 这个数据包其实有1209个字节,但子函数里就只能看到这么一点点,我怀疑就是这里出问题了,但我又没有好的办法。gzip 文件中时包好多的0字符串,不知道有影响没 (gdb)