OSDN Git Service

backup目的。動作しない。
authornyatla <nyatla@47198e57-cb75-475f-84c4-a814cd6f29e0>
Wed, 27 Feb 2013 12:07:39 +0000 (12:07 +0000)
committernyatla <nyatla@47198e57-cb75-475f-84c4-a814cd6f29e0>
Wed, 27 Feb 2013 12:07:39 +0000 (12:07 +0000)
httpdのモジュール化に伴う変更

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

16 files changed:
lib/src/api/NyLPC_cHttpRequestPrefixParser.h
lib/src/api/NyLPC_cHttpd.h
lib/src/api/NyLPC_cHttpdConnection.h
lib/src/api/NyLPC_cHttpdThread.h
lib/src/api/NyLPC_cModShortUrl.h
lib/src/api/NyLPC_cNet.h
lib/src/api/NyLPC_cNetConfig.h
lib/src/http/NyLPC_cHttpBasicHeaderParser.c
lib/src/http/NyLPC_cHttpBodyWriter.c
lib/src/http/NyLPC_cHttpBodyWriter.h
lib/src/http/NyLPC_cHttpHeaderWriter.c
lib/src/http/NyLPC_cHttpHeaderWriter.h
lib/src/http/NyLPC_cHttpNullRequestHeaderParser.c [new file with mode: 0644]
lib/src/http/NyLPC_cHttpNullRequestHeaderParser.h [new file with mode: 0644]
lib/src/http/NyLPC_cHttpShortRequestHeaderParser.h
projects/example/sample.net.simplehttpd/src/sketch.c

