From caa6f653041fd6d416abc0b6f6e2a1aeb4fa1656 Mon Sep 17 00:00:00 2001 From: nyatla Date: Tue, 16 Apr 2013 13:03:39 +0000 Subject: [PATCH] =?utf8?q?add=20mimetype=20bugfix=20cHttpStream=E3=81=8C64?= =?utf8?q?KB=E4=BB=A5=E4=B8=8A=E3=81=AE=E9=9D=9Echunk=E8=BB=A2=E9=80=81?= =?utf8?q?=E3=81=8C=E5=87=BA=E6=9D=A5=E3=81=AA=E3=81=8B=E3=81=A3=E3=81=9F?= =?utf8?q?=E5=95=8F=E9=A1=8C=E3=82=92=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit git-svn-id: http://svn.osdn.jp/svnroot/mimic/trunk@216 47198e57-cb75-475f-84c4-a814cd6f29e0 --- lib/src/http/NyLPC_cHttpStream.c | 9 +++----- lib/src/http/NyLPC_cMimeType.c | 36 ++++++++++++++++++++++++++++++++ lib/src/http/NyLPC_cMimeType.h | 45 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 84 insertions(+), 6 deletions(-) create mode 100644 lib/src/http/NyLPC_cMimeType.c create mode 100644 lib/src/http/NyLPC_cMimeType.h diff --git a/lib/src/http/NyLPC_cHttpStream.c b/lib/src/http/NyLPC_cHttpStream.c index 7512324..2acfc58 100644 --- a/lib/src/http/NyLPC_cHttpStream.c +++ b/lib/src/http/NyLPC_cHttpStream.c @@ -140,12 +140,9 @@ static NyLPC_TBool write_func(void* i_inst,const void* i_data,NyLPC_TInt32 i_len { NyLPC_TcHttpStream_t* inst=(NyLPC_TcHttpStream_t*)i_inst; NyLPC_TUInt16 s,free_size; - NyLPC_TUInt16 l; + NyLPC_TUInt32 l; const char* src=(const char*)i_data; - l=(NyLPC_TUInt16)(i_length<0?strlen(src):i_length); - if(l>=NyLPC_TUInt16_MAX){ - return NyLPC_TBool_FALSE; - } + l=(i_length<0?strlen(src):i_length); while(l>0){ //送信バッファがNULLなら、割り当て。 if(inst->txb==NULL){ @@ -164,7 +161,7 @@ static NyLPC_TBool write_func(void* i_inst,const void* i_data,NyLPC_TInt32 i_len } //書き込み可能サイズの計算 free_size=inst->txb_size-inst->tx_len; - if(free_size>l){ + if((NyLPC_TInt32)free_size>l){ //書き込み可能サイズがi_length未満なら、バッファに貯めるだけ。 memcpy(inst->txb+inst->tx_len,src,l); inst->tx_len+=(NyLPC_TUInt16)l; diff --git a/lib/src/http/NyLPC_cMimeType.c b/lib/src/http/NyLPC_cMimeType.c new file mode 100644 index 0000000..e695ee0 --- /dev/null +++ b/lib/src/http/NyLPC_cMimeType.c @@ -0,0 +1,36 @@ +#include +#include "NyLPC_cMimeType.h" +struct TMimeTypeTable{ + const char* ext; + const char* mimetype; +}; +const static struct TMimeTypeTable table[]= +{ + {"zip" ,"application/zip"}, + {"js" ,"application/x-javascript"}, + {"txt" ,"text/plain"}, + {"html","text/html"}, + {"htm","text/html"}, + {"css" ,"text/css"}, + {"jpeg","image/jpeg"}, + {"jpg" ,"image/jpeg"}, + {"png" ,"image/png"}, + {"gif" ,"image/gif"}, + {NULL,NULL} +}; +const static char* default_mimetype="application/octet-stream"; + +const char* NyLPC_cMiMeType_getFileName2MimeType(const char* i_file_name) +{ + int i; + const char* p=strrchr(i_file_name,'.'); + if(p==NULL){ + return default_mimetype; + } + for(i=0;table[i].ext!=NULL;i++){ + if(strcmp(table[i].ext,p+1)==0){ + return table[i].mimetype; + } + } + return default_mimetype; +} diff --git a/lib/src/http/NyLPC_cMimeType.h b/lib/src/http/NyLPC_cMimeType.h new file mode 100644 index 0000000..2e06abb --- /dev/null +++ b/lib/src/http/NyLPC_cMimeType.h @@ -0,0 +1,45 @@ +/********************************************************************************* + * PROJECT: MiMic + * -------------------------------------------------------------------------------- + * + * This file is part of MiMic + * Copyright (C)2011 Ryo Iizuka + * + * MiMic is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published + * by the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . + * + * For further information please contact. + * http://nyatla.jp/ + * or + * + *********************************************************************************/ +#ifndef NyLPC_TcMimeType_H_ +#define NyLPC_TcMimeType_H_ + +/********************************************************************** + * + * NyLPC_TiHttpPtrStream class + * + **********************************************************************/ +#include "NyLPC_stdlib.h" + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ +const char* NyLPC_cMiMeType_getFileName2MimeType(const char* i_file_name); + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + +#endif -- 2.11.0