#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. http://poj.org/problem?id=2253

    floyd的应用求每条路径两点之间最大距离的最小值 #include <iostream> #include <cstdio> #include <algorithm&g ...

  2. CocoaPods 原理分享及遇到的问题改进

    cocoapods 原理分享及问题阐述 cocoapods 管理私有工程,需要两个git 仓库, repo 仓库,保存podspec 文件,告诉我们项目从哪来, 项目 仓库,保存工程文件,告诉我们引用 ...

  3. android应用一(调用WebServices)

    搞了一个月的android,现学现卖,终于还是搞完了,停下来,整理思路,写写记录吧. 我们知道android访问远程数据库主要有两种协议,一种是SOAP,另外一种就是HTTP.而我们再看看WebSer ...

  4. SQL删除重复行和查询所有大于某成绩的语句分析

    有这样一个题,用一条SQL语句 查询出每门课都大于80分的学生姓名. 下面是表 分析,查询每门课程都大于80的学生.SELECT DISTINCT name FROM dbo.student WHER ...

  5. [PDF] PDFOperation--C#PDF文件操作帮助类 (转载)

    点击下载 PDFOperation.rar 这个类是关于PDFOperation的帮助类,主要是实现C#PDF的文件操作,具体实现功能如下1.构造函数2.私有字段3.设置字体4.设置页面大小5.实例化 ...

  6. 从腾讯QQ升级游戏之“快速加入游戏”功能的实现缺陷看C/S之间如何正确分配相关协作

    转载:http://space.itpub.net/17007506/viewspace-615570 笔者在闲暇时,偶尔会登录腾讯QQGame玩玩升级游戏.这确实是一款非常优秀的软件作品,腾讯的开发 ...

  7. 深入探讨C#中Socket一次性搞定消息发送

    转载自:http://tech.chinaunix.net/a2010/0909/1101/000001101396.shtml     [IT168 技术文档]最近浏览了几篇有关Socket发送消息 ...

  8. 调用支付宝接口Android客户端没有支付宝APP的情况下解决无法调用支付宝页面的问题

    这几天一直研究支付宝接口调用,因为当前应用中需要调用支付宝接口作移动支付. 遇到一个问题困扰几天,就是当我们的手机端未安装支付宝APP的时候,需要在自己应用中调用支付宝的登陆网页进行支付.我是Andr ...

  9. javascript类继承系列一

    js中没有提供类(class,抽象类,接口等高级的抽象),可以用new,但new的function的对象,构造器 但在js中可以通过function来模拟类的一些特性function fun_name ...

  10. 使用dojo遮罩加载进度。

    使用dojox.widget.Standby来实现类似视频缓冲加载时候转圈的效果.