index 2590b1a..13e67d2 100644 (file)
@@ -48,7 +48,6 @@ void NyLPC_cHttpRequestPrefixParser_initialize(NyLPC_TcHttpRequestPrefixParser_t
  * THttpHeaderPrefix._urlに最大TcHttpRequestPrefixParser_MAX_URL_LEN文字のPath文字列を取得する。\r
  * 最大文字数よりも少なければ全てのPath文字列を蓄積し、多ければ先頭だけを蓄積する。\r
  * @return\r
- * HTTPレスポンスコード。200で成功。\r
  */\r
 NyLPC_TBool NyLPC_cHttpRequestPrefixParser_parse(NyLPC_TcHttpRequestPrefixParser_t* i_inst,NyLPC_TcHttpStream_t* i_stream);\r
 \r
index 643eef8..2ef41c8 100644 (file)
@@ -1,8 +1,42 @@
-#ifndef NYLPC_CHTTPD_H_\r
-#define NYLPC_CHTTPD_H_\r
 #include "NyLPC_stdlib.h"\r
 #include "NyLPC_uipService.h"\r
 #include "NyLPC_cNetConfig.h"\r
 #include "NyLPC_cHttpdThread.h"\r
 \r
+#ifndef NYLPC_CHTTPD_H_\r
+#define NYLPC_CHTTPD_H_\r
+\r
+\r
+\r
+#define NyLPC_cNet_NUMBER_OF_THREAD 2\r
+\r
+typedef void (*NyLPC_TcHttpd_onRequest)(NyLPC_TcHttpdConnection_t* i_inst);\r
+\r
+struct NyLPC_TcHttpd\r
+{\r
+       struct{\r
+               NyLPC_TcHttpd_onRequest _handler;\r
+       }function;\r
+       NyLPC_TcTcpListener_t _listener;\r
+       NyLPC_TcHttpdThread_t _thread[NyLPC_cNet_NUMBER_OF_THREAD];\r
+       NyLPC_TUInt16 _num_of_active_connection;\r
+};\r
+\r
+\r
+void NyLPC_cHttpd_initialize(NyLPC_TcHttpd_t* i_inst,NyLPC_TUInt16 i_port_number);\r
+\r
+void NyLPC_cHttpd_loop(NyLPC_TcHttpd_t* i_inst);\r
+\r
+//////\r
+//protected\r
+//////\r
+\r
+#define NyLPC_cHttpd_getNumOfConnection(i_inst) ((i_inst)->_num_of_active_connection)\r
+\r
+NyLPC_TUInt16 NyLPC_cHttpd_incNumOfConnection(NyLPC_TcHttpd_t* i_inst);\r
+\r
+NyLPC_TUInt16 NyLPC_cHttpd_decNumOfConnection(NyLPC_TcHttpd_t* i_inst);\r
+\r
+\r
+\r
 #endif /* NYLPC_CHTTPD_H_ */\r
index c6b9277..0d6dc24 100644 (file)
@@ -11,6 +11,7 @@
 #include "NyLPC_uipService.h"\r
 #include "NyLPC_cHttpRequestPrefixParser.h"\r
 \r
+\r
 /** 受信バッファのサイズ*/\r
 #define NyLPC_NyLPC_TcHttpdConnection_SIZE_OF_RX_BUF 512\r
 \r
 typedef NyLPC_TUInt8 NyLPC_TcHttpdConnection_Status;\r
 \r
 /** リクエストプレフィクスを読み出した状態*/\r
-#define NyLPC_cHttpdConnection_Status_IDLE                     0\r
+#define NyLPC_cHttpdConnection_ReqStatus_LISTEN                        0\r
+/** ACCEPT待ち*/\r
+#define NyLPC_cHttpdConnection_ReqStatus_ACCEPT                        1\r
 /** コネクションは接続済*/\r
-#define NyLPC_cHttpdConnection_Status_CONNECTED                1\r
-/**ã\80\80ã\82³ã\83\8dã\82¯ã\82·ã\83§ã\83³ã\81¯ACCEPTæ¸\88*/\r
-#define NyLPC_cHttpdConnection_Status_ACCEPTED         2\r
-/**ã\80\80ã\83ªã\82¯ã\82¨ã\82¹ã\83\88ã\83\97ã\83¬ã\83\95ã\82£ã\82¯ã\82¹ã\82\92読ã\81¿å\87ºã\81\97ã\81\9fç\8a¶æ\85\8b*/\r
-#define NyLPC_cHttpdConnection_Status_PREFETCH         3\r
-/** リクエストパース済み*/\r
-#define NyLPC_cHttpdConnection_Status_REQPARSED                4\r
+#define NyLPC_cHttpdConnection_ReqStatus_PREFETCH              2\r
+/**ã\80\80ã\83ªã\82¯ã\82¨ã\82¹ã\83\88ã\83\91ã\83¼ã\82¹å¾\85ã\81¡*/\r
+#define NyLPC_cHttpdConnection_ReqStatus_REQPARSE              3\r
+/**ã\80\80ã\83ªã\82¯ã\82¨ã\82¹ã\83\88ã\83\91ã\83¼ã\82¹æ¸\88*/\r
+#define NyLPC_cHttpdConnection_ReqStatus_END                   4\r
+\r
+\r
 /** レスポンスヘッダ送付済*/\r
-#define NyLPC_cHttpdConnection_Status_RESHEAD_SENT     5\r
+#define NyLPC_cHttpdConnection_ResStatus_HEAD   1\r
+/** レスポンスヘッダ送付済*/\r
+#define NyLPC_cHttpdConnection_ResStatus_BODY  2\r
 /** レスポンスBODY送付済*/\r
-#define NyLPC_cHttpdConnection_Status_RESBODY_SENT     6\r
-\r
+#define NyLPC_cHttpdConnection_ResStatus_CLOSED        3\r
+/** エラーが発生した。*/\r
+#define NyLPC_cHttpdConnection_ResStatus_ERROR 4\r
 \r
 \r
 typedef struct NyLPC_TcHttpdConnection NyLPC_TcHttpdConnection_t;\r
 struct NyLPC_TcHttpdConnection\r
 {\r
-       NyLPC_TUInt8 _status;\r
+       NyLPC_TUInt8 _req_status;//リクエストステータス\r
+       NyLPC_TUInt8 _res_status;//レスポンスステータス\r
+       NyLPC_TUInt8 _connection_message_mode;//COnnection:closeをヘッダに書き込むかのフラグ\r
        NyLPC_TcTcpSocket_t _socket;\r
        NyLPC_TUInt8 _rxbuf[NyLPC_NyLPC_TcHttpdConnection_SIZE_OF_RX_BUF];\r
        NyLPC_TcHttpStream_t _in_stream;\r
        NyLPC_TcHttpRequestPrefixParser_t _pparser;\r
+       union{\r
+               NyLPC_TcHttpBodyWriter_t _body_writer;\r
+               NyLPC_TcHttpHeaderWriter_t _head_writer;\r
+       };\r
 };\r
+\r
 void NyLPC_cHttpdConnection_initialize(NyLPC_TcHttpdConnection_t* i_inst);\r
 void NyLPC_cHttpdConnection_finalize(NyLPC_TcHttpdConnection_t* i_inst);\r
 \r
-/**protected */\r
+\r
+\r
 /**\r
- * listenerでConnectionのソケットに接続を待ちます。\r
+ * レスポンスヘッダを送信します。\r
  */\r
-NyLPC_TBool NyLPC_cHttpdConnection_listen(NyLPC_TcHttpdConnection_t* i_inst,NyLPC_TcTcpListener_t* i_listener);\r
+NyLPC_TBool NyLPC_cHttpdConnection_sendResponseHeader(NyLPC_TcHttpdConnection_t* i_inst,NyLPC_TUInt16 i_response_code,const NyLPC_TChar* i_content_type,const NyLPC_TChar* i_additional_header);\r
+\r
+\r
 /**\r
- * コネクションのソケットをacceptします。\r
+ * レスポンスBodyを送信します。\r
+ * 関数を実行後、_res_statusはBODYかERRORに遷移します。\r
  */\r
-NyLPC_TBool NyLPC_cHttpdConnection_accept(NyLPC_TcHttpdConnection_t* i_inst);\r
+NyLPC_TBool NyLPC_cHttpdConnection_sendResponseBody(NyLPC_TcHttpdConnection_t* i_inst,const void* i_data,NyLPC_TUInt16 i_size);\r
+\r
 /**\r
- * コネクションを閉じます。\r
+ * レスポンスBodyを書式出力して送信します。\r
+ * 関数を実行後、_res_statusはBODYかERRORに遷移します。\r
  */\r
-void NyLPC_cHttpdConnection_close(NyLPC_TcHttpdConnection_t* i_inst);\r
-\r
+NyLPC_TBool NyLPC_cHttpdConnection_sendResponseBodyF(NyLPC_TcHttpdConnection_t* i_inst,const char* i_fmt,...);\r
 \r
 \r
 \r
+/**\r
+ * コネクションのStreamを返します。\r
+ */\r
+#define NyLPC_cHttpdConnection_refStream(i_inst) (&(i_inst->_in_stream))\r
 \r
+#define NyLPC_cHttpdConnection_getStatus(i_inst) (&(i_inst->_pparser.method))\r
 \r
 \r
 #endif /* NYLPC_CHTTPDCONNECTION_H_ */\r
index f75a519..ed23e67 100644 (file)
 #include "NyLPC_cNetConfig.h"\r
 #include "NyLPC_cHttpdConnection.h"\r
 \r
+#ifndef NYLPC_CHTTPD_H_\r
+       typedef struct NyLPC_TcHttpd NyLPC_TcHttpd_t;\r
+#endif\r
+\r
 /** Httpdセッションスレッドのスタックサイズ*/\r
 #define NyLPC_TcHttpdThread_SIZE_OF_THREAD_STACK 1024\r
 \r
+\r
 /**\r
  * このクラスは、httpdのワーカースレッドです。1セッションを担当します。\r
  */\r
 typedef struct NyLPC_TcHttpdThread NyLPC_TcHttpdThread_t;\r
+\r
 struct NyLPC_TcHttpdThread\r
 {\r
        NyLPC_TcThread_t _super;\r
+       NyLPC_TcHttpd_t* _parent;\r
+       /** 関数アドレスを格納したポインタ*/\r
+       NyLPC_TcHttpdConnection_t _connection;\r
 };\r
 \r
 \r
-void NyLPC_cHttpdThread_initialize(NyLPC_TcHttpdThread_t* i_inst,NyLPC_TInt32 i_prio);\r
+void NyLPC_cHttpdThread_initialize(NyLPC_TcHttpdThread_t* i_inst,NyLPC_TcHttpd_t* i_parent,NyLPC_TInt32 i_prio);\r
 void NyLPC_cHttpdThread_finalize(NyLPC_TcHttpdThread_t* i_inst);\r
-void NyLPC_cHttpd_Thread_start(NyLPC_TcThread_t* i_inst,void* i_param);\r
+NyLPC_TBool NyLPC_cHttpdThread_start(NyLPC_TcHttpdThread_t* i_inst,NyLPC_TcTcpListener_t* i_listener);\r
 \r
 #endif /* NYLPC_TCHTTPDTHREAD_H_ */\r
index a50bec6..664f740 100644 (file)
  *     <airmail(at)ebony.plala.or.jp> or <nyatla(at)nyatla.jp>\r
  *\r
  *********************************************************************************/\r
-#ifndef NYLPC_CHTTPSHORTHTTPHEADERPARSER_H_\r
-#define NYLPC_CHTTPSHORTHTTPHEADERPARSER_H_\r
-#include "NyLPC_cHttpBasicHeaderParser.h"\r
+#ifndef NYLPC_CMODSHORTURL_H_\r
+#define NYLPC_CMODSHORTURL_H_\r
 \r
 #ifdef __cplusplus\r
 extern "C" {\r
 #endif /* __cplusplus */\r
+#include "../http/NyLPC_cHttpBasicHeaderParser.h"\r
+#include "NyLPC_cHttpdConnection.h"\r
 \r
 /**\r
  * URLが最大31文字までの、短いHttpリクエストを処理します。\r
  * このクラスは、NyLPC_TBasicHttpHeader_tにキャストできます。\r
  */\r
-typedef struct NyLPC_TcHttpShortReqestHeaderParser NyLPC_TcHttpShortRequestHeaderParser_t;\r
+typedef struct NyLPC_TcModShortUrl NyLPC_TcModShortUrl_t;\r
 \r
 \r
-struct NyLPC_THttpShortRequestHeader\r
+struct NyLPC_TcModShortUrl\r
 {\r
-       struct NyLPC_THttpBasicHeader super;\r
-       NyLPC_TChar url[32];\r
+       struct NyLPC_THttpShortRequestHeader _header;\r
 };\r
 \r
-struct NyLPC_TcHttpShortReqestHeaderParser{\r
-       NyLPC_TcHttpBasicHeaderParser_t super;\r
-       NyLPC_TUInt16 url_len;\r
-};\r
 \r
-void NyLPC_cShortUrl_initialize(NyLPC_TcHttpShortRequestHeaderParser_t* i_inst,NyLPC_cHttpdConnection* i_connection);\r
-void NyLPC_cShortUrl_finalize(NyLPC_TcHttpShortRequestHeaderParser_t* i_inst);\r
+void NyLPC_cShortUrl_initialize(NyLPC_TcModShortUrl_t* i_inst);\r
+void NyLPC_cShortUrl_finalize(NyLPC_TcModShortUrl_t* i_inst);\r
 \r
 \r
 void NyLPC_cShortUrl_getHeader();\r
index a9605b7..e48c236 100644 (file)
@@ -17,7 +17,11 @@ struct NyLPC_TcNet
        int dummy;\r
 };\r
 void NyLPC_cNet_initialize(NyLPC_TcNet_t* i_inst);\r
-void NyLPC_cNet_start(NyLPC_TcNet_t* i_inst,const NyLPC_TcNetConfig_t* i_config);\r
+/**\r
+ * @param i_ref_config\r
+ * Networkコンフィギュレーション変数。このオブジェクトはcNetをstopするまで維持すること。\r
+ */\r
+void NyLPC_cNet_start(NyLPC_TcNet_t* i_inst,const NyLPC_TcNetConfig_t* i_ref_config);\r
 \r
 \r
 #endif /* NYLPC_CNET_H_ */\r
index e4c14c0..539ba12 100644 (file)
@@ -25,17 +25,19 @@ struct NyLPC_TcNetConfig
        NyLPC_TUInt16 interface_type;\r
        /** インタフェイス層の設定*/\r
        union{\r
-               struct{\r
-                       /** Ethernet mac address */\r
-                       struct NyLPC_TEthAddr mac_addr;\r
-               }ethernet;\r
+               /** Ethernet mac address */\r
+               NyLPC_TcIPv4Config_t ethernet;\r
+//\r
+//             struct{\r
+//                     struct NyLPC_TEthAddr mac_addr;\r
+//             }ethernet2;\r
        }interface_setting;\r
-       /** ip addressの設定*/\r
-       struct{\r
-               struct NyLPC_TIPv4Addr ip;\r
-               struct NyLPC_TIPv4Addr mask;\r
-               struct NyLPC_TIPv4Addr gateway;\r
-       }ipv4;\r
+//     /** ip addressの設定*/\r
+//     struct{\r
+//             struct NyLPC_TIPv4Addr ip;\r
+//             struct NyLPC_TIPv4Addr mask;\r
+//             struct NyLPC_TIPv4Addr gateway;\r
+//     }ipv4;\r
 };\r
 \r
 /**\r
index 7cee416..eefb287 100644 (file)
@@ -152,6 +152,11 @@ NyLPC_TInt32 NyLPC_cHttpBasicHeaderParser_parseChar(NyLPC_TcHttpBasicHeaderParse
 {\r
        int i;\r
        NyLPC_TChar c;\r
+       //Errorチェック\r
+       if(NyLPC_TcHttpBasicHeaderParser_ST_ERROR==i_inst->_st)\r
+       {\r
+               return 0;\r
+       }\r
        for(i=0;i<i_size;i++){\r
                c=*(i_c+i);\r
                switch(i_inst->_st)\r
index 80fd523..073388c 100644 (file)
@@ -25,7 +25,6 @@
  *********************************************************************************/\r
 \r
 \r
