#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. UVa 872 - Ordering 输出全拓扑排序

    本题要求输出所有拓扑排序的序列. 还好本题的数据量不是非常大.限制在26个大写英文字母,故此能够使用递归法输出. 这个递归输出所有解在Leetcode非常多这种题目的,不小心的话,还是非常难调试的. ...

  2. 部分 CM11 系统 Android 平板执行植物大战僵尸 2 黑屏的解决的方法

    原文 http://forum.xda-developers.com/showthread.php?t=2755197 部分 CM11 系统的 Android 平板(比如三星 GT-P5110 )执行 ...

  3. Android开发:如何安全的中止一个自定义线程Thread

    http://blog.csdn.net/yanzi1225627/article/details/8582078 经研究,我推荐这种写法: /*自定义线程*/ class MyThread impl ...

  4. 传输层:TCP UDP SCTP

    总图 虽然协议族被称为“TCP/IP”,但除了TCP和IP这两个主要协议外,还有许多其他成员.图2-1展示了这些协议的概况. 图2-1中同时展示了IPV4和IPV6.从右向左看该图,最右边的5个网络应 ...

  5. 项目FAQ

    报错: Conversion from String Literal to Char* is deprecated http://stackoverflow.com/questions/1369030 ...

  6. Performance Tuning of Spring/Hibernate Applications---reference

    http://java.dzone.com/articles/performance-tuning For most typical Spring/Hibernate enterprise appli ...

  7. android打包签名介绍

    Keytool 是一个有效的安全钥匙和证书的管理工具. Java 中的 keytool.exe (位于 JDK\Bin 目录下)可以用来创建数字证书,所有的数字证书是以一条一条(采用别名区别)的形式存 ...

  8. ASP.NET 资料下载

    public void downloadfile(string s_fileName) { HttpContext.Current.Response.ContentType = "appli ...

  9. 高效删除 ListItem

    The most efficient way to a lot of transaction in SharePoint is using of SPWeb.ProcessBatchData meth ...

  10. 整理收藏一份PHP高级工程师的笔试…

    注:本文转自 http://www.icultivator.com/p/5535.html 注:本文转自 http://www.yiichina.com/tutorial/57 整理了一份PHP高级工 ...