#include <string.h>
#include "mime.h" static STR_MIME_MAP mime_map[]= { MIME_MAP(MIME_STR_GEN) }; void get_mime_type(const char* filename, EN_MIME_TYPE* filetype)
{
int i =;
for(i=; i<= MIME_ELSE; i++)
{
if(strstr(filename, mime_map[i].extension))
{
*filetype = (EN_MIME_TYPE)i;
break;
}
if( i == MIME_ELSE)
*filetype = MIME_ELSE;
} } char* get_resp_type(EN_MIME_TYPE filetype)
{
if(filetype > MIME_ELSE || filetype < )
return NULL; return mime_map[filetype].mimetype;
}
#ifndef __MIME__H
#define __MIME__H #define MIME_MAP(xx)\
xx(HTML, ".html", "text/html\n")\
xx(HTM, ".htm", "text/html\n")\
xx(XML, ".xml", "text/xml\n")\
xx(IMAGE_GIF, ".gif", "image/gif\n")\
xx(IMAGE_JPG, ".jpg", "image/jpeg\n")\
xx(IMAGE_PNG, ".png", "image/png\n")\
xx(TEXT, ".txt", "text/html\n")\
xx(MP3, ".mp3", "audio/x-mpeg\n")\
xx(ELSE, "*", "text/plain\n")\ #define MIME_ENUM_GEN(n, s, t) MIME_##n, #define MIME_STR_GEN(n, s, t) {MIME_##n, s, t}, typedef enum en_mine_type
{
MIME_MAP(MIME_ENUM_GEN)
}EN_MIME_TYPE; typedef struct str_mime_map
{
EN_MIME_TYPE entype;
char* extension;
char* mimetype;
}STR_MIME_MAP; void get_mime_type(const char* filename, EN_MIME_TYPE* filetype); char* get_resp_type(EN_MIME_TYPE filetype);
//typedef struct str_mime_map STR_MIME_MAP; #endif

http server v0.1_mime.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_parse.c

    #include <stdio.h> #include <string.h> #include <stdlib.h> #include "mime.h&q ...

  4. http server v0.1_http_webapp.c

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

  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. [D3 + AngularJS] 15. Create a D3 Chart as an Angular Directive

    Integrating D3 with Angular can be very simple. In this lesson, you will learn basic integration as ...

  2. redis持久化和常见故障

    https://segmentfault.com/a/1190000004135982 redis 主从复制 Redis主从复制的原理 当建立主从关系时,slave配置slaveof <mast ...

  3. mysql日期时间函数2

    win7可以设定每周从哪一天开始,win2003等不能方便的修改.有的是周日开始,有的是周一开始.而工作中有的时候每周是从周六开始算的,有些数据需要按周统计,那么那种方式比较好呢?   通过下面的研究 ...

  4. CGI与FastCGI 转

    CGI与FastCGI 当我们在谈到cgi的时候,我们在讨论什么 最早的Web服务器简单地响应浏览器发来的HTTP请求,并将存储在服务器上的HTML文件返回给浏览器,也就是静态html.事物总是不 断 ...

  5. hadoop错误FATAL org.apache.hadoop.hdfs.server.namenode.NameNode Exception in namenode join java.io.IOException There appears to be a gap in the edit log

    错误: FATAL org.apache.hadoop.hdfs.server.namenode.NameNode Exception in namenode join java.io.IOExcep ...

  6. MVC Ajax 提交是防止SCRF攻击

    //在View中 <script type="text/javascript"> @functions{ public string ToKenHeaderValue( ...

  7. 大数据应用:五大地区喜新厌旧游戏APP类别之比较与分析

    今天,我们来分享点不一样的资讯.....游戏APP之喜新厌旧排行榜!! 前阵子笔者开发了一套系统可以用来收集亚洲五大地区上架APP的每日排名信息,希望观察出五大地区在APP上的喜好和使用程度之间的相异 ...

  8. Js 命名空间注册方法

    MyApp = { namespace: function () { var a = arguments, o = null, i, j, d, rt; for (i = 0; i < a.le ...

  9. Maven3(笔记二)

    笔记本二   在Eclipse 中使用Maven 第一节:m2eclipse 插件安装 打开Eclipse,点击菜单Help - > Install New Software 点击Add 按钮N ...

  10. tomcat上servlet程序的配置与处理servlet请求过程

    手动配置: tomcat服务器下web项目的基本目录结构 |-tomcat根目录 |-webapps |-WebRoot : web应用的根目录 |-静态资源(html+css+js+image+ve ...