Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1278527
  • 博文数量: 129
  • 博客积分: 1449
  • 博客等级: 上尉
  • 技术积分: 3048
  • 用 户 组: 普通用户
  • 注册时间: 2012-07-24 18:36
文章分类

全部博文(129)

文章存档

2015年(3)

2014年(20)

2013年(65)

2012年(41)

分类: C/C++

2012-12-19 12:18:52


点击(此处)折叠或打开

  1. DEBUGP("uh_http_header_parse: buflen = %d, headers = %s\n", buflen, headers);
  2. for( i = (int)(headers - buffer); i < buflen; i++ )
  3. {
  4. /* found eol and have name + value, push out header tuple */
  5. if( hdrname && hdrdata && (buffer[i] == '\r' || buffer[i] == '\n') )
  6. {
  7. buffer[i] = 0;

  8. /* store */
  9. if( (hdrcount + 1) < array_size(req.headers) )
  10. {
  11. req.headers[hdrcount++] = hdrname;
  12. req.headers[hdrcount++] = hdrdata;

  13. #ifdef INCLUDE_HTTPD_CGI
  14. uri = &buffer[i+1];
  15. DEBUGP("hdrname = %s, hdrdata = %s, uri = %s\n", hdrname, hdrdata, uri);
  16. #endif
  17. hdrname = hdrdata = NULL;
  18. }

  19. /* too large */
  20. else
  21. {
  22. uh_http_response(cl, 413, "Request Entity Too Large");
  23. return NULL;
  24. }
  25. }

  26. /* have name but no value and found a colon, start of value */
  27. else if( hdrname && !hdrdata && ((i+2) < buflen) &&
  28. (buffer[i] == ':') && (buffer[i+1] == ' ')
  29. ) {
  30. buffer[i] = 0;
  31. hdrdata = &buffer[i+2];
  32. }

  33. /* have no name and found [A-Za-z], start of name */
  34. else if( !hdrname && isalpha(buffer[i]) )
  35. {
  36. hdrname = &buffer[i];
  37. }
  38. }
上面代码实现的是解析HTTP收到的第1行以后的数据, 如下记录可看的更清楚

【Receive from 192.168.1.1 : 55142】:
uh_http_header_recv End: len = 432, buffer = POST /xutest/ip.cgi HTTP/1.1
Host: 192.168.1.1
User-Agent: Mozilla/5.0 (Windows NT 5.1; rv:16.0) Gecko/20100101 Firefox/16.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: zh-cn,zh;q=0.8,en-us;q=0.5,en;q=0.3
Accept-Encoding: gzip, deflate
Connection: keep-alive
Referer:
Content-Type: application/x-www-form-urlencoded
Content-Length: 82

staticip=0&sip1=&sip2=&sip3=&sip4=&mip1=&mip2=&mip3=&mip4=&gip1=&gip2=&gip3=&gip4=
 File:uhttpd.c, Line:570

【Receive from 192.168.1.1 : 56802】:
uh_http_header_parse: buflen = 431, headers = Host: 192.168.1.1
User-Agent: Mozilla/5.0 (Windows NT 5.1; rv:16.0) Gecko/20100101 Firefox/16.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: zh-cn,zh;q=0.8,en-us;q=0.5,en;q=0.3
Accept-Encoding: gzip, deflate
Connection: keep-alive
Referer:
Content-Type: application/x-www-form-urlencoded
Content-Length: 82

staticip=0&sip1=&sip2=&sip3=&sip4=&mip1=&mip2=&mip3=&mip4=&gip1=&gip2=&gip3=&gip4=
 File:uhttpd.c, Line:385

【Receive from 192.168.1.1 : 36916】:
hdrname = Host, hdrdata = 192.168.1.1, uri = 
User-Agent: Mozilla/5.0 (Windows NT 5.1; rv:16.0) Gecko/20100101 Firefox/16.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: zh-cn,zh;q=0.8,en-us;q=0.5,en;q=0.3
Accept-Encoding: gzip, deflate
Connection: keep-alive
Referer:
Content-Type: application/x-www-form-urlencoded
Content-Length: 82

