http server v0.1_http_parse.c
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "mime.h"
#include "http_common.h" static const char* methods[]=
{
"GET",
"POST"
}; static int get_version(const char* versionPos, char* version)
{
char* versionEnd = NULL;
int versionlen = ;
if(versionPos == NULL || version == NULL)
return -; versionEnd = strstr(versionPos, "\n");
versionlen = versionEnd - versionPos; #if 0
printf("versionlen = [%d]\n", versionlen);
#endif if(versionlen > || versionlen <)
return -; strncpy(version, versionPos, versionlen); return ;
} static int get_method(const char* request, EN_REQ_METHOD* method)
{ if(strncmp(request, methods[HTTP_GET], ) == )
{
*method = HTTP_GET;
}else if(strncmp(request, methods[HTTP_POST], ) == )
{
*method = HTTP_POST;
}else
{
*method = HTTP_ELSE;
} return (int)(*method);
} /*-------------------------------------------------------------- functionname: parse_request
param: NA
return: NA
author: xxxx --------------------------------------------------------------*/ int parse_request(const char* request, STR_REQUEST* result)
{
int method=;
int urilen =;
char* version_pos = NULL;
if(request == NULL || result == NULL)
return -; method =get_method(request, &(result->method));
//only apply GET POST
if(method == HTTP_ELSE)
return -; //-----------------get URI---------------------------------
version_pos = strstr(request, "HTTP");
//malloc uri
result->URI = (char*)malloc(urilen + WEBAPP_DIR_LEN);
//
if(result->URI == NULL)
{
perror("malloc failed");
return -;
} bzero(result->URI, urilen);
strncpy(result->URI, WEBAPP_DIR, WEBAPP_DIR_LEN);
//
if(result->method == HTTP_GET)
{
urilen = version_pos - (request+) -;
strncpy((result->URI)+WEBAPP_DIR_LEN, request + , urilen);
} if(result->method == HTTP_POST)
{
urilen = version_pos - (request + ) -;
strncpy(result->URI+WEBAPP_DIR_LEN, request + , urilen);
} //--------------------------------------------------------- if(get_version(version_pos, result->http_version) == -)
return -; return ;
}
http server v0.1_http_parse.c的更多相关文章
- http server v0.1_http_reponse.c
#include <string.h> #include <sys/stat.h> #include <sys/mman.h> #include <fcntl ...
- http server v0.1_http_server.c
/**************************************************************** filename: http_server.c author: xx ...
- 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部署 ➜ ...
随机推荐
- [TypeScript] Loading Compiled TypeScript Files in Browser with SystemJS
TypeScript outputs JavaScript, but what are you supposed to do with it? This lesson shows how to tak ...
- 字符集详解 ------------------------ UNICODE +UTF8
http://my.oschina.net/goldenshaw/blog?catalog=3294521 http://my.oschina.net/goldenshaw/blog?catalog= ...
- apache服务器php程序
1.全是.php结尾的.如何首页是index 2.安装完apache,如果输入 http://localhost:50/ 若出现 it works ,代表apache运作正常
- eclipse快速查找一个变量、方法或者类被引用的地方
最近不停debug,拿到一个变量之后总是要先概览一下才好下手,之前一直用Ctrl+F来做,太麻烦.今天查了下eclipse使用,发现有快捷键,使用方法: 先双击要查看的变量.方法或者类,使之被选中,然 ...
- RedHat7安装Nginx及第三方模块
编译安装Nginx 先安装编译过程中所需依赖包# yum -y install gcc pcre-devel openssl-devel zlib-devel jemalloc(更好的内存管理)# w ...
- node安装 教程 + git初步
我的系统是win8.1 64位 这个是对应的安装包:http://files.cnblogs.com/files/zxyun/node-v0.12.5-x64.zip 安装中有不懂可以参考下面的两 ...
- 在picture library中取某一图片的大图、小图
public static string GetPicThumbnail(SPFile file, string type) { string thumbnail = "" ...
- SQL server 跨库插入数据
1.INSERT INTO SELECT语句 语句形式为: Insert into Table2(field1,field2,...) select value1,value2,... from Ta ...
- ROW_NUMBER () 与 PARTITION组合拳
--在一个Book表里面里有字段AuthorID与Author表关联,现在要求按PublishDate字段倒序排列,列出每个作者的前五本书.要求有没有一条语句搞定的--可用游标或者临时表--最好解决方 ...
- hadoop_并行写操作思路_2
如果想实现将 Client端的 File并行写入到 各个Datanode中, 首先, 应该修改的是,DistributedFileSystem中的create方法, 在create 内部调用FSNam ...