C语言开发Linux下web服务器(支持GETPOST,SSL,目录显示等)

阅读: 评论:0

2024年1月30日发(作者:)

C语言开发Linux下web服务器(支持GETPOST,SSL,目录显示等)

sprintf(length,"%d",contentLength); memset(data,0,MAXLINE); Pipe(p); /* The post data is sended by client,we need to redirct the data to cgi stdin. * so, child read contentLength bytes data from fp,and write to p[1]; * parent should redirct p[0] to stdin. As a result, the cgi script can * read the post data from the stdin.

*/ /* https already read all data ,include post data by SSL_read() */

if (Fork() == 0) { /* child */

Close(p[0]); #ifdef HTTPS

if(ishttps) { Write(p[1],httpspostdata,contentLength);

} else #endif { Rio_readnb(rp,data,contentLength); Rio_writen(p[1],data,contentLength); } exit(0) ; }

/* Send response headers to client */ sprintf(buf, "HTTP/1.0 200 OKrn"); sprintf(buf, "%sServer: Tiny Web Serverrn",buf); #ifdef HTTPS

if(ishttps) SSL_write(ssl,buf,strlen(buf)); else #endif Rio_writen(fd, buf, strlen(buf)); Dup2(p[0],STDIN_FILENO); /* Redirct p[0] to stdin */ Close(p[0]); Close(p[1]); setenv("CONTENT-LENGTH",length , 1);

#ifdef HTTPS

if(ishttps) /* if ishttps,we couldnot redirct stdout to client,we must use SSL_write */ { Pipe(httpsp); if(Fork()==0) { Dup2(httpsp[1],STDOUT_FILENO); /* Redirct stdout to https[1] */

Execve(filename, emptylist, environ);

} Read(httpsp[0],data,MAXLINE); SSL_write(ssl,data,strlen(data)); } else

C语言开发Linux下web服务器(支持GETPOST,SSL,目录显示等)

本文发布于:2024-01-30 22:04:22,感谢您对本站的认可!

本文链接:https://www.4u4v.net/it/170662346223146.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

标签:服务器   开发   目录   显示   支持   C语言
留言与评论(共有 0 条评论)
   
验证码:
排行榜

Copyright ©2019-2022 Comsenz Inc.Powered by ©

网站地图1 网站地图2 网站地图3 网站地图4 网站地图5 网站地图6 网站地图7 网站地图8 网站地图9 网站地图10 网站地图11 网站地图12 网站地图13 网站地图14 网站地图15 网站地图16 网站地图17 网站地图18 网站地图19 网站地图20 网站地图21 网站地图22/a> 网站地图23