-#include <stdarg.h>\r
 #include <stdlib.h>\r
 #include "NyLPC_cHttpBodyWriter.h"\r
 \r
@@ -116,6 +115,17 @@ NyLPC_TBool NyLPC_cHttpBodyWriter_format(NyLPC_TcHttpBodyWriter_t* i_inst,const
        return ret;\r
 }\r
 \r
+NyLPC_TBool NyLPC_cHttpBodyWriter_formatV(NyLPC_TcHttpBodyWriter_t* i_inst,const NyLPC_TChar* i_fmt,va_list i_args)\r
+{\r
+       NyLPC_TBool ret;\r
+       //エラー状態ならFALSE\r
+       if(i_inst->_is_error){\r
+               return NyLPC_TBool_FALSE;\r
+       }\r
+       ret=print(i_inst,i_fmt,i_args);\r
+       return ret;\r
+}\r
+\r
 #define NUM_OF_WORK 16\r
 \r
 static NyLPC_TBool print(void* i_inst,const char* i_fmt,va_list args)\r
index e0a2bb3..b9262a7 100644 (file)
@@ -29,6 +29,7 @@
 \r
 #include "NyLPC_cHttpHeaderWriter.h"\r
 #include "NyLPC_cHttpStream.h"\r
+#include <stdarg.h>\r
 \r
 #ifdef __cplusplus\r
 extern "C" {\r
@@ -49,6 +50,8 @@ void NyLPC_cHttpBodyWriter_setChunked(NyLPC_TcHttpBodyWriter_t* i_inst);
 NyLPC_TBool NyLPC_cHttpBodyWriter_write(NyLPC_TcHttpBodyWriter_t* i_inst,const void* i_buf,NyLPC_TUInt32 i_len);\r
 NyLPC_TBool NyLPC_cHttpBodyWriter_close(NyLPC_TcHttpBodyWriter_t* i_inst);\r
 NyLPC_TBool NyLPC_cHttpBodyWriter_format(NyLPC_TcHttpBodyWriter_t* i_inst,const NyLPC_TChar* i_fmt,...);\r
+NyLPC_TBool NyLPC_cHttpBodyWriter_formatV(NyLPC_TcHttpBodyWriter_t* i_inst,const NyLPC_TChar* i_fmt,va_list i_args);\r
+\r
 \r
 \r
 #ifdef __cplusplus\r
index 4454946..b25c3fa 100644 (file)
@@ -176,6 +176,7 @@ Error:
        i_inst->_is_error=NyLPC_TUInt8_FALSE;\r
        return NyLPC_TBool_FALSE;\r
 }\r
