#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. Android-用webservice连接sqlserver数据库

    以前做的东西,只要用数据库的都是在项目里自己重新做一份数据.但是这种方法是很不可取的,首先,手机内存不会很大,把数据表建在项目里无疑又增大了程序.这样一来手机的运行速度可想而知.其次,数据大的时候还是 ...

  2. 使用 OpenSSL API 进行安全编程

    创建基本的安全连接和非安全连接 Kenneth Ballard ( kenneth.ballard@ptk.org), 自由程序员 Kenneth 是 Peru State College(位于 Pe ...

  3. binary heap

    In computer science, a heap is a specialized tree-based data structure that satisfies the heap prope ...

  4. ubuntu权限管理常用命令 分类: linux ubuntu 学习笔记 2015-07-05 14:15 77人阅读 评论(0) 收藏

    1.chmod 第一种方式 chomd [{ugoa}{+-=}{rwx}] [文件或者目录] u 代表该文件所属用户 g 代表该文件所属用户组 o 代表访客 a 代表所有用户 +-=分别表示增加权限 ...

  5. Android(java)学习笔记185:xml文件生成

    1.xml文件: 用元素描述数据,跨平台. 2.利用传统的方式创建xml文件,下面是一个案例: 设计思路:建立一个学生管理系统,创建xml文件保存学生信息: (1)首先是布局文件activity_ma ...

  6. jQuery Validate 插件

    >>>>>>>>>>>>>>>>>>>>>>>>> ...

  7. Bootstrap后台使用问题汇总(一)

    第一次自己汇总写博客啊,不懂规矩,大家包涵~~ 最近进行的项目中需要一个后台,于是在网上Down了许多Bootstrap后台源码.精挑细选决定用“ACE后台管理系统”(因为是中文的,英文三级狗的小鹿还 ...

  8. BufferedWriter和BufferedReader使用方法

    /**  * 上传文件  * @param file  * @param path  * @param fileName  * @throws IOException  */ public void ...

  9. 邓白氏编码(duns number)申请入口的路径-苹果开发者申请必

    http://tieba.baidu.com/p/3861287522 这个网址有详细的介绍

  10. JavaScript 快速入门回顾

    数据类型Number JavaScript不区分整数和浮点数,统一用Number表示,以下都是合法的Number类型: 123; // 整数123 0.456; // 浮点数0.456 1.2345e ...