/*Function: httpParseDate *Description: parse date information *Parameters: none *Return: 0 : Success * -1 : failure */ int httpParseDate(char * strrecv) { char buf[64] = {0}; /*[MMDDhhmm[[CC]YY][.ss]]*/ char mon[4] = {0}; char day[4] = {0}; char hour[4] = {0}; char min[4] = {0}; char sec[4] = {0}; char year[6] = {0}; char * pBegin; char * pEnd; char * pos; char * pBuf; int i; pBegin = strstr(strrecv,"Date"); if (NULL == pBegin){ DDBG("Http head parsing Date information failed\n"); return -1; } else{ pEnd = strstr(strrecv,"GMT"); pos = pBegin; pBuf = buf;
for(i = 0; i < (pEnd-pBegin);i++,pBuf++,pos++) *pBuf = *pos ; *pBuf = '\0'; DBG("[parseDate]Databuf:%s\n", buf); } /*begin parse the date information*/ /*Date: Fri, 03 Aug 2007 07:02:23*/ pBegin = strstr(buf,","); if(NULL == pBegin){ DDBG("Date information parsing failed\n"); return -1; } else{ /*parse day*/ pos = pBegin + 2; pBuf = day; while(*pos != ' ') { *pBuf = *pos; pBuf ++ ; pos ++; } *pBuf = '\0'; DBG("[parseDate]day %s \n",day); /*parse month*/ pos ++; pBuf = mon; while(*pos != ' ') { *pBuf = *pos; pBuf ++ ; pos ++; } *pBuf = '\0'; DBG("[parseDate]Month(abbrev.) %s \n",mon); convertMonth(mon); DBG("[parseDate]Month(Num.) %s \n",mon); /*parse year*/ pos ++; pBuf = year; while(*pos != ' ') { *pBuf = *pos; pBuf ++ ; pos ++; } *pBuf = '\0'; DBG("[parseDate]year %s \n",year); /*parse Hour*/ pos ++; pBuf = hour; while(*pos != ':') { *pBuf = *pos; pBuf ++ ; pos ++; } *pBuf = '\0'; DBG("[parseDate]hour %s \n",hour); /*parse Minute*/ pos ++; pBuf = min; while(*pos != ':') { *pBuf = *pos; pBuf ++ ; pos ++; } *pBuf = '\0'; DBG("[parseDate]Minute %s \n",min); /*parse Seconds*/ pos ++; pBuf = sec; while(*pos != '\0') { *pBuf = *pos; pBuf ++ ; pos ++; } *pBuf = '\0'; DBG("[parseDate]Seconds %s \n",sec); }
/*set the GMT time to system*/ bzero(buf,64); strcpy(buf,"date -s "); strcat(buf,mon); strcat(buf,day); strcat(buf,hour); strcat(buf,min); strcat(buf,year); strcat(buf,"."); strcat(buf,sec); DBG("[parseDate]dateCMD %s\n",buf); system(buf); return 0; }
|