+\r
 /**\r
  * 独自定義のメッセージヘッダを記述します。\r
  */\r
@@ -200,6 +201,22 @@ Error:
        return NyLPC_TBool_FALSE;\r
 }\r
 \r
+\r
+NyLPC_TBool NyLPC_cHttpHeaderWriter_writeRawMessage(NyLPC_TcHttpHeaderWriter_t* i_inst,const NyLPC_TChar* i_additional_header)\r
+{\r
+       //エラー状態ならなにもしない。\r
+       if(i_inst->_is_error){\r
+               return NyLPC_TBool_FALSE;\r
+       }\r
+       if(!NyLPC_iHttpPtrStream_write(i_inst->_ref_stream,i_additional_header,strlen(i_additional_header))){\r
+               NyLPC_OnErrorGoto(Error);\r
+       }\r
+       return NyLPC_TBool_TRUE;\r
+Error:\r
+       i_inst->_is_error=NyLPC_TUInt8_FALSE;\r
+       return NyLPC_TBool_FALSE;\r
+}\r
+\r
 /**\r
  * Httpヘッダの書き込みを完了します。\r
  * 続けてbody転送が可能な場合は、必要に応じてエンコーディングモードを更新します。\r
index cd44455..715d01d 100644 (file)
@@ -61,6 +61,10 @@ NyLPC_TBool NyLPC_cHttpHeaderWriter_initialize(NyLPC_TcHttpHeaderWriter_t* i_ins
 \r
 NyLPC_TBool NyLPC_cHttpHeaderWriter_writeHeader(NyLPC_TcHttpHeaderWriter_t* i_inst,NyLPC_TUInt16 i_status);\r
 NyLPC_TBool NyLPC_cHttpHeaderWriter_writeMessage(NyLPC_TcHttpHeaderWriter_t* i_inst,const NyLPC_TChar* i_name,const NyLPC_TChar* i_field);\r
+/**\r
+ * \r\n区切りのメッセージをそのままヘッダに挿入します。i_additional_headerの終端は\r\nで閉じてください。\r
+ */\r
+NyLPC_TBool NyLPC_cHttpHeaderWriter_writeRawMessage(NyLPC_TcHttpHeaderWriter_t* i_inst,const NyLPC_TChar* i_additional_header);\r
 NyLPC_TBool NyLPC_cHttpHeaderWriter_close(NyLPC_TcHttpHeaderWriter_t* i_inst);\r
 void NyLPC_cHttpHeaderWriter_setContentLength(NyLPC_TcHttpHeaderWriter_t* i_inst,NyLPC_TUInt32 i_content_length);\r
 void NyLPC_cHttpHeaderWriter_setClose(NyLPC_TcHttpHeaderWriter_t* i_inst);\r
