Chinaunix首页 | 论坛 | 博客
  • 博客访问: 390879
  • 博文数量: 87
  • 博客积分: 2571
  • 博客等级: 少校
  • 技术积分: 920
  • 用 户 组: 普通用户
  • 注册时间: 2009-12-29 13:10
文章分类

全部博文(87)

文章存档

2012年(49)

2011年(7)

2010年(26)

2009年(5)

分类: C/C++

2011-08-22 13:58:01

源码包是tHttpd-2.25b
仅供学习记录

mmc -  mmap cache
ssi -  cgi-src/server-side-includes CGI program

fdwatch.c
支持4种fd处理方式,后续fd的操作是通过这里定义的宏进行,效果类似工厂模式
在本文件后半部分有这4中方法的具体实现

  1. #ifdef HAVE_KQUEUE
  2. #else /* HAVE_KQUEUE */
  3. # ifdef HAVE_DEVPOLL
  4. # else /* HAVE_DEVPOLL */
  5. # ifdef HAVE_POLL
  6. # else /* HAVE_POLL */
  7. # ifdef HAVE_SELECT

  8. # endif /* HAVE_SELECT */
  9. # endif /* HAVE_POLL */
  10. # endif /* HAVE_DEVPOLL */
  11. #endif /* HAVE_KQUEUE */

其他重要函数
  1. int fdwatch_get_nfiles(void) 调整fd的资源上线(似乎最多不超过8192个--hardcode?)

libhttpd.h -- defines for libhttpd
libhttpd.c  --  HTTP protocol library,对应结构体参看 libhttpd.h
  它的确是个lib,包含大量Http协议字段的拼接 -- 我是没有耐心去看了。。
  但也有大量实际为server操作服务的函数,少数列举几个:
  1. free_httpd_server();
  2. sockaddr_check();
  3. cgi_kill();
match.c -- simple shell-style filename matcher

timers.c -- simple timer routines

thttpd.c -- tiny/turbo/throttling HTTP server
  这个文件包括多数核心部分

其中几个主要全局变量:
  1. static httpd_server* hs = (httpd_server*) 0;
  2. static connecttab* connects;
  3. static throttletab* throttles;

cgi-src/redirect.c
  顾名思义,是做重定向用
  1. int main( int argc, char** argv )           //入口
main()函数中做了几件事情
1.当前执行的script名称,找不到则退出
2.将环境变量PATH_INFO包含进来,拼成要查找的script名称
3.打开重定向规则文件
  1. fp = fopen( ".redirects", "r" );
4.搜寻重定向script文件是否存在,存在则生成对应url,拼接成http协议字串,返回给请求方
(重定向后的文件名不会出现在这里---因为可能并不存在---只用url代表---请求方根据url请求后才能确定是否存在---这里只是根据规则给出重定向后的url地址)

  1. static void
  2. moved( char* script_name, char* url )
  3.     {
  4.     char* title = "Moved";

  5.     (void) printf( "\
  6. Location: %s\n\
  7. Content-type: text/html\n\
  8. \n\
  9. %s\n\
  10. %s

    \n\
  11. The requested filename, %s, has moved to a new URL:\n\
  12. %s\">%s.\n\
  13. \n", url, title, title, script_name, url, url );
  14.     }

不存在也拼接http字串,内容当然是404
  1. static void
  2. not_found( char* script_name )
  3.     {
  4.     char* title = "404 Not Found";

  5.     (void) printf( "\
  6. Status: %s\n\
  7. Content-type: text/html\n\
  8. \n\
  9. %s\n\
  10. %s

    \n\
  11. The requested filename, %s, is set up to be redirected to another URL;\n\
  12. however, the new URL has not yet been specified.\n\
  13. \n", title, title, title, script_name );
  14.     }


  


阅读(1722) | 评论(0) | 转发(0) |
0

上一篇:归约树

下一篇:zookeeper入门

给主人留下些什么吧!~~