OSDN Git Service

add mimetype
authornyatla <nyatla@47198e57-cb75-475f-84c4-a814cd6f29e0>
Tue, 16 Apr 2013 13:03:39 +0000 (13:03 +0000)
committernyatla <nyatla@47198e57-cb75-475f-84c4-a814cd6f29e0>
Tue, 16 Apr 2013 13:03:39 +0000 (13:03 +0000)
bugfix cHttpStreamが64KB以上の非chunk転送が出来なかった問題を修正

git-svn-id: http://svn.osdn.jp/svnroot/mimic/trunk@216 47198e57-cb75-475f-84c4-a814cd6f29e0

lib/src/http/NyLPC_cHttpStream.c
lib/src/http/NyLPC_cMimeType.c [new file with mode: 0644]
lib/src/http/NyLPC_cMimeType.h [new file with mode: 0644]

index 7512324..2acfc58 100644 (file)
@@ -140,12 +140,9 @@ static NyLPC_TBool write_func(void* i_inst,const void* i_data,NyLPC_TInt32 i_len
 {\r
        NyLPC_TcHttpStream_t* inst=(NyLPC_TcHttpStream_t*)i_inst;\r
        NyLPC_TUInt16 s,free_size;\r
-       NyLPC_TUInt16 l;\r
+       NyLPC_TUInt32 l;\r
        const char* src=(const char*)i_data;\r
-       l=(NyLPC_TUInt16)(i_length<0?strlen(src):i_length);\r
-       if(l>=NyLPC_TUInt16_MAX){\r
-               return NyLPC_TBool_FALSE;\r
-       }\r
+       l=(i_length<0?strlen(src):i_length);\r
        while(l>0){\r
                //送信バッファがNULLなら、割り当て。\r
                if(inst->txb==NULL){\r
@@ -164,7 +161,7 @@ static NyLPC_TBool write_func(void* i_inst,const void* i_data,NyLPC_TInt32 i_len
                }\r
                //書き込み可能サイズの計算\r
                free_size=inst->txb_size-inst->tx_len;\r
-               if(free_size>l){\r
+               if((NyLPC_TInt32)free_size>l){\r
                        //書き込み可能サイズがi_length未満なら、バッファに貯めるだけ。\r
                        memcpy(inst->txb+inst->tx_len,src,l);\r
                        inst->tx_len+=(NyLPC_TUInt16)l;\r
diff --git a/lib/src/http/NyLPC_cMimeType.c b/lib/src/http/NyLPC_cMimeType.c
new file mode 100644 (file)
index 0000000..e695ee0
--- /dev/null
@@ -0,0 +1,36 @@
+#include <stdio.h>\r
+#include "NyLPC_cMimeType.h"\r
+struct TMimeTypeTable{\r
+       const char* ext;\r
+       const char* mimetype;\r
+};\r
+const static struct TMimeTypeTable table[]=\r
+{\r
+       {"zip" ,"application/zip"},\r
+       {"js"  ,"application/x-javascript"},\r
+       {"txt" ,"text/plain"},\r
+       {"html","text/html"},\r
+       {"htm","text/html"},\r
+       {"css" ,"text/css"},\r
+       {"jpeg","image/jpeg"},\r
+       {"jpg" ,"image/jpeg"},\r
+       {"png" ,"image/png"},\r
+       {"gif" ,"image/gif"},\r
+       {NULL,NULL}\r
+};\r
+const static char* default_mimetype="application/octet-stream";\r
+\r
+const char* NyLPC_cMiMeType_getFileName2MimeType(const char* i_file_name)\r
+{\r
+       int i;\r
+       const char* p=strrchr(i_file_name,'.');\r
+       if(p==NULL){\r
+               return default_mimetype;\r
+       }\r
+       for(i=0;table[i].ext!=NULL;i++){\r
+               if(strcmp(table[i].ext,p+1)==0){\r
+                       return table[i].mimetype;\r
+               }\r
+       }\r
+       return default_mimetype;\r
+}\r
diff --git a/lib/src/http/NyLPC_cMimeType.h b/lib/src/http/NyLPC_cMimeType.h
new file mode 100644 (file)
index 0000000..2e06abb
--- /dev/null
@@ -0,0 +1,45 @@
+/*********************************************************************************\r
+ * PROJECT: MiMic\r
+ * --------------------------------------------------------------------------------\r
+ *\r
+ * This file is part of MiMic\r
+ * Copyright (C)2011 Ryo Iizuka\r
+ *\r
+ * MiMic is free software: you can redistribute it and/or modify\r
+ * it under the terms of the GNU Lesser General Public License as published\r
+ * by the Free Software Foundation, either version 3 of the License, or\r
+ * (at your option) any later version.\r
+ *\r
+ * This program is distributed in the hope that it will be useful,\r
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
+ * GNU General Public License for more details.\r
+ *\r
+ * You should have received a copy of the GNU Lesser General Public License\r
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.\r
+ *\r
+ * For further information please contact.\r
+ *     http://nyatla.jp/\r
+ *     <airmail(at)ebony.plala.or.jp> or <nyatla(at)nyatla.jp>\r
+ *\r
+ *********************************************************************************/\r
+#ifndef NyLPC_TcMimeType_H_\r
+#define NyLPC_TcMimeType_H_\r
+\r
+/**********************************************************************\r
+ *\r
+ * NyLPC_TiHttpPtrStream class\r
+ *\r
+ **********************************************************************/\r
+#include "NyLPC_stdlib.h"\r
+\r
+#ifdef __cplusplus\r
+extern "C" {\r
+#endif /* __cplusplus */\r
+const char* NyLPC_cMiMeType_getFileName2MimeType(const char* i_file_name);\r
+\r
+#ifdef __cplusplus\r
+}\r
+#endif /* __cplusplus */\r
+\r
+#endif\r