diff --git a/lib/src/http/NyLPC_cHttpNullRequestHeaderParser.c b/lib/src/http/NyLPC_cHttpNullRequestHeaderParser.c
new file mode 100644 (file)
index 0000000..cfe269a
--- /dev/null
@@ -0,0 +1,55 @@
+/*********************************************************************************\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
+#include "NyLPC_cHttpNullRequestHeaderParser.h"\r
+\r
+static NyLPC_TBool message_handler(NyLPC_TcHttpBasicHeaderParser_t* i_inst,const NyLPC_TChar* i_name,NyLPC_TChar i_c,struct NyLPC_THttpBasicHeader* o_out)\r
+{\r
+       (void)i_inst;\r
+       (void)i_name;\r
+       (void)i_c;\r
+       return NyLPC_TBool_TRUE;\r
+}\r
+static NyLPC_TBool urlHandler(NyLPC_TcHttpBasicHeaderParser_t* i_inst,NyLPC_TChar i_c,struct NyLPC_THttpBasicHeader* o_out)\r
+{\r
+       (void)i_inst;\r
+       (void)o_out;\r
+       (void)i_c;\r
+       return NyLPC_TBool_TRUE;\r
+}\r
+/**\r
+ * デフォルトハンドラ\r
+ */\r
+static const struct NyLPC_TcHttpBasicHeaderParser_Handler _handler=\r
+{\r
+       message_handler,\r
+       urlHandler\r
+};\r
+\r
+void NyLPC_cHttpNullRequestHeaderParser_initialize(NyLPC_TcHttpNullRequestHeaderParser_t* i_inst)\r
+{\r
+       NyLPC_cHttpBasicHeaderParser_initialize(&(i_inst->super),&_handler);\r
+}\r
+\r
diff --git a/lib/src/http/NyLPC_cHttpNullRequestHeaderParser.h b/lib/src/http/NyLPC_cHttpNullRequestHeaderParser.h
new file mode 100644 (file)
index 0000000..d2175aa
--- /dev/null
@@ -0,0 +1,79 @@
+/*********************************************************************************\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_CHTTPNULLHTTPHEADERPARSER_H_\r
+#define NYLPC_CHTTPNULLHTTPHEADERPARSER_H_\r
+#include "NyLPC_cHttpBasicHeaderParser.h"\r
+\r
+#ifdef __cplusplus\r
+extern "C" {\r
+#endif /* __cplusplus */\r
+\r
+/**\r
+ * URLが最大31文字までの、短いHttpリクエストを処理します。\r
+ * このクラスは、NyLPC_TBasicHttpHeader_tにキャストできます。\r
+ */\r
+typedef struct NyLPC_TcHttpNullReqestHeaderParser NyLPC_TcHttpNullRequestHeaderParser_t;\r
+\r
+\r
+\r
+struct NyLPC_TcHttpNullReqestHeaderParser{\r
+       NyLPC_TcHttpBasicHeaderParser_t super;\r
+       struct NyLPC_THttpBasicHeader _header;\r
+};\r
+\r
+void NyLPC_cHttpNullRequestHeaderParser_initialize(NyLPC_TcHttpNullRequestHeaderParser_t* i_inst);\r
+\r
+#define NyLPC_cHttpNullRequestHeaderParser_finalize(i_inst) NyLPC_cHttpBasicHeaderParser_finalize(i_inst);\r
+\r
+/**\r
+ * parseInit,parseStream,parseFinishを一括で実行します。\r
+ */\r
+NyLPC_TBool NyLPC_cHttpNullRequestHeaderParser_parse(NyLPC_TcHttpNullRequestHeaderParser_t* i_inst,NyLPC_TcHttpStream_t* i_stream);\r
+\r
+\r
+/** override\r
+ */\r
+#define NyLPC_cHttpNullRequestHeaderParser_parseInit(i_inst) NyLPC_cHttpBasicHeaderParser_parseInit(&((i_inst)->super),&((i_inst)->_header))\r
+\r
+/** override\r
+ */\r
+#define NyLPC_cHttpNullRequestHeaderParser_parseFinish(i_inst) NyLPC_cHttpBasicHeaderParser_parseFinish(&((i_inst)->super),&((i_inst)->_header))\r
+\r
+/** override\r
+ */\r
+#define NyLPC_cHttpNullRequestHeaderParser_parseChar(i_inst,i_c,i_size) NyLPC_cHttpBasicHeaderParser_parseChar(&((i_inst)->super),i_c,i_size,&((i_inst)->_header));\r
+\r
+/** override\r
+ */\r
+#define NyLPC_cHttpNullRequestHeaderParser_parseStream(i_inst,i_stream) NyLPC_cHttpBasicHeaderParser_parseStream(&((i_inst)->super),i_stream,&((i_inst)->_header))\r
+\r
+\r
+\r
+#ifdef __cplusplus\r
+}\r
+#endif /* __cplusplus */\r
+\r
+#endif /* NYLPC_CHTTPSHORTHTTPHEADERPARSER_H_ */\r
index de19a0c..28abf83 100644 (file)
@@ -51,11 +51,32 @@ struct NyLPC_TcHttpShortReqestHeaderParser{
 \r
 void NyLPC_cHttpShortRequestHeaderParser_initialize(NyLPC_TcHttpShortRequestHeaderParser_t* i_inst);\r
 \r
-#define NyLPC_cHttpShortReqestHeaderParser_finalize(i_inst) NyLPC_cHttpBasicHeaderParser_finalize(i_inst);\r
-\r
+#define NyLPC_cHttpShortRequestHeaderParser_finalize(i_inst) NyLPC_cHttpBasicHeaderParser_finalize(i_inst);\r
 \r
+/**\r
+ * parseInit,parseStream,parseFinishを一括で実行します。\r
+ */\r
 NyLPC_TBool NyLPC_cHttpShortRequestHeaderParser_parse(NyLPC_TcHttpShortRequestHeaderParser_t* i_inst,NyLPC_TcHttpStream_t* i_stream,struct NyLPC_THttpShortRequestHeader* o_out);\r
 \r
+\r
+/** override\r
+ */\r
+#define NyLPC_cHttpShortRequestHeaderParser_parseInit(i_inst,o_out) NyLPC_cHttpBasicHeaderParser_parseInit(&((i_inst)->super),&((o_out)->super))\r
+\r
+/** override\r
+ */\r
+#define NyLPC_cHttpShortRequestHeaderParser_parseFinish(i_inst,o_out) NyLPC_cHttpBasicHeaderParser_parseFinish(&((i_inst)->super),&((o_out)->super))\r
+\r
+/** override\r
+ */\r
+#define NyLPC_cHttpShortRequestHeaderParser_parseChar(i_inst,i_c,i_size,o_out) NyLPC_cHttpBasicHeaderParser_parseChar(&((i_inst)->super),i_c,i_size,&((o_out)->super));\r
+\r
+/** override\r
+ */\r
+#define NyLPC_cHttpShortRequestHeaderParser_parseStream(i_inst,i_stream,o_out) NyLPC_cHttpBasicHeaderParser_parseStream(&((i_inst)->super),i_stream,&((o_out)->super))\r
+\r
+\r
+\r
 #ifdef __cplusplus\r
 }\r
 #endif /* __cplusplus */\r
