#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. 利用京东云擎架设免费Wordpress 博客(git方式)

    京东云擎(JAE)是京东推出的一款公有云产品,是京东云平台生态圈的核心组成部分.与百度的BAE.新浪的SAE同样.可是JAE刚上线不久,可能非常多人都还没听说过或不太了解.我尝试在JAE安装WordP ...

  2. memcpy的使用方法总结

    1.memcpy 函数用于 把资源内存(src所指向的内存区域) 复制到目标内存(dest所指向的内存区域):拷贝多少个?有一个size变量控制拷贝的字节数:函数原型:void *memcpy(voi ...

  3. pip安装 MySQLDb 和 Django

    wget "https://pypi.python.org/packages/source/p/pip/pip-1.5.4.tar.gz#md5=834b2904f92d46aaa33326 ...

  4. hadoop错误ERROR namenode.NameNode (NameNode.javamain(1657)) - Failed to start namenode java.net.BindException:Port in use:host1:50070

    解决方法: 1.通过lsof -i:50070(lsof可以通过yum install lsof安装)查看,发现是mysql被占用了 2.修改mysql端口 从/usr/share/mysql/my- ...

  5. xmemcached user guide --存档

    XMemcached Introduction XMemcached is a new java memcached client. Maybe you don't know "memcac ...

  6. 怎样查看MySql数据库物理文件存放位置

    想导出mysql中的数据库文件,死活找不到,网上说在配置文件中有路径,可是我打开我的配置文件,里边的代码全都是注释掉的,没有一句有用的.后来在某一论坛上找到解决方法了,记录下来. 使用如下命令: my ...

  7. System Operations on AWS - Lab 3W - Managing Storage (Windows)

    创建一个名叫Processor的EC2实例,登陆到CommandHost实例,通过AWS CLI对Processor实例的EBS卷做snapshot,设置周期性snapshot的计划任务, 登陆到Pr ...

  8. ADO简单封装(MFC)

    简单封装了一下,不是很严谨. /************************************************************************/ /* INSTRUC ...

  9. android下4G上网卡

    架构: APP Call Trachker/SMS Dispatch/Service Tracker/Data Tracker ------------------------------------ ...

  10. Js的History对象

    History回顾 window.history表示window对象的历史记录 window.history的简单回顾 历史记录中前进/后退,移动到指定历史记录点 window.history.bac ...