staticip=0&sip1=&sip2=&sip3=&sip4=&mip1=&mip2=&mip3=&mip4=&gip1=&gip2=&gip3=&gip4=
 File:uhttpd.c, Line:401

【Receive from 192.168.1.1 : 51109】:
hdrname = User-Agent, hdrdata = Mozilla/5.0 (Windows NT 5.1; rv:16.0) Gecko/20100101 Firefox/16.0, uri = 
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: zh-cn,zh;q=0.8,en-us;q=0.5,en;q=0.3
Accept-Encoding: gzip, deflate
Connection: keep-alive
Referer:
Content-Type: application/x-www-form-urlencoded
Content-Length: 82

staticip=0&sip1=&sip2=&sip3=&sip4=&mip1=&mip2=&mip3=&mip4=&gip1=&gip2=&gip3=&gip4=
 File:uhttpd.c, Line:401

【Receive from 192.168.1.1 : 60872】:
hdrname = Accept, hdrdata = text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8, uri = 
Accept-Language: zh-cn,zh;q=0.8,en-us;q=0.5,en;q=0.3
Accept-Encoding: gzip, deflate
Connection: keep-alive
Referer:
Content-Type: application/x-www-form-urlencoded
Content-Length: 82

staticip=0&sip1=&sip2=&sip3=&sip4=&mip1=&mip2=&mip3=&mip4=&gip1=&gip2=&gip3=&gip4=
 File:uhttpd.c, Line:401

【Receive from 192.168.1.1 : 60156】:
hdrname = Accept-Language, hdrdata = zh-cn,zh;q=0.8,en-us;q=0.5,en;q=0.3, uri = 
Accept-Encoding: gzip, deflate
Connection: keep-alive
Referer:
Content-Type: application/x-www-form-urlencoded
Content-Length: 82

staticip=0&sip1=&sip2=&sip3=&sip4=&mip1=&mip2=&mip3=&mip4=&gip1=&gip2=&gip3=&gip4=
 File:uhttpd.c, Line:401

【Receive from 192.168.1.1 : 48937】:
hdrname = Accept-Encoding, hdrdata = gzip, deflate, uri = 
Connection: keep-alive
Referer:
Content-Type: application/x-www-form-urlencoded
Content-Length: 82

staticip=0&sip1=&sip2=&sip3=&sip4=&mip1=&mip2=&mip3=&mip4=&gip1=&gip2=&gip3=&gip4=
 File:uhttpd.c, Line:401

【Receive from 192.168.1.1 : 59934】:
hdrname = Connection, hdrdata = keep-alive, uri = 
Referer:
Content-Type: application/x-www-form-urlencoded
Content-Length: 82

staticip=0&sip1=&sip2=&sip3=&sip4=&mip1=&mip2=&mip3=&mip4=&gip1=&gip2=&gip3=&gip4=
 File:uhttpd.c, Line:401

【Receive from 192.168.1.1 : 42927】:
hdrname = Referer, hdrdata = , uri = 
Content-Type: application/x-www-form-urlencoded
Content-Length: 82

staticip=0&sip1=&sip2=&sip3=&sip4=&mip1=&mip2=&mip3=&mip4=&gip1=&gip2=&gip3=&gip4=
 File:uhttpd.c, Line:401

【Receive from 192.168.1.1 : 39386】:
hdrname = Content-Type, hdrdata = application/x-www-form-urlencoded, uri = 
Content-Length: 82

staticip=0&sip1=&sip2=&sip3=&sip4=&mip1=&mip2=&mip3=&mip4=&gip1=&gip2=&gip3=&gip4=
 File:uhttpd.c, Line:401

【Receive from 192.168.1.1 : 36893】:
hdrname = Content-Length, hdrdata = 82, uri = 

staticip=0&sip1=&sip2=&sip3=&sip4=&mip1=&mip2=&mip3=&mip4=&gip1=&gip2=&gip3=&gip4=
 File:uhttpd.c, Line:401

阅读(796) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~