index f8b42bc..5e7aad5 100644 (file)
@@ -9,30 +9,43 @@
 #include <stdio.h>\r
 \r
 #include "../api/NyLPC_cNet.h"\r
-/*\r
+#include "../api/NyLPC_cHttpd.h"\r
+\r
 NyLPC_TcNet_t net;\r
-NyLPC_TcNet_t httpd;\r
+struct MyHttpd{\r
+       NyLPC_TcHttpd_t super;\r
+}httpd;\r
+void handler(NyLPC_TcHttpdConnection_t* i_inst)\r
+{\r
+       return;\r
+}\r
 void setup(void)\r
 {\r
+       //uipサービス初期化。いろいろ利用可能に。\r
        NyLPC_cNet_initialize(&net);\r
+       NyLPC_cHttpd_initialize(&httpd.super,80);\r
+       httpd.super.function._handler=handler;\r
 }\r
+\r
+\r
 void loop(void)\r
 {\r
-       NyLPC_TcNetConfig_t config;\r
-       NyLPC_cNetConfig_initialize(&config);\r
-       NyLPC_cNet_start(&net,&config);\r
-       NyLPC_cHttpd_loop(&httpd);\r
+       NyLPC_TcNetConfig_t c2;\r
+       NyLPC_cNetConfig_initialize(&c2);\r
+       NyLPC_cNet_start(&net,&c2);\r
+       NyLPC_cHttpd_loop(&httpd.super);\r
+       for(;;);\r
 }\r
-*/\r
 \r
