免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 929 | 回复: 0
打印 上一主题 下一主题

从HTTP报头中提取时间数据 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2008-10-28 16:13 |只看该作者 |倒序浏览

[MMDDhhmm[[CC]YY][.ss]]
是BusyBox Shell的date命令格式,和RH9的不太一样。
/*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;

}


本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u2/83623/showart_1348821.html
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP