http server v0.1_http_reponse.c
#include <string.h>
#include <sys/stat.h>
#include <sys/mman.h>
#include <fcntl.h>
#include <unistd.h>
#include <stdio.h> #include "mime.h"
#include "http_common.h"
#include "http_webapp.h"
static STR_STATUS_MAP resp_map[]={HTTP_STATUS_MAP(HTTP_MAP_GEN)}; /*---------------------------------------------------------------------------- -----------------------------------------------------------------------------*/
int get_response_head(EN_REP_STATUS status, EN_MIME_TYPE type, char* resp_head, int content_len)
{
int stat_len = ;
char* point = NULL;
char* content_type = NULL;
char lenstr[]; if(resp_head == NULL)
return -; if(status > HTTP_END || status < )
return -; point = resp_head;
// response status
stat_len = strlen(resp_map[status].head);
strncpy(point, resp_map[status].head, stat_len);
// server version
strcat(point, HTTP_RESP_HEAD_SERVER);
// content type
content_type = get_resp_type(type);
strcat(point, HTTP_RESP_HEAD_CONTENT_TYPE);
strcat(point, content_type);
// content length
strcat(point, HTTP_RESP_HEAD_CONTENT_LENGTH);
bzero(lenstr, sizeof(lenstr));
strcat(point, itoa(content_len,lenstr,));
// head end
strncat(point, "\r\n\r\n", );
return ;
} int get_response_body(EN_MIME_TYPE type, void* body, char* uri, long len)
{
int fd = ;
void* bodybuf = NULL;
if(body == NULL || uri == NULL)
return -; if(len == )
return ; if(type == HTTP_ELSE)
return -; fd = open(uri, O_RDONLY, );
if(fd == -)
{
close(fd);
return -;
}
// virsual memory map
bodybuf = mmap(, len, PROT_READ, MAP_PRIVATE, fd, );
memcpy(body, bodybuf, len);
munmap(bodybuf, len);
close(fd);
return ;
}
http server v0.1_http_reponse.c的更多相关文章
- http server v0.1_http_server.c
/**************************************************************** filename: http_server.c author: xx ...
- http server v0.1_http_parse.c
#include <stdio.h> #include <string.h> #include <stdlib.h> #include "mime.h&q ...
- http server v0.1_http_webapp.c
#include <stdio.h> #include <stdlib.h> #include <string.h> #include <unistd.h&g ...
- http server v0.1_mime.c
#include <string.h> #include "mime.h" static STR_MIME_MAP mime_map[]= { MIME_MAP(MIM ...
- 用FileZilla Server开FTP
FileZilla(教程)是经典的开源FTP解决方案,包括FileZilla客户端和FileZilla Server.其中,FileZilla Server的功能比起商业软件FTP Serv-U毫不逊 ...
- DNS隧道之DNS2TCP实现——dns2tcpc必须带server IP才可以,此外ssh可以穿过墙的,设置代理上网
我自己的命令: server端: dns2tcpd -F -d 1 -f ./dns2tcpd.conf 输出: 09:08:59 : Debug options.c:97 Add resource ...
- docker 下 安装rancher 笔记
sudo yum update 更新系统环境 curl -sSL https://get.docker.com/ | sh 安装最新docker版本 systemctl start docker.se ...
- 容器基础(七): 使用docker compose部署程序
配置 在上一节的基础上, 增加如下的docker-compose.yml文件, 然后用docker-compose up命令启动容器进行部署: version: " services: s ...
- 容器基础(八): 使用docker swarm部署程序
环境 基于上一节的env/server:v0.1, env/worker:v0.1镜像, 在基于debian8.2的两台机器上测试部署docker swarm. docker service部署 ➜ ...
随机推荐
- 包的定义和导入-----package
1.包的定义 其中: . 表示当前路径 2.包的导入 一个类需要被外包访问的话,需要定义为public class. package org.lxh.demo08.a ; public class ...
- Apache Solr配置
Solr配置 Solr的主要功能是全文检索,该功能分为两个过程:创建索引和对索引进行搜索: 在创建索引之前,需要重点关注两个配置文件:SOLR_HOME/collection1/conf/schema ...
- [TypeScript] Using Lodash in TypeScript with Typings and SystemJS
One of the most confusing parts of getting started with TypeScript is figuring out how to use all th ...
- 深入理解Fsync----JBD内核调试 专业打杂程序员 @github yy哥
http://hustcat.github.io/ http://www.cnblogs.com/hustcat/p/3283955.html http://blog.sina.com.cn/s/ar ...
- Cocos2d-x中获取设备语言的方法
1.cocos2dx获取设备语言的方法:CCApplication::sharedApplication()->getCurrentLanguage() 2.cocos2dx 2.1.4支持识别 ...
- java String的比较,BOX装箱拆箱,以及面向对象的小代码
package cn.hncu.day2; public class StringDemo { public static void main(String[] args) { String str1 ...
- android打包签名介绍
Keytool 是一个有效的安全钥匙和证书的管理工具. Java 中的 keytool.exe (位于 JDK\Bin 目录下)可以用来创建数字证书,所有的数字证书是以一条一条(采用别名区别)的形式存 ...
- RedHat7配置IdM server
IdM服务器是一个集成身份验证服务器. Figure 1.1. The IdM Server: Unifying Services Authentication: Kerberos KDC Kerbe ...
- centos7安装chrome的历程(fedora同)
安装 首先是下载,地址奉上:http://www.google.cn/chrome/browser/desktop/index.html,选择64 bit .rpm (适用于 Fedora/openS ...
- mysql免安装版使用
打开命令行,到bin目录下,输入net start mysql 启动服务,输入mysql -u root -p回车后输入密码,进入mysql.