-#ifndef COMMENT\r
+\r
+#ifdef COMMENT\r
 \r
 \r
 //イーサネット用の初期化情報\r
 const struct NyLPC_TEthAddr ethaddr=NyLPC_TEthAddr_pack(0x02,0x01,0x02,0x03,0x04,0x05);\r
-const struct NyLPC_TIPv4Addr ipaddr=NyLPC_TIPv4Addr_pack(192,168,128,201);\r
+const struct NyLPC_TIPv4Addr ipaddr=NyLPC_TIPv4Addr_pack(192,168,0,39);\r
 const struct NyLPC_TIPv4Addr netmask=NyLPC_TIPv4Addr_pack(255,255,255,0);\r
-const struct NyLPC_TIPv4Addr gateway=NyLPC_TIPv4Addr_pack(192,168,128,254);\r
+const struct NyLPC_TIPv4Addr gateway=NyLPC_TIPv4Addr_pack(192,168,0,254);\r
 \r
 //TCP処理スレッドの定義\r
 #define SIZE_OF_RX 256\r
@@ -66,12 +79,12 @@ void setup(void)
        int i;\r
        //uipサービス初期化。いろいろ利用可能に。\r
        NyLPC_cUipService_initialize();\r
-       for(i=0;i<NUM_OF_TH;i++){\r
-               NyLPC_cThread_initialize(&(proc[i].th),200,NyLPC_TcThread_PRIORITY_IDLE);\r
-               NyLPC_cTcpSocket_initialize(&(proc[i].socket),proc[i].rbuf,SIZE_OF_RX);\r
-       }\r
-       //ROMのファイルシステムを初期化\r
-       NyLPC_cRomFileSet_initialize(&rfs,rfsd,2);\r
+//     for(i=0;i<NUM_OF_TH;i++){\r
+//             NyLPC_cThread_initialize(&(proc[i].th),200,NyLPC_TcThread_PRIORITY_IDLE);\r
+//             NyLPC_cTcpSocket_initialize(&(proc[i].socket),proc[i].rbuf,SIZE_OF_RX);\r
+//     }\r
+//     //ROMのファイルシステムを初期化\r
+//     NyLPC_cRomFileSet_initialize(&rfs,rfsd,2);\r
 \r
 }\r
 \r
@@ -158,9 +171,9 @@ void loop(void)
        NyLPC_cIPv4Config_setIp(&config,&ipaddr,&netmask);\r
 \r
 \r
-       NyLPC_cTcpListener_initialize(&listener,80);\r
+//     NyLPC_cTcpListener_initialize(&listener,80);\r
        NyLPC_cUipService_start(&config);\r
-       for(;;){\r
+/*     for(;;){\r
                //ターミネイト状態のタスクを検索\r
                for(i=0;i<NUM_OF_TH;i++){\r
                        if(NyLPC_cThread_isTerminated(&(proc[i].th))){\r
@@ -172,7 +185,7 @@ void loop(void)
                                NyLPC_cThread_start(&(proc[i].th),server,&(proc[i]));\r
                        }\r
                }\r
-       }\r
+       }*/\r
        for(;;){}\r
 }\r
 \r