#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. FontCombobox 和FontSizeCombobox

    附件:http://files.cnblogs.com/xe2011/WindowsFormsFontCombox.rar 自定义组件字体组合框 自定义组件字体组合框如何使用 自定义组件字体大小组合框 ...

  2. Java为何大行其道

    Java为何大行其道 --专訪传智播客冯威老师 冯威老师,多年来一直从事软件开发和教学工作.先后担任过项目经理.软件架构师.软件开发project师.系统架构师.讲师等.具备丰富的软件开发经验和教学经 ...

  3. Day02 - Python 基本数据类型

    1 基本数据类型 Python有五个标准的数据类型: Numbers(数字) String(字符串) List(列表) Tuple(元组) Dictionary(字典) 1.1 数字 数字数据类型用于 ...

  4. http 与https 安全链接

    安全连接 Web应用最常见的用途之一是电子商务,可以利用Web服务器端程序使人们能够网络购物,需要指出一点是,缺省情况下,通过Internet发送信息是不安全的,如果某人碰巧截获了你发给朋友的一则消息 ...

  5. Java基础知识强化之集合框架笔记62:Map集合之HashMap嵌套HashMap

    1. HashMap嵌套HashMap  传智播客          jc    基础班                      陈玉楼  20                      高跃   ...

  6. android 中 ColorDrawable dw = new ColorDrawable(0x3ccccccc),关于颜色定义的总结

    android 中  ColorDrawable dw = new ColorDrawable(0x3ccccccc),关于颜色定义的总结 0x3ccccccc 拆分开来 0x-3c-cccccc   ...

  7. PHP表单验证内容是否为空

    内容为空效果图为: 填写内容效果图: 下面是验证程序的代码: <!doctype html> <html> <head> <meta http-equiv=& ...

  8. HTML+CSS基础学习笔记(8)

    一.水平居中设置--行内元素 如果设置元素为文本.图片等行内元素时,水平居中是通过给父元素设置text-align:center来实现的 二.水平居中设置 --定宽块状元素 #当被设置元素为块状元素时 ...

  9. Spring处理id相同的bean

    http://www.360doc.com/content/13/1018/05/41237_322247510.shtml(应该可以解决) http://www.2cto.com/kf/201601 ...

  10. (八)Struts2 文件上传和下载

    所有的学习我们必须先搭建好Struts2的环境(1.导入对应的jar包,2.web.xml,3.struts.xml) 第一节:Struts2 文件上传 Struts2 文件上传基于Struts2 拦 ...