#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的更多相关文章

  1. http server v0.1_http_reponse.c

    #include <string.h> #include <sys/stat.h> #include <sys/mman.h> #include <fcntl ...

  2. http server v0.1_http_server.c

    /**************************************************************** filename: http_server.c author: xx ...

  3. http server v0.1_http_webapp.c

    #include <stdio.h> #include <stdlib.h> #include <string.h> #include <unistd.h&g ...

  4. http server v0.1_mime.c

    #include <string.h> #include "mime.h" static STR_MIME_MAP mime_map[]= { MIME_MAP(MIM ...

  5. 用FileZilla Server开FTP

    FileZilla(教程)是经典的开源FTP解决方案,包括FileZilla客户端和FileZilla Server.其中,FileZilla Server的功能比起商业软件FTP Serv-U毫不逊 ...

  6. DNS隧道之DNS2TCP实现——dns2tcpc必须带server IP才可以,此外ssh可以穿过墙的,设置代理上网

    我自己的命令: server端: dns2tcpd -F -d 1 -f ./dns2tcpd.conf 输出: 09:08:59 : Debug options.c:97 Add resource ...

  7. docker 下 安装rancher 笔记

    sudo yum update 更新系统环境 curl -sSL https://get.docker.com/ | sh 安装最新docker版本 systemctl start docker.se ...

  8. 容器基础(七): 使用docker compose部署程序

    配置 在上一节的基础上,  增加如下的docker-compose.yml文件, 然后用docker-compose up命令启动容器进行部署: version: " services: s ...

  9. 容器基础(八): 使用docker swarm部署程序

    环境 基于上一节的env/server:v0.1, env/worker:v0.1镜像, 在基于debian8.2的两台机器上测试部署docker swarm. docker service部署 ➜ ...

随机推荐

  1. hdu 1317 XYZZY【Bellheman_ford 判断正环小应用】

    链接: http://acm.hdu.edu.cn/showproblem.php?pid=1317 http://acm.hust.edu.cn/vjudge/contest/view.action ...

  2. allocator例子

    13.39 编写自己的StrVec,包括自己版本的reserve.capacity和resize. 13.40 为StrVec添加一个构造函数,它接受一个initializer_list<str ...

  3. JavaScript判断数据类型总结

    最近做项目中遇到了一些关于javascript数据类型的判断处理,上网找了一下资料,并且亲自验证了各种数据类型的判断网页特效,在此做一个总结吧! 一.JS中的数据类型  1.数值型(Number):包 ...

  4. WPF加载Winform窗体时 报错:子控件不能为顶级窗体

    一.wpf项目中引用WindowsFormsIntegration和System.Windows.Forms 二.Form1.Designer.cs 的 partial class Form1 设置为 ...

  5. 加密算法 DES 3DES RSA AES 简介

    数据加密的基本过程就是对原来为明文的文件或数据按某种算法进行处理,使其成为不可读的一段代码,通常称为[密文],使其只能在输入相应的[密钥]之后才能显示出本来内容,通过这样的途径来达到保护数据不被非法人 ...

  6. CS=0xFFFF IP=0x0000与CS=F000 IP=FFF0

    计算机自动上电后,有些书上说CS=0xFFFF IP=0x0000,例如linux内核设计的艺术(第三版).也有一些书说CS=F000 IP=FFF0,例如赵炯的linux内核完全注释. 其实并不是说 ...

  7. 傻瓜式理解递归之php递归

    写程序这么久了,有时候别人会问道一些算法比如排序啊,递归啊,总是不知道该怎么去说,今天就来整理一下,让更多的人去傻瓜式的理解递归.递归在网络上有很多定义,但有这么一句话听的最多:递归就是自己调用自己! ...

  8. 我对WindowsPhone8的一些反大众看法.

    最近看到网上好多人抱怨wp8的系统设计.我个人有一些观点.实在是不吐不快! 1.为什么系统没有重力感应开关.   答:因为这部分开关功能不是wp8所必备的.只是APP的一个功能.所以.错误在APP上因 ...

  9. SQL Prompt Snippet Manager 妙用

    SQL Prompt有一个很好用的工具叫Snippet Manager,SQL脚本片段管理器. 使用它可以快速的键入一段脚本,如输入ii+Tab,即可变成INSERT INTO 同理,我们可以定义一些 ...

  10. ubuntu 13.04 xrdp 远程桌面连接问题[转载]

    本人ubuntu12.04,遇到了同样的问题,用一下方法解决了,mark一下. ubuntu 13.04 xrdp 远程桌面连接问题. win 7 远程桌面连接 ubuntu desktop 有几种办 ...